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

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: Addressing nits Created 4 years, 1 month 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..176f034533f668ed0633c0f38369f249f79312bd 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();
+
+ 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
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.h ('k') | third_party/WebKit/Source/core/dom/Document.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698