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
Define requestPermission() behavior. #180
Conversation
In the current spec, there is no definition of the requestPermission() method. This change is fixing w3c#94 issue.
@ianbjacobs, @rsolomakhin PTAL Thank you. |
index.html
Outdated
interface PaymentManager { | ||
[SameObject] readonly attribute PaymentInstruments instruments; | ||
[SameObject] readonly attribute PaymentWallets wallets; | ||
Promise<boolean> requestPermission(); | ||
[Exposed=Window] static Promise<PermisionState> requestPermission(); |
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.
What does [Exposed=Window]
do?
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 believe that the [SecureContext]
extended attribute applies to the entire interface (exposing it only in secure contexts) and the [Exposed=Window]
is a further restriction, specifically, on requestPermission
to cause it to only be exposed when the global context is Window
(as opposed to in a Worker
, for example -- where it won't be accessible given this directive).
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.
Also, there's a typo here: PermisionState
=> PermissionState
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.
Done.
FYI, I found a history of Notification.requestPermission().
https://lists.w3.org/Archives/Public/public-whatwg-archive/2014Jul/0178.html
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.
Thanks @romandev, @rsolomakhin, and @dlongley!
@romandev, you deleted:
" The user agent is NOT REQUIRED to prompt the user to grant permission to the origin for each new supported payment method."
I think we still need that text.
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.
@ianbjacobs, You're correct!
Done. Thanks.
allowing adding new payment instruments for the <a data-cite= | ||
"!HTML#current-settings-object">current settings object</a>'s | ||
origin is acceptable. If it is, set <var>permission</var> to | ||
"granted", and "denied" otherwise. |
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.
Your implementation can also resolve p
with "default"
. When would that happen?
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.
In the implementation, I defined PaymentHandlerStatus as 'default' instead of 'prompt'.
Because the Notification spec[1] is doing like that.
But I awared that we can use PermissionState in Permission API spec[2] instead of our own definition.
[1] https://notifications.spec.whatwg.org/#enumdef-notificationpermission
[2] https://www.w3.org/TR/permissions/#idl-def-PermissionState
index.html
Outdated
with <a>payment handler</a>. | ||
</li> | ||
<li>If <var>permission</var> is not "granted", then return a | ||
<a>Promise</a> rejected with a <a>SecurityError</a>. |
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.
NotAllowedError
might be better, IMHO.
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.
Done.
index.html
Outdated
with <a>payment handler</a>. | ||
</li> | ||
<li>If <var>permission</var> is not "granted", then return a | ||
<a>Promise</a> rejected with a <a>SecurityError</a>. |
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.
Ditto
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.
Done.
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.
Thank you for the patch! Good work!
index.html
Outdated
<li>Let <var>permission</var> be the result of running | ||
<a data-cite="!permissions#dfn-retrieve-the-permission-state"> | ||
retrieve the permission state algorithm</a> of the permission | ||
associated with <a>payment handler</a>. |
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.
Should this say for the permission associated with <a>payment handler's</a> <a>origin</a>
?
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.
Done.
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.
index.html
Outdated
interface PaymentManager { | ||
[SameObject] readonly attribute PaymentInstruments instruments; | ||
[SameObject] readonly attribute PaymentWallets wallets; | ||
Promise<boolean> requestPermission(); | ||
[Exposed=Window] static Promise<PermisionState> requestPermission(); |
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.
Done.
FYI, I found a history of Notification.requestPermission().
https://lists.w3.org/Archives/Public/public-whatwg-archive/2014Jul/0178.html
index.html
Outdated
with <a>payment handler</a>. | ||
</li> | ||
<li>If <var>permission</var> is not "granted", then return a | ||
<a>Promise</a> rejected with a <a>SecurityError</a>. |
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.
Done.
index.html
Outdated
with <a>payment handler</a>. | ||
</li> | ||
<li>If <var>permission</var> is not "granted", then return a | ||
<a>Promise</a> rejected with a <a>SecurityError</a>. |
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.
Done.
index.html
Outdated
<li>Let <var>permission</var> be the result of running | ||
<a data-cite="!permissions#dfn-retrieve-the-permission-state"> | ||
retrieve the permission state algorithm</a> of the permission | ||
associated with <a>payment handler</a>. |
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.
Done.
allowing adding new payment instruments for the <a data-cite= | ||
"!HTML#current-settings-object">current settings object</a>'s | ||
origin is acceptable. If it is, set <var>permission</var> to | ||
"granted", and "denied" otherwise. |
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.
In the implementation, I defined PaymentHandlerStatus as 'default' instead of 'prompt'.
Because the Notification spec[1] is doing like that.
But I awared that we can use PermissionState in Permission API spec[2] instead of our own definition.
[1] https://notifications.spec.whatwg.org/#enumdef-notificationpermission
[2] https://www.w3.org/TR/permissions/#idl-def-PermissionState
0bc7f15
to
8de8212
Compare
Thanks @romandev! @rsolomakhin if you are satisfied your comments have been addressed, please give the green light to merge. |
</li> | ||
</ol> | ||
</li> | ||
<li>Return <var>p</var> |
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.
Shouldn't we return the promise before we resolve it?
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.
@adrianhopebailie Thank you for review.
As far as I know, we are already using the pattern in many places in this spec or other specs. [1][2]
Resolving the promise will happen in parallel due to the following sentence:
"Run the following steps in parallel:"
So, I think it makes sense. WDYT?
(If I'm missing something, please correct me! :) )
[1] https://w3c.github.io/payment-handler/#has-method
[2] https://w3c.github.io/ServiceWorker/#cache-match
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.
You are right, happy for you to merge as is.
I find the pattern used in the Payment Request spec easier to follow. If you agree then perhaps we should change across the document in a new PR?
- Let
p
be a new Promise - Return
p
and perform the remaining steps in parallel.
Example in https://www.w3.org/TR/payment-request/#show-method at step 9.
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'll do it in follow-up PR!
Could you merge this PR? I don't have a permission to merge.
Thank you!
This PR is initiated from w3c#180. We should change the patterns of returning promise to more readable patterns as follows: BEFORE Let p be a new promise. Run the following steps in parallel: Do something Resolve p return p AFTER Let p be a new promise. Return p and perform the remaining steps in parallel: Do something Resolve p FYI, the patterns are already widely used in PaymentRequest API spec.
…186) This PR is initiated from #180. We should change the patterns of returning promise to more readable patterns as follows: BEFORE Let p be a new promise. Run the following steps in parallel: Do something Resolve p return p AFTER Let p be a new promise. Return p and perform the remaining steps in parallel: Do something Resolve p FYI, the patterns are already widely used in PaymentRequest API spec.
In the current spec, there is no definition of the requestPermission() method.
This change is fixing #94 issue.