OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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. |
4 | 4 |
5 #include "extensions/renderer/dispatcher.h" | 5 #include "extensions/renderer/dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/ptr_util.h" |
19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
20 #include "base/metrics/user_metrics_action.h" | 21 #include "base/metrics/user_metrics_action.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
22 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "content/grit/content_resources.h" | 29 #include "content/grit/content_resources.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Calls a method |method_name| in a module |module_name| belonging to the | 162 // Calls a method |method_name| in a module |module_name| belonging to the |
162 // module system from |context|. Intended as a callback target from | 163 // module system from |context|. Intended as a callback target from |
163 // ScriptContextSet::ForEach. | 164 // ScriptContextSet::ForEach. |
164 void CallModuleMethod(const std::string& module_name, | 165 void CallModuleMethod(const std::string& module_name, |
165 const std::string& method_name, | 166 const std::string& method_name, |
166 const base::ListValue* args, | 167 const base::ListValue* args, |
167 ScriptContext* context) { | 168 ScriptContext* context) { |
168 v8::HandleScope handle_scope(context->isolate()); | 169 v8::HandleScope handle_scope(context->isolate()); |
169 v8::Context::Scope context_scope(context->v8_context()); | 170 v8::Context::Scope context_scope(context->v8_context()); |
170 | 171 |
171 scoped_ptr<content::V8ValueConverter> converter( | 172 std::unique_ptr<content::V8ValueConverter> converter( |
172 content::V8ValueConverter::create()); | 173 content::V8ValueConverter::create()); |
173 | 174 |
174 std::vector<v8::Local<v8::Value>> arguments; | 175 std::vector<v8::Local<v8::Value>> arguments; |
175 for (base::ListValue::const_iterator it = args->begin(); it != args->end(); | 176 for (base::ListValue::const_iterator it = args->begin(); it != args->end(); |
176 ++it) { | 177 ++it) { |
177 arguments.push_back(converter->ToV8Value(*it, context->v8_context())); | 178 arguments.push_back(converter->ToV8Value(*it, context->v8_context())); |
178 } | 179 } |
179 | 180 |
180 context->module_system()->CallModuleMethod( | 181 context->module_system()->CallModuleMethod( |
181 module_name, method_name, &arguments); | 182 module_name, method_name, &arguments); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 ScriptContext* context = script_context_set_->Register( | 313 ScriptContext* context = script_context_set_->Register( |
313 frame, v8_context, extension_group, world_id); | 314 frame, v8_context, extension_group, world_id); |
314 | 315 |
315 // Initialize origin permissions for content scripts, which can't be | 316 // Initialize origin permissions for content scripts, which can't be |
316 // initialized in |OnActivateExtension|. | 317 // initialized in |OnActivateExtension|. |
317 if (context->context_type() == Feature::CONTENT_SCRIPT_CONTEXT) | 318 if (context->context_type() == Feature::CONTENT_SCRIPT_CONTEXT) |
318 InitOriginPermissions(context->extension()); | 319 InitOriginPermissions(context->extension()); |
319 | 320 |
320 { | 321 { |
321 scoped_ptr<ModuleSystem> module_system( | 322 std::unique_ptr<ModuleSystem> module_system( |
322 new ModuleSystem(context, &source_map_)); | 323 new ModuleSystem(context, &source_map_)); |
323 context->set_module_system(std::move(module_system)); | 324 context->set_module_system(std::move(module_system)); |
324 } | 325 } |
325 ModuleSystem* module_system = context->module_system(); | 326 ModuleSystem* module_system = context->module_system(); |
326 | 327 |
327 // Enable natives in startup. | 328 // Enable natives in startup. |
328 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 329 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
329 | 330 |
330 RegisterNativeHandlers(module_system, context); | 331 RegisterNativeHandlers(module_system, context); |
331 | 332 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // saying that an extension is ready, and documenting that extension APIs | 426 // saying that an extension is ready, and documenting that extension APIs |
426 // won't work before that event has fired? | 427 // won't work before that event has fired? |
427 return; | 428 return; |
428 } | 429 } |
429 | 430 |
430 ScriptContext* context = new ScriptContext( | 431 ScriptContext* context = new ScriptContext( |
431 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, | 432 v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, |
432 extension, Feature::SERVICE_WORKER_CONTEXT); | 433 extension, Feature::SERVICE_WORKER_CONTEXT); |
433 context->set_url(url); | 434 context->set_url(url); |
434 | 435 |
435 g_worker_script_context_set.Get().Insert(make_scoped_ptr(context)); | 436 g_worker_script_context_set.Get().Insert(base::WrapUnique(context)); |
436 | 437 |
437 v8::Isolate* isolate = context->isolate(); | 438 v8::Isolate* isolate = context->isolate(); |
438 | 439 |
439 // Fetch the source code for service_worker_bindings.js. | 440 // Fetch the source code for service_worker_bindings.js. |
440 base::StringPiece script_resource = | 441 base::StringPiece script_resource = |
441 ResourceBundle::GetSharedInstance().GetRawDataResource( | 442 ResourceBundle::GetSharedInstance().GetRawDataResource( |
442 IDR_SERVICE_WORKER_BINDINGS_JS); | 443 IDR_SERVICE_WORKER_BINDINGS_JS); |
443 v8::Local<v8::String> script = v8::String::NewExternal( | 444 v8::Local<v8::String> script = v8::String::NewExternal( |
444 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); | 445 isolate, new StaticV8ExternalOneByteStringResource(script_resource)); |
445 | 446 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 extension_id, base::Bind(&CallModuleMethod, local_event_bindings, | 590 extension_id, base::Bind(&CallModuleMethod, local_event_bindings, |
590 kEventDispatchFunction, &args)); | 591 kEventDispatchFunction, &args)); |
591 } | 592 } |
592 | 593 |
593 void Dispatcher::InvokeModuleSystemMethod(content::RenderFrame* render_frame, | 594 void Dispatcher::InvokeModuleSystemMethod(content::RenderFrame* render_frame, |
594 const std::string& extension_id, | 595 const std::string& extension_id, |
595 const std::string& module_name, | 596 const std::string& module_name, |
596 const std::string& function_name, | 597 const std::string& function_name, |
597 const base::ListValue& args, | 598 const base::ListValue& args, |
598 bool user_gesture) { | 599 bool user_gesture) { |
599 scoped_ptr<WebScopedUserGesture> web_user_gesture; | 600 std::unique_ptr<WebScopedUserGesture> web_user_gesture; |
600 if (user_gesture) | 601 if (user_gesture) |
601 web_user_gesture.reset(new WebScopedUserGesture); | 602 web_user_gesture.reset(new WebScopedUserGesture); |
602 | 603 |
603 script_context_set_->ForEach( | 604 script_context_set_->ForEach( |
604 extension_id, render_frame, | 605 extension_id, render_frame, |
605 base::Bind(&CallModuleMethod, module_name, function_name, &args)); | 606 base::Bind(&CallModuleMethod, module_name, function_name, &args)); |
606 | 607 |
607 // Reset the idle handler each time there's any activity like event or message | 608 // Reset the idle handler each time there's any activity like event or message |
608 // dispatch, for which Invoke is the chokepoint. | 609 // dispatch, for which Invoke is the chokepoint. |
609 if (set_idle_notifications_) { | 610 if (set_idle_notifications_) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 813 } |
813 | 814 |
814 // NOTE: please use the naming convention "foo_natives" for these. | 815 // NOTE: please use the naming convention "foo_natives" for these. |
815 // static | 816 // static |
816 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 817 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
817 ScriptContext* context, | 818 ScriptContext* context, |
818 Dispatcher* dispatcher, | 819 Dispatcher* dispatcher, |
819 RequestSender* request_sender, | 820 RequestSender* request_sender, |
820 V8SchemaRegistry* v8_schema_registry) { | 821 V8SchemaRegistry* v8_schema_registry) { |
821 module_system->RegisterNativeHandler( | 822 module_system->RegisterNativeHandler( |
822 "chrome", scoped_ptr<NativeHandler>(new ChromeNativeHandler(context))); | 823 "chrome", |
| 824 std::unique_ptr<NativeHandler>(new ChromeNativeHandler(context))); |
823 module_system->RegisterNativeHandler( | 825 module_system->RegisterNativeHandler( |
824 "logging", scoped_ptr<NativeHandler>(new LoggingNativeHandler(context))); | 826 "logging", |
| 827 std::unique_ptr<NativeHandler>(new LoggingNativeHandler(context))); |
825 module_system->RegisterNativeHandler("schema_registry", | 828 module_system->RegisterNativeHandler("schema_registry", |
826 v8_schema_registry->AsNativeHandler()); | 829 v8_schema_registry->AsNativeHandler()); |
827 module_system->RegisterNativeHandler( | 830 module_system->RegisterNativeHandler( |
828 "test_features", | 831 "test_features", |
829 scoped_ptr<NativeHandler>(new TestFeaturesNativeHandler(context))); | 832 std::unique_ptr<NativeHandler>(new TestFeaturesNativeHandler(context))); |
830 module_system->RegisterNativeHandler( | 833 module_system->RegisterNativeHandler( |
831 "test_native_handler", | 834 "test_native_handler", |
832 scoped_ptr<NativeHandler>(new TestNativeHandler(context))); | 835 std::unique_ptr<NativeHandler>(new TestNativeHandler(context))); |
833 module_system->RegisterNativeHandler( | 836 module_system->RegisterNativeHandler( |
834 "user_gestures", | 837 "user_gestures", |
835 scoped_ptr<NativeHandler>(new UserGesturesNativeHandler(context))); | 838 std::unique_ptr<NativeHandler>(new UserGesturesNativeHandler(context))); |
836 module_system->RegisterNativeHandler( | 839 module_system->RegisterNativeHandler( |
837 "utils", scoped_ptr<NativeHandler>(new UtilsNativeHandler(context))); | 840 "utils", std::unique_ptr<NativeHandler>(new UtilsNativeHandler(context))); |
838 module_system->RegisterNativeHandler( | 841 module_system->RegisterNativeHandler( |
839 "v8_context", | 842 "v8_context", |
840 scoped_ptr<NativeHandler>(new V8ContextNativeHandler(context))); | 843 std::unique_ptr<NativeHandler>(new V8ContextNativeHandler(context))); |
841 module_system->RegisterNativeHandler( | 844 module_system->RegisterNativeHandler( |
842 "event_natives", scoped_ptr<NativeHandler>(new EventBindings(context))); | 845 "event_natives", |
| 846 std::unique_ptr<NativeHandler>(new EventBindings(context))); |
843 module_system->RegisterNativeHandler( | 847 module_system->RegisterNativeHandler( |
844 "messaging_natives", | 848 "messaging_natives", std::unique_ptr<NativeHandler>( |
845 scoped_ptr<NativeHandler>(MessagingBindings::Get(dispatcher, context))); | 849 MessagingBindings::Get(dispatcher, context))); |
846 module_system->RegisterNativeHandler( | 850 module_system->RegisterNativeHandler( |
847 "apiDefinitions", | 851 "apiDefinitions", std::unique_ptr<NativeHandler>( |
848 scoped_ptr<NativeHandler>( | 852 new ApiDefinitionsNatives(dispatcher, context))); |
849 new ApiDefinitionsNatives(dispatcher, context))); | |
850 module_system->RegisterNativeHandler( | 853 module_system->RegisterNativeHandler( |
851 "sendRequest", | 854 "sendRequest", std::unique_ptr<NativeHandler>( |
852 scoped_ptr<NativeHandler>( | 855 new SendRequestNatives(request_sender, context))); |
853 new SendRequestNatives(request_sender, context))); | |
854 module_system->RegisterNativeHandler( | 856 module_system->RegisterNativeHandler( |
855 "setIcon", | 857 "setIcon", std::unique_ptr<NativeHandler>(new SetIconNatives(context))); |
856 scoped_ptr<NativeHandler>(new SetIconNatives(context))); | |
857 module_system->RegisterNativeHandler( | 858 module_system->RegisterNativeHandler( |
858 "activityLogger", | 859 "activityLogger", |
859 scoped_ptr<NativeHandler>(new APIActivityLogger(context))); | 860 std::unique_ptr<NativeHandler>(new APIActivityLogger(context))); |
860 module_system->RegisterNativeHandler( | 861 module_system->RegisterNativeHandler( |
861 "renderFrameObserverNatives", | 862 "renderFrameObserverNatives", |
862 scoped_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); | 863 std::unique_ptr<NativeHandler>(new RenderFrameObserverNatives(context))); |
863 | 864 |
864 // Natives used by multiple APIs. | 865 // Natives used by multiple APIs. |
865 module_system->RegisterNativeHandler( | 866 module_system->RegisterNativeHandler( |
866 "file_system_natives", | 867 "file_system_natives", |
867 scoped_ptr<NativeHandler>(new FileSystemNatives(context))); | 868 std::unique_ptr<NativeHandler>(new FileSystemNatives(context))); |
868 | 869 |
869 // Custom bindings. | 870 // Custom bindings. |
870 module_system->RegisterNativeHandler( | 871 module_system->RegisterNativeHandler( |
871 "app_window_natives", | 872 "app_window_natives", |
872 scoped_ptr<NativeHandler>(new AppWindowCustomBindings(context))); | 873 std::unique_ptr<NativeHandler>(new AppWindowCustomBindings(context))); |
873 module_system->RegisterNativeHandler( | 874 module_system->RegisterNativeHandler( |
874 "blob_natives", | 875 "blob_natives", |
875 scoped_ptr<NativeHandler>(new BlobNativeHandler(context))); | 876 std::unique_ptr<NativeHandler>(new BlobNativeHandler(context))); |
876 module_system->RegisterNativeHandler( | 877 module_system->RegisterNativeHandler( |
877 "context_menus", | 878 "context_menus", |
878 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings(context))); | 879 std::unique_ptr<NativeHandler>(new ContextMenusCustomBindings(context))); |
879 module_system->RegisterNativeHandler( | 880 module_system->RegisterNativeHandler( |
880 "css_natives", scoped_ptr<NativeHandler>(new CssNativeHandler(context))); | 881 "css_natives", |
| 882 std::unique_ptr<NativeHandler>(new CssNativeHandler(context))); |
881 module_system->RegisterNativeHandler( | 883 module_system->RegisterNativeHandler( |
882 "document_natives", | 884 "document_natives", |
883 scoped_ptr<NativeHandler>(new DocumentCustomBindings(context))); | 885 std::unique_ptr<NativeHandler>(new DocumentCustomBindings(context))); |
884 module_system->RegisterNativeHandler( | 886 module_system->RegisterNativeHandler( |
885 "guest_view_internal", | 887 "guest_view_internal", std::unique_ptr<NativeHandler>( |
886 scoped_ptr<NativeHandler>( | 888 new GuestViewInternalCustomBindings(context))); |
887 new GuestViewInternalCustomBindings(context))); | |
888 module_system->RegisterNativeHandler( | 889 module_system->RegisterNativeHandler( |
889 "id_generator", | 890 "id_generator", |
890 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 891 std::unique_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
891 module_system->RegisterNativeHandler( | 892 module_system->RegisterNativeHandler( |
892 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 893 "runtime", |
| 894 std::unique_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
893 module_system->RegisterNativeHandler( | 895 module_system->RegisterNativeHandler( |
894 "display_source", | 896 "display_source", |
895 scoped_ptr<NativeHandler>(new DisplaySourceCustomBindings(context))); | 897 std::unique_ptr<NativeHandler>(new DisplaySourceCustomBindings(context))); |
896 } | 898 } |
897 | 899 |
898 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 900 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
899 bool handled = true; | 901 bool handled = true; |
900 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 902 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
901 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 903 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
902 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 904 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
903 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 905 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
904 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 906 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
905 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 907 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 InitOriginPermissions(extension); | 990 InitOriginPermissions(extension); |
989 | 991 |
990 UpdateActiveExtensions(); | 992 UpdateActiveExtensions(); |
991 } | 993 } |
992 | 994 |
993 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { | 995 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { |
994 DispatchEvent(extension_id, kOnSuspendCanceledEvent); | 996 DispatchEvent(extension_id, kOnSuspendCanceledEvent); |
995 } | 997 } |
996 | 998 |
997 void Dispatcher::OnDeliverMessage(int target_port_id, const Message& message) { | 999 void Dispatcher::OnDeliverMessage(int target_port_id, const Message& message) { |
998 scoped_ptr<RequestSender::ScopedTabID> scoped_tab_id; | 1000 std::unique_ptr<RequestSender::ScopedTabID> scoped_tab_id; |
999 std::map<int, int>::const_iterator it = | 1001 std::map<int, int>::const_iterator it = |
1000 port_to_tab_id_map_.find(target_port_id); | 1002 port_to_tab_id_map_.find(target_port_id); |
1001 if (it != port_to_tab_id_map_.end()) { | 1003 if (it != port_to_tab_id_map_.end()) { |
1002 scoped_tab_id.reset( | 1004 scoped_tab_id.reset( |
1003 new RequestSender::ScopedTabID(request_sender(), it->second)); | 1005 new RequestSender::ScopedTabID(request_sender(), it->second)); |
1004 } | 1006 } |
1005 | 1007 |
1006 MessagingBindings::DeliverMessage(*script_context_set_, target_port_id, | 1008 MessagingBindings::DeliverMessage(*script_context_set_, target_port_id, |
1007 message, | 1009 message, |
1008 NULL); // All render frames. | 1010 NULL); // All render frames. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 // extension's URL just won't match anything anymore. | 1156 // extension's URL just won't match anything anymore. |
1155 } | 1157 } |
1156 | 1158 |
1157 void Dispatcher::OnUpdatePermissions( | 1159 void Dispatcher::OnUpdatePermissions( |
1158 const ExtensionMsg_UpdatePermissions_Params& params) { | 1160 const ExtensionMsg_UpdatePermissions_Params& params) { |
1159 const Extension* extension = | 1161 const Extension* extension = |
1160 RendererExtensionRegistry::Get()->GetByID(params.extension_id); | 1162 RendererExtensionRegistry::Get()->GetByID(params.extension_id); |
1161 if (!extension) | 1163 if (!extension) |
1162 return; | 1164 return; |
1163 | 1165 |
1164 scoped_ptr<const PermissionSet> active = | 1166 std::unique_ptr<const PermissionSet> active = |
1165 params.active_permissions.ToPermissionSet(); | 1167 params.active_permissions.ToPermissionSet(); |
1166 scoped_ptr<const PermissionSet> withheld = | 1168 std::unique_ptr<const PermissionSet> withheld = |
1167 params.withheld_permissions.ToPermissionSet(); | 1169 params.withheld_permissions.ToPermissionSet(); |
1168 | 1170 |
1169 UpdateOriginPermissions( | 1171 UpdateOriginPermissions( |
1170 extension->url(), | 1172 extension->url(), |
1171 extension->permissions_data()->GetEffectiveHostPermissions(), | 1173 extension->permissions_data()->GetEffectiveHostPermissions(), |
1172 active->effective_hosts()); | 1174 active->effective_hosts()); |
1173 | 1175 |
1174 extension->permissions_data()->SetPermissions(std::move(active), | 1176 extension->permissions_data()->SetPermissions(std::move(active), |
1175 std::move(withheld)); | 1177 std::move(withheld)); |
1176 UpdateBindings(extension->id()); | 1178 UpdateBindings(extension->id()); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 if (bind_object->HasRealNamedCallbackProperty(v8_bind_name)) | 1396 if (bind_object->HasRealNamedCallbackProperty(v8_bind_name)) |
1395 return; // lazy binding still there, nothing to do | 1397 return; // lazy binding still there, nothing to do |
1396 if (bind_object->Get(v8_bind_name)->IsObject()) | 1398 if (bind_object->Get(v8_bind_name)->IsObject()) |
1397 return; // binding has already been fully installed | 1399 return; // binding has already been fully installed |
1398 } | 1400 } |
1399 | 1401 |
1400 ModuleSystem* module_system = context->module_system(); | 1402 ModuleSystem* module_system = context->module_system(); |
1401 if (!source_map_.Contains(api_name)) { | 1403 if (!source_map_.Contains(api_name)) { |
1402 module_system->RegisterNativeHandler( | 1404 module_system->RegisterNativeHandler( |
1403 api_name, | 1405 api_name, |
1404 scoped_ptr<NativeHandler>(new BindingGeneratingNativeHandler( | 1406 std::unique_ptr<NativeHandler>( |
1405 context, api_name, "binding"))); | 1407 new BindingGeneratingNativeHandler(context, api_name, "binding"))); |
1406 module_system->SetNativeLazyField( | 1408 module_system->SetNativeLazyField( |
1407 bind_object, bind_name, api_name, "binding"); | 1409 bind_object, bind_name, api_name, "binding"); |
1408 } else { | 1410 } else { |
1409 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); | 1411 module_system->SetLazyField(bind_object, bind_name, api_name, "binding"); |
1410 } | 1412 } |
1411 } | 1413 } |
1412 | 1414 |
1413 // NOTE: please use the naming convention "foo_natives" for these. | 1415 // NOTE: please use the naming convention "foo_natives" for these. |
1414 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 1416 void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
1415 ScriptContext* context) { | 1417 ScriptContext* context) { |
1416 RegisterNativeHandlers(module_system, | 1418 RegisterNativeHandlers(module_system, |
1417 context, | 1419 context, |
1418 this, | 1420 this, |
1419 request_sender_.get(), | 1421 request_sender_.get(), |
1420 v8_schema_registry_.get()); | 1422 v8_schema_registry_.get()); |
1421 const Extension* extension = context->extension(); | 1423 const Extension* extension = context->extension(); |
1422 int manifest_version = extension ? extension->manifest_version() : 1; | 1424 int manifest_version = extension ? extension->manifest_version() : 1; |
1423 bool is_component_extension = | 1425 bool is_component_extension = |
1424 extension && Manifest::IsComponentLocation(extension->location()); | 1426 extension && Manifest::IsComponentLocation(extension->location()); |
1425 bool send_request_disabled = | 1427 bool send_request_disabled = |
1426 (extension && Manifest::IsUnpackedLocation(extension->location()) && | 1428 (extension && Manifest::IsUnpackedLocation(extension->location()) && |
1427 BackgroundInfo::HasLazyBackgroundPage(extension)); | 1429 BackgroundInfo::HasLazyBackgroundPage(extension)); |
1428 module_system->RegisterNativeHandler( | 1430 module_system->RegisterNativeHandler( |
1429 "process", | 1431 "process", |
1430 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( | 1432 std::unique_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
1431 context, | 1433 context, context->GetExtensionID(), |
1432 context->GetExtensionID(), | |
1433 context->GetContextTypeDescription(), | 1434 context->GetContextTypeDescription(), |
1434 ExtensionsRendererClient::Get()->IsIncognitoProcess(), | 1435 ExtensionsRendererClient::Get()->IsIncognitoProcess(), |
1435 is_component_extension, | 1436 is_component_extension, manifest_version, send_request_disabled))); |
1436 manifest_version, | |
1437 send_request_disabled))); | |
1438 | 1437 |
1439 delegate_->RegisterNativeHandlers(this, module_system, context); | 1438 delegate_->RegisterNativeHandlers(this, module_system, context); |
1440 } | 1439 } |
1441 | 1440 |
1442 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { | 1441 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
1443 for (const auto& extension : | 1442 for (const auto& extension : |
1444 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { | 1443 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
1445 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( | 1444 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
1446 extension->GetManifestData(manifest_keys::kExternallyConnectable)); | 1445 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
1447 if (info && info->matches.MatchesURL(context->url())) | 1446 if (info && info->matches.MatchesURL(context->url())) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 // The "guestViewDeny" module must always be loaded last. It registers | 1600 // The "guestViewDeny" module must always be loaded last. It registers |
1602 // error-providing custom elements for the GuestView types that are not | 1601 // error-providing custom elements for the GuestView types that are not |
1603 // available, and thus all of those types must have been checked and loaded | 1602 // available, and thus all of those types must have been checked and loaded |
1604 // (or not loaded) beforehand. | 1603 // (or not loaded) beforehand. |
1605 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { | 1604 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { |
1606 module_system->Require("guestViewDeny"); | 1605 module_system->Require("guestViewDeny"); |
1607 } | 1606 } |
1608 } | 1607 } |
1609 | 1608 |
1610 } // namespace extensions | 1609 } // namespace extensions |
OLD | NEW |