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

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

Issue 9221017: Hide BrowsingInstance from all but SiteInstance, as intended by design. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make all methods non-public to help ensure BrowsingInstance design is preserved in future. Created 8 years, 11 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) 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/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
10 #include "content/browser/browsing_instance.h"
11 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
12 #if defined(OS_MACOSX) 11 #if defined(OS_MACOSX)
13 #include "chrome/browser/extensions/extension_host_mac.h" 12 #include "chrome/browser/extensions/extension_host_mac.h"
14 #endif 13 #endif
15 #include "chrome/browser/extensions/extension_host.h" 14 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_info_map.h" 15 #include "chrome/browser/extensions/extension_info_map.h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
20 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // 88 //
90 89
91 // static 90 // static
92 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { 91 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) {
93 return (profile->IsOffTheRecord()) ? 92 return (profile->IsOffTheRecord()) ?
94 new IncognitoExtensionProcessManager(profile) : 93 new IncognitoExtensionProcessManager(profile) :
95 new ExtensionProcessManager(profile); 94 new ExtensionProcessManager(profile);
96 } 95 }
97 96
98 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) 97 ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
99 : browsing_instance_(new BrowsingInstance(profile)) { 98 : site_instance_(SiteInstance::CreateSiteInstance(profile)) {
100 Profile* original_profile = profile->GetOriginalProfile(); 99 Profile* original_profile = profile->GetOriginalProfile();
101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, 100 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
102 content::Source<Profile>(original_profile)); 101 content::Source<Profile>(original_profile));
103 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 102 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
104 content::Source<Profile>(original_profile)); 103 content::Source<Profile>(original_profile));
105 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 104 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
106 content::Source<Profile>(original_profile)); 105 content::Source<Profile>(original_profile));
107 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 106 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
108 content::Source<Profile>(profile)); 107 content::Source<Profile>(profile));
109 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 108 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 OnExtensionHostCreated(host, false); 149 OnExtensionHostCreated(host, false);
151 return host; 150 return host;
152 } 151 }
153 152
154 ExtensionHost* ExtensionProcessManager::CreateViewHost( 153 ExtensionHost* ExtensionProcessManager::CreateViewHost(
155 const GURL& url, Browser* browser, content::ViewType view_type) { 154 const GURL& url, Browser* browser, content::ViewType view_type) {
156 // A NULL browser may only be given for pop-up views. 155 // A NULL browser may only be given for pop-up views.
157 DCHECK(browser || 156 DCHECK(browser ||
158 (!browser && view_type == chrome::VIEW_TYPE_EXTENSION_POPUP)); 157 (!browser && view_type == chrome::VIEW_TYPE_EXTENSION_POPUP));
159 Profile* profile = 158 Profile* profile =
160 Profile::FromBrowserContext(browsing_instance_->browser_context()); 159 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
Matt Perry 2012/01/17 19:35:09 nit: since you're in here, if you wouldn't mind, c
Jói 2012/01/18 10:29:11 Done.
161 ExtensionService* service = profile->GetExtensionService(); 160 ExtensionService* service = profile->GetExtensionService();
162 if (service) { 161 if (service) {
163 const Extension* extension = 162 const Extension* extension =
164 service->extensions()->GetByID(url.host()); 163 service->extensions()->GetByID(url.host());
165 if (extension) 164 if (extension)
166 return CreateViewHost(extension, url, browser, view_type); 165 return CreateViewHost(extension, url, browser, view_type);
167 } 166 }
168 return NULL; 167 return NULL;
169 } 168 }
170 169
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 219 }
221 220
222 void ExtensionProcessManager::OpenOptionsPage(const Extension* extension, 221 void ExtensionProcessManager::OpenOptionsPage(const Extension* extension,
223 Browser* browser) { 222 Browser* browser) {
224 DCHECK(!extension->options_url().is_empty()); 223 DCHECK(!extension->options_url().is_empty());
225 224
226 // Force the options page to open in non-OTR window, because it won't be 225 // Force the options page to open in non-OTR window, because it won't be
227 // able to save settings from OTR. 226 // able to save settings from OTR.
228 if (!browser || browser->profile()->IsOffTheRecord()) { 227 if (!browser || browser->profile()->IsOffTheRecord()) {
229 Profile* profile = 228 Profile* profile =
230 Profile::FromBrowserContext(browsing_instance_->browser_context()); 229 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
231 browser = Browser::GetOrCreateTabbedBrowser(profile->GetOriginalProfile()); 230 browser = Browser::GetOrCreateTabbedBrowser(profile->GetOriginalProfile());
232 } 231 }
233 232
234 OpenURLParams params(extension->options_url(), Referrer(), SINGLETON_TAB, 233 OpenURLParams params(extension->options_url(), Referrer(), SINGLETON_TAB,
235 content::PAGE_TRANSITION_LINK, false); 234 content::PAGE_TRANSITION_LINK, false);
236 browser->OpenURL(params); 235 browser->OpenURL(params);
237 browser->window()->Show(); 236 browser->window()->Show();
238 browser->GetSelectedWebContents()->GetRenderViewHost()->delegate()-> 237 browser->GetSelectedWebContents()->GetRenderViewHost()->delegate()->
239 Activate(); 238 Activate();
240 } 239 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 const Extension* extension) { 275 const Extension* extension) {
277 all_extension_views_.insert(render_view_host); 276 all_extension_views_.insert(render_view_host);
278 } 277 }
279 278
280 void ExtensionProcessManager::UnregisterRenderViewHost( 279 void ExtensionProcessManager::UnregisterRenderViewHost(
281 RenderViewHost* render_view_host) { 280 RenderViewHost* render_view_host) {
282 all_extension_views_.erase(render_view_host); 281 all_extension_views_.erase(render_view_host);
283 } 282 }
284 283
285 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { 284 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
286 return browsing_instance_->GetSiteInstanceForURL(url); 285 return site_instance_->GetRelatedSiteInstance(url);
287 } 286 }
288 287
289 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { 288 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
290 return all_hosts_.find(host) != all_hosts_.end(); 289 return all_hosts_.find(host) != all_hosts_.end();
291 } 290 }
292 291
293 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) { 292 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) {
294 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 293 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
295 if (host && !HasVisibleViews(extension_id)) { 294 if (host && !HasVisibleViews(extension_id)) {
296 Profile* profile = 295 Profile* profile =
297 Profile::FromBrowserContext(browsing_instance_->browser_context()); 296 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
298 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id)) 297 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id))
299 CloseBackgroundHost(host); 298 CloseBackgroundHost(host);
300 } 299 }
301 } 300 }
302 301
303 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) { 302 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) {
304 const std::set<RenderViewHost*>& views = 303 const std::set<RenderViewHost*>& views =
305 GetRenderViewHostsForExtension(extension_id); 304 GetRenderViewHostsForExtension(extension_id);
306 for (std::set<RenderViewHost*>::const_iterator it = views.begin(); 305 for (std::set<RenderViewHost*>::const_iterator it = views.begin();
307 it != views.end(); ++it) { 306 it != views.end(); ++it) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 break; 375 break;
377 } 376 }
378 377
379 default: 378 default:
380 NOTREACHED(); 379 NOTREACHED();
381 } 380 }
382 } 381 }
383 382
384 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 383 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
385 bool is_background) { 384 bool is_background) {
386 DCHECK_EQ(browsing_instance_->browser_context(), host->profile()); 385 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile());
387 386
388 all_hosts_.insert(host); 387 all_hosts_.insert(host);
389 if (is_background) 388 if (is_background)
390 background_hosts_.insert(host); 389 background_hosts_.insert(host);
391 } 390 }
392 391
393 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { 392 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) {
394 CHECK(host->extension_host_type() == 393 CHECK(host->extension_host_type() ==
395 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 394 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
396 delete host; 395 delete host;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 ExtensionProcessManager::CreateBackgroundHost(extension, url); 448 ExtensionProcessManager::CreateBackgroundHost(extension, url);
450 } else { 449 } else {
451 // Do nothing. If an extension is spanning, then its original-profile 450 // Do nothing. If an extension is spanning, then its original-profile
452 // background page is shared with incognito, so we don't create another. 451 // background page is shared with incognito, so we don't create another.
453 } 452 }
454 } 453 }
455 454
456 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL( 455 SiteInstance* IncognitoExtensionProcessManager::GetSiteInstanceForURL(
457 const GURL& url) { 456 const GURL& url) {
458 Profile* profile = 457 Profile* profile =
459 Profile::FromBrowserContext(browsing_instance_->browser_context()); 458 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
460 ExtensionService* service = profile->GetExtensionService(); 459 ExtensionService* service = profile->GetExtensionService();
461 if (service) { 460 if (service) {
462 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( 461 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
463 ExtensionURLInfo(url)); 462 ExtensionURLInfo(url));
464 if (extension && !extension->incognito_split_mode()) 463 if (extension && !extension->incognito_split_mode())
465 return original_manager_->GetSiteInstanceForURL(url); 464 return original_manager_->GetSiteInstanceForURL(url);
466 } 465 }
467 return ExtensionProcessManager::GetSiteInstanceForURL(url); 466 return ExtensionProcessManager::GetSiteInstanceForURL(url);
468 } 467 }
469 468
470 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( 469 bool IncognitoExtensionProcessManager::IsIncognitoEnabled(
471 const Extension* extension) { 470 const Extension* extension) {
472 // Keep in sync with duplicate in extension_info_map.cc. 471 // Keep in sync with duplicate in extension_info_map.cc.
473 Profile* profile = 472 Profile* profile =
474 Profile::FromBrowserContext(browsing_instance_->browser_context()); 473 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
475 ExtensionService* service = profile->GetExtensionService(); 474 ExtensionService* service = profile->GetExtensionService();
476 return service && service->IsIncognitoEnabled(extension->id()); 475 return service && service->IsIncognitoEnabled(extension->id());
477 } 476 }
478 477
479 void IncognitoExtensionProcessManager::Observe( 478 void IncognitoExtensionProcessManager::Observe(
480 int type, 479 int type,
481 const content::NotificationSource& source, 480 const content::NotificationSource& source,
482 const content::NotificationDetails& details) { 481 const content::NotificationDetails& details) {
483 switch (type) { 482 switch (type) {
484 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { 483 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
485 if (CommandLine::ForCurrentProcess()->HasSwitch( 484 if (CommandLine::ForCurrentProcess()->HasSwitch(
486 switches::kEnableLazyBackgroundPages)) 485 switches::kEnableLazyBackgroundPages))
487 break; 486 break;
488 // We want to spawn our background hosts as soon as the user opens an 487 // We want to spawn our background hosts as soon as the user opens an
489 // incognito window. Watch for new browsers and create the hosts if 488 // incognito window. Watch for new browsers and create the hosts if
490 // it matches our profile. 489 // it matches our profile.
491 Browser* browser = content::Source<Browser>(source).ptr(); 490 Browser* browser = content::Source<Browser>(source).ptr();
492 if (browser->profile() == browsing_instance_->browser_context()) { 491 if (browser->profile() == site_instance_->GetBrowserContext()) {
493 // On Chrome OS, a login screen is implemented as a browser. 492 // On Chrome OS, a login screen is implemented as a browser.
494 // This browser has no extension service. In this case, 493 // This browser has no extension service. In this case,
495 // service will be NULL. 494 // service will be NULL.
496 Profile* profile = 495 Profile* profile =
497 Profile::FromBrowserContext(browsing_instance_->browser_context()); 496 Profile::FromBrowserContext(site_instance_->GetBrowserContext());
498 ExtensionService* service = profile->GetExtensionService(); 497 ExtensionService* service = profile->GetExtensionService();
499 if (service && service->is_ready()) 498 if (service && service->is_ready())
500 CreateBackgroundHostsForProfileStartup(this, service->extensions()); 499 CreateBackgroundHostsForProfileStartup(this, service->extensions());
501 } 500 }
502 break; 501 break;
503 } 502 }
504 default: 503 default:
505 ExtensionProcessManager::Observe(type, source, details); 504 ExtensionProcessManager::Observe(type, source, details);
506 break; 505 break;
507 } 506 }
508 } 507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698