OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browsing_instance.h" | 7 #include "chrome/browser/browsing_instance.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extensions_service.h" | 9 #include "chrome/browser/extensions/extensions_service.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
11 #include "chrome/browser/tab_contents/site_instance.h" | 11 #include "chrome/browser/tab_contents/site_instance.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 14 #include "chrome/common/notification_type.h" |
14 | 15 |
15 static void CreateBackgroundHosts( | 16 static void CreateBackgroundHosts( |
16 ExtensionProcessManager* manager, const ExtensionList* extensions) { | 17 ExtensionProcessManager* manager, const ExtensionList* extensions) { |
17 for (ExtensionList::const_iterator extension = extensions->begin(); | 18 for (ExtensionList::const_iterator extension = extensions->begin(); |
18 extension != extensions->end(); ++extension) { | 19 extension != extensions->end(); ++extension) { |
19 // Start the process for the master page, if it exists. | 20 // Start the process for the master page, if it exists. |
20 if ((*extension)->background_url().is_valid()) | 21 if ((*extension)->background_url().is_valid()) |
21 manager->CreateBackgroundHost(*extension, (*extension)->background_url()); | 22 manager->CreateBackgroundHost(*extension, (*extension)->background_url()); |
22 } | 23 } |
23 } | 24 } |
(...skipping 17 matching lines...) Expand all Loading... |
41 for (iter = to_delete.begin(); iter != to_delete.end(); ++iter) | 42 for (iter = to_delete.begin(); iter != to_delete.end(); ++iter) |
42 delete *iter; | 43 delete *iter; |
43 } | 44 } |
44 | 45 |
45 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, | 46 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, |
46 const GURL& url, | 47 const GURL& url, |
47 Browser* browser) { | 48 Browser* browser) { |
48 ExtensionHost* host = | 49 ExtensionHost* host = |
49 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); | 50 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); |
50 host->CreateView(browser); | 51 host->CreateView(browser); |
| 52 OnExtensionHostCreated(host, false); |
51 return host; | 53 return host; |
52 } | 54 } |
53 | 55 |
54 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( | 56 ExtensionHost* ExtensionProcessManager::CreateBackgroundHost( |
55 Extension* extension, const GURL& url) { | 57 Extension* extension, const GURL& url) { |
56 ExtensionHost* host = | 58 ExtensionHost* host = |
57 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); | 59 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, this); |
58 host->CreateRenderView(NULL); // create a RenderViewHost with no view | 60 host->CreateRenderView(NULL); // create a RenderViewHost with no view |
59 all_hosts_.insert(host); | 61 OnExtensionHostCreated(host, true); |
60 background_hosts_.insert(host); | |
61 return host; | 62 return host; |
62 } | 63 } |
63 | 64 |
64 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 65 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { |
65 return browsing_instance_->GetSiteInstanceForURL(url); | 66 return browsing_instance_->GetSiteInstanceForURL(url); |
66 } | 67 } |
67 | 68 |
68 void ExtensionProcessManager::Observe(NotificationType type, | 69 void ExtensionProcessManager::Observe(NotificationType type, |
69 const NotificationSource& source, | 70 const NotificationSource& source, |
70 const NotificationDetails& details) { | 71 const NotificationDetails& details) { |
(...skipping 20 matching lines...) Expand all Loading... |
91 } | 92 } |
92 | 93 |
93 default: | 94 default: |
94 NOTREACHED(); | 95 NOTREACHED(); |
95 } | 96 } |
96 } | 97 } |
97 | 98 |
98 void ExtensionProcessManager::OnExtensionHostDestroyed(ExtensionHost* host) { | 99 void ExtensionProcessManager::OnExtensionHostDestroyed(ExtensionHost* host) { |
99 all_hosts_.erase(host); | 100 all_hosts_.erase(host); |
100 background_hosts_.erase(host); | 101 background_hosts_.erase(host); |
| 102 NotificationService::current()->Notify( |
| 103 NotificationType::EXTENSION_HOST_DESTROYED, |
| 104 Source<ExtensionProcessManager>(this), |
| 105 Details<ExtensionHost>(host)); |
101 } | 106 } |
| 107 |
| 108 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
| 109 bool is_background) { |
| 110 all_hosts_.insert(host); |
| 111 if (is_background) |
| 112 background_hosts_.insert(host); |
| 113 NotificationService::current()->Notify( |
| 114 NotificationType::EXTENSION_HOST_CREATED, |
| 115 Source<ExtensionProcessManager>(this), |
| 116 Details<ExtensionHost>(host)); |
| 117 } |
OLD | NEW |