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

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: Remove overaggressive bool transform Created 4 years, 3 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
new file mode 100644
index 0000000000000000000000000000000000000000..e993c8cd67326b11faba36aff06eba139d1e22e2
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp
@@ -0,0 +1,56 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "bindings/core/v8/ConditionalFeatures.h"
+
+#include "bindings/core/v8/ScriptController.h"
+#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/WindowProxy.h"
+#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
+#include "core/dom/Document.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/frame/LocalFrame.h"
+#include "core/workers/WorkerGlobalScope.h"
+#include "platform/feature_policy/FeaturePolicy.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+void initializeConditionalFeatures(ExecutionContext* context)
+{
+ if (context->isDocument()) {
+ LocalFrame* frame = toDocument(context)->frame();
+ if (!frame)
+ return;
+ ScriptState* state = ScriptState::forMainWorld(frame);
+ if (!state)
+ return;
+ if (!frame->script().windowProxy(state->world())->isContextInitialized())
+ return;
+ v8::HandleScope handleScope(state->isolate());
+ installOriginTrials(state);
+ } else if (context->isWorkerGlobalScope()) {
+ WorkerOrWorkletScriptController* scriptController = toWorkerGlobalScope(context)->scriptController();
+ if (!scriptController)
+ return;
+ ScriptState* state = scriptController->getScriptState();
+ if (!state)
+ return;
+ if (!scriptController->isContextInitialized())
+ return;
+ v8::HandleScope handleScope(state->isolate());
+ installOriginTrials(state);
+ }
+}
+
+bool isFeatureEnabledInFrame(const FeaturePolicyFeature* feature, const Frame* frame)
+{
+ if (!frame)
+ return FeaturePolicy::isFeatureEnabledByDefault(feature, true);
+ FeaturePolicy* featurePolicy = frame->getFeaturePolicy();
+ if (!featurePolicy)
+ return FeaturePolicy::isFeatureEnabledByDefault(feature, frame->isMainFrame());
+ return featurePolicy->isFeatureEnabledForOrigin(feature, frame->securityContext()->getSecurityOrigin());
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698