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/bundle_installer.h"
12 #include "chrome/browser/extensions/chrome_extension_function.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/webstore_install_helper.h"
15 #include "chrome/browser/extensions/webstore_installer.h"
16 #include "chrome/common/extensions/api/webstore_private.h"
17 #include "chrome/common/extensions/webstore_install_result.h"
18 #include "content/public/browser/gpu_data_manager_observer.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "google_apis/gaia/google_service_auth_error.h"
22 #include "third_party/skia/include/core/SkBitmap.h"
24 class ProfileSyncService;
30 class GPUFeatureChecker;
32 namespace extensions {
34 class WebstorePrivateApi {
36 // Allows you to override the WebstoreInstaller delegate for testing.
37 static void SetWebstoreInstallerDelegateForTesting(
38 WebstoreInstaller::Delegate* delegate);
40 // Gets the pending approval for the |extension_id| in |profile|. Pending
41 // approvals are held between the calls to beginInstallWithManifest and
42 // completeInstall. This should only be used for testing.
43 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
44 Profile* profile, const std::string& extension_id);
47 class WebstorePrivateInstallBundleFunction
48 : public ChromeAsyncExtensionFunction,
49 public extensions::BundleInstaller::Delegate {
51 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
52 WEBSTOREPRIVATE_INSTALLBUNDLE)
54 WebstorePrivateInstallBundleFunction();
56 // BundleInstaller::Delegate:
57 virtual void OnBundleInstallApproved() OVERRIDE;
58 virtual void OnBundleInstallCanceled(bool user_initiated) OVERRIDE;
59 virtual void OnBundleInstallCompleted() OVERRIDE;
62 virtual ~WebstorePrivateInstallBundleFunction();
65 virtual bool RunAsync() OVERRIDE;
67 // Reads the extension |details| into |items|.
69 const api::webstore_private::InstallBundle::Params& details,
70 extensions::BundleInstaller::ItemList* items);
73 scoped_refptr<extensions::BundleInstaller> bundle_;
76 class WebstorePrivateBeginInstallWithManifest3Function
77 : public ChromeAsyncExtensionFunction,
78 public ExtensionInstallPrompt::Delegate,
79 public WebstoreInstallHelper::Delegate {
81 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
82 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
84 // Result codes for the return value. If you change this, make sure to
85 // update the description for the beginInstallWithManifest3 callback in
86 // the extension API JSON.
90 // An unspecified error occurred.
93 // The user cancelled the confirmation dialog instead of accepting it.
96 // The manifest failed to parse correctly.
99 // There was a problem parsing the base64 encoded icon data.
102 // The extension id was invalid.
105 // The page does not have permission to call this function.
111 // An extension with the same extension id has already been installed.
115 WebstorePrivateBeginInstallWithManifest3Function();
117 // WebstoreInstallHelper::Delegate:
118 virtual void OnWebstoreParseSuccess(
119 const std::string& id,
120 const SkBitmap& icon,
121 base::DictionaryValue* parsed_manifest) OVERRIDE;
122 virtual void OnWebstoreParseFailure(
123 const std::string& id,
124 InstallHelperResultCode result_code,
125 const std::string& error_message) OVERRIDE;
127 // ExtensionInstallPrompt::Delegate:
128 virtual void InstallUIProceed() OVERRIDE;
129 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
132 virtual ~WebstorePrivateBeginInstallWithManifest3Function();
134 // ExtensionFunction:
135 virtual bool RunAsync() OVERRIDE;
137 // Sets the result_ as a string based on |code|.
138 void SetResultCode(ResultCode code);
141 const char* ResultCodeToString(ResultCode code);
143 // These store the input parameters to the function.
144 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
146 // The results of parsing manifest_ and icon_data_ go into these two.
147 scoped_ptr<base::DictionaryValue> parsed_manifest_;
150 // A dummy Extension object we create for the purposes of using
151 // ExtensionInstallPrompt to prompt for confirmation of the install.
152 scoped_refptr<extensions::Extension> dummy_extension_;
154 // The class that displays the install prompt.
155 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
157 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
159 // The authuser query parameter value which should be used with CRX download
160 // requests. This is empty if authuser should not be set on download requests.
161 std::string authuser_;
164 class WebstorePrivateCompleteInstallFunction
165 : public ChromeAsyncExtensionFunction,
166 public WebstoreInstaller::Delegate {
168 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
169 WEBSTOREPRIVATE_COMPLETEINSTALL)
171 WebstorePrivateCompleteInstallFunction();
173 // WebstoreInstaller::Delegate:
174 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
175 virtual void OnExtensionInstallFailure(
176 const std::string& id,
177 const std::string& error,
178 WebstoreInstaller::FailureReason reason) OVERRIDE;
181 virtual ~WebstorePrivateCompleteInstallFunction();
183 // ExtensionFunction:
184 virtual bool RunAsync() OVERRIDE;
187 scoped_ptr<WebstoreInstaller::Approval> approval_;
188 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
190 void OnInstallSuccess(const std::string& id);
193 class WebstorePrivateEnableAppLauncherFunction
194 : public ChromeSyncExtensionFunction {
196 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
197 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
199 WebstorePrivateEnableAppLauncherFunction();
202 virtual ~WebstorePrivateEnableAppLauncherFunction();
204 // ExtensionFunction:
205 virtual bool RunSync() OVERRIDE;
208 class WebstorePrivateGetBrowserLoginFunction
209 : public ChromeSyncExtensionFunction {
211 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
212 WEBSTOREPRIVATE_GETBROWSERLOGIN)
215 virtual ~WebstorePrivateGetBrowserLoginFunction() {}
217 // ExtensionFunction:
218 virtual bool RunSync() OVERRIDE;
221 class WebstorePrivateGetStoreLoginFunction
222 : public ChromeSyncExtensionFunction {
224 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
225 WEBSTOREPRIVATE_GETSTORELOGIN)
228 virtual ~WebstorePrivateGetStoreLoginFunction() {}
230 // ExtensionFunction:
231 virtual bool RunSync() OVERRIDE;
234 class WebstorePrivateSetStoreLoginFunction
235 : public ChromeSyncExtensionFunction {
237 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
238 WEBSTOREPRIVATE_SETSTORELOGIN)
241 virtual ~WebstorePrivateSetStoreLoginFunction() {}
243 // ExtensionFunction:
244 virtual bool RunSync() OVERRIDE;
247 class WebstorePrivateGetWebGLStatusFunction
248 : public ChromeAsyncExtensionFunction {
250 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
251 WEBSTOREPRIVATE_GETWEBGLSTATUS)
253 WebstorePrivateGetWebGLStatusFunction();
256 virtual ~WebstorePrivateGetWebGLStatusFunction();
258 void OnFeatureCheck(bool feature_allowed);
260 // ExtensionFunction:
261 virtual bool RunAsync() OVERRIDE;
264 void CreateResult(bool webgl_allowed);
266 scoped_refptr<GPUFeatureChecker> feature_checker_;
269 class WebstorePrivateGetIsLauncherEnabledFunction
270 : public ChromeSyncExtensionFunction {
272 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
273 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
275 WebstorePrivateGetIsLauncherEnabledFunction() {}
278 virtual ~WebstorePrivateGetIsLauncherEnabledFunction() {}
280 // ExtensionFunction:
281 virtual bool RunSync() OVERRIDE;
284 void OnIsLauncherCheckCompleted(bool is_enabled);
287 class WebstorePrivateIsInIncognitoModeFunction
288 : public ChromeSyncExtensionFunction {
290 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
291 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
293 WebstorePrivateIsInIncognitoModeFunction() {}
296 virtual ~WebstorePrivateIsInIncognitoModeFunction() {}
298 // ExtensionFunction:
299 virtual bool RunSync() OVERRIDE;
302 class WebstorePrivateLaunchEphemeralAppFunction
303 : public ChromeAsyncExtensionFunction {
305 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp",
306 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP)
308 WebstorePrivateLaunchEphemeralAppFunction();
311 virtual ~WebstorePrivateLaunchEphemeralAppFunction();
313 // ExtensionFunction:
314 virtual bool RunAsync() OVERRIDE;
317 void OnLaunchComplete(webstore_install::Result result,
318 const std::string& error);
320 api::webstore_private::LaunchEphemeralApp::Results::Result result,
321 const std::string& error);
324 class WebstorePrivateGetEphemeralAppsEnabledFunction
325 : public ChromeSyncExtensionFunction {
327 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled",
328 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED)
330 WebstorePrivateGetEphemeralAppsEnabledFunction();
333 virtual ~WebstorePrivateGetEphemeralAppsEnabledFunction();
335 // ExtensionFunction:
336 virtual bool RunSync() OVERRIDE;
339 } // namespace extensions
341 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_