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/browser/extensions/api/declarative_content/content_rules_regist
ry.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/api/declarative_content/content_action.h" | 8 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
9 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" | 9 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" |
10 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 10 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/navigation_details.h" | 13 #include "content/public/browser/navigation_details.h" |
14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
20 #include "extensions/common/extension_messages.h" | 20 #include "extensions/common/extension_messages.h" |
21 | 21 |
22 using url_matcher::URLMatcherConditionSet; | 22 using url_matcher::URLMatcherConditionSet; |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 ContentRulesRegistry::ContentRulesRegistry(Profile* profile, | 26 ContentRulesRegistry::ContentRulesRegistry(Profile* profile, |
| 27 const std::string& event_name, |
| 28 const WatchedPagesRecipient |
| 29 watched_pages_recipient, |
27 RulesCacheDelegate* cache_delegate) | 30 RulesCacheDelegate* cache_delegate) |
28 : RulesRegistry(profile, | 31 : RulesRegistry(profile, |
29 declarative_content_constants::kOnPageChanged, | 32 event_name, |
30 content::BrowserThread::UI, | 33 content::BrowserThread::UI, |
31 cache_delegate, | 34 cache_delegate, |
32 WebViewKey(0, 0)) { | 35 WebViewKey(0, 0)), |
| 36 watched_pages_recipient_(watched_pages_recipient) { |
33 extension_info_map_ = ExtensionSystem::Get(profile)->info_map(); | 37 extension_info_map_ = ExtensionSystem::Get(profile)->info_map(); |
34 | 38 |
35 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 39 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
36 content::NotificationService::AllBrowserContextsAndSources()); | 40 content::NotificationService::AllBrowserContextsAndSources()); |
37 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 41 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
38 content::NotificationService::AllBrowserContextsAndSources()); | 42 content::NotificationService::AllBrowserContextsAndSources()); |
39 } | 43 } |
40 | 44 |
41 void ContentRulesRegistry::Observe( | 45 void ContentRulesRegistry::Observe( |
42 int type, | 46 int type, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 !it.IsAtEnd(); it.Advance()) { | 297 !it.IsAtEnd(); it.Advance()) { |
294 content::RenderProcessHost* process = it.GetCurrentValue(); | 298 content::RenderProcessHost* process = it.GetCurrentValue(); |
295 if (process->GetBrowserContext() == profile()) | 299 if (process->GetBrowserContext() == profile()) |
296 InstructRenderProcess(process); | 300 InstructRenderProcess(process); |
297 } | 301 } |
298 } | 302 } |
299 } | 303 } |
300 | 304 |
301 void ContentRulesRegistry::InstructRenderProcess( | 305 void ContentRulesRegistry::InstructRenderProcess( |
302 content::RenderProcessHost* process) { | 306 content::RenderProcessHost* process) { |
303 process->Send(new ExtensionMsg_WatchPages(watched_css_selectors_)); | 307 process->Send( |
| 308 new ExtensionMsg_WatchPages(event_name(), |
| 309 watched_pages_recipient_, |
| 310 watched_css_selectors_)); |
304 } | 311 } |
305 | 312 |
306 bool ContentRulesRegistry::IsEmpty() const { | 313 bool ContentRulesRegistry::IsEmpty() const { |
307 return match_id_to_rule_.empty() && content_rules_.empty() && | 314 return match_id_to_rule_.empty() && content_rules_.empty() && |
308 url_matcher_.IsEmpty(); | 315 url_matcher_.IsEmpty(); |
309 } | 316 } |
310 | 317 |
311 ContentRulesRegistry::~ContentRulesRegistry() {} | 318 ContentRulesRegistry::~ContentRulesRegistry() {} |
312 | 319 |
313 base::Time ContentRulesRegistry::GetExtensionInstallationTime( | 320 base::Time ContentRulesRegistry::GetExtensionInstallationTime( |
314 const std::string& extension_id) const { | 321 const std::string& extension_id) const { |
315 if (!extension_info_map_.get()) // May be NULL during testing. | 322 if (!extension_info_map_.get()) // May be NULL during testing. |
316 return base::Time(); | 323 return base::Time(); |
317 | 324 |
318 return extension_info_map_->GetInstallTime(extension_id); | 325 return extension_info_map_->GetInstallTime(extension_id); |
319 } | 326 } |
320 | 327 |
321 } // namespace extensions | 328 } // namespace extensions |
OLD | NEW |