Index: third_party/WebKit/Source/modules/payments/PaymentManager.cpp |
diff --git a/third_party/WebKit/Source/modules/payments/PaymentManager.cpp b/third_party/WebKit/Source/modules/payments/PaymentManager.cpp |
index 4be03f6f5d7b24c02f9c0a641b85473399fe59c6..9830a32b52cb58308628b3d632bc59fac7935302 100644 |
--- a/third_party/WebKit/Source/modules/payments/PaymentManager.cpp |
+++ b/third_party/WebKit/Source/modules/payments/PaymentManager.cpp |
@@ -6,7 +6,9 @@ |
#include "bindings/core/v8/ScriptPromise.h" |
#include "core/dom/DOMException.h" |
+#include "core/dom/UserGestureIndicator.h" |
#include "modules/payments/PaymentInstruments.h" |
+#include "modules/permissions/PermissionUtils.h" |
#include "modules/serviceworkers/ServiceWorkerRegistration.h" |
#include "platform/bindings/ScriptState.h" |
#include "platform/mojo/MojoHelper.h" |
@@ -26,6 +28,31 @@ PaymentInstruments* PaymentManager::instruments() { |
return instruments_; |
} |
+ScriptPromise PaymentManager::requestPermission(ScriptState* script_state) { |
+ ExecutionContext* context = ExecutionContext::From(script_state); |
+ |
+ if (!permission_service_) { |
+ ConnectToPermissionService(context, |
+ mojo::MakeRequest(&permission_service_)); |
+ permission_service_.set_connection_error_handler(ConvertToBaseCallback( |
+ WTF::Bind(&PaymentManager::OnPermissionServiceConnectionError, |
+ WrapWeakPersistent(this)))); |
+ } |
+ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
+ ScriptPromise promise = resolver->Promise(); |
+ |
+ permission_service_->RequestPermission( |
+ CreatePermissionDescriptor(mojom::blink::PermissionName::PAYMENT_HANDLER), |
+ context->GetSecurityOrigin(), |
+ UserGestureIndicator::ProcessingUserGesture(), |
+ ConvertToBaseCallback( |
+ WTF::Bind(&PaymentManager::OnPermissionRequestComplete, |
+ WrapPersistent(this), WrapPersistent(resolver)))); |
+ |
+ return promise; |
+} |
+ |
DEFINE_TRACE(PaymentManager) { |
visitor->Trace(registration_); |
visitor->Trace(instruments_); |
@@ -47,4 +74,21 @@ void PaymentManager::OnServiceConnectionError() { |
manager_.reset(); |
} |
+void PaymentManager::OnPermissionRequestComplete( |
+ ScriptPromiseResolver* resolver, |
+ mojom::blink::PermissionStatus status) { |
+ switch (status) { |
+ case mojom::blink::PermissionStatus::GRANTED: |
+ return resolver->Resolve("granted"); |
+ case mojom::blink::PermissionStatus::DENIED: |
+ return resolver->Resolve("denied"); |
+ case mojom::blink::PermissionStatus::ASK: |
+ return resolver->Resolve("prompt"); |
+ } |
+} |
+ |
+void PaymentManager::OnPermissionServiceConnectionError() { |
+ permission_service_.reset(); |
+} |
+ |
} // namespace blink |