Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698