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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
157 content::Source<Profile>(original_profile)); | 157 content::Source<Profile>(original_profile)); |
158 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 158 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
159 content::Source<Profile>(original_profile)); | 159 content::Source<Profile>(original_profile)); |
160 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 160 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
161 content::Source<Profile>(original_profile)); | 161 content::Source<Profile>(original_profile)); |
162 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 162 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
163 content::Source<Profile>(profile)); | 163 content::Source<Profile>(profile)); |
164 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 164 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
165 content::Source<Profile>(profile)); | 165 content::Source<Profile>(profile)); |
166 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 166 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
167 content::NotificationService::AllSources()); | 167 content::NotificationService::AllSources()); |
168 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | 168 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
169 content::NotificationService::AllSources()); | 169 content::NotificationService::AllSources()); |
170 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | 170 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
171 content::Source<Profile>(original_profile)); | 171 content::Source<Profile>(original_profile)); |
172 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 172 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
173 content::Source<Profile>(profile)); | 173 content::Source<Profile>(profile)); |
174 if (profile->IsOffTheRecord()) { | 174 if (profile->IsOffTheRecord()) { |
175 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 175 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
176 content::Source<Profile>(original_profile)); | 176 content::Source<Profile>(original_profile)); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); | 343 for (ExtensionRenderViews::iterator view = all_extension_views_.begin(); |
344 view != all_extension_views_.end(); ++view) { | 344 view != all_extension_views_.end(); ++view) { |
345 if (view->first->GetSiteInstance() == site_instance) | 345 if (view->first->GetSiteInstance() == site_instance) |
346 result.insert(view->first); | 346 result.insert(view->first); |
347 } | 347 } |
348 | 348 |
349 return result; | 349 return result; |
350 } | 350 } |
351 | 351 |
352 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( | 352 const Extension* ExtensionProcessManager::GetExtensionForRenderViewHost( |
353 content::RenderViewHost* render_view_host) { | 353 RenderViewHost* render_view_host) { |
354 if (!render_view_host->GetSiteInstance()) | 354 if (!render_view_host->GetSiteInstance()) |
355 return NULL; | 355 return NULL; |
356 | 356 |
357 ExtensionService* service = | 357 ExtensionService* service = |
358 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 358 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); |
359 if (!service) | 359 if (!service) |
360 return NULL; | 360 return NULL; |
361 | 361 |
362 return service->extensions()->GetByID(GetExtensionID(render_view_host)); | 362 return service->extensions()->GetByID(GetExtensionID(render_view_host)); |
363 } | 363 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 633 |
634 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 634 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
635 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); | 635 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
636 if (host->extension_host_type() == | 636 if (host->extension_host_type() == |
637 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 637 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
638 CloseBackgroundHost(host); | 638 CloseBackgroundHost(host); |
639 } | 639 } |
640 break; | 640 break; |
641 } | 641 } |
642 | 642 |
643 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: { | 643 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { |
644 // We get this notification both for new WebContents and when one | 644 // We get this notification both for new WebContents and when one |
645 // has its RenderViewHost replaced (e.g. when a user does a cross-site | 645 // has its RenderViewHost replaced (e.g. when a user does a cross-site |
646 // navigation away from an extension URL). For the replaced case, we must | 646 // navigation away from an extension URL). For the replaced case, we must |
647 // unregister the old RVH so it doesn't count as an active view that would | 647 // unregister the old RVH so it doesn't count as an active view that would |
648 // keep the event page alive. | 648 // keep the event page alive. |
649 content::WebContents* contents = | 649 WebContents* contents = content::Source<WebContents>(source).ptr(); |
650 content::Source<content::WebContents>(source).ptr(); | |
651 if (contents->GetBrowserContext() != GetProfile()) | 650 if (contents->GetBrowserContext() != GetProfile()) |
652 break; | 651 break; |
653 | 652 |
654 content::RenderViewHost* old_render_view_host = | 653 typedef std::pair<RenderViewHost*, RenderViewHost*> RVHPair; |
655 content::Details<content::RenderViewHost>(details).ptr(); | 654 RVHPair* switched_details = content::Details<RVHPair>(details).ptr(); |
656 if (old_render_view_host) | 655 if (switched_details->first) |
657 UnregisterRenderViewHost(old_render_view_host); | 656 UnregisterRenderViewHost(switched_details->first); |
658 RegisterRenderViewHost(contents->GetRenderViewHost()); | 657 RegisterRenderViewHost(switched_details->second); |
659 break; | 658 break; |
660 } | 659 } |
661 | 660 |
662 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { | 661 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: { |
663 content::WebContents* contents = | 662 WebContents* contents = content::Source<WebContents>(source).ptr(); |
664 content::Source<content::WebContents>(source).ptr(); | |
665 if (contents->GetBrowserContext() != GetProfile()) | 663 if (contents->GetBrowserContext() != GetProfile()) |
666 break; | 664 break; |
667 const Extension* extension = GetExtensionForRenderViewHost( | 665 const Extension* extension = GetExtensionForRenderViewHost( |
668 contents->GetRenderViewHost()); | 666 contents->GetRenderViewHost()); |
669 if (!extension) | 667 if (!extension) |
670 return; | 668 return; |
671 | 669 |
672 // RegisterRenderViewHost is called too early (before the process is | 670 // RegisterRenderViewHost is called too early (before the process is |
673 // available), so we need to wait until now to notify. | 671 // available), so we need to wait until now to notify. |
674 content::NotificationService::current()->Notify( | 672 content::NotificationService::current()->Notify( |
(...skipping 11 matching lines...) Expand all Loading... |
686 break; | 684 break; |
687 } | 685 } |
688 | 686 |
689 default: | 687 default: |
690 NOTREACHED(); | 688 NOTREACHED(); |
691 } | 689 } |
692 } | 690 } |
693 | 691 |
694 void ExtensionProcessManager::OnDevToolsStateChanged( | 692 void ExtensionProcessManager::OnDevToolsStateChanged( |
695 content::DevToolsAgentHost* agent_host, bool attached) { | 693 content::DevToolsAgentHost* agent_host, bool attached) { |
696 content::RenderViewHost* rvh = agent_host->GetRenderViewHost(); | 694 RenderViewHost* rvh = agent_host->GetRenderViewHost(); |
697 // Ignore unrelated notifications. | 695 // Ignore unrelated notifications. |
698 if (!rvh || | 696 if (!rvh || |
699 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) | 697 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext() != GetProfile()) |
700 return; | 698 return; |
701 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != | 699 if (extensions::GetViewType(WebContents::FromRenderViewHost(rvh)) != |
702 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) | 700 extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) |
703 return; | 701 return; |
704 const Extension* extension = GetExtensionForRenderViewHost(rvh); | 702 const Extension* extension = GetExtensionForRenderViewHost(rvh); |
705 if (!extension) | 703 if (!extension) |
706 return; | 704 return; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 if (service && service->is_ready()) | 939 if (service && service->is_ready()) |
942 CreateBackgroundHostsForProfileStartup(); | 940 CreateBackgroundHostsForProfileStartup(); |
943 } | 941 } |
944 break; | 942 break; |
945 } | 943 } |
946 default: | 944 default: |
947 ExtensionProcessManager::Observe(type, source, details); | 945 ExtensionProcessManager::Observe(type, source, details); |
948 break; | 946 break; |
949 } | 947 } |
950 } | 948 } |
OLD | NEW |