Chromium Code Reviews| 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/LocalFrame.h" |
| 14 #include "core/origin_trials/OriginTrialContext.h" | 14 #include "core/origin_trials/OriginTrialContext.h" |
| 15 #include "core/origin_trials/OriginTrials.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) |
| 25 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 26 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 26 if (!executionContext) | 27 if (!executionContext) |
| 27 return; | 28 return; |
| 28 OriginTrialContext* originTrialContext = OriginTrialContext::from( | |
| 29 executionContext, OriginTrialContext::DontCreateIfNotExists); | |
| 30 v8::Isolate* isolate = scriptState->isolate(); | 29 v8::Isolate* isolate = scriptState->isolate(); |
| 31 const DOMWrapperWorld& world = scriptState->world(); | 30 const DOMWrapperWorld& world = scriptState->world(); |
| 32 if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) { | 31 if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) { |
| 33 if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() || | 32 if (OriginTrials::linkServiceWorkerEnabled(executionContext)) { |
| 34 (originTrialContext && | |
| 35 originTrialContext->isTrialEnabled("ForeignFetch"))) { | |
| 36 V8HTMLLinkElement::installLinkServiceWorker( | 33 V8HTMLLinkElement::installLinkServiceWorker( |
| 37 isolate, world, v8::Local<v8::Object>(), prototypeObject, | 34 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
| 38 interfaceObject); | 35 interfaceObject); |
| 39 } | 36 } |
| 40 } else if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) { | 37 } else if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) { |
| 41 v8::Local<v8::Object> instanceObject = scriptState->context()->Global(); | 38 v8::Local<v8::Object> instanceObject = scriptState->context()->Global(); |
| 42 if (RuntimeEnabledFeatures::longTaskObserverEnabled() || | 39 if (OriginTrials::longTaskObserverEnabled(executionContext)) { |
| 43 (originTrialContext && | |
| 44 originTrialContext->isTrialEnabled("LongTaskObserver"))) { | |
| 45 V8Window::installLongTaskObserver(isolate, world, instanceObject, | 40 V8Window::installLongTaskObserver(isolate, world, instanceObject, |
| 46 prototypeObject, interfaceObject); | 41 prototypeObject, interfaceObject); |
| 47 } | 42 } |
| 48 } else if (wrapperTypeInfo == &V8Document::wrapperTypeInfo) { | 43 } else if (wrapperTypeInfo == &V8Document::wrapperTypeInfo) { |
| 49 if (RuntimeEnabledFeatures::setRootScrollerEnabled() || | 44 if (OriginTrials::setRootScrollerEnabled(executionContext)) { |
| 50 (originTrialContext && | |
| 51 originTrialContext->isTrialEnabled("RootScroller"))) { | |
| 52 V8Document::installRootScroller(isolate, world, v8::Local<v8::Object>(), | 45 V8Document::installRootScroller(isolate, world, v8::Local<v8::Object>(), |
| 53 prototypeObject, interfaceObject); | 46 prototypeObject, interfaceObject); |
| 54 } | 47 } |
| 55 } | 48 } |
| 56 } | 49 } |
| 57 | 50 |
| 51 bool installConditionalFeaturesIfNeededCore( | |
| 52 const WrapperTypeInfo* wrapperTypeInfo, | |
| 53 const ScriptState* scriptState) { | |
| 54 if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) { | |
| 55 LOG(INFO) << "Just install, don't look for existing instance for type: " | |
|
iclelland
2017/01/20 14:31:19
Is this a debug message to be removed?
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
| |
| 56 << wrapperTypeInfo->interfaceName; | |
| 57 installConditionalFeatures(wrapperTypeInfo, scriptState, | |
|
iclelland
2017/01/20 14:31:19
V8Window is a global object, which is the one case
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
| |
| 58 v8::Local<v8::Object>(), | |
| 59 v8::Local<v8::Function>()); | |
| 60 return true; | |
| 61 } | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 void getAffectedTypesForConditionalFeatureCore( | |
|
iclelland
2017/01/20 14:31:19
Rather than modifying its input, could this return
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
| |
| 66 const String& feature, | |
| 67 HashSet<const WrapperTypeInfo*>* affectedTypes) { | |
| 68 if (feature == "LongTaskObserver") { | |
| 69 affectedTypes->add(&V8Window::wrapperTypeInfo); | |
| 70 return; | |
| 71 } | |
| 72 } | |
| 73 | |
| 58 namespace { | 74 namespace { |
| 59 | 75 |
| 60 InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = | 76 InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = |
| 61 &installConditionalFeaturesCore; | 77 &installConditionalFeaturesCore; |
| 78 | |
| 79 InstallConditionalFeaturesIfNeededFunction | |
| 80 s_installConditionalFeaturesIfNeededFunction = | |
| 81 &installConditionalFeaturesIfNeededCore; | |
| 82 | |
| 83 GetAffectedTypesForConditionalFeatureFunction | |
| 84 s_getAffectedTypesForConditionalFeatureFunction = | |
| 85 &getAffectedTypesForConditionalFeatureCore; | |
| 62 } | 86 } |
| 63 | 87 |
| 64 InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( | 88 InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
| 65 InstallConditionalFeaturesFunction newInstallConditionalFeaturesFunction) { | 89 InstallConditionalFeaturesFunction newInstallConditionalFeaturesFunction) { |
| 66 InstallConditionalFeaturesFunction originalFunction = | 90 InstallConditionalFeaturesFunction originalFunction = |
| 67 s_installConditionalFeaturesFunction; | 91 s_installConditionalFeaturesFunction; |
| 68 s_installConditionalFeaturesFunction = newInstallConditionalFeaturesFunction; | 92 s_installConditionalFeaturesFunction = newInstallConditionalFeaturesFunction; |
| 69 return originalFunction; | 93 return originalFunction; |
| 70 } | 94 } |
| 71 | 95 |
| 96 InstallConditionalFeaturesIfNeededFunction | |
| 97 setInstallConditionalFeaturesIfNeededFunction( | |
| 98 InstallConditionalFeaturesIfNeededFunction | |
| 99 newInstallConditionalFeaturesIfNeededFunction) { | |
| 100 InstallConditionalFeaturesIfNeededFunction originalFunction = | |
| 101 s_installConditionalFeaturesIfNeededFunction; | |
| 102 s_installConditionalFeaturesIfNeededFunction = | |
| 103 newInstallConditionalFeaturesIfNeededFunction; | |
| 104 return originalFunction; | |
| 105 } | |
| 106 | |
| 107 GetAffectedTypesForConditionalFeatureFunction | |
| 108 setGetAffectedTypesForConditionalFeatureFunction( | |
| 109 GetAffectedTypesForConditionalFeatureFunction | |
| 110 newGetAffectedTypesForConditionalFeatureFunction) { | |
| 111 GetAffectedTypesForConditionalFeatureFunction originalFunction = | |
| 112 s_getAffectedTypesForConditionalFeatureFunction; | |
| 113 s_getAffectedTypesForConditionalFeatureFunction = | |
| 114 newGetAffectedTypesForConditionalFeatureFunction; | |
| 115 return originalFunction; | |
| 116 } | |
| 117 | |
| 72 void installConditionalFeatures(const WrapperTypeInfo* type, | 118 void installConditionalFeatures(const WrapperTypeInfo* type, |
| 73 const ScriptState* scriptState, | 119 const ScriptState* scriptState, |
| 74 v8::Local<v8::Object> prototypeObject, | 120 v8::Local<v8::Object> prototypeObject, |
| 75 v8::Local<v8::Function> interfaceObject) { | 121 v8::Local<v8::Function> interfaceObject) { |
| 76 (*s_installConditionalFeaturesFunction)(type, scriptState, prototypeObject, | 122 (*s_installConditionalFeaturesFunction)(type, scriptState, prototypeObject, |
| 77 interfaceObject); | 123 interfaceObject); |
| 78 } | 124 } |
| 79 | 125 |
| 80 void installPendingConditionalFeaturesOnWindow(const ScriptState* scriptState) { | 126 void installPendingConditionalFeaturesOnWindow(const ScriptState* scriptState) { |
| 81 DCHECK(scriptState); | 127 DCHECK(scriptState); |
| 82 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); | 128 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); |
| 83 DCHECK(scriptState->perContextData()); | 129 DCHECK(scriptState->perContextData()); |
| 84 DCHECK(scriptState->world().isMainWorld()); | 130 DCHECK(scriptState->world().isMainWorld()); |
| 85 (*s_installConditionalFeaturesFunction)(&V8Window::wrapperTypeInfo, | 131 (*s_installConditionalFeaturesFunction)(&V8Window::wrapperTypeInfo, |
| 86 scriptState, v8::Local<v8::Object>(), | 132 scriptState, v8::Local<v8::Object>(), |
| 87 v8::Local<v8::Function>()); | 133 v8::Local<v8::Function>()); |
| 88 } | 134 } |
| 89 | 135 |
| 136 bool installPendingConditionalFeature(const ScriptState* scriptState, | |
| 137 const String& feature) { | |
| 138 DCHECK(scriptState); | |
| 139 DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); | |
| 140 DCHECK(scriptState->perContextData()); | |
| 141 DCHECK(scriptState->world().isMainWorld()); | |
| 142 | |
| 143 // TODO(chasej): Make the installation of features more granular, rather | |
| 144 // than attempting to install all features per type | |
| 145 HashSet<const WrapperTypeInfo*> affectedTypes; | |
| 146 LOG(INFO) << "Install pending feature: " << feature; | |
|
iclelland
2017/01/20 14:31:19
Debug, right?
chasej
2017/01/25 19:58:20
Removed (along with this method being rewritten).
| |
| 147 (*s_getAffectedTypesForConditionalFeatureFunction)(feature, &affectedTypes); | |
| 148 | |
| 149 bool allInstalled = true; | |
| 150 for (auto type : affectedTypes) { | |
| 151 LOG(INFO) << "Install on affected type: " << type->interfaceName; | |
| 152 if (!((*s_installConditionalFeaturesIfNeededFunction)(type, scriptState))) | |
| 153 allInstalled = false; | |
| 154 } | |
| 155 | |
| 156 return allInstalled; | |
| 157 } | |
| 158 | |
| 90 bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, | 159 bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, |
| 91 const LocalFrame* frame) { | 160 const LocalFrame* frame) { |
| 92 // If there is no frame, or if feature policy is disabled, use defaults. | 161 // If there is no frame, or if feature policy is disabled, use defaults. |
| 93 bool enabledByDefault = | 162 bool enabledByDefault = |
| 94 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForAll || | 163 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForAll || |
| 95 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForSelf && | 164 (feature.defaultPolicy == FeaturePolicy::FeatureDefault::EnableForSelf && |
| 96 !frame->isCrossOriginSubframe())); | 165 !frame->isCrossOriginSubframe())); |
| 97 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) | 166 if (!RuntimeEnabledFeatures::featurePolicyEnabled() || !frame) |
| 98 return enabledByDefault; | 167 return enabledByDefault; |
| 99 FeaturePolicy* featurePolicy = frame->securityContext()->getFeaturePolicy(); | 168 FeaturePolicy* featurePolicy = frame->securityContext()->getFeaturePolicy(); |
| 100 // 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 |
| 101 // properly inherit the parent policy. | 170 // properly inherit the parent policy. |
| 102 DCHECK(featurePolicy); | 171 DCHECK(featurePolicy); |
| 103 | 172 |
| 104 // Otherwise, check policy. | 173 // Otherwise, check policy. |
| 105 return featurePolicy->isFeatureEnabled(feature); | 174 return featurePolicy->isFeatureEnabled(feature); |
| 106 } | 175 } |
| 107 | 176 |
| 108 } // namespace blink | 177 } // namespace blink |
| OLD | NEW |