Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentManager.cpp

Issue 2946013002: PaymentHandler: Implement requestPermission().
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..fac0827503403e80df8364f853b5bb1cf6818775 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("default");
+ }
+}
+
+void PaymentManager::OnPermissionServiceConnectionError() {
+ permission_service_.reset();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698