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
35 changes: 21 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ <h2>
<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>
Expand Down Expand Up @@ -297,13 +301,18 @@ <h2>
<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>'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, 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.
<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>SecurityError</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.
Copy link

Choose a reason for hiding this comment

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

You could add something like "unless specifically allowed by the document's feature policy." to this, if you wanted to be clear that it's possible to grant access to cross-origin subframes, but you have to be deliberate about it. The default situation is exactly as you describe here.

</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 @@ -526,13 +535,11 @@ <h2>
Feature Policy integration
</h2>
<p data-link-for="Navigator">
The Battery Status API is a <a>policy-controlled feature</a>, as
defined by Feature Policy [[!FEATURE-POLICY]]. The <a>feature name</a>
for the Battery Status API is "<code>battery</code>". The <a>default
allowlist</a> for the Battery Status API is <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>.
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">
Expand Down