OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
11 #include "chrome/common/child_process_logging.h" | 11 #include "chrome/common/child_process_logging.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
14 #include "chrome/common/extensions/api/extension_api.h" | 14 #include "chrome/common/extensions/api/extension_api.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_messages.h" | 16 #include "chrome/common/extensions/extension_messages.h" |
17 #include "chrome/common/extensions/permissions/permission_set.h" | 17 #include "chrome/common/extensions/permissions/permission_set.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/common/view_type.h" | 19 #include "chrome/common/view_type.h" |
20 #include "chrome/renderer/chrome_render_process_observer.h" | 20 #include "chrome/renderer/chrome_render_process_observer.h" |
21 #include "chrome/renderer/extensions/api_definitions_natives.h" | 21 #include "chrome/renderer/extensions/api_definitions_natives.h" |
22 #include "chrome/renderer/extensions/app_bindings.h" | 22 #include "chrome/renderer/extensions/app_bindings.h" |
23 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" | 23 #include "chrome/renderer/extensions/app_runtime_custom_bindings.h" |
24 #include "chrome/renderer/extensions/app_window_custom_bindings.h" | 24 #include "chrome/renderer/extensions/app_window_custom_bindings.h" |
25 #include "chrome/renderer/extensions/chrome_v8_context.h" | 25 #include "chrome/renderer/extensions/chrome_v8_context.h" |
26 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 26 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 27 #include "chrome/renderer/extensions/content_watcher.h" |
27 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | 28 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
28 #include "chrome/renderer/extensions/event_bindings.h" | 29 #include "chrome/renderer/extensions/event_bindings.h" |
29 #include "chrome/renderer/extensions/extension_custom_bindings.h" | 30 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
30 #include "chrome/renderer/extensions/extension_groups.h" | 31 #include "chrome/renderer/extensions/extension_groups.h" |
31 #include "chrome/renderer/extensions/extension_helper.h" | 32 #include "chrome/renderer/extensions/extension_helper.h" |
32 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 33 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
33 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | 34 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
34 #include "chrome/renderer/extensions/file_system_natives.h" | 35 #include "chrome/renderer/extensions/file_system_natives.h" |
35 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | 36 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
36 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" | 37 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 global->Set(chrome_string, chrome_object); | 308 global->Set(chrome_string, chrome_object); |
308 return chrome_object; | 309 return chrome_object; |
309 } | 310 } |
310 CHECK(chrome->IsObject()); | 311 CHECK(chrome->IsObject()); |
311 return chrome->ToObject(); | 312 return chrome->ToObject(); |
312 } | 313 } |
313 | 314 |
314 } // namespace | 315 } // namespace |
315 | 316 |
316 Dispatcher::Dispatcher() | 317 Dispatcher::Dispatcher() |
317 : is_webkit_initialized_(false), | 318 : content_watcher_(new ContentWatcher(this)), |
| 319 is_webkit_initialized_(false), |
318 webrequest_adblock_(false), | 320 webrequest_adblock_(false), |
319 webrequest_adblock_plus_(false), | 321 webrequest_adblock_plus_(false), |
320 webrequest_other_(false), | 322 webrequest_other_(false), |
321 source_map_(&ResourceBundle::GetSharedInstance()) { | 323 source_map_(&ResourceBundle::GetSharedInstance()) { |
322 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 324 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
323 is_extension_process_ = | 325 is_extension_process_ = |
324 command_line.HasSwitch(switches::kExtensionProcess) || | 326 command_line.HasSwitch(switches::kExtensionProcess) || |
325 command_line.HasSwitch(switches::kSingleProcess); | 327 command_line.HasSwitch(switches::kSingleProcess); |
326 | 328 |
327 if (is_extension_process_) { | 329 if (is_extension_process_) { |
(...skipping 28 matching lines...) Expand all Loading... |
356 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 358 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
357 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, | 359 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, |
358 OnUpdateTabSpecificPermissions) | 360 OnUpdateTabSpecificPermissions) |
359 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, | 361 IPC_MESSAGE_HANDLER(ExtensionMsg_ClearTabSpecificPermissions, |
360 OnClearTabSpecificPermissions) | 362 OnClearTabSpecificPermissions) |
361 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 363 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
362 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 364 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
363 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldUnload, OnShouldUnload) | 365 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldUnload, OnShouldUnload) |
364 IPC_MESSAGE_HANDLER(ExtensionMsg_Unload, OnUnload) | 366 IPC_MESSAGE_HANDLER(ExtensionMsg_Unload, OnUnload) |
365 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelUnload, OnCancelUnload) | 367 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelUnload, OnCancelUnload) |
| 368 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, |
| 369 content_watcher_.get(), ContentWatcher::OnWatchPages) |
366 IPC_MESSAGE_UNHANDLED(handled = false) | 370 IPC_MESSAGE_UNHANDLED(handled = false) |
367 IPC_END_MESSAGE_MAP() | 371 IPC_END_MESSAGE_MAP() |
368 | 372 |
369 return handled; | 373 return handled; |
370 } | 374 } |
371 | 375 |
372 void Dispatcher::WebKitInitialized() { | 376 void Dispatcher::WebKitInitialized() { |
373 // For extensions, we want to ensure we call the IdleHandler every so often, | 377 // For extensions, we want to ensure we call the IdleHandler every so often, |
374 // even if the extension keeps up activity. | 378 // even if the extension keeps up activity. |
375 if (is_extension_process_) { | 379 if (is_extension_process_) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 module_system->RegisterNativeHandler("miscellaneous_bindings", | 561 module_system->RegisterNativeHandler("miscellaneous_bindings", |
558 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 562 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
559 module_system->RegisterNativeHandler("apiDefinitions", | 563 module_system->RegisterNativeHandler("apiDefinitions", |
560 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); | 564 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); |
561 module_system->RegisterNativeHandler("sendRequest", | 565 module_system->RegisterNativeHandler("sendRequest", |
562 scoped_ptr<NativeHandler>( | 566 scoped_ptr<NativeHandler>( |
563 new SendRequestNatives(this, request_sender_.get()))); | 567 new SendRequestNatives(this, request_sender_.get()))); |
564 module_system->RegisterNativeHandler("setIcon", | 568 module_system->RegisterNativeHandler("setIcon", |
565 scoped_ptr<NativeHandler>( | 569 scoped_ptr<NativeHandler>( |
566 new SetIconNatives(this, request_sender_.get()))); | 570 new SetIconNatives(this, request_sender_.get()))); |
| 571 module_system->RegisterNativeHandler("contentWatcherNative", |
| 572 content_watcher_->MakeNatives()); |
567 | 573 |
568 // Natives used by multiple APIs. | 574 // Natives used by multiple APIs. |
569 module_system->RegisterNativeHandler("file_system_natives", | 575 module_system->RegisterNativeHandler("file_system_natives", |
570 scoped_ptr<NativeHandler>(new FileSystemNatives())); | 576 scoped_ptr<NativeHandler>(new FileSystemNatives())); |
571 | 577 |
572 // Custom bindings. | 578 // Custom bindings. |
573 module_system->RegisterNativeHandler("app", | 579 module_system->RegisterNativeHandler("app", |
574 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | 580 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
575 module_system->RegisterNativeHandler("app_runtime", | 581 module_system->RegisterNativeHandler("app_runtime", |
576 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings())); | 582 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 void Dispatcher::PopulateSourceMap() { | 617 void Dispatcher::PopulateSourceMap() { |
612 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 618 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
613 source_map_.RegisterSource("miscellaneous_bindings", | 619 source_map_.RegisterSource("miscellaneous_bindings", |
614 IDR_MISCELLANEOUS_BINDINGS_JS); | 620 IDR_MISCELLANEOUS_BINDINGS_JS); |
615 source_map_.RegisterSource("schema_generated_bindings", | 621 source_map_.RegisterSource("schema_generated_bindings", |
616 IDR_SCHEMA_GENERATED_BINDINGS_JS); | 622 IDR_SCHEMA_GENERATED_BINDINGS_JS); |
617 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 623 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
618 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 624 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); |
619 | 625 |
620 // Libraries. | 626 // Libraries. |
| 627 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS); |
621 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); | 628 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); |
622 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); | 629 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); |
623 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); | 630 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); |
624 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); | 631 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); |
625 source_map_.RegisterSource("utils", IDR_UTILS_JS); | 632 source_map_.RegisterSource("utils", IDR_UTILS_JS); |
626 | 633 |
627 // Custom bindings. | 634 // Custom bindings. |
628 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); | 635 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); |
629 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); | 636 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); |
630 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); | 637 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); |
631 source_map_.RegisterSource("bluetooth", IDR_BLUETOOTH_CUSTOM_BINDINGS_JS); | 638 source_map_.RegisterSource("bluetooth", IDR_BLUETOOTH_CUSTOM_BINDINGS_JS); |
632 source_map_.RegisterSource("browserAction", | 639 source_map_.RegisterSource("browserAction", |
633 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); | 640 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); |
634 source_map_.RegisterSource("contentSettings", | 641 source_map_.RegisterSource("contentSettings", |
635 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); | 642 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); |
636 source_map_.RegisterSource("contextMenus", | 643 source_map_.RegisterSource("contextMenus", |
637 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); | 644 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); |
| 645 source_map_.RegisterSource("declarativeContent", |
| 646 IDR_DECLARATIVE_CONTENT_CUSTOM_BINDINGS_JS); |
638 source_map_.RegisterSource("declarativeWebRequest", | 647 source_map_.RegisterSource("declarativeWebRequest", |
639 IDR_DECLARATIVE_WEBREQUEST_CUSTOM_BINDINGS_JS); | 648 IDR_DECLARATIVE_WEBREQUEST_CUSTOM_BINDINGS_JS); |
640 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); | 649 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); |
641 source_map_.RegisterSource( | 650 source_map_.RegisterSource( |
642 "experimental.mediaGalleries", | 651 "experimental.mediaGalleries", |
643 IDR_EXPERIMENTAL_MEDIA_GALLERIES_CUSTOM_BINDINGS_JS); | 652 IDR_EXPERIMENTAL_MEDIA_GALLERIES_CUSTOM_BINDINGS_JS); |
644 source_map_.RegisterSource("experimental.offscreen", | 653 source_map_.RegisterSource("experimental.offscreen", |
645 IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS); | 654 IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS); |
646 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS); | 655 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS); |
647 source_map_.RegisterSource("fileBrowserHandler", | 656 source_map_.RegisterSource("fileBrowserHandler", |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { | 869 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { |
861 if (IsWithinPlatformApp(frame)) { | 870 if (IsWithinPlatformApp(frame)) { |
862 // WebKit doesn't let us define an additional user agent stylesheet, so we | 871 // WebKit doesn't let us define an additional user agent stylesheet, so we |
863 // insert the default platform app stylesheet into all documents that are | 872 // insert the default platform app stylesheet into all documents that are |
864 // loaded in each app. | 873 // loaded in each app. |
865 frame->document().insertUserStyleSheet( | 874 frame->document().insertUserStyleSheet( |
866 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). | 875 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). |
867 GetRawDataResource(IDR_PLATFORM_APP_CSS)), | 876 GetRawDataResource(IDR_PLATFORM_APP_CSS)), |
868 WebDocument::UserStyleUserLevel); | 877 WebDocument::UserStyleUserLevel); |
869 } | 878 } |
| 879 |
| 880 content_watcher_->DidCreateDocumentElement(frame); |
870 } | 881 } |
871 | 882 |
872 void Dispatcher::OnActivateExtension(const std::string& extension_id) { | 883 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
873 active_extension_ids_.insert(extension_id); | 884 active_extension_ids_.insert(extension_id); |
874 const Extension* extension = extensions_.GetByID(extension_id); | 885 const Extension* extension = extensions_.GetByID(extension_id); |
875 CHECK(extension); | 886 CHECK(extension); |
876 | 887 |
877 // This is called when starting a new extension page, so start the idle | 888 // This is called when starting a new extension page, so start the idle |
878 // handler ticking. | 889 // handler ticking. |
879 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 890 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 1142 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
1132 v8::ThrowException( | 1143 v8::ThrowException( |
1133 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 1144 v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
1134 return false; | 1145 return false; |
1135 } | 1146 } |
1136 | 1147 |
1137 return true; | 1148 return true; |
1138 } | 1149 } |
1139 | 1150 |
1140 } // namespace extensions | 1151 } // namespace extensions |
OLD | NEW |