| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ConditionalFeaturesForCore.h" | 5 #include "bindings/core/v8/ConditionalFeaturesForCore.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ConditionalFeatures.h" | 7 #include "bindings/core/v8/ConditionalFeatures.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/V8Document.h" | 9 #include "bindings/core/v8/V8Document.h" |
| 10 #include "bindings/core/v8/V8HTMLLinkElement.h" | 10 #include "bindings/core/v8/V8HTMLLinkElement.h" |
| 11 #include "bindings/core/v8/V8Navigator.h" | 11 #include "bindings/core/v8/V8Navigator.h" |
| 12 #include "bindings/core/v8/V8Window.h" | 12 #include "bindings/core/v8/V8Window.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/Frame.h" |
| 15 #include "core/origin_trials/OriginTrials.h" | 15 #include "core/origin_trials/OriginTrials.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 InstallConditionalFeaturesFunction s_oldInstallConditionalFeaturesFunction = | 20 InstallConditionalFeaturesFunction s_oldInstallConditionalFeaturesFunction = |
| 21 nullptr; | 21 nullptr; |
| 22 InstallPendingConditionalFeatureFunction | 22 InstallPendingConditionalFeatureFunction |
| 23 s_oldInstallPendingConditionalFeatureFunction = nullptr; | 23 s_oldInstallPendingConditionalFeatureFunction = nullptr; |
| 24 } | 24 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void installConditionalFeaturesOnWindow(const ScriptState* scriptState) { | 87 void installConditionalFeaturesOnWindow(const ScriptState* scriptState) { |
| 88 DCHECK(scriptState); | 88 DCHECK(scriptState); |
| 89 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); | 89 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); |
| 90 DCHECK(scriptState->perContextData()); | 90 DCHECK(scriptState->perContextData()); |
| 91 DCHECK(scriptState->world().isMainWorld()); | 91 DCHECK(scriptState->world().isMainWorld()); |
| 92 installConditionalFeatures(&V8Window::wrapperTypeInfo, scriptState, | 92 installConditionalFeatures(&V8Window::wrapperTypeInfo, scriptState, |
| 93 v8::Local<v8::Object>(), | 93 v8::Local<v8::Object>(), |
| 94 v8::Local<v8::Function>()); | 94 v8::Local<v8::Function>()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, | 97 bool isFeatureEnabledInFrame(WebFeaturePolicyFeature feature, |
| 98 const LocalFrame* frame) { | 98 const Frame* frame) { |
| 99 // If there is no frame, or if feature policy is disabled, use defaults. | 99 DCHECK(frame); |
| 100 bool enabledByDefault = | 100 WebFeaturePolicy* featurePolicy = |
| 101 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForAll || | 101 frame->securityContext()->getFeaturePolicy(); |
| 102 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForSelf && | |
| 103 !frame->isCrossOriginSubframe())); | |
| 104 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) | |
| 105 return enabledByDefault; | |
| 106 FeaturePolicy* featurePolicy = frame->securityContext()->getFeaturePolicy(); | |
| 107 // The policy should always be initialized before checking it to ensure we | 102 // The policy should always be initialized before checking it to ensure we |
| 108 // properly inherit the parent policy. | 103 // properly inherit the parent policy. |
| 109 DCHECK(featurePolicy); | 104 DCHECK(featurePolicy); |
| 110 | 105 |
| 111 // Otherwise, check policy. | 106 // Otherwise, check policy. |
| 112 return featurePolicy->isFeatureEnabled(feature); | 107 return featurePolicy->IsFeatureEnabled(feature); |
| 113 } | 108 } |
| 114 | 109 |
| 115 void registerInstallConditionalFeaturesForCore() { | 110 void registerInstallConditionalFeaturesForCore() { |
| 116 s_oldInstallConditionalFeaturesFunction = | 111 s_oldInstallConditionalFeaturesFunction = |
| 117 setInstallConditionalFeaturesFunction(&installConditionalFeaturesCore); | 112 setInstallConditionalFeaturesFunction(&installConditionalFeaturesCore); |
| 118 s_oldInstallPendingConditionalFeatureFunction = | 113 s_oldInstallPendingConditionalFeatureFunction = |
| 119 setInstallPendingConditionalFeatureFunction( | 114 setInstallPendingConditionalFeatureFunction( |
| 120 &installPendingConditionalFeatureCore); | 115 &installPendingConditionalFeatureCore); |
| 121 } | 116 } |
| 122 | 117 |
| 123 } // namespace blink | 118 } // namespace blink |
| OLD | NEW |