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/time/time.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; |
20 class OneShotTimer; | |
19 } | 21 } |
20 | 22 |
21 class ShellIntegration { | 23 class ShellIntegration { |
22 public: | 24 public: |
23 // 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 |
24 // false if this operation fails. | 26 // false if this operation fails. |
25 static bool SetAsDefaultBrowser(); | 27 static bool SetAsDefaultBrowser(); |
26 | 28 |
27 // Initiates an OS shell flow which (if followed by the user) should set | 29 // 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 | 30 // 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 | 31 // 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 | 32 // 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 | 33 // thread. If Chrome is already default browser, no interactive dialog will be |
32 // shown and this method returns true. | 34 // shown and this method returns true. |
33 static bool SetAsDefaultBrowserInteractive(); | 35 static bool SetAsDefaultBrowserInteractive(); |
34 | 36 |
37 // Returns true if setting the default browser is an asynchronous operation. | |
38 // In practice, this is only true on Windows 10+. | |
39 static bool IsSetAsDefaultAsynchronous(); | |
40 | |
35 // Sets Chrome as the default client application for the given protocol | 41 // Sets Chrome as the default client application for the given protocol |
36 // (only for the current user). Returns false if this operation fails. | 42 // (only for the current user). Returns false if this operation fails. |
37 static bool SetAsDefaultProtocolClient(const std::string& protocol); | 43 static bool SetAsDefaultProtocolClient(const std::string& protocol); |
38 | 44 |
39 // Initiates an OS shell flow which (if followed by the user) should set | 45 // 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 | 46 // 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) | 47 // 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 | 48 // 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 | 49 // a FILE thread. If Chrome is already default for |protocol|, no interactive |
44 // dialog will be shown and this method returns true. | 50 // dialog will be shown and this method returns true. |
45 static bool SetAsDefaultProtocolClientInteractive( | 51 static bool SetAsDefaultProtocolClientInteractive( |
46 const std::string& protocol); | 52 const std::string& protocol); |
47 | 53 |
48 // In Windows 8 a browser can be made default-in-metro only in an interactive | 54 // Windows 8 and Windows 10 introduced different ways to set the default |
49 // flow. We will distinguish between two types of permissions here to avoid | 55 // browser. |
50 // forcing the user into UI interaction when this should not be done. | |
51 enum DefaultWebClientSetPermission { | 56 enum DefaultWebClientSetPermission { |
57 // The browser distribution is not permitted to be made default. | |
52 SET_DEFAULT_NOT_ALLOWED, | 58 SET_DEFAULT_NOT_ALLOWED, |
59 // This is the most common case where no special permission or interaction | |
60 // is required to set the default browser. | |
53 SET_DEFAULT_UNATTENDED, | 61 SET_DEFAULT_UNATTENDED, |
62 // On Windows 8, a browser can be made default only in an interactive flow. | |
54 SET_DEFAULT_INTERACTIVE, | 63 SET_DEFAULT_INTERACTIVE, |
64 // On Windows 10+, the set default browser flow is both interactive and | |
65 // asynchronous. | |
66 SET_DEFAULT_ASYNCHRONOUS, | |
55 }; | 67 }; |
56 | 68 |
57 // Returns requirements for making the running browser the user's default. | 69 // Returns requirements for making the running browser the user's default. |
58 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); | 70 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); |
59 | 71 |
60 // Returns requirements for making the running browser the user's default | 72 // Returns requirements for making the running browser the user's default |
61 // client application for specific protocols. | 73 // client application for specific protocols. |
62 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); | 74 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); |
63 | 75 |
64 // Returns true if making the running browser the default client for any | 76 // Returns true if making the running browser the default client for any |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 // observer, once the operation has completed the new default will be | 229 // observer, once the operation has completed the new default will be |
218 // queried and the current status reported via SetDefaultWebClientUIState. | 230 // queried and the current status reported via SetDefaultWebClientUIState. |
219 void StartSetAsDefault(); | 231 void StartSetAsDefault(); |
220 | 232 |
221 // Called to notify the worker that the view is gone. | 233 // Called to notify the worker that the view is gone. |
222 void ObserverDestroyed(); | 234 void ObserverDestroyed(); |
223 | 235 |
224 protected: | 236 protected: |
225 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 237 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
226 | 238 |
227 virtual ~DefaultWebClientWorker() {} | 239 virtual ~DefaultWebClientWorker(); |
240 | |
241 // Communicates the result to the observer. In contrast to | |
242 // OnSetAsDefaultAttemptComplete(), this should not be called multiple | |
243 // times. | |
244 void OnCheckIsDefaultComplete(DefaultWebClientState state); | |
245 | |
246 // Called when the set as default operation is completed. This then invokes | |
247 // FinalizeSetAsDefault() and, if an observer is present, starts the check | |
248 // is default process. |succeeded| is true if the actual call to a | |
249 // set-default function was successful. | |
250 // It is safe to call this multiple times. Only the first call is processed | |
251 // after StartSetAsDefault() is invoked. | |
252 void OnSetAsDefaultAttemptComplete(bool succeeded); | |
253 | |
254 // Flag that indicates if the set-as-default operation is in progess to | |
255 // prevent multiple notifications to the observer. | |
256 bool set_as_default_in_progress_ = false; | |
228 | 257 |
229 private: | 258 private: |
230 // Function that performs the check. | 259 // Checks whether Chrome is the default web client. Always called on the |
231 virtual DefaultWebClientState CheckIsDefault() = 0; | 260 // FILE thread. Subclasses are responsible for calling |
261 // OnCheckIsDefaultComplete() on the UI thread. | |
262 virtual void CheckIsDefault() = 0; | |
232 | 263 |
233 // Function that sets Chrome as the default web client. Returns false if | 264 // Sets Chrome as the default web client. Always called on the FILE thread. |
234 // the operation fails or has been cancelled by the user. | 265 // |interactive_permitted| will make SetAsDefault() fail if it requires |
235 virtual bool SetAsDefault(bool interactive_permitted) = 0; | 266 // interaction with the user. Subclasses are responsible for calling |
267 // OnSetAsDefaultAttemptComplete() on the UI thread. | |
268 virtual void SetAsDefault(bool interactive_permitted) = 0; | |
236 | 269 |
237 // Function that handles performing the check on the file thread. This | 270 // Invoked on the UI thread prior to starting a set-as-default operation. |
238 // function is posted as a task onto the file thread, where it performs | 271 virtual void InitializeSetAsDefault(); |
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 | 272 |
244 // Function that handles setting Chrome as the default web client on the | 273 // Invoked on the UI thread following a set-as-default operation. |
245 // file thread. This function is posted as a task onto the file thread. | 274 virtual void FinalizeSetAsDefault(bool succeeded); |
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); | |
258 | |
259 // When the action to set Chrome as the default has completed this function | |
260 // is run. It is posted as a task back onto the UI thread by the | |
261 // ExecuteSetAsDefault function running in the file thread. This function | |
262 // will the start the check process, which, if an observer is present, | |
263 // reports to it the new status. | |
264 // |succeeded| is true if the actual call to a set-default function (from | |
265 // ExecuteSetAsDefault) was successful. | |
266 void CompleteSetAsDefault(bool succeeded); | |
267 | 275 |
268 // Updates the UI in our associated view with the current default web | 276 // Updates the UI in our associated view with the current default web |
269 // client state. | 277 // client state. |
270 void UpdateUI(DefaultWebClientState state); | 278 void UpdateUI(DefaultWebClientState state); |
271 | 279 |
272 DefaultWebClientObserver* observer_; | 280 DefaultWebClientObserver* observer_; |
273 | 281 |
274 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 282 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
275 }; | 283 }; |
276 | 284 |
277 // Worker for checking and setting the default browser. | 285 // Worker for checking and setting the default browser. |
278 class DefaultBrowserWorker : public DefaultWebClientWorker { | 286 class DefaultBrowserWorker : public DefaultWebClientWorker { |
279 public: | 287 public: |
280 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 288 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
281 | 289 |
282 private: | 290 private: |
283 ~DefaultBrowserWorker() override {} | 291 ~DefaultBrowserWorker() override; |
284 | 292 |
285 // Check if Chrome is the default browser. | 293 // Check if Chrome is the default browser. |
286 DefaultWebClientState CheckIsDefault() override; | 294 void CheckIsDefault() override; |
287 | 295 |
288 // Set Chrome as the default browser. | 296 // Set Chrome as the default browser. |
289 bool SetAsDefault(bool interactive_permitted) override; | 297 void SetAsDefault(bool interactive_permitted) override; |
298 | |
299 #if defined(OS_WIN) | |
300 // On Windows 10+, adds the default browser callback and starts the timer | |
301 // that determines if the operation was successful or not. | |
302 void InitializeSetAsDefault() override; | |
303 | |
304 // On Windows 10+, removes the default browser callback and stops the timer. | |
305 void FinalizeSetAsDefault(bool succeeded) override; | |
306 | |
307 // Prompts the user to select the default browser by trying to open the help | |
308 // page that explains how to set Chrome as the default browser. | |
309 void SetAsDefaultBrowserAsynchronous(); | |
grt (UTC plus 2)
2015/09/30 17:22:32
static?
Patrick Monette
2015/10/01 21:12:51
Done.
| |
310 | |
311 // Used to determine if setting the default browser was unsuccesful. | |
312 scoped_ptr<base::OneShotTimer> async_timer_; | |
313 | |
314 // Records the time it takes to set the default browser asynchronously. | |
315 base::TimeTicks start_time_; | |
316 #endif // !defined(OS_WIN) | |
290 | 317 |
291 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 318 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
292 }; | 319 }; |
293 | 320 |
294 // Worker for checking and setting the default client application | 321 // Worker for checking and setting the default client application |
295 // for a given protocol. A different worker instance is needed for each | 322 // 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 | 323 // protocol you are interested in, so to check or set the default for |
297 // multiple protocols you should use multiple worker objects. | 324 // multiple protocols you should use multiple worker objects. |
298 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 325 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
299 public: | 326 public: |
300 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 327 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
301 const std::string& protocol); | 328 const std::string& protocol); |
302 | 329 |
303 const std::string& protocol() const { return protocol_; } | 330 const std::string& protocol() const { return protocol_; } |
304 | 331 |
305 protected: | 332 protected: |
306 ~DefaultProtocolClientWorker() override {} | 333 ~DefaultProtocolClientWorker() override; |
307 | 334 |
308 private: | 335 private: |
309 // Check is Chrome is the default handler for this protocol. | 336 // Check is Chrome is the default handler for this protocol. |
310 DefaultWebClientState CheckIsDefault() override; | 337 void CheckIsDefault() override; |
311 | 338 |
312 // Set Chrome as the default handler for this protocol. | 339 // Set Chrome as the default handler for this protocol. |
313 bool SetAsDefault(bool interactive_permitted) override; | 340 void SetAsDefault(bool interactive_permitted) override; |
314 | 341 |
315 std::string protocol_; | 342 std::string protocol_; |
316 | 343 |
317 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 344 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
318 }; | 345 }; |
319 }; | 346 }; |
320 | 347 |
321 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 348 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |