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

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: Don't leak FeaturePolicy objects 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..7fda3d97d7be5851efb8419ea33f4aef7289860f 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
@@ -5,10 +5,12 @@
#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/LocalFrame.h"
#include "core/origin_trials/OriginTrialContext.h"
namespace blink {
@@ -25,13 +27,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();
dcheng 2016/10/24 19:16:45 This is probably a dumb question, but what is exec
iclelland 2016/10/25 18:34:33 executingFrame() can also return the frame of the
+
+ 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 +82,19 @@ void installConditionalFeatures(const WrapperTypeInfo* type,
interfaceObject);
}
+bool isFeatureEnabledInFrame(const FeaturePolicy::Feature* feature,
+ const LocalFrame* frame) {
+ // If there is no frame, or if feature policy is disabled, use defaults.
+ bool enabledByDefault =
+ (feature->defaultPolicy != FeaturePolicy::FeatureDefault::DisableForAll);
+ if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame)
+ return enabledByDefault;
+ FeaturePolicy* featurePolicy = frame->getFeaturePolicy();
+ if (!featurePolicy)
+ return enabledByDefault;
+
+ // Otherwise, check policy.
+ return featurePolicy->isFeatureEnabled(feature);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698