Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: extensions/renderer/dispatcher.cc

Issue 399363002: Add support for writing unit tests for Mojo-backed apps/extensions APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 458 }
457 } 459 }
458 460
459 void Dispatcher::ClearPortData(int port_id) { 461 void Dispatcher::ClearPortData(int port_id) {
460 // Only the target port side has entries in |port_to_tab_id_map_|. If 462 // Only the target port side has entries in |port_to_tab_id_map_|. If
461 // |port_id| is a source port, std::map::erase() will just silently fail 463 // |port_id| is a source port, std::map::erase() will just silently fail
462 // here as a no-op. 464 // here as a no-op.
463 port_to_tab_id_map_.erase(port_id); 465 port_to_tab_id_map_.erase(port_id);
464 } 466 }
465 467
468 // static
469 std::vector<std::pair<std::string, int> > Dispatcher::GetJsResources() {
470 std::vector<std::pair<std::string, int> > resources;
471
472 // Libraries.
473 resources.push_back(std::make_pair("entryIdManager", IDR_ENTRY_ID_MANAGER));
474 resources.push_back(std::make_pair(kEventBindings, IDR_EVENT_BINDINGS_JS));
475 resources.push_back(std::make_pair("imageUtil", IDR_IMAGE_UTIL_JS));
476 resources.push_back(std::make_pair("json_schema", IDR_JSON_SCHEMA_JS));
477 resources.push_back(std::make_pair("lastError", IDR_LAST_ERROR_JS));
478 resources.push_back(std::make_pair("messaging", IDR_MESSAGING_JS));
479 resources.push_back(
480 std::make_pair("messaging_utils", IDR_MESSAGING_UTILS_JS));
481 resources.push_back(std::make_pair(kSchemaUtils, IDR_SCHEMA_UTILS_JS));
482 resources.push_back(std::make_pair("sendRequest", IDR_SEND_REQUEST_JS));
483 resources.push_back(std::make_pair("setIcon", IDR_SET_ICON_JS));
484 resources.push_back(std::make_pair("test", IDR_TEST_CUSTOM_BINDINGS_JS));
485 resources.push_back(
486 std::make_pair("test_environment_specific_bindings",
487 IDR_BROWSER_TEST_ENVIRONMENT_SPECIFIC_BINDINGS_JS));
488 resources.push_back(std::make_pair("uncaught_exception_handler",
489 IDR_UNCAUGHT_EXCEPTION_HANDLER_JS));
490 resources.push_back(std::make_pair("unload_event", IDR_UNLOAD_EVENT_JS));
491 resources.push_back(std::make_pair("utils", IDR_UTILS_JS));
492 resources.push_back(
493 std::make_pair(mojo::kCodecModuleName, IDR_MOJO_CODEC_JS));
not at google - send to devlin 2014/07/25 00:17:57 this mojo stuff is new. will it be needed outside
Sam McNally 2014/07/25 07:38:59 They will eventually, but not yet.
494 resources.push_back(
495 std::make_pair(mojo::kConnectionModuleName, IDR_MOJO_CONNECTION_JS));
496 resources.push_back(
497 std::make_pair(mojo::kConnectorModuleName, IDR_MOJO_CONNECTOR_JS));
498 resources.push_back(
499 std::make_pair(mojo::kRouterModuleName, IDR_MOJO_ROUTER_JS));
500 resources.push_back(
501 std::make_pair(mojo::kUnicodeModuleName, IDR_MOJO_UNICODE_JS));
502
503 // Custom bindings.
504 resources.push_back(
505 std::make_pair("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS));
506 resources.push_back(
507 std::make_pair("contextMenus", IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS));
508 resources.push_back(
509 std::make_pair("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS));
510 resources.push_back(std::make_pair("i18n", IDR_I18N_CUSTOM_BINDINGS_JS));
511 resources.push_back(
512 std::make_pair("permissions", IDR_PERMISSIONS_CUSTOM_BINDINGS_JS));
513 resources.push_back(
514 std::make_pair("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS));
515 resources.push_back(std::make_pair("binding", IDR_BINDING_JS));
516
517 // Custom types sources.
518 resources.push_back(std::make_pair("StorageArea", IDR_STORAGE_AREA_JS));
519
520 // Platform app sources that are not API-specific..
521 resources.push_back(std::make_pair("platformApp", IDR_PLATFORM_APP_JS));
522
523 return resources;
524 }
525
466 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { 526 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) {
467 bool handled = true; 527 bool handled = true;
468 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) 528 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message)
469 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) 529 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension)
470 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) 530 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend)
471 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, 531 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions,
472 OnClearTabSpecificPermissions) 532 OnClearTabSpecificPermissions)
473 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) 533 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage)
474 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) 534 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect)
475 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) 535 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect)
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 module_system->RegisterNativeHandler( 1111 module_system->RegisterNativeHandler(
1052 "id_generator", 1112 "id_generator",
1053 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); 1113 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context)));
1054 module_system->RegisterNativeHandler( 1114 module_system->RegisterNativeHandler(
1055 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); 1115 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context)));
1056 1116
1057 delegate_->RegisterNativeHandlers(this, module_system, context); 1117 delegate_->RegisterNativeHandlers(this, module_system, context);
1058 } 1118 }
1059 1119
1060 void Dispatcher::PopulateSourceMap() { 1120 void Dispatcher::PopulateSourceMap() {
1061 // Libraries. 1121 const std::vector<std::pair<std::string, int> > resources = GetJsResources();
1062 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); 1122 for (std::vector<std::pair<std::string, int> >::const_iterator resource =
1063 source_map_.RegisterSource(kEventBindings, IDR_EVENT_BINDINGS_JS); 1123 resources.begin();
1064 source_map_.RegisterSource("imageUtil", IDR_IMAGE_UTIL_JS); 1124 resource != resources.end();
1065 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); 1125 ++resource) {
1066 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); 1126 source_map_.RegisterSource(resource->first, resource->second);
1067 source_map_.RegisterSource("messaging", IDR_MESSAGING_JS); 1127 }
1068 source_map_.RegisterSource("messaging_utils", IDR_MESSAGING_UTILS_JS);
1069 source_map_.RegisterSource(kSchemaUtils, IDR_SCHEMA_UTILS_JS);
1070 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS);
1071 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS);
1072 source_map_.RegisterSource("test", IDR_TEST_CUSTOM_BINDINGS_JS);
1073 source_map_.RegisterSource("uncaught_exception_handler",
1074 IDR_UNCAUGHT_EXCEPTION_HANDLER_JS);
1075 source_map_.RegisterSource("unload_event", IDR_UNLOAD_EVENT_JS);
1076 source_map_.RegisterSource("utils", IDR_UTILS_JS);
1077
1078 // Custom bindings.
1079 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS);
1080 source_map_.RegisterSource("contextMenus",
1081 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS);
1082 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS);
1083 source_map_.RegisterSource("i18n", IDR_I18N_CUSTOM_BINDINGS_JS);
1084 source_map_.RegisterSource("permissions", IDR_PERMISSIONS_CUSTOM_BINDINGS_JS);
1085 source_map_.RegisterSource("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS);
1086 source_map_.RegisterSource("binding", IDR_BINDING_JS);
1087
1088 // Custom types sources.
1089 source_map_.RegisterSource("StorageArea", IDR_STORAGE_AREA_JS);
1090
1091 // Platform app sources that are not API-specific..
1092 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS);
1093
1094 delegate_->PopulateSourceMap(&source_map_); 1128 delegate_->PopulateSourceMap(&source_map_);
1095 } 1129 }
1096 1130
1097 bool Dispatcher::IsWithinPlatformApp() { 1131 bool Dispatcher::IsWithinPlatformApp() {
1098 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 1132 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
1099 iter != active_extension_ids_.end(); 1133 iter != active_extension_ids_.end();
1100 ++iter) { 1134 ++iter) {
1101 const Extension* extension = extensions_.GetByID(*iter); 1135 const Extension* extension = extensions_.GetByID(*iter);
1102 if (extension && extension->is_platform_app()) 1136 if (extension && extension->is_platform_app())
1103 return true; 1137 return true;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 return v8::Handle<v8::Object>(); 1268 return v8::Handle<v8::Object>();
1235 1269
1236 if (bind_name) 1270 if (bind_name)
1237 *bind_name = split.back(); 1271 *bind_name = split.back();
1238 1272
1239 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1273 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1240 : bind_object; 1274 : bind_object;
1241 } 1275 }
1242 1276
1243 } // namespace extensions 1277 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698