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/V8HTMLLinkElement.h" | 9 #include "bindings/core/v8/V8HTMLLinkElement.h" |
9 #include "bindings/core/v8/V8Navigator.h" | 10 #include "bindings/core/v8/V8Navigator.h" |
10 #include "bindings/core/v8/V8Window.h" | 11 #include "bindings/core/v8/V8Window.h" |
11 #include "core/dom/ExecutionContext.h" | 12 #include "core/dom/ExecutionContext.h" |
13 #include "core/frame/Frame.h" | |
14 #include "core/frame/LocalFrame.h" | |
12 #include "core/origin_trials/OriginTrialContext.h" | 15 #include "core/origin_trials/OriginTrialContext.h" |
16 #include "platform/feature_policy/FeaturePolicy.h" | |
13 | 17 |
14 namespace blink { | 18 namespace blink { |
15 | 19 |
16 void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo, | 20 void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo, |
17 const ScriptState* scriptState, | 21 const ScriptState* scriptState, |
18 v8::Local<v8::Object> prototypeObject, | 22 v8::Local<v8::Object> prototypeObject, |
19 v8::Local<v8::Function> interfaceObject) { | 23 v8::Local<v8::Function> interfaceObject) { |
20 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 24 // TODO(iclelland): Generate all of this logic at compile-time, based on the |
21 // configuration of origin trial enabled attibutes and interfaces in IDL | 25 // configuration of origin trial enabled attibutes and interfaces in IDL |
22 // files. (crbug.com/615060) | 26 // files. (crbug.com/615060) |
23 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 27 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
24 if (!executionContext) | 28 if (!executionContext) |
25 return; | 29 return; |
26 OriginTrialContext* originTrialContext = OriginTrialContext::from( | 30 OriginTrialContext* originTrialContext = OriginTrialContext::from( |
27 executionContext, OriginTrialContext::DontCreateIfNotExists); | 31 executionContext, OriginTrialContext::DontCreateIfNotExists); |
32 v8::Isolate* isolate = scriptState->isolate(); | |
33 const DOMWrapperWorld& world = scriptState->world(); | |
28 if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) { | 34 if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) { |
29 if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() || | 35 if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() || |
30 (originTrialContext && | 36 (originTrialContext && |
31 originTrialContext->isTrialEnabled("ForeignFetch"))) { | 37 originTrialContext->isTrialEnabled("ForeignFetch"))) { |
32 V8HTMLLinkElement::installLinkServiceWorker( | 38 V8HTMLLinkElement::installLinkServiceWorker( |
33 scriptState->isolate(), scriptState->world(), v8::Local<v8::Object>(), | 39 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
34 prototypeObject, interfaceObject); | 40 interfaceObject); |
41 } | |
42 } | |
43 | |
44 // Install feature-policy-controlled features | |
45 LocalFrame* frame = nullptr; | |
46 if (executionContext->isDocument()) | |
47 frame = toDocument(executionContext)->executingFrame(); | |
48 | |
49 if (wrapperTypeInfo == &V8Document::wrapperTypeInfo) { | |
50 if (isFeatureEnabledInFrame(&blink::kDocumentCookie, frame)) { | |
51 V8Document::installDocumentCookie(isolate, world, v8::Local<v8::Object>(), | |
52 prototypeObject, interfaceObject); | |
53 } | |
54 if (isFeatureEnabledInFrame(&blink::kDocumentDomain, frame)) { | |
55 V8Document::installDocumentDomain(isolate, world, v8::Local<v8::Object>(), | |
56 prototypeObject, interfaceObject); | |
57 } | |
58 if (isFeatureEnabledInFrame(&blink::kDocumentWrite, frame)) { | |
59 V8Document::installDocumentWrite(isolate, world, v8::Local<v8::Object>(), | |
60 prototypeObject, interfaceObject); | |
35 } | 61 } |
36 } | 62 } |
37 } | 63 } |
38 | 64 |
39 namespace { | 65 namespace { |
40 | 66 |
41 InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = | 67 InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = |
42 &installConditionalFeaturesCore; | 68 &installConditionalFeaturesCore; |
43 } | 69 } |
44 | 70 |
45 InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( | 71 InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
46 InstallConditionalFeaturesFunction newInstallConditionalFeaturesFunction) { | 72 InstallConditionalFeaturesFunction newInstallConditionalFeaturesFunction) { |
47 InstallConditionalFeaturesFunction originalFunction = | 73 InstallConditionalFeaturesFunction originalFunction = |
48 s_installConditionalFeaturesFunction; | 74 s_installConditionalFeaturesFunction; |
49 s_installConditionalFeaturesFunction = newInstallConditionalFeaturesFunction; | 75 s_installConditionalFeaturesFunction = newInstallConditionalFeaturesFunction; |
50 return originalFunction; | 76 return originalFunction; |
51 } | 77 } |
52 | 78 |
53 void installConditionalFeatures(const WrapperTypeInfo* type, | 79 void installConditionalFeatures(const WrapperTypeInfo* type, |
54 const ScriptState* scriptState, | 80 const ScriptState* scriptState, |
55 v8::Local<v8::Object> prototypeObject, | 81 v8::Local<v8::Object> prototypeObject, |
56 v8::Local<v8::Function> interfaceObject) { | 82 v8::Local<v8::Function> interfaceObject) { |
57 (*s_installConditionalFeaturesFunction)(type, scriptState, prototypeObject, | 83 (*s_installConditionalFeaturesFunction)(type, scriptState, prototypeObject, |
58 interfaceObject); | 84 interfaceObject); |
59 } | 85 } |
60 | 86 |
87 bool isFeatureEnabledInFrame(const FeaturePolicyFeature* feature, | |
88 const Frame* frame) { | |
89 // If there is no frame, or if feature policy is disabled, use defaults | |
raymes
2016/10/18 02:42:30
nit: "." at end of sentence
iclelland
2016/10/19 12:51:55
Done.
| |
90 bool enabledByDefault = | |
91 (feature->defaultPolicy != kDisableFeatureForAllOrigins); | |
92 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) | |
93 return enabledByDefault; | |
94 FeaturePolicy* featurePolicy = frame->getFeaturePolicy(); | |
95 if (!featurePolicy) | |
96 return enabledByDefault; | |
97 | |
98 // Otherwise, check policy | |
raymes
2016/10/18 02:42:30
nit: same here.
iclelland
2016/10/19 12:51:55
Done.
| |
99 return featurePolicy->isFeatureEnabledForOrigin( | |
raymes
2016/10/18 02:42:30
nit: couldn't this just be isFeatureEnabled?
iclelland
2016/10/19 12:51:55
Probably; we shouldn't ever be using a policy for
| |
100 feature, frame->securityContext()->getSecurityOrigin()); | |
101 } | |
102 | |
61 } // namespace blink | 103 } // namespace blink |
OLD | NEW |