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