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

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

Issue 2880133002: PaymentHandler: Should not allow accessing PaymentManager in Extension.
Patch Set: PaymentHandler: Should not allow accessing PaymentManager in Extension. Created 3 years, 7 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/PaymentAppServiceWorkerRegistration.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentAppServiceWorkerRegistration.cpp b/third_party/WebKit/Source/modules/payments/PaymentAppServiceWorkerRegistration.cpp
index e8c3b7bae9441310de21a0791793174118a1bc8d..b9b2f3429e34202ef95c8769524f0c13664f709a 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentAppServiceWorkerRegistration.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentAppServiceWorkerRegistration.cpp
@@ -4,10 +4,14 @@
#include "modules/payments/PaymentAppServiceWorkerRegistration.h"
+#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/Document.h"
+#include "core/dom/ExecutionContext.h"
#include "modules/payments/PaymentManager.h"
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/bindings/ScriptState.h"
+#include "platform/weborigin/KURL.h"
+#include "platform/weborigin/SecurityOrigin.h"
namespace blink {
@@ -32,13 +36,27 @@ PaymentAppServiceWorkerRegistration& PaymentAppServiceWorkerRegistration::From(
// static
PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager(
ScriptState* script_state,
- ServiceWorkerRegistration& registration) {
+ ServiceWorkerRegistration& registration,
+ ExceptionState& exception_state) {
return PaymentAppServiceWorkerRegistration::From(registration)
- .paymentManager(script_state);
+ .paymentManager(script_state, exception_state);
}
PaymentManager* PaymentAppServiceWorkerRegistration::paymentManager(
- ScriptState* script_state) {
+ ScriptState* script_state,
+ ExceptionState& exception_state) {
+ ExecutionContext* context = ExecutionContext::From(script_state);
+ KURL origin = KURL(KURL(), context->GetSecurityOrigin()->ToString());
+
+ // The PaymentManager can be used only in SecureContext but we don't want to
+ // enable the feature in Extension side. So, we additionally need the follwing
+ // check whether the origin is HTTPS or not.
+ if (!origin.ProtocolIsInHTTPFamily()) {
+ exception_state.ThrowSecurityError(
+ "PaymentManger can be used only in HTTPS scheme.");
+ return nullptr;
+ }
+
if (!payment_manager_) {
payment_manager_ = PaymentManager::Create(registration_);
}

Powered by Google App Engine
This is Rietveld 408576698