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

Side by Side Diff: chrome/browser/extensions/tab_helper.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: Greatly simplified: Got rid of WatchedPagesRecipient and new event types 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 (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/browser/extensions/tab_helper.h" 5 #include "chrome/browser/extensions/tab_helper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 233 }
234 } 234 }
235 235
236 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { 236 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) {
237 SetTabId(render_view_host); 237 SetTabId(render_view_host);
238 } 238 }
239 239
240 void TabHelper::DidNavigateMainFrame( 240 void TabHelper::DidNavigateMainFrame(
241 const content::LoadCommittedDetails& details, 241 const content::LoadCommittedDetails& details,
242 const content::FrameNavigateParams& params) { 242 const content::FrameNavigateParams& params) {
243 typedef std::map<std::string, ContentRulesRegistry*> ContentRulesRegistryMap;
243 if (ExtensionSystem::Get(profile_)->extension_service() && 244 if (ExtensionSystem::Get(profile_)->extension_service() &&
244 RulesRegistryService::Get(profile_)) { 245 RulesRegistryService::Get(profile_)) {
245 RulesRegistryService::Get(profile_)->content_rules_registry()-> 246 ContentRulesRegistryMap& content_rules_registry_map =
246 DidNavigateMainFrame(web_contents(), details, params); 247 RulesRegistryService::Get(profile_)->content_rules_registry_map();
248 for (ContentRulesRegistryMap::iterator it =
249 content_rules_registry_map.begin();
250 it != content_rules_registry_map.end(); ++it) {
251 it->second->DidNavigateMainFrame(web_contents(),
252 details,
253 params);
254 }
247 } 255 }
248 256
249 content::BrowserContext* context = web_contents()->GetBrowserContext(); 257 content::BrowserContext* context = web_contents()->GetBrowserContext();
250 ExtensionRegistry* registry = ExtensionRegistry::Get(context); 258 ExtensionRegistry* registry = ExtensionRegistry::Get(context);
251 const ExtensionSet& enabled_extensions = registry->enabled_extensions(); 259 const ExtensionSet& enabled_extensions = registry->enabled_extensions();
252 260
253 if (CommandLine::ForCurrentProcess()->HasSwitch( 261 if (CommandLine::ForCurrentProcess()->HasSwitch(
254 switches::kEnableStreamlinedHostedApps)) { 262 switches::kEnableStreamlinedHostedApps)) {
255 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); 263 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
256 if (browser && browser->is_app()) { 264 if (browser && browser->is_app()) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 int32 on_page_id, 445 int32 on_page_id,
438 const GURL& on_url) { 446 const GURL& on_url) {
439 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, 447 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_,
440 OnScriptsExecuted(web_contents(), 448 OnScriptsExecuted(web_contents(),
441 executing_scripts_map, 449 executing_scripts_map,
442 on_page_id, 450 on_page_id,
443 on_url)); 451 on_url));
444 } 452 }
445 453
446 void TabHelper::OnWatchedPageChange( 454 void TabHelper::OnWatchedPageChange(
455 const std::string& event_name,
447 const std::vector<std::string>& css_selectors) { 456 const std::vector<std::string>& css_selectors) {
448 if (ExtensionSystem::Get(profile_)->extension_service() && 457 if (ExtensionSystem::Get(profile_)->extension_service() &&
449 RulesRegistryService::Get(profile_)) { 458 RulesRegistryService::Get(profile_)) {
450 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( 459 ContentRulesRegistry* content_rules_registry =
451 web_contents(), css_selectors); 460 RulesRegistryService::Get(profile_)->
461 GetContentRulesRegistry(event_name);
462 if (!content_rules_registry)
463 return;
464
465 content_rules_registry->Apply(web_contents(), css_selectors);
452 } 466 }
453 } 467 }
454 468
455 void TabHelper::OnDetailedConsoleMessageAdded( 469 void TabHelper::OnDetailedConsoleMessageAdded(
456 const base::string16& message, 470 const base::string16& message,
457 const base::string16& source, 471 const base::string16& source,
458 const StackTrace& stack_trace, 472 const StackTrace& stack_trace,
459 int32 severity_level) { 473 int32 severity_level) {
460 if (IsSourceFromAnExtension(source)) { 474 if (IsSourceFromAnExtension(source)) {
461 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); 475 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 581 }
568 } 582 }
569 583
570 void TabHelper::SetTabId(RenderViewHost* render_view_host) { 584 void TabHelper::SetTabId(RenderViewHost* render_view_host) {
571 render_view_host->Send( 585 render_view_host->Send(
572 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), 586 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(),
573 SessionID::IdForTab(web_contents()))); 587 SessionID::IdForTab(web_contents())));
574 } 588 }
575 589
576 } // namespace extensions 590 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698