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

Define requestPermission() behavior. #180

Merged
merged 4 commits into from Jun 23, 2017

Conversation

romandev
Copy link
Member

In the current spec, there is no definition of the requestPermission() method.
This change is fixing #94 issue.

In the current spec, there is no definition of the requestPermission() method.
This change is fixing w3c#94 issue.
@romandev
Copy link
Member Author

@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();
Copy link
Collaborator

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?

Copy link
Contributor

@dlongley dlongley Jun 21, 2017

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).

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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.
Copy link
Collaborator

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?

Copy link
Member Author

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>.
Copy link
Collaborator

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.

Copy link
Member Author

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>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@rsolomakhin rsolomakhin left a 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>.
Copy link
Contributor

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>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member Author

@romandev romandev left a comment

Choose a reason for hiding this comment

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

@rsolomakhin, @dlongley

Thank you for review 👍

I addressed your comments.

index.html Outdated
interface PaymentManager {
[SameObject] readonly attribute PaymentInstruments instruments;
[SameObject] readonly attribute PaymentWallets wallets;
Promise&lt;boolean&gt; requestPermission();
[Exposed=Window] static Promise&lt;PermisionState&gt; requestPermission();
Copy link
Member Author

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>.
Copy link
Member Author

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>.
Copy link
Member Author

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>.
Copy link
Member Author

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.
Copy link
Member Author

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

@ianbjacobs
Copy link
Contributor

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>
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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?

  1. Let p be a new Promise
  2. Return p and perform the remaining steps in parallel.

Example in https://www.w3.org/TR/payment-request/#show-method at step 9.

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'll do it in follow-up PR!
Could you merge this PR? I don't have a permission to merge.
Thank you!

@ianbjacobs ianbjacobs merged commit 6856ef2 into w3c:gh-pages Jun 23, 2017
@romandev romandev deleted the request_permission branch June 23, 2017 22:19
romandev added a commit to romandev/payment-handler that referenced this pull request Jun 23, 2017
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.
ianbjacobs pushed a commit that referenced this pull request Jun 24, 2017
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants