Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.h

Issue 1268853003: Move webstorePrivate DelegatedInstall functions into new dashboardPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" 11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
11 #include "chrome/browser/extensions/active_install_data.h" 12 #include "chrome/browser/extensions/active_install_data.h"
12 #include "chrome/browser/extensions/bundle_installer.h" 13 #include "chrome/browser/extensions/bundle_installer.h"
13 #include "chrome/browser/extensions/chrome_extension_function_details.h" 14 #include "chrome/browser/extensions/chrome_extension_function_details.h"
14 #include "chrome/browser/extensions/extension_install_prompt.h" 15 #include "chrome/browser/extensions/extension_install_prompt.h"
15 #include "chrome/browser/extensions/webstore_install_helper.h" 16 #include "chrome/browser/extensions/webstore_install_helper.h"
16 #include "chrome/browser/extensions/webstore_installer.h" 17 #include "chrome/browser/extensions/webstore_installer.h"
17 #include "chrome/common/extensions/api/webstore_private.h" 18 #include "chrome/common/extensions/api/webstore_private.h"
18 #include "chrome/common/extensions/webstore_install_result.h" 19 #include "chrome/common/extensions/webstore_install_result.h"
19 #include "extensions/browser/extension_function.h" 20 #include "extensions/browser/extension_function.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
21 22
22 class GPUFeatureChecker; 23 class GPUFeatureChecker;
24 class GURL;
23 25
24 namespace chrome { 26 namespace chrome {
25 class BitmapFetcher; 27 class BitmapFetcher;
26 } // namespace chrome 28 } // namespace chrome
27 29
28 namespace extensions { 30 namespace extensions {
29 31
32 class Extension;
33
30 class WebstorePrivateApi { 34 class WebstorePrivateApi {
31 public: 35 public:
32 // Allows you to override the WebstoreInstaller delegate for testing. 36 // Allows you to override the WebstoreInstaller delegate for testing.
33 static void SetWebstoreInstallerDelegateForTesting( 37 static void SetWebstoreInstallerDelegateForTesting(
34 WebstoreInstaller::Delegate* delegate); 38 WebstoreInstaller::Delegate* delegate);
35 39
36 // Gets the pending approval for the |extension_id| in |profile|. Pending 40 // Gets the pending approval for the |extension_id| in |profile|. Pending
37 // approvals are held between the calls to beginInstallWithManifest and 41 // approvals are held between the calls to beginInstallWithManifest and
38 // completeInstall. This should only be used for testing. 42 // completeInstall. This should only be used for testing.
39 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting( 43 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
40 Profile* profile, const std::string& extension_id); 44 Profile* profile, const std::string& extension_id);
41 }; 45 };
42 46
43 // Base class for webstorePrivate functions that show a permission prompt. 47 class WebstorePrivateBeginInstallWithManifest3Function
44 template<typename Params>
45 class WebstorePrivateFunctionWithPermissionPrompt
46 : public UIThreadExtensionFunction, 48 : public UIThreadExtensionFunction,
47 public ExtensionInstallPrompt::Delegate, 49 public ExtensionInstallPrompt::Delegate,
48 public WebstoreInstallHelper::Delegate { 50 public WebstoreInstallHelper::Delegate {
49 public: 51 public:
50 WebstorePrivateFunctionWithPermissionPrompt(); 52 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
53 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
51 54
52 protected: 55 WebstorePrivateBeginInstallWithManifest3Function();
53 ~WebstorePrivateFunctionWithPermissionPrompt() override;
54
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();
59
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;
63
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) {}
69
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;
74
75 ExtensionFunction::ResponseValue BuildResponse(
76 api::webstore_private::Result result,
77 const std::string& error);
78
79 const typename Params::Details& details() const { return params_->details; }
80 const SkBitmap& icon() const { return icon_; }
81 const scoped_refptr<Extension>& dummy_extension() const {
82 return dummy_extension_;
83 }
84
85 scoped_ptr<base::DictionaryValue> PassParsedManifest();
86 56
87 private: 57 private:
58 using Params = api::webstore_private::BeginInstallWithManifest3::Params;
59
60 ~WebstorePrivateBeginInstallWithManifest3Function() override;
61
88 // ExtensionFunction: 62 // ExtensionFunction:
89 ExtensionFunction::ResponseAction Run() override; 63 ExtensionFunction::ResponseAction Run() override;
90 64
91 // WebstoreInstallHelper::Delegate: 65 // WebstoreInstallHelper::Delegate:
92 void OnWebstoreParseSuccess(const std::string& id, 66 void OnWebstoreParseSuccess(const std::string& id,
93 const SkBitmap& icon, 67 const SkBitmap& icon,
94 base::DictionaryValue* parsed_manifest) override; 68 base::DictionaryValue* parsed_manifest) override;
95 void OnWebstoreParseFailure(const std::string& id, 69 void OnWebstoreParseFailure(const std::string& id,
96 InstallHelperResultCode result, 70 InstallHelperResultCode result,
97 const std::string& error_message) override; 71 const std::string& error_message) override;
98 72
99 // ExtensionInstallPrompt::Delegate: 73 // ExtensionInstallPrompt::Delegate:
100 void InstallUIProceed() override; 74 void InstallUIProceed() override;
101 void InstallUIAbort(bool user_initiated) override; 75 void InstallUIAbort(bool user_initiated) override;
102 76
103 // This stores the input parameters to the function. 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;
82
83 const Params::Details& details() const { return params_->details; }
84
85 ChromeExtensionFunctionDetails chrome_details_;
86
104 scoped_ptr<Params> params_; 87 scoped_ptr<Params> params_;
105 88
106 // The results of parsing manifest_ and icon_data_. 89 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
90
107 scoped_ptr<base::DictionaryValue> parsed_manifest_; 91 scoped_ptr<base::DictionaryValue> parsed_manifest_;
108 SkBitmap icon_; 92 SkBitmap icon_;
109 93
110 // A dummy Extension object we create for the purposes of using 94 // A dummy Extension object we create for the purposes of using
111 // ExtensionInstallPrompt to prompt for confirmation of the install. 95 // ExtensionInstallPrompt to prompt for confirmation of the install.
112 scoped_refptr<Extension> dummy_extension_; 96 scoped_refptr<Extension> dummy_extension_;
113 97
114 // The class that displays the install prompt.
115 scoped_ptr<ExtensionInstallPrompt> install_prompt_; 98 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
116 }; 99 };
117 100
118 class WebstorePrivateBeginInstallWithManifest3Function
119 : public WebstorePrivateFunctionWithPermissionPrompt
120 <api::webstore_private::BeginInstallWithManifest3::Params> {
121 public:
122 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
123 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
124
125 WebstorePrivateBeginInstallWithManifest3Function();
126
127 private:
128 ~WebstorePrivateBeginInstallWithManifest3Function() override;
129
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;
136
137 ChromeExtensionFunctionDetails chrome_details_;
138
139 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
140 };
141
142 class WebstorePrivateCompleteInstallFunction 101 class WebstorePrivateCompleteInstallFunction
143 : public UIThreadExtensionFunction, 102 : public UIThreadExtensionFunction,
144 public WebstoreInstaller::Delegate { 103 public WebstoreInstaller::Delegate {
145 public: 104 public:
146 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", 105 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
147 WEBSTOREPRIVATE_COMPLETEINSTALL) 106 WEBSTOREPRIVATE_COMPLETEINSTALL)
148 107
149 WebstorePrivateCompleteInstallFunction(); 108 WebstorePrivateCompleteInstallFunction();
150 109
151 private: 110 private:
(...skipping 10 matching lines...) Expand all
162 WebstoreInstaller::FailureReason reason) override; 121 WebstoreInstaller::FailureReason reason) override;
163 122
164 void OnInstallSuccess(const std::string& id); 123 void OnInstallSuccess(const std::string& id);
165 124
166 ChromeExtensionFunctionDetails chrome_details_; 125 ChromeExtensionFunctionDetails chrome_details_;
167 126
168 scoped_ptr<WebstoreInstaller::Approval> approval_; 127 scoped_ptr<WebstoreInstaller::Approval> approval_;
169 scoped_ptr<ScopedActiveInstall> scoped_active_install_; 128 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
170 }; 129 };
171 130
172 class WebstorePrivateShowPermissionPromptForDelegatedInstallFunction 131 class WebstorePrivateInstallBundleFunction
173 : public WebstorePrivateFunctionWithPermissionPrompt
174 <api::webstore_private::ShowPermissionPromptForDelegatedInstall::
175 Params> {
176 public:
177 DECLARE_EXTENSION_FUNCTION(
178 "webstorePrivate.showPermissionPromptForDelegatedInstall",
179 WEBSTOREPRIVATE_SHOWPERMISSIONPROMPTFORDELEGATEDINSTALL)
180
181 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction();
182
183 private:
184 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() override;
185
186 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override;
187 scoped_ptr<base::ListValue> CreateResults(
188 api::webstore_private::Result result) const override;
189 };
190
191 // Base class for webstorePrivate functions that deal with bundles.
192 template<typename Params>
193 class WebstorePrivateFunctionWithBundle
194 : public UIThreadExtensionFunction, 132 : public UIThreadExtensionFunction,
195 public chrome::BitmapFetcherDelegate { 133 public chrome::BitmapFetcherDelegate {
196 public: 134 public:
197 WebstorePrivateFunctionWithBundle(); 135 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
136 WEBSTOREPRIVATE_INSTALLBUNDLE)
198 137
199 protected: 138 WebstorePrivateInstallBundleFunction();
200 ~WebstorePrivateFunctionWithBundle() override;
201
202 const typename Params::Details& details() const { return params_->details; }
203 extensions::BundleInstaller* bundle() { return bundle_.get(); }
204 ChromeExtensionFunctionDetails* chrome_details() { return &chrome_details_; }
205
206 void set_auth_user(const std::string& user) { auth_user_ = user; }
207 void set_delegated_user(const std::string& user) {
208 delegated_user_ = user;
209 }
210
211 // Called after |params_| has been created.
212 virtual void ProcessParams() = 0;
213 // Called for each bundle item before showing them in the dialog.
214 virtual bool ShouldSkipItem(const std::string& id) const = 0;
215 // Called after the user has confirmed the dialog.
216 virtual void OnInstallApprovalHook() = 0;
217 139
218 private: 140 private:
141 using Params = api::webstore_private::InstallBundle::Params;
142
143 ~WebstorePrivateInstallBundleFunction() override;
144
219 // ExtensionFunction: 145 // ExtensionFunction:
220 ExtensionFunction::ResponseAction Run() override; 146 ExtensionFunction::ResponseAction Run() override;
221 147
222 // chrome::BitmapFetcherDelegate: 148 // chrome::BitmapFetcherDelegate:
223 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; 149 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override;
224 150
225 void OnInstallApproval(BundleInstaller::ApprovalState state); 151 void OnInstallApproval(BundleInstaller::ApprovalState state);
152 void OnInstallComplete();
153
154 const Params::Details& details() const { return params_->details; }
226 155
227 ChromeExtensionFunctionDetails chrome_details_; 156 ChromeExtensionFunctionDetails chrome_details_;
228 157
229 // This stores the input parameters to the function.
230 scoped_ptr<Params> params_; 158 scoped_ptr<Params> params_;
231 159
232 std::string auth_user_;
233 std::string delegated_user_;
234
235 scoped_ptr<extensions::BundleInstaller> bundle_; 160 scoped_ptr<extensions::BundleInstaller> bundle_;
236
237 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_; 161 scoped_ptr<chrome::BitmapFetcher> icon_fetcher_;
238 }; 162 };
239 163
240 class WebstorePrivateInstallBundleFunction
241 : public WebstorePrivateFunctionWithBundle
242 <api::webstore_private::InstallBundle::Params> {
243 public:
244 DECLARE_EXTENSION_FUNCTION("webstorePrivate.installBundle",
245 WEBSTOREPRIVATE_INSTALLBUNDLE)
246
247 WebstorePrivateInstallBundleFunction();
248
249 private:
250 ~WebstorePrivateInstallBundleFunction() override;
251
252 // WebstorePrivateFunctionWithBundle:
253 void ProcessParams() override;
254 bool ShouldSkipItem(const std::string& id) const override;
255 void OnInstallApprovalHook() override;
256
257 void OnInstallComplete();
258 };
259
260 class WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction
261 : public WebstorePrivateFunctionWithBundle
262 <api::webstore_private::
263 ShowPermissionPromptForDelegatedBundleInstall::Params> {
264 public:
265 DECLARE_EXTENSION_FUNCTION(
266 "webstorePrivate.showPermissionPromptForDelegatedBundleInstall",
267 WEBSTOREPRIVATE_SHOWPERMISSIONPROMPTFORDELEGATEDBUNDLEINSTALL)
268
269 WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction();
270
271 private:
272 ~WebstorePrivateShowPermissionPromptForDelegatedBundleInstallFunction()
273 override;
274
275 // WebstorePrivateFunctionWithBundle:
276 void ProcessParams() override;
277 bool ShouldSkipItem(const std::string& id) const override;
278 void OnInstallApprovalHook() override;
279 };
280
281 class WebstorePrivateEnableAppLauncherFunction 164 class WebstorePrivateEnableAppLauncherFunction
282 : public UIThreadExtensionFunction { 165 : public UIThreadExtensionFunction {
283 public: 166 public:
284 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", 167 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
285 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) 168 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
286 169
287 WebstorePrivateEnableAppLauncherFunction(); 170 WebstorePrivateEnableAppLauncherFunction();
288 171
289 private: 172 private:
290 ~WebstorePrivateEnableAppLauncherFunction() override; 173 ~WebstorePrivateEnableAppLauncherFunction() override;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 private: 317 private:
435 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; 318 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override;
436 319
437 // ExtensionFunction: 320 // ExtensionFunction:
438 ExtensionFunction::ResponseAction Run() override; 321 ExtensionFunction::ResponseAction Run() override;
439 }; 322 };
440 323
441 } // namespace extensions 324 } // namespace extensions
442 325
443 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H _ 326 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698