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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
10 #include "chrome/browser/extensions/active_install_data.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/browser/extensions/extension_install_prompt.h"
13 #include "chrome/browser/extensions/webstore_install_helper.h"
14 #include "chrome/browser/extensions/webstore_installer.h"
15 #include "chrome/common/extensions/api/webstore_private.h"
16 #include "chrome/common/extensions/webstore_install_result.h"
17 #include "content/public/browser/gpu_data_manager_observer.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"
23 class ProfileSyncService;
29 class GPUFeatureChecker;
31 namespace extensions {
33 class WebstorePrivateApi {
35 // Allows you to override the WebstoreInstaller delegate for testing.
36 static void SetWebstoreInstallerDelegateForTesting(
37 WebstoreInstaller::Delegate* delegate);
39 // Gets the pending approval for the |extension_id| in |profile|. Pending
40 // approvals are held between the calls to beginInstallWithManifest and
41 // completeInstall. This should only be used for testing.
42 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
43 Profile* profile, const std::string& extension_id);
46 class WebstorePrivateBeginInstallWithManifest3Function
47 : public ChromeAsyncExtensionFunction,
48 public ExtensionInstallPrompt::Delegate,
49 public WebstoreInstallHelper::Delegate {
51 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
52 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
54 // Result codes for the return value. If you change this, make sure to
55 // update the description for the beginInstallWithManifest3 callback in
56 // the extension API JSON.
60 // An unspecified error occurred.
63 // The user cancelled the confirmation dialog instead of accepting it.
66 // The manifest failed to parse correctly.
69 // There was a problem parsing the base64 encoded icon data.
72 // The extension id was invalid.
75 // The page does not have permission to call this function.
81 // An extension with the same extension id has already been installed.
85 WebstorePrivateBeginInstallWithManifest3Function();
87 // WebstoreInstallHelper::Delegate:
88 void OnWebstoreParseSuccess(const std::string& id,
90 base::DictionaryValue* parsed_manifest) override;
91 void OnWebstoreParseFailure(const std::string& id,
92 InstallHelperResultCode result_code,
93 const std::string& error_message) override;
95 // ExtensionInstallPrompt::Delegate:
96 void InstallUIProceed() override;
97 void InstallUIAbort(bool user_initiated) override;
100 ~WebstorePrivateBeginInstallWithManifest3Function() override;
102 // ExtensionFunction:
103 bool RunAsync() override;
105 // Sets the result_ as a string based on |code|.
106 void SetResultCode(ResultCode code);
109 const char* ResultCodeToString(ResultCode code);
111 // These store the input parameters to the function.
112 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
114 // The results of parsing manifest_ and icon_data_ go into these two.
115 scoped_ptr<base::DictionaryValue> parsed_manifest_;
118 // A dummy Extension object we create for the purposes of using
119 // ExtensionInstallPrompt to prompt for confirmation of the install.
120 scoped_refptr<extensions::Extension> dummy_extension_;
122 // The class that displays the install prompt.
123 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
125 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
127 // 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.
129 std::string authuser_;
132 class WebstorePrivateCompleteInstallFunction
133 : public ChromeAsyncExtensionFunction,
134 public WebstoreInstaller::Delegate {
136 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
137 WEBSTOREPRIVATE_COMPLETEINSTALL)
139 WebstorePrivateCompleteInstallFunction();
141 // WebstoreInstaller::Delegate:
142 void OnExtensionInstallSuccess(const std::string& id) override;
143 void OnExtensionInstallFailure(
144 const std::string& id,
145 const std::string& error,
146 WebstoreInstaller::FailureReason reason) override;
149 ~WebstorePrivateCompleteInstallFunction() override;
151 // ExtensionFunction:
152 bool RunAsync() override;
155 scoped_ptr<WebstoreInstaller::Approval> approval_;
156 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
158 void OnInstallSuccess(const std::string& id);
161 class WebstorePrivateEnableAppLauncherFunction
162 : public ChromeSyncExtensionFunction {
164 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
165 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
167 WebstorePrivateEnableAppLauncherFunction();
170 ~WebstorePrivateEnableAppLauncherFunction() override;
172 // ExtensionFunction:
173 bool RunSync() override;
176 class WebstorePrivateGetBrowserLoginFunction
177 : public ChromeSyncExtensionFunction {
179 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
180 WEBSTOREPRIVATE_GETBROWSERLOGIN)
183 ~WebstorePrivateGetBrowserLoginFunction() override {}
185 // ExtensionFunction:
186 bool RunSync() override;
189 class WebstorePrivateGetStoreLoginFunction
190 : public ChromeSyncExtensionFunction {
192 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
193 WEBSTOREPRIVATE_GETSTORELOGIN)
196 ~WebstorePrivateGetStoreLoginFunction() override {}
198 // ExtensionFunction:
199 bool RunSync() override;
202 class WebstorePrivateSetStoreLoginFunction
203 : public ChromeSyncExtensionFunction {
205 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
206 WEBSTOREPRIVATE_SETSTORELOGIN)
209 ~WebstorePrivateSetStoreLoginFunction() override {}
211 // ExtensionFunction:
212 bool RunSync() override;
215 class WebstorePrivateGetWebGLStatusFunction
216 : public ChromeAsyncExtensionFunction {
218 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
219 WEBSTOREPRIVATE_GETWEBGLSTATUS)
221 WebstorePrivateGetWebGLStatusFunction();
224 ~WebstorePrivateGetWebGLStatusFunction() override;
226 void OnFeatureCheck(bool feature_allowed);
228 // ExtensionFunction:
229 bool RunAsync() override;
232 void CreateResult(bool webgl_allowed);
234 scoped_refptr<GPUFeatureChecker> feature_checker_;
237 class WebstorePrivateGetIsLauncherEnabledFunction
238 : public ChromeSyncExtensionFunction {
240 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
241 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
243 WebstorePrivateGetIsLauncherEnabledFunction() {}
246 ~WebstorePrivateGetIsLauncherEnabledFunction() override {}
248 // ExtensionFunction:
249 bool RunSync() override;
252 void OnIsLauncherCheckCompleted(bool is_enabled);
255 class WebstorePrivateIsInIncognitoModeFunction
256 : public ChromeSyncExtensionFunction {
258 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
259 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
261 WebstorePrivateIsInIncognitoModeFunction() {}
264 ~WebstorePrivateIsInIncognitoModeFunction() override {}
266 // ExtensionFunction:
267 bool RunSync() override;
270 class WebstorePrivateLaunchEphemeralAppFunction
271 : public ChromeAsyncExtensionFunction {
273 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp",
274 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP)
276 WebstorePrivateLaunchEphemeralAppFunction();
279 ~WebstorePrivateLaunchEphemeralAppFunction() override;
281 // ExtensionFunction:
282 bool RunAsync() override;
285 void OnLaunchComplete(webstore_install::Result result,
286 const std::string& error);
288 api::webstore_private::LaunchEphemeralApp::Results::Result result,
289 const std::string& error);
292 class WebstorePrivateGetEphemeralAppsEnabledFunction
293 : public ChromeSyncExtensionFunction {
295 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled",
296 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED)
298 WebstorePrivateGetEphemeralAppsEnabledFunction();
301 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override;
303 // ExtensionFunction:
304 bool RunSync() override;
307 } // namespace extensions
309 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_