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

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

Issue 850283003: Add a new webstorePrivate API to show a permission prompt for delegated installs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_permission_prompt
Patch Set: common base class Created 5 years, 10 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 "chrome/browser/extensions/active_install_data.h" 10 #include "chrome/browser/extensions/active_install_data.h"
(...skipping 16 matching lines...) Expand all
27 static void SetWebstoreInstallerDelegateForTesting( 27 static void SetWebstoreInstallerDelegateForTesting(
28 WebstoreInstaller::Delegate* delegate); 28 WebstoreInstaller::Delegate* delegate);
29 29
30 // Gets the pending approval for the |extension_id| in |profile|. Pending 30 // Gets the pending approval for the |extension_id| in |profile|. Pending
31 // approvals are held between the calls to beginInstallWithManifest and 31 // approvals are held between the calls to beginInstallWithManifest and
32 // completeInstall. This should only be used for testing. 32 // completeInstall. This should only be used for testing.
33 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting( 33 static scoped_ptr<WebstoreInstaller::Approval> PopApprovalForTesting(
34 Profile* profile, const std::string& extension_id); 34 Profile* profile, const std::string& extension_id);
35 }; 35 };
36 36
37 class WebstorePrivateBeginInstallWithManifest3Function 37 // Base class for webstorePrivate functions that show a permission prompt.
38 template<typename Params>
39 class WebstorePrivateFunctionWithPermissionPrompt
38 : public UIThreadExtensionFunction, 40 : public UIThreadExtensionFunction,
39 public ExtensionInstallPrompt::Delegate, 41 public ExtensionInstallPrompt::Delegate,
40 public WebstoreInstallHelper::Delegate { 42 public WebstoreInstallHelper::Delegate {
41 public: 43 public:
42 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3", 44 WebstorePrivateFunctionWithPermissionPrompt();
43 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
44 45
45 WebstorePrivateBeginInstallWithManifest3Function(); 46 protected:
47 ~WebstorePrivateFunctionWithPermissionPrompt() override;
48
49 // May be implemented by subclasses to add their own code to the
50 // ExtensionFunction::Run implementation. Return true and fill |result| and
51 // |error| to trigger an immediate response.
52 virtual bool RunImpl(api::webstore_private::Result* result,
53 std::string* error);
54
55 // Must be implemented by subclasses to call one of the Confirm* methods on
56 // |install_prompt|.
57 virtual void ShowPrompt(ExtensionInstallPrompt* install_prompt) = 0;
58
59 virtual void OnInstallUIProceed() {}
60 virtual void OnInstallUIAbort(bool user_initiated) {}
61
62 virtual ExtensionFunction::ResponseValue BuildResponse(
63 api::webstore_private::Result result, const std::string& error) = 0;
64
65 const Params& params() const { return *params_; }
66 const SkBitmap& icon() const { return icon_; }
67 const scoped_refptr<Extension>& dummy_extension() const {
68 return dummy_extension_;
69 }
70
71 scoped_ptr<base::DictionaryValue> PassParsedManifest();
46 72
47 private: 73 private:
48 ~WebstorePrivateBeginInstallWithManifest3Function() override;
49
50 // ExtensionFunction: 74 // ExtensionFunction:
51 ExtensionFunction::ResponseAction Run() override; 75 ExtensionFunction::ResponseAction Run() override;
52 76
53 // WebstoreInstallHelper::Delegate: 77 // WebstoreInstallHelper::Delegate:
54 void OnWebstoreParseSuccess(const std::string& id, 78 void OnWebstoreParseSuccess(const std::string& id,
55 const SkBitmap& icon, 79 const SkBitmap& icon,
56 base::DictionaryValue* parsed_manifest) override; 80 base::DictionaryValue* parsed_manifest) override;
57 void OnWebstoreParseFailure(const std::string& id, 81 void OnWebstoreParseFailure(const std::string& id,
58 InstallHelperResultCode result, 82 InstallHelperResultCode result,
59 const std::string& error_message) override; 83 const std::string& error_message) override;
60 84
61 // ExtensionInstallPrompt::Delegate: 85 // ExtensionInstallPrompt::Delegate:
62 void InstallUIProceed() override; 86 void InstallUIProceed() override;
63 void InstallUIAbort(bool user_initiated) override; 87 void InstallUIAbort(bool user_initiated) override;
64 88
65 // Response helpers. 89 // This stores the input parameters to the function.
66 ExtensionFunction::ResponseValue BuildResponseForSuccess(); 90 scoped_ptr<Params> params_;
67 ExtensionFunction::ResponseValue BuildResponseForError(
68 api::webstore_private::Result result, const std::string& error);
69 91
70 ChromeExtensionFunctionDetails chrome_details_; 92 // The results of parsing manifest_ and icon_data_.
71
72 // This stores the input parameters to the function.
73 scoped_ptr<api::webstore_private::BeginInstallWithManifest3::Params> params_;
74
75 // The results of parsing manifest_ and icon_data_ go into these two.
76 scoped_ptr<base::DictionaryValue> parsed_manifest_; 93 scoped_ptr<base::DictionaryValue> parsed_manifest_;
77 SkBitmap icon_; 94 SkBitmap icon_;
78 95
79 // A dummy Extension object we create for the purposes of using 96 // A dummy Extension object we create for the purposes of using
80 // ExtensionInstallPrompt to prompt for confirmation of the install. 97 // ExtensionInstallPrompt to prompt for confirmation of the install.
81 scoped_refptr<Extension> dummy_extension_; 98 scoped_refptr<Extension> dummy_extension_;
82 99
83 // The class that displays the install prompt. 100 // The class that displays the install prompt.
84 scoped_ptr<ExtensionInstallPrompt> install_prompt_; 101 scoped_ptr<ExtensionInstallPrompt> install_prompt_;
102 };
103
104 class WebstorePrivateBeginInstallWithManifest3Function
105 : public WebstorePrivateFunctionWithPermissionPrompt
106 <api::webstore_private::BeginInstallWithManifest3::Params> {
107 public:
108 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3",
109 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3)
110
111 WebstorePrivateBeginInstallWithManifest3Function();
112
113 private:
114 ~WebstorePrivateBeginInstallWithManifest3Function() override;
115
116 bool RunImpl(api::webstore_private::Result* result,
117 std::string* error) override;
118 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override;
119 void OnInstallUIProceed() override;
120 void OnInstallUIAbort(bool user_initiated) override;
121 ExtensionFunction::ResponseValue BuildResponse(
122 api::webstore_private::Result result, const std::string& error) override;
123
124 ChromeExtensionFunctionDetails chrome_details_;
85 125
86 scoped_ptr<ScopedActiveInstall> scoped_active_install_; 126 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
87
88 // The authuser query parameter value which should be used with CRX download
89 // requests. This is empty if authuser should not be set on download requests.
90 std::string authuser_;
91 }; 127 };
92 128
93 class WebstorePrivateCompleteInstallFunction 129 class WebstorePrivateCompleteInstallFunction
94 : public UIThreadExtensionFunction, 130 : public UIThreadExtensionFunction,
95 public WebstoreInstaller::Delegate { 131 public WebstoreInstaller::Delegate {
96 public: 132 public:
97 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", 133 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall",
98 WEBSTOREPRIVATE_COMPLETEINSTALL) 134 WEBSTOREPRIVATE_COMPLETEINSTALL)
99 135
100 WebstorePrivateCompleteInstallFunction(); 136 WebstorePrivateCompleteInstallFunction();
(...skipping 12 matching lines...) Expand all
113 WebstoreInstaller::FailureReason reason) override; 149 WebstoreInstaller::FailureReason reason) override;
114 150
115 void OnInstallSuccess(const std::string& id); 151 void OnInstallSuccess(const std::string& id);
116 152
117 ChromeExtensionFunctionDetails chrome_details_; 153 ChromeExtensionFunctionDetails chrome_details_;
118 154
119 scoped_ptr<WebstoreInstaller::Approval> approval_; 155 scoped_ptr<WebstoreInstaller::Approval> approval_;
120 scoped_ptr<ScopedActiveInstall> scoped_active_install_; 156 scoped_ptr<ScopedActiveInstall> scoped_active_install_;
121 }; 157 };
122 158
159 class WebstorePrivateShowPermissionPromptForDelegatedInstallFunction
160 : public WebstorePrivateFunctionWithPermissionPrompt
161 <api::webstore_private::ShowPermissionPromptForDelegatedInstall::
162 Params> {
163 public:
164 DECLARE_EXTENSION_FUNCTION(
165 "webstorePrivate.showPermissionPromptForDelegatedInstall",
166 WEBSTOREPRIVATE_SHOWPERMISSIONPROMPTFORDELEGATEDINSTALL)
167
168 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction();
169
170 private:
171 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() override;
172
173 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override;
174 ExtensionFunction::ResponseValue BuildResponse(
175 api::webstore_private::Result result,
176 const std::string& error) override;
177 };
178
123 class WebstorePrivateEnableAppLauncherFunction 179 class WebstorePrivateEnableAppLauncherFunction
124 : public UIThreadExtensionFunction { 180 : public UIThreadExtensionFunction {
125 public: 181 public:
126 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", 182 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher",
127 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) 183 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER)
128 184
129 WebstorePrivateEnableAppLauncherFunction(); 185 WebstorePrivateEnableAppLauncherFunction();
130 186
131 private: 187 private:
132 ~WebstorePrivateEnableAppLauncherFunction() override; 188 ~WebstorePrivateEnableAppLauncherFunction() override;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 private: 332 private:
277 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; 333 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override;
278 334
279 // ExtensionFunction: 335 // ExtensionFunction:
280 ExtensionFunction::ResponseAction Run() override; 336 ExtensionFunction::ResponseAction Run() override;
281 }; 337 };
282 338
283 } // namespace extensions 339 } // namespace extensions
284 340
285 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H _ 341 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698