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/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/timer/timer.h" | |
grt (UTC plus 2)
2015/09/28 14:31:04
nit: remove this and instead forward decl OneShotT
Patrick Monette
2015/09/28 23:46:37
Done.
| |
14 #include "ui/gfx/image/image_family.h" | 15 #include "ui/gfx/image/image_family.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class CommandLine; | 19 class CommandLine; |
19 } | 20 } |
20 | 21 |
21 class ShellIntegration { | 22 class ShellIntegration { |
22 public: | 23 public: |
23 // Sets Chrome as the default browser (only for the current user). Returns | 24 // Sets Chrome as the default browser (only for the current user). Returns |
24 // false if this operation fails. | 25 // false if this operation fails. |
25 static bool SetAsDefaultBrowser(); | 26 static bool SetAsDefaultBrowser(); |
26 | 27 |
27 // Initiates an OS shell flow which (if followed by the user) should set | 28 // Initiates an OS shell flow which (if followed by the user) should set |
28 // Chrome as the default browser. Returns false if the flow cannot be | 29 // Chrome as the default browser. Returns false if the flow cannot be |
29 // initialized, if it is not supported (introduced for Windows 8) or if the | 30 // initialized, if it is not supported (introduced for Windows 8) or if the |
30 // user cancels the operation. This is a blocking call and requires a FILE | 31 // user cancels the operation. This is a blocking call and requires a FILE |
31 // thread. If Chrome is already default browser, no interactive dialog will be | 32 // thread. If Chrome is already default browser, no interactive dialog will be |
32 // shown and this method returns true. | 33 // shown and this method returns true. |
33 static bool SetAsDefaultBrowserInteractive(); | 34 static bool SetAsDefaultBrowserInteractive(); |
34 | 35 |
36 // Returns true if setting the default browser is an asynchronous operation. | |
37 // In practice, this is only true on Windows 10+. | |
38 static bool IsSetAsDefaultAsynchronous(); | |
39 | |
40 // Prompt the user to select the default browser by trying to open | |
Peter Kasting
2015/09/25 20:52:26
Nit: Prompts
Patrick Monette
2015/09/28 23:46:37
Done.
| |
41 // https://support.google.com/chrome?p=default_browser which is the "How to | |
42 // set Chrome as your default browser" help page. Only call this if | |
Peter Kasting
2015/09/25 20:52:27
Nit: Don't give the actual URL in this comment; ju
Patrick Monette
2015/09/28 23:46:37
Done.
| |
43 // |IsSetAsDefaultAsynchronous| is true. | |
44 // | |
45 // This call provides no indication as to whether or not the operation | |
46 // succeeded. Consider using DefaultBrowserWorker which will invoke its | |
47 // observer as appropriate. | |
48 static void SetAsDefaultBrowserAsynchronous(); | |
49 | |
35 // Sets Chrome as the default client application for the given protocol | 50 // Sets Chrome as the default client application for the given protocol |
36 // (only for the current user). Returns false if this operation fails. | 51 // (only for the current user). Returns false if this operation fails. |
37 static bool SetAsDefaultProtocolClient(const std::string& protocol); | 52 static bool SetAsDefaultProtocolClient(const std::string& protocol); |
38 | 53 |
39 // Initiates an OS shell flow which (if followed by the user) should set | 54 // Initiates an OS shell flow which (if followed by the user) should set |
40 // Chrome as the default handler for |protocol|. Returns false if the flow | 55 // Chrome as the default handler for |protocol|. Returns false if the flow |
41 // cannot be initialized, if it is not supported (introduced for Windows 8) | 56 // cannot be initialized, if it is not supported (introduced for Windows 8) |
42 // or if the user cancels the operation. This is a blocking call and requires | 57 // or if the user cancels the operation. This is a blocking call and requires |
43 // a FILE thread. If Chrome is already default for |protocol|, no interactive | 58 // a FILE thread. If Chrome is already default for |protocol|, no interactive |
44 // dialog will be shown and this method returns true. | 59 // dialog will be shown and this method returns true. |
45 static bool SetAsDefaultProtocolClientInteractive( | 60 static bool SetAsDefaultProtocolClientInteractive( |
46 const std::string& protocol); | 61 const std::string& protocol); |
47 | 62 |
48 // In Windows 8 a browser can be made default-in-metro only in an interactive | 63 // Windows 8 and Windows 10 introduced differents way to set the default |
Peter Kasting
2015/09/25 20:52:26
Nit: differents way -> different ways (or "a diffe
Patrick Monette
2015/09/28 23:46:37
Done.
| |
49 // flow. We will distinguish between two types of permissions here to avoid | 64 // browser. |
50 // forcing the user into UI interaction when this should not be done. | |
51 enum DefaultWebClientSetPermission { | 65 enum DefaultWebClientSetPermission { |
66 // The browser distribution is not permitted to be made default. | |
Peter Kasting
2015/09/25 20:52:26
Nit: Maybe give an example of why?
| |
52 SET_DEFAULT_NOT_ALLOWED, | 67 SET_DEFAULT_NOT_ALLOWED, |
68 // This is the most common case where no special permission or interaction | |
69 // is required to set the default browser. | |
53 SET_DEFAULT_UNATTENDED, | 70 SET_DEFAULT_UNATTENDED, |
71 // On Windows 8, a browser can be made default only in an interactive flow. | |
54 SET_DEFAULT_INTERACTIVE, | 72 SET_DEFAULT_INTERACTIVE, |
73 // On Windows 10+, the set as default browser flow is still interactive but | |
74 // is it also asynchronous. | |
Peter Kasting
2015/09/25 20:52:26
Nit: is it -> it is
Although this might be better
Patrick Monette
2015/09/28 23:46:37
Done.
| |
75 SET_DEFAULT_ASYNCHRONOUS, | |
55 }; | 76 }; |
56 | 77 |
57 // Returns requirements for making the running browser the user's default. | 78 // Returns requirements for making the running browser the user's default. |
58 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); | 79 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); |
59 | 80 |
60 // Returns requirements for making the running browser the user's default | 81 // Returns requirements for making the running browser the user's default |
61 // client application for specific protocols. | 82 // client application for specific protocols. |
62 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); | 83 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); |
63 | 84 |
64 // Returns true if making the running browser the default client for any | 85 // Returns true if making the running browser the default client for any |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 void StartSetAsDefault(); | 240 void StartSetAsDefault(); |
220 | 241 |
221 // Called to notify the worker that the view is gone. | 242 // Called to notify the worker that the view is gone. |
222 void ObserverDestroyed(); | 243 void ObserverDestroyed(); |
223 | 244 |
224 protected: | 245 protected: |
225 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 246 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
226 | 247 |
227 virtual ~DefaultWebClientWorker() {} | 248 virtual ~DefaultWebClientWorker() {} |
228 | 249 |
229 private: | 250 // Communicates the result to the observer. In contrast to |
230 // Function that performs the check. | 251 // CompleteSetAsDefault, this should not be called multiple times. |
Peter Kasting
2015/09/25 20:52:26
Nit: Here and everywhere else in the CL you give a
Patrick Monette
2015/09/28 23:46:37
Done.
| |
231 virtual DefaultWebClientState CheckIsDefault() = 0; | |
232 | |
233 // 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; | |
236 | |
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. | |
249 // |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); | |
253 | |
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); | 252 void CompleteCheckIsDefault(DefaultWebClientState state); |
258 | 253 |
259 // When the action to set Chrome as the default has completed this function | 254 // Called when the set as default operation is finished. This then invokes |
260 // is run. It is posted as a task back onto the UI thread by the | 255 // FinalizeSetAsDefault and, if an observer is present, starts the check is |
261 // ExecuteSetAsDefault function running in the file thread. This function | 256 // default process. |succeeded| is true if the actual call to a set-default |
262 // will the start the check process, which, if an observer is present, | 257 // function was successful. |
263 // reports to it the new status. | 258 // It is safe to call this multiple times. Only the first call is processed |
264 // |succeeded| is true if the actual call to a set-default function (from | 259 // after StartSetAsDefault is invoked. |
265 // ExecuteSetAsDefault) was successful. | |
266 void CompleteSetAsDefault(bool succeeded); | 260 void CompleteSetAsDefault(bool succeeded); |
Peter Kasting
2015/09/25 20:52:26
Nit: The names "CompleteSetAsDefault()" and "Final
Patrick Monette
2015/09/28 23:46:37
Done.
| |
267 | 261 |
262 // Flag that indicates if the SetAsDefault operation is in progess to | |
263 // prevent multiple notifications to the observer. | |
264 bool set_as_default_in_progress_ = false; | |
265 | |
266 private: | |
267 // Function that performs the check. Always called on the FILE thread. | |
Peter Kasting
2015/09/25 20:52:26
Nit: Remove "Function that"; change "Performs the
Patrick Monette
2015/09/28 23:46:37
Done.
| |
268 // Subclasses are responsible for calling CompleteCheckIsDefault on the UI | |
269 // thread. | |
270 virtual void CheckIsDefault() = 0; | |
271 | |
272 // Sets Chrome as the default web client. Always called on the FILE thread. | |
Peter Kasting
2015/09/25 20:52:26
Nit: web client -> browser?
Patrick Monette
2015/09/28 23:46:37
Browser is related to http and https protocols and
Peter Kasting
2015/09/28 23:57:49
There's certainly a ton of usage of "browser" in t
Patrick Monette
2015/09/29 14:44:18
Well to me it seems like the person who designed t
| |
273 // |interactive_permitted| will make SetAsDefault fails if it requires | |
Peter Kasting
2015/09/25 20:52:26
Nit: fails -> fail
Patrick Monette
2015/09/28 23:46:37
Done.
| |
274 // interaction with the user. Subclasses are responsible for calling | |
275 // CompleteSetAsDefault on the UI thread. | |
276 virtual void SetAsDefault(bool interactive_permitted) = 0; | |
277 | |
278 // Invoked on the UI thread prior to starting a SetAsDefault operation. | |
279 virtual void InitializeSetAsDefault() {} | |
Peter Kasting
2015/09/25 20:52:27
Nit: Don't give even no-op implementations of virt
grt (UTC plus 2)
2015/09/28 14:31:04
Just curious: I see inline empty inlines for virut
Peter Kasting
2015/09/28 20:40:48
To me we shouldn't be doing that there, and it's i
Patrick Monette
2015/09/28 23:46:37
Done.
| |
280 | |
281 // Invoked on the UI thread following a SetAsDefault operation. | |
282 virtual void FinalizeSetAsDefault(bool succeeded) {} | |
283 | |
268 // Updates the UI in our associated view with the current default web | 284 // Updates the UI in our associated view with the current default web |
269 // client state. | 285 // client state. |
270 void UpdateUI(DefaultWebClientState state); | 286 void UpdateUI(DefaultWebClientState state); |
271 | 287 |
272 DefaultWebClientObserver* observer_; | 288 DefaultWebClientObserver* observer_; |
273 | 289 |
274 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 290 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
275 }; | 291 }; |
276 | 292 |
277 // Worker for checking and setting the default browser. | 293 // Worker for checking and setting the default browser. |
278 class DefaultBrowserWorker : public DefaultWebClientWorker { | 294 class DefaultBrowserWorker : public DefaultWebClientWorker { |
279 public: | 295 public: |
280 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 296 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
281 | 297 |
282 private: | 298 private: |
283 ~DefaultBrowserWorker() override {} | 299 ~DefaultBrowserWorker() override; |
284 | 300 |
285 // Check if Chrome is the default browser. | 301 // Check if Chrome is the default browser. |
286 DefaultWebClientState CheckIsDefault() override; | 302 void CheckIsDefault() override; |
287 | 303 |
288 // Set Chrome as the default browser. | 304 // Set Chrome as the default browser. |
289 bool SetAsDefault(bool interactive_permitted) override; | 305 void SetAsDefault(bool interactive_permitted) override; |
306 | |
307 // On windows 10+, adds the default browser callback and starts the timer | |
Peter Kasting
2015/09/25 20:52:26
Nit: Capitalize Windows (here and below)
Patrick Monette
2015/09/28 23:46:37
Done.
| |
308 // that determines if the operation was successful or not. | |
309 void InitializeSetAsDefault() override; | |
310 | |
311 // On windows 10+, removes the default browser callback and stops the timer. | |
312 void FinalizeSetAsDefault(bool succeeded) override; | |
313 | |
314 #if defined(OS_WIN) | |
Peter Kasting
2015/09/25 20:52:26
Nit: You can move this #if up to include the two f
Patrick Monette
2015/09/28 23:46:37
Done.
| |
315 // Used to determine if setting the default browser was unsuccesful. | |
316 scoped_ptr<base::OneShotTimer> async_timer_; | |
317 | |
318 // Records the time it takes to set the default browser asynchronously. | |
319 base::TimeTicks start_time_; | |
320 #endif // !defined(OS_WIN) | |
290 | 321 |
291 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 322 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
292 }; | 323 }; |
293 | 324 |
294 // Worker for checking and setting the default client application | 325 // Worker for checking and setting the default client application |
295 // for a given protocol. A different worker instance is needed for each | 326 // 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 | 327 // protocol you are interested in, so to check or set the default for |
297 // multiple protocols you should use multiple worker objects. | 328 // multiple protocols you should use multiple worker objects. |
298 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 329 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
299 public: | 330 public: |
300 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 331 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
301 const std::string& protocol); | 332 const std::string& protocol); |
302 | 333 |
303 const std::string& protocol() const { return protocol_; } | 334 const std::string& protocol() const { return protocol_; } |
304 | 335 |
305 protected: | 336 protected: |
306 ~DefaultProtocolClientWorker() override {} | 337 ~DefaultProtocolClientWorker() override {} |
307 | 338 |
308 private: | 339 private: |
309 // Check is Chrome is the default handler for this protocol. | 340 // Check is Chrome is the default handler for this protocol. |
310 DefaultWebClientState CheckIsDefault() override; | 341 void CheckIsDefault() override; |
311 | 342 |
312 // Set Chrome as the default handler for this protocol. | 343 // Set Chrome as the default handler for this protocol. |
313 bool SetAsDefault(bool interactive_permitted) override; | 344 void SetAsDefault(bool interactive_permitted) override; |
314 | 345 |
315 std::string protocol_; | 346 std::string protocol_; |
316 | 347 |
317 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 348 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
318 }; | 349 }; |
319 }; | 350 }; |
320 | 351 |
321 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 352 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |