| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "chrome/browser/extensions/extension_process_manager.h" | 7 #include "chrome/browser/extensions/extension_process_manager.h" |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/extension_event_router.h" | 9 #include "chrome/browser/extensions/extension_event_router.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #if defined(OS_MACOSX) | 11 #if defined(OS_MACOSX) |
| 12 #include "chrome/browser/extensions/extension_host_mac.h" | 12 #include "chrome/browser/extensions/extension_host_mac.h" |
| 13 #endif | 13 #endif |
| 14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_info_map.h" | 15 #include "chrome/browser/extensions/extension_info_map.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_view_type.h" | 21 #include "chrome/common/chrome_view_type.h" |
| 22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/browser/site_instance.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/render_view_host_delegate.h" | 28 #include "content/public/browser/render_view_host_delegate.h" |
| 29 #include "content/public/browser/site_instance.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/renderer_preferences.h" | 31 #include "content/public/common/renderer_preferences.h" |
| 32 | 32 |
| 33 using content::BrowserThread; | 33 using content::BrowserThread; |
| 34 using content::OpenURLParams; | 34 using content::OpenURLParams; |
| 35 using content::Referrer; | 35 using content::Referrer; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // Incognito profiles use this process manager. It is mostly a shim that decides | 39 // Incognito profiles use this process manager. It is mostly a shim that decides |
| 40 // whether to fall back on the original profile's ExtensionProcessManager based | 40 // whether to fall back on the original profile's ExtensionProcessManager based |
| 41 // on whether a given extension uses "split" or "spanning" incognito behavior. | 41 // on whether a given extension uses "split" or "spanning" incognito behavior. |
| 42 class IncognitoExtensionProcessManager : public ExtensionProcessManager { | 42 class IncognitoExtensionProcessManager : public ExtensionProcessManager { |
| 43 public: | 43 public: |
| 44 explicit IncognitoExtensionProcessManager(Profile* profile); | 44 explicit IncognitoExtensionProcessManager(Profile* profile); |
| 45 virtual ~IncognitoExtensionProcessManager() {} | 45 virtual ~IncognitoExtensionProcessManager() {} |
| 46 virtual ExtensionHost* CreateViewHost( | 46 virtual ExtensionHost* CreateViewHost( |
| 47 const Extension* extension, | 47 const Extension* extension, |
| 48 const GURL& url, | 48 const GURL& url, |
| 49 Browser* browser, | 49 Browser* browser, |
| 50 content::ViewType view_type) OVERRIDE; | 50 content::ViewType view_type) OVERRIDE; |
| 51 virtual void CreateBackgroundHost(const Extension* extension, | 51 virtual void CreateBackgroundHost(const Extension* extension, |
| 52 const GURL& url); | 52 const GURL& url); |
| 53 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url); | 53 virtual content::SiteInstance* GetSiteInstanceForURL(const GURL& url); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // content::NotificationObserver: | 56 // content::NotificationObserver: |
| 57 virtual void Observe(int type, | 57 virtual void Observe(int type, |
| 58 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
| 59 const content::NotificationDetails& details); | 59 const content::NotificationDetails& details); |
| 60 | 60 |
| 61 // Returns true if the extension is allowed to run in incognito mode. | 61 // Returns true if the extension is allowed to run in incognito mode. |
| 62 bool IsIncognitoEnabled(const Extension* extension); | 62 bool IsIncognitoEnabled(const Extension* extension); |
| 63 | 63 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 89 // | 89 // |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { | 92 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { |
| 93 return (profile->IsOffTheRecord()) ? | 93 return (profile->IsOffTheRecord()) ? |
| 94 new IncognitoExtensionProcessManager(profile) : | 94 new IncognitoExtensionProcessManager(profile) : |
| 95 new ExtensionProcessManager(profile); | 95 new ExtensionProcessManager(profile); |
| 96 } | 96 } |
| 97 | 97 |
| 98 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) | 98 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) |
| 99 : site_instance_(SiteInstance::CreateSiteInstance(profile)) { | 99 : site_instance_(content::SiteInstance::CreateSiteInstance(profile)) { |
| 100 Profile* original_profile = profile->GetOriginalProfile(); | 100 Profile* original_profile = profile->GetOriginalProfile(); |
| 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 102 content::Source<Profile>(original_profile)); | 102 content::Source<Profile>(original_profile)); |
| 103 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 103 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 104 content::Source<Profile>(original_profile)); | 104 content::Source<Profile>(original_profile)); |
| 105 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 105 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 106 content::Source<Profile>(original_profile)); | 106 content::Source<Profile>(original_profile)); |
| 107 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 107 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 108 content::Source<Profile>(profile)); | 108 content::Source<Profile>(profile)); |
| 109 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 109 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 return NULL; | 250 return NULL; |
| 251 | 251 |
| 252 } | 252 } |
| 253 | 253 |
| 254 std::set<RenderViewHost*> | 254 std::set<RenderViewHost*> |
| 255 ExtensionProcessManager::GetRenderViewHostsForExtension( | 255 ExtensionProcessManager::GetRenderViewHostsForExtension( |
| 256 const std::string& extension_id) { | 256 const std::string& extension_id) { |
| 257 std::set<RenderViewHost*> result; | 257 std::set<RenderViewHost*> result; |
| 258 | 258 |
| 259 SiteInstance* site_instance = GetSiteInstanceForURL( | 259 content::SiteInstance* site_instance = GetSiteInstanceForURL( |
| 260 Extension::GetBaseURLFromExtensionId(extension_id)); | 260 Extension::GetBaseURLFromExtensionId(extension_id)); |
| 261 if (!site_instance) | 261 if (!site_instance) |
| 262 return result; | 262 return result; |
| 263 | 263 |
| 264 // Gather up all the views for that site. | 264 // Gather up all the views for that site. |
| 265 for (RenderViewHostSet::iterator view = all_extension_views_.begin(); | 265 for (RenderViewHostSet::iterator view = all_extension_views_.begin(); |
| 266 view != all_extension_views_.end(); ++view) { | 266 view != all_extension_views_.end(); ++view) { |
| 267 if ((*view)->site_instance() == site_instance) | 267 if ((*view)->site_instance() == site_instance) |
| 268 result.insert(*view); | 268 result.insert(*view); |
| 269 } | 269 } |
| 270 | 270 |
| 271 return result; | 271 return result; |
| 272 } | 272 } |
| 273 | 273 |
| 274 void ExtensionProcessManager::RegisterRenderViewHost( | 274 void ExtensionProcessManager::RegisterRenderViewHost( |
| 275 RenderViewHost* render_view_host, | 275 RenderViewHost* render_view_host, |
| 276 const Extension* extension) { | 276 const Extension* extension) { |
| 277 all_extension_views_.insert(render_view_host); | 277 all_extension_views_.insert(render_view_host); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void ExtensionProcessManager::UnregisterRenderViewHost( | 280 void ExtensionProcessManager::UnregisterRenderViewHost( |
| 281 RenderViewHost* render_view_host) { | 281 RenderViewHost* render_view_host) { |
| 282 all_extension_views_.erase(render_view_host); | 282 all_extension_views_.erase(render_view_host); |
| 283 } | 283 } |
| 284 | 284 |
| 285 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 285 content::SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL( |
| 286 const GURL& url) { |
| 286 return site_instance_->GetRelatedSiteInstance(url); | 287 return site_instance_->GetRelatedSiteInstance(url); |
| 287 } | 288 } |
| 288 | 289 |
| 289 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { | 290 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { |
| 290 return all_hosts_.find(host) != all_hosts_.end(); | 291 return all_hosts_.find(host) != all_hosts_.end(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) { | 294 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) { |
| 294 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 295 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| 295 if (host && !HasVisibleViews(extension_id)) { | 296 if (host && !HasVisibleViews(extension_id)) { |
| 296 Profile* profile = GetProfile(); | 297 Profile* profile = GetProfile(); |
| 297 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id)) | 298 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id)) |
| 298 CloseBackgroundHost(host); | 299 CloseBackgroundHost(host); |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) { | 303 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) { |
| 303 const std::set<RenderViewHost*>& views = | 304 const std::set<RenderViewHost*>& views = |
| 304 GetRenderViewHostsForExtension(extension_id); | 305 GetRenderViewHostsForExtension(extension_id); |
| 305 for (std::set<RenderViewHost*>::const_iterator it = views.begin(); | 306 for (std::set<RenderViewHost*>::const_iterator it = views.begin(); |
| 306 it != views.end(); ++it) { | 307 it != views.end(); ++it) { |
| 307 const RenderViewHost* host = *it; | 308 const RenderViewHost* host = *it; |
| 308 if (host->site_instance()->site().host() == extension_id && | 309 if (host->site_instance()->GetSite().host() == extension_id && |
| 309 host->delegate()->GetRenderViewType() != | 310 host->delegate()->GetRenderViewType() != |
| 310 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 311 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 311 return true; | 312 return true; |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 return false; | 315 return false; |
| 315 } | 316 } |
| 316 | 317 |
| 317 void ExtensionProcessManager::Observe( | 318 void ExtensionProcessManager::Observe( |
| 318 int type, | 319 int type, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 const Extension* extension, const GURL& url) { | 450 const Extension* extension, const GURL& url) { |
| 450 if (extension->incognito_split_mode()) { | 451 if (extension->incognito_split_mode()) { |
| 451 if (IsIncognitoEnabled(extension)) | 452 if (IsIncognitoEnabled(extension)) |
| 452 ExtensionProcessManager::CreateBackgroundHost(extension, url); | 453 ExtensionProcessManager::CreateBackgroundHost(extension, url); |
| 453 } else { | 454 } else { |
| 454 // Do nothing. If an extension is spanning, then its original-profile | 455 // Do nothing. If an extension is spanning, then its original-profile |
| 455 // background page is shared with incognito, so we don't create another. | 456 // background page is shared with incognito, so we don't create another. |
| 456 } | 457 } |
| 457 } | 458 } |
| 458 | 459 |
| 459 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( | 460 content::SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( |
| 460 const GURL& url) { | 461 const GURL& url) { |
| 461 ExtensionService* service = GetProfile()->GetExtensionService(); | 462 ExtensionService* service = GetProfile()->GetExtensionService(); |
| 462 if (service) { | 463 if (service) { |
| 463 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( | 464 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( |
| 464 ExtensionURLInfo(url)); | 465 ExtensionURLInfo(url)); |
| 465 if (extension && !extension->incognito_split_mode()) | 466 if (extension && !extension->incognito_split_mode()) |
| 466 return original_manager_->GetSiteInstanceForURL(url); | 467 return original_manager_->GetSiteInstanceForURL(url); |
| 467 } | 468 } |
| 468 return ExtensionProcessManager::GetSiteInstanceForURL(url); | 469 return ExtensionProcessManager::GetSiteInstanceForURL(url); |
| 469 } | 470 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 496 if (service && service->is_ready()) | 497 if (service && service->is_ready()) |
| 497 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 498 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 498 } | 499 } |
| 499 break; | 500 break; |
| 500 } | 501 } |
| 501 default: | 502 default: |
| 502 ExtensionProcessManager::Observe(type, source, details); | 503 ExtensionProcessManager::Observe(type, source, details); |
| 503 break; | 504 break; |
| 504 } | 505 } |
| 505 } | 506 } |
| OLD | NEW |