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 InstallPendingConditionalFeatureFunction |
| 33 s_originalInstallPendingConditionalFeatureFunction = nullptr; |
32 } | 34 } |
33 | 35 |
34 void installConditionalFeaturesForModules( | 36 void installConditionalFeaturesForModules( |
35 const WrapperTypeInfo* wrapperTypeInfo, | 37 const WrapperTypeInfo* wrapperTypeInfo, |
36 const ScriptState* scriptState, | 38 const ScriptState* scriptState, |
37 v8::Local<v8::Object> prototypeObject, | 39 v8::Local<v8::Object> prototypeObject, |
38 v8::Local<v8::Function> interfaceObject) { | 40 v8::Local<v8::Function> interfaceObject) { |
39 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 41 // TODO(iclelland): Generate all of this logic at compile-time, based on the |
40 // configuration of origin trial enabled attibutes and interfaces in IDL | 42 // configuration of origin trial enabled attibutes and interfaces in IDL |
41 // files. (crbug.com/615060) | 43 // files. (crbug.com/615060) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 135 } |
134 } else if (wrapperTypeInfo == &V8GamepadButton::wrapperTypeInfo) { | 136 } else if (wrapperTypeInfo == &V8GamepadButton::wrapperTypeInfo) { |
135 if (OriginTrials::gamepadExtensionsEnabled(executionContext)) { | 137 if (OriginTrials::gamepadExtensionsEnabled(executionContext)) { |
136 V8GamepadButton::installGamepadExtensions( | 138 V8GamepadButton::installGamepadExtensions( |
137 isolate, world, v8::Local<v8::Object>(), prototypeObject, | 139 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
138 interfaceObject); | 140 interfaceObject); |
139 } | 141 } |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
| 145 void installPendingConditionalFeatureForModules( |
| 146 const String& feature, |
| 147 const ScriptState* scriptState) { |
| 148 // TODO(iclelland): Generate all of this logic at compile-time, based on the |
| 149 // configuration of origin trial enabled attributes and interfaces in IDL |
| 150 // files. (crbug.com/615060) |
| 151 (*s_originalInstallPendingConditionalFeatureFunction)(feature, scriptState); |
| 152 v8::Local<v8::Object> globalInstanceObject; |
| 153 v8::Local<v8::Object> prototypeObject; |
| 154 v8::Local<v8::Function> interfaceObject; |
| 155 v8::Isolate* isolate = scriptState->isolate(); |
| 156 const DOMWrapperWorld& world = scriptState->world(); |
| 157 V8PerContextData* contextData = scriptState->perContextData(); |
| 158 if (feature == "ForeignFetch") { |
| 159 if (contextData->getExistingConstructorAndPrototypeForType( |
| 160 &V8InstallEvent::wrapperTypeInfo, &prototypeObject, |
| 161 &interfaceObject)) { |
| 162 V8InstallEvent::installForeignFetch(isolate, world, |
| 163 v8::Local<v8::Object>(), |
| 164 prototypeObject, interfaceObject); |
| 165 } |
| 166 return; |
| 167 } |
| 168 if (feature == "ImageCapture") { |
| 169 globalInstanceObject = scriptState->context()->Global(); |
| 170 V8WindowPartial::installImageCapture(isolate, world, globalInstanceObject, |
| 171 v8::Local<v8::Object>(), |
| 172 v8::Local<v8::Function>()); |
| 173 return; |
| 174 } |
| 175 if (feature == "ServiceWorkerNavigationPreload") { |
| 176 globalInstanceObject = scriptState->context()->Global(); |
| 177 V8WindowPartial::installServiceWorkerNavigationPreload( |
| 178 isolate, world, globalInstanceObject, v8::Local<v8::Object>(), |
| 179 v8::Local<v8::Function>()); |
| 180 if (contextData->getExistingConstructorAndPrototypeForType( |
| 181 &V8FetchEvent::wrapperTypeInfo, &prototypeObject, |
| 182 &interfaceObject)) { |
| 183 V8FetchEvent::installServiceWorkerNavigationPreload( |
| 184 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
| 185 interfaceObject); |
| 186 } |
| 187 if (contextData->getExistingConstructorAndPrototypeForType( |
| 188 &V8ServiceWorkerRegistration::wrapperTypeInfo, &prototypeObject, |
| 189 &interfaceObject)) { |
| 190 V8ServiceWorkerRegistration::installServiceWorkerNavigationPreload( |
| 191 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
| 192 interfaceObject); |
| 193 } |
| 194 return; |
| 195 } |
| 196 if (feature == "WebShare") { |
| 197 if (contextData->getExistingConstructorAndPrototypeForType( |
| 198 &V8Navigator::wrapperTypeInfo, &prototypeObject, |
| 199 &interfaceObject)) { |
| 200 V8NavigatorPartial::installWebShare(isolate, world, |
| 201 v8::Local<v8::Object>(), |
| 202 prototypeObject, interfaceObject); |
| 203 } |
| 204 return; |
| 205 } |
| 206 if (feature == "WebUSB2") { |
| 207 globalInstanceObject = scriptState->context()->Global(); |
| 208 V8WindowPartial::installWebUSB(isolate, world, globalInstanceObject, |
| 209 v8::Local<v8::Object>(), |
| 210 v8::Local<v8::Function>()); |
| 211 if (contextData->getExistingConstructorAndPrototypeForType( |
| 212 &V8Navigator::wrapperTypeInfo, &prototypeObject, |
| 213 &interfaceObject)) { |
| 214 V8NavigatorPartial::installWebUSB(isolate, world, v8::Local<v8::Object>(), |
| 215 prototypeObject, interfaceObject); |
| 216 } |
| 217 return; |
| 218 } |
| 219 if (feature == "WebVR") { |
| 220 globalInstanceObject = scriptState->context()->Global(); |
| 221 V8WindowPartial::installGamepadExtensions( |
| 222 isolate, world, globalInstanceObject, v8::Local<v8::Object>(), |
| 223 v8::Local<v8::Function>()); |
| 224 V8WindowPartial::installWebVR(isolate, world, globalInstanceObject, |
| 225 v8::Local<v8::Object>(), |
| 226 v8::Local<v8::Function>()); |
| 227 if (contextData->getExistingConstructorAndPrototypeForType( |
| 228 &V8Gamepad::wrapperTypeInfo, &prototypeObject, &interfaceObject)) { |
| 229 V8Gamepad::installGamepadExtensions(isolate, world, |
| 230 v8::Local<v8::Object>(), |
| 231 prototypeObject, interfaceObject); |
| 232 } |
| 233 if (contextData->getExistingConstructorAndPrototypeForType( |
| 234 &V8GamepadButton::wrapperTypeInfo, &prototypeObject, |
| 235 &interfaceObject)) { |
| 236 V8GamepadButton::installGamepadExtensions( |
| 237 isolate, world, v8::Local<v8::Object>(), prototypeObject, |
| 238 interfaceObject); |
| 239 } |
| 240 if (contextData->getExistingConstructorAndPrototypeForType( |
| 241 &V8Navigator::wrapperTypeInfo, &prototypeObject, |
| 242 &interfaceObject)) { |
| 243 V8NavigatorPartial::installWebVR(isolate, world, v8::Local<v8::Object>(), |
| 244 prototypeObject, interfaceObject); |
| 245 } |
| 246 return; |
| 247 } |
| 248 } |
| 249 |
143 void registerInstallConditionalFeaturesForModules() { | 250 void registerInstallConditionalFeaturesForModules() { |
144 s_originalInstallConditionalFeaturesFunction = | 251 s_originalInstallConditionalFeaturesFunction = |
145 setInstallConditionalFeaturesFunction( | 252 setInstallConditionalFeaturesFunction( |
146 &installConditionalFeaturesForModules); | 253 &installConditionalFeaturesForModules); |
| 254 s_originalInstallPendingConditionalFeatureFunction = |
| 255 setInstallPendingConditionalFeatureFunction( |
| 256 &installPendingConditionalFeatureForModules); |
147 } | 257 } |
148 | 258 |
149 } // namespace blink | 259 } // namespace blink |
OLD | NEW |