| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 STATE_NOT_DEFAULT, | 162 STATE_NOT_DEFAULT, |
| 163 STATE_IS_DEFAULT, | 163 STATE_IS_DEFAULT, |
| 164 STATE_UNKNOWN | 164 STATE_UNKNOWN |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 class DefaultWebClientObserver { | 167 class DefaultWebClientObserver { |
| 168 public: | 168 public: |
| 169 virtual ~DefaultWebClientObserver() {} | 169 virtual ~DefaultWebClientObserver() {} |
| 170 // Updates the UI state to reflect the current default browser state. | 170 // Updates the UI state to reflect the current default browser state. |
| 171 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 171 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| 172 // Called to notify the UI of the immediate result of invoking |
| 173 // SetAsDefault. |
| 174 virtual void OnSetAsDefaultConcluded(bool succeeded) {} |
| 172 // Observer classes that return true to OwnedByWorker are automatically | 175 // Observer classes that return true to OwnedByWorker are automatically |
| 173 // freed by the worker when they are no longer needed. | 176 // freed by the worker when they are no longer needed. False by default. |
| 174 virtual bool IsOwnedByWorker() { return false; } | 177 virtual bool IsOwnedByWorker(); |
| 175 // An observer can permit or decline set-as-default operation if it | 178 // An observer can permit or decline set-as-default operation if it |
| 176 // requires triggering user interaction. | 179 // requires triggering user interaction. By default not allowed. |
| 177 virtual bool IsInteractiveSetDefaultPermitted() { return false; } | 180 virtual bool IsInteractiveSetDefaultPermitted(); |
| 178 }; | 181 }; |
| 179 | 182 |
| 180 // Helper objects that handle checking if Chrome is the default browser | 183 // Helper objects that handle checking if Chrome is the default browser |
| 181 // or application for a url protocol on Windows and Linux, and also setting | 184 // or application for a url protocol on Windows and Linux, and also setting |
| 182 // it as the default. These operations are performed asynchronously on the | 185 // it as the default. These operations are performed asynchronously on the |
| 183 // file thread since registry access (on Windows) or the preference database | 186 // file thread since registry access (on Windows) or the preference database |
| 184 // (on Linux) are involved and this can be slow. | 187 // (on Linux) are involved and this can be slow. |
| 185 class DefaultWebClientWorker | 188 class DefaultWebClientWorker |
| 186 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 189 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| 187 public: | 190 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 | 205 |
| 203 protected: | 206 protected: |
| 204 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 207 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
| 205 | 208 |
| 206 virtual ~DefaultWebClientWorker() {} | 209 virtual ~DefaultWebClientWorker() {} |
| 207 | 210 |
| 208 private: | 211 private: |
| 209 // Function that performs the check. | 212 // Function that performs the check. |
| 210 virtual DefaultWebClientState CheckIsDefault() = 0; | 213 virtual DefaultWebClientState CheckIsDefault() = 0; |
| 211 | 214 |
| 212 // Function that sets Chrome as the default web client. | 215 // Function that sets Chrome as the default web client. Returns false if |
| 213 virtual void SetAsDefault(bool interactive_permitted) = 0; | 216 // the operation fails or has been cancelled by the user. |
| 217 virtual bool SetAsDefault(bool interactive_permitted) = 0; |
| 214 | 218 |
| 215 // Function that handles performing the check on the file thread. This | 219 // Function that handles performing the check on the file thread. This |
| 216 // function is posted as a task onto the file thread, where it performs | 220 // function is posted as a task onto the file thread, where it performs |
| 217 // the check. When the check has finished the CompleteCheckIsDefault | 221 // the check. When the check has finished the CompleteCheckIsDefault |
| 218 // function is posted to the UI thread, where the result is sent back to | 222 // function is posted to the UI thread, where the result is sent back to |
| 219 // the observer. | 223 // the observer. |
| 220 void ExecuteCheckIsDefault(); | 224 void ExecuteCheckIsDefault(); |
| 221 | 225 |
| 222 // Function that handles setting Chrome as the default web client on the | 226 // Function that handles setting Chrome as the default web client on the |
| 223 // file thread. This function is posted as a task onto the file thread. | 227 // file thread. This function is posted as a task onto the file thread. |
| 224 // Once it is finished the CompleteSetAsDefault function is posted to the | 228 // Once it is finished the CompleteSetAsDefault function is posted to the |
| 225 // UI thread which will check the status of Chrome as the default, and | 229 // UI thread which will check the status of Chrome as the default, and |
| 226 // send this to the observer. | 230 // send this to the observer. |
| 227 void ExecuteSetAsDefault(); | 231 // |interactive_permitted| indicates if the routine is allowed to carry on |
| 232 // in context where user interaction is required (CanSetAsDefault* |
| 233 // returns SET_DEFAULT_INTERACTIVE). |
| 234 void ExecuteSetAsDefault(bool interactive_permitted); |
| 228 | 235 |
| 229 // Communicate results to the observer. This function is posted as a task | 236 // Communicate results to the observer. This function is posted as a task |
| 230 // onto the UI thread by the ExecuteCheckIsDefault function running in the | 237 // onto the UI thread by the ExecuteCheckIsDefault function running in the |
| 231 // file thread. | 238 // file thread. |
| 232 void CompleteCheckIsDefault(DefaultWebClientState state); | 239 void CompleteCheckIsDefault(DefaultWebClientState state); |
| 233 | 240 |
| 234 // When the action to set Chrome as the default has completed this function | 241 // When the action to set Chrome as the default has completed this function |
| 235 // is run. It is posted as a task back onto the UI thread by the | 242 // is run. It is posted as a task back onto the UI thread by the |
| 236 // ExecuteSetAsDefault function running in the file thread. This function | 243 // ExecuteSetAsDefault function running in the file thread. This function |
| 237 // will the start the check process, which, if an observer is present, | 244 // will the start the check process, which, if an observer is present, |
| 238 // reports to it the new status. | 245 // reports to it the new status. |
| 239 void CompleteSetAsDefault(); | 246 // |succeeded| is true if the actual call to a set-default function (from |
| 247 // ExecuteSetAsDefault) was successful. |
| 248 void CompleteSetAsDefault(bool succeeded); |
| 240 | 249 |
| 241 // Updates the UI in our associated view with the current default web | 250 // Updates the UI in our associated view with the current default web |
| 242 // client state. | 251 // client state. |
| 243 void UpdateUI(DefaultWebClientState state); | 252 void UpdateUI(DefaultWebClientState state); |
| 244 | 253 |
| 245 DefaultWebClientObserver* observer_; | 254 DefaultWebClientObserver* observer_; |
| 246 | 255 |
| 247 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 256 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 248 }; | 257 }; |
| 249 | 258 |
| 250 // Worker for checking and setting the default browser. | 259 // Worker for checking and setting the default browser. |
| 251 class DefaultBrowserWorker : public DefaultWebClientWorker { | 260 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 252 public: | 261 public: |
| 253 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 262 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| 254 | 263 |
| 255 private: | 264 private: |
| 256 virtual ~DefaultBrowserWorker() {} | 265 virtual ~DefaultBrowserWorker() {} |
| 257 | 266 |
| 258 // Check if Chrome is the default browser. | 267 // Check if Chrome is the default browser. |
| 259 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 268 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
| 260 | 269 |
| 261 // Set Chrome as the default browser. | 270 // Set Chrome as the default browser. |
| 262 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; | 271 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE; |
| 263 | 272 |
| 264 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 273 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 265 }; | 274 }; |
| 266 | 275 |
| 267 // Worker for checking and setting the default client application | 276 // Worker for checking and setting the default client application |
| 268 // for a given protocol. A different worker instance is needed for each | 277 // for a given protocol. A different worker instance is needed for each |
| 269 // protocol you are interested in, so to check or set the default for | 278 // protocol you are interested in, so to check or set the default for |
| 270 // multiple protocols you should use multiple worker objects. | 279 // multiple protocols you should use multiple worker objects. |
| 271 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 280 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 272 public: | 281 public: |
| 273 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 282 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 274 const std::string& protocol); | 283 const std::string& protocol); |
| 275 | 284 |
| 276 const std::string& protocol() const { return protocol_; } | 285 const std::string& protocol() const { return protocol_; } |
| 277 | 286 |
| 278 protected: | 287 protected: |
| 279 virtual ~DefaultProtocolClientWorker() {} | 288 virtual ~DefaultProtocolClientWorker() {} |
| 280 | 289 |
| 281 private: | 290 private: |
| 282 // Check is Chrome is the default handler for this protocol. | 291 // Check is Chrome is the default handler for this protocol. |
| 283 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 292 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
| 284 | 293 |
| 285 // Set Chrome as the default handler for this protocol. | 294 // Set Chrome as the default handler for this protocol. |
| 286 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; | 295 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE; |
| 287 | 296 |
| 288 std::string protocol_; | 297 std::string protocol_; |
| 289 | 298 |
| 290 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 299 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 291 }; | 300 }; |
| 292 }; | 301 }; |
| 293 | 302 |
| 294 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 303 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |