OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SHELL_INTEGRATION_H_ | 5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ |
6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ | 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "ui/gfx/image/image_family.h" | 16 #include "ui/gfx/image/image_family.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class CommandLine; | 20 class CommandLine; |
21 } | 21 } |
22 | 22 |
23 namespace shell_integration { | 23 namespace shell_integration { |
24 | 24 |
25 // Sets Chrome as the default browser (only for the current user). Returns | 25 // Sets Chrome as the default browser (only for the current user). Returns false |
26 // false if this operation fails. | 26 // if this operation fails. This does not work on Windows version 8 or higher. |
| 27 // Prefer to use the DefaultBrowserWorker class below since it works on all OSs. |
27 bool SetAsDefaultBrowser(); | 28 bool SetAsDefaultBrowser(); |
28 | 29 |
29 // Initiates an OS shell flow which (if followed by the user) should set | |
30 // Chrome as the default browser. Returns false if the flow cannot be | |
31 // initialized, if it is not supported (introduced for Windows 8) or if the | |
32 // user cancels the operation. This is a blocking call and requires a FILE | |
33 // thread. If Chrome is already default browser, no interactive dialog will be | |
34 // shown and this method returns true. | |
35 bool SetAsDefaultBrowserInteractive(); | |
36 | |
37 // Sets Chrome as the default client application for the given protocol | 30 // Sets Chrome as the default client application for the given protocol |
38 // (only for the current user). Returns false if this operation fails. | 31 // (only for the current user). Returns false if this operation fails. |
| 32 // Prefer to use the DefaultProtocolClientWorker class below since it works on |
| 33 // all OSs. |
39 bool SetAsDefaultProtocolClient(const std::string& protocol); | 34 bool SetAsDefaultProtocolClient(const std::string& protocol); |
40 | 35 |
41 // Initiates an OS shell flow which (if followed by the user) should set | 36 // The different types of permissions required to set a default web client. |
42 // Chrome as the default handler for |protocol|. Returns false if the flow | |
43 // cannot be initialized, if it is not supported (introduced for Windows 8) | |
44 // or if the user cancels the operation. This is a blocking call and requires | |
45 // a FILE thread. If Chrome is already default for |protocol|, no interactive | |
46 // dialog will be shown and this method returns true. | |
47 bool SetAsDefaultProtocolClientInteractive(const std::string& protocol); | |
48 | |
49 // Windows 8 and Windows 10 introduced different ways to set the default | |
50 // browser. | |
51 enum DefaultWebClientSetPermission { | 37 enum DefaultWebClientSetPermission { |
52 // The browser distribution is not permitted to be made default. | 38 // The browser distribution is not permitted to be made default. |
53 SET_DEFAULT_NOT_ALLOWED, | 39 SET_DEFAULT_NOT_ALLOWED, |
54 // No special permission or interaction is required to set the default | 40 // No special permission or interaction is required to set the default |
55 // browser. This is used in Linux, Mac and Windows 7 and under. | 41 // browser. This is used in Linux, Mac and Windows 7 and under. |
56 SET_DEFAULT_UNATTENDED, | 42 SET_DEFAULT_UNATTENDED, |
57 // On Windows 8, a browser can be made default only in an interactive flow. | 43 // On Windows 8+, a browser can be made default only in an interactive flow. |
58 SET_DEFAULT_INTERACTIVE, | 44 SET_DEFAULT_INTERACTIVE, |
59 }; | 45 }; |
60 | 46 |
61 // Returns requirements for making the running browser the user's default. | 47 // Returns requirements for making the running browser either the default |
62 DefaultWebClientSetPermission CanSetAsDefaultBrowser(); | 48 // browser or the default client application for a specific protocols for the |
| 49 // current user. |
| 50 DefaultWebClientSetPermission GetDefaultWebClientSetPermission(); |
63 | 51 |
64 // Returns requirements for making the running browser the user's default | 52 // Returns true if the running browser can be set as the default browser, |
65 // client application for specific protocols. | 53 // whether user interaction is needed or not. Use |
66 DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); | 54 // GetDefaultWebClientSetPermission() if this distinction is important. |
| 55 bool CanSetAsDefaultBrowser(); |
67 | 56 |
68 // Returns true if making the running browser the default client for any | 57 // Returns true if making the running browser the default client for any |
69 // protocol requires elevated privileges. | 58 // protocol requires elevated privileges. |
70 bool IsElevationNeededForSettingDefaultProtocolClient(); | 59 bool IsElevationNeededForSettingDefaultProtocolClient(); |
71 | 60 |
72 // Returns a string representing the application to be launched given the | 61 // Returns a string representing the application to be launched given the |
73 // protocol of the requested url. This string may be a name or a path, but | 62 // protocol of the requested url. This string may be a name or a path, but |
74 // neither is guaranteed and it should only be used as a display string. | 63 // neither is guaranteed and it should only be used as a display string. |
75 // Returns an empty string on failure. | 64 // Returns an empty string on failure. |
76 base::string16 GetApplicationNameForProtocol(const GURL& url); | 65 base::string16 GetApplicationNameForProtocol(const GURL& url); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Checks whether Chrome is the default web client. Always called on the | 214 // Checks whether Chrome is the default web client. Always called on the |
226 // FILE thread. When |is_following_set_as_default| is true, The default state | 215 // FILE thread. When |is_following_set_as_default| is true, The default state |
227 // will be reported to UMA as the result of the set-as-default operation. | 216 // will be reported to UMA as the result of the set-as-default operation. |
228 void CheckIsDefault(bool is_following_set_as_default); | 217 void CheckIsDefault(bool is_following_set_as_default); |
229 | 218 |
230 // Sets Chrome as the default web client. Always called on the FILE thread. | 219 // Sets Chrome as the default web client. Always called on the FILE thread. |
231 void SetAsDefault(); | 220 void SetAsDefault(); |
232 | 221 |
233 // Implementation of CheckIsDefault() and SetAsDefault() for subclasses. | 222 // Implementation of CheckIsDefault() and SetAsDefault() for subclasses. |
234 virtual DefaultWebClientState CheckIsDefaultImpl() = 0; | 223 virtual DefaultWebClientState CheckIsDefaultImpl() = 0; |
235 virtual void SetAsDefaultImpl() = 0; | 224 |
| 225 // The callback may be run synchronously or at an arbitrary time later on this |
| 226 // thread. |
| 227 // Note: Subclasses MUST make sure |on_finished_callback| is executed. |
| 228 virtual void SetAsDefaultImpl(const base::Closure& on_finished_callback) = 0; |
236 | 229 |
237 // Reports the result for the set-as-default operation. | 230 // Reports the result for the set-as-default operation. |
238 void ReportSetDefaultResult(DefaultWebClientState state); | 231 void ReportSetDefaultResult(DefaultWebClientState state); |
239 | 232 |
240 // Updates the UI in our associated view with the current default web | 233 // Updates the UI in our associated view with the current default web |
241 // client state. | 234 // client state. |
242 void UpdateUI(DefaultWebClientState state); | 235 void UpdateUI(DefaultWebClientState state); |
243 | 236 |
244 // Called with the default state after the worker is done. | 237 // Called with the default state after the worker is done. |
245 DefaultWebClientWorkerCallback callback_; | 238 DefaultWebClientWorkerCallback callback_; |
(...skipping 15 matching lines...) Expand all Loading... |
261 public: | 254 public: |
262 explicit DefaultBrowserWorker(const DefaultWebClientWorkerCallback& callback); | 255 explicit DefaultBrowserWorker(const DefaultWebClientWorkerCallback& callback); |
263 | 256 |
264 private: | 257 private: |
265 ~DefaultBrowserWorker() override; | 258 ~DefaultBrowserWorker() override; |
266 | 259 |
267 // Check if Chrome is the default browser. | 260 // Check if Chrome is the default browser. |
268 DefaultWebClientState CheckIsDefaultImpl() override; | 261 DefaultWebClientState CheckIsDefaultImpl() override; |
269 | 262 |
270 // Set Chrome as the default browser. | 263 // Set Chrome as the default browser. |
271 void SetAsDefaultImpl() override; | 264 void SetAsDefaultImpl(const base::Closure& on_finished_callback) override; |
272 | 265 |
273 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 266 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
274 }; | 267 }; |
275 | 268 |
276 // Worker for checking and setting the default client application | 269 // Worker for checking and setting the default client application |
277 // for a given protocol. A different worker instance is needed for each | 270 // 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 | 271 // protocol you are interested in, so to check or set the default for |
279 // multiple protocols you should use multiple worker objects. | 272 // multiple protocols you should use multiple worker objects. |
280 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 273 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
281 public: | 274 public: |
282 DefaultProtocolClientWorker(const DefaultWebClientWorkerCallback& callback, | 275 DefaultProtocolClientWorker(const DefaultWebClientWorkerCallback& callback, |
283 const std::string& protocol); | 276 const std::string& protocol); |
284 | 277 |
285 const std::string& protocol() const { return protocol_; } | 278 const std::string& protocol() const { return protocol_; } |
286 | 279 |
287 protected: | 280 protected: |
288 ~DefaultProtocolClientWorker() override; | 281 ~DefaultProtocolClientWorker() override; |
289 | 282 |
290 private: | 283 private: |
291 // Check if Chrome is the default handler for this protocol. | 284 // Check if Chrome is the default handler for this protocol. |
292 DefaultWebClientState CheckIsDefaultImpl() override; | 285 DefaultWebClientState CheckIsDefaultImpl() override; |
293 | 286 |
294 // Set Chrome as the default handler for this protocol. | 287 // Set Chrome as the default handler for this protocol. |
295 void SetAsDefaultImpl() override; | 288 void SetAsDefaultImpl(const base::Closure& on_finished_callback) override; |
296 | 289 |
297 std::string protocol_; | 290 std::string protocol_; |
298 | 291 |
299 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 292 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
300 }; | 293 }; |
301 | 294 |
302 } // namespace shell_integration | 295 } // namespace shell_integration |
303 | 296 |
304 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 297 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |