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/modules/v8/ConditionalFeaturesForModules.h" | 5 #include "bindings/modules/v8/ConditionalFeaturesForModules.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" | 8 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" |
9 #include "bindings/core/v8/V8Navigator.h" | 9 #include "bindings/core/v8/V8Navigator.h" |
10 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" | 10 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "bindings/modules/v8/V8WindowPartial.h" | 22 #include "bindings/modules/v8/V8WindowPartial.h" |
23 #include "bindings/modules/v8/V8WorkerNavigatorPartial.h" | 23 #include "bindings/modules/v8/V8WorkerNavigatorPartial.h" |
24 #include "core/dom/ExecutionContext.h" | 24 #include "core/dom/ExecutionContext.h" |
25 #include "core/origin_trials/OriginTrials.h" | 25 #include "core/origin_trials/OriginTrials.h" |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 namespace { | 29 namespace { |
30 InstallConditionalFeaturesFunction | 30 InstallConditionalFeaturesFunction |
31 s_originalInstallConditionalFeaturesFunction = nullptr; | 31 s_originalInstallConditionalFeaturesFunction = nullptr; |
32 InstallConditionalFeaturesIfNeededFunction | |
33 s_originalInstallConditionalFeaturesIfNeededFunction = nullptr; | |
34 GetAffectedTypesForConditionalFeatureFunction | |
35 s_originalGetAffectedTypesForConditionalFeatureFunction = nullptr; | |
32 } | 36 } |
33 | 37 |
34 void installConditionalFeaturesForModules( | 38 void installConditionalFeaturesForModules( |
35 const WrapperTypeInfo* wrapperTypeInfo, | 39 const WrapperTypeInfo* wrapperTypeInfo, |
36 const ScriptState* scriptState, | 40 const ScriptState* scriptState, |
37 v8::Local<v8::Object> prototypeObject, | 41 v8::Local<v8::Object> prototypeObject, |
38 v8::Local<v8::Function> interfaceObject) { | 42 v8::Local<v8::Function> interfaceObject) { |
39 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 43 // TODO(iclelland): Generate all of this logic at compile-time, based on the |
40 // configuration of origin trial enabled attibutes and interfaces in IDL | 44 // configuration of origin trial enabled attibutes and interfaces in IDL |
41 // files. (crbug.com/615060) | 45 // files. (crbug.com/615060) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 137 } |
134 } else if (wrapperTypeInfo == &V8GamepadButton::wrapperTypeInfo) { | 138 } else if (wrapperTypeInfo == &V8GamepadButton::wrapperTypeInfo) { |
135 if (OriginTrials::gamepadExtensionsEnabled(executionContext)) { | 139 if (OriginTrials::gamepadExtensionsEnabled(executionContext)) { |
136 V8GamepadButton::installGamepadExtensions( | 140 V8GamepadButton::installGamepadExtensions( |
137 isolate, world, v8::Local<v8::Object>(), prototypeObject, | 141 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
138 interfaceObject); | 142 interfaceObject); |
139 } | 143 } |
140 } | 144 } |
141 } | 145 } |
142 | 146 |
147 bool installConditionalFeaturesIfNeededForModules( | |
148 const WrapperTypeInfo* wrapperTypeInfo, | |
149 const ScriptState* scriptState) { | |
150 (*s_originalInstallConditionalFeaturesIfNeededFunction)(wrapperTypeInfo, | |
151 scriptState); | |
152 | |
153 // Only install features here, if the target type has an existing instance | |
iclelland
2017/01/20 14:31:19
I think rather than instance, you mean prototype/c
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
| |
154 V8PerContextData* contextData = scriptState->perContextData(); | |
155 if (wrapperTypeInfo == &V8Navigator::wrapperTypeInfo) { | |
156 v8::Local<v8::Function> interfaceObject = | |
157 contextData->constructorForTypeFromCache(wrapperTypeInfo); | |
158 if (interfaceObject.IsEmpty()) { | |
159 LOG(INFO) << "No existing instance for type: " | |
160 << wrapperTypeInfo->interfaceName; | |
161 return true; | |
162 } | |
163 LOG(INFO) << "Found existing instance for type: " | |
164 << wrapperTypeInfo->interfaceName; | |
165 v8::Local<v8::Object> prototypeObject = | |
166 contextData->prototypeForType(wrapperTypeInfo); | |
167 | |
168 installConditionalFeaturesForModules(wrapperTypeInfo, scriptState, | |
169 prototypeObject, interfaceObject); | |
170 return true; | |
171 } | |
172 return false; | |
173 } | |
174 | |
175 void getAffectedTypesForConditionalFeatureFunctionForModules( | |
176 const String& feature, | |
177 HashSet<const WrapperTypeInfo*>* affectedTypes) { | |
178 (*s_originalGetAffectedTypesForConditionalFeatureFunction)(feature, | |
179 affectedTypes); | |
180 if (feature == "ServiceWorkerNavigationPreload") { | |
iclelland
2017/01/20 14:31:19
Is this method eventually intended to cover all of
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
| |
181 // affectedTypes->add(&V8Navigator::wrapperTypeInfo); | |
182 affectedTypes->add(&V8Window::wrapperTypeInfo); | |
183 return; | |
184 } | |
185 if (feature == "WebUSB") { | |
186 affectedTypes->add(&V8Navigator::wrapperTypeInfo); | |
187 affectedTypes->add(&V8Window::wrapperTypeInfo); | |
188 return; | |
189 } | |
190 } | |
191 | |
143 void registerInstallConditionalFeaturesForModules() { | 192 void registerInstallConditionalFeaturesForModules() { |
144 s_originalInstallConditionalFeaturesFunction = | 193 s_originalInstallConditionalFeaturesFunction = |
145 setInstallConditionalFeaturesFunction( | 194 setInstallConditionalFeaturesFunction( |
146 &installConditionalFeaturesForModules); | 195 &installConditionalFeaturesForModules); |
196 s_originalInstallConditionalFeaturesIfNeededFunction = | |
197 setInstallConditionalFeaturesIfNeededFunction( | |
198 &installConditionalFeaturesIfNeededForModules); | |
199 s_originalGetAffectedTypesForConditionalFeatureFunction = | |
200 setGetAffectedTypesForConditionalFeatureFunction( | |
201 &getAffectedTypesForConditionalFeatureFunctionForModules); | |
147 } | 202 } |
148 | 203 |
149 } // namespace blink | 204 } // namespace blink |
OLD | NEW |