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_manager_factory.h"
16 #include "chrome/common/extensions/api/webstore_private.h"
17 #include "components/signin/core/browser/signin_tracker.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;
25 class SigninManagerBase;
31 class GPUFeatureChecker;
33 namespace extensions {
35 class WebstorePrivateApi {
37 // Allows you to override the WebstoreInstaller delegate for testing.
38 static void SetWebstoreInstallerDelegateForTesting(
39 WebstoreInstaller::Delegate* delegate);
41 // Gets the pending approval for the |extension_id| in |profile|. Pending
42 // approvals are held between the calls to beginInstallWithManifest and
43 // completeInstall. This should only be used for testing.
44 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
45 Profile* profile, const std::string& extension_id);
48 class WebstorePrivateInstallBundleFunction
49 : public ChromeAsyncExtensionFunction,
50 public extensions::BundleInstaller::Delegate {
52 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
53 WEBSTOREPRIVATE_INSTALLBUNDLE)
55 WebstorePrivateInstallBundleFunction();
57 // BundleInstaller::Delegate:
58 virtual void OnBundleInstallApproved() OVERRIDE;
59 virtual void OnBundleInstallCanceled(bool user_initiated) OVERRIDE;
60 virtual void OnBundleInstallCompleted() OVERRIDE;
63 virtual ~WebstorePrivateInstallBundleFunction();
66 virtual bool RunAsync() OVERRIDE;
68 // Reads the extension |details| into |items|.
70 const api::webstore_private::InstallBundle::Params& details,
71 extensions::BundleInstaller::ItemList* items);
74 scoped_refptr<extensions::BundleInstaller> bundle_;
77 class WebstorePrivateBeginInstallWithManifest3Function
78 : public ChromeAsyncExtensionFunction,
79 public ExtensionInstallPrompt::Delegate,
80 public WebstoreInstallHelper::Delegate,
81 public SigninTracker::Observer {
83 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
84 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
86 // Result codes for the return value. If you change this, make sure to
87 // update the description for the beginInstallWithManifest3 callback in
88 // the extension API JSON.
92 // An unspecified error occurred.
95 // The user cancelled the confirmation dialog instead of accepting it.
98 // The manifest failed to parse correctly.
101 // There was a problem parsing the base64 encoded icon data.
104 // The extension id was invalid.
107 // The page does not have permission to call this function.
113 // Signin has failed.
116 // An extension with the same extension id has already been installed.
120 WebstorePrivateBeginInstallWithManifest3Function();
122 // WebstoreInstallHelper::Delegate:
123 virtual void OnWebstoreParseSuccess(
124 const std::string& id,
125 const SkBitmap& icon,
126 base::DictionaryValue* parsed_manifest) OVERRIDE;
127 virtual void OnWebstoreParseFailure(
128 const std::string& id,
129 InstallHelperResultCode result_code,
130 const std::string& error_message) OVERRIDE;
132 // ExtensionInstallPrompt::Delegate:
133 virtual void InstallUIProceed() OVERRIDE;
134 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
137 virtual ~WebstorePrivateBeginInstallWithManifest3Function();
139 // ExtensionFunction:
140 virtual bool RunAsync() OVERRIDE;
142 // Sets the result_ as a string based on |code|.
143 void SetResultCode(ResultCode code);
146 // SigninTracker::Observer override.
147 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE;
148 virtual void SigninSuccess() OVERRIDE;
149 virtual void MergeSessionComplete(
150 const GoogleServiceAuthError& error) OVERRIDE;
152 // Called when signin is complete or not needed.
153 void SigninCompletedOrNotNeeded();
155 const char* ResultCodeToString(ResultCode code);
157 // These store the input parameters to the function.
158 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
160 // The results of parsing manifest_ and icon_data_ go into these two.
161 scoped_ptr<base::DictionaryValue> parsed_manifest_;
164 // A dummy Extension object we create for the purposes of using
165 // ExtensionInstallPrompt to prompt for confirmation of the install.
166 scoped_refptr<extensions::Extension> dummy_extension_;
168 // The class that displays the install prompt.
169 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
171 scoped_ptr<SigninTracker> signin_tracker_;
173 // The authuser query parameter value which should be used with CRX download
174 // requests. This is empty if authuser should not be set on download requests.
175 std::string authuser_;
178 class WebstorePrivateCompleteInstallFunction
179 : public ChromeAsyncExtensionFunction,
180 public WebstoreInstaller::Delegate {
182 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
183 WEBSTOREPRIVATE_COMPLETEINSTALL)
185 WebstorePrivateCompleteInstallFunction();
187 // WebstoreInstaller::Delegate:
188 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
189 virtual void OnExtensionInstallFailure(
190 const std::string& id,
191 const std::string& error,
192 WebstoreInstaller::FailureReason reason) OVERRIDE;
195 virtual ~WebstorePrivateCompleteInstallFunction();
197 // ExtensionFunction:
198 virtual bool RunAsync() OVERRIDE;
201 scoped_ptr<WebstoreInstaller::Approval> approval_;
204 class WebstorePrivateEnableAppLauncherFunction
205 : public ChromeSyncExtensionFunction {
207 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
208 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
210 WebstorePrivateEnableAppLauncherFunction();
213 virtual ~WebstorePrivateEnableAppLauncherFunction();
215 // ExtensionFunction:
216 virtual bool RunSync() OVERRIDE;
219 class WebstorePrivateGetBrowserLoginFunction
220 : public ChromeSyncExtensionFunction {
222 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
223 WEBSTOREPRIVATE_GETBROWSERLOGIN)
226 virtual ~WebstorePrivateGetBrowserLoginFunction() {}
228 // ExtensionFunction:
229 virtual bool RunSync() OVERRIDE;
232 class WebstorePrivateGetStoreLoginFunction
233 : public ChromeSyncExtensionFunction {
235 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
236 WEBSTOREPRIVATE_GETSTORELOGIN)
239 virtual ~WebstorePrivateGetStoreLoginFunction() {}
241 // ExtensionFunction:
242 virtual bool RunSync() OVERRIDE;
245 class WebstorePrivateSetStoreLoginFunction
246 : public ChromeSyncExtensionFunction {
248 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
249 WEBSTOREPRIVATE_SETSTORELOGIN)
252 virtual ~WebstorePrivateSetStoreLoginFunction() {}
254 // ExtensionFunction:
255 virtual bool RunSync() OVERRIDE;
258 class WebstorePrivateGetWebGLStatusFunction
259 : public ChromeAsyncExtensionFunction {
261 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
262 WEBSTOREPRIVATE_GETWEBGLSTATUS)
264 WebstorePrivateGetWebGLStatusFunction();
267 virtual ~WebstorePrivateGetWebGLStatusFunction();
269 void OnFeatureCheck(bool feature_allowed);
271 // ExtensionFunction:
272 virtual bool RunAsync() OVERRIDE;
275 void CreateResult(bool webgl_allowed);
277 scoped_refptr<GPUFeatureChecker> feature_checker_;
280 class WebstorePrivateGetIsLauncherEnabledFunction
281 : public ChromeSyncExtensionFunction {
283 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
284 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
286 WebstorePrivateGetIsLauncherEnabledFunction() {}
289 virtual ~WebstorePrivateGetIsLauncherEnabledFunction() {}
291 // ExtensionFunction:
292 virtual bool RunSync() OVERRIDE;
295 void OnIsLauncherCheckCompleted(bool is_enabled);
298 class WebstorePrivateIsInIncognitoModeFunction
299 : public ChromeSyncExtensionFunction {
301 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
302 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
304 WebstorePrivateIsInIncognitoModeFunction() {}
307 virtual ~WebstorePrivateIsInIncognitoModeFunction() {}
309 // ExtensionFunction:
310 virtual bool RunSync() OVERRIDE;
313 class WebstorePrivateSignInFunction : public ChromeAsyncExtensionFunction,
314 public SigninManagerFactory::Observer,
315 public SigninTracker::Observer {
317 DECLARE_EXTENSION_FUNCTION("webstorePrivate.signIn",
318 WEBSTOREPRIVATE_SIGNINFUNCTION)
320 WebstorePrivateSignInFunction();
323 virtual ~WebstorePrivateSignInFunction();
325 // ExtensionFunction:
326 virtual bool RunAsync() OVERRIDE;
328 // SigninManagerFactory::Observer:
329 virtual void SigninManagerShutdown(SigninManagerBase* manager) OVERRIDE;
331 // SigninTracker::Observer:
332 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE;
333 virtual void SigninSuccess() OVERRIDE;
334 virtual void MergeSessionComplete(const GoogleServiceAuthError& error)
338 // The sign-in manager for the invoking tab's Chrome Profile. Weak reference.
339 SigninManagerBase* signin_manager_;
341 // Tracks changes to sign-in state. Used to notify the page when an existing
342 // in-progress sign-in completes, either with success or failure.
343 scoped_ptr<SigninTracker> signin_tracker_;
346 } // namespace extensions
348 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_