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 | |
34 // current user). Returns false if this operation fails. | |
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 DefaultClientAppState { |
Mark Mentovai
2011/05/23 00:23:52
In isolation, DefaultClientAppState doesn’t tell m
benwells
2011/05/23 06:08:37
Agreed, it doesn't say enough. I avoided the word
benwells
2011/05/24 06:10:38
Done.
| |
38 NOT_DEFAULT_BROWSER = 0, | 42 NOT_DEFAULT_CLIENT_APP = 0, |
39 IS_DEFAULT_BROWSER, | 43 IS_DEFAULT_CLIENT_APP, |
40 UNKNOWN_DEFAULT_BROWSER | 44 UNKNOWN_DEFAULT_CLIENT_APP |
Mark Mentovai
2011/05/23 00:23:52
My own preference would be for the UNKNOWN element
benwells
2011/05/24 06:10:38
Done.
| |
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 DefaultClientAppState 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 DefaultClientAppState | |
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 |
127 enum DefaultBrowserUIState { | 136 enum DefaultClientAppUIState { |
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 DefaultClientAppObserver { |
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 SetDefaultClientAppUIState(DefaultClientAppUIState state) = 0; |
138 virtual ~DefaultBrowserObserver() {} | 147 virtual ~DefaultClientAppObserver() {} |
139 }; | 148 }; |
140 // A helper object that handles checking if Chrome is the default browser on | 149 // A helper object that handles checking if Chrome is the default browser |
141 // Windows and also setting it as the default browser. These operations are | 150 // or application for a url protocol on Windows and Linux, and also setting |
142 // performed asynchronously on the file thread since registry access is | 151 // it as the default. These operations are performed asynchronously on the |
143 // involved and this can be slow. | 152 // file thread since registry access is involved and this can be slow. |
Mark Mentovai
2011/05/23 00:23:52
Any comment in this file that mentions the “regist
benwells
2011/05/24 06:10:38
Done.
| |
144 // | 153 class DefaultClientAppWorker |
Mark Mentovai
2011/05/23 00:23:52
I believe that this interface is now too cumbersom
benwells
2011/05/23 06:08:37
Yes, there would be some hazard if you tried to re
benwells
2011/05/24 06:10:38
Done.
| |
145 class DefaultBrowserWorker | 154 : public base::RefCountedThreadSafe<DefaultClientAppWorker> { |
146 : public base::RefCountedThreadSafe<DefaultBrowserWorker> { | |
147 public: | 155 public: |
148 explicit DefaultBrowserWorker(DefaultBrowserObserver* observer); | 156 explicit DefaultClientAppWorker(DefaultClientAppObserver* observer); |
149 | 157 |
150 // Checks if Chrome is the default browser. | 158 // Checks to see if Chrome is the default browser or protocol client. |
151 void StartCheckDefaultBrowser(); | 159 void StartCheckDefaultBrowser(); |
160 void StartCheckDefaultProtocolClient(const std::string& protocol); | |
152 | 161 |
153 // Sets Chrome as the default browser. | 162 // Sets Chrome as the default browser or protocol client. |
154 void StartSetAsDefaultBrowser(); | 163 void StartSetAsDefaultBrowser(); |
164 void StartSetAsDefaultProtocolClient(const std::string& protocol); | |
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 |
159 private: | 169 private: |
160 friend class base::RefCountedThreadSafe<DefaultBrowserWorker>; | 170 friend class base::RefCountedThreadSafe<DefaultClientAppWorker>; |
161 | 171 |
162 virtual ~DefaultBrowserWorker() {} | 172 virtual ~DefaultClientAppWorker() {} |
163 | 173 |
164 // Functions that track the process of checking if Chrome is the default | 174 // Functions that track the process of checking if Chrome is the default |
165 // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file | 175 // browser. |ExecuteCheckDefault*| checks the registry on the file thread. |
166 // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the | 176 // |CompleteCheckDefaultApplication| notifies the view to update on the |
167 // UI thread. | 177 // UI thread. |
168 void ExecuteCheckDefaultBrowser(); | 178 void ExecuteCheckDefaultBrowser(); |
169 void CompleteCheckDefaultBrowser(DefaultBrowserState state); | 179 void ExecuteCheckDefaultProtocolClient(); |
180 void CompleteCheckDefaultApplication(DefaultClientAppState state); | |
170 | 181 |
171 // Functions that track the process of setting Chrome as the default | 182 // Functions that track the process of setting Chrome as the default |
172 // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file | 183 // browser. |ExecuteSetAsDefault*| updates the registry on the file |
173 // thread. |CompleteSetAsDefaultBrowser| notifies the view to update on the | 184 // thread. |CompleteSetAsDefault*| notifies the view to update on the |
174 // UI thread. | 185 // UI thread. |
175 void ExecuteSetAsDefaultBrowser(); | 186 void ExecuteSetAsDefaultBrowser(); |
187 void ExecuteSetAsDefaultProtocolClient(); | |
176 void CompleteSetAsDefaultBrowser(); | 188 void CompleteSetAsDefaultBrowser(); |
189 void CompleteSetAsDefaultProtocolClient(); | |
177 | 190 |
178 // Updates the UI in our associated view with the current default browser | 191 // Updates the UI in our associated view with the current default browser |
179 // state. | 192 // state. |
180 void UpdateUI(DefaultBrowserState state); | 193 void UpdateUI(DefaultClientAppState state); |
181 | 194 |
182 DefaultBrowserObserver* observer_; | 195 DefaultClientAppObserver* observer_; |
196 std::string protocol_; | |
183 | 197 |
184 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 198 DISALLOW_COPY_AND_ASSIGN(DefaultClientAppWorker); |
185 }; | 199 }; |
186 }; | 200 }; |
187 | 201 |
188 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 202 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |