| 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "extensions/common/view_type.h" | 19 #include "extensions/common/view_type.h" |
| 20 | 20 |
| 21 class Browser; | |
| 22 class GURL; | 21 class GURL; |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 class BrowserContext; | 24 class BrowserContext; |
| 26 class DevToolsAgentHost; | 25 class DevToolsAgentHost; |
| 27 class RenderViewHost; | 26 class RenderViewHost; |
| 28 class SiteInstance; | 27 class SiteInstance; |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 namespace extensions { | 30 namespace extensions { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 static ExtensionProcessManager* Create(content::BrowserContext* context); | 43 static ExtensionProcessManager* Create(content::BrowserContext* context); |
| 45 virtual ~ExtensionProcessManager(); | 44 virtual ~ExtensionProcessManager(); |
| 46 | 45 |
| 47 const ExtensionHostSet& background_hosts() const { | 46 const ExtensionHostSet& background_hosts() const { |
| 48 return background_hosts_; | 47 return background_hosts_; |
| 49 } | 48 } |
| 50 | 49 |
| 51 typedef std::set<content::RenderViewHost*> ViewSet; | 50 typedef std::set<content::RenderViewHost*> ViewSet; |
| 52 const ViewSet GetAllViews() const; | 51 const ViewSet GetAllViews() const; |
| 53 | 52 |
| 54 // Creates a new ExtensionHost with its associated view, grouping it in the | |
| 55 // appropriate SiteInstance (and therefore process) based on the URL and | |
| 56 // profile. | |
| 57 virtual extensions::ExtensionHost* CreateViewHost( | |
| 58 const extensions::Extension* extension, | |
| 59 const GURL& url, | |
| 60 Browser* browser, | |
| 61 extensions::ViewType view_type); | |
| 62 extensions::ExtensionHost* CreateViewHost(const GURL& url, | |
| 63 Browser* browser, | |
| 64 extensions::ViewType view_type); | |
| 65 extensions::ExtensionHost* CreatePopupHost( | |
| 66 const extensions::Extension* extension, | |
| 67 const GURL& url, | |
| 68 Browser* browser); | |
| 69 extensions::ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser); | |
| 70 extensions::ExtensionHost* CreateDialogHost(const GURL& url); | |
| 71 extensions::ExtensionHost* CreateInfobarHost( | |
| 72 const extensions::Extension* extension, | |
| 73 const GURL& url, | |
| 74 Browser* browser); | |
| 75 extensions::ExtensionHost* CreateInfobarHost(const GURL& url, | |
| 76 Browser* browser); | |
| 77 | |
| 78 // Creates a new UI-less extension instance. Like CreateViewHost, but not | 53 // Creates a new UI-less extension instance. Like CreateViewHost, but not |
| 79 // displayed anywhere. | 54 // displayed anywhere. |
| 80 virtual extensions::ExtensionHost* CreateBackgroundHost( | 55 virtual extensions::ExtensionHost* CreateBackgroundHost( |
| 81 const extensions::Extension* extension, | 56 const extensions::Extension* extension, |
| 82 const GURL& url); | 57 const GURL& url); |
| 83 | 58 |
| 84 // Gets the ExtensionHost for the background page for an extension, or NULL if | 59 // Gets the ExtensionHost for the background page for an extension, or NULL if |
| 85 // the extension isn't running or doesn't have a background page. | 60 // the extension isn't running or doesn't have a background page. |
| 86 extensions::ExtensionHost* GetBackgroundHostForExtension( | 61 extensions::ExtensionHost* GetBackgroundHostForExtension( |
| 87 const std::string& extension_id); | 62 const std::string& extension_id); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Gets the BrowserContext associated with site_instance_ and all other | 121 // Gets the BrowserContext associated with site_instance_ and all other |
| 147 // related SiteInstances. | 122 // related SiteInstances. |
| 148 content::BrowserContext* GetBrowserContext() const; | 123 content::BrowserContext* GetBrowserContext() const; |
| 149 | 124 |
| 150 protected: | 125 protected: |
| 151 // If |context| is incognito pass the master context as |original_context|. | 126 // If |context| is incognito pass the master context as |original_context|. |
| 152 // Otherwise pass the same context for both. | 127 // Otherwise pass the same context for both. |
| 153 ExtensionProcessManager(content::BrowserContext* context, | 128 ExtensionProcessManager(content::BrowserContext* context, |
| 154 content::BrowserContext* original_context); | 129 content::BrowserContext* original_context); |
| 155 | 130 |
| 156 // Called just after |host| is created so it can be registered in our lists. | |
| 157 void OnExtensionHostCreated(extensions::ExtensionHost* host, | |
| 158 bool is_background); | |
| 159 | |
| 160 // Called on browser shutdown to close our extension hosts. | 131 // Called on browser shutdown to close our extension hosts. |
| 161 void CloseBackgroundHosts(); | 132 void CloseBackgroundHosts(); |
| 162 | 133 |
| 163 // content::NotificationObserver: | 134 // content::NotificationObserver: |
| 164 virtual void Observe(int type, | 135 virtual void Observe(int type, |
| 165 const content::NotificationSource& source, | 136 const content::NotificationSource& source, |
| 166 const content::NotificationDetails& details) OVERRIDE; | 137 const content::NotificationDetails& details) OVERRIDE; |
| 167 | 138 |
| 168 // Load all background pages once the profile data is ready and the pages | 139 // Load all background pages once the profile data is ready and the pages |
| 169 // should be loaded. | 140 // should be loaded. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 182 private: | 153 private: |
| 183 friend class ExtensionProcessManagerTest; | 154 friend class ExtensionProcessManagerTest; |
| 184 | 155 |
| 185 // Extra information we keep for each extension's background page. | 156 // Extra information we keep for each extension's background page. |
| 186 struct BackgroundPageData; | 157 struct BackgroundPageData; |
| 187 typedef std::string ExtensionId; | 158 typedef std::string ExtensionId; |
| 188 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; | 159 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; |
| 189 typedef std::map<content::RenderViewHost*, | 160 typedef std::map<content::RenderViewHost*, |
| 190 extensions::ViewType> ExtensionRenderViews; | 161 extensions::ViewType> ExtensionRenderViews; |
| 191 | 162 |
| 163 // Called just after |host| is created so it can be registered in our lists. |
| 164 void OnBackgroundHostCreated(extensions::ExtensionHost* host); |
| 165 |
| 192 // Close the given |host| iff it's a background page. | 166 // Close the given |host| iff it's a background page. |
| 193 void CloseBackgroundHost(extensions::ExtensionHost* host); | 167 void CloseBackgroundHost(extensions::ExtensionHost* host); |
| 194 | 168 |
| 195 // Ensure browser object is not null except for certain situations. | |
| 196 void EnsureBrowserWhenRequired(Browser* browser, | |
| 197 extensions::ViewType view_type); | |
| 198 | |
| 199 // These are called when the extension transitions between idle and active. | 169 // These are called when the extension transitions between idle and active. |
| 200 // They control the process of closing the background page when idle. | 170 // They control the process of closing the background page when idle. |
| 201 void OnLazyBackgroundPageIdle(const std::string& extension_id, | 171 void OnLazyBackgroundPageIdle(const std::string& extension_id, |
| 202 int sequence_id); | 172 int sequence_id); |
| 203 void OnLazyBackgroundPageActive(const std::string& extension_id); | 173 void OnLazyBackgroundPageActive(const std::string& extension_id); |
| 204 void CloseLazyBackgroundPageNow(const std::string& extension_id, | 174 void CloseLazyBackgroundPageNow(const std::string& extension_id, |
| 205 int sequence_id); | 175 int sequence_id); |
| 206 | 176 |
| 207 // Potentially registers a RenderViewHost, if it is associated with an | 177 // Potentially registers a RenderViewHost, if it is associated with an |
| 208 // extension. Does nothing if this is not an extension renderer. | 178 // extension. Does nothing if this is not an extension renderer. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 bool startup_background_hosts_created_; | 212 bool startup_background_hosts_created_; |
| 243 | 213 |
| 244 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 214 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
| 245 | 215 |
| 246 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; | 216 base::WeakPtrFactory<ExtensionProcessManager> weak_ptr_factory_; |
| 247 | 217 |
| 248 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); | 218 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager); |
| 249 }; | 219 }; |
| 250 | 220 |
| 251 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ | 221 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_ |
| OLD | NEW |