-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[Origin API] Define an Origin interface. (#11534)
#11846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
9d56f34
b0fdce5
2904ac2
37fa923
2d77ad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26062,6 +26062,19 @@ document.body.appendChild(wbr);</code></pre> | |||||
| <p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has an associated <dfn | ||||||
| data-x="concept-hyperlink-url">url</dfn> (null or a <span>URL</span>). It is initially null. | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has the following | ||||||
| <span>extract an origin</span> steps:</p> | ||||||
|
|
||||||
| <ol> | ||||||
| <li><p>If <span>this</span>'s <span data-x="concept-hyperlink-url">url</span> is null, then | ||||||
| return null.</p></li> | ||||||
|
|
||||||
| <li><p>Return <span>this</span>'s <span data-x="concept-hyperlink-url">url</span>'s | ||||||
mikewest marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| <span data-x="concept-url-origin">origin</span>.</p></li> | ||||||
| </ol> | ||||||
| </div> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has an associated <dfn | ||||||
| data-x="concept-hyperlink-url-set">set the url</dfn> algorithm, which runs these steps:</p> | ||||||
|
|
@@ -92415,6 +92428,111 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> { | |||||
|
|
||||||
| </div> | ||||||
|
|
||||||
| <h5>The <code data-x="dom-Origin-interface">Origin</code> interface</h5> | ||||||
|
|
||||||
| <p>The <code data-x="dom-Origin-interface">Origin</code> interface represents an | ||||||
| <span>origin</span>, allowing robust <span>same origin</span> and <span>same site</span> | ||||||
| comparisons.</p> | ||||||
|
|
||||||
| <pre><code class="idl">[Exposed=*] | ||||||
| interface <dfn interface data-x="dom-Origin-interface">Origin</dfn> { | ||||||
| <span data-x="dom-Origin-constructor">constructor</span>(); | ||||||
|
|
||||||
| static <span data-x="dom-Origin-interface">Origin</span> <span data-x="dom-Origin-from">from</span>(any value); | ||||||
|
|
||||||
| readonly attribute boolean <span data-x="dom-Origin-opaque">opaque</span>; | ||||||
|
|
||||||
| boolean <span data-x="dom-Origin-isSameOrigin">isSameOrigin</span>(Origin other); | ||||||
| boolean <span data-x="dom-Origin-isSameSite">isSameSite</span>(Origin other); | ||||||
| };</code></pre> | ||||||
|
|
||||||
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| <p><code data-x="dom-Origin-interface">Origin</code> objects have an associated | ||||||
| <dfn for="Origin" attribute data-x="dom-Origin-origin">origin</dfn>, which holds an | ||||||
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| <span>origin</span>.</p> | ||||||
|
|
||||||
| <p><span data-x="platform object">Platform objects</span> have an | ||||||
| <dfn for="platform object" export>extract an origin</dfn> operation, which returns null unless | ||||||
| otherwise specified.</p> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>Objects implementing the <code data-x="dom-Origin-interface">Origin</code> interface's | ||||||
| <span>extract an origin</span> steps are to return <span>this</span>'s | ||||||
| <span data-x="dom-Origin-origin">origin</span>.</p> | ||||||
| </div> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>The <dfn constructor for="Origin"><code | ||||||
| data-x="dom-Origin-constructor">new Origin()</code></dfn> constructor steps are:</p> | ||||||
|
|
||||||
| <ol> | ||||||
| <li><p>Set <span>this</span>'s <span data-x="dom-Origin-origin">origin</span> to a unique | ||||||
| <span data-x="concept-origin-opaque">opaque origin</span>.</p></li> | ||||||
| </ol> | ||||||
| </div> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>The static <dfn method for="Origin"><code data-x="dom-Origin-from">from(value)</code></dfn> | ||||||
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| method accepts an arbitrary object <var>value</var>, and returns either a newly-constructed | ||||||
| <code data-x="dom-Origin-interface">Origin</code> object if one can be extracted from | ||||||
| <var>value</var>, or throws a <code>TypeError</code> otherwise:</p> | ||||||
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| <ol> | ||||||
| <li> | ||||||
| <p>If <var>value</var> is a <span>platform object</span>:</p> | ||||||
| <ol> | ||||||
| <li><p>Let <var>origin</var> be the result of executing <var>value</var>'s <span>extract an | ||||||
| origin</span> operation.</p></li> | ||||||
|
|
||||||
| <li><p>If <var>origin</var> is not null, then return a new | ||||||
| <code data-x="dom-Origin-interface">Origin</code> object whose | ||||||
| <span data-x="dom-Origin-origin">origin</span> is set to <var>origin</var>.</p></li> | ||||||
| </ol> | ||||||
| </li> | ||||||
|
|
||||||
| <li> | ||||||
| <p>If <var>value</var> is a <span>string</span>:</p> | ||||||
| <ol> | ||||||
| <li><p>Let <var>parsed url</var> be the result of <span data-x="basic url parser">basic URL | ||||||
| parsing</span> <var>value</var>.</p></li> | ||||||
|
|
||||||
| <li><p>If <var>parsed url</var> is not failure, then return a new | ||||||
| <code data-x="dom-Origin-interface">Origin</code> object whose | ||||||
| <span data-x="dom-Origin-origin">origin</span> is set to <var>parsed url</var>'s | ||||||
| <span data-x="concept-url-origin">origin</span>.</p></li> | ||||||
| </ol> | ||||||
| </li> | ||||||
|
|
||||||
| <li><p>Throw a <code>TypeError</code>.</p></li> | ||||||
| </ol> | ||||||
| </div> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>The <dfn attribute for="Origin"><code data-x="dom-Origin-opaque">opaque</code></dfn> attribute | ||||||
| getter steps are to return true if <span>this</span>'s | ||||||
| <span data-x="dom-Origin-origin">origin</span> is an <span data-x="concept-origin-opaque">opaque | ||||||
| origin</span>, and false otherwise.</p> | ||||||
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| </div> | ||||||
|
|
||||||
| <div algorithm> | ||||||
| <p>The <dfn method for="Origin"><code | ||||||
| data-x="dom-Origin-isSameOrigin">isSameOrigin(other)</code></dfn> method returns true if | ||||||
| <span>this</span>'s <span data-x="dom-Origin-origin">origin</span> is <span>same origin</span> | ||||||
| with <var>other</var>'s <span data-x="dom-Origin-origin">origin</span>, and false otherwise.</p> | ||||||
|
||||||
| with <var>other</var>'s <span data-x="dom-Origin-origin">origin</span>, and false otherwise.</p> | |
| with <var>other</var>'s <span data-x="dom-Origin-origin">origin</span>; otherwise false.</p> |
mikewest marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this note in response to @erik-anderson's suggestion in mikewest/origin-api#11. Otherwise, I think this PR is pretty good to go.
If @annevk and @zcorpan are happy-enough, I'll go file bugs against browsers, and see if Chromium folks will let me get it out the door.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this as there's quite a number of APIs this applies to and I don't think we want to call this out all over. I could maybe see adding it to URL (or even better would be the Public Suffix standard once we finally rescue that project from its current state).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I've taken it back out, and I'll put it up as a PR against URL.
Uh oh!
There was an error while loading. Please reload this page.