blob: 10a33dcbd475806cafddc956beef090ad99b1aff [file] [log] [blame]
[email protected]b6b72222012-02-11 02:04:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]9bc8cff2010-04-03 01:05:395#ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_
6#define CHROME_BROWSER_SHELL_INTEGRATION_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <string>
9
[email protected]b96aa932009-08-12 21:34:4910#include "base/basictypes.h"
[email protected]378017072012-02-24 06:52:4711#include "base/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]b96aa932009-08-12 21:34:4913#include "base/string16.h"
[email protected]42896802009-08-28 23:39:4414#include "googleurl/src/gurl.h"
[email protected]bdd6eec2012-03-03 19:58:0615#include "ui/gfx/image/image.h"
[email protected]0b303cc2009-09-28 22:35:1516
[email protected]b10392932011-03-08 21:28:1417class CommandLine;
[email protected]d24c4012009-07-28 01:57:3118
initial.commit09911bf2008-07-26 23:55:2919class ShellIntegration {
20 public:
[email protected]4468a5b2011-05-26 07:48:0221 // Sets Chrome as the default browser (only for the current user). Returns
22 // false if this operation fails.
initial.commit09911bf2008-07-26 23:55:2923 static bool SetAsDefaultBrowser();
24
[email protected]bd046bd42012-06-08 05:07:3225 // Initiates an OS shell flow which (if followed by the user) should set
26 // Chrome as the default browser. Returns false if the flow cannot be
27 // initialized, if it is not supported (introduced for Windows 8) or if the
28 // user cancels the operation. This is a blocking call and requires a FILE
[email protected]0e94de002012-11-09 01:38:3429 // thread. If Chrome is already default browser, no interactive dialog will be
30 // shown and this method returns true.
[email protected]bd046bd42012-06-08 05:07:3231 static bool SetAsDefaultBrowserInteractive();
32
[email protected]4468a5b2011-05-26 07:48:0233 // Sets Chrome as the default client application for the given protocol
34 // (only for the current user). Returns false if this operation fails.
35 static bool SetAsDefaultProtocolClient(const std::string& protocol);
36
[email protected]ee9d89d2012-09-25 18:21:0337 // Initiates an OS shell flow which (if followed by the user) should set
38 // Chrome as the default handler for |protocol|. Returns false if the flow
39 // cannot be initialized, if it is not supported (introduced for Windows 8)
40 // or if the user cancels the operation. This is a blocking call and requires
[email protected]0e94de002012-11-09 01:38:3441 // a FILE thread. If Chrome is already default for |protocol|, no interactive
42 // dialog will be shown and this method returns true.
[email protected]ee9d89d2012-09-25 18:21:0343 static bool SetAsDefaultProtocolClientInteractive(
44 const std::string& protocol);
45
[email protected]bd046bd42012-06-08 05:07:3246 // In Windows 8 a browser can be made default-in-metro only in an interactive
47 // flow. We will distinguish between two types of permissions here to avoid
48 // forcing the user into UI interaction when this should not be done.
49 enum DefaultWebClientSetPermission {
[email protected]89886652012-12-11 18:09:0750 SET_DEFAULT_NOT_ALLOWED,
[email protected]bd046bd42012-06-08 05:07:3251 SET_DEFAULT_UNATTENDED,
52 SET_DEFAULT_INTERACTIVE,
53 };
[email protected]a01481b2011-07-15 04:30:0254
[email protected]bd046bd42012-06-08 05:07:3255 // Returns requirements for making the running browser the user's default.
56 static DefaultWebClientSetPermission CanSetAsDefaultBrowser();
57
58 // Returns requirements for making the running browser the user's default
59 // client application for specific protocols.
60 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient();
[email protected]a01481b2011-07-15 04:30:0261
[email protected]264f74d12009-09-04 23:39:5862 // On Linux, it may not be possible to determine or set the default browser
63 // on some desktop environments or configurations. So, we use this enum and
[email protected]89886652012-12-11 18:09:0764 // not a plain bool.
[email protected]4468a5b2011-05-26 07:48:0265 enum DefaultWebClientState {
[email protected]89886652012-12-11 18:09:0766 NOT_DEFAULT,
67 IS_DEFAULT,
68 UNKNOWN_DEFAULT,
69 NUM_DEFAULT_STATES
[email protected]264f74d12009-09-04 23:39:5870 };
71
72 // Attempt to determine if this instance of Chrome is the default browser and
73 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
74 // protocols; we don't want to report "no" here if the user has simply chosen
75 // to open HTML files in a text editor and FTP links with an FTP client.)
[email protected]89886652012-12-11 18:09:0776 static DefaultWebClientState GetDefaultBrowser();
initial.commit09911bf2008-07-26 23:55:2977
[email protected]cd63ef62009-05-06 19:41:3778 // Returns true if Firefox is likely to be the default browser for the current
initial.commit09911bf2008-07-26 23:55:2979 // user. This method is very fast so it can be invoked in the UI thread.
80 static bool IsFirefoxDefaultBrowser();
[email protected]d24c4012009-07-28 01:57:3181
[email protected]4468a5b2011-05-26 07:48:0282 // Attempt to determine if this instance of Chrome is the default client
83 // application for the given protocol and return the appropriate state.
84 static DefaultWebClientState
85 IsDefaultProtocolClient(const std::string& protocol);
86
[email protected]ed5431872009-11-17 08:39:5187 struct ShortcutInfo {
[email protected]93aa89c72010-10-20 21:32:0488 ShortcutInfo();
89 ~ShortcutInfo();
90
[email protected]ed5431872009-11-17 08:39:5191 GURL url;
[email protected]28375ae2010-02-05 04:45:5092 // If |extension_id| is non-empty, this is short cut is to an extension-app
93 // and the launch url will be detected at start-up. In this case, |url|
94 // is still used to generate the app id (windows app id, not chrome app id).
[email protected]01ed1962011-03-04 19:03:1395 std::string extension_id;
[email protected]3e3ad7f62012-11-27 04:55:3896 bool is_platform_app;
[email protected]ed5431872009-11-17 08:39:5197 string16 title;
98 string16 description;
[email protected]378017072012-02-24 06:52:4799 FilePath extension_path;
[email protected]bdd6eec2012-03-03 19:58:06100 gfx::Image favicon;
[email protected]5951c852012-06-20 00:12:53101 FilePath profile_path;
[email protected]ed5431872009-11-17 08:39:51102
[email protected]ed5431872009-11-17 08:39:51103 bool create_on_desktop;
104 bool create_in_applications_menu;
105
106 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
107 // this means "pin to taskbar". For Mac/Linux, this could be used for
108 // Mac dock or the gnome/kde application launcher. However, those are not
109 // implemented yet.
110 bool create_in_quick_launch_bar;
111 };
112
[email protected]9561bc912012-03-07 02:41:16113 // Data that needs to be passed between the app launcher stub and Chrome.
114 struct AppModeInfo {
115 };
116 static void SetAppModeInfo(const AppModeInfo* info);
117 static const AppModeInfo* AppModeInfo();
118
119 // Is the current instance of Chrome running in App mode.
120 bool IsRunningInAppMode();
121
[email protected]b10392932011-03-08 21:28:14122 // Set up command line arguments for launching a URL or an app.
123 // The new command line reuses the current process's user data directory (and
124 // login profile, for ChromeOS).
125 // If |extension_app_id| is non-empty, the arguments use kAppId=<id>.
[email protected]dd5f67e92012-09-06 04:19:22126 // Otherwise, kApp=<url> is used.
[email protected]b10392932011-03-08 21:28:14127 static CommandLine CommandLineArgsForLauncher(
[email protected]01ed1962011-03-04 19:03:13128 const GURL& url,
[email protected]5a20b192012-03-01 06:01:57129 const std::string& extension_app_id,
[email protected]5951c852012-06-20 00:12:53130 const FilePath& profile_path);
[email protected]5a20b192012-03-01 06:01:57131
[email protected]12f520c2010-01-06 18:11:15132#if defined(OS_WIN)
[email protected]a0448002012-06-19 04:32:10133 // Generates an application user model ID (AppUserModelId) for a given app
134 // name and profile path. The returned app id is in the format of
135 // "|app_name|[.<profile_id>]". "profile_id" is appended when user override
136 // the default value.
137 // Note: If the app has an installation specific suffix (e.g. on user-level
138 // Chrome installs), |app_name| should already be suffixed, this method will
139 // then further suffix it with the profile id as described above.
140 static string16 GetAppModelIdForProfile(const string16& app_name,
141 const FilePath& profile_path);
[email protected]12f520c2010-01-06 18:11:15142
[email protected]a0448002012-06-19 04:32:10143 // Generates an application user model ID (AppUserModelId) for Chromium by
144 // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
145 static string16 GetChromiumModelIdForProfile(const FilePath& profile_path);
[email protected]c9bb06f42010-01-13 23:53:48146
[email protected]99002fd2012-11-06 04:35:52147 // Get the AppUserModelId for the App List, for the profile in |profile_path|.
148 static string16 GetAppListAppModelIdForProfile(const FilePath& profile_path);
149
[email protected]9c91fc22012-11-20 04:13:49150 // Returns the location (path and index) of the Chromium icon, (e.g.,
151 // "C:\path\to\chrome.exe,0"). This is used to specify the icon to use
152 // for the taskbar group on Win 7.
153 static string16 GetChromiumIconLocation();
[email protected]2de2d622011-10-21 22:07:37154
[email protected]c9bb06f42010-01-13 23:53:48155 // Migrates existing chrome shortcuts by tagging them with correct app id.
156 // see http://crbug.com/28104
157 static void MigrateChromiumShortcuts();
[email protected]43903b82012-06-01 05:26:23158
[email protected]8ea8f1ef2013-01-06 18:39:03159 // Migrates all shortcuts in |path| which point to |chrome_exe| such that they
160 // have the appropriate AppUserModelId. Also makes sure those shortcuts have
161 // the dual_mode property set if such is requested by |check_dual_mode|.
162 // Returns the number of shortcuts migrated.
163 // This method should not be called prior to Windows 7.
164 // This method is only public for the sake of tests and shouldn't be called
165 // externally otherwise.
166 static int MigrateShortcutsInPathInternal(const FilePath& chrome_exe,
167 const FilePath& path,
168 bool check_dual_mode);
169
[email protected]3f69d6e612012-08-03 18:52:27170 // Returns the path to the Start Menu shortcut for the given Chrome.
171 static FilePath GetStartMenuShortcut(const FilePath& chrome_exe);
[email protected]12f520c2010-01-06 18:11:15172#endif // defined(OS_WIN)
173
[email protected]4468a5b2011-05-26 07:48:02174 // The current default web client application UI state. This is used when
175 // querying if Chrome is the default browser or the default handler
176 // application for a url protocol, and communicates the state and result of
177 // a request.
178 enum DefaultWebClientUIState {
[email protected]d24c4012009-07-28 01:57:31179 STATE_PROCESSING,
[email protected]264f74d12009-09-04 23:39:58180 STATE_NOT_DEFAULT,
181 STATE_IS_DEFAULT,
182 STATE_UNKNOWN
[email protected]d24c4012009-07-28 01:57:31183 };
184
[email protected]4468a5b2011-05-26 07:48:02185 class DefaultWebClientObserver {
[email protected]d24c4012009-07-28 01:57:31186 public:
[email protected]4468a5b2011-05-26 07:48:02187 virtual ~DefaultWebClientObserver() {}
[email protected]d24c4012009-07-28 01:57:31188 // Updates the UI state to reflect the current default browser state.
[email protected]4468a5b2011-05-26 07:48:02189 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0;
[email protected]693baa5d2012-06-22 22:23:38190 // Called to notify the UI of the immediate result of invoking
191 // SetAsDefault.
192 virtual void OnSetAsDefaultConcluded(bool succeeded) {}
[email protected]97e2e3f2011-07-22 10:21:25193 // Observer classes that return true to OwnedByWorker are automatically
[email protected]693baa5d2012-06-22 22:23:38194 // freed by the worker when they are no longer needed. False by default.
195 virtual bool IsOwnedByWorker();
[email protected]bd046bd42012-06-08 05:07:32196 // An observer can permit or decline set-as-default operation if it
[email protected]693baa5d2012-06-22 22:23:38197 // requires triggering user interaction. By default not allowed.
198 virtual bool IsInteractiveSetDefaultPermitted();
[email protected]d24c4012009-07-28 01:57:31199 };
[email protected]4468a5b2011-05-26 07:48:02200
201 // Helper objects that handle checking if Chrome is the default browser
202 // or application for a url protocol on Windows and Linux, and also setting
203 // it as the default. These operations are performed asynchronously on the
204 // file thread since registry access (on Windows) or the preference database
205 // (on Linux) are involved and this can be slow.
206 class DefaultWebClientWorker
207 : public base::RefCountedThreadSafe<DefaultWebClientWorker> {
[email protected]d24c4012009-07-28 01:57:31208 public:
[email protected]4468a5b2011-05-26 07:48:02209 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer);
[email protected]d24c4012009-07-28 01:57:31210
[email protected]4468a5b2011-05-26 07:48:02211 // Checks to see if Chrome is the default web client application. The result
212 // will be passed back to the observer via the SetDefaultWebClientUIState
213 // function. If there is no observer, this function does not do anything.
214 void StartCheckIsDefault();
[email protected]d24c4012009-07-28 01:57:31215
[email protected]4468a5b2011-05-26 07:48:02216 // Sets Chrome as the default web client application. If there is an
217 // observer, once the operation has completed the new default will be
218 // queried and the current status reported via SetDefaultWebClientUIState.
219 void StartSetAsDefault();
[email protected]d24c4012009-07-28 01:57:31220
221 // Called to notify the worker that the view is gone.
222 void ObserverDestroyed();
223
[email protected]4468a5b2011-05-26 07:48:02224 protected:
225 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>;
[email protected]e6e6ba42009-11-07 01:56:19226
[email protected]4468a5b2011-05-26 07:48:02227 virtual ~DefaultWebClientWorker() {}
228
229 private:
230 // Function that performs the check.
231 virtual DefaultWebClientState CheckIsDefault() = 0;
232
[email protected]693baa5d2012-06-22 22:23:38233 // Function that sets Chrome as the default web client. Returns false if
234 // the operation fails or has been cancelled by the user.
235 virtual bool SetAsDefault(bool interactive_permitted) = 0;
[email protected]4468a5b2011-05-26 07:48:02236
237 // Function that handles performing the check on the file thread. This
238 // function is posted as a task onto the file thread, where it performs
239 // the check. When the check has finished the CompleteCheckIsDefault
240 // function is posted to the UI thread, where the result is sent back to
241 // the observer.
242 void ExecuteCheckIsDefault();
243
244 // Function that handles setting Chrome as the default web client on the
245 // file thread. This function is posted as a task onto the file thread.
246 // Once it is finished the CompleteSetAsDefault function is posted to the
247 // UI thread which will check the status of Chrome as the default, and
248 // send this to the observer.
[email protected]693baa5d2012-06-22 22:23:38249 // |interactive_permitted| indicates if the routine is allowed to carry on
250 // in context where user interaction is required (CanSetAsDefault*
251 // returns SET_DEFAULT_INTERACTIVE).
252 void ExecuteSetAsDefault(bool interactive_permitted);
[email protected]4468a5b2011-05-26 07:48:02253
254 // Communicate results to the observer. This function is posted as a task
255 // onto the UI thread by the ExecuteCheckIsDefault function running in the
256 // file thread.
257 void CompleteCheckIsDefault(DefaultWebClientState state);
258
259 // When the action to set Chrome as the default has completed this function
260 // is run. It is posted as a task back onto the UI thread by the
261 // ExecuteSetAsDefault function running in the file thread. This function
262 // will the start the check process, which, if an observer is present,
263 // reports to it the new status.
[email protected]693baa5d2012-06-22 22:23:38264 // |succeeded| is true if the actual call to a set-default function (from
265 // ExecuteSetAsDefault) was successful.
266 void CompleteSetAsDefault(bool succeeded);
[email protected]4468a5b2011-05-26 07:48:02267
268 // Updates the UI in our associated view with the current default web
269 // client state.
270 void UpdateUI(DefaultWebClientState state);
271
272 DefaultWebClientObserver* observer_;
273
274 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker);
275 };
276
277 // Worker for checking and setting the default browser.
278 class DefaultBrowserWorker : public DefaultWebClientWorker {
279 public:
280 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer);
281
282 private:
[email protected]e6e6ba42009-11-07 01:56:19283 virtual ~DefaultBrowserWorker() {}
284
[email protected]4468a5b2011-05-26 07:48:02285 // Check if Chrome is the default browser.
[email protected]49fd7e22011-11-21 16:52:21286 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31287
[email protected]4468a5b2011-05-26 07:48:02288 // Set Chrome as the default browser.
[email protected]693baa5d2012-06-22 22:23:38289 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31290
[email protected]d24c4012009-07-28 01:57:31291 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
292 };
[email protected]4468a5b2011-05-26 07:48:02293
294 // Worker for checking and setting the default client application
295 // for a given protocol. A different worker instance is needed for each
296 // protocol you are interested in, so to check or set the default for
297 // multiple protocols you should use multiple worker objects.
298 class DefaultProtocolClientWorker : public DefaultWebClientWorker {
299 public:
300 DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
301 const std::string& protocol);
302
[email protected]bcb999d2011-05-31 15:11:35303 const std::string& protocol() const { return protocol_; }
304
[email protected]97e2e3f2011-07-22 10:21:25305 protected:
[email protected]4468a5b2011-05-26 07:48:02306 virtual ~DefaultProtocolClientWorker() {}
307
[email protected]97e2e3f2011-07-22 10:21:25308 private:
[email protected]4468a5b2011-05-26 07:48:02309 // Check is Chrome is the default handler for this protocol.
[email protected]49fd7e22011-11-21 16:52:21310 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02311
312 // Set Chrome as the default handler for this protocol.
[email protected]693baa5d2012-06-22 22:23:38313 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02314
315 std::string protocol_;
316
317 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker);
318 };
initial.commit09911bf2008-07-26 23:55:29319};
320
[email protected]9bc8cff2010-04-03 01:05:39321#endif // CHROME_BROWSER_SHELL_INTEGRATION_H_