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" | |
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 | |
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 | |
43 // |IsSetAsDefaultAsynchronous| is true. | |
44 // | |
45 // The caller should call SetAsyncSetAsDefaultFilterCallback to intercept the | |
grt (UTC plus 2)
2015/09/24 18:24:11
this comment isn't necessary. i think it's better
Patrick Monette
2015/09/25 20:06:24
Done.
| |
46 // link navigation (See SetAsyncSetAsDefaultFilterCallback in | |
47 // startup_browser_creator.h). The caller should also set up a timer to | |
48 // represent an unsuccessful attempt after a certain amount of time. | |
49 static void SetAsDefaultBrowserAsynchronous(); | |
50 | |
35 // Sets Chrome as the default client application for the given protocol | 51 // Sets Chrome as the default client application for the given protocol |
36 // (only for the current user). Returns false if this operation fails. | 52 // (only for the current user). Returns false if this operation fails. |
37 static bool SetAsDefaultProtocolClient(const std::string& protocol); | 53 static bool SetAsDefaultProtocolClient(const std::string& protocol); |
38 | 54 |
39 // Initiates an OS shell flow which (if followed by the user) should set | 55 // 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 | 56 // 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) | 57 // 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 | 58 // 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 | 59 // a FILE thread. If Chrome is already default for |protocol|, no interactive |
44 // dialog will be shown and this method returns true. | 60 // dialog will be shown and this method returns true. |
45 static bool SetAsDefaultProtocolClientInteractive( | 61 static bool SetAsDefaultProtocolClientInteractive( |
46 const std::string& protocol); | 62 const std::string& protocol); |
47 | 63 |
48 // In Windows 8 a browser can be made default-in-metro only in an interactive | 64 // Windows 8 and Windows 10 introduced differents way to set the default |
49 // flow. We will distinguish between two types of permissions here to avoid | 65 // browsers. |
50 // forcing the user into UI interaction when this should not be done. | |
51 enum DefaultWebClientSetPermission { | 66 enum DefaultWebClientSetPermission { |
67 // The browser control policy disallow setting the default browser. | |
grt (UTC plus 2)
2015/09/24 18:24:11
even i didn't know what this meant. :-) i think a
Patrick Monette
2015/09/25 20:06:24
Done.
| |
52 SET_DEFAULT_NOT_ALLOWED, | 68 SET_DEFAULT_NOT_ALLOWED, |
69 // This is the most common case where no special permission or interaction | |
70 // is required to set the default browser. | |
53 SET_DEFAULT_UNATTENDED, | 71 SET_DEFAULT_UNATTENDED, |
72 // On Windows 8, a browser can be made fault only in an interactive flow. | |
grt (UTC plus 2)
2015/09/24 18:24:11
fault -> default
Patrick Monette
2015/09/25 20:06:24
Done.
| |
54 SET_DEFAULT_INTERACTIVE, | 73 SET_DEFAULT_INTERACTIVE, |
74 // On Windows 10+, the set as default browser flow is still interactive but | |
75 // is it also asynchronous. | |
76 SET_DEFAULT_ASYNCHRONOUS, | |
55 }; | 77 }; |
56 | 78 |
57 // Returns requirements for making the running browser the user's default. | 79 // Returns requirements for making the running browser the user's default. |
58 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); | 80 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); |
59 | 81 |
60 // Returns requirements for making the running browser the user's default | 82 // Returns requirements for making the running browser the user's default |
61 // client application for specific protocols. | 83 // client application for specific protocols. |
62 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); | 84 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); |
63 | 85 |
64 // Returns true if making the running browser the default client for any | 86 // 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(); | 241 void StartSetAsDefault(); |
220 | 242 |
221 // Called to notify the worker that the view is gone. | 243 // Called to notify the worker that the view is gone. |
222 void ObserverDestroyed(); | 244 void ObserverDestroyed(); |
223 | 245 |
224 protected: | 246 protected: |
225 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 247 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
226 | 248 |
227 virtual ~DefaultWebClientWorker() {} | 249 virtual ~DefaultWebClientWorker() {} |
228 | 250 |
229 private: | 251 // Communicate results to the observer. In contrast to CompleteSetAsDefault, |
230 // Function that performs the check. | 252 // this should not be called multiple times. |
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); | 253 void CompleteCheckIsDefault(DefaultWebClientState state); |
258 | 254 |
259 // When the action to set Chrome as the default has completed this function | 255 // 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 | 256 // FinalizeSetAsDefault and, if an observer is present, starts the check is |
261 // ExecuteSetAsDefault function running in the file thread. This function | 257 // 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, | 258 // function was successful. |
263 // reports to it the new status. | 259 // 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 | 260 // after StartSetAsDefault is invoked. |
265 // ExecuteSetAsDefault) was successful. | |
266 void CompleteSetAsDefault(bool succeeded); | 261 void CompleteSetAsDefault(bool succeeded); |
267 | 262 |
263 private: | |
264 // Function that performs the check. Subclasses are responsible for calling | |
grt (UTC plus 2)
2015/09/24 18:24:11
nit: mention that this is run on the FILE thread.
Patrick Monette
2015/09/25 20:06:24
Done.
| |
265 // CompleteCheckIsDefault on the UI thread. | |
266 virtual void CheckIsDefault() = 0; | |
267 | |
268 // Sets Chrome as the default web client. Always called on the file thread. | |
269 // |interactive_permitted| will make SetAsDefault fails if it requires | |
270 // interaction with the user. Subclasses are responsible for calling | |
271 // CompleteSetAsDefault on the UI thread. | |
272 virtual void SetAsDefault(bool interactive_permitted) = 0; | |
273 | |
274 // Invoked on the UI thread prior to starting a SetAsDefault operation. | |
275 virtual void InitializeSetAsDefault() {} | |
276 | |
277 // Invoked on the UI thread following a SetAsDefault operation. | |
278 virtual void FinalizeSetAsDefault(bool succeeded) {} | |
279 | |
268 // Updates the UI in our associated view with the current default web | 280 // Updates the UI in our associated view with the current default web |
269 // client state. | 281 // client state. |
270 void UpdateUI(DefaultWebClientState state); | 282 void UpdateUI(DefaultWebClientState state); |
271 | 283 |
272 DefaultWebClientObserver* observer_; | 284 DefaultWebClientObserver* observer_; |
273 | 285 |
286 // Flag that indicates if the SetAsDefault operation was completed to | |
287 // prevent multiple completed notifications to the observer. | |
288 bool set_as_default_completed_; | |
grt (UTC plus 2)
2015/09/24 18:24:11
bool set_as_default_completed_ = true;
and remove
Patrick Monette
2015/09/25 20:06:24
Done.
| |
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+, add the URL filter and starts the timer that determines | |
308 // if the operation was successful or not. | |
309 void InitializeSetAsDefault() override; | |
310 | |
311 // On windows 10+, remove the URL filter and stops the timer. | |
312 void FinalizeSetAsDefault(bool succeeded) override; | |
313 | |
314 #if defined(OS_WIN) | |
315 // Used to determine if setting the default browser was unsuccesful. | |
316 scoped_ptr<base::OneShotTimer<DefaultBrowserWorker>> async_timer_; | |
grt (UTC plus 2)
2015/09/24 18:24:11
the OneShotTimer tweak landed at r350496; please r
Patrick Monette
2015/09/25 20:06:24
Done.
| |
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 |