OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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. |
chasej
2017/07/11 20:12:32
Should this copyright be replaced by an include? L
iclelland
2017/07/12 17:23:20
Done.
| |
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 InstallConditionalFeaturesCore(const WrapperTypeInfo* wrapper_type_info, |
chasej
2017/07/11 20:12:32
Should be "...ForCore" to be consistent with file
iclelland
2017/07/12 17:23:20
Done.
| |
28 const ScriptState* script_state, | 21 const ScriptState* script_state, |
29 v8::Local<v8::Object> prototype_object, | 22 v8::Local<v8::Object> prototype_object, |
30 v8::Local<v8::Function> interface_object) { | 23 v8::Local<v8::Function> interface_object) { |
31 (*g_old_install_conditional_features_function)( | 24 (*g_old_install_conditional_features_function)( |
32 wrapper_type_info, script_state, prototype_object, interface_object); | 25 wrapper_type_info, script_state, prototype_object, interface_object); |
33 | 26 |
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); | 27 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
38 if (!execution_context) | 28 if (!execution_context) |
39 return; | 29 return; |
40 v8::Isolate* isolate = script_state->GetIsolate(); | 30 v8::Isolate* isolate = script_state->GetIsolate(); |
41 const DOMWrapperWorld& world = script_state->World(); | 31 const DOMWrapperWorld& world = script_state->World(); |
32 // TODO(iclelland): Unify ContextFeatureSettings with the rest of the | |
33 // conditional features. | |
42 if (wrapper_type_info == &V8Window::wrapperTypeInfo) { | 34 if (wrapper_type_info == &V8Window::wrapperTypeInfo) { |
43 auto* settings = ContextFeatureSettings::From( | 35 auto* settings = ContextFeatureSettings::From( |
44 execution_context, | 36 execution_context, |
45 ContextFeatureSettings::CreationMode::kDontCreateIfNotExists); | 37 ContextFeatureSettings::CreationMode::kDontCreateIfNotExists); |
46 if (settings && settings->isMojoJSEnabled()) { | 38 if (settings && settings->isMojoJSEnabled()) { |
47 v8::Local<v8::Object> instance_object = | 39 v8::Local<v8::Object> instance_object = |
48 script_state->GetContext()->Global(); | 40 script_state->GetContext()->Global(); |
49 V8Window::installMojoJS(isolate, world, instance_object, prototype_object, | 41 V8Window::installMojoJS(isolate, world, instance_object, prototype_object, |
50 interface_object); | 42 interface_object); |
51 } | 43 } |
52 } else if (wrapper_type_info == &V8HTMLLinkElement::wrapperTypeInfo) { | 44 } |
53 if (OriginTrials::linkServiceWorkerEnabled(execution_context)) { | 45 {% for interface in installers_by_interface %} |
54 V8HTMLLinkElement::installLinkServiceWorker( | 46 if (wrapper_type_info == &{{ interface.class }}::wrapperTypeInfo) { |
47 {% for installer in interface.installers %} | |
chasej
2017/07/11 20:12:31
Will this code generation properly handle global o
iclelland
2017/07/12 17:23:20
That's a good point, we've never defined a trial i
chasej
2017/07/12 19:53:41
Actually, the Long Task Observer trial required in
| |
48 if ({{ installer.condition }}(execution_context)) { | |
49 {{ installer.class }}::{{ installer.install_method }}( | |
55 isolate, world, v8::Local<v8::Object>(), prototype_object, | 50 isolate, world, v8::Local<v8::Object>(), prototype_object, |
56 interface_object); | 51 interface_object); |
57 } | 52 } |
53 {% endfor %} | |
58 } | 54 } |
55 {% endfor %} | |
59 } | 56 } |
60 | 57 |
61 void InstallPendingConditionalFeatureCore(const String& feature, | 58 void InstallPendingConditionalFeatureCore(const String& feature, |
chasej
2017/07/11 20:12:32
Ditto. Should be "...ForCore" to be consistent wit
iclelland
2017/07/12 17:23:20
Yes, this was a holdover from the handwritten code
| |
62 const ScriptState* script_state) { | 59 const ScriptState* script_state) { |
63 (*g_old_install_pending_conditional_feature_function)(feature, script_state); | 60 (*g_old_install_pending_conditional_feature_function)(feature, script_state); |
64 | 61 |
65 // TODO(iclelland): Generate all of this logic at compile-time, based on the | 62 {% if installers_by_feature %} |
66 // configuration of origin trial enabled attributes and interfaces in IDL | |
67 // files. (crbug.com/615060) | |
68 v8::Local<v8::Object> prototype_object; | 63 v8::Local<v8::Object> prototype_object; |
69 v8::Local<v8::Function> interface_object; | 64 v8::Local<v8::Function> interface_object; |
70 v8::Isolate* isolate = script_state->GetIsolate(); | 65 v8::Isolate* isolate = script_state->GetIsolate(); |
71 const DOMWrapperWorld& world = script_state->World(); | 66 const DOMWrapperWorld& world = script_state->World(); |
72 V8PerContextData* context_data = script_state->PerContextData(); | 67 V8PerContextData* context_data = script_state->PerContextData(); |
73 if (feature == "ForeignFetch") { | 68 {% for feature in installers_by_feature %} |
69 if (feature == "{{ feature.name }}") { | |
70 {% for installer in feature.installers %} | |
74 if (context_data->GetExistingConstructorAndPrototypeForType( | 71 if (context_data->GetExistingConstructorAndPrototypeForType( |
75 &V8HTMLLinkElement::wrapperTypeInfo, &prototype_object, | 72 &{{ installer.class }}::wrapperTypeInfo, &prototype_object, |
76 &interface_object)) { | 73 &interface_object)) { |
77 V8HTMLLinkElement::installLinkServiceWorker( | 74 {{ installer.class_or_partial }}::{{ installer.install_method }}( |
78 isolate, world, v8::Local<v8::Object>(), prototype_object, | 75 isolate, world, v8::Local<v8::Object>(), prototype_object, |
79 interface_object); | 76 interface_object); |
80 } | 77 } |
78 {% endfor %} | |
81 return; | 79 return; |
82 } | 80 } |
81 {% endfor %} | |
82 {% endif %} | |
83 } | 83 } |
84 | 84 |
85 void InstallConditionalFeaturesOnWindow(const ScriptState* script_state) { | 85 void InstallConditionalFeaturesOnWindow(const ScriptState* script_state) { |
86 DCHECK(script_state); | 86 DCHECK(script_state); |
87 DCHECK(script_state->GetContext() == | 87 DCHECK(script_state->GetContext() == |
88 script_state->GetIsolate()->GetCurrentContext()); | 88 script_state->GetIsolate()->GetCurrentContext()); |
89 DCHECK(script_state->PerContextData()); | 89 DCHECK(script_state->PerContextData()); |
90 DCHECK(script_state->World().IsMainWorld()); | 90 DCHECK(script_state->World().IsMainWorld()); |
91 InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state, | 91 InstallConditionalFeatures(&V8Window::wrapperTypeInfo, script_state, |
92 v8::Local<v8::Object>(), | 92 v8::Local<v8::Object>(), |
93 v8::Local<v8::Function>()); | 93 v8::Local<v8::Function>()); |
94 } | 94 } |
95 | 95 |
96 void RegisterInstallConditionalFeaturesForCore() { | 96 void RegisterInstallConditionalFeaturesForCore() { |
97 g_old_install_conditional_features_function = | 97 g_old_install_conditional_features_function = |
98 SetInstallConditionalFeaturesFunction(&InstallConditionalFeaturesCore); | 98 SetInstallConditionalFeaturesFunction(&InstallConditionalFeaturesCore); |
99 g_old_install_pending_conditional_feature_function = | 99 g_old_install_pending_conditional_feature_function = |
100 SetInstallPendingConditionalFeatureFunction( | 100 SetInstallPendingConditionalFeatureFunction( |
101 &InstallPendingConditionalFeatureCore); | 101 &InstallPendingConditionalFeatureCore); |
102 } | 102 } |
103 | 103 |
104 } // namespace blink | 104 } // namespace blink |
OLD | NEW |