license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H__ |
| 6 | #define CHROME_BROWSER_SHELL_INTEGRATION_H__ |
| 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 11 | #include "base/ref_counted.h" |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 13 | #include "googleurl/src/gurl.h" |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 14 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 15 | class FilePath; |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 16 | class MessageLoop; |
| 17 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | class ShellIntegration { |
| 19 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | // Sets Chrome as default browser (only for current user). Returns false if |
| 21 | // this operation fails. |
| 22 | static bool SetAsDefaultBrowser(); |
| 23 | |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame^] | 24 | // On Linux, it may not be possible to determine or set the default browser |
| 25 | // on some desktop environments or configurations. So, we use this enum and |
| 26 | // not a plain bool. (Note however that if used like a bool, this enum will |
| 27 | // have reasonable behavior.) |
| 28 | enum DefaultBrowserState { |
| 29 | NOT_DEFAULT_BROWSER = 0, |
| 30 | IS_DEFAULT_BROWSER, |
| 31 | UNKNOWN_DEFAULT_BROWSER |
| 32 | }; |
| 33 | |
| 34 | // Attempt to determine if this instance of Chrome is the default browser and |
| 35 | // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| 36 | // protocols; we don't want to report "no" here if the user has simply chosen |
| 37 | // to open HTML files in a text editor and FTP links with an FTP client.) |
| 38 | static DefaultBrowserState IsDefaultBrowser(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | |
[email protected] | cd63ef6 | 2009-05-06 19:41:37 | [diff] [blame] | 40 | // Returns true if Firefox is likely to be the default browser for the current |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // user. This method is very fast so it can be invoked in the UI thread. |
| 42 | static bool IsFirefoxDefaultBrowser(); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 43 | |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 44 | #if defined(OS_LINUX) |
| 45 | // Returns filename for .desktop file based on |url|, sanitized for security. |
| 46 | static FilePath GetDesktopShortcutFilename(const GURL& url); |
| 47 | |
| 48 | // Returns contents for .desktop file based on |template_contents|, |url| |
| 49 | // and |title|. The |template_contents| should be contents of .desktop file |
| 50 | // used to launch Chrome. |
| 51 | static std::string GetDesktopFileContents( |
| 52 | const std::string& template_contents, const GURL& url, |
| 53 | const string16& title); |
| 54 | |
[email protected] | 4289680 | 2009-08-28 23:39:44 | [diff] [blame] | 55 | struct ShortcutInfo { |
| 56 | GURL url; |
| 57 | string16 title; |
| 58 | |
| 59 | bool create_on_desktop; |
| 60 | bool create_in_applications_menu; |
| 61 | }; |
| 62 | |
| 63 | // Creates a desktop shortcut. It is not guaranteed to exist immediately after |
| 64 | // returning from this function, because actual file operation is done on the |
| 65 | // file thread. |
| 66 | static void CreateDesktopShortcut(const ShortcutInfo& shortcut_info); |
[email protected] | b96aa93 | 2009-08-12 21:34:49 | [diff] [blame] | 67 | #endif // defined(OS_LINUX) |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 68 | |
| 69 | // The current default browser UI state |
| 70 | enum DefaultBrowserUIState { |
| 71 | STATE_PROCESSING, |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame^] | 72 | STATE_NOT_DEFAULT, |
| 73 | STATE_IS_DEFAULT, |
| 74 | STATE_UNKNOWN |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | class DefaultBrowserObserver { |
| 78 | public: |
| 79 | // Updates the UI state to reflect the current default browser state. |
| 80 | virtual void SetDefaultBrowserUIState(DefaultBrowserUIState state) = 0; |
| 81 | virtual ~DefaultBrowserObserver() {} |
| 82 | }; |
| 83 | // A helper object that handles checking if Chrome is the default browser on |
| 84 | // Windows and also setting it as the default browser. These operations are |
| 85 | // performed asynchronously on the file thread since registry access is |
| 86 | // involved and this can be slow. |
| 87 | // |
| 88 | class DefaultBrowserWorker |
| 89 | : public base::RefCountedThreadSafe<DefaultBrowserWorker> { |
| 90 | public: |
| 91 | explicit DefaultBrowserWorker(DefaultBrowserObserver* observer); |
| 92 | virtual ~DefaultBrowserWorker() {} |
| 93 | |
| 94 | // Checks if Chrome is the default browser. |
| 95 | void StartCheckDefaultBrowser(); |
| 96 | |
| 97 | // Sets Chrome as the default browser. |
| 98 | void StartSetAsDefaultBrowser(); |
| 99 | |
| 100 | // Called to notify the worker that the view is gone. |
| 101 | void ObserverDestroyed(); |
| 102 | |
| 103 | private: |
| 104 | // Functions that track the process of checking if Chrome is the default |
| 105 | // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file |
| 106 | // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the |
| 107 | // UI thread. |
| 108 | void ExecuteCheckDefaultBrowser(); |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame^] | 109 | void CompleteCheckDefaultBrowser(DefaultBrowserState state); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 110 | |
| 111 | // Functions that track the process of setting Chrome as the default |
| 112 | // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file |
| 113 | // thread. |CompleteSetAsDefaultBrowser| notifies the view to update on the |
| 114 | // UI thread. |
| 115 | void ExecuteSetAsDefaultBrowser(); |
| 116 | void CompleteSetAsDefaultBrowser(); |
| 117 | |
| 118 | // Updates the UI in our associated view with the current default browser |
| 119 | // state. |
[email protected] | 264f74d1 | 2009-09-04 23:39:58 | [diff] [blame^] | 120 | void UpdateUI(DefaultBrowserState state); |
[email protected] | d24c401 | 2009-07-28 01:57:31 | [diff] [blame] | 121 | |
| 122 | DefaultBrowserObserver* observer_; |
| 123 | |
| 124 | MessageLoop* ui_loop_; |
| 125 | MessageLoop* file_loop_; |
| 126 | |
| 127 | DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 128 | }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #endif // CHROME_BROWSER_SHELL_INTEGRATION_H__ |