| 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 "chrome/browser/extensions/extension_process_manager.h" | 5 #include "chrome/browser/extensions/extension_process_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); | 334 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); |
| 335 view != all_extension_views_.end(); ++view) { | 335 view != all_extension_views_.end(); ++view) { |
| 336 if (view->first->GetSiteInstance() == site_instance) | 336 if (view->first->GetSiteInstance() == site_instance) |
| 337 result.insert(view->first); | 337 result.insert(view->first); |
| 338 } | 338 } |
| 339 | 339 |
| 340 return result; | 340 return result; |
| 341 } | 341 } |
| 342 | 342 |
| 343 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( | 343 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( |
| 344 content::RenderViewHost* render_view_host) { | 344 RenderViewHost* render_view_host) { |
| 345 if (!render_view_host->GetSiteInstance()) | 345 if (!render_view_host->GetSiteInstance()) |
| 346 return NULL; | 346 return NULL; |
| 347 | 347 |
| 348 ExtensionService* service = | 348 ExtensionService* service = |
| 349 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 349 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); |
| 350 if (!service) | 350 if (!service) |
| 351 return NULL; | 351 return NULL; |
| 352 | 352 |
| 353 return service->extensions()->GetByID(GetExtensionID(render_view_host)); | 353 return service->extensions()->GetByID(GetExtensionID(render_view_host)); |
| 354 } | 354 } |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 } | 629 } |
| 630 break; | 630 break; |
| 631 } | 631 } |
| 632 | 632 |
| 633 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: { | 633 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: { |
| 634 // We get this notification both for new WebContents and when one | 634 // We get this notification both for new WebContents and when one |
| 635 // has its RenderViewHost replaced (e.g. when a user does a cross-site | 635 // has its RenderViewHost replaced (e.g. when a user does a cross-site |
| 636 // navigation away from an extension URL). For the replaced case, we must | 636 // navigation away from an extension URL). For the replaced case, we must |
| 637 // unregister the old RVH so it doesn't count as an active view that would | 637 // unregister the old RVH so it doesn't count as an active view that would |
| 638 // keep the event page alive. | 638 // keep the event page alive. |
| 639 content::WebContents* contents = | 639 WebContents* contents = content::Source<WebContents>(source).ptr(); |
| 640 content::Source<content::WebContents>(source).ptr(); | |
| 641 if (contents->GetBrowserContext() != GetProfile()) | 640 if (contents->GetBrowserContext() != GetProfile()) |
| 642 break; | 641 break; |
| 643 | 642 |
| 644 content::RenderViewHost* old_render_view_host = | 643 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair; |
| 645 content::Details<content::RenderViewHost>(details).ptr(); | 644 RVHPair* switched_details = content::Details<RVHPair>(details).ptr(); |
| 646 if (old_render_view_host) | 645 if (switched_details->first) |
| 647 UnregisterRenderViewHost(old_render_view_host); | 646 UnregisterRenderViewHost(switched_details->first); |
| 648 RegisterRenderViewHost(contents->GetRenderViewHost()); | 647 RegisterRenderViewHost(switched_details->second); |
| 649 break; | 648 break; |
| 650 } | 649 } |
| 651 | 650 |
| 652 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { | 651 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { |
| 653 content::WebContents* contents = | 652 WebContents* contents = content::Source<WebContents>(source).ptr(); |
| 654 content::Source<content::WebContents>(source).ptr(); | |
| 655 if (contents->GetBrowserContext() != GetProfile()) | 653 if (contents->GetBrowserContext() != GetProfile()) |
| 656 break; | 654 break; |
| 657 const Extension* extension = GetExtensionForRenderViewHost( | 655 const Extension* extension = GetExtensionForRenderViewHost( |
| 658 contents->GetRenderViewHost()); | 656 contents->GetRenderViewHost()); |
| 659 if (!extension) | 657 if (!extension) |
| 660 return; | 658 return; |
| 661 | 659 |
| 662 // RegisterRenderViewHost is called too early (before the process is | 660 // RegisterRenderViewHost is called too early (before the process is |
| 663 // available), so we need to wait until now to notify. | 661 // available), so we need to wait until now to notify. |
| 664 content::NotificationService::current()->Notify( | 662 content::NotificationService::current()->Notify( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 676 break; | 674 break; |
| 677 } | 675 } |
| 678 | 676 |
| 679 default: | 677 default: |
| 680 NOTREACHED(); | 678 NOTREACHED(); |
| 681 } | 679 } |
| 682 } | 680 } |
| 683 | 681 |
| 684 void ExtensionProcessManager::OnDevToolsStateChanged( | 682 void ExtensionProcessManager::OnDevToolsStateChanged( |
| 685 content::DevToolsAgentHost* agent_host, bool attached) { | 683 content::DevToolsAgentHost* agent_host, bool attached) { |
| 686 content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 684 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
| 687 // Ignore unrelated notifications. | 685 // Ignore unrelated notifications. |
| 688 if (!rvh || | 686 if (!rvh || |
| 689 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) | 687 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) |
| 690 return; | 688 return; |
| 691 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != | 689 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != |
| 692 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) | 690 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) |
| 693 return; | 691 return; |
| 694 const Extension* extension = GetExtensionForRenderViewHost(rvh); | 692 const Extension* extension = GetExtensionForRenderViewHost(rvh); |
| 695 if (!extension) | 693 if (!extension) |
| 696 return; | 694 return; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 if (service && service->is_ready()) | 907 if (service && service->is_ready()) |
| 910 CreateBackgroundHostsForProfileStartup(); | 908 CreateBackgroundHostsForProfileStartup(); |
| 911 } | 909 } |
| 912 break; | 910 break; |
| 913 } | 911 } |
| 914 default: | 912 default: |
| 915 ExtensionProcessManager::Observe(type, source, details); | 913 ExtensionProcessManager::Observe(type, source, details); |
| 916 break; | 914 break; |
| 917 } | 915 } |
| 918 } | 916 } |
| OLD | NEW |