Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/templates/ConditionalFeaturesForModules.cpp.tmpl |
| diff --git a/third_party/WebKit/Source/bindings/templates/ConditionalFeaturesForModules.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/ConditionalFeaturesForModules.cpp.tmpl |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..50a495191d7160f7b1c3a6f396da6873426c40e3 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/templates/ConditionalFeaturesForModules.cpp.tmpl |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
|
chasej
2017/07/11 20:12:32
Ditto about copyright include.
iclelland
2017/07/12 17:23:20
Done.
|
| + |
| +#include "bindings/modules/v8/ConditionalFeaturesForModules.h" |
| + |
| +#include "bindings/core/v8/ConditionalFeaturesForCore.h" |
| +{% for include in includes %} |
| +#include "{{ include }}" |
| +{% endfor %} |
| + |
| +namespace blink { |
| + |
| +namespace { |
| +InstallConditionalFeaturesFunction |
| + g_original_install_conditional_features_function = nullptr; |
| +InstallPendingConditionalFeatureFunction |
| + g_original_install_pending_conditional_feature_function = nullptr; |
| +} |
| + |
| +void InstallConditionalFeaturesForModules( |
|
chasej
2017/07/11 20:12:32
This method seems very similar to the Core version
iclelland
2017/07/12 17:23:20
I've made them identical now, except that the Core
chasej
2017/07/12 19:53:41
Is that newly-added todo in this CL? I'm not seein
iclelland
2017/07/13 15:32:59
Oops -- missed it, thanks for catching.
|
| + const WrapperTypeInfo* wrapper_type_info, |
| + const ScriptState* script_state, |
| + v8::Local<v8::Object> prototype_object, |
| + v8::Local<v8::Function> interface_object) { |
| + (*g_original_install_conditional_features_function)( |
| + wrapper_type_info, script_state, prototype_object, interface_object); |
| + |
| + {% if installers_by_interface %} |
| + ExecutionContext* execution_context = ExecutionContext::From(script_state); |
| + if (!execution_context) |
| + return; |
| + v8::Isolate* isolate = script_state->GetIsolate(); |
| + const DOMWrapperWorld& world = script_state->World(); |
| + {% for interface in installers_by_interface %} |
| + if (wrapper_type_info == &{{ interface.class }}::wrapperTypeInfo) { |
| + {% if interface.is_global %} |
| + v8::Local<v8::Object> instance_object = |
| + script_state->GetContext()->Global(); |
| + {% endif %} |
| + {% for installer in interface.installers %} |
| + if ({{ installer.condition }}(execution_context)) { |
| + {{ installer.class_or_partial }}::{{ installer.install_method }}( |
| + isolate, world, {% if interface.is_global %}instance_object{% else %}v8::Local<v8::Object>(){% endif %}, prototype_object, |
| + interface_object); |
| + } |
| + {% endfor %} |
| + } |
| + {% endfor %} |
| + {% endif %} |
| +} |
| + |
| +void InstallPendingConditionalFeatureForModules( |
| + const String& feature, |
| + const ScriptState* script_state) { |
| + (*g_original_install_pending_conditional_feature_function)(feature, |
| + script_state); |
| + |
| + {% if installers_by_feature %} |
| + v8::Local<v8::Object> prototype_object; |
| + v8::Local<v8::Function> interface_object; |
| + v8::Isolate* isolate = script_state->GetIsolate(); |
| + const DOMWrapperWorld& world = script_state->World(); |
| + V8PerContextData* context_data = script_state->PerContextData(); |
| + {% for feature in installers_by_feature %} |
| + if (feature == "{{ feature.name }}") { |
| + {% for installer in feature.installers %} |
| + if (context_data->GetExistingConstructorAndPrototypeForType( |
| + &{{ installer.class }}::wrapperTypeInfo, &prototype_object, |
| + &interface_object)) { |
| + {{ installer.class_or_partial }}::{{ installer.install_method }}( |
| + isolate, world, v8::Local<v8::Object>(), prototype_object, |
| + interface_object); |
| + } |
| + {% endfor %} |
| + return; |
| + } |
| + {% endfor %} |
| + {% endif %} |
| +} |
| + |
| +void RegisterInstallConditionalFeaturesForModules() { |
| + RegisterInstallConditionalFeaturesForCore(); |
| + g_original_install_conditional_features_function = |
| + SetInstallConditionalFeaturesFunction( |
| + &InstallConditionalFeaturesForModules); |
| + g_original_install_pending_conditional_feature_function = |
| + SetInstallPendingConditionalFeatureFunction( |
| + &InstallPendingConditionalFeatureForModules); |
| +} |
| + |
| +} // namespace blink |