• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
7 
8 #include <string>
9 
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"
23 
24 class ProfileSyncService;
25 
26 namespace content {
27 class GpuDataManager;
28 }
29 
30 class GPUFeatureChecker;
31 
32 namespace extensions {
33 
34 class WebstorePrivateApi {
35  public:
36   // Allows you to override the WebstoreInstaller delegate for testing.
37   static void SetWebstoreInstallerDelegateForTesting(
38       WebstoreInstaller::Delegate* delegate);
39 
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);
45 };
46 
47 class WebstorePrivateInstallBundleFunction
48     : public ChromeAsyncExtensionFunction,
49       public extensions::BundleInstaller::Delegate {
50  public:
51   DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
52                              WEBSTOREPRIVATE_INSTALLBUNDLE)
53 
54   WebstorePrivateInstallBundleFunction();
55 
56   // BundleInstaller::Delegate:
57   virtual void OnBundleInstallApproved() OVERRIDE;
58   virtual void OnBundleInstallCanceled(bool user_initiated) OVERRIDE;
59   virtual void OnBundleInstallCompleted() OVERRIDE;
60 
61  protected:
62   virtual ~WebstorePrivateInstallBundleFunction();
63 
64   // ExtensionFunction:
65   virtual bool RunAsync() OVERRIDE;
66 
67   // Reads the extension |details| into |items|.
68   bool ReadBundleInfo(
69       const api::webstore_private::InstallBundle::Params& details,
70           extensions::BundleInstaller::ItemList* items);
71 
72  private:
73   scoped_refptr<extensions::BundleInstaller> bundle_;
74 };
75 
76 class WebstorePrivateBeginInstallWithManifest3Function
77     : public ChromeAsyncExtensionFunction,
78       public ExtensionInstallPrompt::Delegate,
79       public WebstoreInstallHelper::Delegate {
80  public:
81   DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
82                              WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
83 
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.
87   enum ResultCode {
88     ERROR_NONE = 0,
89 
90     // An unspecified error occurred.
91     UNKNOWN_ERROR,
92 
93     // The user cancelled the confirmation dialog instead of accepting it.
94     USER_CANCELLED,
95 
96     // The manifest failed to parse correctly.
97     MANIFEST_ERROR,
98 
99     // There was a problem parsing the base64 encoded icon data.
100     ICON_ERROR,
101 
102     // The extension id was invalid.
103     INVALID_ID,
104 
105     // The page does not have permission to call this function.
106     PERMISSION_DENIED,
107 
108     // Invalid icon url.
109     INVALID_ICON_URL,
110 
111     // An extension with the same extension id has already been installed.
112     ALREADY_INSTALLED,
113   };
114 
115   WebstorePrivateBeginInstallWithManifest3Function();
116 
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;
126 
127   // ExtensionInstallPrompt::Delegate:
128   virtual void InstallUIProceed() OVERRIDE;
129   virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
130 
131  protected:
132   virtual ~WebstorePrivateBeginInstallWithManifest3Function();
133 
134   // ExtensionFunction:
135   virtual bool RunAsync() OVERRIDE;
136 
137   // Sets the result_ as a string based on |code|.
138   void SetResultCode(ResultCode code);
139 
140  private:
141   const char* ResultCodeToString(ResultCode code);
142 
143   // These store the input parameters to the function.
144   scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
145 
146   // The results of parsing manifest_ and icon_data_ go into these two.
147   scoped_ptr<base::DictionaryValue> parsed_manifest_;
148   SkBitmap icon_;
149 
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_;
153 
154   // The class that displays the install prompt.
155   scoped_ptr<ExtensionInstallPrompt> install_prompt_;
156 
157   scoped_ptr<ScopedActiveInstall> scoped_active_install_;
158 
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_;
162 };
163 
164 class WebstorePrivateCompleteInstallFunction
165     : public ChromeAsyncExtensionFunction,
166       public WebstoreInstaller::Delegate {
167  public:
168   DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
169                              WEBSTOREPRIVATE_COMPLETEINSTALL)
170 
171   WebstorePrivateCompleteInstallFunction();
172 
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;
179 
180  protected:
181   virtual ~WebstorePrivateCompleteInstallFunction();
182 
183   // ExtensionFunction:
184   virtual bool RunAsync() OVERRIDE;
185 
186  private:
187   scoped_ptr<WebstoreInstaller::Approval> approval_;
188   scoped_ptr<ScopedActiveInstall> scoped_active_install_;
189 
190   void OnInstallSuccess(const std::string& id);
191 };
192 
193 class WebstorePrivateEnableAppLauncherFunction
194     : public ChromeSyncExtensionFunction {
195  public:
196   DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
197                              WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
198 
199   WebstorePrivateEnableAppLauncherFunction();
200 
201  protected:
202   virtual ~WebstorePrivateEnableAppLauncherFunction();
203 
204   // ExtensionFunction:
205   virtual bool RunSync() OVERRIDE;
206 };
207 
208 class WebstorePrivateGetBrowserLoginFunction
209     : public ChromeSyncExtensionFunction {
210  public:
211   DECLARE_EXTENSION_FUNCTION("webstorePrivate.getBrowserLogin",
212                              WEBSTOREPRIVATE_GETBROWSERLOGIN)
213 
214  protected:
~WebstorePrivateGetBrowserLoginFunction()215   virtual ~WebstorePrivateGetBrowserLoginFunction() {}
216 
217   // ExtensionFunction:
218   virtual bool RunSync() OVERRIDE;
219 };
220 
221 class WebstorePrivateGetStoreLoginFunction
222     : public ChromeSyncExtensionFunction {
223  public:
224   DECLARE_EXTENSION_FUNCTION("webstorePrivate.getStoreLogin",
225                              WEBSTOREPRIVATE_GETSTORELOGIN)
226 
227  protected:
~WebstorePrivateGetStoreLoginFunction()228   virtual ~WebstorePrivateGetStoreLoginFunction() {}
229 
230   // ExtensionFunction:
231   virtual bool RunSync() OVERRIDE;
232 };
233 
234 class WebstorePrivateSetStoreLoginFunction
235     : public ChromeSyncExtensionFunction {
236  public:
237   DECLARE_EXTENSION_FUNCTION("webstorePrivate.setStoreLogin",
238                              WEBSTOREPRIVATE_SETSTORELOGIN)
239 
240  protected:
~WebstorePrivateSetStoreLoginFunction()241   virtual ~WebstorePrivateSetStoreLoginFunction() {}
242 
243   // ExtensionFunction:
244   virtual bool RunSync() OVERRIDE;
245 };
246 
247 class WebstorePrivateGetWebGLStatusFunction
248     : public ChromeAsyncExtensionFunction {
249  public:
250   DECLARE_EXTENSION_FUNCTION("webstorePrivate.getWebGLStatus",
251                              WEBSTOREPRIVATE_GETWEBGLSTATUS)
252 
253   WebstorePrivateGetWebGLStatusFunction();
254 
255  protected:
256   virtual ~WebstorePrivateGetWebGLStatusFunction();
257 
258   void OnFeatureCheck(bool feature_allowed);
259 
260   // ExtensionFunction:
261   virtual bool RunAsync() OVERRIDE;
262 
263  private:
264   void CreateResult(bool webgl_allowed);
265 
266   scoped_refptr<GPUFeatureChecker> feature_checker_;
267 };
268 
269 class WebstorePrivateGetIsLauncherEnabledFunction
270     : public ChromeSyncExtensionFunction {
271  public:
272   DECLARE_EXTENSION_FUNCTION("webstorePrivate.getIsLauncherEnabled",
273                              WEBSTOREPRIVATE_GETISLAUNCHERENABLED)
274 
WebstorePrivateGetIsLauncherEnabledFunction()275   WebstorePrivateGetIsLauncherEnabledFunction() {}
276 
277  protected:
~WebstorePrivateGetIsLauncherEnabledFunction()278   virtual ~WebstorePrivateGetIsLauncherEnabledFunction() {}
279 
280   // ExtensionFunction:
281   virtual bool RunSync() OVERRIDE;
282 
283  private:
284   void OnIsLauncherCheckCompleted(bool is_enabled);
285 };
286 
287 class WebstorePrivateIsInIncognitoModeFunction
288     : public ChromeSyncExtensionFunction {
289  public:
290   DECLARE_EXTENSION_FUNCTION("webstorePrivate.isInIncognitoMode",
291                              WEBSTOREPRIVATE_ISININCOGNITOMODEFUNCTION)
292 
WebstorePrivateIsInIncognitoModeFunction()293   WebstorePrivateIsInIncognitoModeFunction() {}
294 
295  protected:
~WebstorePrivateIsInIncognitoModeFunction()296   virtual ~WebstorePrivateIsInIncognitoModeFunction() {}
297 
298   // ExtensionFunction:
299   virtual bool RunSync() OVERRIDE;
300 };
301 
302 class WebstorePrivateLaunchEphemeralAppFunction
303     : public ChromeAsyncExtensionFunction {
304  public:
305   DECLARE_EXTENSION_FUNCTION("webstorePrivate.launchEphemeralApp",
306                              WEBSTOREPRIVATE_LAUNCHEPHEMERALAPP)
307 
308   WebstorePrivateLaunchEphemeralAppFunction();
309 
310  protected:
311   virtual ~WebstorePrivateLaunchEphemeralAppFunction();
312 
313   // ExtensionFunction:
314   virtual bool RunAsync() OVERRIDE;
315 
316  private:
317   void OnLaunchComplete(webstore_install::Result result,
318                         const std::string& error);
319   void SetResult(
320       api::webstore_private::LaunchEphemeralApp::Results::Result result,
321       const std::string& error);
322 };
323 
324 class WebstorePrivateGetEphemeralAppsEnabledFunction
325     : public ChromeSyncExtensionFunction {
326  public:
327   DECLARE_EXTENSION_FUNCTION("webstorePrivate.getEphemeralAppsEnabled",
328                              WEBSTOREPRIVATE_GETEPHEMERALAPPSENABLED)
329 
330   WebstorePrivateGetEphemeralAppsEnabledFunction();
331 
332  protected:
333   virtual ~WebstorePrivateGetEphemeralAppsEnabledFunction();
334 
335   // ExtensionFunction:
336   virtual bool RunSync() OVERRIDE;
337 };
338 
339 }  // namespace extensions
340 
341 #endif  // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
342