Chromium Code Reviews| 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 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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 default browser (only for current user). Returns false if |
| 30 // this operation fails. | 30 // this operation fails. |
| 31 static bool SetAsDefaultBrowser(); | 31 static bool SetAsDefaultBrowser(); |
| 32 | 32 |
| 33 // Sets Chrome as client application for the given protocol (only for | |
|
Mark Mentovai
2011/05/24 16:28:53
as the client application
benwells
2011/05/25 08:07:19
Done.
| |
| 34 // current user). Returns false if this operation fails. | |
|
Mark Mentovai
2011/05/24 16:28:53
for the current user
benwells
2011/05/25 08:07:19
Done.
| |
| 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 browser / client application UI state |
|
xiyuan
2011/05/24 17:55:20
nit: did you mean "web client application"?
benwells
2011/05/25 08:07:19
Done.
| |
| 127 enum DefaultBrowserUIState { | 136 enum DefaultWebClientUIState { |
| 128 STATE_PROCESSING, | 137 STATE_PROCESSING, |
| 129 STATE_NOT_DEFAULT, | 138 STATE_NOT_DEFAULT, |
| 130 STATE_IS_DEFAULT, | 139 STATE_IS_DEFAULT, |
| 131 STATE_UNKNOWN | 140 STATE_UNKNOWN |
| 132 }; | 141 }; |
| 133 | 142 |
| 134 class DefaultBrowserObserver { | 143 class DefaultWebClientObserver { |
| 135 public: | 144 public: |
| 136 // Updates the UI state to reflect the current default browser state. | 145 // Updates the UI state to reflect the current default browser state. |
| 137 virtual void SetDefaultBrowserUIState(DefaultBrowserUIState state) = 0; | 146 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| 138 virtual ~DefaultBrowserObserver() {} | 147 virtual ~DefaultWebClientObserver() {} |
|
Mark Mentovai
2011/05/24 16:28:53
Nit (to fix the existing code): within public, pri
benwells
2011/05/25 08:07:19
Done.
| |
| 139 }; | 148 }; |
| 140 // A helper object that handles checking if Chrome is the default browser on | 149 |
| 141 // Windows and also setting it as the default browser. These operations are | 150 // Helper objects that handle checking if Chrome is the default browser |
| 142 // performed asynchronously on the file thread since registry access is | 151 // or application for a url protocol on Windows and Linux, and also setting |
| 143 // involved and this can be slow. | 152 // it as the default. These operations are performed asynchronously on the |
| 144 // | 153 // file thread since registry access (on Windows) or the preference database |
| 145 class DefaultBrowserWorker | 154 // (on Linux) are involved and this can be slow. |
| 146 : public base::RefCountedThreadSafe<DefaultBrowserWorker> { | 155 class DefaultWebClientWorker |
| 156 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | |
| 147 public: | 157 public: |
| 148 explicit DefaultBrowserWorker(DefaultBrowserObserver* observer); | 158 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); |
| 149 | 159 |
| 150 // Checks if Chrome is the default browser. | 160 // Checks to see if Chrome is the default web client application. |
|
Mark Mentovai
2011/05/24 16:28:53
For this and the next “Start” call, the header com
benwells
2011/05/25 08:07:19
Done.
| |
| 151 void StartCheckDefaultBrowser(); | 161 void StartCheckIsDefault(); |
| 152 | 162 |
| 153 // Sets Chrome as the default browser. | 163 // Sets Chrome as the default web client application. |
| 154 void StartSetAsDefaultBrowser(); | 164 void StartSetAsDefault(); |
| 155 | 165 |
| 156 // Called to notify the worker that the view is gone. | 166 // Called to notify the worker that the view is gone. |
| 157 void ObserverDestroyed(); | 167 void ObserverDestroyed(); |
| 158 | 168 |
| 169 protected: | |
| 170 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | |
| 171 | |
| 172 virtual ~DefaultWebClientWorker() {} | |
| 173 | |
| 159 private: | 174 private: |
| 160 friend class base::RefCountedThreadSafe<DefaultBrowserWorker>; | 175 // Function that performs the check. |
| 176 virtual DefaultWebClientState CheckIsDefault() = 0; | |
| 161 | 177 |
| 178 // Function that sets Chrome as the default web client. | |
| 179 virtual void SetAsDefault() = 0; | |
| 180 | |
| 181 // Function that handles performing the check on the file thread. This | |
| 182 // function is posted as a task onto the file thread, where it performs | |
| 183 // the check and sends the result back to the UI thread. | |
|
Mark Mentovai
2011/05/24 16:28:53
Instead of “sends the result back to the UI thread
benwells
2011/05/25 08:07:19
Done.
| |
| 184 void ExecuteCheckIsDefault(); | |
| 185 | |
| 186 // Function that handles setting Chrome as the default web client on the | |
| 187 // file thread. This function is posted as a task onto the file thread. | |
| 188 // Once it is finished it posts a task back to the UI thread to complete | |
|
Mark Mentovai
2011/05/24 16:28:53
Same: say what will be called on the UI thread.
benwells
2011/05/25 08:07:19
Done.
| |
| 189 // the job. | |
| 190 void ExecuteSetAsDefault(); | |
| 191 | |
| 192 // Communicate results to the observer. This function is posted as a task | |
| 193 // back to the UI thread from the file thread. | |
|
Mark Mentovai
2011/05/24 16:28:53
And again, for this and the next one, it’s more us
benwells
2011/05/25 08:07:19
Done.
| |
| 194 void CompleteCheckIsDefault(DefaultWebClientState state); | |
| 195 | |
| 196 // When the action to set Chrome as the default has completed this function | |
| 197 // is posted as a task back to the UI thread. If an observer is present | |
| 198 // it will execute a check, which will report the status of Chrome as the | |
| 199 // default web client back to the observer. | |
| 200 void CompleteSetAsDefault(); | |
| 201 | |
| 202 // Updates the UI in our associated view with the current default web | |
| 203 // client state. | |
| 204 void UpdateUI(DefaultWebClientState state); | |
| 205 | |
| 206 DefaultWebClientObserver* observer_; | |
| 207 | |
| 208 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | |
| 209 }; | |
| 210 | |
| 211 // Worker for checking and setting the default browser. | |
| 212 class DefaultBrowserWorker : public DefaultWebClientWorker { | |
| 213 public: | |
| 214 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | |
| 215 | |
| 216 private: | |
| 162 virtual ~DefaultBrowserWorker() {} | 217 virtual ~DefaultBrowserWorker() {} |
| 163 | 218 |
| 164 // Functions that track the process of checking if Chrome is the default | 219 // Check if Chrome is the default browser. |
| 165 // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file | 220 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 | 221 |
| 171 // Functions that track the process of setting Chrome as the default | 222 // Set Chrome as the default browser. |
| 172 // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file | 223 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 | 224 |
| 184 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 225 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 185 }; | 226 }; |
| 227 | |
| 228 // Worker for checking and setting the default client application | |
| 229 // for a given protocol. A different worker instance is needed for each | |
| 230 // protocol you are interested in, so to check or set the default for | |
| 231 // multiple protocols you should use multiple worker objects. | |
| 232 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | |
| 233 public: | |
| 234 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | |
| 235 const std::string& protocol); | |
| 236 | |
| 237 private: | |
| 238 virtual ~DefaultProtocolClientWorker() {} | |
| 239 | |
| 240 // Check is Chrome is the default handler for this protocol. | |
| 241 virtual DefaultWebClientState CheckIsDefault(); | |
| 242 | |
| 243 // Set Chrome as the default handler for this protocol. | |
| 244 virtual void SetAsDefault(); | |
| 245 | |
| 246 std::string protocol_; | |
| 247 | |
| 248 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | |
| 249 }; | |
| 186 }; | 250 }; |
| 187 | 251 |
| 188 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 252 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |