| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ | 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_ | 6 #define CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "apps/app_lifetime_monitor.h" | 13 #include "apps/app_lifetime_monitor.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.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" |
| 16 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/browser/app_window/app_window_registry.h" | 21 #include "extensions/browser/app_window/app_window_registry.h" |
| 19 | 22 |
| 20 class Profile; | 23 class Profile; |
| 21 | 24 |
| 22 namespace base { | 25 namespace base { |
| 23 class FilePath; | 26 class FilePath; |
| 24 } | 27 } |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 class WebContents; | 30 class WebContents; |
| 28 } | 31 } |
| 29 | 32 |
| 30 namespace extensions { | 33 namespace extensions { |
| 31 class AppWindow; | 34 class AppWindow; |
| 32 class Extension; | 35 class Extension; |
| 33 } | 36 } |
| 34 | 37 |
| 35 namespace apps { | 38 namespace apps { |
| 36 | 39 |
| 37 // This app shim handler that handles events for app shims that correspond to an | 40 // This app shim handler that handles events for app shims that correspond to an |
| 38 // extension. | 41 // extension. |
| 39 class ExtensionAppShimHandler : public AppShimHandler, | 42 class ExtensionAppShimHandler : public AppShimHandler, |
| 40 public content::NotificationObserver, | 43 public content::NotificationObserver, |
| 41 public AppLifetimeMonitor::Observer { | 44 public AppLifetimeMonitor::Observer, |
| 45 public chrome::BrowserListObserver { |
| 42 public: | 46 public: |
| 43 class Delegate { | 47 class Delegate { |
| 44 public: | 48 public: |
| 45 virtual ~Delegate() {} | 49 virtual ~Delegate() {} |
| 46 | 50 |
| 47 virtual bool ProfileExistsForPath(const base::FilePath& path); | 51 virtual bool ProfileExistsForPath(const base::FilePath& path); |
| 48 virtual Profile* ProfileForPath(const base::FilePath& path); | 52 virtual Profile* ProfileForPath(const base::FilePath& path); |
| 49 virtual void LoadProfileAsync(const base::FilePath& path, | 53 virtual void LoadProfileAsync(const base::FilePath& path, |
| 50 base::Callback<void(Profile*)> callback); | 54 base::Callback<void(Profile*)> callback); |
| 51 | 55 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 const extensions::Extension* extension); | 69 const extensions::Extension* extension); |
| 66 | 70 |
| 67 virtual void MaybeTerminate(); | 71 virtual void MaybeTerminate(); |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 ExtensionAppShimHandler(); | 74 ExtensionAppShimHandler(); |
| 71 ~ExtensionAppShimHandler() override; | 75 ~ExtensionAppShimHandler() override; |
| 72 | 76 |
| 73 AppShimHandler::Host* FindHost(Profile* profile, const std::string& app_id); | 77 AppShimHandler::Host* FindHost(Profile* profile, const std::string& app_id); |
| 74 | 78 |
| 79 void SetHostedAppHidden(Profile* profile, |
| 80 const std::string& app_id, |
| 81 bool hidden); |
| 82 |
| 83 static const extensions::Extension* GetAppExtension( |
| 84 Profile* profile, |
| 85 const std::string& extension_id); |
| 86 |
| 87 static const extensions::Extension* GetAppForBrowser(Browser* browser); |
| 88 |
| 75 static void QuitAppForWindow(extensions::AppWindow* app_window); | 89 static void QuitAppForWindow(extensions::AppWindow* app_window); |
| 76 | 90 |
| 91 static void QuitHostedAppForWindow(Profile* profile, |
| 92 const std::string& app_id); |
| 93 |
| 77 static void HideAppForWindow(extensions::AppWindow* app_window); | 94 static void HideAppForWindow(extensions::AppWindow* app_window); |
| 78 | 95 |
| 96 static void HideHostedApp(Profile* profile, const std::string& app_id); |
| 97 |
| 79 static void FocusAppForWindow(extensions::AppWindow* app_window); | 98 static void FocusAppForWindow(extensions::AppWindow* app_window); |
| 80 | 99 |
| 81 // Brings the window to the front without showing it and instructs the shim to | 100 // Brings the window to the front without showing it and instructs the shim to |
| 82 // request user attention. If there is no shim, show the app and return false. | 101 // request user attention. If there is no shim, show the app and return false. |
| 83 static bool ActivateAndRequestUserAttentionForWindow( | 102 static bool ActivateAndRequestUserAttentionForWindow( |
| 84 extensions::AppWindow* app_window); | 103 extensions::AppWindow* app_window); |
| 85 | 104 |
| 86 // Instructs the shim to request user attention. Returns false if there is no | 105 // Instructs the shim to request user attention. Returns false if there is no |
| 87 // shim for this window. | 106 // shim for this window. |
| 88 static void RequestUserAttentionForWindow( | 107 static void RequestUserAttentionForWindow( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 void OnAppActivated(Profile* profile, const std::string& app_id) override; | 127 void OnAppActivated(Profile* profile, const std::string& app_id) override; |
| 109 void OnAppDeactivated(Profile* profile, const std::string& app_id) override; | 128 void OnAppDeactivated(Profile* profile, const std::string& app_id) override; |
| 110 void OnAppStop(Profile* profile, const std::string& app_id) override; | 129 void OnAppStop(Profile* profile, const std::string& app_id) override; |
| 111 void OnChromeTerminating() override; | 130 void OnChromeTerminating() override; |
| 112 | 131 |
| 113 // content::NotificationObserver overrides: | 132 // content::NotificationObserver overrides: |
| 114 void Observe(int type, | 133 void Observe(int type, |
| 115 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
| 116 const content::NotificationDetails& details) override; | 135 const content::NotificationDetails& details) override; |
| 117 | 136 |
| 137 // chrome::BrowserListObserver overrides; |
| 138 void OnBrowserAdded(Browser* browser) override; |
| 139 void OnBrowserRemoved(Browser* browser) override; |
| 140 |
| 118 protected: | 141 protected: |
| 119 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*> | 142 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*> |
| 120 HostMap; | 143 HostMap; |
| 144 typedef std::set<Browser*> BrowserSet; |
| 145 typedef std::map<std::string, BrowserSet> AppBrowserMap; |
| 121 | 146 |
| 122 // Exposed for testing. | 147 // Exposed for testing. |
| 123 void set_delegate(Delegate* delegate); | 148 void set_delegate(Delegate* delegate); |
| 124 HostMap& hosts() { return hosts_; } | 149 HostMap& hosts() { return hosts_; } |
| 125 content::NotificationRegistrar& registrar() { return registrar_; } | 150 content::NotificationRegistrar& registrar() { return registrar_; } |
| 126 | 151 |
| 127 private: | 152 private: |
| 128 // Helper function to get the instance on the browser process. | 153 // Helper function to get the instance on the browser process. |
| 129 static ExtensionAppShimHandler* GetInstance(); | 154 static ExtensionAppShimHandler* GetInstance(); |
| 130 | 155 |
| 156 // Closes all browsers associated with an app. |
| 157 void CloseBrowsersForApp(const std::string& app_id); |
| 158 |
| 131 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches | 159 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches |
| 132 // where the profile was not yet loaded. | 160 // where the profile was not yet loaded. |
| 133 void OnProfileLoaded(Host* host, | 161 void OnProfileLoaded(Host* host, |
| 134 AppShimLaunchType launch_type, | 162 AppShimLaunchType launch_type, |
| 135 const std::vector<base::FilePath>& files, | 163 const std::vector<base::FilePath>& files, |
| 136 Profile* profile); | 164 Profile* profile); |
| 137 | 165 |
| 138 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches | 166 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches |
| 139 // where the extension is disabled. | 167 // where the extension is disabled. |
| 140 void OnExtensionEnabled(const base::FilePath& profile_path, | 168 void OnExtensionEnabled(const base::FilePath& profile_path, |
| 141 const std::string& app_id, | 169 const std::string& app_id, |
| 142 const std::vector<base::FilePath>& files); | 170 const std::vector<base::FilePath>& files); |
| 143 | 171 |
| 144 scoped_ptr<Delegate> delegate_; | 172 scoped_ptr<Delegate> delegate_; |
| 145 | 173 |
| 146 HostMap hosts_; | 174 HostMap hosts_; |
| 147 | 175 |
| 176 // A map of app ids to associated browser windows. |
| 177 AppBrowserMap app_browser_windows_; |
| 178 |
| 148 content::NotificationRegistrar registrar_; | 179 content::NotificationRegistrar registrar_; |
| 149 | 180 |
| 150 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_; | 181 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_; |
| 151 | 182 |
| 152 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler); | 183 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler); |
| 153 }; | 184 }; |
| 154 | 185 |
| 155 } // namespace apps | 186 } // namespace apps |
| 156 | 187 |
| 157 #endif // CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ | 188 #endif // CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ |
| OLD | NEW |