Chromium Code Reviews| 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/rules_registry_service.h" | 5 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" | 12 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h" |
| 13 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" | 13 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" |
| 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" | 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" |
| 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" | 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" |
| 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "extensions/browser/extension_registry.h" | |
| 23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Registers |web_request_rules_registry| on the IO thread. | 30 // Registers |web_request_rules_registry| on the IO thread. |
| 30 void RegisterToExtensionWebRequestEventRouterOnIO( | 31 void RegisterToExtensionWebRequestEventRouterOnIO( |
| 31 void* profile, | 32 void* profile, |
| 32 const RulesRegistryService::WebViewKey& webview_key, | 33 const RulesRegistryService::WebViewKey& webview_key, |
| 33 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { | 34 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { |
| 34 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( | 35 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( |
| 35 profile, webview_key, web_request_rules_registry); | 36 profile, webview_key, web_request_rules_registry); |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { | 39 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { |
| 39 return webview_key.embedder_process_id && webview_key.webview_instance_id; | 40 return webview_key.embedder_process_id && webview_key.webview_instance_id; |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 RulesRegistryService::RulesRegistryService(content::BrowserContext* context) | 45 RulesRegistryService::RulesRegistryService(content::BrowserContext* context) |
| 45 : content_rules_registry_(NULL), | 46 : content_rules_registry_(NULL), |
| 47 extension_registry_observer_(this), | |
| 46 profile_(Profile::FromBrowserContext(context)) { | 48 profile_(Profile::FromBrowserContext(context)) { |
| 47 if (profile_) { | 49 if (profile_) { |
| 48 registrar_.Add(this, | 50 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 49 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
| 50 content::Source<Profile>(profile_->GetOriginalProfile())); | |
| 51 registrar_.Add(this, | 51 registrar_.Add(this, |
| 52 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 52 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 53 content::Source<Profile>(profile_->GetOriginalProfile())); | 53 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 54 registrar_.Add(this, | |
| 55 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
| 56 content::Source<Profile>(profile_->GetOriginalProfile())); | |
| 57 registrar_.Add( | 54 registrar_.Add( |
| 58 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 55 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 59 content::NotificationService::AllBrowserContextsAndSources()); | 56 content::NotificationService::AllBrowserContextsAndSources()); |
| 60 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); | 57 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); |
| 61 } | 58 } |
| 62 } | 59 } |
| 63 | 60 |
| 64 RulesRegistryService::~RulesRegistryService() {} | 61 RulesRegistryService::~RulesRegistryService() {} |
| 65 | 62 |
| 66 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered( | 63 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 (registry->*notification_callback)(extension_id); | 196 (registry->*notification_callback)(extension_id); |
| 200 } else { | 197 } else { |
| 201 content::BrowserThread::PostTask( | 198 content::BrowserThread::PostTask( |
| 202 registry->owner_thread(), | 199 registry->owner_thread(), |
| 203 FROM_HERE, | 200 FROM_HERE, |
| 204 base::Bind(notification_callback, registry, extension_id)); | 201 base::Bind(notification_callback, registry, extension_id)); |
| 205 } | 202 } |
| 206 } | 203 } |
| 207 } | 204 } |
| 208 | 205 |
| 206 void RulesRegistryService::OnExtensionLoaded( | |
| 207 content::BrowserContext* browser_context, | |
| 208 const Extension* extension) { | |
| 209 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, extension->id()); | |
| 210 } | |
|
not at google - send to devlin
2014/05/12 17:53:27
blank line here
limasdf
2014/05/12 23:19:50
Done.
| |
| 211 void RulesRegistryService::OnExtensionUnloaded( | |
| 212 content::BrowserContext* browser_context, | |
| 213 const Extension* extension, | |
| 214 UnloadedExtensionInfo::Reason reason) { | |
| 215 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, extension->id()); | |
| 216 } | |
| 217 | |
| 209 void RulesRegistryService::Observe( | 218 void RulesRegistryService::Observe( |
| 210 int type, | 219 int type, |
| 211 const content::NotificationSource& source, | 220 const content::NotificationSource& source, |
| 212 const content::NotificationDetails& details) { | 221 const content::NotificationDetails& details) { |
| 213 switch (type) { | 222 switch (type) { |
| 214 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | |
| 215 const Extension* extension = | |
| 216 content::Details<UnloadedExtensionInfo>(details)->extension; | |
| 217 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, | |
| 218 extension->id()); | |
| 219 break; | |
| 220 } | |
| 221 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 223 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 222 const Extension* extension = | 224 const Extension* extension = |
| 223 content::Details<const Extension>(details).ptr(); | 225 content::Details<const Extension>(details).ptr(); |
| 224 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, | 226 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, |
| 225 extension->id()); | 227 extension->id()); |
| 226 break; | 228 break; |
| 227 } | 229 } |
| 228 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | |
| 229 const Extension* extension = | |
| 230 content::Details<const Extension>(details).ptr(); | |
| 231 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, | |
| 232 extension->id()); | |
| 233 break; | |
| 234 } | |
| 235 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | 230 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 236 content::RenderProcessHost* process = | 231 content::RenderProcessHost* process = |
| 237 content::Source<content::RenderProcessHost>(source).ptr(); | 232 content::Source<content::RenderProcessHost>(source).ptr(); |
| 238 RemoveWebViewRulesRegistries(process->GetID()); | 233 RemoveWebViewRulesRegistries(process->GetID()); |
| 239 break; | 234 break; |
| 240 } | 235 } |
| 241 default: | 236 default: |
| 242 NOTREACHED(); | 237 NOTREACHED(); |
| 243 break; | 238 break; |
| 244 } | 239 } |
| 245 } | 240 } |
| 246 | 241 |
| 247 } // namespace extensions | 242 } // namespace extensions |
| OLD | NEW |