Chromium Code Reviews| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/extensions/extension_event_router.h" | 8 #include "chrome/browser/extensions/extension_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_process_manager.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 content::Source<content::BrowserContext>(profile)); | 145 content::Source<content::BrowserContext>(profile)); |
| 146 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, | 146 registrar_.Add(this, content::NOTIFICATION_DEVTOOLS_WINDOW_CLOSING, |
| 147 content::Source<content::BrowserContext>(profile)); | 147 content::Source<content::BrowserContext>(profile)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 ExtensionProcessManager::~ExtensionProcessManager() { | 150 ExtensionProcessManager::~ExtensionProcessManager() { |
| 151 CloseBackgroundHosts(); | 151 CloseBackgroundHosts(); |
| 152 DCHECK(background_hosts_.empty()); | 152 DCHECK(background_hosts_.empty()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 ExtensionHost* ExtensionProcessManager::CreateShellHost( | |
| 156 const Extension* extension, | |
| 157 const GURL& url) { | |
| 158 DCHECK(extension); | |
| 159 ExtensionHost* host = new ExtensionHost(extension, | |
| 160 GetSiteInstanceForURL(url), | |
| 161 url, | |
| 162 chrome::VIEW_TYPE_APP_SHELL); | |
| 163 host->CreateViewWithoutBrowser(); | |
| 164 content::WebContents* host_contents = host->host_contents(); | |
| 165 host_contents->GetMutableRendererPrefs()->browser_handles_all_requests = true; | |
| 166 host_contents->GetRenderViewHost()->SyncRendererPrefs(); | |
| 167 OnExtensionHostCreated(host, false /* not a background host */); | |
| 168 return host; | |
| 169 } | |
| 170 | |
| 171 void ExtensionProcessManager::EnsureBrowserWhenRequired( | 155 void ExtensionProcessManager::EnsureBrowserWhenRequired( |
| 172 Browser* browser, | 156 Browser* browser, |
| 173 content::ViewType view_type) { | 157 content::ViewType view_type) { |
| 174 if (!browser) { | 158 if (!browser) { |
| 175 #if defined (OS_CHROMEOS) | 159 #if defined (OS_CHROMEOS) |
| 176 // On ChromeOS we'll only use ExtensionView, which | 160 // On ChromeOS we'll only use ExtensionView, which |
| 177 // does not use the browser parameter. | 161 // does not use the browser parameter. |
| 178 // TODO(rkc): Remove all this once we create a new host for | 162 // TODO(rkc): Remove all this once we create a new host for |
| 179 // screensaver extensions (crosbug.com/28211). | 163 // screensaver extensions (crosbug.com/28211). |
| 180 DCHECK(view_type == chrome::VIEW_TYPE_EXTENSION_POPUP || | 164 DCHECK(view_type == chrome::VIEW_TYPE_EXTENSION_POPUP || |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; | 321 all_extension_views_[render_view_host] = content::VIEW_TYPE_INVALID; |
| 338 } | 322 } |
| 339 | 323 |
| 340 void ExtensionProcessManager::UnregisterRenderViewHost( | 324 void ExtensionProcessManager::UnregisterRenderViewHost( |
| 341 RenderViewHost* render_view_host) { | 325 RenderViewHost* render_view_host) { |
| 342 ExtensionRenderViews::iterator view = | 326 ExtensionRenderViews::iterator view = |
| 343 all_extension_views_.find(render_view_host); | 327 all_extension_views_.find(render_view_host); |
| 344 if (view == all_extension_views_.end()) | 328 if (view == all_extension_views_.end()) |
| 345 return; | 329 return; |
| 346 | 330 |
| 331 content::NotificationService::current()->Notify( | |
| 332 chrome::NOTIFICATION_EXTENSION_VIEW_UNREGISTERED, | |
| 333 content::Source<Profile>(GetProfile()), | |
| 334 content::Details<RenderViewHost>(render_view_host)); | |
|
benwells
2012/04/26 08:36:33
This is to keep the task manager from crashing if
| |
| 335 | |
| 347 content::ViewType view_type = view->second; | 336 content::ViewType view_type = view->second; |
| 348 all_extension_views_.erase(view); | 337 all_extension_views_.erase(view); |
| 349 | 338 |
| 350 // Keepalive count, balanced in UpdateRegisteredRenderView. | 339 // Keepalive count, balanced in UpdateRegisteredRenderView. |
| 351 if (view_type != content::VIEW_TYPE_INVALID && | 340 if (view_type != content::VIEW_TYPE_INVALID && |
| 352 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 341 view_type != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 353 const Extension* extension = GetExtensionForRenderViewHost( | 342 const Extension* extension = GetExtensionForRenderViewHost( |
| 354 render_view_host); | 343 render_view_host); |
| 355 if (extension) | 344 if (extension) |
| 356 DecrementLazyKeepaliveCount(extension); | 345 DecrementLazyKeepaliveCount(extension); |
| 357 } | 346 } |
| 358 } | 347 } |
| 359 | 348 |
| 360 void ExtensionProcessManager::UpdateRegisteredRenderView( | 349 void ExtensionProcessManager::UpdateRegisteredRenderView( |
| 361 RenderViewHost* render_view_host) { | 350 RenderViewHost* render_view_host) { |
| 362 ExtensionRenderViews::iterator view = | 351 ExtensionRenderViews::iterator view = |
| 363 all_extension_views_.find(render_view_host); | 352 all_extension_views_.find(render_view_host); |
| 364 if (view == all_extension_views_.end()) | 353 if (view == all_extension_views_.end()) |
| 365 return; | 354 return; |
| 366 | 355 |
| 356 content::NotificationService::current()->Notify( | |
| 357 chrome::NOTIFICATION_EXTENSION_VIEW_REGISTERED, | |
| 358 content::Source<Profile>(GetProfile()), | |
| 359 content::Details<RenderViewHost>(render_view_host)); | |
| 360 | |
| 367 view->second = render_view_host->GetDelegate()->GetRenderViewType(); | 361 view->second = render_view_host->GetDelegate()->GetRenderViewType(); |
| 368 | 362 |
| 369 // Keep the lazy background page alive as long as any non-background-page | 363 // Keep the lazy background page alive as long as any non-background-page |
| 370 // extension views are visible. Keepalive count balanced in | 364 // extension views are visible. Keepalive count balanced in |
| 371 // UnregisterRenderViewHost. | 365 // UnregisterRenderViewHost. |
| 372 if (view->second != content::VIEW_TYPE_INVALID && | 366 if (view->second != content::VIEW_TYPE_INVALID && |
| 373 view->second != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 367 view->second != chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 374 const Extension* extension = GetExtensionForRenderViewHost( | 368 const Extension* extension = GetExtensionForRenderViewHost( |
| 375 render_view_host); | 369 render_view_host); |
| 376 if (extension) | 370 if (extension) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 } | 504 } |
| 511 } | 505 } |
| 512 background_page_data_.erase(extension->id()); | 506 background_page_data_.erase(extension->id()); |
| 513 break; | 507 break; |
| 514 } | 508 } |
| 515 | 509 |
| 516 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 510 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 517 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 511 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 518 if (background_hosts_.erase(host)) | 512 if (background_hosts_.erase(host)) |
| 519 background_page_data_.erase(host->extension()->id()); | 513 background_page_data_.erase(host->extension()->id()); |
| 520 platform_app_hosts_.erase(host); | |
| 521 break; | 514 break; |
| 522 } | 515 } |
| 523 | 516 |
| 524 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 517 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
| 525 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 518 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| 526 if (host->extension_host_type() == | 519 if (host->extension_host_type() == |
| 527 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 520 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 528 CloseBackgroundHost(host); | 521 CloseBackgroundHost(host); |
| 529 } | 522 } |
| 530 break; | 523 break; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 | 574 |
| 582 Profile* ExtensionProcessManager::GetProfile() const { | 575 Profile* ExtensionProcessManager::GetProfile() const { |
| 583 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); | 576 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); |
| 584 } | 577 } |
| 585 | 578 |
| 586 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 579 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
| 587 bool is_background) { | 580 bool is_background) { |
| 588 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); | 581 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); |
| 589 if (is_background) | 582 if (is_background) |
| 590 background_hosts_.insert(host); | 583 background_hosts_.insert(host); |
| 591 if (host->extension()->is_platform_app()) | |
| 592 platform_app_hosts_.insert(host); | |
| 593 } | 584 } |
| 594 | 585 |
| 595 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { | 586 void ExtensionProcessManager::CloseBackgroundHost(ExtensionHost* host) { |
| 596 CHECK(host->extension_host_type() == | 587 CHECK(host->extension_host_type() == |
| 597 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 588 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 598 delete host; | 589 delete host; |
| 599 // |host| should deregister itself from our structures. | 590 // |host| should deregister itself from our structures. |
| 600 CHECK(background_hosts_.find(host) == background_hosts_.end()); | 591 CHECK(background_hosts_.find(host) == background_hosts_.end()); |
| 601 } | 592 } |
| 602 | 593 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 if (service && service->is_ready()) | 694 if (service && service->is_ready()) |
| 704 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 695 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 705 } | 696 } |
| 706 break; | 697 break; |
| 707 } | 698 } |
| 708 default: | 699 default: |
| 709 ExtensionProcessManager::Observe(type, source, details); | 700 ExtensionProcessManager::Observe(type, source, details); |
| 710 break; | 701 break; |
| 711 } | 702 } |
| 712 } | 703 } |
| OLD | NEW |