OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 {% filter format_blink_cpp_source_code %} |
2 // Use of this source code is governed by a BSD-style license that can be | 2 |
3 // found in the LICENSE file. | 3 {% include 'copyright_block.txt' %} |
4 | 4 |
5 #include "bindings/core/v8/ConditionalFeaturesForCore.h" | 5 #include "bindings/core/v8/ConditionalFeaturesForCore.h" |
6 | 6 |
7 #include "bindings/core/v8/V8Document.h" | 7 {% for include in includes %} |
8 #include "bindings/core/v8/V8HTMLLinkElement.h" | 8 #include "{{include}}" |
9 #include "bindings/core/v8/V8Navigator.h" | 9 {% endfor %} |
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 | 10 |
18 namespace blink { | 11 namespace blink { |
19 | 12 |
20 namespace { | 13 namespace { |
21 InstallConditionalFeaturesFunction g_old_install_conditional_features_function = | 14 InstallConditionalFeaturesFunction g_old_install_conditional_features_function = |
22 nullptr; | 15 nullptr; |
23 InstallPendingConditionalFeatureFunction | 16 InstallPendingConditionalFeatureFunction |
24 g_old_install_pending_conditional_feature_function = nullptr; | 17 g_old_install_pending_conditional_feature_function = nullptr; |
25 } | 18 } |
26 | 19 |
27 void InstallConditionalFeaturesCore(const WrapperTypeInfo* wrapper_type_info, | 20 void InstallConditionalFeaturesForCore( |
28 const ScriptState* script_state, | 21 const WrapperTypeInfo* wrapper_type_info, |
29 v8::Local<v8::Object> prototype_object, | 22 const ScriptState* script_state, |
30 v8::Local<v8::Function> interface_object) { | 23 v8::Local<v8::Object> prototype_object, |
| 24 v8::Local<v8::Function> interface_object) { |
31 (*g_old_install_conditional_features_function)( | 25 (*g_old_install_conditional_features_function)( |
32 wrapper_type_info, script_state, prototype_object, interface_object); | 26 wrapper_type_info, script_state, prototype_object, interface_object); |
33 | 27 |
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); | 28 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
38 if (!execution_context) | 29 if (!execution_context) |
39 return; | 30 return; |
40 v8::Isolate* isolate = script_state->GetIsolate(); | 31 v8::Isolate* isolate = script_state->GetIsolate(); |
41 const DOMWrapperWorld& world = script_state->World(); | 32 const DOMWrapperWorld& world = script_state->World(); |
| 33 // TODO(iclelland): Unify ContextFeatureSettings with the rest of the |
| 34 // conditional features. |
42 if (wrapper_type_info == &V8Window::wrapperTypeInfo) { | 35 if (wrapper_type_info == &V8Window::wrapperTypeInfo) { |
43 auto* settings = ContextFeatureSettings::From( | 36 auto* settings = ContextFeatureSettings::From( |
44 execution_context, | 37 execution_context, |
45 ContextFeatureSettings::CreationMode::kDontCreateIfNotExists); | 38 ContextFeatureSettings::CreationMode::kDontCreateIfNotExists); |
46 if (settings && settings->isMojoJSEnabled()) { | 39 if (settings && settings->isMojoJSEnabled()) { |
47 v8::Local<v8::Object> instance_object = | 40 v8::Local<v8::Object> instance_object = |
48 script_state->GetContext()->Global(); | 41 script_state->GetContext()->Global(); |
49 V8Window::installMojoJS(isolate, world, instance_object, prototype_object, | 42 V8Window::installMojoJS(isolate, world, instance_object, prototype_object, |
50 interface_object); | 43 interface_object); |
51 } | 44 } |
52 } else if (wrapper_type_info == &V8HTMLLinkElement::wrapperTypeInfo) { | 45 } |
53 if (OriginTrials::linkServiceWorkerEnabled(execution_context)) { | 46 // TODO(iclelland): Extract this common code out of ConditionalFeaturesForCore |
54 V8HTMLLinkElement::installLinkServiceWorker( | 47 // and ConditionalFeaturesForModules into a block. |
55 isolate, world, v8::Local<v8::Object>(), prototype_object, | 48 {% for interface in installers_by_interface %} |
56 interface_object); | 49 if (wrapper_type_info == &{{interface.v8_class}}::wrapperTypeInfo) { |
| 50 {% if interface.is_global %} |
| 51 v8::Local<v8::Object> instance_object = |
| 52 script_state->GetContext()->Global(); |
| 53 {% endif %} |
| 54 {% for installer in interface.installers %} |
| 55 if ({{installer.condition}}(execution_context)) { |
| 56 {{installer.v8_class_or_partial}}::{{installer.install_method}}( |
| 57 isolate, world, {% if interface.is_global %}instance_object{% else %}v
8::Local<v8::Object>(){% endif %}, prototype_object, interface_object); |
57 } | 58 } |
| 59 {% endfor %} |
58 } | 60 } |
| 61 {% endfor %} |
59 } | 62 } |
60 | 63 |
61 void InstallPendingConditionalFeatureCore(const String& feature, | 64 void InstallPendingConditionalFeatureForCore(const String& feature, |
62 const ScriptState* script_state) { | 65 const ScriptState* script_state) { |
63 (*g_old_install_pending_conditional_feature_function)(feature, script_state); | 66 (*g_old_install_pending_conditional_feature_function)(feature, script_state); |
64 | 67 |
65 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 68 // TODO(iclelland): Extract this common code out of ConditionalFeaturesForCore |
66 // configuration of origin trial enabled attributes and interfaces in IDL | 69 // and ConditionalFeaturesForModules into a block. |
67 // files. (crbug.com/615060) | 70 {% if installers_by_feature %} |
68 v8::Local<v8::Object> prototype_object; | 71 v8::Local<v8::Object> prototype_object; |
69 v8::Local<v8::Function> interface_object; | 72 v8::Local<v8::Function> interface_object; |
70 v8::Isolate* isolate = script_state->GetIsolate(); | 73 v8::Isolate* isolate = script_state->GetIsolate(); |
71 const DOMWrapperWorld& world = script_state->World(); | 74 const DOMWrapperWorld& world = script_state->World(); |
72 V8PerContextData* context_data = script_state->PerContextData(); | 75 V8PerContextData* context_data = script_state->PerContextData(); |
73 if (feature == "ForeignFetch") { | 76 {% for feature in installers_by_feature %} |
| 77 if (feature == "{{feature.name}}") { |
| 78 {% for installer in feature.installers %} |
74 if (context_data->GetExistingConstructorAndPrototypeForType( | 79 if (context_data->GetExistingConstructorAndPrototypeForType( |
75 &V8HTMLLinkElement::wrapperTypeInfo, &prototype_object, | 80 &{{installer.v8_class}}::wrapperTypeInfo, &prototype_object, &interf
ace_object)) { |
76 &interface_object)) { | 81 {{installer.v8_class_or_partial}}::{{installer.install_method}}( |
77 V8HTMLLinkElement::installLinkServiceWorker( | 82 isolate, world, v8::Local<v8::Object>(), prototype_object, interface_o
bject); |
78 isolate, world, v8::Local<v8::Object>(), prototype_object, | |
79 interface_object); | |
80 } | 83 } |
| 84 {% endfor %} |
81 return; | 85 return; |
82 } | 86 } |
| 87 {% endfor %} |
| 88 {% endif %} |
83 } | 89 } |
84 | 90 |
85 void InstallConditionalFeaturesOnWindow(const ScriptState* script_state) { | 91 void InstallConditionalFeaturesOnWindow(const ScriptState* script_state) { |
86 DCHECK(script_state); | 92 DCHECK(script_state); |
87 DCHECK(script_state->GetContext() == | 93 DCHECK(script_state->GetContext() == |
88 script_state->GetIsolate()->GetCurrentContext()); | 94 script_state->GetIsolate()->GetCurrentContext()); |
89 DCHECK(script_state->PerContextData()); | 95 DCHECK(script_state->PerContextData()); |
90 DCHECK(script_state->World().IsMainWorld()); | 96 DCHECK(script_state->World().IsMainWorld()); |
91 InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state, | 97 InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state, |
92 v8::Local<v8::Object>(), | 98 v8::Local<v8::Object>(), |
93 v8::Local<v8::Function>()); | 99 v8::Local<v8::Function>()); |
94 } | 100 } |
95 | 101 |
96 void RegisterInstallConditionalFeaturesForCore() { | 102 void RegisterInstallConditionalFeaturesForCore() { |
97 g_old_install_conditional_features_function = | 103 g_old_install_conditional_features_function = |
98 SetInstallConditionalFeaturesFunction(&InstallConditionalFeaturesCore); | 104 SetInstallConditionalFeaturesFunction(&InstallConditionalFeaturesForCore); |
99 g_old_install_pending_conditional_feature_function = | 105 g_old_install_pending_conditional_feature_function = |
100 SetInstallPendingConditionalFeatureFunction( | 106 SetInstallPendingConditionalFeatureFunction( |
101 &InstallPendingConditionalFeatureCore); | 107 &InstallPendingConditionalFeatureForCore); |
102 } | 108 } |
103 | 109 |
104 } // namespace blink | 110 } // namespace blink |
| 111 |
| 112 {% endfilter %}{# format_blink_cpp_source_code #} |
OLD | NEW |