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/bundle_installer.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/browser/signin/signin_tracker.h"
16 #include "chrome/common/extensions/api/webstore_private.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 WebstorePrivateInstallBundleFunction
47 : public ChromeAsyncExtensionFunction,
48 public extensions::BundleInstaller::Delegate {
50 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
51 WEBSTOREPRIVATE_INSTALLBUNDLE)
53 WebstorePrivateInstallBundleFunction();
55 // BundleInstaller::Delegate:
56 virtual void OnBundleInstallApproved() OVERRIDE;
57 virtual void OnBundleInstallCanceled(bool user_initiated) OVERRIDE;
58 virtual void OnBundleInstallCompleted() OVERRIDE;
61 virtual ~WebstorePrivateInstallBundleFunction();
64 virtual bool RunImpl() OVERRIDE;
66 // Reads the extension |details| into |items|.
68 const api::webstore_private::InstallBundle::Params& details,
69 extensions::BundleInstaller::ItemList* items);
72 scoped_refptr<extensions::BundleInstaller> bundle_;
75 class WebstorePrivateBeginInstallWithManifest3Function
76 : public ChromeAsyncExtensionFunction,
77 public ExtensionInstallPrompt::Delegate,
78 public WebstoreInstallHelper::Delegate,
79 public SigninTracker::Observer {
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 // Signin has failed.
114 // An extension with the same extension id has already been installed.
118 WebstorePrivateBeginInstallWithManifest3Function();
120 // WebstoreInstallHelper::Delegate:
121 virtual void OnWebstoreParseSuccess(
122 const std::string& id,
123 const SkBitmap& icon,
124 base::DictionaryValue* parsed_manifest) OVERRIDE;
125 virtual void OnWebstoreParseFailure(
126 const std::string& id,
127 InstallHelperResultCode result_code,
128 const std::string& error_message) OVERRIDE;
130 // ExtensionInstallPrompt::Delegate:
131 virtual void InstallUIProceed() OVERRIDE;
132 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
135 virtual ~WebstorePrivateBeginInstallWithManifest3Function();
137 // ExtensionFunction:
138 virtual bool RunImpl() OVERRIDE;
140 // Sets the result_ as a string based on |code|.
141 void SetResultCode(ResultCode code);
144 // SigninTracker::Observer override.
145 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE;
146 virtual void SigninSuccess() OVERRIDE;
148 // Called when signin is complete or not needed.
149 void SigninCompletedOrNotNeeded();
151 const char* ResultCodeToString(ResultCode code);
153 // These store the input parameters to the function.
154 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
156 // The results of parsing manifest_ and icon_data_ go into these two.
157 scoped_ptr<base::DictionaryValue> parsed_manifest_;
160 // A dummy Extension object we create for the purposes of using
161 // ExtensionInstallPrompt to prompt for confirmation of the install.
162 scoped_refptr<extensions::Extension> dummy_extension_;
164 // The class that displays the install prompt.
165 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
167 scoped_ptr<SigninTracker> signin_tracker_;
170 class WebstorePrivateCompleteInstallFunction
171 : public ChromeAsyncExtensionFunction,
172 public WebstoreInstaller::Delegate {
174 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
175 WEBSTOREPRIVATE_COMPLETEINSTALL)
177 WebstorePrivateCompleteInstallFunction();
179 // WebstoreInstaller::Delegate:
180 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
181 virtual void OnExtensionInstallFailure(
182 const std::string& id,
183 const std::string& error,
184 WebstoreInstaller::FailureReason reason) OVERRIDE;
187 virtual ~WebstorePrivateCompleteInstallFunction();
189 // ExtensionFunction:
190 virtual bool RunImpl() OVERRIDE;
193 scoped_ptr<WebstoreInstaller::Approval> approval_;
196 class WebstorePrivateEnableAppLauncherFunction
197 : public ChromeSyncExtensionFunction {
199 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
200 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
202 WebstorePrivateEnableAppLauncherFunction();
205 virtual ~WebstorePrivateEnableAppLauncherFunction();
207 // ExtensionFunction:
208 virtual bool RunImpl() OVERRIDE;
211 class WebstorePrivateGetBrowserLoginFunction
212 : public ChromeSyncExtensionFunction {
214 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
215 WEBSTOREPRIVATE_GETBROWSERLOGIN)
218 virtual ~WebstorePrivateGetBrowserLoginFunction() {}
220 // ExtensionFunction:
221 virtual bool RunImpl() OVERRIDE;
224 class WebstorePrivateGetStoreLoginFunction
225 : public ChromeSyncExtensionFunction {
227 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
228 WEBSTOREPRIVATE_GETSTORELOGIN)
231 virtual ~WebstorePrivateGetStoreLoginFunction() {}
233 // ExtensionFunction:
234 virtual bool RunImpl() OVERRIDE;
237 class WebstorePrivateSetStoreLoginFunction
238 : public ChromeSyncExtensionFunction {
240 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
241 WEBSTOREPRIVATE_SETSTORELOGIN)
244 virtual ~WebstorePrivateSetStoreLoginFunction() {}
246 // ExtensionFunction:
247 virtual bool RunImpl() OVERRIDE;
250 class WebstorePrivateGetWebGLStatusFunction
251 : public ChromeAsyncExtensionFunction {
253 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
254 WEBSTOREPRIVATE_GETWEBGLSTATUS)
256 WebstorePrivateGetWebGLStatusFunction();
259 virtual ~WebstorePrivateGetWebGLStatusFunction();
261 void OnFeatureCheck(bool feature_allowed);
263 // ExtensionFunction:
264 virtual bool RunImpl() OVERRIDE;
267 void CreateResult(bool webgl_allowed);
269 scoped_refptr<GPUFeatureChecker> feature_checker_;
272 class WebstorePrivateGetIsLauncherEnabledFunction
273 : public ChromeSyncExtensionFunction {
275 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
276 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
278 WebstorePrivateGetIsLauncherEnabledFunction() {}
281 virtual ~WebstorePrivateGetIsLauncherEnabledFunction() {}
283 // ExtensionFunction:
284 virtual bool RunImpl() OVERRIDE;
287 void OnIsLauncherCheckCompleted(bool is_enabled);
290 class WebstorePrivateIsInIncognitoModeFunction
291 : public ChromeSyncExtensionFunction {
293 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
294 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
296 WebstorePrivateIsInIncognitoModeFunction() {}
299 virtual ~WebstorePrivateIsInIncognitoModeFunction() {}
301 // ExtensionFunction:
302 virtual bool RunImpl() OVERRIDE;
305 } // namespace extensions
307 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_