| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser_window.h" | 7 #include "chrome/browser/ui/browser_window.h" |
| 8 #include "content/browser/browsing_instance.h" | 8 #include "content/browser/browsing_instance.h" |
| 9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
| 10 #include "chrome/browser/extensions/extension_host_mac.h" | 10 #include "chrome/browser/extensions/extension_host_mac.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 #endif | 125 #endif |
| 126 host->CreateView(browser); | 126 host->CreateView(browser); |
| 127 OnExtensionHostCreated(host, false); | 127 OnExtensionHostCreated(host, false); |
| 128 return host; | 128 return host; |
| 129 } | 129 } |
| 130 | 130 |
| 131 ExtensionHost* ExtensionProcessManager::CreateViewHost( | 131 ExtensionHost* ExtensionProcessManager::CreateViewHost( |
| 132 const GURL& url, Browser* browser, ViewType::Type view_type) { | 132 const GURL& url, Browser* browser, ViewType::Type view_type) { |
| 133 // A NULL browser may only be given for pop-up views. | 133 // A NULL browser may only be given for pop-up views. |
| 134 DCHECK(browser || (!browser && view_type == ViewType::EXTENSION_POPUP)); | 134 DCHECK(browser || (!browser && view_type == ViewType::EXTENSION_POPUP)); |
| 135 ExtensionService* service = | 135 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 136 browsing_instance_->profile()->GetExtensionService(); | 136 ExtensionService* service = profile->GetExtensionService(); |
| 137 if (service) { | 137 if (service) { |
| 138 const Extension* extension = service->GetExtensionByURL(url); | 138 const Extension* extension = service->GetExtensionByURL(url); |
| 139 if (extension) | 139 if (extension) |
| 140 return CreateViewHost(extension, url, browser, view_type); | 140 return CreateViewHost(extension, url, browser, view_type); |
| 141 } | 141 } |
| 142 return NULL; | 142 return NULL; |
| 143 } | 143 } |
| 144 | 144 |
| 145 ExtensionHost* ExtensionProcessManager::CreatePopupHost( | 145 ExtensionHost* ExtensionProcessManager::CreatePopupHost( |
| 146 const Extension* extension, const GURL& url, Browser* browser) { | 146 const Extension* extension, const GURL& url, Browser* browser) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 OnExtensionHostCreated(host, true); | 191 OnExtensionHostCreated(host, true); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void ExtensionProcessManager::OpenOptionsPage(const Extension* extension, | 194 void ExtensionProcessManager::OpenOptionsPage(const Extension* extension, |
| 195 Browser* browser) { | 195 Browser* browser) { |
| 196 DCHECK(!extension->options_url().is_empty()); | 196 DCHECK(!extension->options_url().is_empty()); |
| 197 | 197 |
| 198 // Force the options page to open in non-OTR window, because it won't be | 198 // Force the options page to open in non-OTR window, because it won't be |
| 199 // able to save settings from OTR. | 199 // able to save settings from OTR. |
| 200 if (!browser || browser->profile()->IsOffTheRecord()) { | 200 if (!browser || browser->profile()->IsOffTheRecord()) { |
| 201 browser = Browser::GetOrCreateTabbedBrowser( | 201 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 202 browsing_instance_->profile()->GetOriginalProfile()); | 202 browser = Browser::GetOrCreateTabbedBrowser(profile->GetOriginalProfile()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 browser->OpenURL(extension->options_url(), GURL(), SINGLETON_TAB, | 205 browser->OpenURL(extension->options_url(), GURL(), SINGLETON_TAB, |
| 206 PageTransition::LINK); | 206 PageTransition::LINK); |
| 207 browser->window()->Show(); | 207 browser->window()->Show(); |
| 208 static_cast<RenderViewHostDelegate*>(browser->GetSelectedTabContents())-> | 208 static_cast<RenderViewHostDelegate*>(browser->GetSelectedTabContents())-> |
| 209 Activate(); | 209 Activate(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension( | 212 ExtensionHost* ExtensionProcessManager::GetBackgroundHostForExtension( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return GetExtensionProcess( | 255 return GetExtensionProcess( |
| 256 Extension::GetBaseURLFromExtensionId(extension_id)); | 256 Extension::GetBaseURLFromExtensionId(extension_id)); |
| 257 } | 257 } |
| 258 | 258 |
| 259 const Extension* ExtensionProcessManager::GetExtensionForSiteInstance( | 259 const Extension* ExtensionProcessManager::GetExtensionForSiteInstance( |
| 260 int site_instance_id) { | 260 int site_instance_id) { |
| 261 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); | 261 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); |
| 262 if (it != extension_ids_.end()) { | 262 if (it != extension_ids_.end()) { |
| 263 // Look up the extension by ID, including disabled extensions in case | 263 // Look up the extension by ID, including disabled extensions in case |
| 264 // this gets called while an old process is still around. | 264 // this gets called while an old process is still around. |
| 265 ExtensionService* service = | 265 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 266 browsing_instance_->profile()->GetExtensionService(); | 266 ExtensionService* service = profile->GetExtensionService(); |
| 267 return service->GetExtensionById(it->second, false); | 267 return service->GetExtensionById(it->second, false); |
| 268 } | 268 } |
| 269 | 269 |
| 270 return NULL; | 270 return NULL; |
| 271 } | 271 } |
| 272 | 272 |
| 273 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 273 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
| 274 return browsing_instance_->GetSiteInstanceForURL(url); | 274 return browsing_instance_->GetSiteInstanceForURL(url); |
| 275 } | 275 } |
| 276 | 276 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 break; | 335 break; |
| 336 } | 336 } |
| 337 | 337 |
| 338 default: | 338 default: |
| 339 NOTREACHED(); | 339 NOTREACHED(); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 | 342 |
| 343 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 343 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
| 344 bool is_background) { | 344 bool is_background) { |
| 345 DCHECK_EQ(browsing_instance_->profile(), host->profile()); | 345 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 346 DCHECK_EQ(profile, host->profile()); |
| 346 | 347 |
| 347 all_hosts_.insert(host); | 348 all_hosts_.insert(host); |
| 348 if (is_background) | 349 if (is_background) |
| 349 background_hosts_.insert(host); | 350 background_hosts_.insert(host); |
| 350 NotificationService::current()->Notify( | 351 NotificationService::current()->Notify( |
| 351 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 352 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| 352 Source<ExtensionProcessManager>(this), | 353 Source<ExtensionProcessManager>(this), |
| 353 Details<ExtensionHost>(host)); | 354 Details<ExtensionHost>(host)); |
| 354 } | 355 } |
| 355 | 356 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 ExtensionProcessManager::GetExtensionForSiteInstance(site_instance_id); | 436 ExtensionProcessManager::GetExtensionForSiteInstance(site_instance_id); |
| 436 if (extension && extension->incognito_split_mode()) { | 437 if (extension && extension->incognito_split_mode()) { |
| 437 return extension; | 438 return extension; |
| 438 } else { | 439 } else { |
| 439 return original_manager_->GetExtensionForSiteInstance(site_instance_id); | 440 return original_manager_->GetExtensionForSiteInstance(site_instance_id); |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 | 443 |
| 443 const Extension* IncognitoExtensionProcessManager::GetExtensionOrAppByURL( | 444 const Extension* IncognitoExtensionProcessManager::GetExtensionOrAppByURL( |
| 444 const GURL& url) { | 445 const GURL& url) { |
| 445 ExtensionService* service = | 446 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 446 browsing_instance_->profile()->GetExtensionService(); | 447 ExtensionService* service = profile->GetExtensionService(); |
| 447 if (!service) | 448 if (!service) |
| 448 return NULL; | 449 return NULL; |
| 449 return (url.SchemeIs(chrome::kExtensionScheme)) ? | 450 return (url.SchemeIs(chrome::kExtensionScheme)) ? |
| 450 service->GetExtensionByURL(url) : service->GetExtensionByWebExtent(url); | 451 service->GetExtensionByURL(url) : service->GetExtensionByWebExtent(url); |
| 451 } | 452 } |
| 452 | 453 |
| 453 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( | 454 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( |
| 454 const Extension* extension) { | 455 const Extension* extension) { |
| 455 ExtensionService* service = | 456 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 456 browsing_instance_->profile()->GetExtensionService(); | 457 ExtensionService* service = profile->GetExtensionService(); |
| 457 return service && service->IsIncognitoEnabled(extension->id()); | 458 return service && service->IsIncognitoEnabled(extension->id()); |
| 458 } | 459 } |
| 459 | 460 |
| 460 void IncognitoExtensionProcessManager::Observe( | 461 void IncognitoExtensionProcessManager::Observe( |
| 461 int type, | 462 int type, |
| 462 const NotificationSource& source, | 463 const NotificationSource& source, |
| 463 const NotificationDetails& details) { | 464 const NotificationDetails& details) { |
| 464 switch (type) { | 465 switch (type) { |
| 465 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 466 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
| 466 // We want to spawn our background hosts as soon as the user opens an | 467 // We want to spawn our background hosts as soon as the user opens an |
| 467 // incognito window. Watch for new browsers and create the hosts if | 468 // incognito window. Watch for new browsers and create the hosts if |
| 468 // it matches our profile. | 469 // it matches our profile. |
| 469 Browser* browser = Source<Browser>(source).ptr(); | 470 Browser* browser = Source<Browser>(source).ptr(); |
| 470 if (browser->profile() == browsing_instance_->profile()) { | 471 Profile* profile = static_cast<Profile*>(browsing_instance_->context()); |
| 472 if (browser->profile() == profile) { |
| 471 // On Chrome OS, a login screen is implemented as a browser. | 473 // On Chrome OS, a login screen is implemented as a browser. |
| 472 // This browser has no extension service. In this case, | 474 // This browser has no extension service. In this case, |
| 473 // service will be NULL. | 475 // service will be NULL. |
| 474 ExtensionService* service = | 476 ExtensionService* service = profile->GetExtensionService(); |
| 475 browsing_instance_->profile()->GetExtensionService(); | |
| 476 if (service && service->is_ready()) | 477 if (service && service->is_ready()) |
| 477 CreateBackgroundHosts(this, service->extensions()); | 478 CreateBackgroundHosts(this, service->extensions()); |
| 478 } | 479 } |
| 479 break; | 480 break; |
| 480 } | 481 } |
| 481 default: | 482 default: |
| 482 ExtensionProcessManager::Observe(type, source, details); | 483 ExtensionProcessManager::Observe(type, source, details); |
| 483 break; | 484 break; |
| 484 } | 485 } |
| 485 } | 486 } |
| OLD | NEW |