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

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 note about what it means to revert RequestContentScript 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/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 #include "extensions/common/manifest.h" 29 #include "extensions/common/manifest.h"
30 #include "extensions/common/manifest_constants.h" 30 #include "extensions/common/manifest_constants.h"
31 #include "extensions/common/manifest_handlers/background_info.h" 31 #include "extensions/common/manifest_handlers/background_info.h"
32 #include "extensions/common/manifest_handlers/externally_connectable.h" 32 #include "extensions/common/manifest_handlers/externally_connectable.h"
33 #include "extensions/common/manifest_handlers/sandboxed_page_info.h" 33 #include "extensions/common/manifest_handlers/sandboxed_page_info.h"
34 #include "extensions/common/message_bundle.h" 34 #include "extensions/common/message_bundle.h"
35 #include "extensions/common/permissions/permission_set.h" 35 #include "extensions/common/permissions/permission_set.h"
36 #include "extensions/common/permissions/permissions_data.h" 36 #include "extensions/common/permissions/permissions_data.h"
37 #include "extensions/common/switches.h" 37 #include "extensions/common/switches.h"
38 #include "extensions/common/view_type.h" 38 #include "extensions/common/view_type.h"
39 #include "extensions/common/watched_pages_recipient.h"
39 #include "extensions/renderer/api_activity_logger.h" 40 #include "extensions/renderer/api_activity_logger.h"
40 #include "extensions/renderer/api_definitions_natives.h" 41 #include "extensions/renderer/api_definitions_natives.h"
41 #include "extensions/renderer/app_runtime_custom_bindings.h" 42 #include "extensions/renderer/app_runtime_custom_bindings.h"
42 #include "extensions/renderer/binding_generating_native_handler.h" 43 #include "extensions/renderer/binding_generating_native_handler.h"
43 #include "extensions/renderer/blob_native_handler.h" 44 #include "extensions/renderer/blob_native_handler.h"
44 #include "extensions/renderer/content_watcher.h" 45 #include "extensions/renderer/content_watcher.h"
45 #include "extensions/renderer/context_menus_custom_bindings.h" 46 #include "extensions/renderer/context_menus_custom_bindings.h"
46 #include "extensions/renderer/css_native_handler.h" 47 #include "extensions/renderer/css_native_handler.h"
47 #include "extensions/renderer/dispatcher_delegate.h" 48 #include "extensions/renderer/dispatcher_delegate.h"
48 #include "extensions/renderer/document_custom_bindings.h" 49 #include "extensions/renderer/document_custom_bindings.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 168
168 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) { 169 void GetChrome(const v8::FunctionCallbackInfo<v8::Value>& args) {
169 args.GetReturnValue().Set(GetOrCreateChrome(context())); 170 args.GetReturnValue().Set(GetOrCreateChrome(context()));
170 } 171 }
171 }; 172 };
172 173
173 } // namespace 174 } // namespace
174 175
175 Dispatcher::Dispatcher(DispatcherDelegate* delegate) 176 Dispatcher::Dispatcher(DispatcherDelegate* delegate)
176 : delegate_(delegate), 177 : delegate_(delegate),
177 content_watcher_(new ContentWatcher()),
178 source_map_(&ResourceBundle::GetSharedInstance()), 178 source_map_(&ResourceBundle::GetSharedInstance()),
179 v8_schema_registry_(new V8SchemaRegistry), 179 v8_schema_registry_(new V8SchemaRegistry),
180 is_webkit_initialized_(false) { 180 is_webkit_initialized_(false) {
181 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 181 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
182 is_extension_process_ = 182 is_extension_process_ =
183 command_line.HasSwitch(extensions::switches::kExtensionProcess) || 183 command_line.HasSwitch(extensions::switches::kExtensionProcess) ||
184 command_line.HasSwitch(::switches::kSingleProcess); 184 command_line.HasSwitch(::switches::kSingleProcess);
185 185
186 if (is_extension_process_) { 186 if (is_extension_process_) {
187 RenderThread::Get()->SetIdleNotificationDelayInMs( 187 RenderThread::Get()->SetIdleNotificationDelayInMs(
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 std::string stylesheet = ResourceBundle::GetSharedInstance() 322 std::string stylesheet = ResourceBundle::GetSharedInstance()
323 .GetRawDataResource(IDR_PLATFORM_APP_CSS) 323 .GetRawDataResource(IDR_PLATFORM_APP_CSS)
324 .as_string(); 324 .as_string();
325 ReplaceFirstSubstringAfterOffset( 325 ReplaceFirstSubstringAfterOffset(
326 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 326 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
327 ReplaceFirstSubstringAfterOffset( 327 ReplaceFirstSubstringAfterOffset(
328 &stylesheet, 0, "$FONTSIZE", system_font_size_); 328 &stylesheet, 0, "$FONTSIZE", system_font_size_);
329 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet)); 329 frame->document().insertStyleSheet(WebString::fromUTF8(stylesheet));
330 } 330 }
331 331
332 content_watcher_->DidCreateDocumentElement(frame); 332 for (ContentWatcherMap::iterator it = content_watchers_.begin();
333 it != content_watchers_.end(); ++it) {
334 it->second->DidCreateDocumentElement(frame);
335 }
333 } 336 }
334 337
335 void Dispatcher::DidMatchCSS( 338 void Dispatcher::DidMatchCSS(
336 blink::WebFrame* frame, 339 blink::WebFrame* frame,
337 const blink::WebVector<blink::WebString>& newly_matching_selectors, 340 const blink::WebVector<blink::WebString>& newly_matching_selectors,
338 const blink::WebVector<blink::WebString>& stopped_matching_selectors) { 341 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
339 content_watcher_->DidMatchCSS( 342 for (ContentWatcherMap::iterator it = content_watchers_.begin();
340 frame, newly_matching_selectors, stopped_matching_selectors); 343 it != content_watchers_.end(); ++it) {
344 it->second->DidMatchCSS(
345 frame, newly_matching_selectors, stopped_matching_selectors);
346 }
341 } 347 }
342 348
343 void Dispatcher::OnExtensionResponse(int request_id, 349 void Dispatcher::OnExtensionResponse(int request_id,
344 bool success, 350 bool success,
345 const base::ListValue& response, 351 const base::ListValue& response,
346 const std::string& error) { 352 const std::string& error) {
347 request_sender_->HandleResponse(request_id, success, response, error); 353 request_sender_->HandleResponse(request_id, success, response, error);
348 } 354 }
349 355
350 bool Dispatcher::CheckContextAccessToExtensionAPI( 356 bool Dispatcher::CheckContextAccessToExtensionAPI(
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont) 467 IPC_MESSAGE_HANDLER(ExtensionMsg_SetSystemFont, OnSetSystemFont)
462 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend) 468 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldSuspend, OnShouldSuspend)
463 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend) 469 IPC_MESSAGE_HANDLER(ExtensionMsg_Suspend, OnSuspend)
464 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs) 470 IPC_MESSAGE_HANDLER(ExtensionMsg_TransferBlobs, OnTransferBlobs)
465 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) 471 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded)
466 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) 472 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions)
467 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions, 473 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateTabSpecificPermissions,
468 OnUpdateTabSpecificPermissions) 474 OnUpdateTabSpecificPermissions)
469 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) 475 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts)
470 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) 476 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI)
471 IPC_MESSAGE_FORWARD(ExtensionMsg_WatchPages, 477 IPC_MESSAGE_HANDLER(ExtensionMsg_WatchPages,
472 content_watcher_.get(), 478 OnWatchPages)
473 ContentWatcher::OnWatchPages)
474 IPC_MESSAGE_UNHANDLED(handled = false) 479 IPC_MESSAGE_UNHANDLED(handled = false)
475 IPC_END_MESSAGE_MAP() 480 IPC_END_MESSAGE_MAP()
476 481
477 return handled; 482 return handled;
478 } 483 }
479 484
480 void Dispatcher::WebKitInitialized() { 485 void Dispatcher::WebKitInitialized() {
481 // For extensions, we want to ensure we call the IdleHandler every so often, 486 // For extensions, we want to ensure we call the IdleHandler every so often,
482 // even if the extension keeps up activity. 487 // even if the extension keeps up activity.
483 if (is_extension_process_) { 488 if (is_extension_process_) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 } 790 }
786 791
787 user_script_slave_->UpdateScripts(scripts, extension_ids); 792 user_script_slave_->UpdateScripts(scripts, extension_ids);
788 UpdateActiveExtensions(); 793 UpdateActiveExtensions();
789 } 794 }
790 795
791 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { 796 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) {
792 delegate_->HandleWebRequestAPIUsage(webrequest_used); 797 delegate_->HandleWebRequestAPIUsage(webrequest_used);
793 } 798 }
794 799
800 void Dispatcher::OnWatchPages(
801 const std::string& event_name,
802 const WatchedPagesRecipient& watched_pages_recipient,
803 const std::vector<std::string>& css_selectors) {
804 ContentWatcherMap::iterator it = content_watchers_.find(event_name);
805 if (it == content_watchers_.end()) {
806 content_watchers_.insert(std::make_pair(event_name,
Fady Samuel 2014/06/23 18:56:28 Array notation preferred.
Mark Dittmer 2014/06/24 14:14:19 Done.
807 new ContentWatcher(
808 event_name,
809 watched_pages_recipient)));
810 }
811 content_watchers_[event_name]->OnWatchPages(css_selectors);
812 }
813
795 void Dispatcher::UpdateActiveExtensions() { 814 void Dispatcher::UpdateActiveExtensions() {
796 std::set<std::string> active_extensions = active_extension_ids_; 815 std::set<std::string> active_extensions = active_extension_ids_;
797 user_script_slave_->GetActiveExtensions(&active_extensions); 816 user_script_slave_->GetActiveExtensions(&active_extensions);
798 delegate_->OnActiveExtensionsUpdated(active_extensions); 817 delegate_->OnActiveExtensionsUpdated(active_extensions);
799 } 818 }
800 819
801 void Dispatcher::InitOriginPermissions(const Extension* extension) { 820 void Dispatcher::InitOriginPermissions(const Extension* extension) {
802 delegate_->InitOriginPermissions(extension, 821 delegate_->InitOriginPermissions(extension,
803 IsExtensionActive(extension->id())); 822 IsExtensionActive(extension->id()));
804 UpdateOriginPermissions( 823 UpdateOriginPermissions(
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 return v8::Handle<v8::Object>(); 1250 return v8::Handle<v8::Object>();
1232 1251
1233 if (bind_name) 1252 if (bind_name)
1234 *bind_name = split.back(); 1253 *bind_name = split.back();
1235 1254
1236 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) 1255 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context))
1237 : bind_object; 1256 : bind_object;
1238 } 1257 }
1239 1258
1240 } // namespace extensions 1259 } // namespace extensions
OLDNEW
« chrome/browser/extensions/tab_helper.cc ('K') | « extensions/renderer/dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698