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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 #include "extensions/renderer/script_context.h" | 68 #include "extensions/renderer/script_context.h" |
69 #include "extensions/renderer/script_context_set.h" | 69 #include "extensions/renderer/script_context_set.h" |
70 #include "extensions/renderer/script_injection.h" | 70 #include "extensions/renderer/script_injection.h" |
71 #include "extensions/renderer/script_injection_manager.h" | 71 #include "extensions/renderer/script_injection_manager.h" |
72 #include "extensions/renderer/send_request_natives.h" | 72 #include "extensions/renderer/send_request_natives.h" |
73 #include "extensions/renderer/set_icon_natives.h" | 73 #include "extensions/renderer/set_icon_natives.h" |
74 #include "extensions/renderer/test_features_native_handler.h" | 74 #include "extensions/renderer/test_features_native_handler.h" |
75 #include "extensions/renderer/user_gestures_native_handler.h" | 75 #include "extensions/renderer/user_gestures_native_handler.h" |
76 #include "extensions/renderer/utils_native_handler.h" | 76 #include "extensions/renderer/utils_native_handler.h" |
77 #include "extensions/renderer/v8_context_native_handler.h" | 77 #include "extensions/renderer/v8_context_native_handler.h" |
| 78 #include "grit/content_resources.h" |
78 #include "grit/extensions_renderer_resources.h" | 79 #include "grit/extensions_renderer_resources.h" |
| 80 #include "mojo/public/js/bindings/constants.h" |
79 #include "third_party/WebKit/public/platform/WebString.h" | 81 #include "third_party/WebKit/public/platform/WebString.h" |
80 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 82 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
81 #include "third_party/WebKit/public/web/WebCustomElement.h" | 83 #include "third_party/WebKit/public/web/WebCustomElement.h" |
82 #include "third_party/WebKit/public/web/WebDataSource.h" | 84 #include "third_party/WebKit/public/web/WebDataSource.h" |
83 #include "third_party/WebKit/public/web/WebDocument.h" | 85 #include "third_party/WebKit/public/web/WebDocument.h" |
84 #include "third_party/WebKit/public/web/WebFrame.h" | 86 #include "third_party/WebKit/public/web/WebFrame.h" |
85 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 87 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
86 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 88 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
87 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 89 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
88 #include "third_party/WebKit/public/web/WebView.h" | 90 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 447 } |
446 } | 448 } |
447 | 449 |
448 void Dispatcher::ClearPortData(int port_id) { | 450 void Dispatcher::ClearPortData(int port_id) { |
449 // Only the target port side has entries in |port_to_tab_id_map_|. If | 451 // Only the target port side has entries in |port_to_tab_id_map_|. If |
450 // |port_id| is a source port, std::map::erase() will just silently fail | 452 // |port_id| is a source port, std::map::erase() will just silently fail |
451 // here as a no-op. | 453 // here as a no-op. |
452 port_to_tab_id_map_.erase(port_id); | 454 port_to_tab_id_map_.erase(port_id); |
453 } | 455 } |
454 | 456 |
| 457 // static |
| 458 std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() { |
| 459 std::vector<std::pair<std::string, int> > resources; |
| 460 |
| 461 // Libraries. |
| 462 resources.push_back(std::make_pair("entryIdManager", IDR_ENTRY_ID_MANAGER)); |
| 463 resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS)); |
| 464 resources.push_back(std::make_pair("imageUtil", IDR_IMAGE_UTIL_JS)); |
| 465 resources.push_back(std::make_pair("json_schema", IDR_JSON_SCHEMA_JS)); |
| 466 resources.push_back(std::make_pair("lastError", IDR_LAST_ERROR_JS)); |
| 467 resources.push_back(std::make_pair("messaging", IDR_MESSAGING_JS)); |
| 468 resources.push_back( |
| 469 std::make_pair("messaging_utils", IDR_MESSAGING_UTILS_JS)); |
| 470 resources.push_back(std::make_pair(kSchemaUtils, IDR_SCHEMA_UTILS_JS)); |
| 471 resources.push_back(std::make_pair("sendRequest", IDR_SEND_REQUEST_JS)); |
| 472 resources.push_back(std::make_pair("setIcon", IDR_SET_ICON_JS)); |
| 473 resources.push_back(std::make_pair("test", IDR_TEST_CUSTOM_BINDINGS_JS)); |
| 474 resources.push_back( |
| 475 std::make_pair("test_delegate", IDR_TEST_CUSTOM_BINDINGS_DELEGATE_JS)); |
| 476 resources.push_back(std::make_pair("uncaught_exception_handler", |
| 477 IDR_UNCAUGHT_EXCEPTION_HANDLER_JS)); |
| 478 resources.push_back(std::make_pair("unload_event", IDR_UNLOAD_EVENT_JS)); |
| 479 resources.push_back(std::make_pair("utils", IDR_UTILS_JS)); |
| 480 resources.push_back( |
| 481 std::make_pair(mojo::kCodecModuleName, IDR_MOJO_CODEC_JS)); |
| 482 resources.push_back( |
| 483 std::make_pair(mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS)); |
| 484 resources.push_back( |
| 485 std::make_pair(mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS)); |
| 486 resources.push_back( |
| 487 std::make_pair(mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS)); |
| 488 resources.push_back( |
| 489 std::make_pair(mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS)); |
| 490 |
| 491 // Custom bindings. |
| 492 resources.push_back( |
| 493 std::make_pair("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS)); |
| 494 resources.push_back( |
| 495 std::make_pair("contextMenus", IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS)); |
| 496 resources.push_back( |
| 497 std::make_pair("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS)); |
| 498 resources.push_back(std::make_pair("i18n", IDR_I18N_CUSTOM_BINDINGS_JS)); |
| 499 resources.push_back( |
| 500 std::make_pair("permissions", IDR_PERMISSIONS_CUSTOM_BINDINGS_JS)); |
| 501 resources.push_back( |
| 502 std::make_pair("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS)); |
| 503 resources.push_back(std::make_pair("binding", IDR_BINDING_JS)); |
| 504 |
| 505 // Custom types sources. |
| 506 resources.push_back(std::make_pair("StorageArea", IDR_STORAGE_AREA_JS)); |
| 507 |
| 508 // Platform app sources that are not API-specific.. |
| 509 resources.push_back(std::make_pair("platformApp", IDR_PLATFORM_APP_JS)); |
| 510 |
| 511 return resources; |
| 512 } |
| 513 |
455 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 514 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
456 bool handled = true; | 515 bool handled = true; |
457 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 516 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
458 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 517 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
459 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 518 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
460 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, | 519 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, |
461 OnClearTabSpecificPermissions) | 520 OnClearTabSpecificPermissions) |
462 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 521 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
463 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 522 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
464 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 523 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 module_system->RegisterNativeHandler( | 1073 module_system->RegisterNativeHandler( |
1015 "id_generator", | 1074 "id_generator", |
1016 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 1075 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
1017 module_system->RegisterNativeHandler( | 1076 module_system->RegisterNativeHandler( |
1018 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 1077 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
1019 | 1078 |
1020 delegate_->RegisterNativeHandlers(this, module_system, context); | 1079 delegate_->RegisterNativeHandlers(this, module_system, context); |
1021 } | 1080 } |
1022 | 1081 |
1023 void Dispatcher::PopulateSourceMap() { | 1082 void Dispatcher::PopulateSourceMap() { |
1024 // Libraries. | 1083 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1025 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); | 1084 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1026 source_map_.RegisterSource(kEventBindings, IDR_EVENT_BINDINGS_JS); | 1085 resources.begin(); |
1027 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); | 1086 resource != resources.end(); |
1028 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 1087 ++resource) { |
1029 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 1088 source_map_.RegisterSource(resource->first, resource->second); |
1030 source_map_.RegisterSource("messaging", IDR_MESSAGING_JS); | 1089 } |
1031 source_map_.RegisterSource("messaging_utils", IDR_MESSAGING_UTILS_JS); | |
1032 source_map_.RegisterSource(kSchemaUtils, IDR_SCHEMA_UTILS_JS); | |
1033 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | |
1034 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | |
1035 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS); | |
1036 source_map_.RegisterSource("uncaught_exception_handler", | |
1037 IDR_UNCAUGHT_EXCEPTION_HANDLER_JS); | |
1038 source_map_.RegisterSource("unload_event", IDR_UNLOAD_EVENT_JS); | |
1039 source_map_.RegisterSource("utils", IDR_UTILS_JS); | |
1040 | |
1041 // Custom bindings. | |
1042 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); | |
1043 source_map_.RegisterSource("contextMenus", | |
1044 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); | |
1045 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS); | |
1046 source_map_.RegisterSource("i18n", IDR_I18N_CUSTOM_BINDINGS_JS); | |
1047 source_map_.RegisterSource("permissions", IDR_PERMISSIONS_CUSTOM_BINDINGS_JS); | |
1048 source_map_.RegisterSource("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS); | |
1049 source_map_.RegisterSource("binding", IDR_BINDING_JS); | |
1050 | |
1051 // Custom types sources. | |
1052 source_map_.RegisterSource("StorageArea", IDR_STORAGE_AREA_JS); | |
1053 | |
1054 // Platform app sources that are not API-specific.. | |
1055 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | |
1056 | |
1057 delegate_->PopulateSourceMap(&source_map_); | 1090 delegate_->PopulateSourceMap(&source_map_); |
1058 } | 1091 } |
1059 | 1092 |
1060 bool Dispatcher::IsWithinPlatformApp() { | 1093 bool Dispatcher::IsWithinPlatformApp() { |
1061 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 1094 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
1062 iter != active_extension_ids_.end(); | 1095 iter != active_extension_ids_.end(); |
1063 ++iter) { | 1096 ++iter) { |
1064 const Extension* extension = extensions_.GetByID(*iter); | 1097 const Extension* extension = extensions_.GetByID(*iter); |
1065 if (extension && extension->is_platform_app()) | 1098 if (extension && extension->is_platform_app()) |
1066 return true; | 1099 return true; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 return v8::Handle<v8::Object>(); | 1230 return v8::Handle<v8::Object>(); |
1198 | 1231 |
1199 if (bind_name) | 1232 if (bind_name) |
1200 *bind_name = split.back(); | 1233 *bind_name = split.back(); |
1201 | 1234 |
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1235 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1203 : bind_object; | 1236 : bind_object; |
1204 } | 1237 } |
1205 | 1238 |
1206 } // namespace extensions | 1239 } // namespace extensions |
OLD | NEW |