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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 Source<Profile>(profile)); | 42 Source<Profile>(profile)); |
43 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 43 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
44 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
45 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, | 45 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, |
46 NotificationService::AllSources()); | 46 NotificationService::AllSources()); |
47 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 47 registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
48 NotificationService::AllSources()); | 48 NotificationService::AllSources()); |
49 } | 49 } |
50 | 50 |
51 ExtensionProcessManager::~ExtensionProcessManager() { | 51 ExtensionProcessManager::~ExtensionProcessManager() { |
| 52 CloseBackgroundHosts(); |
52 DCHECK(background_hosts_.empty()); | 53 DCHECK(background_hosts_.empty()); |
53 } | 54 } |
54 | 55 |
55 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, | 56 ExtensionHost* ExtensionProcessManager::CreateView(Extension* extension, |
56 const GURL& url, | 57 const GURL& url, |
57 Browser* browser, | 58 Browser* browser, |
58 ViewType::Type view_type) { | 59 ViewType::Type view_type) { |
59 DCHECK(extension); | 60 DCHECK(extension); |
60 DCHECK(browser); | 61 // A NULL browser may only be given for pop-up views. |
| 62 DCHECK(browser || (!browser && view_type == ViewType::EXTENSION_POPUP)); |
61 ExtensionHost* host = | 63 ExtensionHost* host = |
62 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); | 64 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, view_type); |
63 host->CreateView(browser); | 65 host->CreateView(browser); |
64 OnExtensionHostCreated(host, false); | 66 OnExtensionHostCreated(host, false); |
65 return host; | 67 return host; |
66 } | 68 } |
67 | 69 |
68 ExtensionHost* ExtensionProcessManager::CreateView(const GURL& url, | 70 ExtensionHost* ExtensionProcessManager::CreateView(const GURL& url, |
69 Browser* browser, | 71 Browser* browser, |
70 ViewType::Type view_type) { | 72 ViewType::Type view_type) { |
71 DCHECK(browser); | 73 // A NULL browser may only be given for pop-up views. |
| 74 DCHECK(browser || (!browser && view_type == ViewType::EXTENSION_POPUP)); |
72 ExtensionsService* service = | 75 ExtensionsService* service = |
73 browsing_instance_->profile()->GetExtensionsService(); | 76 browsing_instance_->profile()->GetExtensionsService(); |
74 if (service) { | 77 if (service) { |
75 Extension* extension = service->GetExtensionByURL(url); | 78 Extension* extension = service->GetExtensionByURL(url); |
76 if (extension) | 79 if (extension) |
77 return CreateView(extension, url, browser, view_type); | 80 return CreateView(extension, url, browser, view_type); |
78 } | 81 } |
79 return NULL; | 82 return NULL; |
80 } | 83 } |
81 | 84 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 Details<ExtensionHost>(host)); | 255 Details<ExtensionHost>(host)); |
253 } | 256 } |
254 | 257 |
255 void ExtensionProcessManager::CloseBackgroundHosts() { | 258 void ExtensionProcessManager::CloseBackgroundHosts() { |
256 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 259 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
257 iter != background_hosts_.end(); ) { | 260 iter != background_hosts_.end(); ) { |
258 ExtensionHostSet::iterator current = iter++; | 261 ExtensionHostSet::iterator current = iter++; |
259 delete *current; | 262 delete *current; |
260 } | 263 } |
261 } | 264 } |
OLD | NEW |