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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp

Issue 2254533002: [FeaturePolicy] Initial implementation of Feature Policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fp-flag
Patch Set: Clean up; add remaining policy-controlled features Created 4 years, 2 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/bindings/core/v8/ConditionalFeatures.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
index 3929759df25e58c445070c7e2ccebb37abb477e4..29bc44d04fd7a8a8d4740b83bed42d8543ca6bb8 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
@@ -5,11 +5,15 @@
#include "bindings/core/v8/ConditionalFeatures.h"
#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/V8Document.h"
#include "bindings/core/v8/V8HTMLLinkElement.h"
#include "bindings/core/v8/V8Navigator.h"
#include "bindings/core/v8/V8Window.h"
#include "core/dom/ExecutionContext.h"
+#include "core/frame/Frame.h"
+#include "core/frame/LocalFrame.h"
#include "core/origin_trials/OriginTrialContext.h"
+#include "platform/feature_policy/FeaturePolicy.h"
namespace blink {
@@ -25,13 +29,35 @@ void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo,
return;
OriginTrialContext* originTrialContext = OriginTrialContext::from(
executionContext, OriginTrialContext::DontCreateIfNotExists);
+ v8::Isolate* isolate = scriptState->isolate();
+ const DOMWrapperWorld& world = scriptState->world();
if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) {
if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() ||
(originTrialContext &&
originTrialContext->isTrialEnabled("ForeignFetch"))) {
V8HTMLLinkElement::installLinkServiceWorker(
- scriptState->isolate(), scriptState->world(), v8::Local<v8::Object>(),
- prototypeObject, interfaceObject);
+ isolate, world, v8::Local<v8::Object>(), prototypeObject,
+ interfaceObject);
+ }
+ }
+
+ // Install feature-policy-controlled features
+ LocalFrame* frame = nullptr;
+ if (executionContext->isDocument())
+ frame = toDocument(executionContext)->executingFrame();
+
+ if (wrapperTypeInfo == &V8Document::wrapperTypeInfo) {
+ if (isFeatureEnabledInFrame(&blink::kDocumentCookie, frame)) {
+ V8Document::installDocumentCookie(isolate, world, v8::Local<v8::Object>(),
+ prototypeObject, interfaceObject);
+ }
+ if (isFeatureEnabledInFrame(&blink::kDocumentDomain, frame)) {
+ V8Document::installDocumentDomain(isolate, world, v8::Local<v8::Object>(),
+ prototypeObject, interfaceObject);
+ }
+ if (isFeatureEnabledInFrame(&blink::kDocumentWrite, frame)) {
+ V8Document::installDocumentWrite(isolate, world, v8::Local<v8::Object>(),
+ prototypeObject, interfaceObject);
}
}
}
@@ -58,4 +84,20 @@ void installConditionalFeatures(const WrapperTypeInfo* type,
interfaceObject);
}
+bool isFeatureEnabledInFrame(const FeaturePolicyFeature* feature,
+ const Frame* frame) {
+ // If there is no frame, or if feature policy is disabled, use defaults
raymes 2016/10/18 02:42:30 nit: "." at end of sentence
iclelland 2016/10/19 12:51:55 Done.
+ bool enabledByDefault =
+ (feature->defaultPolicy != kDisableFeatureForAllOrigins);
+ if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame)
+ return enabledByDefault;
+ FeaturePolicy* featurePolicy = frame->getFeaturePolicy();
+ if (!featurePolicy)
+ return enabledByDefault;
+
+ // Otherwise, check policy
raymes 2016/10/18 02:42:30 nit: same here.
iclelland 2016/10/19 12:51:55 Done.
+ return featurePolicy->isFeatureEnabledForOrigin(
raymes 2016/10/18 02:42:30 nit: couldn't this just be isFeatureEnabled?
iclelland 2016/10/19 12:51:55 Probably; we shouldn't ever be using a policy for
+ feature, frame->securityContext()->getSecurityOrigin());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698