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

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

Issue 344433003: Prepare declarativeContent API for new script injection feature. Added Javascript types and functio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add description to new Javascript events Created 6 years, 6 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 19 matching lines...) Expand all
30 #include "extensions/common/manifest.h" 30 #include "extensions/common/manifest.h"
31 #include "extensions/common/manifest_constants.h" 31 #include "extensions/common/manifest_constants.h"
32 #include "extensions/common/manifest_handlers/background_info.h" 32 #include "extensions/common/manifest_handlers/background_info.h"
33 #include "extensions/common/manifest_handlers/externally_connectable.h" 33 #include "extensions/common/manifest_handlers/externally_connectable.h"
34 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" 34 #include "extensions/common/manifest_handlers/sandboxed_page_info.h"
35 #include "extensions/common/message_bundle.h" 35 #include "extensions/common/message_bundle.h"
36 #include "extensions/common/permissions/permission_set.h" 36 #include "extensions/common/permissions/permission_set.h"
37 #include "extensions/common/permissions/permissions_data.h" 37 #include "extensions/common/permissions/permissions_data.h"
38 #include "extensions/common/switches.h" 38 #include "extensions/common/switches.h"
39 #include "extensions/common/view_type.h" 39 #include "extensions/common/view_type.h"
40 #include "extensions/common/watched_pages_recipient.h"
40 #include "extensions/renderer/api_activity_logger.h" 41 #include "extensions/renderer/api_activity_logger.h"
41 #include "extensions/renderer/api_definitions_natives.h" 42 #include "extensions/renderer/api_definitions_natives.h"
42 #include "extensions/renderer/app_runtime_custom_bindings.h" 43 #include "extensions/renderer/app_runtime_custom_bindings.h"
43 #include "extensions/renderer/binding_generating_native_handler.h" 44 #include "extensions/renderer/binding_generating_native_handler.h"
44 #include "extensions/renderer/blob_native_handler.h" 45 #include "extensions/renderer/blob_native_handler.h"
45 #include "extensions/renderer/content_watcher.h" 46 #include "extensions/renderer/content_watcher.h"
46 #include "extensions/renderer/context_menus_custom_bindings.h" 47 #include "extensions/renderer/context_menus_custom_bindings.h"
47 #include "extensions/renderer/css_native_handler.h" 48 #include "extensions/renderer/css_native_handler.h"
48 #include "extensions/renderer/dispatcher_delegate.h" 49 #include "extensions/renderer/dispatcher_delegate.h"
49 #include "extensions/renderer/document_custom_bindings.h" 50 #include "extensions/renderer/document_custom_bindings.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 170
170 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) { 171 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) {
171 args.GetReturnValue().Set(GetOrCreateChrome(context())); 172 args.GetReturnValue().Set(GetOrCreateChrome(context()));
172 } 173 }
173 }; 174 };
174 175
175 } // namespace 176 } // namespace
176 177
177 Dispatcher::Dispatcher(DispatcherDelegate* delegate) 178 Dispatcher::Dispatcher(DispatcherDelegate* delegate)
178 : delegate_(delegate), 179 : delegate_(delegate),
179 content_watcher_(new ContentWatcher()),
180 source_map_(&ResourceBundle::GetSharedInstance()), 180 source_map_(&ResourceBundle::GetSharedInstance()),
181 v8_schema_registry_(new V8SchemaRegistry), 181 v8_schema_registry_(new V8SchemaRegistry),
182 is_webkit_initialized_(false), 182 is_webkit_initialized_(false),
183 user_script_set_observer_(this) { 183 user_script_set_observer_(this) {
184 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 184 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
185 is_extension_process_ = 185 is_extension_process_ =
186 command_line.HasSwitch(extensions::switches::kExtensionProcess) || 186 command_line.HasSwitch(extensions::switches::kExtensionProcess) ||
187 command_line.HasSwitch(::switches::kSingleProcess); 187 command_line.HasSwitch(::switches::kSingleProcess);
188 188
189 if (is_extension_process_) { 189 if (is_extension_process_) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 std::string stylesheet = ResourceBundle::GetSharedInstance() 332 std::string stylesheet = ResourceBundle::GetSharedInstance()
333 .GetRawDataResource(IDR_PLATFORM_APP_CSS) 333 .GetRawDataResource(IDR_PLATFORM_APP_CSS)
334 .as_string(); 334 .as_string();
335 ReplaceFirstSubstringAfterOffset( 335 ReplaceFirstSubstringAfterOffset(
336 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 336 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
337 ReplaceFirstSubstringAfterOffset( 337 ReplaceFirstSubstringAfterOffset(
338 &stylesheet, 0, "$FONTSIZE", system_font_size_); 338 &stylesheet, 0, "$FONTSIZE", system_font_size_);
339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 339 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
340 } 340 }
341 341
342 content_watcher_->DidCreateDocumentElement(frame); 342 for (ContentWatcherMap::iterator it = content_watchers_.begin();
343 it != content_watchers_.end(); ++it) {
344 it->second->DidCreateDocumentElement(frame);
345 }
343 } 346 }
344 347
345 void Dispatcher::DidMatchCSS( 348 void Dispatcher::DidMatchCSS(
346 blink::WebFrame* frame, 349 blink::WebFrame* frame,
347 const blink::WebVector<blink::WebString>& newly_matching_selectors, 350 const blink::WebVector<blink::WebString>& newly_matching_selectors,
348 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 351 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
349 content_watcher_->DidMatchCSS( 352 for (ContentWatcherMap::iterator it = content_watchers_.begin();
350 frame, newly_matching_selectors, stopped_matching_selectors); 353 it != content_watchers_.end(); ++it) {
354 it->second->DidMatchCSS(
355 frame, newly_matching_selectors, stopped_matching_selectors);
356 }
351 } 357 }
352 358
353 void Dispatcher::OnExtensionResponse(int request_id, 359 void Dispatcher::OnExtensionResponse(int request_id,
354 bool success, 360 bool success,
355 const base::ListValue& response, 361 const base::ListValue& response,
356 const std::string& error) { 362 const std::string& error) {
357 request_sender_->HandleResponse(request_id, success, response, error); 363 request_sender_->HandleResponse(request_id, success, response, error);
358 } 364 }
359 365
360 bool Dispatcher::CheckContextAccessToExtensionAPI( 366 bool Dispatcher::CheckContextAccessToExtensionAPI(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 OnSetScriptingWhitelist) 476 OnSetScriptingWhitelist)
471 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) 477 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont)
472 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) 478 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend)
473 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) 479 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend)
474 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) 480 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs)
475 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) 481 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded)
476 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) 482 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions)
477 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, 483 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions,
478 OnUpdateTabSpecificPermissions) 484 OnUpdateTabSpecificPermissions)
479 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) 485 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI)
480 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, 486 IPC_MESSAGE_HANDLER(ExtensionMsg_WatchPages,
481 content_watcher_.get(), 487 OnWatchPages)
482 ContentWatcher::OnWatchPages)
483 IPC_MESSAGE_UNHANDLED(handled = false) 488 IPC_MESSAGE_UNHANDLED(handled = false)
484 IPC_END_MESSAGE_MAP() 489 IPC_END_MESSAGE_MAP()
485 490
486 return handled; 491 return handled;
487 } 492 }
488 493
489 void Dispatcher::WebKitInitialized() { 494 void Dispatcher::WebKitInitialized() {
490 // For extensions, we want to ensure we call the IdleHandler every so often, 495 // For extensions, we want to ensure we call the IdleHandler every so often,
491 // even if the extension keeps up activity. 496 // even if the extension keeps up activity.
492 if (is_extension_process_) { 497 if (is_extension_process_) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { 784 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) {
780 delegate_->HandleWebRequestAPIUsage(webrequest_used); 785 delegate_->HandleWebRequestAPIUsage(webrequest_used);
781 } 786 }
782 787
783 void Dispatcher::OnUserScriptsUpdated( 788 void Dispatcher::OnUserScriptsUpdated(
784 const std::set<std::string>& changed_extensions, 789 const std::set<std::string>& changed_extensions,
785 const std::vector<UserScript*>& scripts) { 790 const std::vector<UserScript*>& scripts) {
786 UpdateActiveExtensions(); 791 UpdateActiveExtensions();
787 } 792 }
788 793
794 void Dispatcher::OnWatchPages(
795 const std::string& event_name,
796 const WatchedPagesRecipient& watched_pages_recipient,
797 const std::vector<std::string>& css_selectors) {
798 ContentWatcherMap::iterator it = content_watchers_.find(event_name);
799 if (it == content_watchers_.end()) {
800 content_watchers_[event_name] = make_linked_ptr(
801 new ContentWatcher(event_name, watched_pages_recipient));
802 }
803 content_watchers_[event_name]->OnWatchPages(css_selectors);
804 }
805
789 void Dispatcher::UpdateActiveExtensions() { 806 void Dispatcher::UpdateActiveExtensions() {
790 std::set<std::string> active_extensions = active_extension_ids_; 807 std::set<std::string> active_extensions = active_extension_ids_;
791 user_script_set_->GetActiveExtensionIds(&active_extensions); 808 user_script_set_->GetActiveExtensionIds(&active_extensions);
792 delegate_->OnActiveExtensionsUpdated(active_extensions); 809 delegate_->OnActiveExtensionsUpdated(active_extensions);
793 } 810 }
794 811
795 void Dispatcher::InitOriginPermissions(const Extension* extension) { 812 void Dispatcher::InitOriginPermissions(const Extension* extension) {
796 delegate_->InitOriginPermissions(extension, 813 delegate_->InitOriginPermissions(extension,
797 IsExtensionActive(extension->id())); 814 IsExtensionActive(extension->id()));
798 UpdateOriginPermissions( 815 UpdateOriginPermissions(
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 return v8::Handle<v8::Object>(); 1242 return v8::Handle<v8::Object>();
1226 1243
1227 if (bind_name) 1244 if (bind_name)
1228 *bind_name = split.back(); 1245 *bind_name = split.back();
1229 1246
1230 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1247 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1231 : bind_object; 1248 : bind_object;
1232 } 1249 }
1233 1250
1234 } // namespace extensions 1251 } // namespace extensions
OLDNEW
« extensions/common/watched_pages_recipient.h ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698