Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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 |
| 75 static void QuitAppForWindow(extensions::AppWindow* app_window); | 79 static void QuitAppForWindow(extensions::AppWindow* app_window); |
| 76 | 80 |
| 81 static void QuitHostedAppForWindow(Browser* browser, | |
| 82 const extensions::Extension* extension); | |
| 83 | |
| 77 static void HideAppForWindow(extensions::AppWindow* app_window); | 84 static void HideAppForWindow(extensions::AppWindow* app_window); |
| 78 | 85 |
| 86 static void HideHostedApp(Profile* profile, const std::string& app_id); | |
| 87 | |
| 88 void SetHostedAppHidden(Profile* profile, | |
|
jackhou1
2014/12/12 00:48:29
Move this below FindHost.
mitchellj
2014/12/12 03:46:23
Done.
| |
| 89 const std::string& app_id, | |
| 90 bool hidden); | |
| 91 | |
| 79 static void FocusAppForWindow(extensions::AppWindow* app_window); | 92 static void FocusAppForWindow(extensions::AppWindow* app_window); |
| 80 | 93 |
| 94 const static extensions::Extension* GetAppExtension( | |
|
jackhou1
2014/12/12 00:48:29
s/const static/static const/
Also move this so th
mitchellj
2014/12/12 03:46:23
Done.
| |
| 95 Profile* profile, | |
| 96 const std::string& extension_id); | |
| 97 | |
| 81 // Brings the window to the front without showing it and instructs the shim to | 98 // 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. | 99 // request user attention. If there is no shim, show the app and return false. |
| 83 static bool ActivateAndRequestUserAttentionForWindow( | 100 static bool ActivateAndRequestUserAttentionForWindow( |
| 84 extensions::AppWindow* app_window); | 101 extensions::AppWindow* app_window); |
| 85 | 102 |
| 86 // Instructs the shim to request user attention. Returns false if there is no | 103 // Instructs the shim to request user attention. Returns false if there is no |
| 87 // shim for this window. | 104 // shim for this window. |
| 88 static void RequestUserAttentionForWindow( | 105 static void RequestUserAttentionForWindow( |
| 89 extensions::AppWindow* app_window, | 106 extensions::AppWindow* app_window, |
| 90 AppShimAttentionType attention_type); | 107 AppShimAttentionType attention_type); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 108 void OnAppActivated(Profile* profile, const std::string& app_id) override; | 125 void OnAppActivated(Profile* profile, const std::string& app_id) override; |
| 109 void OnAppDeactivated(Profile* profile, const std::string& app_id) override; | 126 void OnAppDeactivated(Profile* profile, const std::string& app_id) override; |
| 110 void OnAppStop(Profile* profile, const std::string& app_id) override; | 127 void OnAppStop(Profile* profile, const std::string& app_id) override; |
| 111 void OnChromeTerminating() override; | 128 void OnChromeTerminating() override; |
| 112 | 129 |
| 113 // content::NotificationObserver overrides: | 130 // content::NotificationObserver overrides: |
| 114 void Observe(int type, | 131 void Observe(int type, |
| 115 const content::NotificationSource& source, | 132 const content::NotificationSource& source, |
| 116 const content::NotificationDetails& details) override; | 133 const content::NotificationDetails& details) override; |
| 117 | 134 |
| 135 // chrome::BrowserListObserver overrides; | |
| 136 void OnBrowserAdded(Browser* browser) override; | |
| 137 void OnBrowserRemoved(Browser* browser) override; | |
| 138 | |
| 118 protected: | 139 protected: |
| 119 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*> | 140 typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*> |
| 120 HostMap; | 141 HostMap; |
| 142 typedef std::set<Browser*> BrowserSet; | |
| 143 typedef std::map<std::string, BrowserSet> AppBrowserMap; | |
| 121 | 144 |
| 122 // Exposed for testing. | 145 // Exposed for testing. |
| 123 void set_delegate(Delegate* delegate); | 146 void set_delegate(Delegate* delegate); |
| 124 HostMap& hosts() { return hosts_; } | 147 HostMap& hosts() { return hosts_; } |
| 125 content::NotificationRegistrar& registrar() { return registrar_; } | 148 content::NotificationRegistrar& registrar() { return registrar_; } |
| 126 | 149 |
| 127 private: | 150 private: |
| 128 // Helper function to get the instance on the browser process. | 151 // Helper function to get the instance on the browser process. |
| 129 static ExtensionAppShimHandler* GetInstance(); | 152 static ExtensionAppShimHandler* GetInstance(); |
| 130 | 153 |
| 131 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches | 154 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches |
| 132 // where the profile was not yet loaded. | 155 // where the profile was not yet loaded. |
| 133 void OnProfileLoaded(Host* host, | 156 void OnProfileLoaded(Host* host, |
| 134 AppShimLaunchType launch_type, | 157 AppShimLaunchType launch_type, |
| 135 const std::vector<base::FilePath>& files, | 158 const std::vector<base::FilePath>& files, |
| 136 Profile* profile); | 159 Profile* profile); |
| 137 | 160 |
| 138 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches | 161 // This is passed to Delegate::EnableViaPrompt for shim-initiated launches |
| 139 // where the extension is disabled. | 162 // where the extension is disabled. |
| 140 void OnExtensionEnabled(const base::FilePath& profile_path, | 163 void OnExtensionEnabled(const base::FilePath& profile_path, |
| 141 const std::string& app_id, | 164 const std::string& app_id, |
| 142 const std::vector<base::FilePath>& files); | 165 const std::vector<base::FilePath>& files); |
| 143 | 166 |
| 144 scoped_ptr<Delegate> delegate_; | 167 scoped_ptr<Delegate> delegate_; |
| 145 | 168 |
| 146 HostMap hosts_; | 169 HostMap hosts_; |
| 147 | 170 |
| 171 // A map of app ids to associated browser windows. | |
| 172 AppBrowserMap app_browser_windows_; | |
| 173 | |
| 148 content::NotificationRegistrar registrar_; | 174 content::NotificationRegistrar registrar_; |
| 149 | 175 |
| 150 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_; | 176 base::WeakPtrFactory<ExtensionAppShimHandler> weak_factory_; |
| 151 | 177 |
| 152 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler); | 178 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler); |
| 153 }; | 179 }; |
| 154 | 180 |
| 155 } // namespace apps | 181 } // namespace apps |
| 156 | 182 |
| 157 #endif // CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ | 183 #endif // CHROME_BROWSER_APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_MAC_H_ |
| OLD | NEW |