Skip to content
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

Allow use in same-origin children, add Feature Policy integration #13

Merged
merged 11 commits into from
Sep 24, 2019
106 changes: 90 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ <h2>
"https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler"><dfn><code>
EventHandler</code></dfn></a>
</li>
<li>
<a href=
"https://dom.spec.whatwg.org/#eventtarget"><dfn><code>
EventTarget</code></dfn></a>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task">queue a
task</a></dfn>
</li>
<li>
<code><dfn data-cite="DOM#eventtarget">EventTarget</dfn></code>
</li>
<li>
<dfn><a href=
"https://dom.spec.whatwg.org/#concept-event-fire">fires
Expand All @@ -177,6 +175,21 @@ <h2>
"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">browsing
context</a></dfn>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/#concept-relevant-global">relevant
global object</a></dfn>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/#relevant-settings-object">relevant
settings object</a></dfn>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/#current-settings-object">current
settings object</a></dfn>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context">
Expand All @@ -187,6 +200,11 @@ <h2>
"https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object">
incumbent settings object</a></dfn>
</li>
<li>
<dfn><a href=
"https://html.spec.whatwg.org/#concept-document-window">associated
<code>Document</code></a></dfn>
</li>
<li>
<a href=
"https://tc39.github.io/ecma262/#sec-promise-objects"><dfn>Promise</dfn></a>
Expand All @@ -199,6 +217,10 @@ <h2>
<a href=
"https://heycam.github.io/webidl/#securityerror"><dfn><code>SecurityError</code></dfn></a>
</li>
<li>
<a href=
"https://heycam.github.io/webidl/#notallowederror"><dfn><code>NotAllowedError</code></dfn></a>
</li>
<li>
<a href=
"https://heycam.github.io/webidl/#idl-DOMException"><dfn><code>DOMException</code></dfn></a>
Expand All @@ -208,6 +230,37 @@ <h2>
"https://www.w3.org/TR/secure-contexts/#secure-context"><dfn>secure
context</dfn></a>
</li>
<li>
<a href="https://html.spec.whatwg.org/#active-document"><dfn>active
document</dfn></a>
</li>
<li>
<a href=
"https://html.spec.whatwg.org/#concept-origin"><dfn>origin</dfn></a>
</li>
<li>
<a href="https://html.spec.whatwg.org/#same-origin-domain"><dfn>same
origin-domain</dfn></a>
</li>
<li>
<a href="https://html.spec.whatwg.org/#allowed-to-use"><dfn>allowed
to use</dfn></a>
</li>
<li>
<a href=
"https://wicg.github.io/feature-policy/#policy-controlled-feature"><dfn>
policy-controlled feature</dfn></a>
</li>
<li>
<a href=
"https://wicg.github.io/feature-policy/#feature-name"><dfn>feature
name</dfn></a>
</li>
<li>
<a href=
"https://wicg.github.io/feature-policy/#default-allowlist"><dfn>default
allowlist</dfn></a>
</li>
</ul>
</section>
<section class="informative">
Expand Down Expand Up @@ -259,17 +312,26 @@ <h2>
the following steps:
</p>
<ol>
<li>If the <a>incumbent settings object</a> is not a <a>secure
context</a>, then reject this <a>Navigator</a> object's <a>battery
promise</a> with a "<a>SecurityError</a>" <a>DOMException</a>, return
this <a>Navigator</a> object's <a>battery promise</a> and abort these
steps.
</li>
<li>If the <a>browsing context</a> is not a <a>top-level browsing
context</a>, then reject this <a>Navigator</a> object's <a>battery
promise</a> with a "<a>SecurityError</a>" <a>DOMException</a>, return
this <a>Navigator</a> object's <a>battery promise</a> and abort these
steps.
<li>If the <a>relevant settings object</a> of this <a>Navigator</a>
object is not a <a>secure context</a>, then reject this
<a>Navigator</a> object's <a>battery promise</a> with a
"<a>SecurityError</a>" <a>DOMException</a>, return this
<a>Navigator</a> object's <a>battery promise</a> and abort these steps.
</li>
<li>If this <a>Navigator</a> object's <a>relevant global object</a>'s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With feature policy integration, I think you can replace this entire paragraph with something like

If this Navigator object's relevant global object's associated Document is not allowed to use the battery feature, then reject...

Because the default allowlist is 'self', that will automatically take care of the same-origin embed case, while allowing cross-origin usage only if explicitly enabled by the embedding document (which this paragraph still prohibits, I think)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an update in an attempt to make use of "allowed to use". Please take a look. (I'm happy to see "allowed to use" abstracted out and reusable.)

<a>associated <code>Document</code></a> is not <a>allowed to use</a>
the <code>battery</code> feature, then reject this <a>Navigator</a>
object's <a>battery promise</a> with a "<a>NotAllowedError</a>"
<a>DOMException</a>, return this <a>Navigator</a> object's <a>battery
promise</a> and abort these steps.
<div class="note">
In other words, this step rejects if the <a>associated
<code>Document</code></a>'s <a>browsing context</a>'s <a>active
document</a>'s <a>origin</a> is not <a>same origin-domain</a> with
the <a>origin</a> of the <a>current settings object</a> of this
<a>Navigator</a> object, unless specifically allowed by the
document's feature policy.
</div>
</li>
<li>If this <a>Navigator</a> object's <a>battery promise</a> is not
<code>null</code>, return this <a>Navigator</a> object's <a>battery
Expand Down Expand Up @@ -486,6 +548,18 @@ <h2>
</table>
</section>
</section>
<section>
<h2>
Feature Policy integration
</h2>
<p data-link-for="Navigator">
The Battery Status API is a <a>policy-controlled feature</a> identified
by the string "<code>battery</code>". It's default allowlist is
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Note to self: s/It’s/Its/)

<code>'self'</code>. When disabled in a document, the
<code><a>getBattery</a>()</code> method MUST return a <a>promise</a>
which rejects with a "<a>SecurityError</a>" <a>DOMException</a>.
</p>
</section>
<section class="informative">
<h2>
Examples
Expand Down