| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 | 16 |
| 17 class CommandLine; | 17 class CommandLine; |
| 18 class FilePath; | 18 class FilePath; |
| 19 class PrefService; | 19 class PrefService; |
| 20 | 20 |
| 21 #if defined(USE_X11) | 21 #if defined(USE_X11) |
| 22 namespace base { | 22 namespace base { |
| 23 class Environment; | 23 class Environment; |
| 24 } | 24 } |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 class ShellIntegration { | 27 class ShellIntegration { |
| 28 public: | 28 public: |
| 29 // Sets Chrome as default browser (only for current user). Returns false if | 29 // Sets Chrome as the default browser (only for the current user). Returns |
| 30 // this operation fails. | 30 // false if this operation fails. |
| 31 static bool SetAsDefaultBrowser(); | 31 static bool SetAsDefaultBrowser(); |
| 32 | 32 |
| 33 // Sets Chrome as the default client application for the given protocol |
| 34 // (only for the current user). Returns false if this operation fails. |
| 35 static bool SetAsDefaultProtocolClient(const std::string& protocol); |
| 36 |
| 33 // On Linux, it may not be possible to determine or set the default browser | 37 // On Linux, it may not be possible to determine or set the default browser |
| 34 // on some desktop environments or configurations. So, we use this enum and | 38 // on some desktop environments or configurations. So, we use this enum and |
| 35 // not a plain bool. (Note however that if used like a bool, this enum will | 39 // not a plain bool. (Note however that if used like a bool, this enum will |
| 36 // have reasonable behavior.) | 40 // have reasonable behavior.) |
| 37 enum DefaultBrowserState { | 41 enum DefaultWebClientState { |
| 38 NOT_DEFAULT_BROWSER = 0, | 42 NOT_DEFAULT_WEB_CLIENT = 0, |
| 39 IS_DEFAULT_BROWSER, | 43 IS_DEFAULT_WEB_CLIENT, |
| 40 UNKNOWN_DEFAULT_BROWSER | 44 UNKNOWN_DEFAULT_WEB_CLIENT = -1 |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 // Attempt to determine if this instance of Chrome is the default browser and | 47 // Attempt to determine if this instance of Chrome is the default browser and |
| 44 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS | 48 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| 45 // protocols; we don't want to report "no" here if the user has simply chosen | 49 // protocols; we don't want to report "no" here if the user has simply chosen |
| 46 // to open HTML files in a text editor and FTP links with an FTP client.) | 50 // to open HTML files in a text editor and FTP links with an FTP client.) |
| 47 static DefaultBrowserState IsDefaultBrowser(); | 51 static DefaultWebClientState IsDefaultBrowser(); |
| 48 | 52 |
| 49 // Returns true if Firefox is likely to be the default browser for the current | 53 // Returns true if Firefox is likely to be the default browser for the current |
| 50 // user. This method is very fast so it can be invoked in the UI thread. | 54 // user. This method is very fast so it can be invoked in the UI thread. |
| 51 static bool IsFirefoxDefaultBrowser(); | 55 static bool IsFirefoxDefaultBrowser(); |
| 52 | 56 |
| 57 // Attempt to determine if this instance of Chrome is the default client |
| 58 // application for the given protocol and return the appropriate state. |
| 59 static DefaultWebClientState |
| 60 IsDefaultProtocolClient(const std::string& protocol); |
| 61 |
| 53 struct ShortcutInfo { | 62 struct ShortcutInfo { |
| 54 ShortcutInfo(); | 63 ShortcutInfo(); |
| 55 ~ShortcutInfo(); | 64 ~ShortcutInfo(); |
| 56 | 65 |
| 57 GURL url; | 66 GURL url; |
| 58 // If |extension_id| is non-empty, this is short cut is to an extension-app | 67 // If |extension_id| is non-empty, this is short cut is to an extension-app |
| 59 // and the launch url will be detected at start-up. In this case, |url| | 68 // and the launch url will be detected at start-up. In this case, |url| |
| 60 // is still used to generate the app id (windows app id, not chrome app id). | 69 // is still used to generate the app id (windows app id, not chrome app id). |
| 61 std::string extension_id; | 70 std::string extension_id; |
| 62 string16 title; | 71 string16 title; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 125 |
| 117 // Generates Win7 app id for Chromium by calling GetAppId with | 126 // Generates Win7 app id for Chromium by calling GetAppId with |
| 118 // chrome::kBrowserAppID as app_name. | 127 // chrome::kBrowserAppID as app_name. |
| 119 static std::wstring GetChromiumAppId(const FilePath& profile_path); | 128 static std::wstring GetChromiumAppId(const FilePath& profile_path); |
| 120 | 129 |
| 121 // Migrates existing chrome shortcuts by tagging them with correct app id. | 130 // Migrates existing chrome shortcuts by tagging them with correct app id. |
| 122 // see http://crbug.com/28104 | 131 // see http://crbug.com/28104 |
| 123 static void MigrateChromiumShortcuts(); | 132 static void MigrateChromiumShortcuts(); |
| 124 #endif // defined(OS_WIN) | 133 #endif // defined(OS_WIN) |
| 125 | 134 |
| 126 // The current default browser UI state | 135 // The current default web client application UI state. This is used when |
| 127 enum DefaultBrowserUIState { | 136 // querying if Chrome is the default browser or the default handler |
| 137 // application for a url protocol, and communicates the state and result of |
| 138 // a request. |
| 139 enum DefaultWebClientUIState { |
| 128 STATE_PROCESSING, | 140 STATE_PROCESSING, |
| 129 STATE_NOT_DEFAULT, | 141 STATE_NOT_DEFAULT, |
| 130 STATE_IS_DEFAULT, | 142 STATE_IS_DEFAULT, |
| 131 STATE_UNKNOWN | 143 STATE_UNKNOWN |
| 132 }; | 144 }; |
| 133 | 145 |
| 134 class DefaultBrowserObserver { | 146 class DefaultWebClientObserver { |
| 135 public: | 147 public: |
| 148 virtual ~DefaultWebClientObserver() {} |
| 136 // Updates the UI state to reflect the current default browser state. | 149 // Updates the UI state to reflect the current default browser state. |
| 137 virtual void SetDefaultBrowserUIState(DefaultBrowserUIState state) = 0; | 150 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| 138 virtual ~DefaultBrowserObserver() {} | |
| 139 }; | 151 }; |
| 140 // A helper object that handles checking if Chrome is the default browser on | 152 |
| 141 // Windows and also setting it as the default browser. These operations are | 153 // Helper objects that handle checking if Chrome is the default browser |
| 142 // performed asynchronously on the file thread since registry access is | 154 // or application for a url protocol on Windows and Linux, and also setting |
| 143 // involved and this can be slow. | 155 // it as the default. These operations are performed asynchronously on the |
| 144 // | 156 // file thread since registry access (on Windows) or the preference database |
| 145 class DefaultBrowserWorker | 157 // (on Linux) are involved and this can be slow. |
| 146 : public base::RefCountedThreadSafe<DefaultBrowserWorker> { | 158 class DefaultWebClientWorker |
| 159 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| 147 public: | 160 public: |
| 148 explicit DefaultBrowserWorker(DefaultBrowserObserver* observer); | 161 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); |
| 149 | 162 |
| 150 // Checks if Chrome is the default browser. | 163 // Checks to see if Chrome is the default web client application. The result |
| 151 void StartCheckDefaultBrowser(); | 164 // will be passed back to the observer via the SetDefaultWebClientUIState |
| 165 // function. If there is no observer, this function does not do anything. |
| 166 void StartCheckIsDefault(); |
| 152 | 167 |
| 153 // Sets Chrome as the default browser. | 168 // Sets Chrome as the default web client application. If there is an |
| 154 void StartSetAsDefaultBrowser(); | 169 // observer, once the operation has completed the new default will be |
| 170 // queried and the current status reported via SetDefaultWebClientUIState. |
| 171 void StartSetAsDefault(); |
| 155 | 172 |
| 156 // Called to notify the worker that the view is gone. | 173 // Called to notify the worker that the view is gone. |
| 157 void ObserverDestroyed(); | 174 void ObserverDestroyed(); |
| 158 | 175 |
| 176 protected: |
| 177 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
| 178 |
| 179 virtual ~DefaultWebClientWorker() {} |
| 180 |
| 159 private: | 181 private: |
| 160 friend class base::RefCountedThreadSafe<DefaultBrowserWorker>; | 182 // Function that performs the check. |
| 183 virtual DefaultWebClientState CheckIsDefault() = 0; |
| 161 | 184 |
| 185 // Function that sets Chrome as the default web client. |
| 186 virtual void SetAsDefault() = 0; |
| 187 |
| 188 // Function that handles performing the check on the file thread. This |
| 189 // function is posted as a task onto the file thread, where it performs |
| 190 // the check. When the check has finished the CompleteCheckIsDefault |
| 191 // function is posted to the UI thread, where the result is sent back to |
| 192 // the observer. |
| 193 void ExecuteCheckIsDefault(); |
| 194 |
| 195 // Function that handles setting Chrome as the default web client on the |
| 196 // file thread. This function is posted as a task onto the file thread. |
| 197 // Once it is finished the CompleteSetAsDefault function is posted to the |
| 198 // UI thread which will check the status of Chrome as the default, and |
| 199 // send this to the observer. |
| 200 void ExecuteSetAsDefault(); |
| 201 |
| 202 // Communicate results to the observer. This function is posted as a task |
| 203 // onto the UI thread by the ExecuteCheckIsDefault function running in the |
| 204 // file thread. |
| 205 void CompleteCheckIsDefault(DefaultWebClientState state); |
| 206 |
| 207 // When the action to set Chrome as the default has completed this function |
| 208 // is run. It is posted as a task back onto the UI thread by the |
| 209 // ExecuteSetAsDefault function running in the file thread. This function |
| 210 // will the start the check process, which, if an observer is present, |
| 211 // reports to it the new status. |
| 212 void CompleteSetAsDefault(); |
| 213 |
| 214 // Updates the UI in our associated view with the current default web |
| 215 // client state. |
| 216 void UpdateUI(DefaultWebClientState state); |
| 217 |
| 218 DefaultWebClientObserver* observer_; |
| 219 |
| 220 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 221 }; |
| 222 |
| 223 // Worker for checking and setting the default browser. |
| 224 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 225 public: |
| 226 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| 227 |
| 228 private: |
| 162 virtual ~DefaultBrowserWorker() {} | 229 virtual ~DefaultBrowserWorker() {} |
| 163 | 230 |
| 164 // Functions that track the process of checking if Chrome is the default | 231 // Check if Chrome is the default browser. |
| 165 // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file | 232 virtual DefaultWebClientState CheckIsDefault(); |
| 166 // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the | |
| 167 // UI thread. | |
| 168 void ExecuteCheckDefaultBrowser(); | |
| 169 void CompleteCheckDefaultBrowser(DefaultBrowserState state); | |
| 170 | 233 |
| 171 // Functions that track the process of setting Chrome as the default | 234 // Set Chrome as the default browser. |
| 172 // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file | 235 virtual void SetAsDefault(); |
| 173 // thread. |CompleteSetAsDefaultBrowser| notifies the view to update on the | |
| 174 // UI thread. | |
| 175 void ExecuteSetAsDefaultBrowser(); | |
| 176 void CompleteSetAsDefaultBrowser(); | |
| 177 | |
| 178 // Updates the UI in our associated view with the current default browser | |
| 179 // state. | |
| 180 void UpdateUI(DefaultBrowserState state); | |
| 181 | |
| 182 DefaultBrowserObserver* observer_; | |
| 183 | 236 |
| 184 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 237 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 185 }; | 238 }; |
| 239 |
| 240 // Worker for checking and setting the default client application |
| 241 // for a given protocol. A different worker instance is needed for each |
| 242 // protocol you are interested in, so to check or set the default for |
| 243 // multiple protocols you should use multiple worker objects. |
| 244 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 245 public: |
| 246 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 247 const std::string& protocol); |
| 248 |
| 249 private: |
| 250 virtual ~DefaultProtocolClientWorker() {} |
| 251 |
| 252 // Check is Chrome is the default handler for this protocol. |
| 253 virtual DefaultWebClientState CheckIsDefault(); |
| 254 |
| 255 // Set Chrome as the default handler for this protocol. |
| 256 virtual void SetAsDefault(); |
| 257 |
| 258 std::string protocol_; |
| 259 |
| 260 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 261 }; |
| 186 }; | 262 }; |
| 187 | 263 |
| 188 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 264 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |