Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / webstore_private / webstore_private_api.h
blob457a18fffda5203c076e99f7eebcd7128e336fca
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_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
12 #include "chrome/browser/extensions/active_install_data.h"
13 #include "chrome/browser/extensions/bundle_installer.h"
14 #include "chrome/browser/extensions/chrome_extension_function_details.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/extensions/webstore_install_helper.h"
17 #include "chrome/browser/extensions/webstore_installer.h"
18 #include "chrome/common/extensions/api/webstore_private.h"
19 #include "chrome/common/extensions/webstore_install_result.h"
20 #include "extensions/browser/extension_function.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
23 class GPUFeatureChecker;
24 class GURL;
26 namespace chrome {
27 class BitmapFetcher;
28 } // namespace chrome
30 namespace extensions {
32 class Extension;
34 class WebstorePrivateApi {
35 public:
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 WebstorePrivateBeginInstallWithManifest3Function
48 : public UIThreadExtensionFunction,
49 public ExtensionInstallPrompt::Delegate,
50 public WebstoreInstallHelper::Delegate {
51 public:
52 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
53 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
55 WebstorePrivateBeginInstallWithManifest3Function();
57 private:
58 using Params = api::webstore_private::BeginInstallWithManifest3::Params;
60 ~WebstorePrivateBeginInstallWithManifest3Function() override;
62 // ExtensionFunction:
63 ExtensionFunction::ResponseAction Run() override;
65 // WebstoreInstallHelper::Delegate:
66 void OnWebstoreParseSuccess(const std::string& id,
67 const SkBitmap& icon,
68 base::DictionaryValue* parsed_manifest) override;
69 void OnWebstoreParseFailure(const std::string& id,
70 InstallHelperResultCode result,
71 const std::string& error_message) override;
73 // ExtensionInstallPrompt::Delegate:
74 void InstallUIProceed() override;
75 void InstallUIAbort(bool user_initiated) override;
77 ExtensionFunction::ResponseValue BuildResponse(
78 api::webstore_private::Result result,
79 const std::string& error);
80 scoped_ptr<base::ListValue> CreateResults(
81 api::webstore_private::Result result) const;
83 const Params::Details& details() const { return params_->details; }
85 ChromeExtensionFunctionDetails chrome_details_;
87 scoped_ptr<Params> params_;
89 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
91 scoped_ptr<base::DictionaryValue> parsed_manifest_;
92 SkBitmap icon_;
94 // A dummy Extension object we create for the purposes of using
95 // ExtensionInstallPrompt to prompt for confirmation of the install.
96 scoped_refptr<Extension> dummy_extension_;
98 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
101 class WebstorePrivateCompleteInstallFunction
102 : public UIThreadExtensionFunction,
103 public WebstoreInstaller::Delegate {
104 public:
105 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
106 WEBSTOREPRIVATE_COMPLETEINSTALL)
108 WebstorePrivateCompleteInstallFunction();
110 private:
111 ~WebstorePrivateCompleteInstallFunction() override;
113 // ExtensionFunction:
114 ExtensionFunction::ResponseAction Run() override;
116 // WebstoreInstaller::Delegate:
117 void OnExtensionInstallSuccess(const std::string& id) override;
118 void OnExtensionInstallFailure(
119 const std::string& id,
120 const std::string& error,
121 WebstoreInstaller::FailureReason reason) override;
123 void OnInstallSuccess(const std::string& id);
125 ChromeExtensionFunctionDetails chrome_details_;
127 scoped_ptr<WebstoreInstaller::Approval> approval_;
128 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
131 class WebstorePrivateInstallBundleFunction
132 : public UIThreadExtensionFunction,
133 public chrome::BitmapFetcherDelegate {
134 public:
135 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
136 WEBSTOREPRIVATE_INSTALLBUNDLE)
138 WebstorePrivateInstallBundleFunction();
140 private:
141 using Params = api::webstore_private::InstallBundle::Params;
143 ~WebstorePrivateInstallBundleFunction() override;
145 // ExtensionFunction:
146 ExtensionFunction::ResponseAction Run() override;
148 // chrome::BitmapFetcherDelegate:
149 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override;
151 void OnInstallApproval(BundleInstaller::ApprovalState state);
152 void OnInstallComplete();
154 const Params::Details& details() const { return params_->details; }
156 ChromeExtensionFunctionDetails chrome_details_;
158 scoped_ptr<Params> params_;
160 scoped_ptr<extensions::BundleInstaller> bundle_;
161 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
164 class WebstorePrivateEnableAppLauncherFunction
165 : public UIThreadExtensionFunction {
166 public:
167 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
168 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
170 WebstorePrivateEnableAppLauncherFunction();
172 private:
173 ~WebstorePrivateEnableAppLauncherFunction() override;
175 // ExtensionFunction:
176 ExtensionFunction::ResponseAction Run() override;
178 ChromeExtensionFunctionDetails chrome_details_;
181 class WebstorePrivateGetBrowserLoginFunction
182 : public UIThreadExtensionFunction {
183 public:
184 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
185 WEBSTOREPRIVATE_GETBROWSERLOGIN)
187 WebstorePrivateGetBrowserLoginFunction();
189 private:
190 ~WebstorePrivateGetBrowserLoginFunction() override;
192 // ExtensionFunction:
193 ExtensionFunction::ResponseAction Run() override;
195 ChromeExtensionFunctionDetails chrome_details_;
198 class WebstorePrivateGetStoreLoginFunction
199 : public UIThreadExtensionFunction {
200 public:
201 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
202 WEBSTOREPRIVATE_GETSTORELOGIN)
204 WebstorePrivateGetStoreLoginFunction();
206 private:
207 ~WebstorePrivateGetStoreLoginFunction() override;
209 // ExtensionFunction:
210 ExtensionFunction::ResponseAction Run() override;
212 ChromeExtensionFunctionDetails chrome_details_;
215 class WebstorePrivateSetStoreLoginFunction
216 : public UIThreadExtensionFunction {
217 public:
218 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
219 WEBSTOREPRIVATE_SETSTORELOGIN)
221 WebstorePrivateSetStoreLoginFunction();
223 private:
224 ~WebstorePrivateSetStoreLoginFunction() override;
226 // ExtensionFunction:
227 ExtensionFunction::ResponseAction Run() override;
229 ChromeExtensionFunctionDetails chrome_details_;
232 class WebstorePrivateGetWebGLStatusFunction
233 : public UIThreadExtensionFunction {
234 public:
235 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
236 WEBSTOREPRIVATE_GETWEBGLSTATUS)
238 WebstorePrivateGetWebGLStatusFunction();
240 private:
241 ~WebstorePrivateGetWebGLStatusFunction() override;
243 // ExtensionFunction:
244 ExtensionFunction::ResponseAction Run() override;
246 void OnFeatureCheck(bool feature_allowed);
248 scoped_refptr<GPUFeatureChecker> feature_checker_;
251 class WebstorePrivateGetIsLauncherEnabledFunction
252 : public UIThreadExtensionFunction {
253 public:
254 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
255 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
257 WebstorePrivateGetIsLauncherEnabledFunction();
259 private:
260 ~WebstorePrivateGetIsLauncherEnabledFunction() override;
262 // ExtensionFunction:
263 ExtensionFunction::ResponseAction Run() override;
265 void OnIsLauncherCheckCompleted(bool is_enabled);
268 class WebstorePrivateIsInIncognitoModeFunction
269 : public UIThreadExtensionFunction {
270 public:
271 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
272 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
274 WebstorePrivateIsInIncognitoModeFunction();
276 private:
277 ~WebstorePrivateIsInIncognitoModeFunction() override;
279 // ExtensionFunction:
280 ExtensionFunction::ResponseAction Run() override;
282 ChromeExtensionFunctionDetails chrome_details_;
285 class WebstorePrivateLaunchEphemeralAppFunction
286 : public UIThreadExtensionFunction {
287 public:
288 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp",
289 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP)
291 WebstorePrivateLaunchEphemeralAppFunction();
293 private:
294 ~WebstorePrivateLaunchEphemeralAppFunction() override;
296 // ExtensionFunction:
297 ExtensionFunction::ResponseAction Run() override;
299 void OnLaunchComplete(webstore_install::Result result,
300 const std::string& error);
302 ExtensionFunction::ResponseValue BuildResponse(
303 api::webstore_private::Result result,
304 const std::string& error);
306 ChromeExtensionFunctionDetails chrome_details_;
309 class WebstorePrivateGetEphemeralAppsEnabledFunction
310 : public UIThreadExtensionFunction {
311 public:
312 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled",
313 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED)
315 WebstorePrivateGetEphemeralAppsEnabledFunction();
317 private:
318 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override;
320 // ExtensionFunction:
321 ExtensionFunction::ResponseAction Run() override;
324 } // namespace extensions
326 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_