| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 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/core/v8/ConditionalFeaturesForCore.h" | |
| 6 | |
| 7 #include "bindings/core/v8/V8Document.h" | |
| 8 #include "bindings/core/v8/V8HTMLLinkElement.h" | |
| 9 #include "bindings/core/v8/V8Navigator.h" | |
| 10 #include "bindings/core/v8/V8Window.h" | |
| 11 #include "core/context_features/ContextFeatureSettings.h" | |
| 12 #include "core/dom/ExecutionContext.h" | |
| 13 #include "core/frame/Frame.h" | |
| 14 #include "core/origin_trials/OriginTrials.h" | |
| 15 #include "platform/bindings/ConditionalFeatures.h" | |
| 16 #include "platform/bindings/ScriptState.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 namespace { | |
| 21 InstallConditionalFeaturesFunction g_old_install_conditional_features_function = | |
| 22 nullptr; | |
| 23 InstallPendingConditionalFeatureFunction | |
| 24 g_old_install_pending_conditional_feature_function = nullptr; | |
| 25 } | |
| 26 | |
| 27 void InstallConditionalFeaturesCore(const WrapperTypeInfo* wrapper_type_info, | |
| 28 const ScriptState* script_state, | |
| 29 v8::Local<v8::Object> prototype_object, | |
| 30 v8::Local<v8::Function> interface_object) { | |
| 31 (*g_old_install_conditional_features_function)( | |
| 32 wrapper_type_info, script_state, prototype_object, interface_object); | |
| 33 | |
| 34 // TODO(iclelland): Generate all of this logic at compile-time, based on the | |
| 35 // configuration of origin trial enabled attributes and interfaces in IDL | |
| 36 // files. (crbug.com/615060) | |
| 37 ExecutionContext* execution_context = ExecutionContext::From(script_state); | |
| 38 if (!execution_context) | |
| 39 return; | |
| 40 v8::Isolate* isolate = script_state->GetIsolate(); | |
| 41 const DOMWrapperWorld& world = script_state->World(); | |
| 42 if (wrapper_type_info == &V8Window::wrapperTypeInfo) { | |
| 43 auto* settings = ContextFeatureSettings::From( | |
| 44 execution_context, | |
| 45 ContextFeatureSettings::CreationMode::kDontCreateIfNotExists); | |
| 46 if (settings && settings->isMojoJSEnabled()) { | |
| 47 v8::Local<v8::Object> instance_object = | |
| 48 script_state->GetContext()->Global(); | |
| 49 V8Window::installMojoJS(isolate, world, instance_object, prototype_object, | |
| 50 interface_object); | |
| 51 } | |
| 52 } else if (wrapper_type_info == &V8HTMLLinkElement::wrapperTypeInfo) { | |
| 53 if (OriginTrials::linkServiceWorkerEnabled(execution_context)) { | |
| 54 V8HTMLLinkElement::installLinkServiceWorker( | |
| 55 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 56 interface_object); | |
| 57 } | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void InstallPendingConditionalFeatureCore(const String& feature, | |
| 62 const ScriptState* script_state) { | |
| 63 (*g_old_install_pending_conditional_feature_function)(feature, script_state); | |
| 64 | |
| 65 // TODO(iclelland): Generate all of this logic at compile-time, based on the | |
| 66 // configuration of origin trial enabled attributes and interfaces in IDL | |
| 67 // files. (crbug.com/615060) | |
| 68 v8::Local<v8::Object> prototype_object; | |
| 69 v8::Local<v8::Function> interface_object; | |
| 70 v8::Isolate* isolate = script_state->GetIsolate(); | |
| 71 const DOMWrapperWorld& world = script_state->World(); | |
| 72 V8PerContextData* context_data = script_state->PerContextData(); | |
| 73 if (feature == "ForeignFetch") { | |
| 74 if (context_data->GetExistingConstructorAndPrototypeForType( | |
| 75 &V8HTMLLinkElement::wrapperTypeInfo, &prototype_object, | |
| 76 &interface_object)) { | |
| 77 V8HTMLLinkElement::installLinkServiceWorker( | |
| 78 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
| 79 interface_object); | |
| 80 } | |
| 81 return; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 void InstallConditionalFeaturesOnWindow(const ScriptState* script_state) { | |
| 86 DCHECK(script_state); | |
| 87 DCHECK(script_state->GetContext() == | |
| 88 script_state->GetIsolate()->GetCurrentContext()); | |
| 89 DCHECK(script_state->PerContextData()); | |
| 90 DCHECK(script_state->World().IsMainWorld()); | |
| 91 InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state, | |
| 92 v8::Local<v8::Object>(), | |
| 93 v8::Local<v8::Function>()); | |
| 94 } | |
| 95 | |
| 96 void RegisterInstallConditionalFeaturesForCore() { | |
| 97 g_old_install_conditional_features_function = | |
| 98 SetInstallConditionalFeaturesFunction(&InstallConditionalFeaturesCore); | |
| 99 g_old_install_pending_conditional_feature_function = | |
| 100 SetInstallPendingConditionalFeatureFunction( | |
| 101 &InstallPendingConditionalFeatureCore); | |
| 102 } | |
| 103 | |
| 104 } // namespace blink | |
| OLD | NEW |