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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 | 17 |
18 class CommandLine; | 18 class CommandLine; |
19 | 19 |
20 class ShellIntegration { | 20 class ShellIntegration { |
21 public: | 21 public: |
22 // Sets Chrome as the default browser (only for the current user). Returns | 22 // Sets Chrome as the default browser (only for the current user). Returns |
23 // false if this operation fails. | 23 // false if this operation fails. |
24 static bool SetAsDefaultBrowser(); | 24 static bool SetAsDefaultBrowser(); |
25 | 25 |
| 26 // Initiates an OS shell flow which (if followed by the user) should set |
| 27 // Chrome as the default browser. Returns false if the flow cannot be |
| 28 // initialized, if it is not supported (introduced for Windows 8) or if the |
| 29 // user cancels the operation. This is a blocking call and requires a FILE |
| 30 // thread. |
| 31 static bool SetAsDefaultBrowserInteractive(); |
| 32 |
26 // Sets Chrome as the default client application for the given protocol | 33 // Sets Chrome as the default client application for the given protocol |
27 // (only for the current user). Returns false if this operation fails. | 34 // (only for the current user). Returns false if this operation fails. |
28 static bool SetAsDefaultProtocolClient(const std::string& protocol); | 35 static bool SetAsDefaultProtocolClient(const std::string& protocol); |
29 | 36 |
30 // Returns true if the running browser can be set as the default browser. | 37 // In Windows 8 a browser can be made default-in-metro only in an interactive |
31 static bool CanSetAsDefaultBrowser(); | 38 // flow. We will distinguish between two types of permissions here to avoid |
| 39 // forcing the user into UI interaction when this should not be done. |
| 40 enum DefaultWebClientSetPermission { |
| 41 SET_DEFAULT_NOT_ALLOWED = 0, |
| 42 SET_DEFAULT_UNATTENDED, |
| 43 SET_DEFAULT_INTERACTIVE, |
| 44 }; |
32 | 45 |
33 // Returns true if the running browser can be set as the default client | 46 // Returns requirements for making the running browser the user's default. |
34 // application for specific protocols. | 47 static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); |
35 static bool CanSetAsDefaultProtocolClient(); | 48 |
| 49 // Returns requirements for making the running browser the user's default |
| 50 // client application for specific protocols. |
| 51 static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); |
36 | 52 |
37 // On Linux, it may not be possible to determine or set the default browser | 53 // On Linux, it may not be possible to determine or set the default browser |
38 // on some desktop environments or configurations. So, we use this enum and | 54 // on some desktop environments or configurations. So, we use this enum and |
39 // not a plain bool. (Note however that if used like a bool, this enum will | 55 // not a plain bool. (Note however that if used like a bool, this enum will |
40 // have reasonable behavior.) | 56 // have reasonable behavior.) |
41 enum DefaultWebClientState { | 57 enum DefaultWebClientState { |
42 NOT_DEFAULT_WEB_CLIENT = 0, | 58 NOT_DEFAULT_WEB_CLIENT = 0, |
43 IS_DEFAULT_WEB_CLIENT, | 59 IS_DEFAULT_WEB_CLIENT, |
44 UNKNOWN_DEFAULT_WEB_CLIENT = -1 | 60 UNKNOWN_DEFAULT_WEB_CLIENT = -1 |
45 }; | 61 }; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 }; | 159 }; |
144 | 160 |
145 class DefaultWebClientObserver { | 161 class DefaultWebClientObserver { |
146 public: | 162 public: |
147 virtual ~DefaultWebClientObserver() {} | 163 virtual ~DefaultWebClientObserver() {} |
148 // Updates the UI state to reflect the current default browser state. | 164 // Updates the UI state to reflect the current default browser state. |
149 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 165 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
150 // Observer classes that return true to OwnedByWorker are automatically | 166 // Observer classes that return true to OwnedByWorker are automatically |
151 // freed by the worker when they are no longer needed. | 167 // freed by the worker when they are no longer needed. |
152 virtual bool IsOwnedByWorker() { return false; } | 168 virtual bool IsOwnedByWorker() { return false; } |
| 169 // An observer can permit or decline set-as-default operation if it |
| 170 // requires triggering user interaction. |
| 171 virtual bool IsInteractiveSetDefaultPermitted() { return false; } |
153 }; | 172 }; |
154 | 173 |
155 // Helper objects that handle checking if Chrome is the default browser | 174 // Helper objects that handle checking if Chrome is the default browser |
156 // or application for a url protocol on Windows and Linux, and also setting | 175 // or application for a url protocol on Windows and Linux, and also setting |
157 // it as the default. These operations are performed asynchronously on the | 176 // it as the default. These operations are performed asynchronously on the |
158 // file thread since registry access (on Windows) or the preference database | 177 // file thread since registry access (on Windows) or the preference database |
159 // (on Linux) are involved and this can be slow. | 178 // (on Linux) are involved and this can be slow. |
160 class DefaultWebClientWorker | 179 class DefaultWebClientWorker |
161 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 180 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
162 public: | 181 public: |
(...skipping 15 matching lines...) Expand all Loading... |
178 protected: | 197 protected: |
179 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 198 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
180 | 199 |
181 virtual ~DefaultWebClientWorker() {} | 200 virtual ~DefaultWebClientWorker() {} |
182 | 201 |
183 private: | 202 private: |
184 // Function that performs the check. | 203 // Function that performs the check. |
185 virtual DefaultWebClientState CheckIsDefault() = 0; | 204 virtual DefaultWebClientState CheckIsDefault() = 0; |
186 | 205 |
187 // Function that sets Chrome as the default web client. | 206 // Function that sets Chrome as the default web client. |
188 virtual void SetAsDefault() = 0; | 207 virtual void SetAsDefault(bool interactive_permitted) = 0; |
189 | 208 |
190 // Function that handles performing the check on the file thread. This | 209 // Function that handles performing the check on the file thread. This |
191 // function is posted as a task onto the file thread, where it performs | 210 // function is posted as a task onto the file thread, where it performs |
192 // the check. When the check has finished the CompleteCheckIsDefault | 211 // the check. When the check has finished the CompleteCheckIsDefault |
193 // function is posted to the UI thread, where the result is sent back to | 212 // function is posted to the UI thread, where the result is sent back to |
194 // the observer. | 213 // the observer. |
195 void ExecuteCheckIsDefault(); | 214 void ExecuteCheckIsDefault(); |
196 | 215 |
197 // Function that handles setting Chrome as the default web client on the | 216 // Function that handles setting Chrome as the default web client on the |
198 // file thread. This function is posted as a task onto the file thread. | 217 // file thread. This function is posted as a task onto the file thread. |
(...skipping 28 matching lines...) Expand all Loading... |
227 public: | 246 public: |
228 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 247 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
229 | 248 |
230 private: | 249 private: |
231 virtual ~DefaultBrowserWorker() {} | 250 virtual ~DefaultBrowserWorker() {} |
232 | 251 |
233 // Check if Chrome is the default browser. | 252 // Check if Chrome is the default browser. |
234 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 253 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
235 | 254 |
236 // Set Chrome as the default browser. | 255 // Set Chrome as the default browser. |
237 virtual void SetAsDefault() OVERRIDE; | 256 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; |
238 | 257 |
239 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 258 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
240 }; | 259 }; |
241 | 260 |
242 // Worker for checking and setting the default client application | 261 // Worker for checking and setting the default client application |
243 // for a given protocol. A different worker instance is needed for each | 262 // for a given protocol. A different worker instance is needed for each |
244 // protocol you are interested in, so to check or set the default for | 263 // protocol you are interested in, so to check or set the default for |
245 // multiple protocols you should use multiple worker objects. | 264 // multiple protocols you should use multiple worker objects. |
246 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 265 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
247 public: | 266 public: |
248 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 267 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
249 const std::string& protocol); | 268 const std::string& protocol); |
250 | 269 |
251 const std::string& protocol() const { return protocol_; } | 270 const std::string& protocol() const { return protocol_; } |
252 | 271 |
253 protected: | 272 protected: |
254 virtual ~DefaultProtocolClientWorker() {} | 273 virtual ~DefaultProtocolClientWorker() {} |
255 | 274 |
256 private: | 275 private: |
257 // Check is Chrome is the default handler for this protocol. | 276 // Check is Chrome is the default handler for this protocol. |
258 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 277 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
259 | 278 |
260 // Set Chrome as the default handler for this protocol. | 279 // Set Chrome as the default handler for this protocol. |
261 virtual void SetAsDefault() OVERRIDE; | 280 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; |
262 | 281 |
263 std::string protocol_; | 282 std::string protocol_; |
264 | 283 |
265 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 284 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
266 }; | 285 }; |
267 }; | 286 }; |
268 | 287 |
269 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 288 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |