blob: d8aca1f449eb03185d5d2a94253bad8c89c51114 [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
29 // thread.
30 static bool SetAsDefaultBrowserInteractive();
31
[email protected]4468a5b2011-05-26 07:48:0232 // 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]ee9d89d2012-09-25 18:21:0336 // Initiates an OS shell flow which (if followed by the user) should set
37 // Chrome as the default handler for |protocol|. Returns false if the flow
38 // cannot be initialized, if it is not supported (introduced for Windows 8)
39 // or if the user cancels the operation. This is a blocking call and requires
40 // a FILE thread.
41 static bool SetAsDefaultProtocolClientInteractive(
42 const std::string& protocol);
43
[email protected]bd046bd42012-06-08 05:07:3244 // In Windows 8 a browser can be made default-in-metro only in an interactive
45 // flow. We will distinguish between two types of permissions here to avoid
46 // forcing the user into UI interaction when this should not be done.
47 enum DefaultWebClientSetPermission {
48 SET_DEFAULT_NOT_ALLOWED = 0,
49 SET_DEFAULT_UNATTENDED,
50 SET_DEFAULT_INTERACTIVE,
51 };
[email protected]a01481b2011-07-15 04:30:0252
[email protected]bd046bd42012-06-08 05:07:3253 // Returns requirements for making the running browser the user's default.
54 static DefaultWebClientSetPermission CanSetAsDefaultBrowser();
55
56 // Returns requirements for making the running browser the user's default
57 // client application for specific protocols.
58 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient();
[email protected]a01481b2011-07-15 04:30:0259
[email protected]264f74d12009-09-04 23:39:5860 // On Linux, it may not be possible to determine or set the default browser
61 // on some desktop environments or configurations. So, we use this enum and
62 // not a plain bool. (Note however that if used like a bool, this enum will
63 // have reasonable behavior.)
[email protected]4468a5b2011-05-26 07:48:0264 enum DefaultWebClientState {
65 NOT_DEFAULT_WEB_CLIENT = 0,
66 IS_DEFAULT_WEB_CLIENT,
67 UNKNOWN_DEFAULT_WEB_CLIENT = -1
[email protected]264f74d12009-09-04 23:39:5868 };
69
70 // Attempt to determine if this instance of Chrome is the default browser and
71 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
72 // protocols; we don't want to report "no" here if the user has simply chosen
73 // to open HTML files in a text editor and FTP links with an FTP client.)
[email protected]4468a5b2011-05-26 07:48:0274 static DefaultWebClientState IsDefaultBrowser();
initial.commit09911bf2008-07-26 23:55:2975
[email protected]cd63ef62009-05-06 19:41:3776 // Returns true if Firefox is likely to be the default browser for the current
initial.commit09911bf2008-07-26 23:55:2977 // user. This method is very fast so it can be invoked in the UI thread.
78 static bool IsFirefoxDefaultBrowser();
[email protected]d24c4012009-07-28 01:57:3179
[email protected]4468a5b2011-05-26 07:48:0280 // Attempt to determine if this instance of Chrome is the default client
81 // application for the given protocol and return the appropriate state.
82 static DefaultWebClientState
83 IsDefaultProtocolClient(const std::string& protocol);
84
[email protected]ed5431872009-11-17 08:39:5185 struct ShortcutInfo {
[email protected]93aa89c72010-10-20 21:32:0486 ShortcutInfo();
87 ~ShortcutInfo();
88
[email protected]ed5431872009-11-17 08:39:5189 GURL url;
[email protected]28375ae2010-02-05 04:45:5090 // If |extension_id| is non-empty, this is short cut is to an extension-app
91 // and the launch url will be detected at start-up. In this case, |url|
92 // is still used to generate the app id (windows app id, not chrome app id).
[email protected]01ed1962011-03-04 19:03:1393 std::string extension_id;
[email protected]ed5431872009-11-17 08:39:5194 string16 title;
95 string16 description;
[email protected]378017072012-02-24 06:52:4796 FilePath extension_path;
[email protected]bdd6eec2012-03-03 19:58:0697 gfx::Image favicon;
[email protected]5951c852012-06-20 00:12:5398 FilePath profile_path;
[email protected]ed5431872009-11-17 08:39:5199
[email protected]ed5431872009-11-17 08:39:51100 bool create_on_desktop;
101 bool create_in_applications_menu;
102
103 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
104 // this means "pin to taskbar". For Mac/Linux, this could be used for
105 // Mac dock or the gnome/kde application launcher. However, those are not
106 // implemented yet.
107 bool create_in_quick_launch_bar;
108 };
109
[email protected]9561bc912012-03-07 02:41:16110 // Data that needs to be passed between the app launcher stub and Chrome.
111 struct AppModeInfo {
112 };
113 static void SetAppModeInfo(const AppModeInfo* info);
114 static const AppModeInfo* AppModeInfo();
115
116 // Is the current instance of Chrome running in App mode.
117 bool IsRunningInAppMode();
118
[email protected]b10392932011-03-08 21:28:14119 // Set up command line arguments for launching a URL or an app.
120 // The new command line reuses the current process's user data directory (and
121 // login profile, for ChromeOS).
122 // If |extension_app_id| is non-empty, the arguments use kAppId=<id>.
[email protected]dd5f67e92012-09-06 04:19:22123 // Otherwise, kApp=<url> is used.
[email protected]b10392932011-03-08 21:28:14124 static CommandLine CommandLineArgsForLauncher(
[email protected]01ed1962011-03-04 19:03:13125 const GURL& url,
[email protected]5a20b192012-03-01 06:01:57126 const std::string& extension_app_id,
[email protected]5951c852012-06-20 00:12:53127 const FilePath& profile_path);
[email protected]5a20b192012-03-01 06:01:57128
[email protected]12f520c2010-01-06 18:11:15129#if defined(OS_WIN)
[email protected]a0448002012-06-19 04:32:10130 // Generates an application user model ID (AppUserModelId) for a given app
131 // name and profile path. The returned app id is in the format of
132 // "|app_name|[.<profile_id>]". "profile_id" is appended when user override
133 // the default value.
134 // Note: If the app has an installation specific suffix (e.g. on user-level
135 // Chrome installs), |app_name| should already be suffixed, this method will
136 // then further suffix it with the profile id as described above.
137 static string16 GetAppModelIdForProfile(const string16& app_name,
138 const FilePath& profile_path);
[email protected]12f520c2010-01-06 18:11:15139
[email protected]a0448002012-06-19 04:32:10140 // Generates an application user model ID (AppUserModelId) for Chromium by
141 // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
142 static string16 GetChromiumModelIdForProfile(const FilePath& profile_path);
[email protected]c9bb06f42010-01-13 23:53:48143
[email protected]99002fd2012-11-06 04:35:52144 // Get the AppUserModelId for the App List, for the profile in |profile_path|.
145 static string16 GetAppListAppModelIdForProfile(const FilePath& profile_path);
146
[email protected]2de2d622011-10-21 22:07:37147 // Returns the path to the Chromium icon. This is used to specify the icon
148 // to use for the taskbar group on Win 7.
149 static string16 GetChromiumIconPath();
150
[email protected]c9bb06f42010-01-13 23:53:48151 // Migrates existing chrome shortcuts by tagging them with correct app id.
152 // see http://crbug.com/28104
153 static void MigrateChromiumShortcuts();
[email protected]43903b82012-06-01 05:26:23154
[email protected]3f69d6e612012-08-03 18:52:27155 // Returns the path to the Start Menu shortcut for the given Chrome.
156 static FilePath GetStartMenuShortcut(const FilePath& chrome_exe);
[email protected]12f520c2010-01-06 18:11:15157#endif // defined(OS_WIN)
158
[email protected]4468a5b2011-05-26 07:48:02159 // The current default web client application UI state. This is used when
160 // querying if Chrome is the default browser or the default handler
161 // application for a url protocol, and communicates the state and result of
162 // a request.
163 enum DefaultWebClientUIState {
[email protected]d24c4012009-07-28 01:57:31164 STATE_PROCESSING,
[email protected]264f74d12009-09-04 23:39:58165 STATE_NOT_DEFAULT,
166 STATE_IS_DEFAULT,
167 STATE_UNKNOWN
[email protected]d24c4012009-07-28 01:57:31168 };
169
[email protected]4468a5b2011-05-26 07:48:02170 class DefaultWebClientObserver {
[email protected]d24c4012009-07-28 01:57:31171 public:
[email protected]4468a5b2011-05-26 07:48:02172 virtual ~DefaultWebClientObserver() {}
[email protected]d24c4012009-07-28 01:57:31173 // Updates the UI state to reflect the current default browser state.
[email protected]4468a5b2011-05-26 07:48:02174 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0;
[email protected]693baa5d2012-06-22 22:23:38175 // Called to notify the UI of the immediate result of invoking
176 // SetAsDefault.
177 virtual void OnSetAsDefaultConcluded(bool succeeded) {}
[email protected]97e2e3f2011-07-22 10:21:25178 // Observer classes that return true to OwnedByWorker are automatically
[email protected]693baa5d2012-06-22 22:23:38179 // freed by the worker when they are no longer needed. False by default.
180 virtual bool IsOwnedByWorker();
[email protected]bd046bd42012-06-08 05:07:32181 // An observer can permit or decline set-as-default operation if it
[email protected]693baa5d2012-06-22 22:23:38182 // requires triggering user interaction. By default not allowed.
183 virtual bool IsInteractiveSetDefaultPermitted();
[email protected]d24c4012009-07-28 01:57:31184 };
[email protected]4468a5b2011-05-26 07:48:02185
186 // Helper objects that handle checking if Chrome is the default browser
187 // or application for a url protocol on Windows and Linux, and also setting
188 // it as the default. These operations are performed asynchronously on the
189 // file thread since registry access (on Windows) or the preference database
190 // (on Linux) are involved and this can be slow.
191 class DefaultWebClientWorker
192 : public base::RefCountedThreadSafe<DefaultWebClientWorker> {
[email protected]d24c4012009-07-28 01:57:31193 public:
[email protected]4468a5b2011-05-26 07:48:02194 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer);
[email protected]d24c4012009-07-28 01:57:31195
[email protected]4468a5b2011-05-26 07:48:02196 // Checks to see if Chrome is the default web client application. The result
197 // will be passed back to the observer via the SetDefaultWebClientUIState
198 // function. If there is no observer, this function does not do anything.
199 void StartCheckIsDefault();
[email protected]d24c4012009-07-28 01:57:31200
[email protected]4468a5b2011-05-26 07:48:02201 // Sets Chrome as the default web client application. If there is an
202 // observer, once the operation has completed the new default will be
203 // queried and the current status reported via SetDefaultWebClientUIState.
204 void StartSetAsDefault();
[email protected]d24c4012009-07-28 01:57:31205
206 // Called to notify the worker that the view is gone.
207 void ObserverDestroyed();
208
[email protected]4468a5b2011-05-26 07:48:02209 protected:
210 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>;
[email protected]e6e6ba42009-11-07 01:56:19211
[email protected]4468a5b2011-05-26 07:48:02212 virtual ~DefaultWebClientWorker() {}
213
214 private:
215 // Function that performs the check.
216 virtual DefaultWebClientState CheckIsDefault() = 0;
217
[email protected]693baa5d2012-06-22 22:23:38218 // Function that sets Chrome as the default web client. Returns false if
219 // the operation fails or has been cancelled by the user.
220 virtual bool SetAsDefault(bool interactive_permitted) = 0;
[email protected]4468a5b2011-05-26 07:48:02221
222 // Function that handles performing the check on the file thread. This
223 // function is posted as a task onto the file thread, where it performs
224 // the check. When the check has finished the CompleteCheckIsDefault
225 // function is posted to the UI thread, where the result is sent back to
226 // the observer.
227 void ExecuteCheckIsDefault();
228
229 // Function that handles setting Chrome as the default web client on the
230 // file thread. This function is posted as a task onto the file thread.
231 // Once it is finished the CompleteSetAsDefault function is posted to the
232 // UI thread which will check the status of Chrome as the default, and
233 // send this to the observer.
[email protected]693baa5d2012-06-22 22:23:38234 // |interactive_permitted| indicates if the routine is allowed to carry on
235 // in context where user interaction is required (CanSetAsDefault*
236 // returns SET_DEFAULT_INTERACTIVE).
237 void ExecuteSetAsDefault(bool interactive_permitted);
[email protected]4468a5b2011-05-26 07:48:02238
239 // Communicate results to the observer. This function is posted as a task
240 // onto the UI thread by the ExecuteCheckIsDefault function running in the
241 // file thread.
242 void CompleteCheckIsDefault(DefaultWebClientState state);
243
244 // When the action to set Chrome as the default has completed this function
245 // is run. It is posted as a task back onto the UI thread by the
246 // ExecuteSetAsDefault function running in the file thread. This function
247 // will the start the check process, which, if an observer is present,
248 // reports to it the new status.
[email protected]693baa5d2012-06-22 22:23:38249 // |succeeded| is true if the actual call to a set-default function (from
250 // ExecuteSetAsDefault) was successful.
251 void CompleteSetAsDefault(bool succeeded);
[email protected]4468a5b2011-05-26 07:48:02252
253 // Updates the UI in our associated view with the current default web
254 // client state.
255 void UpdateUI(DefaultWebClientState state);
256
257 DefaultWebClientObserver* observer_;
258
259 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker);
260 };
261
262 // Worker for checking and setting the default browser.
263 class DefaultBrowserWorker : public DefaultWebClientWorker {
264 public:
265 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer);
266
267 private:
[email protected]e6e6ba42009-11-07 01:56:19268 virtual ~DefaultBrowserWorker() {}
269
[email protected]4468a5b2011-05-26 07:48:02270 // Check if Chrome is the default browser.
[email protected]49fd7e22011-11-21 16:52:21271 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31272
[email protected]4468a5b2011-05-26 07:48:02273 // Set Chrome as the default browser.
[email protected]693baa5d2012-06-22 22:23:38274 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31275
[email protected]d24c4012009-07-28 01:57:31276 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
277 };
[email protected]4468a5b2011-05-26 07:48:02278
279 // Worker for checking and setting the default client application
280 // for a given protocol. A different worker instance is needed for each
281 // protocol you are interested in, so to check or set the default for
282 // multiple protocols you should use multiple worker objects.
283 class DefaultProtocolClientWorker : public DefaultWebClientWorker {
284 public:
285 DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
286 const std::string& protocol);
287
[email protected]bcb999d2011-05-31 15:11:35288 const std::string& protocol() const { return protocol_; }
289
[email protected]97e2e3f2011-07-22 10:21:25290 protected:
[email protected]4468a5b2011-05-26 07:48:02291 virtual ~DefaultProtocolClientWorker() {}
292
[email protected]97e2e3f2011-07-22 10:21:25293 private:
[email protected]4468a5b2011-05-26 07:48:02294 // Check is Chrome is the default handler for this protocol.
[email protected]49fd7e22011-11-21 16:52:21295 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02296
297 // Set Chrome as the default handler for this protocol.
[email protected]693baa5d2012-06-22 22:23:38298 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02299
300 std::string protocol_;
301
302 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker);
303 };
initial.commit09911bf2008-07-26 23:55:29304};
305
[email protected]9bc8cff2010-04-03 01:05:39306#endif // CHROME_BROWSER_SHELL_INTEGRATION_H_