[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| 6 | #define CHROME_BROWSER_SHELL_INTEGRATION_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 37801707 | 2012-02-24 06:52:47 | [diff] [blame] | 12 | #include "base/file_path.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 14 | #include "base/string16.h" |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 15 | #include "googleurl/src/gurl.h" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 16 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 17 | |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 18 | class CommandLine; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 19 | |
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 20 | #if defined(USE_X11) |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 21 | namespace base { |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 22 | class Environment; |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 23 | } |
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 24 | #endif |
[email protected] | af71d64 | 2010-03-12 10:29:04 | [diff] [blame] | 25 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | class ShellIntegration { |
| 27 | public: |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 28 | // Sets Chrome as the default browser (only for the current user). Returns |
| 29 | // false if this operation fails. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | static bool SetAsDefaultBrowser(); |
| 31 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 32 | // Sets Chrome as the default client application for the given protocol |
| 33 | // (only for the current user). Returns false if this operation fails. |
| 34 | static bool SetAsDefaultProtocolClient(const std::string& protocol); |
| 35 | |
[email protected] | a01481b | 2011-07-15 04:30:02 | [diff] [blame] | 36 | // Returns true if the running browser can be set as the default browser. |
| 37 | static bool CanSetAsDefaultBrowser(); |
| 38 | |
| 39 | // Returns true if the running browser can be set as the default client |
[email protected] | 5e3e0963 | 2011-07-18 02:25:31 | [diff] [blame] | 40 | // application for specific protocols. |
| 41 | static bool CanSetAsDefaultProtocolClient(); |
[email protected] | a01481b | 2011-07-15 04:30:02 | [diff] [blame] | 42 | |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame] | 43 | // On Linux, it may not be possible to determine or set the default browser |
| 44 | // on some desktop environments or configurations. So, we use this enum and |
| 45 | // not a plain bool. (Note however that if used like a bool, this enum will |
| 46 | // have reasonable behavior.) |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 47 | enum DefaultWebClientState { |
| 48 | NOT_DEFAULT_WEB_CLIENT = 0, |
| 49 | IS_DEFAULT_WEB_CLIENT, |
| 50 | UNKNOWN_DEFAULT_WEB_CLIENT = -1 |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | // Attempt to determine if this instance of Chrome is the default browser and |
| 54 | // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| 55 | // protocols; we don't want to report "no" here if the user has simply chosen |
| 56 | // to open HTML files in a text editor and FTP links with an FTP client.) |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 57 | static DefaultWebClientState IsDefaultBrowser(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | |
[email protected] | cd63ef6 | 2009-05-06 19:41:37 | [diff] [blame] | 59 | // Returns true if Firefox is likely to be the default browser for the current |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | // user. This method is very fast so it can be invoked in the UI thread. |
| 61 | static bool IsFirefoxDefaultBrowser(); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 62 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 63 | // Attempt to determine if this instance of Chrome is the default client |
| 64 | // application for the given protocol and return the appropriate state. |
| 65 | static DefaultWebClientState |
| 66 | IsDefaultProtocolClient(const std::string& protocol); |
| 67 | |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 68 | struct ShortcutInfo { |
[email protected] | 93aa89c7 | 2010-10-20 21:32:04 | [diff] [blame] | 69 | ShortcutInfo(); |
| 70 | ~ShortcutInfo(); |
| 71 | |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 72 | GURL url; |
[email protected] | 28375ae | 2010-02-05 04:45:50 | [diff] [blame] | 73 | // If |extension_id| is non-empty, this is short cut is to an extension-app |
| 74 | // and the launch url will be detected at start-up. In this case, |url| |
| 75 | // is still used to generate the app id (windows app id, not chrome app id). |
[email protected] | 01ed196 | 2011-03-04 19:03:13 | [diff] [blame] | 76 | std::string extension_id; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 77 | string16 title; |
| 78 | string16 description; |
[email protected] | 37801707 | 2012-02-24 06:52:47 | [diff] [blame] | 79 | FilePath extension_path; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 80 | SkBitmap favicon; |
| 81 | |
[email protected] | 5a20b19 | 2012-03-01 06:01:57 | [diff] [blame^] | 82 | // Shortcuts to platform apps are created differently. They start up with |
| 83 | // their own user data directory and load the app from |extension_path|. |
| 84 | bool is_platform_app; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 85 | bool create_on_desktop; |
| 86 | bool create_in_applications_menu; |
| 87 | |
| 88 | // For Windows, this refers to quick launch bar prior to Win7. In Win7, |
| 89 | // this means "pin to taskbar". For Mac/Linux, this could be used for |
| 90 | // Mac dock or the gnome/kde application launcher. However, those are not |
| 91 | // implemented yet. |
| 92 | bool create_in_quick_launch_bar; |
| 93 | }; |
| 94 | |
[email protected] | b1039293 | 2011-03-08 21:28:14 | [diff] [blame] | 95 | // Set up command line arguments for launching a URL or an app. |
| 96 | // The new command line reuses the current process's user data directory (and |
| 97 | // login profile, for ChromeOS). |
| 98 | // If |extension_app_id| is non-empty, the arguments use kAppId=<id>. |
| 99 | // Otherwise, kApp=<url> is used. |
| 100 | static CommandLine CommandLineArgsForLauncher( |
[email protected] | 01ed196 | 2011-03-04 19:03:13 | [diff] [blame] | 101 | const GURL& url, |
| 102 | const std::string& extension_app_id); |
[email protected] | 28375ae | 2010-02-05 04:45:50 | [diff] [blame] | 103 | |
[email protected] | 5a20b19 | 2012-03-01 06:01:57 | [diff] [blame^] | 104 | // Set up command line arguments for launching a platform app. |
| 105 | // The command line will have the switches --app-id, --user-data-dir and |
| 106 | // --load-extension, using values |extension_app_id|, |user_data_dir| and |
| 107 | // |extension_path| respectively. |
| 108 | static CommandLine CommandLineArgsForPlatformApp( |
| 109 | const std::string& extension_app_id, |
| 110 | const FilePath& user_data_dir, |
| 111 | const FilePath& extension_path); |
| 112 | |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 113 | #if defined(USE_X11) |
[email protected] | 1379919b | 2010-09-23 16:56:37 | [diff] [blame] | 114 | // Returns filename of the desktop shortcut used to launch the browser. |
[email protected] | c5ae574 | 2010-09-20 18:59:53 | [diff] [blame] | 115 | static std::string GetDesktopName(base::Environment* env); |
| 116 | |
[email protected] | 76b90d31 | 2010-08-03 03:00:50 | [diff] [blame] | 117 | static bool GetDesktopShortcutTemplate(base::Environment* env, |
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 118 | std::string* output); |
[email protected] | 620942e | 2010-02-16 10:12:12 | [diff] [blame] | 119 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 120 | // Returns filename for .desktop file based on |url|, sanitized for security. |
| 121 | static FilePath GetDesktopShortcutFilename(const GURL& url); |
| 122 | |
| 123 | // Returns contents for .desktop file based on |template_contents|, |url| |
| 124 | // and |title|. The |template_contents| should be contents of .desktop file |
| 125 | // used to launch Chrome. |
| 126 | static std::string GetDesktopFileContents( |
[email protected] | a0b60cfd | 2011-04-06 18:02:41 | [diff] [blame] | 127 | const std::string& template_contents, |
| 128 | const std::string& app_name, |
| 129 | const GURL& url, |
| 130 | const std::string& extension_id, |
| 131 | const string16& title, |
[email protected] | 28375ae | 2010-02-05 04:45:50 | [diff] [blame] | 132 | const std::string& icon_name); |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 133 | |
[email protected] | 620942e | 2010-02-16 10:12:12 | [diff] [blame] | 134 | static void CreateDesktopShortcut(const ShortcutInfo& shortcut_info, |
| 135 | const std::string& shortcut_template); |
[email protected] | 753efc4 | 2010-03-09 19:52:16 | [diff] [blame] | 136 | #endif // defined(USE_X11) |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 137 | |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 138 | #if defined(OS_WIN) |
| 139 | // Generates Win7 app id for given app name and profile path. The returned app |
| 140 | // id is in the format of "|app_name|[.<profile_id>]". "profile_id" is |
| 141 | // appended when user override the default value. |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 142 | static string16 GetAppId(const string16& app_name, |
| 143 | const FilePath& profile_path); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 144 | |
| 145 | // Generates Win7 app id for Chromium by calling GetAppId with |
| 146 | // chrome::kBrowserAppID as app_name. |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 147 | static string16 GetChromiumAppId(const FilePath& profile_path); |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 148 | |
[email protected] | 2de2d62 | 2011-10-21 22:07:37 | [diff] [blame] | 149 | // Returns the path to the Chromium icon. This is used to specify the icon |
| 150 | // to use for the taskbar group on Win 7. |
| 151 | static string16 GetChromiumIconPath(); |
| 152 | |
[email protected] | c9bb06f4 | 2010-01-13 23:53:48 | [diff] [blame] | 153 | // Migrates existing chrome shortcuts by tagging them with correct app id. |
| 154 | // see http://crbug.com/28104 |
| 155 | static void MigrateChromiumShortcuts(); |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 156 | #endif // defined(OS_WIN) |
| 157 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 158 | // The current default web client application UI state. This is used when |
| 159 | // querying if Chrome is the default browser or the default handler |
| 160 | // application for a url protocol, and communicates the state and result of |
| 161 | // a request. |
| 162 | enum DefaultWebClientUIState { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 163 | STATE_PROCESSING, |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame] | 164 | STATE_NOT_DEFAULT, |
| 165 | STATE_IS_DEFAULT, |
| 166 | STATE_UNKNOWN |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 167 | }; |
| 168 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 169 | class DefaultWebClientObserver { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 170 | public: |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 171 | virtual ~DefaultWebClientObserver() {} |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 172 | // Updates the UI state to reflect the current default browser state. |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 173 | virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
[email protected] | 97e2e3f | 2011-07-22 10:21:25 | [diff] [blame] | 174 | // Observer classes that return true to OwnedByWorker are automatically |
| 175 | // freed by the worker when they are no longer needed. |
| 176 | virtual bool IsOwnedByWorker() { return false; } |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 177 | }; |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 178 | |
| 179 | // Helper objects that handle checking if Chrome is the default browser |
| 180 | // or application for a url protocol on Windows and Linux, and also setting |
| 181 | // it as the default. These operations are performed asynchronously on the |
| 182 | // file thread since registry access (on Windows) or the preference database |
| 183 | // (on Linux) are involved and this can be slow. |
| 184 | class DefaultWebClientWorker |
| 185 | : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 186 | public: |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 187 | explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 188 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 189 | // Checks to see if Chrome is the default web client application. The result |
| 190 | // will be passed back to the observer via the SetDefaultWebClientUIState |
| 191 | // function. If there is no observer, this function does not do anything. |
| 192 | void StartCheckIsDefault(); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 193 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 194 | // Sets Chrome as the default web client application. If there is an |
| 195 | // observer, once the operation has completed the new default will be |
| 196 | // queried and the current status reported via SetDefaultWebClientUIState. |
| 197 | void StartSetAsDefault(); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 198 | |
| 199 | // Called to notify the worker that the view is gone. |
| 200 | void ObserverDestroyed(); |
| 201 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 202 | protected: |
| 203 | friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 204 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 205 | virtual ~DefaultWebClientWorker() {} |
| 206 | |
| 207 | private: |
| 208 | // Function that performs the check. |
| 209 | virtual DefaultWebClientState CheckIsDefault() = 0; |
| 210 | |
| 211 | // Function that sets Chrome as the default web client. |
| 212 | virtual void SetAsDefault() = 0; |
| 213 | |
| 214 | // Function that handles performing the check on the file thread. This |
| 215 | // function is posted as a task onto the file thread, where it performs |
| 216 | // the check. When the check has finished the CompleteCheckIsDefault |
| 217 | // function is posted to the UI thread, where the result is sent back to |
| 218 | // the observer. |
| 219 | void ExecuteCheckIsDefault(); |
| 220 | |
| 221 | // Function that handles setting Chrome as the default web client on the |
| 222 | // file thread. This function is posted as a task onto the file thread. |
| 223 | // Once it is finished the CompleteSetAsDefault function is posted to the |
| 224 | // UI thread which will check the status of Chrome as the default, and |
| 225 | // send this to the observer. |
| 226 | void ExecuteSetAsDefault(); |
| 227 | |
| 228 | // Communicate results to the observer. This function is posted as a task |
| 229 | // onto the UI thread by the ExecuteCheckIsDefault function running in the |
| 230 | // file thread. |
| 231 | void CompleteCheckIsDefault(DefaultWebClientState state); |
| 232 | |
| 233 | // When the action to set Chrome as the default has completed this function |
| 234 | // is run. It is posted as a task back onto the UI thread by the |
| 235 | // ExecuteSetAsDefault function running in the file thread. This function |
| 236 | // will the start the check process, which, if an observer is present, |
| 237 | // reports to it the new status. |
| 238 | void CompleteSetAsDefault(); |
| 239 | |
| 240 | // Updates the UI in our associated view with the current default web |
| 241 | // client state. |
| 242 | void UpdateUI(DefaultWebClientState state); |
| 243 | |
| 244 | DefaultWebClientObserver* observer_; |
| 245 | |
| 246 | DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 247 | }; |
| 248 | |
| 249 | // Worker for checking and setting the default browser. |
| 250 | class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 251 | public: |
| 252 | explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| 253 | |
| 254 | private: |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 255 | virtual ~DefaultBrowserWorker() {} |
| 256 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 257 | // Check if Chrome is the default browser. |
[email protected] | 49fd7e2 | 2011-11-21 16:52:21 | [diff] [blame] | 258 | virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 259 | |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 260 | // Set Chrome as the default browser. |
[email protected] | 49fd7e2 | 2011-11-21 16:52:21 | [diff] [blame] | 261 | virtual void SetAsDefault() OVERRIDE; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 262 | |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 263 | DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 264 | }; |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 265 | |
| 266 | // Worker for checking and setting the default client application |
| 267 | // for a given protocol. A different worker instance is needed for each |
| 268 | // protocol you are interested in, so to check or set the default for |
| 269 | // multiple protocols you should use multiple worker objects. |
| 270 | class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 271 | public: |
| 272 | DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 273 | const std::string& protocol); |
| 274 | |
[email protected] | bcb999d | 2011-05-31 15:11:35 | [diff] [blame] | 275 | const std::string& protocol() const { return protocol_; } |
| 276 | |
[email protected] | 97e2e3f | 2011-07-22 10:21:25 | [diff] [blame] | 277 | protected: |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 278 | virtual ~DefaultProtocolClientWorker() {} |
| 279 | |
[email protected] | 97e2e3f | 2011-07-22 10:21:25 | [diff] [blame] | 280 | private: |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 281 | // Check is Chrome is the default handler for this protocol. |
[email protected] | 49fd7e2 | 2011-11-21 16:52:21 | [diff] [blame] | 282 | virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 283 | |
| 284 | // Set Chrome as the default handler for this protocol. |
[email protected] | 49fd7e2 | 2011-11-21 16:52:21 | [diff] [blame] | 285 | virtual void SetAsDefault() OVERRIDE; |
[email protected] | 4468a5b | 2011-05-26 07:48:02 | [diff] [blame] | 286 | |
| 287 | std::string protocol_; |
| 288 | |
| 289 | DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 290 | }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | }; |
| 292 | |
[email protected] | 9bc8cff | 2010-04-03 01:05:39 | [diff] [blame] | 293 | #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |