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 |