blob: 3ee2a4fa46cbda1287ea3da398a48fb4032df292 [file] [log] [blame]
[email protected]b3841c502011-03-09 01:21:311// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]481e1a42009-05-06 20:56:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]481e1a42009-05-06 20:56:058
[email protected]45776222009-07-15 20:21:589#include <map>
[email protected]8a17bd52009-06-06 08:19:4910#include <set>
[email protected]45776222009-07-15 20:21:5811#include <string>
[email protected]481e1a42009-05-06 20:56:0512
[email protected]17902752011-08-31 22:52:5413#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
[email protected]da4dfc42011-10-12 15:53:5615#include "content/public/common/view_types.h"
[email protected]6c2381d2011-10-19 02:52:5316#include "content/public/browser/notification_observer.h"
17#include "content/public/browser/notification_registrar.h"
[email protected]481e1a42009-05-06 20:56:0518
19class Browser;
20class BrowsingInstance;
21class Extension;
22class ExtensionHost;
[email protected]481e1a42009-05-06 20:56:0523class GURL;
24class Profile;
[email protected]7120f132009-07-20 21:05:3725class RenderProcessHost;
[email protected]3e194992011-10-20 05:39:1026class RenderViewHost;
[email protected]481e1a42009-05-06 20:56:0527class SiteInstance;
28
[email protected]bc535ee52010-08-31 18:40:3229// Manages dynamic state of running Chromium extensions. There is one instance
30// of this class per Profile. OTR Profiles have a separate instance that keeps
31// track of split-mode extensions only.
[email protected]6c2381d2011-10-19 02:52:5332class ExtensionProcessManager : public content::NotificationObserver {
[email protected]481e1a42009-05-06 20:56:0533 public:
[email protected]bc535ee52010-08-31 18:40:3234 static ExtensionProcessManager* Create(Profile* profile);
35 virtual ~ExtensionProcessManager();
[email protected]481e1a42009-05-06 20:56:0536
[email protected]ab4eaf782009-06-10 00:11:2437 // Creates a new ExtensionHost with its associated view, grouping it in the
38 // appropriate SiteInstance (and therefore process) based on the URL and
39 // profile.
[email protected]029ad372011-05-20 17:12:5640 virtual ExtensionHost* CreateViewHost(const Extension* extension,
41 const GURL& url,
42 Browser* browser,
[email protected]da4dfc42011-10-12 15:53:5643 content::ViewType view_type);
[email protected]029ad372011-05-20 17:12:5644 ExtensionHost* CreateViewHost(const GURL& url,
45 Browser* browser,
[email protected]da4dfc42011-10-12 15:53:5646 content::ViewType view_type);
[email protected]029ad372011-05-20 17:12:5647 ExtensionHost* CreatePopupHost(const Extension* extension,
48 const GURL& url,
49 Browser* browser);
50 ExtensionHost* CreatePopupHost(const GURL& url, Browser* browser);
51 ExtensionHost* CreateDialogHost(const GURL& url, Browser* browser);
52 ExtensionHost* CreateInfobarHost(const Extension* extension,
53 const GURL& url,
54 Browser* browser);
55 ExtensionHost* CreateInfobarHost(const GURL& url,
56 Browser* browser);
[email protected]481e1a42009-05-06 20:56:0557
[email protected]550e9942010-03-10 01:40:3458 // Open the extension's options page.
[email protected]9adb9692010-10-29 23:14:0259 void OpenOptionsPage(const Extension* extension, Browser* browser);
[email protected]550e9942010-03-10 01:40:3460
[email protected]029ad372011-05-20 17:12:5661 // Creates a new UI-less extension instance. Like CreateViewHost, but not
[email protected]bc535ee52010-08-31 18:40:3262 // displayed anywhere.
[email protected]9adb9692010-10-29 23:14:0263 virtual void CreateBackgroundHost(const Extension* extension,
64 const GURL& url);
[email protected]bc535ee52010-08-31 18:40:3265
[email protected]4814b512009-11-07 00:12:2966 // Gets the ExtensionHost for the background page for an extension, or NULL if
67 // the extension isn't running or doesn't have a background page.
[email protected]06024c62011-10-20 20:57:1268 ExtensionHost* GetBackgroundHostForExtension(const std::string& extension_id);
[email protected]4814b512009-11-07 00:12:2969
[email protected]481e1a42009-05-06 20:56:0570 // Returns the SiteInstance that the given URL belongs to.
[email protected]6f371442011-11-09 06:45:4671 // TODO(aa): This only returns correct results for extensions and packaged
72 // apps, not hosted apps.
[email protected]bc535ee52010-08-31 18:40:3273 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url);
[email protected]481e1a42009-05-06 20:56:0574
[email protected]3e194992011-10-20 05:39:1075 // Registers a RenderViewHost as hosting a given extension.
76 void RegisterRenderViewHost(RenderViewHost* render_view_host,
77 const Extension* extension);
[email protected]45776222009-07-15 20:21:5878
[email protected]3e194992011-10-20 05:39:1079 // Unregisters a RenderViewHost as hosting any extension.
80 void UnregisterRenderViewHost(RenderViewHost* render_view_host);
81
82 // Returns all RenderViewHosts that are registered for the specified
83 // extension.
84 std::set<RenderViewHost*> GetRenderViewHostsForExtension(
85 const std::string& extension_id);
[email protected]45776222009-07-15 20:21:5886
[email protected]27e469a2010-01-11 20:35:0987 // Returns true if |host| is managed by this process manager.
88 bool HasExtensionHost(ExtensionHost* host) const;
89
[email protected]06024c62011-10-20 20:57:1290 // Called when the render reports that the extension is idle (only if
91 // lazy background pages are enabled).
92 void OnExtensionIdle(const std::string& extension_id);
93
[email protected]8a17bd52009-06-06 08:19:4994 typedef std::set<ExtensionHost*> ExtensionHostSet;
95 typedef ExtensionHostSet::const_iterator const_iterator;
96 const_iterator begin() const { return all_hosts_.begin(); }
97 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:0698
[email protected]bc535ee52010-08-31 18:40:3299 protected:
100 explicit ExtensionProcessManager(Profile* profile);
101
[email protected]94fe52e2009-06-13 10:09:06102 // Called just after |host| is created so it can be registered in our lists.
103 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
104
[email protected]ae5497f2009-11-05 00:39:46105 // Called on browser shutdown to close our extension hosts.
106 void CloseBackgroundHosts();
107
[email protected]6c2381d2011-10-19 02:52:53108 // content::NotificationObserver:
[email protected]432115822011-07-10 15:52:27109 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53110 const content::NotificationSource& source,
111 const content::NotificationDetails& details) OVERRIDE;
[email protected]bc535ee52010-08-31 18:40:32112
[email protected]6c2381d2011-10-19 02:52:53113 content::NotificationRegistrar registrar_;
[email protected]fc368952009-05-21 21:37:06114
[email protected]8a17bd52009-06-06 08:19:49115 // The set of all ExtensionHosts managed by this process manager.
116 ExtensionHostSet all_hosts_;
117
118 // The set of running viewless background extensions.
119 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:05120
121 // The BrowsingInstance shared by all extensions in this profile. This
122 // controls process grouping.
123 scoped_refptr<BrowsingInstance> browsing_instance_;
124
[email protected]3e194992011-10-20 05:39:10125 private:
[email protected]3e194992011-10-20 05:39:10126 // Contains all extension-related RenderViewHost instances for all extensions.
127 typedef std::set<RenderViewHost*> RenderViewHostSet;
128 RenderViewHostSet all_extension_views_;
129
[email protected]06024c62011-10-20 20:57:12130 // Close the given |host| iff it's a background page.
131 void CloseBackgroundHost(ExtensionHost* host);
132
133 // Excludes background page.
134 bool HasVisibleViews(const std::string& extension_id);
135
[email protected]481e1a42009-05-06 20:56:05136 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
137};
138
139#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_