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