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