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_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/extensions/active_install_data.h" | 10 #include "chrome/browser/extensions/active_install_data.h" |
11 #include "chrome/browser/extensions/chrome_extension_function.h" | 11 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
12 #include "chrome/browser/extensions/extension_install_prompt.h" | 12 #include "chrome/browser/extensions/extension_install_prompt.h" |
13 #include "chrome/browser/extensions/webstore_install_helper.h" | 13 #include "chrome/browser/extensions/webstore_install_helper.h" |
14 #include "chrome/browser/extensions/webstore_installer.h" | 14 #include "chrome/browser/extensions/webstore_installer.h" |
15 #include "chrome/common/extensions/api/webstore_private.h" | 15 #include "chrome/common/extensions/api/webstore_private.h" |
16 #include "chrome/common/extensions/webstore_install_result.h" | 16 #include "chrome/common/extensions/webstore_install_result.h" |
17 #include "content/public/browser/gpu_data_manager_observer.h" | 17 #include "extensions/browser/extension_function.h" |
18 #include "content/public/browser/notification_observer.h" | |
19 #include "content/public/browser/notification_registrar.h" | |
20 #include "google_apis/gaia/google_service_auth_error.h" | |
21 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
22 | 19 |
23 class ProfileSyncService; | |
24 | |
25 namespace content { | |
26 class GpuDataManager; | |
27 } | |
28 | |
29 class GPUFeatureChecker; | 20 class GPUFeatureChecker; |
30 | 21 |
31 namespace extensions { | 22 namespace extensions { |
32 | 23 |
33 class WebstorePrivateApi { | 24 class WebstorePrivateApi { |
34 public: | 25 public: |
35 // Allows you to override the WebstoreInstaller delegate for testing. | 26 // Allows you to override the WebstoreInstaller delegate for testing. |
36 static void SetWebstoreInstallerDelegateForTesting( | 27 static void SetWebstoreInstallerDelegateForTesting( |
37 WebstoreInstaller::Delegate* delegate); | 28 WebstoreInstaller::Delegate* delegate); |
38 | 29 |
39 // Gets the pending approval for the |extension_id| in |profile|. Pending | 30 // Gets the pending approval for the |extension_id| in |profile|. Pending |
40 // approvals are held between the calls to beginInstallWithManifest and | 31 // approvals are held between the calls to beginInstallWithManifest and |
41 // completeInstall. This should only be used for testing. | 32 // completeInstall. This should only be used for testing. |
42 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting( | 33 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting( |
43 Profile* profile, const std::string& extension_id); | 34 Profile* profile, const std::string& extension_id); |
44 }; | 35 }; |
45 | 36 |
46 class WebstorePrivateBeginInstallWithManifest3Function | 37 class WebstorePrivateBeginInstallWithManifest3Function |
47 : public ChromeAsyncExtensionFunction, | 38 : public UIThreadExtensionFunction, |
48 public ExtensionInstallPrompt::Delegate, | 39 public ExtensionInstallPrompt::Delegate, |
49 public WebstoreInstallHelper::Delegate { | 40 public WebstoreInstallHelper::Delegate { |
50 public: | 41 public: |
51 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3", | 42 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3", |
52 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3) | 43 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3) |
53 | 44 |
54 // Result codes for the return value. If you change this, make sure to | 45 // Result codes for the return value. If you change this, make sure to |
55 // update the description for the beginInstallWithManifest3 callback in | 46 // update the description for the beginInstallWithManifest3 callback in |
56 // the extension API JSON. | 47 // the extension API JSON. |
57 enum ResultCode { | 48 enum ResultCode { |
(...skipping 19 matching lines...) Expand all Loading... |
77 | 68 |
78 // Invalid icon url. | 69 // Invalid icon url. |
79 INVALID_ICON_URL, | 70 INVALID_ICON_URL, |
80 | 71 |
81 // An extension with the same extension id has already been installed. | 72 // An extension with the same extension id has already been installed. |
82 ALREADY_INSTALLED, | 73 ALREADY_INSTALLED, |
83 }; | 74 }; |
84 | 75 |
85 WebstorePrivateBeginInstallWithManifest3Function(); | 76 WebstorePrivateBeginInstallWithManifest3Function(); |
86 | 77 |
| 78 private: |
| 79 ~WebstorePrivateBeginInstallWithManifest3Function() override; |
| 80 |
| 81 // ExtensionFunction: |
| 82 ExtensionFunction::ResponseAction Run() override; |
| 83 |
87 // WebstoreInstallHelper::Delegate: | 84 // WebstoreInstallHelper::Delegate: |
88 void OnWebstoreParseSuccess(const std::string& id, | 85 void OnWebstoreParseSuccess(const std::string& id, |
89 const SkBitmap& icon, | 86 const SkBitmap& icon, |
90 base::DictionaryValue* parsed_manifest) override; | 87 base::DictionaryValue* parsed_manifest) override; |
91 void OnWebstoreParseFailure(const std::string& id, | 88 void OnWebstoreParseFailure(const std::string& id, |
92 InstallHelperResultCode result_code, | 89 InstallHelperResultCode result_code, |
93 const std::string& error_message) override; | 90 const std::string& error_message) override; |
94 | 91 |
95 // ExtensionInstallPrompt::Delegate: | 92 // ExtensionInstallPrompt::Delegate: |
96 void InstallUIProceed() override; | 93 void InstallUIProceed() override; |
97 void InstallUIAbort(bool user_initiated) override; | 94 void InstallUIAbort(bool user_initiated) override; |
98 | 95 |
99 protected: | 96 // Response helpers. |
100 ~WebstorePrivateBeginInstallWithManifest3Function() override; | 97 const char* ResultCodeToString(ResultCode code) const; |
| 98 ExtensionFunction::ResponseValue BuildResponseForSuccess(); |
| 99 ExtensionFunction::ResponseValue BuildResponseForError( |
| 100 ResultCode code, const std::string& error); |
101 | 101 |
102 // ExtensionFunction: | 102 ChromeExtensionFunctionDetails chrome_details_; |
103 bool RunAsync() override; | |
104 | 103 |
105 // Sets the result_ as a string based on |code|. | 104 // This stores the input parameters to the function. |
106 void SetResultCode(ResultCode code); | |
107 | |
108 private: | |
109 const char* ResultCodeToString(ResultCode code); | |
110 | |
111 // These store the input parameters to the function. | |
112 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_; | 105 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_; |
113 | 106 |
114 // The results of parsing manifest_ and icon_data_ go into these two. | 107 // The results of parsing manifest_ and icon_data_ go into these two. |
115 scoped_ptr<base::DictionaryValue> parsed_manifest_; | 108 scoped_ptr<base::DictionaryValue> parsed_manifest_; |
116 SkBitmap icon_; | 109 SkBitmap icon_; |
117 | 110 |
118 // A dummy Extension object we create for the purposes of using | 111 // A dummy Extension object we create for the purposes of using |
119 // ExtensionInstallPrompt to prompt for confirmation of the install. | 112 // ExtensionInstallPrompt to prompt for confirmation of the install. |
120 scoped_refptr<extensions::Extension> dummy_extension_; | 113 scoped_refptr<Extension> dummy_extension_; |
121 | 114 |
122 // The class that displays the install prompt. | 115 // The class that displays the install prompt. |
123 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | 116 scoped_ptr<ExtensionInstallPrompt> install_prompt_; |
124 | 117 |
125 scoped_ptr<ScopedActiveInstall> scoped_active_install_; | 118 scoped_ptr<ScopedActiveInstall> scoped_active_install_; |
126 | 119 |
127 // The authuser query parameter value which should be used with CRX download | 120 // The authuser query parameter value which should be used with CRX download |
128 // requests. This is empty if authuser should not be set on download requests. | 121 // requests. This is empty if authuser should not be set on download requests. |
129 std::string authuser_; | 122 std::string authuser_; |
130 }; | 123 }; |
131 | 124 |
132 class WebstorePrivateCompleteInstallFunction | 125 class WebstorePrivateCompleteInstallFunction |
133 : public ChromeAsyncExtensionFunction, | 126 : public UIThreadExtensionFunction, |
134 public WebstoreInstaller::Delegate { | 127 public WebstoreInstaller::Delegate { |
135 public: | 128 public: |
136 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", | 129 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", |
137 WEBSTOREPRIVATE_COMPLETEINSTALL) | 130 WEBSTOREPRIVATE_COMPLETEINSTALL) |
138 | 131 |
139 WebstorePrivateCompleteInstallFunction(); | 132 WebstorePrivateCompleteInstallFunction(); |
140 | 133 |
| 134 private: |
| 135 ~WebstorePrivateCompleteInstallFunction() override; |
| 136 |
| 137 // ExtensionFunction: |
| 138 ExtensionFunction::ResponseAction Run() override; |
| 139 |
141 // WebstoreInstaller::Delegate: | 140 // WebstoreInstaller::Delegate: |
142 void OnExtensionInstallSuccess(const std::string& id) override; | 141 void OnExtensionInstallSuccess(const std::string& id) override; |
143 void OnExtensionInstallFailure( | 142 void OnExtensionInstallFailure( |
144 const std::string& id, | 143 const std::string& id, |
145 const std::string& error, | 144 const std::string& error, |
146 WebstoreInstaller::FailureReason reason) override; | 145 WebstoreInstaller::FailureReason reason) override; |
147 | 146 |
148 protected: | 147 void OnInstallSuccess(const std::string& id); |
149 ~WebstorePrivateCompleteInstallFunction() override; | |
150 | 148 |
151 // ExtensionFunction: | 149 ChromeExtensionFunctionDetails chrome_details_; |
152 bool RunAsync() override; | |
153 | 150 |
154 private: | |
155 scoped_ptr<WebstoreInstaller::Approval> approval_; | 151 scoped_ptr<WebstoreInstaller::Approval> approval_; |
156 scoped_ptr<ScopedActiveInstall> scoped_active_install_; | 152 scoped_ptr<ScopedActiveInstall> scoped_active_install_; |
157 | |
158 void OnInstallSuccess(const std::string& id); | |
159 }; | 153 }; |
160 | 154 |
161 class WebstorePrivateEnableAppLauncherFunction | 155 class WebstorePrivateEnableAppLauncherFunction |
162 : public ChromeSyncExtensionFunction { | 156 : public UIThreadExtensionFunction { |
163 public: | 157 public: |
164 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", | 158 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", |
165 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) | 159 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) |
166 | 160 |
167 WebstorePrivateEnableAppLauncherFunction(); | 161 WebstorePrivateEnableAppLauncherFunction(); |
168 | 162 |
169 protected: | 163 private: |
170 ~WebstorePrivateEnableAppLauncherFunction() override; | 164 ~WebstorePrivateEnableAppLauncherFunction() override; |
171 | 165 |
172 // ExtensionFunction: | 166 // ExtensionFunction: |
173 bool RunSync() override; | 167 ExtensionFunction::ResponseAction Run() override; |
| 168 |
| 169 ChromeExtensionFunctionDetails chrome_details_; |
174 }; | 170 }; |
175 | 171 |
176 class WebstorePrivateGetBrowserLoginFunction | 172 class WebstorePrivateGetBrowserLoginFunction |
177 : public ChromeSyncExtensionFunction { | 173 : public UIThreadExtensionFunction { |
178 public: | 174 public: |
179 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin", | 175 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin", |
180 WEBSTOREPRIVATE_GETBROWSERLOGIN) | 176 WEBSTOREPRIVATE_GETBROWSERLOGIN) |
181 | 177 |
182 protected: | 178 WebstorePrivateGetBrowserLoginFunction(); |
183 ~WebstorePrivateGetBrowserLoginFunction() override {} | 179 |
| 180 private: |
| 181 ~WebstorePrivateGetBrowserLoginFunction() override; |
184 | 182 |
185 // ExtensionFunction: | 183 // ExtensionFunction: |
186 bool RunSync() override; | 184 ExtensionFunction::ResponseAction Run() override; |
| 185 |
| 186 ChromeExtensionFunctionDetails chrome_details_; |
187 }; | 187 }; |
188 | 188 |
189 class WebstorePrivateGetStoreLoginFunction | 189 class WebstorePrivateGetStoreLoginFunction |
190 : public ChromeSyncExtensionFunction { | 190 : public UIThreadExtensionFunction { |
191 public: | 191 public: |
192 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin", | 192 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin", |
193 WEBSTOREPRIVATE_GETSTORELOGIN) | 193 WEBSTOREPRIVATE_GETSTORELOGIN) |
194 | 194 |
195 protected: | 195 WebstorePrivateGetStoreLoginFunction(); |
196 ~WebstorePrivateGetStoreLoginFunction() override {} | 196 |
| 197 private: |
| 198 ~WebstorePrivateGetStoreLoginFunction() override; |
197 | 199 |
198 // ExtensionFunction: | 200 // ExtensionFunction: |
199 bool RunSync() override; | 201 ExtensionFunction::ResponseAction Run() override; |
| 202 |
| 203 ChromeExtensionFunctionDetails chrome_details_; |
200 }; | 204 }; |
201 | 205 |
202 class WebstorePrivateSetStoreLoginFunction | 206 class WebstorePrivateSetStoreLoginFunction |
203 : public ChromeSyncExtensionFunction { | 207 : public UIThreadExtensionFunction { |
204 public: | 208 public: |
205 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin", | 209 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin", |
206 WEBSTOREPRIVATE_SETSTORELOGIN) | 210 WEBSTOREPRIVATE_SETSTORELOGIN) |
207 | 211 |
208 protected: | 212 WebstorePrivateSetStoreLoginFunction(); |
209 ~WebstorePrivateSetStoreLoginFunction() override {} | 213 |
| 214 private: |
| 215 ~WebstorePrivateSetStoreLoginFunction() override; |
210 | 216 |
211 // ExtensionFunction: | 217 // ExtensionFunction: |
212 bool RunSync() override; | 218 ExtensionFunction::ResponseAction Run() override; |
| 219 |
| 220 ChromeExtensionFunctionDetails chrome_details_; |
213 }; | 221 }; |
214 | 222 |
215 class WebstorePrivateGetWebGLStatusFunction | 223 class WebstorePrivateGetWebGLStatusFunction |
216 : public ChromeAsyncExtensionFunction { | 224 : public UIThreadExtensionFunction { |
217 public: | 225 public: |
218 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus", | 226 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus", |
219 WEBSTOREPRIVATE_GETWEBGLSTATUS) | 227 WEBSTOREPRIVATE_GETWEBGLSTATUS) |
220 | 228 |
221 WebstorePrivateGetWebGLStatusFunction(); | 229 WebstorePrivateGetWebGLStatusFunction(); |
222 | 230 |
223 protected: | 231 private: |
224 ~WebstorePrivateGetWebGLStatusFunction() override; | 232 ~WebstorePrivateGetWebGLStatusFunction() override; |
225 | 233 |
| 234 // ExtensionFunction: |
| 235 ExtensionFunction::ResponseAction Run() override; |
| 236 |
226 void OnFeatureCheck(bool feature_allowed); | 237 void OnFeatureCheck(bool feature_allowed); |
227 | 238 |
228 // ExtensionFunction: | |
229 bool RunAsync() override; | |
230 | |
231 private: | |
232 void CreateResult(bool webgl_allowed); | |
233 | |
234 scoped_refptr<GPUFeatureChecker> feature_checker_; | 239 scoped_refptr<GPUFeatureChecker> feature_checker_; |
235 }; | 240 }; |
236 | 241 |
237 class WebstorePrivateGetIsLauncherEnabledFunction | 242 class WebstorePrivateGetIsLauncherEnabledFunction |
238 : public ChromeSyncExtensionFunction { | 243 : public UIThreadExtensionFunction { |
239 public: | 244 public: |
240 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled", | 245 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled", |
241 WEBSTOREPRIVATE_GETISLAUNCHERENABLED) | 246 WEBSTOREPRIVATE_GETISLAUNCHERENABLED) |
242 | 247 |
243 WebstorePrivateGetIsLauncherEnabledFunction() {} | 248 WebstorePrivateGetIsLauncherEnabledFunction(); |
244 | 249 |
245 protected: | 250 private: |
246 ~WebstorePrivateGetIsLauncherEnabledFunction() override {} | 251 ~WebstorePrivateGetIsLauncherEnabledFunction() override; |
247 | 252 |
248 // ExtensionFunction: | 253 // ExtensionFunction: |
249 bool RunSync() override; | 254 ExtensionFunction::ResponseAction Run() override; |
250 | 255 |
251 private: | |
252 void OnIsLauncherCheckCompleted(bool is_enabled); | 256 void OnIsLauncherCheckCompleted(bool is_enabled); |
253 }; | 257 }; |
254 | 258 |
255 class WebstorePrivateIsInIncognitoModeFunction | 259 class WebstorePrivateIsInIncognitoModeFunction |
256 : public ChromeSyncExtensionFunction { | 260 : public UIThreadExtensionFunction { |
257 public: | 261 public: |
258 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode", | 262 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode", |
259 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION) | 263 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION) |
260 | 264 |
261 WebstorePrivateIsInIncognitoModeFunction() {} | 265 WebstorePrivateIsInIncognitoModeFunction(); |
262 | 266 |
263 protected: | 267 private: |
264 ~WebstorePrivateIsInIncognitoModeFunction() override {} | 268 ~WebstorePrivateIsInIncognitoModeFunction() override; |
265 | 269 |
266 // ExtensionFunction: | 270 // ExtensionFunction: |
267 bool RunSync() override; | 271 ExtensionFunction::ResponseAction Run() override; |
| 272 |
| 273 ChromeExtensionFunctionDetails chrome_details_; |
268 }; | 274 }; |
269 | 275 |
270 class WebstorePrivateLaunchEphemeralAppFunction | 276 class WebstorePrivateLaunchEphemeralAppFunction |
271 : public ChromeAsyncExtensionFunction { | 277 : public UIThreadExtensionFunction { |
272 public: | 278 public: |
273 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp", | 279 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp", |
274 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP) | 280 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP) |
275 | 281 |
276 WebstorePrivateLaunchEphemeralAppFunction(); | 282 WebstorePrivateLaunchEphemeralAppFunction(); |
277 | 283 |
278 protected: | 284 private: |
279 ~WebstorePrivateLaunchEphemeralAppFunction() override; | 285 ~WebstorePrivateLaunchEphemeralAppFunction() override; |
280 | 286 |
281 // ExtensionFunction: | 287 // ExtensionFunction: |
282 bool RunAsync() override; | 288 ExtensionFunction::ResponseAction Run() override; |
283 | 289 |
284 private: | |
285 void OnLaunchComplete(webstore_install::Result result, | 290 void OnLaunchComplete(webstore_install::Result result, |
286 const std::string& error); | 291 const std::string& error); |
287 void SetResult( | 292 |
| 293 ExtensionFunction::ResponseValue BuildResponse( |
288 api::webstore_private::LaunchEphemeralApp::Results::Result result, | 294 api::webstore_private::LaunchEphemeralApp::Results::Result result, |
289 const std::string& error); | 295 const std::string& error); |
| 296 |
| 297 ChromeExtensionFunctionDetails chrome_details_; |
290 }; | 298 }; |
291 | 299 |
292 class WebstorePrivateGetEphemeralAppsEnabledFunction | 300 class WebstorePrivateGetEphemeralAppsEnabledFunction |
293 : public ChromeSyncExtensionFunction { | 301 : public UIThreadExtensionFunction { |
294 public: | 302 public: |
295 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled", | 303 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled", |
296 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED) | 304 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED) |
297 | 305 |
298 WebstorePrivateGetEphemeralAppsEnabledFunction(); | 306 WebstorePrivateGetEphemeralAppsEnabledFunction(); |
299 | 307 |
300 protected: | 308 private: |
301 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; | 309 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; |
302 | 310 |
303 // ExtensionFunction: | 311 // ExtensionFunction: |
304 bool RunSync() override; | 312 ExtensionFunction::ResponseAction Run() override; |
305 }; | 313 }; |
306 | 314 |
307 } // namespace extensions | 315 } // namespace extensions |
308 | 316 |
309 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H
_ | 317 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H
_ |
OLD | NEW |