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