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

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

Issue 2618383002: Initial implementation for feature policy - PaymentRequest (Closed)
Patch Set: Codereivew: made assert_unreached Error message more explicit in payment-disabled.php test Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/LayoutTests/virtual/feature-policy/http/tests/feature-policy/payment-enabledforself-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
index 2335412fc98595133f3ab7ad184b89a9c663862d..4a130d513c4e58577ce7d6a6bb5c6a6b48d8c08f 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp
@@ -4,6 +4,7 @@
#include "modules/payments/PaymentRequest.h"
+#include "bindings/core/v8/ConditionalFeatures.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
@@ -559,19 +560,54 @@ bool allowedToUsePaymentRequest(const Frame* frame) {
if (!frame)
return false;
- // 2. If |document|'s browsing context is a top-level browsing context, then
- // return true.
- if (frame->isMainFrame())
+ if (!RuntimeEnabledFeatures::featurePolicyEnabled()) {
+ // 2. If |document|'s browsing context is a top-level browsing context, then
+ // return true.
+ if (frame->isMainFrame())
+ return true;
+
+ // 3. If |document|'s browsing context has a browsing context container that
+ // is an iframe element with an |allowpaymentrequest| attribute specified,
+ // and whose node document is allowed to use the feature indicated by
+ // |allowpaymentrequest|, then return true.
+ if (frame->owner() && frame->owner()->allowPaymentRequest())
+ return allowedToUsePaymentRequest(frame->tree().parent());
+
+ // 4. Return false.
+ return false;
+ }
+
+ // If Feature Policy is enabled. then we need this hack to support it, until
+ // we have proper support for <iframe allowfullscreen> in FP:
+ // TODO(lunalu): clean up the code once FP iframe is supported
+ // crbug.com/682280
+
+ // 1. If FP, by itself, enables paymentrequest in this document, then
+ // paymentrequest is allowed.
+ if (frame->securityContext()->getFeaturePolicy()->isFeatureEnabled(
+ kPaymentFeature)) {
return true;
+ }
- // 3. If |document|'s browsing context has a browsing context container that
- // is an iframe element with an |allowpaymentrequest| attribute specified, and
- // whose node document is allowed to use the feature indicated by
- // |allowpaymentrequest|, then return true.
- if (frame->owner() && frame->owner()->allowPaymentRequest())
- return allowedToUsePaymentRequest(frame->tree().parent());
+ // 2. Otherwise, if the embedding frame's document is allowed to use
+ // paymentrequest (either through FP or otherwise), and either:
+ // a) this is a same-origin embedded document, or
+ // b) this document's iframe has the allowpayment attribute set,
+ // then paymentrequest is allowed.
+ if (!frame->isMainFrame()) {
+ if (allowedToUsePaymentRequest(frame->tree().parent())) {
+ return (frame->owner() && frame->owner()->allowPaymentRequest()) ||
+ frame->tree()
+ .parent()
+ ->securityContext()
+ ->getSecurityOrigin()
+ ->isSameSchemeHostPortAndSuborigin(
+ frame->securityContext()->getSecurityOrigin());
+ }
+ }
- // 4. Return false.
+ // Otherwise, paymentrequest is not allowed. (If we reach here and this is
+ // the main frame, then paymentrequest must have been disabled by FP.)
return false;
}
« no previous file with comments | « third_party/WebKit/LayoutTests/virtual/feature-policy/http/tests/feature-policy/payment-enabledforself-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698