Skip to content

Commit ca52252

Browse files
committed
[Origin API] Define an Origin interface. (#11534)
This patch shifts the normative portions of https://mikewest.github.io/origin-api/ into a patch against HTML for discussion. As a followup, this will require changes to [[URL]] and [[ServiceWorker]] as well to define the "extract an origin" for relevant objects. See discussion in w3ctag/design-reviews#1130, WebKit/standards-positions#538, and mozilla/standards-positions#1280.
1 parent 0e5e7c9 commit ca52252

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

source

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26061,6 +26061,18 @@ document.body.appendChild(wbr);</code></pre>
2606126061
<p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has an associated <dfn
2606226062
data-x="concept-hyperlink-url">url</dfn> (null or a <span>URL</span>). It is initially null.
2606326063

26064+
<div algorithm>
26065+
<p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has the following
26066+
<span>extract an origin</span> steps:</p>
26067+
26068+
<ol>
26069+
<li><p>If <span>this</span>'s <span data-x="concept-hyperlink-url">url</span> is null, return
26070+
null.</p></li>
26071+
<li><p>Return <span>this</span>'s <span data-x="concept-hyperlink-url">url</span>'s
26072+
<span data-x="concept-url-origin">origin</span>.</p></li>
26073+
</ol>
26074+
</div>
26075+
2606426076
<div algorithm>
2606526077
<p>An element implementing the <code>HTMLHyperlinkElementUtils</code> mixin has an associated <dfn
2606626078
data-x="concept-hyperlink-url-set">set the url</dfn> algorithm, which runs these steps:</p>
@@ -92414,6 +92426,104 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> {
9241492426

9241592427
</div>
9241692428

92429+
<h5>The <code data-x="dom-Origin-interface">Origin</code> interface</h5>
92430+
92431+
<p>The <code data-x="dom-Origin-interface">Origin</code> interface represents an
92432+
<span>origin</span>, allowing robust <span>same origin</span> and <span>same site</span>
92433+
comparisons.</p>
92434+
92435+
<pre><code class="idl">[Exposed=*]
92436+
interface <dfn interface data-x="dom-Origin-interface">Origin</dfn> {
92437+
<span data-x="dom-Origin-constructor">constructor</span>();
92438+
92439+
static <span data-x="dom-Origin-interface">Origin</span> <span data-x="dom-Origin-from">from</span>(any value);
92440+
92441+
readonly attribute boolean <span data-x="dom-Origin-opaque">opaque</span>;
92442+
92443+
boolean <span data-x="dom-Origin-isSameOrigin">isSameOrigin</span>(Origin other);
92444+
boolean <span data-x="dom-Origin-isSameSite">isSameSite</span>(Origin other);
92445+
};</code></pre>
92446+
92447+
<p><code data-x="dom-Origin-interface">Origin</code> objects have an
92448+
<dfn for="Origin" attribute>[[origin]]</dfn> internal slot, which holds an
92449+
<span>origin</span>.</p>
92450+
92451+
<p><span data-x="platform object">Platform objects</span> have an
92452+
<dfn for="platform object" export>extract an origin</dfn> operation, which returns null unless
92453+
otherwise specified.</p>
92454+
92455+
<div algorithm>
92456+
<p>Objects implementing the <code data-x="dom-Origin-interface">Origin</code> interface's
92457+
<span>extract an origin</span> steps are to return <span>this</span>'s
92458+
<span>[[origin]]</span>.</p>
92459+
</div>
92460+
92461+
<div algorithm>
92462+
<p>The <dfn constructor for="Origin"><code
92463+
data-x="dom-Origin-constructor">new Origin()</code></dfn> constructor steps are:</p>
92464+
92465+
<ol>
92466+
<li><p>Set <span>this</span>'s <span>[[origin]]</span> internal slot to a unique
92467+
<span data-x="concept-origin-opaque">opaque origin</span>.</p></li>
92468+
</ol>
92469+
</div>
92470+
92471+
<div algorithm>
92472+
<p>The static <dfn method for="Origin"><code data-x="dom-Origin-from">from(value)</code></dfn>
92473+
method accepts an arbitrary object <var>value</var>, and returns either a newly-constructed
92474+
<code data-x="dom-Origin-interface">Origin</code> object if one can be extracted from
92475+
<var>value</var>, or throws a <code>TypeError</code> otherwise:</p>
92476+
92477+
<ol>
92478+
<li>
92479+
<p>If <var>value</var> is a <span>platform object</span>:</p>
92480+
<ol>
92481+
<li><p>Let <var>origin</var> be the result of executing <var>value</var>'s <span>extract an
92482+
origin</span> operation.</p></li>
92483+
<li><p>If <var>origin</var> is not null, return a new
92484+
<code data-x="dom-Origin-interface">Origin</code> object whose <span>[[origin]]</span> is set
92485+
to <var>origin</var>.</p></li>
92486+
</ol>
92487+
</li>
92488+
<li>
92489+
<p>If <var>value</var> is a <span>string</span>:</p>
92490+
<ol>
92491+
<li><p>Let <var>parsed url</var> be the result of <span data-x="basic url parser">basic URL
92492+
parsing</span> <var>value</var>.</p></li>
92493+
<li><p>If <var>parsed url</var> is not failure, return a new
92494+
<code data-x="dom-Origin-interface">Origin</code> object whose <span>[[origin]]</span> is set
92495+
to <var>parsed url</var>'s <span data-x="concept-url-origin">origin</span>.</p></li>
92496+
</ol>
92497+
</li>
92498+
<li><p>Throw a <code>TypeError</code>.</p></li>
92499+
</ol>
92500+
</div>
92501+
92502+
<div algorithm>
92503+
<p>The <dfn attribute for="Origin"><code data-x="dom-Origin-opaque">opaque</code></dfn> attribute
92504+
getter steps are to return true if <span>this</span>'s <span>[[origin]]</span> is an <span
92505+
data-x="concept-origin-opaque">opaque origin</span>, and false otherwise.</p>
92506+
</div>
92507+
92508+
<div algorithm>
92509+
<p>The <dfn method for="Origin"><code
92510+
data-x="dom-Origin-isSameOrigin">isSameOrigin(other)</code></dfn> method returns true if
92511+
<span>this</span>'s <span>[[origin]]</span> is <span>same origin</span> with <var>other</var>'s
92512+
<span>[[origin]]</span>, and false otherwise.</p>
92513+
</div>
92514+
92515+
<div algorithm>
92516+
<p>The <dfn method for="Origin"><code
92517+
data-x="dom-Origin-isSameSite">isSameSite(other)</code></dfn> method returns true if
92518+
<span>this</span>'s <span>[[origin]]</span> is <span>same site</span> with <var>other</var>'s
92519+
<span>[[origin]]</span>, and false otherwise.</p>
92520+
92521+
<p class="note">This is a <span>same site</span>, <em>not</em> <span>schemelessly same
92522+
site</span>, comparison. For the reasons <a
92523+
href="https://url.spec.whatwg.org/#warning-avoid-psl">explained in <cite>URL</cite></a> The
92524+
<code data-x="dom-Origin-interface">Origin</code> origin does not offer schemeless comparison.</p>
92525+
</div>
92526+
9241792527

9241892528
<h4><span id="origin-isolation"></span>Origin-keyed agent clusters</h4>
9241992529

@@ -96905,6 +97015,21 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
9690597015
<code>Document</code></span> is non-null, and <code>about:blank</code> otherwise.</p>
9690697016
</div>
9690797017

97018+
<div algorithm>
97019+
<p>An element implementing the <code>Location</code> interface has the following <span>extract an
97020+
origin</span> steps:</p>
97021+
97022+
<ol>
97023+
<li><p>If <span>this</span>'s <span>relevant <code>Document</code></span> is non-null and its
97024+
<span data-x="concept-document-origin">origin</span> is not <span>same origin-domain</span> with
97025+
the <span>entry settings object</span>'s
97026+
<span data-x="concept-settings-object-origin">origin</span>, then return null.</p></li>
97027+
97028+
<li><p>Return <span>this</span>'s <span data-x="concept-location-url">url</span>'s
97029+
<span data-x="concept-url-origin">origin</span>.</p></li>
97030+
</ol>
97031+
</div>
97032+
9690897033
<div algorithm>
9690997034
<p>A <code>Location</code> object has an associated <dfn
9691097035
data-x="concept-location-ancestor-origins-list">ancestor origins list</dfn>. When a
@@ -123028,6 +123153,24 @@ document.body.appendChild(frame)</code></pre>
123028123153
capability</span>.</p>
123029123154
</div>
123030123155

123156+
<div algorithm>
123157+
<p>An element implementing the <code>WindowOrWorkerGlobalScope</code> mixin has the following
123158+
<span>extract an origin</span> steps:</p>
123159+
123160+
<ol>
123161+
<li><p>If <span>this</span>'s <span>relevant settings object</span>'s <span
123162+
data-x="concept-settings-object-origin">origin</span> is not <span>same origin-domain</span>
123163+
with the <span>entry settings object</span>'s <span
123164+
data-x="concept-settings-object-origin">origin</span>, return null.</p></li>
123165+
123166+
<li><p>Return <span>this</span>'s return <span>this</span>'s <span>relevant settings
123167+
object</span>'s <span data-x="concept-settings-object-origin">origin</span>.</p></li>
123168+
</ol>
123169+
123170+
<p class="note">Since these objects are potentially accessible cross-origin (e.g. through
123171+
<code>WindowProxy</code>), we need a security check here before granting access to the origin.</p>
123172+
</div>
123173+
123031123174
</div>
123032123175

123033123176

@@ -127520,6 +127663,12 @@ typedef (<span>WindowProxy</span> or <span>MessagePort</span> or <span>ServiceWo
127520127663
<span data-x="concept-url-fragment">fragment</span>).</p>
127521127664
</div>
127522127665

127666+
<div algorithm>
127667+
<p>Objects implementing the <code>MessageEvent</code> interface's <span>extract an origin</span>
127668+
steps are to return <span>this</span>'s <span>relevant settings object</span>'s
127669+
<span data-x="concept-settings-object-origin">origin</span>.</p>
127670+
</div>
127671+
127523127672
<div algorithm>
127524127673
<p>The <dfn attribute for="MessageEvent"><code
127525127674
data-x="dom-MessageEvent-lastEventId">lastEventId</code></dfn> attribute must return the value it
@@ -131617,6 +131766,14 @@ interface <dfn interface>WorkerLocation</dfn> {
131617131766

131618131767
<div w-nodev>
131619131768

131769+
<div algorithm>
131770+
<p>Objects implementing the <code>WorkerLocation</code> interface's <span>extract an origin</span>
131771+
steps are to return <span>this</span>'s <span
131772+
data-x="concept-WorkerLocation-WorkerGlobalScope"><code>WorkerGlobalScope</code> object</span>'s
131773+
<span data-x="concept-WorkerGlobalScope-url">url</span>'s <span
131774+
data-x="concept-url-origin">origin</span>.</p>
131775+
</div>
131776+
131620131777
<p>A <code>WorkerLocation</code> object has an associated <dfn
131621131778
data-x="concept-WorkerLocation-WorkerGlobalScope"><code>WorkerGlobalScope</code> object</dfn> (a
131622131779
<code>WorkerGlobalScope</code> object).

0 commit comments

Comments
 (0)