blob: 37689c8be65990eac67f8c2ce9067e8af1e7af9c [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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
9#include <string>
10
[email protected]b96aa932009-08-12 21:34:4911#include "base/basictypes.h"
[email protected]378017072012-02-24 06:52:4712#include "base/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]b96aa932009-08-12 21:34:4914#include "base/string16.h"
[email protected]42896802009-08-28 23:39:4415#include "googleurl/src/gurl.h"
[email protected]bdd6eec2012-03-03 19:58:0616#include "ui/gfx/image/image.h"
[email protected]0b303cc2009-09-28 22:35:1517
[email protected]b10392932011-03-08 21:28:1418class CommandLine;
[email protected]d24c4012009-07-28 01:57:3119
initial.commit09911bf2008-07-26 23:55:2920class ShellIntegration {
21 public:
[email protected]4468a5b2011-05-26 07:48:0222 // Sets Chrome as the default browser (only for the current user). Returns
23 // false if this operation fails.
initial.commit09911bf2008-07-26 23:55:2924 static bool SetAsDefaultBrowser();
25
[email protected]bd046bd42012-06-08 05:07:3226 // Initiates an OS shell flow which (if followed by the user) should set
27 // Chrome as the default browser. Returns false if the flow cannot be
28 // initialized, if it is not supported (introduced for Windows 8) or if the
29 // user cancels the operation. This is a blocking call and requires a FILE
30 // thread.
31 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]bd046bd42012-06-08 05:07:3237 // In Windows 8 a browser can be made default-in-metro only in an interactive
38 // flow. We will distinguish between two types of permissions here to avoid
39 // forcing the user into UI interaction when this should not be done.
40 enum DefaultWebClientSetPermission {
41 SET_DEFAULT_NOT_ALLOWED = 0,
42 SET_DEFAULT_UNATTENDED,
43 SET_DEFAULT_INTERACTIVE,
44 };
[email protected]a01481b2011-07-15 04:30:0245
[email protected]bd046bd42012-06-08 05:07:3246 // Returns requirements for making the running browser the user's default.
47 static DefaultWebClientSetPermission CanSetAsDefaultBrowser();
48
49 // Returns requirements for making the running browser the user's default
50 // client application for specific protocols.
51 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient();
[email protected]a01481b2011-07-15 04:30:0252
[email protected]264f74d12009-09-04 23:39:5853 // On Linux, it may not be possible to determine or set the default browser
54 // on some desktop environments or configurations. So, we use this enum and
55 // not a plain bool. (Note however that if used like a bool, this enum will
56 // have reasonable behavior.)
[email protected]4468a5b2011-05-26 07:48:0257 enum DefaultWebClientState {
58 NOT_DEFAULT_WEB_CLIENT = 0,
59 IS_DEFAULT_WEB_CLIENT,
60 UNKNOWN_DEFAULT_WEB_CLIENT = -1
[email protected]264f74d12009-09-04 23:39:5861 };
62
63 // Attempt to determine if this instance of Chrome is the default browser and
64 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
65 // protocols; we don't want to report "no" here if the user has simply chosen
66 // to open HTML files in a text editor and FTP links with an FTP client.)
[email protected]4468a5b2011-05-26 07:48:0267 static DefaultWebClientState IsDefaultBrowser();
initial.commit09911bf2008-07-26 23:55:2968
[email protected]cd63ef62009-05-06 19:41:3769 // Returns true if Firefox is likely to be the default browser for the current
initial.commit09911bf2008-07-26 23:55:2970 // user. This method is very fast so it can be invoked in the UI thread.
71 static bool IsFirefoxDefaultBrowser();
[email protected]d24c4012009-07-28 01:57:3172
[email protected]4468a5b2011-05-26 07:48:0273 // Attempt to determine if this instance of Chrome is the default client
74 // application for the given protocol and return the appropriate state.
75 static DefaultWebClientState
76 IsDefaultProtocolClient(const std::string& protocol);
77
[email protected]ed5431872009-11-17 08:39:5178 struct ShortcutInfo {
[email protected]93aa89c72010-10-20 21:32:0479 ShortcutInfo();
80 ~ShortcutInfo();
81
[email protected]ed5431872009-11-17 08:39:5182 GURL url;
[email protected]28375ae2010-02-05 04:45:5083 // If |extension_id| is non-empty, this is short cut is to an extension-app
84 // and the launch url will be detected at start-up. In this case, |url|
85 // is still used to generate the app id (windows app id, not chrome app id).
[email protected]01ed1962011-03-04 19:03:1386 std::string extension_id;
[email protected]ed5431872009-11-17 08:39:5187 string16 title;
88 string16 description;
[email protected]378017072012-02-24 06:52:4789 FilePath extension_path;
[email protected]bdd6eec2012-03-03 19:58:0690 gfx::Image favicon;
[email protected]5951c852012-06-20 00:12:5391 FilePath profile_path;
[email protected]ed5431872009-11-17 08:39:5192
[email protected]5a20b192012-03-01 06:01:5793 // Shortcuts to platform apps are created differently. They start up with
94 // their own user data directory and load the app from |extension_path|.
95 bool is_platform_app;
[email protected]ed5431872009-11-17 08:39:5196 bool create_on_desktop;
97 bool create_in_applications_menu;
98
99 // For Windows, this refers to quick launch bar prior to Win7. In Win7,
100 // this means "pin to taskbar". For Mac/Linux, this could be used for
101 // Mac dock or the gnome/kde application launcher. However, those are not
102 // implemented yet.
103 bool create_in_quick_launch_bar;
104 };
105
[email protected]9561bc912012-03-07 02:41:16106 // Data that needs to be passed between the app launcher stub and Chrome.
107 struct AppModeInfo {
108 };
109 static void SetAppModeInfo(const AppModeInfo* info);
110 static const AppModeInfo* AppModeInfo();
111
112 // Is the current instance of Chrome running in App mode.
113 bool IsRunningInAppMode();
114
[email protected]b10392932011-03-08 21:28:14115 // Set up command line arguments for launching a URL or an app.
116 // The new command line reuses the current process's user data directory (and
117 // login profile, for ChromeOS).
118 // If |extension_app_id| is non-empty, the arguments use kAppId=<id>.
[email protected]5c93a0c12012-05-02 19:45:24119 // Otherwise, kApp=<url> is used. If |is_platform_app| is true the flag
120 // --enable-platform-apps is added to the command line.
[email protected]b10392932011-03-08 21:28:14121 static CommandLine CommandLineArgsForLauncher(
[email protected]01ed1962011-03-04 19:03:13122 const GURL& url,
[email protected]5a20b192012-03-01 06:01:57123 const std::string& extension_app_id,
[email protected]5951c852012-06-20 00:12:53124 bool is_platform_app,
125 const FilePath& profile_path);
[email protected]5a20b192012-03-01 06:01:57126
[email protected]12f520c2010-01-06 18:11:15127#if defined(OS_WIN)
[email protected]a0448002012-06-19 04:32:10128 // Generates an application user model ID (AppUserModelId) for a given app
129 // name and profile path. The returned app id is in the format of
130 // "|app_name|[.<profile_id>]". "profile_id" is appended when user override
131 // the default value.
132 // Note: If the app has an installation specific suffix (e.g. on user-level
133 // Chrome installs), |app_name| should already be suffixed, this method will
134 // then further suffix it with the profile id as described above.
135 static string16 GetAppModelIdForProfile(const string16& app_name,
136 const FilePath& profile_path);
[email protected]12f520c2010-01-06 18:11:15137
[email protected]a0448002012-06-19 04:32:10138 // Generates an application user model ID (AppUserModelId) for Chromium by
139 // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
140 static string16 GetChromiumModelIdForProfile(const FilePath& profile_path);
[email protected]c9bb06f42010-01-13 23:53:48141
[email protected]2de2d622011-10-21 22:07:37142 // Returns the path to the Chromium icon. This is used to specify the icon
143 // to use for the taskbar group on Win 7.
144 static string16 GetChromiumIconPath();
145
[email protected]c9bb06f42010-01-13 23:53:48146 // Migrates existing chrome shortcuts by tagging them with correct app id.
147 // see http://crbug.com/28104
148 static void MigrateChromiumShortcuts();
[email protected]43903b82012-06-01 05:26:23149
150 // Activates Chrome in metro-mode on Windows 8. Returns false if called on
151 // earlier versions of Windows, if called from within metro-mode, if Chrome
152 // is not the default browser, or if an actual error occurs.
153 static bool ActivateMetroChrome();
[email protected]12f520c2010-01-06 18:11:15154#endif // defined(OS_WIN)
155
[email protected]4468a5b2011-05-26 07:48:02156 // The current default web client application UI state. This is used when
157 // querying if Chrome is the default browser or the default handler
158 // application for a url protocol, and communicates the state and result of
159 // a request.
160 enum DefaultWebClientUIState {
[email protected]d24c4012009-07-28 01:57:31161 STATE_PROCESSING,
[email protected]264f74d12009-09-04 23:39:58162 STATE_NOT_DEFAULT,
163 STATE_IS_DEFAULT,
164 STATE_UNKNOWN
[email protected]d24c4012009-07-28 01:57:31165 };
166
[email protected]4468a5b2011-05-26 07:48:02167 class DefaultWebClientObserver {
[email protected]d24c4012009-07-28 01:57:31168 public:
[email protected]4468a5b2011-05-26 07:48:02169 virtual ~DefaultWebClientObserver() {}
[email protected]d24c4012009-07-28 01:57:31170 // Updates the UI state to reflect the current default browser state.
[email protected]4468a5b2011-05-26 07:48:02171 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0;
[email protected]693baa5d2012-06-22 22:23:38172 // Called to notify the UI of the immediate result of invoking
173 // SetAsDefault.
174 virtual void OnSetAsDefaultConcluded(bool succeeded) {}
[email protected]97e2e3f2011-07-22 10:21:25175 // Observer classes that return true to OwnedByWorker are automatically
[email protected]693baa5d2012-06-22 22:23:38176 // freed by the worker when they are no longer needed. False by default.
177 virtual bool IsOwnedByWorker();
[email protected]bd046bd42012-06-08 05:07:32178 // An observer can permit or decline set-as-default operation if it
[email protected]693baa5d2012-06-22 22:23:38179 // requires triggering user interaction. By default not allowed.
180 virtual bool IsInteractiveSetDefaultPermitted();
[email protected]d24c4012009-07-28 01:57:31181 };
[email protected]4468a5b2011-05-26 07:48:02182
183 // Helper objects that handle checking if Chrome is the default browser
184 // or application for a url protocol on Windows and Linux, and also setting
185 // it as the default. These operations are performed asynchronously on the
186 // file thread since registry access (on Windows) or the preference database
187 // (on Linux) are involved and this can be slow.
188 class DefaultWebClientWorker
189 : public base::RefCountedThreadSafe<DefaultWebClientWorker> {
[email protected]d24c4012009-07-28 01:57:31190 public:
[email protected]4468a5b2011-05-26 07:48:02191 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer);
[email protected]d24c4012009-07-28 01:57:31192
[email protected]4468a5b2011-05-26 07:48:02193 // Checks to see if Chrome is the default web client application. The result
194 // will be passed back to the observer via the SetDefaultWebClientUIState
195 // function. If there is no observer, this function does not do anything.
196 void StartCheckIsDefault();
[email protected]d24c4012009-07-28 01:57:31197
[email protected]4468a5b2011-05-26 07:48:02198 // Sets Chrome as the default web client application. If there is an
199 // observer, once the operation has completed the new default will be
200 // queried and the current status reported via SetDefaultWebClientUIState.
201 void StartSetAsDefault();
[email protected]d24c4012009-07-28 01:57:31202
203 // Called to notify the worker that the view is gone.
204 void ObserverDestroyed();
205
[email protected]4468a5b2011-05-26 07:48:02206 protected:
207 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>;
[email protected]e6e6ba42009-11-07 01:56:19208
[email protected]4468a5b2011-05-26 07:48:02209 virtual ~DefaultWebClientWorker() {}
210
211 private:
212 // Function that performs the check.
213 virtual DefaultWebClientState CheckIsDefault() = 0;
214
[email protected]693baa5d2012-06-22 22:23:38215 // Function that sets Chrome as the default web client. Returns false if
216 // the operation fails or has been cancelled by the user.
217 virtual bool SetAsDefault(bool interactive_permitted) = 0;
[email protected]4468a5b2011-05-26 07:48:02218
219 // Function that handles performing the check on the file thread. This
220 // function is posted as a task onto the file thread, where it performs
221 // the check. When the check has finished the CompleteCheckIsDefault
222 // function is posted to the UI thread, where the result is sent back to
223 // the observer.
224 void ExecuteCheckIsDefault();
225
226 // Function that handles setting Chrome as the default web client on the
227 // file thread. This function is posted as a task onto the file thread.
228 // Once it is finished the CompleteSetAsDefault function is posted to the
229 // UI thread which will check the status of Chrome as the default, and
230 // send this to the observer.
[email protected]693baa5d2012-06-22 22:23:38231 // |interactive_permitted| indicates if the routine is allowed to carry on
232 // in context where user interaction is required (CanSetAsDefault*
233 // returns SET_DEFAULT_INTERACTIVE).
234 void ExecuteSetAsDefault(bool interactive_permitted);
[email protected]4468a5b2011-05-26 07:48:02235
236 // Communicate results to the observer. This function is posted as a task
237 // onto the UI thread by the ExecuteCheckIsDefault function running in the
238 // file thread.
239 void CompleteCheckIsDefault(DefaultWebClientState state);
240
241 // When the action to set Chrome as the default has completed this function
242 // is run. It is posted as a task back onto the UI thread by the
243 // ExecuteSetAsDefault function running in the file thread. This function
244 // will the start the check process, which, if an observer is present,
245 // reports to it the new status.
[email protected]693baa5d2012-06-22 22:23:38246 // |succeeded| is true if the actual call to a set-default function (from
247 // ExecuteSetAsDefault) was successful.
248 void CompleteSetAsDefault(bool succeeded);
[email protected]4468a5b2011-05-26 07:48:02249
250 // Updates the UI in our associated view with the current default web
251 // client state.
252 void UpdateUI(DefaultWebClientState state);
253
254 DefaultWebClientObserver* observer_;
255
256 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker);
257 };
258
259 // Worker for checking and setting the default browser.
260 class DefaultBrowserWorker : public DefaultWebClientWorker {
261 public:
262 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer);
263
264 private:
[email protected]e6e6ba42009-11-07 01:56:19265 virtual ~DefaultBrowserWorker() {}
266
[email protected]4468a5b2011-05-26 07:48:02267 // Check if Chrome is the default browser.
[email protected]49fd7e22011-11-21 16:52:21268 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31269
[email protected]4468a5b2011-05-26 07:48:02270 // Set Chrome as the default browser.
[email protected]693baa5d2012-06-22 22:23:38271 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]d24c4012009-07-28 01:57:31272
[email protected]d24c4012009-07-28 01:57:31273 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
274 };
[email protected]4468a5b2011-05-26 07:48:02275
276 // Worker for checking and setting the default client application
277 // for a given protocol. A different worker instance is needed for each
278 // protocol you are interested in, so to check or set the default for
279 // multiple protocols you should use multiple worker objects.
280 class DefaultProtocolClientWorker : public DefaultWebClientWorker {
281 public:
282 DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
283 const std::string& protocol);
284
[email protected]bcb999d2011-05-31 15:11:35285 const std::string& protocol() const { return protocol_; }
286
[email protected]97e2e3f2011-07-22 10:21:25287 protected:
[email protected]4468a5b2011-05-26 07:48:02288 virtual ~DefaultProtocolClientWorker() {}
289
[email protected]97e2e3f2011-07-22 10:21:25290 private:
[email protected]4468a5b2011-05-26 07:48:02291 // Check is Chrome is the default handler for this protocol.
[email protected]49fd7e22011-11-21 16:52:21292 virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02293
294 // Set Chrome as the default handler for this protocol.
[email protected]693baa5d2012-06-22 22:23:38295 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
[email protected]4468a5b2011-05-26 07:48:02296
297 std::string protocol_;
298
299 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker);
300 };
initial.commit09911bf2008-07-26 23:55:29301};
302
[email protected]9bc8cff2010-04-03 01:05:39303#endif // CHROME_BROWSER_SHELL_INTEGRATION_H_