blob: 63e93adc20d467b5056cca826053d978bbb37602 [file] [log] [blame]
[email protected]f34e79632010-03-17 02:34:081// Copyright (c) 2010 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
13#include "base/ref_counted.h"
[email protected]fc368952009-05-21 21:37:0614#include "chrome/common/notification_registrar.h"
[email protected]2d8d9232009-10-02 20:19:2015#include "chrome/common/view_types.h"
[email protected]481e1a42009-05-06 20:56:0516
17class Browser;
18class BrowsingInstance;
19class Extension;
20class ExtensionHost;
[email protected]a4c368182009-05-29 21:53:2721#if defined(TOOLKIT_VIEWS)
[email protected]481e1a42009-05-06 20:56:0522class ExtensionView;
[email protected]673aad72009-05-29 06:32:4323#endif
[email protected]481e1a42009-05-06 20:56:0524class GURL;
25class Profile;
[email protected]7120f132009-07-20 21:05:3726class RenderProcessHost;
[email protected]481e1a42009-05-06 20:56:0527class SiteInstance;
28
29// Manages dynamic state of running Chromium extensions. There is one instance
30// of this class per Profile (including OTR).
31class ExtensionProcessManager : public NotificationObserver {
32 public:
[email protected]8a17bd52009-06-06 08:19:4933 explicit ExtensionProcessManager(Profile* profile);
[email protected]481e1a42009-05-06 20:56:0534 ~ExtensionProcessManager();
35
[email protected]ab4eaf782009-06-10 00:11:2436 // Creates a new ExtensionHost with its associated view, grouping it in the
37 // appropriate SiteInstance (and therefore process) based on the URL and
38 // profile.
39 ExtensionHost* CreateView(Extension* extension,
[email protected]481e1a42009-05-06 20:56:0540 const GURL& url,
[email protected]2d8d9232009-10-02 20:19:2041 Browser* browser,
42 ViewType::Type view_type);
43 ExtensionHost* CreateView(const GURL& url,
44 Browser* browser,
45 ViewType::Type view_type);
46 ExtensionHost* CreateToolstrip(Extension* extension,
47 const GURL& url,
48 Browser* browser);
49 ExtensionHost* CreateToolstrip(const GURL& url, Browser* browser);
50 ExtensionHost* CreatePopup(Extension* extension,
51 const GURL& url,
52 Browser* browser);
53 ExtensionHost* CreatePopup(const GURL& url, Browser* browser);
[email protected]f34e79632010-03-17 02:34:0854 ExtensionHost* CreateInfobar(Extension* extension,
55 const GURL& url,
56 Browser* browser);
57 ExtensionHost* CreateInfobar(const GURL& url,
58 Browser* browser);
[email protected]481e1a42009-05-06 20:56:0559
60 // Creates a new UI-less extension instance. Like CreateView, but not
61 // displayed anywhere.
[email protected]ab4eaf782009-06-10 00:11:2462 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
[email protected]481e1a42009-05-06 20:56:0563
[email protected]550e9942010-03-10 01:40:3464 // Open the extension's options page.
65 void OpenOptionsPage(Extension* extension, Browser* browser);
66
[email protected]4814b512009-11-07 00:12:2967 // Gets the ExtensionHost for the background page for an extension, or NULL if
68 // the extension isn't running or doesn't have a background page.
69 ExtensionHost* GetBackgroundHostForExtension(Extension* extension);
70
[email protected]481e1a42009-05-06 20:56:0571 // Returns the SiteInstance that the given URL belongs to.
72 SiteInstance* GetSiteInstanceForURL(const GURL& url);
73
[email protected]7120f132009-07-20 21:05:3774 // Registers an extension process by |extension_id| and specifying which
[email protected]45776222009-07-15 20:21:5875 // |process_id| it belongs to.
[email protected]7120f132009-07-20 21:05:3776 void RegisterExtensionProcess(const std::string& extension_id,
77 int process_id);
[email protected]45776222009-07-15 20:21:5878
[email protected]7120f132009-07-20 21:05:3779 // Unregisters an extension process with specified |process_id|.
[email protected]45776222009-07-15 20:21:5880 void UnregisterExtensionProcess(int process_id);
81
[email protected]5ab79b02010-04-26 16:47:1182 // Returns the extension process that |url| is associated with if it exists.
83 RenderProcessHost* GetExtensionProcess(const GURL& url);
84
[email protected]7120f132009-07-20 21:05:3785 // Returns the process that the extension with the given ID is running in.
[email protected]5ab79b02010-04-26 16:47:1186 // NOTE: This does not currently handle app processes with no
87 // ExtensionFunctionDispatcher objects.
[email protected]7120f132009-07-20 21:05:3788 RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
89
[email protected]27e469a2010-01-11 20:35:0990 // Returns true if |host| is managed by this process manager.
91 bool HasExtensionHost(ExtensionHost* host) const;
92
[email protected]481e1a42009-05-06 20:56:0593 // NotificationObserver:
94 virtual void Observe(NotificationType type,
95 const NotificationSource& source,
96 const NotificationDetails& details);
97
[email protected]8a17bd52009-06-06 08:19:4998 typedef std::set<ExtensionHost*> ExtensionHostSet;
99 typedef ExtensionHostSet::const_iterator const_iterator;
100 const_iterator begin() const { return all_hosts_.begin(); }
101 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:06102
[email protected]8a17bd52009-06-06 08:19:49103 private:
[email protected]94fe52e2009-06-13 10:09:06104 // Called just after |host| is created so it can be registered in our lists.
105 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
106
[email protected]ae5497f2009-11-05 00:39:46107 // Called on browser shutdown to close our extension hosts.
108 void CloseBackgroundHosts();
109
[email protected]fc368952009-05-21 21:37:06110 NotificationRegistrar registrar_;
111
[email protected]8a17bd52009-06-06 08:19:49112 // The set of all ExtensionHosts managed by this process manager.
113 ExtensionHostSet all_hosts_;
114
115 // The set of running viewless background extensions.
116 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:05117
118 // The BrowsingInstance shared by all extensions in this profile. This
119 // controls process grouping.
120 scoped_refptr<BrowsingInstance> browsing_instance_;
121
[email protected]45776222009-07-15 20:21:58122 // A map of extension ID to the render_process_id that the extension lives in.
123 typedef std::map<std::string, int> ProcessIDMap;
124 ProcessIDMap process_ids_;
125
[email protected]481e1a42009-05-06 20:56:05126 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
127};
128
129#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_