Chromium Code Reviews| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // querying if Chrome is the default browser or the default handler | 155 // querying if Chrome is the default browser or the default handler |
| 156 // application for a url protocol, and communicates the state and result of | 156 // application for a url protocol, and communicates the state and result of |
| 157 // a request. | 157 // a request. |
| 158 enum DefaultWebClientUIState { | 158 enum DefaultWebClientUIState { |
| 159 STATE_PROCESSING, | 159 STATE_PROCESSING, |
| 160 STATE_NOT_DEFAULT, | 160 STATE_NOT_DEFAULT, |
| 161 STATE_IS_DEFAULT, | 161 STATE_IS_DEFAULT, |
| 162 STATE_UNKNOWN | 162 STATE_UNKNOWN |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 // The result of invoking SetAsDefault operation from within a | |
| 166 // DefaultWebClientWorker implementation. Note that from this result we | |
| 167 // cannot really infere if Chrome indeed become the default, because | |
|
grt (UTC plus 2)
2012/06/19 20:43:09
infere -> infer
motek.
2012/06/20 16:02:15
This is gone.
| |
| 168 // in the interactive mode user could ended up chosing a different client. | |
| 169 enum SetDefaultWebClientResult { | |
| 170 RESULT_SET_DEFAULT_OK, | |
| 171 RESULT_SET_DEFAULT_FAILED_OR_CANCELLED, | |
| 172 RESULT_SET_DEFAULT_UNDEFINED, | |
| 173 }; | |
| 174 | |
| 165 class DefaultWebClientObserver { | 175 class DefaultWebClientObserver { |
| 166 public: | 176 public: |
| 167 virtual ~DefaultWebClientObserver() {} | 177 virtual ~DefaultWebClientObserver() {} |
| 168 // Updates the UI state to reflect the current default browser state. | 178 // Updates the UI state to reflect the current default browser state. |
| 169 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 179 virtual void SetDefaultWebClientUIState( |
| 180 DefaultWebClientUIState state, | |
| 181 SetDefaultWebClientResult call_result) = 0; | |
| 170 // Observer classes that return true to OwnedByWorker are automatically | 182 // Observer classes that return true to OwnedByWorker are automatically |
| 171 // freed by the worker when they are no longer needed. | 183 // freed by the worker when they are no longer needed. |
| 172 virtual bool IsOwnedByWorker() { return false; } | 184 virtual bool IsOwnedByWorker() { return false; } |
| 173 // An observer can permit or decline set-as-default operation if it | 185 // An observer can permit or decline set-as-default operation if it |
| 174 // requires triggering user interaction. | 186 // requires triggering user interaction. |
| 175 virtual bool IsInteractiveSetDefaultPermitted() { return false; } | 187 virtual bool IsInteractiveSetDefaultPermitted() { return false; } |
| 176 }; | 188 }; |
| 177 | 189 |
| 178 // Helper objects that handle checking if Chrome is the default browser | 190 // Helper objects that handle checking if Chrome is the default browser |
| 179 // or application for a url protocol on Windows and Linux, and also setting | 191 // or application for a url protocol on Windows and Linux, and also setting |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 201 protected: | 213 protected: |
| 202 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 214 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
| 203 | 215 |
| 204 virtual ~DefaultWebClientWorker() {} | 216 virtual ~DefaultWebClientWorker() {} |
| 205 | 217 |
| 206 private: | 218 private: |
| 207 // Function that performs the check. | 219 // Function that performs the check. |
| 208 virtual DefaultWebClientState CheckIsDefault() = 0; | 220 virtual DefaultWebClientState CheckIsDefault() = 0; |
| 209 | 221 |
| 210 // Function that sets Chrome as the default web client. | 222 // Function that sets Chrome as the default web client. |
| 211 virtual void SetAsDefault(bool interactive_permitted) = 0; | 223 virtual SetDefaultWebClientResult SetAsDefault( |
| 224 bool interactive_permitted) = 0; | |
| 225 | |
| 226 // Private version takes a call result to be eventually forwarded to the | |
| 227 // observer. | |
| 228 void StartCheckIsDefault(SetDefaultWebClientResult call_result); | |
| 212 | 229 |
| 213 // Function that handles performing the check on the file thread. This | 230 // Function that handles performing the check on the file thread. This |
| 214 // function is posted as a task onto the file thread, where it performs | 231 // function is posted as a task onto the file thread, where it performs |
| 215 // the check. When the check has finished the CompleteCheckIsDefault | 232 // the check. When the check has finished the CompleteCheckIsDefault |
| 216 // function is posted to the UI thread, where the result is sent back to | 233 // function is posted to the UI thread, where the result is sent back to |
| 217 // the observer. | 234 // the observer. |
| 218 void ExecuteCheckIsDefault(); | 235 void ExecuteCheckIsDefault(SetDefaultWebClientResult call_result); |
| 219 | 236 |
| 220 // Function that handles setting Chrome as the default web client on the | 237 // Function that handles setting Chrome as the default web client on the |
| 221 // file thread. This function is posted as a task onto the file thread. | 238 // file thread. This function is posted as a task onto the file thread. |
| 222 // Once it is finished the CompleteSetAsDefault function is posted to the | 239 // Once it is finished the CompleteSetAsDefault function is posted to the |
| 223 // UI thread which will check the status of Chrome as the default, and | 240 // UI thread which will check the status of Chrome as the default, and |
| 224 // send this to the observer. | 241 // send this to the observer. |
| 225 void ExecuteSetAsDefault(); | 242 void ExecuteSetAsDefault(); |
| 226 | 243 |
| 227 // Communicate results to the observer. This function is posted as a task | 244 // Communicate results to the observer. This function is posted as a task |
| 228 // onto the UI thread by the ExecuteCheckIsDefault function running in the | 245 // onto the UI thread by the ExecuteCheckIsDefault function running in the |
| 229 // file thread. | 246 // file thread. |
| 230 void CompleteCheckIsDefault(DefaultWebClientState state); | 247 void CompleteCheckIsDefault(DefaultWebClientState state, |
| 248 SetDefaultWebClientResult call_result); | |
| 231 | 249 |
| 232 // When the action to set Chrome as the default has completed this function | 250 // When the action to set Chrome as the default has completed this function |
| 233 // is run. It is posted as a task back onto the UI thread by the | 251 // is run. It is posted as a task back onto the UI thread by the |
| 234 // ExecuteSetAsDefault function running in the file thread. This function | 252 // ExecuteSetAsDefault function running in the file thread. This function |
| 235 // will the start the check process, which, if an observer is present, | 253 // will the start the check process, which, if an observer is present, |
| 236 // reports to it the new status. | 254 // reports to it the new status. |
| 237 void CompleteSetAsDefault(); | 255 void CompleteSetAsDefault(SetDefaultWebClientResult call_result); |
| 238 | 256 |
| 239 // Updates the UI in our associated view with the current default web | 257 // Updates the UI in our associated view with the current default web |
| 240 // client state. | 258 // client state. |
| 241 void UpdateUI(DefaultWebClientState state); | 259 void UpdateUI(DefaultWebClientState state, |
| 260 SetDefaultWebClientResult call_result); | |
| 242 | 261 |
| 243 DefaultWebClientObserver* observer_; | 262 DefaultWebClientObserver* observer_; |
| 244 | 263 |
| 245 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 264 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 246 }; | 265 }; |
| 247 | 266 |
| 248 // Worker for checking and setting the default browser. | 267 // Worker for checking and setting the default browser. |
| 249 class DefaultBrowserWorker : public DefaultWebClientWorker { | 268 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 250 public: | 269 public: |
| 251 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 270 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| 252 | 271 |
| 253 private: | 272 private: |
| 254 virtual ~DefaultBrowserWorker() {} | 273 virtual ~DefaultBrowserWorker() {} |
| 255 | 274 |
| 256 // Check if Chrome is the default browser. | 275 // Check if Chrome is the default browser. |
| 257 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 276 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
| 258 | 277 |
| 259 // Set Chrome as the default browser. | 278 // Set Chrome as the default browser. |
| 260 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; | 279 virtual SetDefaultWebClientResult SetAsDefault( |
| 280 bool interactive_permitted) OVERRIDE; | |
| 261 | 281 |
| 262 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 282 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 263 }; | 283 }; |
| 264 | 284 |
| 265 // Worker for checking and setting the default client application | 285 // Worker for checking and setting the default client application |
| 266 // for a given protocol. A different worker instance is needed for each | 286 // for a given protocol. A different worker instance is needed for each |
| 267 // protocol you are interested in, so to check or set the default for | 287 // protocol you are interested in, so to check or set the default for |
| 268 // multiple protocols you should use multiple worker objects. | 288 // multiple protocols you should use multiple worker objects. |
| 269 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 289 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 270 public: | 290 public: |
| 271 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 291 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 272 const std::string& protocol); | 292 const std::string& protocol); |
| 273 | 293 |
| 274 const std::string& protocol() const { return protocol_; } | 294 const std::string& protocol() const { return protocol_; } |
| 275 | 295 |
| 276 protected: | 296 protected: |
| 277 virtual ~DefaultProtocolClientWorker() {} | 297 virtual ~DefaultProtocolClientWorker() {} |
| 278 | 298 |
| 279 private: | 299 private: |
| 280 // Check is Chrome is the default handler for this protocol. | 300 // Check is Chrome is the default handler for this protocol. |
| 281 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 301 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
| 282 | 302 |
| 283 // Set Chrome as the default handler for this protocol. | 303 // Set Chrome as the default handler for this protocol. |
| 284 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; | 304 virtual SetDefaultWebClientResult SetAsDefault( |
| 305 bool interactive_permitted) OVERRIDE; | |
| 285 | 306 |
| 286 std::string protocol_; | 307 std::string protocol_; |
| 287 | 308 |
| 288 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 309 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 289 }; | 310 }; |
| 290 }; | 311 }; |
| 291 | 312 |
| 292 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 313 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |