blob: 5f718066f0445f35b620a1ca95cca66652b9f21f [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]4d36536b2010-08-20 06:23:2714#include "chrome/common/notification_observer.h"
[email protected]fc368952009-05-21 21:37:0615#include "chrome/common/notification_registrar.h"
[email protected]2d8d9232009-10-02 20:19:2016#include "chrome/common/view_types.h"
[email protected]481e1a42009-05-06 20:56:0517
18class Browser;
19class BrowsingInstance;
20class Extension;
21class ExtensionHost;
[email protected]481e1a42009-05-06 20:56:0522class GURL;
23class Profile;
[email protected]7120f132009-07-20 21:05:3724class RenderProcessHost;
[email protected]481e1a42009-05-06 20:56:0525class SiteInstance;
26
27// Manages dynamic state of running Chromium extensions. There is one instance
28// of this class per Profile (including OTR).
29class ExtensionProcessManager : public NotificationObserver {
30 public:
[email protected]8a17bd52009-06-06 08:19:4931 explicit ExtensionProcessManager(Profile* profile);
[email protected]481e1a42009-05-06 20:56:0532 ~ExtensionProcessManager();
33
[email protected]ab4eaf782009-06-10 00:11:2434 // Creates a new ExtensionHost with its associated view, grouping it in the
35 // appropriate SiteInstance (and therefore process) based on the URL and
36 // profile.
37 ExtensionHost* CreateView(Extension* extension,
[email protected]481e1a42009-05-06 20:56:0538 const GURL& url,
[email protected]2d8d9232009-10-02 20:19:2039 Browser* browser,
40 ViewType::Type view_type);
41 ExtensionHost* CreateView(const GURL& url,
42 Browser* browser,
43 ViewType::Type view_type);
[email protected]2d8d9232009-10-02 20:19:2044 ExtensionHost* CreatePopup(Extension* extension,
45 const GURL& url,
46 Browser* browser);
47 ExtensionHost* CreatePopup(const GURL& url, Browser* browser);
[email protected]f34e79632010-03-17 02:34:0848 ExtensionHost* CreateInfobar(Extension* extension,
49 const GURL& url,
50 Browser* browser);
51 ExtensionHost* CreateInfobar(const GURL& url,
52 Browser* browser);
[email protected]481e1a42009-05-06 20:56:0553
54 // Creates a new UI-less extension instance. Like CreateView, but not
55 // displayed anywhere.
[email protected]ab4eaf782009-06-10 00:11:2456 ExtensionHost* CreateBackgroundHost(Extension* extension, const GURL& url);
[email protected]481e1a42009-05-06 20:56:0557
[email protected]550e9942010-03-10 01:40:3458 // Open the extension's options page.
59 void OpenOptionsPage(Extension* extension, Browser* browser);
60
[email protected]4814b512009-11-07 00:12:2961 // Gets the ExtensionHost for the background page for an extension, or NULL if
62 // the extension isn't running or doesn't have a background page.
63 ExtensionHost* GetBackgroundHostForExtension(Extension* extension);
64
[email protected]481e1a42009-05-06 20:56:0565 // Returns the SiteInstance that the given URL belongs to.
66 SiteInstance* GetSiteInstanceForURL(const GURL& url);
67
[email protected]7120f132009-07-20 21:05:3768 // Registers an extension process by |extension_id| and specifying which
[email protected]45776222009-07-15 20:21:5869 // |process_id| it belongs to.
[email protected]7120f132009-07-20 21:05:3770 void RegisterExtensionProcess(const std::string& extension_id,
71 int process_id);
[email protected]45776222009-07-15 20:21:5872
[email protected]7120f132009-07-20 21:05:3773 // Unregisters an extension process with specified |process_id|.
[email protected]45776222009-07-15 20:21:5874 void UnregisterExtensionProcess(int process_id);
75
[email protected]5ab79b02010-04-26 16:47:1176 // Returns the extension process that |url| is associated with if it exists.
77 RenderProcessHost* GetExtensionProcess(const GURL& url);
78
[email protected]7120f132009-07-20 21:05:3779 // Returns the process that the extension with the given ID is running in.
[email protected]5ab79b02010-04-26 16:47:1180 // NOTE: This does not currently handle app processes with no
81 // ExtensionFunctionDispatcher objects.
[email protected]7120f132009-07-20 21:05:3782 RenderProcessHost* GetExtensionProcess(const std::string& extension_id);
83
[email protected]27e469a2010-01-11 20:35:0984 // Returns true if |host| is managed by this process manager.
85 bool HasExtensionHost(ExtensionHost* host) const;
86
[email protected]481e1a42009-05-06 20:56:0587 // NotificationObserver:
88 virtual void Observe(NotificationType type,
89 const NotificationSource& source,
90 const NotificationDetails& details);
91
[email protected]8a17bd52009-06-06 08:19:4992 typedef std::set<ExtensionHost*> ExtensionHostSet;
93 typedef ExtensionHostSet::const_iterator const_iterator;
94 const_iterator begin() const { return all_hosts_.begin(); }
95 const_iterator end() const { return all_hosts_.end(); }
[email protected]fc368952009-05-21 21:37:0696
[email protected]8a17bd52009-06-06 08:19:4997 private:
[email protected]94fe52e2009-06-13 10:09:0698 // Called just after |host| is created so it can be registered in our lists.
99 void OnExtensionHostCreated(ExtensionHost* host, bool is_background);
100
[email protected]ae5497f2009-11-05 00:39:46101 // Called on browser shutdown to close our extension hosts.
102 void CloseBackgroundHosts();
103
[email protected]fc368952009-05-21 21:37:06104 NotificationRegistrar registrar_;
105
[email protected]8a17bd52009-06-06 08:19:49106 // The set of all ExtensionHosts managed by this process manager.
107 ExtensionHostSet all_hosts_;
108
109 // The set of running viewless background extensions.
110 ExtensionHostSet background_hosts_;
[email protected]481e1a42009-05-06 20:56:05111
112 // The BrowsingInstance shared by all extensions in this profile. This
113 // controls process grouping.
114 scoped_refptr<BrowsingInstance> browsing_instance_;
115
[email protected]45776222009-07-15 20:21:58116 // A map of extension ID to the render_process_id that the extension lives in.
117 typedef std::map<std::string, int> ProcessIDMap;
118 ProcessIDMap process_ids_;
119
[email protected]481e1a42009-05-06 20:56:05120 DISALLOW_COPY_AND_ASSIGN(ExtensionProcessManager);
121};
122
123#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROCESS_MANAGER_H_