OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ConditionalFeatures.h" | 5 #include "bindings/core/v8/ConditionalFeatures.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/V8Document.h" | 8 #include "bindings/core/v8/V8Document.h" |
9 #include "bindings/core/v8/V8HTMLLinkElement.h" | 9 #include "bindings/core/v8/V8HTMLLinkElement.h" |
10 #include "bindings/core/v8/V8Navigator.h" | 10 #include "bindings/core/v8/V8Navigator.h" |
11 #include "bindings/core/v8/V8Window.h" | 11 #include "bindings/core/v8/V8Window.h" |
12 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/Frame.h" |
14 #include "core/origin_trials/OriginTrials.h" | 14 #include "core/origin_trials/OriginTrials.h" |
15 #include "public/platform/Platform.h" | |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo, | 19 void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo, |
19 const ScriptState* scriptState, | 20 const ScriptState* scriptState, |
20 v8::Local<v8::Object> prototypeObject, | 21 v8::Local<v8::Object> prototypeObject, |
21 v8::Local<v8::Function> interfaceObject) { | 22 v8::Local<v8::Function> interfaceObject) { |
22 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 23 // TODO(iclelland): Generate all of this logic at compile-time, based on the |
23 // configuration of origin trial enabled attributes and interfaces in IDL | 24 // configuration of origin trial enabled attributes and interfaces in IDL |
24 // files. (crbug.com/615060) | 25 // files. (crbug.com/615060) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 void installPendingConditionalFeature(const String& feature, | 135 void installPendingConditionalFeature(const String& feature, |
135 const ScriptState* scriptState) { | 136 const ScriptState* scriptState) { |
136 DCHECK(scriptState); | 137 DCHECK(scriptState); |
137 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); | 138 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); |
138 DCHECK(scriptState->perContextData()); | 139 DCHECK(scriptState->perContextData()); |
139 DCHECK(scriptState->world().isMainWorld()); | 140 DCHECK(scriptState->world().isMainWorld()); |
140 | 141 |
141 (*s_installPendingConditionalFeatureFunction)(feature, scriptState); | 142 (*s_installPendingConditionalFeatureFunction)(feature, scriptState); |
142 } | 143 } |
143 | 144 |
144 bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, | 145 bool isFeatureEnabledInFrame(WebFeaturePolicyFeature feature, |
145 const LocalFrame* frame) { | 146 const Frame* frame) { |
146 // If there is no frame, or if feature policy is disabled, use defaults. | 147 SecurityOrigin* origin = nullptr; |
147 bool enabledByDefault = | 148 if (frame) |
148 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForAll || | 149 origin = frame->securityContext()->getSecurityOrigin(); |
149 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForSelf && | 150 |
150 !frame->isCrossOriginSubframe())); | 151 // TODO: Remove this check when FP ships. This sets the static policy for |
151 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) | 152 // fullscreen and vibrate to be allowed at the top-level, but not in cross- |
152 return enabledByDefault; | 153 // origin content. With FP enabled, this logic is centralized in the |
153 FeaturePolicy* featurePolicy = frame->securityContext()->getFeaturePolicy(); | 154 // FeaturePolicy class. |
155 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) { | |
raymes
2017/02/13 04:45:22
Currently the only callsites I see for this check
iclelland
2017/02/23 20:04:12
Agreed; most of this should be removed; when featu
| |
156 bool isSameOriginSubframe = | |
157 frame && | |
158 (frame->isMainFrame() || | |
159 origin->canAccess( | |
160 frame->tree().top()->securityContext()->getSecurityOrigin())); | |
161 return (isSameOriginSubframe || | |
raymes
2017/02/13 04:45:22
This might be a bit simpler to read as:
if (isSame
iclelland
2017/02/23 20:04:12
Done.
| |
162 !(feature == WebFeaturePolicyFeature::Fullscreen || | |
raymes
2017/02/13 04:45:22
Does this mean fullscreen won't work at all in a c
iclelland
2017/02/23 20:04:12
That edge case actually isn't ever hit -- it was a
| |
163 feature == WebFeaturePolicyFeature::Geolocation || | |
raymes
2017/02/13 04:45:22
Should geolocation be here?
iclelland
2017/02/23 20:04:12
It was just all of the features that had a default
| |
164 feature == WebFeaturePolicyFeature::Payment || | |
165 feature == WebFeaturePolicyFeature::Vibrate)); | |
166 } | |
167 WebFeaturePolicy* featurePolicy = | |
168 frame->securityContext()->getFeaturePolicy(); | |
154 // The policy should always be initialized before checking it to ensure we | 169 // The policy should always be initialized before checking it to ensure we |
155 // properly inherit the parent policy. | 170 // properly inherit the parent policy. |
156 DCHECK(featurePolicy); | 171 DCHECK(featurePolicy); |
157 | 172 |
158 // Otherwise, check policy. | 173 // Otherwise, check policy. |
159 return featurePolicy->isFeatureEnabled(feature); | 174 return Platform::current()->isFeatureEnabledByPolicy(featurePolicy, feature); |
160 } | 175 } |
161 | 176 |
162 } // namespace blink | 177 } // namespace blink |
OLD | NEW |