Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / apps / app_shim / extension_app_shim_handler_mac.h
blob5e2f9028c3d5b47efd37fadec6cb64ec15b0bef1
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_
6 #define CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "apps/app_lifetime_monitor.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_list_observer.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "extensions/browser/app_window/app_window_registry.h"
23 class Profile;
25 namespace base {
26 class FilePath;
29 namespace content {
30 class WebContents;
33 namespace extensions {
34 class AppWindow;
35 class Extension;
38 namespace apps {
40 // This app shim handler that handles events for app shims that correspond to an
41 // extension.
42 class ExtensionAppShimHandler : public AppShimHandler,
43 public content::NotificationObserver,
44 public AppLifetimeMonitor::Observer,
45 public chrome::BrowserListObserver {
46 public:
47 class Delegate {
48 public:
49 virtual ~Delegate() {}
51 virtual bool ProfileExistsForPath(const base::FilePath& path);
52 virtual Profile* ProfileForPath(const base::FilePath& path);
53 virtual void LoadProfileAsync(const base::FilePath& path,
54 base::Callback<void(Profile*)> callback);
55 virtual bool IsProfileLockedForPath(const base::FilePath& path);
57 virtual extensions::AppWindowRegistry::AppWindowList GetWindows(
58 Profile* profile,
59 const std::string& extension_id);
61 virtual const extensions::Extension* MaybeGetAppExtension(
62 Profile* profile,
63 const std::string& extension_id);
64 virtual void EnableExtension(Profile* profile,
65 const std::string& extension_id,
66 const base::Callback<void()>& callback);
67 virtual void LaunchApp(Profile* profile,
68 const extensions::Extension* extension,
69 const std::vector<base::FilePath>& files);
70 virtual void LaunchShim(Profile* profile,
71 const extensions::Extension* extension);
72 virtual void LaunchUserManager();
74 virtual void MaybeTerminate();
77 ExtensionAppShimHandler();
78 ~ExtensionAppShimHandler() override;
80 // Get the host corresponding to a profile and app id, or null if there is
81 // none. Virtual for tests.
82 virtual AppShimHandler::Host* FindHost(Profile* profile,
83 const std::string& app_id);
85 void SetHostedAppHidden(Profile* profile,
86 const std::string& app_id,
87 bool hidden);
89 static const extensions::Extension* MaybeGetAppExtension(
90 Profile* profile,
91 const std::string& extension_id);
93 static const extensions::Extension* MaybeGetAppForBrowser(Browser* browser);
95 static void QuitAppForWindow(extensions::AppWindow* app_window);
97 static void QuitHostedAppForWindow(Profile* profile,
98 const std::string& app_id);
100 static void HideAppForWindow(extensions::AppWindow* app_window);
102 static void HideHostedApp(Profile* profile, const std::string& app_id);
104 static void FocusAppForWindow(extensions::AppWindow* app_window);
106 // Instructs the shim to set it's "Hide/Show" state to not-hidden.
107 static void UnhideWithoutActivationForWindow(
108 extensions::AppWindow* app_window);
110 // Instructs the shim to request user attention. Returns false if there is no
111 // shim for this window.
112 static void RequestUserAttentionForWindow(
113 extensions::AppWindow* app_window,
114 AppShimAttentionType attention_type);
116 // Called by AppControllerMac when Chrome hides.
117 static void OnChromeWillHide();
119 // AppShimHandler overrides:
120 void OnShimLaunch(Host* host,
121 AppShimLaunchType launch_type,
122 const std::vector<base::FilePath>& files) override;
123 void OnShimClose(Host* host) override;
124 void OnShimFocus(Host* host,
125 AppShimFocusType focus_type,
126 const std::vector<base::FilePath>& files) override;
127 void OnShimSetHidden(Host* host, bool hidden) override;
128 void OnShimQuit(Host* host) override;
130 // AppLifetimeMonitor::Observer overrides:
131 void OnAppStart(Profile* profile, const std::string& app_id) override;
132 void OnAppActivated(Profile* profile, const std::string& app_id) override;
133 void OnAppDeactivated(Profile* profile, const std::string& app_id) override;
134 void OnAppStop(Profile* profile, const std::string& app_id) override;
135 void OnChromeTerminating() override;
137 // content::NotificationObserver overrides:
138 void Observe(int type,
139 const content::NotificationSource& source,
140 const content::NotificationDetails& details) override;
142 // chrome::BrowserListObserver overrides;
143 void OnBrowserAdded(Browser* browser) override;
144 void OnBrowserRemoved(Browser* browser) override;
146 protected:
147 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*>
148 HostMap;
149 typedef std::set<Browser*> BrowserSet;
150 typedef std::map<std::string, BrowserSet> AppBrowserMap;
152 // Exposed for testing.
153 void set_delegate(Delegate* delegate);
154 HostMap& hosts() { return hosts_; }
155 content::NotificationRegistrar& registrar() { return registrar_; }
157 private:
158 // Helper function to get the instance on the browser process.
159 static ExtensionAppShimHandler* GetInstance();
161 // Gets the extension for the corresponding |host|. Note that extensions can
162 // be uninstalled at any time (even between sending OnAppClosed() to the host,
163 // and receiving the quit confirmation). If the extension has been uninstalled
164 // or disabled, the host is immediately closed. If non-nil, the Extension's
165 // Profile will be set in |profile|.
166 const extensions::Extension* MaybeGetExtensionOrCloseHost(Host* host,
167 Profile** profile);
169 // Closes all browsers associated with an app.
170 void CloseBrowsersForApp(const std::string& app_id);
172 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches
173 // where the profile was not yet loaded.
174 void OnProfileLoaded(Host* host,
175 AppShimLaunchType launch_type,
176 const std::vector<base::FilePath>& files,
177 Profile* profile);
179 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches
180 // where the extension is disabled.
181 void OnExtensionEnabled(const base::FilePath& profile_path,
182 const std::string& app_id,
183 const std::vector<base::FilePath>& files);
185 scoped_ptr<Delegate> delegate_;
187 HostMap hosts_;
189 // A map of app ids to associated browser windows.
190 AppBrowserMap app_browser_windows_;
192 content::NotificationRegistrar registrar_;
194 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_;
196 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler);
199 } // namespace apps
201 #endif // CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_