Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / apps / app_shim / extension_app_shim_handler_mac.h
blobbc8efb14c077c65e57f59f83468fd2b44de807b7
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 APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_
6 #define APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "apps/app_lifetime_monitor.h"
13 #include "apps/app_shim/app_shim_handler_mac.h"
14 #include "apps/app_window_registry.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
20 class Profile;
22 namespace base {
23 class FilePath;
26 namespace content {
27 class WebContents;
30 namespace extensions {
31 class Extension;
34 namespace apps {
36 class AppWindow;
38 // This app shim handler that handles events for app shims that correspond to an
39 // extension.
40 class ExtensionAppShimHandler : public AppShimHandler,
41 public content::NotificationObserver,
42 public AppLifetimeMonitor::Observer {
43 public:
44 class Delegate {
45 public:
46 virtual ~Delegate() {}
48 virtual bool ProfileExistsForPath(const base::FilePath& path);
49 virtual Profile* ProfileForPath(const base::FilePath& path);
50 virtual void LoadProfileAsync(const base::FilePath& path,
51 base::Callback<void(Profile*)> callback);
53 virtual AppWindowRegistry::AppWindowList GetWindows(
54 Profile* profile,
55 const std::string& extension_id);
57 virtual const extensions::Extension* GetAppExtension(
58 Profile* profile, const std::string& extension_id);
59 virtual void EnableExtension(Profile* profile,
60 const std::string& extension_id,
61 const base::Callback<void()>& callback);
62 virtual void LaunchApp(Profile* profile,
63 const extensions::Extension* extension,
64 const std::vector<base::FilePath>& files);
65 virtual void LaunchShim(Profile* profile,
66 const extensions::Extension* extension);
68 virtual void MaybeTerminate();
71 ExtensionAppShimHandler();
72 virtual ~ExtensionAppShimHandler();
74 AppShimHandler::Host* FindHost(Profile* profile, const std::string& app_id);
76 static void QuitAppForWindow(AppWindow* app_window);
78 static void HideAppForWindow(AppWindow* app_window);
80 static void FocusAppForWindow(AppWindow* app_window);
82 // Brings the window to the front without showing it and instructs the shim to
83 // request user attention. If there is no shim, show the app and return false.
84 static bool ActivateAndRequestUserAttentionForWindow(AppWindow* app_window);
86 // Instructs the shim to request user attention. Returns false if there is no
87 // shim for this window.
88 static void RequestUserAttentionForWindow(
89 AppWindow* app_window,
90 AppShimAttentionType attention_type);
92 // Called by AppControllerMac when Chrome hides.
93 static void OnChromeWillHide();
95 // AppShimHandler overrides:
96 virtual void OnShimLaunch(Host* host,
97 AppShimLaunchType launch_type,
98 const std::vector<base::FilePath>& files) OVERRIDE;
99 virtual void OnShimClose(Host* host) OVERRIDE;
100 virtual void OnShimFocus(Host* host,
101 AppShimFocusType focus_type,
102 const std::vector<base::FilePath>& files) OVERRIDE;
103 virtual void OnShimSetHidden(Host* host, bool hidden) OVERRIDE;
104 virtual void OnShimQuit(Host* host) OVERRIDE;
106 // AppLifetimeMonitor::Observer overrides:
107 virtual void OnAppStart(Profile* profile, const std::string& app_id) OVERRIDE;
108 virtual void OnAppActivated(Profile* profile,
109 const std::string& app_id) OVERRIDE;
110 virtual void OnAppDeactivated(Profile* profile,
111 const std::string& app_id) OVERRIDE;
112 virtual void OnAppStop(Profile* profile, const std::string& app_id) OVERRIDE;
113 virtual void OnChromeTerminating() OVERRIDE;
115 // content::NotificationObserver overrides:
116 virtual void Observe(int type,
117 const content::NotificationSource& source,
118 const content::NotificationDetails& details) OVERRIDE;
120 protected:
121 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*>
122 HostMap;
124 // Exposed for testing.
125 void set_delegate(Delegate* delegate);
126 HostMap& hosts() { return hosts_; }
127 content::NotificationRegistrar& registrar() { return registrar_; }
129 private:
130 // Helper function to get the instance on the browser process.
131 static ExtensionAppShimHandler* GetInstance();
133 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches
134 // where the profile was not yet loaded.
135 void OnProfileLoaded(Host* host,
136 AppShimLaunchType launch_type,
137 const std::vector<base::FilePath>& files,
138 Profile* profile);
140 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches
141 // where the extension is disabled.
142 void OnExtensionEnabled(const base::FilePath& profile_path,
143 const std::string& app_id,
144 const std::vector<base::FilePath>& files);
146 scoped_ptr<Delegate> delegate_;
148 HostMap hosts_;
150 content::NotificationRegistrar registrar_;
152 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_;
154 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler);
157 } // namespace apps
159 #endif // APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_