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

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

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync past refactoring and fix build+tests Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/module_system.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 module_system->RegisterNativeHandler("miscellaneous_bindings", 563 module_system->RegisterNativeHandler("miscellaneous_bindings",
560 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); 564 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this)));
561 module_system->RegisterNativeHandler("apiDefinitions", 565 module_system->RegisterNativeHandler("apiDefinitions",
562 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this))); 566 scoped_ptr<NativeHandler>(new ApiDefinitionsNatives(this)));
563 module_system->RegisterNativeHandler("sendRequest", 567 module_system->RegisterNativeHandler("sendRequest",
564 scoped_ptr<NativeHandler>( 568 scoped_ptr<NativeHandler>(
565 new SendRequestNatives(this, request_sender_.get()))); 569 new SendRequestNatives(this, request_sender_.get())));
566 module_system->RegisterNativeHandler("setIcon", 570 module_system->RegisterNativeHandler("setIcon",
567 scoped_ptr<NativeHandler>( 571 scoped_ptr<NativeHandler>(
568 new SetIconNatives(this, request_sender_.get()))); 572 new SetIconNatives(this, request_sender_.get())));
573 module_system->RegisterNativeHandler("contentWatcherNative",
574 content_watcher_->MakeNatives());
569 575
570 // Natives used by multiple APIs. 576 // Natives used by multiple APIs.
571 module_system->RegisterNativeHandler("file_system_natives", 577 module_system->RegisterNativeHandler("file_system_natives",
572 scoped_ptr<NativeHandler>(new FileSystemNatives())); 578 scoped_ptr<NativeHandler>(new FileSystemNatives()));
573 579
574 // Custom bindings. 580 // Custom bindings.
575 module_system->RegisterNativeHandler("app", 581 module_system->RegisterNativeHandler("app",
576 scoped_ptr<NativeHandler>(new AppBindings(this, context))); 582 scoped_ptr<NativeHandler>(new AppBindings(this, context)));
577 module_system->RegisterNativeHandler("app_runtime", 583 module_system->RegisterNativeHandler("app_runtime",
578 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings())); 584 scoped_ptr<NativeHandler>(new AppRuntimeCustomBindings()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 void Dispatcher::PopulateSourceMap() { 619 void Dispatcher::PopulateSourceMap() {
614 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); 620 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS);
615 source_map_.RegisterSource("miscellaneous_bindings", 621 source_map_.RegisterSource("miscellaneous_bindings",
616 IDR_MISCELLANEOUS_BINDINGS_JS); 622 IDR_MISCELLANEOUS_BINDINGS_JS);
617 source_map_.RegisterSource("schema_generated_bindings", 623 source_map_.RegisterSource("schema_generated_bindings",
618 IDR_SCHEMA_GENERATED_BINDINGS_JS); 624 IDR_SCHEMA_GENERATED_BINDINGS_JS);
619 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); 625 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS);
620 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); 626 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS);
621 627
622 // Libraries. 628 // Libraries.
629 source_map_.RegisterSource("contentWatcher", IDR_CONTENT_WATCHER_JS);
623 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS); 630 source_map_.RegisterSource("lastError", IDR_LAST_ERROR_JS);
624 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS); 631 source_map_.RegisterSource("schemaUtils", IDR_SCHEMA_UTILS_JS);
625 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS); 632 source_map_.RegisterSource("sendRequest", IDR_SEND_REQUEST_JS);
626 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS); 633 source_map_.RegisterSource("setIcon", IDR_SET_ICON_JS);
627 source_map_.RegisterSource("utils", IDR_UTILS_JS); 634 source_map_.RegisterSource("utils", IDR_UTILS_JS);
628 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER); 635 source_map_.RegisterSource("entryIdManager", IDR_ENTRY_ID_MANAGER);
629 636
630 // Custom bindings. 637 // Custom bindings.
631 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); 638 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS);
632 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS); 639 source_map_.RegisterSource("app.runtime", IDR_APP_RUNTIME_CUSTOM_BINDINGS_JS);
633 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); 640 source_map_.RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS);
634 source_map_.RegisterSource("bluetooth", IDR_BLUETOOTH_CUSTOM_BINDINGS_JS); 641 source_map_.RegisterSource("bluetooth", IDR_BLUETOOTH_CUSTOM_BINDINGS_JS);
635 source_map_.RegisterSource("browserAction", 642 source_map_.RegisterSource("browserAction",
636 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); 643 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS);
637 source_map_.RegisterSource("contentSettings", 644 source_map_.RegisterSource("contentSettings",
638 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); 645 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS);
639 source_map_.RegisterSource("contextMenus", 646 source_map_.RegisterSource("contextMenus",
640 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); 647 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS);
648 source_map_.RegisterSource("declarativeContent",
649 IDR_DECLARATIVE_CONTENT_CUSTOM_BINDINGS_JS);
641 source_map_.RegisterSource("declarativeWebRequest", 650 source_map_.RegisterSource("declarativeWebRequest",
642 IDR_DECLARATIVE_WEBREQUEST_CUSTOM_BINDINGS_JS); 651 IDR_DECLARATIVE_WEBREQUEST_CUSTOM_BINDINGS_JS);
643 source_map_.RegisterSource( 652 source_map_.RegisterSource(
644 "experimental.mediaGalleries", 653 "experimental.mediaGalleries",
645 IDR_EXPERIMENTAL_MEDIA_GALLERIES_CUSTOM_BINDINGS_JS); 654 IDR_EXPERIMENTAL_MEDIA_GALLERIES_CUSTOM_BINDINGS_JS);
646 source_map_.RegisterSource("experimental.offscreen", 655 source_map_.RegisterSource("experimental.offscreen",
647 IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS); 656 IDR_EXPERIMENTAL_OFFSCREENTABS_CUSTOM_BINDINGS_JS);
648 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS); 657 source_map_.RegisterSource("extension", IDR_EXTENSION_CUSTOM_BINDINGS_JS);
649 source_map_.RegisterSource("fileBrowserHandler", 658 source_map_.RegisterSource("fileBrowserHandler",
650 IDR_FILE_BROWSER_HANDLER_CUSTOM_BINDINGS_JS); 659 IDR_FILE_BROWSER_HANDLER_CUSTOM_BINDINGS_JS);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) { 871 void Dispatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) {
863 if (IsWithinPlatformApp(frame)) { 872 if (IsWithinPlatformApp(frame)) {
864 // WebKit doesn't let us define an additional user agent stylesheet, so we 873 // WebKit doesn't let us define an additional user agent stylesheet, so we
865 // insert the default platform app stylesheet into all documents that are 874 // insert the default platform app stylesheet into all documents that are
866 // loaded in each app. 875 // loaded in each app.
867 frame->document().insertUserStyleSheet( 876 frame->document().insertUserStyleSheet(
868 WebString::fromUTF8(ResourceBundle::GetSharedInstance(). 877 WebString::fromUTF8(ResourceBundle::GetSharedInstance().
869 GetRawDataResource(IDR_PLATFORM_APP_CSS)), 878 GetRawDataResource(IDR_PLATFORM_APP_CSS)),
870 WebDocument::UserStyleUserLevel); 879 WebDocument::UserStyleUserLevel);
871 } 880 }
881
882 content_watcher_->DidCreateDocumentElement(frame);
872 } 883 }
873 884
874 void Dispatcher::OnActivateExtension(const std::string& extension_id) { 885 void Dispatcher::OnActivateExtension(const std::string& extension_id) {
875 active_extension_ids_.insert(extension_id); 886 active_extension_ids_.insert(extension_id);
876 const Extension* extension = extensions_.GetByID(extension_id); 887 const Extension* extension = extensions_.GetByID(extension_id);
877 CHECK(extension); 888 CHECK(extension);
878 889
879 // This is called when starting a new extension page, so start the idle 890 // This is called when starting a new extension page, so start the idle
880 // handler ticking. 891 // handler ticking.
881 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); 892 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); 1144 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
1134 v8::ThrowException( 1145 v8::ThrowException(
1135 v8::Exception::Error(v8::String::New(error_msg.c_str()))); 1146 v8::Exception::Error(v8::String::New(error_msg.c_str())));
1136 return false; 1147 return false;
1137 } 1148 }
1138 1149
1139 return true; 1150 return true;
1140 } 1151 }
1141 1152
1142 } // namespace extensions 1153 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/module_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698