Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / api / webstore_private / webstore_private_api.h
bloba6b83b18f37b630dc53e629c6f1c171597b16f06
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 "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
11 #include "chrome/browser/extensions/active_install_data.h"
12 #include "chrome/browser/extensions/bundle_installer.h"
13 #include "chrome/browser/extensions/chrome_extension_function_details.h"
14 #include "chrome/browser/extensions/extension_install_prompt.h"
15 #include "chrome/browser/extensions/webstore_install_helper.h"
16 #include "chrome/browser/extensions/webstore_installer.h"
17 #include "chrome/common/extensions/api/webstore_private.h"
18 #include "chrome/common/extensions/webstore_install_result.h"
19 #include "extensions/browser/extension_function.h"
20 #include "third_party/skia/include/core/SkBitmap.h"
22 class GPUFeatureChecker;
24 namespace chrome {
25 class BitmapFetcher;
26 } // namespace chrome
28 namespace extensions {
30 class WebstorePrivateApi {
31 public:
32 // Allows you to override the WebstoreInstaller delegate for testing.
33 static void SetWebstoreInstallerDelegateForTesting(
34 WebstoreInstaller::Delegate* delegate);
36 // Gets the pending approval for the |extension_id| in |profile|. Pending
37 // approvals are held between the calls to beginInstallWithManifest and
38 // completeInstall. This should only be used for testing.
39 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
40 Profile* profile, const std::string& extension_id);
43 // Base class for webstorePrivate functions that show a permission prompt.
44 template<typename Params>
45 class WebstorePrivateFunctionWithPermissionPrompt
46 : public UIThreadExtensionFunction,
47 public ExtensionInstallPrompt::Delegate,
48 public WebstoreInstallHelper::Delegate {
49 public:
50 WebstorePrivateFunctionWithPermissionPrompt();
52 protected:
53 ~WebstorePrivateFunctionWithPermissionPrompt() override;
55 // May be implemented by subclasses to add their own code to the
56 // ExtensionFunction::Run implementation. Return a non-null ResponseValue to
57 // trigger an immediate response.
58 virtual ExtensionFunction::ResponseValue RunExtraForResponse();
60 // Must be implemented by subclasses to call one of the Confirm* methods on
61 // |install_prompt|.
62 virtual void ShowPrompt(ExtensionInstallPrompt* install_prompt) = 0;
64 // May be implemented by subclasses to add their own code to the
65 // ExtensionInstallPrompt::Delegate::InstallUIProceed and InstallUIAbort
66 // implementations.
67 virtual void InstallUIProceedHook() {}
68 virtual void InstallUIAbortHook(bool user_initiated) {}
70 // Must be implemented by subclasses to forward to their own Results::Create
71 // function.
72 virtual scoped_ptr<base::ListValue> CreateResults(
73 api::webstore_private::Result result) const = 0;
75 ExtensionFunction::ResponseValue BuildResponse(
76 api::webstore_private::Result result,
77 const std::string& error);
79 const Params& params() const { return *params_; }
80 const SkBitmap& icon() const { return icon_; }
81 const scoped_refptr<Extension>& dummy_extension() const {
82 return dummy_extension_;
85 scoped_ptr<base::DictionaryValue> PassParsedManifest();
87 private:
88 // ExtensionFunction:
89 ExtensionFunction::ResponseAction Run() override;
91 // WebstoreInstallHelper::Delegate:
92 void OnWebstoreParseSuccess(const std::string& id,
93 const SkBitmap& icon,
94 base::DictionaryValue* parsed_manifest) override;
95 void OnWebstoreParseFailure(const std::string& id,
96 InstallHelperResultCode result,
97 const std::string& error_message) override;
99 // ExtensionInstallPrompt::Delegate:
100 void InstallUIProceed() override;
101 void InstallUIAbort(bool user_initiated) override;
103 // This stores the input parameters to the function.
104 scoped_ptr<Params> params_;
106 // The results of parsing manifest_ and icon_data_.
107 scoped_ptr<base::DictionaryValue> parsed_manifest_;
108 SkBitmap icon_;
110 // A dummy Extension object we create for the purposes of using
111 // ExtensionInstallPrompt to prompt for confirmation of the install.
112 scoped_refptr<Extension> dummy_extension_;
114 // The class that displays the install prompt.
115 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
118 class WebstorePrivateBeginInstallWithManifest3Function
119 : public WebstorePrivateFunctionWithPermissionPrompt
120 <api::webstore_private::BeginInstallWithManifest3::Params> {
121 public:
122 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
123 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
125 WebstorePrivateBeginInstallWithManifest3Function();
127 private:
128 ~WebstorePrivateBeginInstallWithManifest3Function() override;
130 ExtensionFunction::ResponseValue RunExtraForResponse() override;
131 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override;
132 void InstallUIProceedHook() override;
133 void InstallUIAbortHook(bool user_initiated) override;
134 scoped_ptr<base::ListValue> CreateResults(
135 api::webstore_private::Result result) const override;
137 ChromeExtensionFunctionDetails chrome_details_;
139 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
142 class WebstorePrivateCompleteInstallFunction
143 : public UIThreadExtensionFunction,
144 public WebstoreInstaller::Delegate {
145 public:
146 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
147 WEBSTOREPRIVATE_COMPLETEINSTALL)
149 WebstorePrivateCompleteInstallFunction();
151 private:
152 ~WebstorePrivateCompleteInstallFunction() override;
154 // ExtensionFunction:
155 ExtensionFunction::ResponseAction Run() override;
157 // WebstoreInstaller::Delegate:
158 void OnExtensionInstallSuccess(const std::string& id) override;
159 void OnExtensionInstallFailure(
160 const std::string& id,
161 const std::string& error,
162 WebstoreInstaller::FailureReason reason) override;
164 void OnInstallSuccess(const std::string& id);
166 ChromeExtensionFunctionDetails chrome_details_;
168 scoped_ptr<WebstoreInstaller::Approval> approval_;
169 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
172 class WebstorePrivateShowPermissionPromptForDelegatedInstallFunction
173 : public WebstorePrivateFunctionWithPermissionPrompt
174 <api::webstore_private::ShowPermissionPromptForDelegatedInstall::
175 Params> {
176 public:
177 DECLARE_EXTENSION_FUNCTION(
178 "webstorePrivate.showPermissionPromptForDelegatedInstall",
179 WEBSTOREPRIVATE_SHOWPERMISSIONPROMPTFORDELEGATEDINSTALL)
181 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction();
183 private:
184 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() override;
186 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override;
187 scoped_ptr<base::ListValue> CreateResults(
188 api::webstore_private::Result result) const override;
191 class WebstorePrivateInstallBundleFunction
192 : public UIThreadExtensionFunction,
193 public chrome::BitmapFetcherDelegate {
194 public:
195 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
196 WEBSTOREPRIVATE_INSTALLBUNDLE)
198 WebstorePrivateInstallBundleFunction();
200 private:
201 ~WebstorePrivateInstallBundleFunction() override;
203 // ExtensionFunction:
204 ExtensionFunction::ResponseAction Run() override;
206 // chrome::BitmapFetcherDelegate:
207 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override;
209 void OnInstallApproval(BundleInstaller::ApprovalState state);
210 void OnInstallComplete();
212 ChromeExtensionFunctionDetails chrome_details_;
214 // This stores the input parameters to the function.
215 scoped_ptr<api::webstore_private::InstallBundle::Params> params_;
217 scoped_ptr<extensions::BundleInstaller> bundle_;
219 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
222 class WebstorePrivateEnableAppLauncherFunction
223 : public UIThreadExtensionFunction {
224 public:
225 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
226 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
228 WebstorePrivateEnableAppLauncherFunction();
230 private:
231 ~WebstorePrivateEnableAppLauncherFunction() override;
233 // ExtensionFunction:
234 ExtensionFunction::ResponseAction Run() override;
236 ChromeExtensionFunctionDetails chrome_details_;
239 class WebstorePrivateGetBrowserLoginFunction
240 : public UIThreadExtensionFunction {
241 public:
242 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
243 WEBSTOREPRIVATE_GETBROWSERLOGIN)
245 WebstorePrivateGetBrowserLoginFunction();
247 private:
248 ~WebstorePrivateGetBrowserLoginFunction() override;
250 // ExtensionFunction:
251 ExtensionFunction::ResponseAction Run() override;
253 ChromeExtensionFunctionDetails chrome_details_;
256 class WebstorePrivateGetStoreLoginFunction
257 : public UIThreadExtensionFunction {
258 public:
259 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
260 WEBSTOREPRIVATE_GETSTORELOGIN)
262 WebstorePrivateGetStoreLoginFunction();
264 private:
265 ~WebstorePrivateGetStoreLoginFunction() override;
267 // ExtensionFunction:
268 ExtensionFunction::ResponseAction Run() override;
270 ChromeExtensionFunctionDetails chrome_details_;
273 class WebstorePrivateSetStoreLoginFunction
274 : public UIThreadExtensionFunction {
275 public:
276 DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
277 WEBSTOREPRIVATE_SETSTORELOGIN)
279 WebstorePrivateSetStoreLoginFunction();
281 private:
282 ~WebstorePrivateSetStoreLoginFunction() override;
284 // ExtensionFunction:
285 ExtensionFunction::ResponseAction Run() override;
287 ChromeExtensionFunctionDetails chrome_details_;
290 class WebstorePrivateGetWebGLStatusFunction
291 : public UIThreadExtensionFunction {
292 public:
293 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
294 WEBSTOREPRIVATE_GETWEBGLSTATUS)
296 WebstorePrivateGetWebGLStatusFunction();
298 private:
299 ~WebstorePrivateGetWebGLStatusFunction() override;
301 // ExtensionFunction:
302 ExtensionFunction::ResponseAction Run() override;
304 void OnFeatureCheck(bool feature_allowed);
306 scoped_refptr<GPUFeatureChecker> feature_checker_;
309 class WebstorePrivateGetIsLauncherEnabledFunction
310 : public UIThreadExtensionFunction {
311 public:
312 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
313 WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
315 WebstorePrivateGetIsLauncherEnabledFunction();
317 private:
318 ~WebstorePrivateGetIsLauncherEnabledFunction() override;
320 // ExtensionFunction:
321 ExtensionFunction::ResponseAction Run() override;
323 void OnIsLauncherCheckCompleted(bool is_enabled);
326 class WebstorePrivateIsInIncognitoModeFunction
327 : public UIThreadExtensionFunction {
328 public:
329 DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
330 WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
332 WebstorePrivateIsInIncognitoModeFunction();
334 private:
335 ~WebstorePrivateIsInIncognitoModeFunction() override;
337 // ExtensionFunction:
338 ExtensionFunction::ResponseAction Run() override;
340 ChromeExtensionFunctionDetails chrome_details_;
343 class WebstorePrivateLaunchEphemeralAppFunction
344 : public UIThreadExtensionFunction {
345 public:
346 DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp",
347 WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP)
349 WebstorePrivateLaunchEphemeralAppFunction();
351 private:
352 ~WebstorePrivateLaunchEphemeralAppFunction() override;
354 // ExtensionFunction:
355 ExtensionFunction::ResponseAction Run() override;
357 void OnLaunchComplete(webstore_install::Result result,
358 const std::string& error);
360 ExtensionFunction::ResponseValue BuildResponse(
361 api::webstore_private::Result result,
362 const std::string& error);
364 ChromeExtensionFunctionDetails chrome_details_;
367 class WebstorePrivateGetEphemeralAppsEnabledFunction
368 : public UIThreadExtensionFunction {
369 public:
370 DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled",
371 WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED)
373 WebstorePrivateGetEphemeralAppsEnabledFunction();
375 private:
376 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override;
378 // ExtensionFunction:
379 ExtensionFunction::ResponseAction Run() override;
382 } // namespace extensions
384 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_