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