| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "bindings/modules/v8/ConditionalFeaturesForModules.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ConditionalFeaturesForCore.h" | |
| 8 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" | |
| 9 #include "bindings/core/v8/V8Navigator.h" | |
| 10 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" | |
| 11 #include "bindings/core/v8/V8Window.h" | |
| 12 #include "bindings/core/v8/V8WorkerNavigator.h" | |
| 13 #include "bindings/modules/v8/V8BudgetService.h" | |
| 14 #include "bindings/modules/v8/V8DedicatedWorkerGlobalScopePartial.h" | |
| 15 #include "bindings/modules/v8/V8Gamepad.h" | |
| 16 #include "bindings/modules/v8/V8GamepadButton.h" | |
| 17 #include "bindings/modules/v8/V8InstallEvent.h" | |
| 18 #include "bindings/modules/v8/V8NavigatorPartial.h" | |
| 19 #include "bindings/modules/v8/V8ServiceWorkerGlobalScope.h" | |
| 20 #include "bindings/modules/v8/V8SharedWorkerGlobalScopePartial.h" | |
| 21 #include "bindings/modules/v8/V8WindowPartial.h" | |
| 22 #include "bindings/modules/v8/V8WorkerNavigatorPartial.h" | |
| 23 #include "core/dom/ExecutionContext.h" | |
| 24 #include "core/origin_trials/OriginTrials.h" | |
| 25 #include "platform/bindings/ConditionalFeatures.h" | |
| 26 #include "platform/bindings/ScriptState.h" | |
| 27 | |
| 28 namespace blink { | |
| 29 | |
| 30 namespace { | |
| 31 InstallConditionalFeaturesFunction | |
| 32 g_original_install_conditional_features_function = nullptr; | |
| 33 InstallPendingConditionalFeatureFunction | |
| 34 g_original_install_pending_conditional_feature_function = nullptr; | |
| 35 } | |
| 36 | |
| 37 void InstallConditionalFeaturesForModules( | |
| 38 const WrapperTypeInfo* wrapper_type_info, | |
| 39 const ScriptState* script_state, | |
| 40 v8::Local<v8::Object> prototype_object, | |
| 41 v8::Local<v8::Function> interface_object) { | |
| 42 // TODO(iclelland): Generate all of this logic at compile-time, based on the | |
| 43 // configuration of origin trial enabled attibutes and interfaces in IDL | |
| 44 // files. (crbug.com/615060) | |
| 45 (*g_original_install_conditional_features_function)( | |
| 46 wrapper_type_info, script_state, prototype_object, interface_object); | |
| 47 | |
| 48 ExecutionContext* execution_context = ExecutionContext::From(script_state); | |
| 49 if (!execution_context) | |
| 50 return; | |
| 51 v8::Isolate* isolate = script_state->GetIsolate(); | |
| 52 const DOMWrapperWorld& world = script_state->World(); | |
| 53 if (wrapper_type_info == &V8Navigator::wrapperTypeInfo) { | |
| 54 if (OriginTrials::installedAppEnabled(execution_context)) { | |
| 55 V8NavigatorPartial::installInstalledApp( | |
| 56 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 57 interface_object); | |
| 58 } | |
| 59 if (OriginTrials::webVREnabled(execution_context)) { | |
| 60 V8NavigatorPartial::installWebVR(isolate, world, v8::Local<v8::Object>(), | |
| 61 prototype_object, interface_object); | |
| 62 } | |
| 63 } else if (wrapper_type_info == &V8Window::wrapperTypeInfo) { | |
| 64 v8::Local<v8::Object> instance_object = | |
| 65 script_state->GetContext()->Global(); | |
| 66 if (OriginTrials::webVREnabled(execution_context)) { | |
| 67 V8WindowPartial::installWebVR(isolate, world, instance_object, | |
| 68 prototype_object, interface_object); | |
| 69 } | |
| 70 if (OriginTrials::gamepadExtensionsEnabled(execution_context)) { | |
| 71 V8WindowPartial::installGamepadExtensions( | |
| 72 isolate, world, instance_object, prototype_object, interface_object); | |
| 73 } | |
| 74 if (OriginTrials::budgetQueryEnabled(execution_context)) { | |
| 75 V8WindowPartial::installBudgetQuery(isolate, world, instance_object, | |
| 76 prototype_object, interface_object); | |
| 77 } | |
| 78 } else if (wrapper_type_info == | |
| 79 &V8DedicatedWorkerGlobalScope::wrapperTypeInfo) { | |
| 80 v8::Local<v8::Object> instance_object = | |
| 81 script_state->GetContext()->Global(); | |
| 82 if (OriginTrials::budgetQueryEnabled(execution_context)) { | |
| 83 V8DedicatedWorkerGlobalScopePartial::installBudgetQuery( | |
| 84 isolate, world, instance_object, prototype_object, interface_object); | |
| 85 } | |
| 86 } else if (wrapper_type_info == &V8SharedWorkerGlobalScope::wrapperTypeInfo) { | |
| 87 v8::Local<v8::Object> instance_object = | |
| 88 script_state->GetContext()->Global(); | |
| 89 if (OriginTrials::budgetQueryEnabled(execution_context)) { | |
| 90 V8SharedWorkerGlobalScopePartial::installBudgetQuery( | |
| 91 isolate, world, instance_object, prototype_object, interface_object); | |
| 92 } | |
| 93 } else if (wrapper_type_info == | |
| 94 &V8ServiceWorkerGlobalScope::wrapperTypeInfo) { | |
| 95 v8::Local<v8::Object> instance_object = | |
| 96 script_state->GetContext()->Global(); | |
| 97 if (OriginTrials::foreignFetchEnabled(execution_context)) { | |
| 98 V8ServiceWorkerGlobalScope::installForeignFetch( | |
| 99 isolate, world, instance_object, prototype_object, interface_object); | |
| 100 } | |
| 101 if (OriginTrials::budgetQueryEnabled(execution_context)) { | |
| 102 V8ServiceWorkerGlobalScope::installBudgetQuery( | |
| 103 isolate, world, instance_object, prototype_object, interface_object); | |
| 104 } | |
| 105 } else if (wrapper_type_info == &V8InstallEvent::wrapperTypeInfo) { | |
| 106 if (OriginTrials::foreignFetchEnabled(execution_context)) { | |
| 107 V8InstallEvent::installForeignFetch(isolate, world, | |
| 108 v8::Local<v8::Object>(), | |
| 109 prototype_object, interface_object); | |
| 110 } | |
| 111 } else if (wrapper_type_info == &V8BudgetService::wrapperTypeInfo) { | |
| 112 if (OriginTrials::budgetQueryEnabled(execution_context)) { | |
| 113 V8BudgetService::installBudgetQuery(isolate, world, | |
| 114 v8::Local<v8::Object>(), | |
| 115 prototype_object, interface_object); | |
| 116 } | |
| 117 } else if (wrapper_type_info == &V8Gamepad::wrapperTypeInfo) { | |
| 118 if (OriginTrials::gamepadExtensionsEnabled(execution_context)) { | |
| 119 V8Gamepad::installGamepadExtensions(isolate, world, | |
| 120 v8::Local<v8::Object>(), | |
| 121 prototype_object, interface_object); | |
| 122 } | |
| 123 } else if (wrapper_type_info == &V8GamepadButton::wrapperTypeInfo) { | |
| 124 if (OriginTrials::gamepadExtensionsEnabled(execution_context)) { | |
| 125 V8GamepadButton::installGamepadExtensions( | |
| 126 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 127 interface_object); | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 void InstallPendingConditionalFeatureForModules( | |
| 133 const String& feature, | |
| 134 const ScriptState* script_state) { | |
| 135 // TODO(iclelland): Generate all of this logic at compile-time, based on the | |
| 136 // configuration of origin trial enabled attributes and interfaces in IDL | |
| 137 // files. (crbug.com/615060) | |
| 138 (*g_original_install_pending_conditional_feature_function)(feature, | |
| 139 script_state); | |
| 140 v8::Local<v8::Object> global_instance_object; | |
| 141 v8::Local<v8::Object> prototype_object; | |
| 142 v8::Local<v8::Function> interface_object; | |
| 143 v8::Isolate* isolate = script_state->GetIsolate(); | |
| 144 const DOMWrapperWorld& world = script_state->World(); | |
| 145 V8PerContextData* context_data = script_state->PerContextData(); | |
| 146 if (feature == "ForeignFetch") { | |
| 147 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 148 &V8InstallEvent::wrapperTypeInfo, &prototype_object, | |
| 149 &interface_object)) { | |
| 150 V8InstallEvent::installForeignFetch(isolate, world, | |
| 151 v8::Local<v8::Object>(), | |
| 152 prototype_object, interface_object); | |
| 153 } | |
| 154 return; | |
| 155 } | |
| 156 if (feature == "InstalledApp") { | |
| 157 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 158 &V8Navigator::wrapperTypeInfo, &prototype_object, | |
| 159 &interface_object)) { | |
| 160 V8NavigatorPartial::installInstalledApp( | |
| 161 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 162 interface_object); | |
| 163 } | |
| 164 return; | |
| 165 } | |
| 166 if (feature == "WebVR1.1") { | |
| 167 global_instance_object = script_state->GetContext()->Global(); | |
| 168 V8WindowPartial::installGamepadExtensions( | |
| 169 isolate, world, global_instance_object, v8::Local<v8::Object>(), | |
| 170 v8::Local<v8::Function>()); | |
| 171 V8WindowPartial::installWebVR(isolate, world, global_instance_object, | |
| 172 v8::Local<v8::Object>(), | |
| 173 v8::Local<v8::Function>()); | |
| 174 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 175 &V8Gamepad::wrapperTypeInfo, &prototype_object, | |
| 176 &interface_object)) { | |
| 177 V8Gamepad::installGamepadExtensions(isolate, world, | |
| 178 v8::Local<v8::Object>(), | |
| 179 prototype_object, interface_object); | |
| 180 } | |
| 181 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 182 &V8GamepadButton::wrapperTypeInfo, &prototype_object, | |
| 183 &interface_object)) { | |
| 184 V8GamepadButton::installGamepadExtensions( | |
| 185 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 186 interface_object); | |
| 187 } | |
| 188 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 189 &V8Navigator::wrapperTypeInfo, &prototype_object, | |
| 190 &interface_object)) { | |
| 191 V8NavigatorPartial::installWebVR(isolate, world, v8::Local<v8::Object>(), | |
| 192 prototype_object, interface_object); | |
| 193 } | |
| 194 return; | |
| 195 } | |
| 196 if (feature == "BudgetQuery") { | |
| 197 global_instance_object = script_state->GetContext()->Global(); | |
| 198 | |
| 199 ExecutionContext* execution_context = ExecutionContext::From(script_state); | |
| 200 if (execution_context->IsDocument()) { | |
| 201 V8WindowPartial::installBudgetQuery( | |
| 202 isolate, world, global_instance_object, v8::Local<v8::Object>(), | |
| 203 v8::Local<v8::Function>()); | |
| 204 } else if (execution_context->IsDedicatedWorkerGlobalScope()) { | |
| 205 V8DedicatedWorkerGlobalScopePartial::installBudgetQuery( | |
| 206 isolate, world, global_instance_object, v8::Local<v8::Object>(), | |
| 207 v8::Local<v8::Function>()); | |
| 208 } else if (execution_context->IsSharedWorkerGlobalScope()) { | |
| 209 V8SharedWorkerGlobalScopePartial::installBudgetQuery( | |
| 210 isolate, world, global_instance_object, v8::Local<v8::Object>(), | |
| 211 v8::Local<v8::Function>()); | |
| 212 } else if (execution_context->IsServiceWorkerGlobalScope()) { | |
| 213 V8ServiceWorkerGlobalScope::installBudgetQuery( | |
| 214 isolate, world, global_instance_object, v8::Local<v8::Object>(), | |
| 215 v8::Local<v8::Function>()); | |
| 216 } | |
| 217 | |
| 218 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 219 &V8BudgetService::wrapperTypeInfo, &prototype_object, | |
| 220 &interface_object)) { | |
| 221 V8BudgetService::installBudgetQuery(isolate, world, | |
| 222 v8::Local<v8::Object>(), | |
| 223 prototype_object, interface_object); | |
| 224 } | |
| 225 return; | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 void RegisterInstallConditionalFeaturesForModules() { | |
| 230 RegisterInstallConditionalFeaturesForCore(); | |
| 231 g_original_install_conditional_features_function = | |
| 232 SetInstallConditionalFeaturesFunction( | |
| 233 &InstallConditionalFeaturesForModules); | |
| 234 g_original_install_pending_conditional_feature_function = | |
| 235 SetInstallPendingConditionalFeatureFunction( | |
| 236 &InstallPendingConditionalFeatureForModules); | |
| 237 } | |
| 238 | |
| 239 } // namespace blink | |
| OLD | NEW |