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 DefaultSettingsChangePermission { |
| 41 CHANGE_DEFAULT_NOT_ALLOWED = 0, |
| 42 CHANGE_DEFAULT_UNATTENDED, |
| 43 CHANGE_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 DefaultSettingsChangePermission 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 DefaultSettingsChangePermission 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }; | 154 }; |
139 | 155 |
140 class DefaultWebClientObserver { | 156 class DefaultWebClientObserver { |
141 public: | 157 public: |
142 virtual ~DefaultWebClientObserver() {} | 158 virtual ~DefaultWebClientObserver() {} |
143 // Updates the UI state to reflect the current default browser state. | 159 // Updates the UI state to reflect the current default browser state. |
144 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 160 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
145 // Observer classes that return true to OwnedByWorker are automatically | 161 // Observer classes that return true to OwnedByWorker are automatically |
146 // freed by the worker when they are no longer needed. | 162 // freed by the worker when they are no longer needed. |
147 virtual bool IsOwnedByWorker() { return false; } | 163 virtual bool IsOwnedByWorker() { return false; } |
| 164 // An observer can permit or decline set-as-default operation if it |
| 165 // requires triggering user interaction. |
| 166 virtual bool IsInteractiveSetDefaultPermitted() { return false; } |
148 }; | 167 }; |
149 | 168 |
150 // Helper objects that handle checking if Chrome is the default browser | 169 // Helper objects that handle checking if Chrome is the default browser |
151 // or application for a url protocol on Windows and Linux, and also setting | 170 // or application for a url protocol on Windows and Linux, and also setting |
152 // it as the default. These operations are performed asynchronously on the | 171 // it as the default. These operations are performed asynchronously on the |
153 // file thread since registry access (on Windows) or the preference database | 172 // file thread since registry access (on Windows) or the preference database |
154 // (on Linux) are involved and this can be slow. | 173 // (on Linux) are involved and this can be slow. |
155 class DefaultWebClientWorker | 174 class DefaultWebClientWorker |
156 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 175 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
157 public: | 176 public: |
(...skipping 15 matching lines...) Expand all Loading... |
173 protected: | 192 protected: |
174 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 193 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
175 | 194 |
176 virtual ~DefaultWebClientWorker() {} | 195 virtual ~DefaultWebClientWorker() {} |
177 | 196 |
178 private: | 197 private: |
179 // Function that performs the check. | 198 // Function that performs the check. |
180 virtual DefaultWebClientState CheckIsDefault() = 0; | 199 virtual DefaultWebClientState CheckIsDefault() = 0; |
181 | 200 |
182 // Function that sets Chrome as the default web client. | 201 // Function that sets Chrome as the default web client. |
183 virtual void SetAsDefault() = 0; | 202 virtual void SetAsDefault(bool interactive_permitted) = 0; |
184 | 203 |
185 // Function that handles performing the check on the file thread. This | 204 // Function that handles performing the check on the file thread. This |
186 // function is posted as a task onto the file thread, where it performs | 205 // function is posted as a task onto the file thread, where it performs |
187 // the check. When the check has finished the CompleteCheckIsDefault | 206 // the check. When the check has finished the CompleteCheckIsDefault |
188 // function is posted to the UI thread, where the result is sent back to | 207 // function is posted to the UI thread, where the result is sent back to |
189 // the observer. | 208 // the observer. |
190 void ExecuteCheckIsDefault(); | 209 void ExecuteCheckIsDefault(); |
191 | 210 |
192 // Function that handles setting Chrome as the default web client on the | 211 // Function that handles setting Chrome as the default web client on the |
193 // file thread. This function is posted as a task onto the file thread. | 212 // file thread. This function is posted as a task onto the file thread. |
(...skipping 28 matching lines...) Expand all Loading... |
222 public: | 241 public: |
223 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 242 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
224 | 243 |
225 private: | 244 private: |
226 virtual ~DefaultBrowserWorker() {} | 245 virtual ~DefaultBrowserWorker() {} |
227 | 246 |
228 // Check if Chrome is the default browser. | 247 // Check if Chrome is the default browser. |
229 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 248 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
230 | 249 |
231 // Set Chrome as the default browser. | 250 // Set Chrome as the default browser. |
232 virtual void SetAsDefault() OVERRIDE; | 251 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; |
233 | 252 |
234 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 253 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
235 }; | 254 }; |
236 | 255 |
237 // Worker for checking and setting the default client application | 256 // Worker for checking and setting the default client application |
238 // for a given protocol. A different worker instance is needed for each | 257 // for a given protocol. A different worker instance is needed for each |
239 // protocol you are interested in, so to check or set the default for | 258 // protocol you are interested in, so to check or set the default for |
240 // multiple protocols you should use multiple worker objects. | 259 // multiple protocols you should use multiple worker objects. |
241 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 260 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
242 public: | 261 public: |
243 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 262 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
244 const std::string& protocol); | 263 const std::string& protocol); |
245 | 264 |
246 const std::string& protocol() const { return protocol_; } | 265 const std::string& protocol() const { return protocol_; } |
247 | 266 |
248 protected: | 267 protected: |
249 virtual ~DefaultProtocolClientWorker() {} | 268 virtual ~DefaultProtocolClientWorker() {} |
250 | 269 |
251 private: | 270 private: |
252 // Check is Chrome is the default handler for this protocol. | 271 // Check is Chrome is the default handler for this protocol. |
253 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; | 272 virtual DefaultWebClientState CheckIsDefault() OVERRIDE; |
254 | 273 |
255 // Set Chrome as the default handler for this protocol. | 274 // Set Chrome as the default handler for this protocol. |
256 virtual void SetAsDefault() OVERRIDE; | 275 virtual void SetAsDefault(bool interactive_permitted) OVERRIDE; |
257 | 276 |
258 std::string protocol_; | 277 std::string protocol_; |
259 | 278 |
260 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 279 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
261 }; | 280 }; |
262 }; | 281 }; |
263 | 282 |
264 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 283 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |