OLD | NEW |
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 Loading... |
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 a non-null ResponseValue to |
| 51 // trigger an immediate response. |
| 52 virtual ExtensionFunction::ResponseValue RunExtraForResponse(); |
| 53 |
| 54 // Must be implemented by subclasses to call one of the Confirm* methods on |
| 55 // |install_prompt|. |
| 56 virtual void ShowPrompt(ExtensionInstallPrompt* install_prompt) = 0; |
| 57 |
| 58 // May be implemented by subclasses to add their own code to the |
| 59 // ExtensionInstallPrompt::Delegate::InstallUIProceed and InstallUIAbort |
| 60 // implementations. |
| 61 virtual void InstallUIProceedHook() {} |
| 62 virtual void InstallUIAbortHook(bool user_initiated) {} |
| 63 |
| 64 // Must be implemented by subclasses to forward to their own Results::Create |
| 65 // function. |
| 66 virtual scoped_ptr<base::ListValue> CreateResults( |
| 67 api::webstore_private::Result result) const = 0; |
| 68 |
| 69 ExtensionFunction::ResponseValue BuildResponse( |
| 70 api::webstore_private::Result result, |
| 71 const std::string& error); |
| 72 |
| 73 const Params& params() const { return *params_; } |
| 74 const SkBitmap& icon() const { return icon_; } |
| 75 const scoped_refptr<Extension>& dummy_extension() const { |
| 76 return dummy_extension_; |
| 77 } |
| 78 |
| 79 scoped_ptr<base::DictionaryValue> PassParsedManifest(); |
46 | 80 |
47 private: | 81 private: |
48 ~WebstorePrivateBeginInstallWithManifest3Function() override; | |
49 | |
50 // ExtensionFunction: | 82 // ExtensionFunction: |
51 ExtensionFunction::ResponseAction Run() override; | 83 ExtensionFunction::ResponseAction Run() override; |
52 | 84 |
53 // WebstoreInstallHelper::Delegate: | 85 // WebstoreInstallHelper::Delegate: |
54 void OnWebstoreParseSuccess(const std::string& id, | 86 void OnWebstoreParseSuccess(const std::string& id, |
55 const SkBitmap& icon, | 87 const SkBitmap& icon, |
56 base::DictionaryValue* parsed_manifest) override; | 88 base::DictionaryValue* parsed_manifest) override; |
57 void OnWebstoreParseFailure(const std::string& id, | 89 void OnWebstoreParseFailure(const std::string& id, |
58 InstallHelperResultCode result, | 90 InstallHelperResultCode result, |
59 const std::string& error_message) override; | 91 const std::string& error_message) override; |
60 | 92 |
61 // ExtensionInstallPrompt::Delegate: | 93 // ExtensionInstallPrompt::Delegate: |
62 void InstallUIProceed() override; | 94 void InstallUIProceed() override; |
63 void InstallUIAbort(bool user_initiated) override; | 95 void InstallUIAbort(bool user_initiated) override; |
64 | 96 |
65 // Response helpers. | 97 // This stores the input parameters to the function. |
66 ExtensionFunction::ResponseValue BuildResponseForSuccess(); | 98 scoped_ptr<Params> params_; |
67 ExtensionFunction::ResponseValue BuildResponseForError( | |
68 api::webstore_private::Result result, const std::string& error); | |
69 | 99 |
70 ChromeExtensionFunctionDetails chrome_details_; | 100 // 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_; | 101 scoped_ptr<base::DictionaryValue> parsed_manifest_; |
77 SkBitmap icon_; | 102 SkBitmap icon_; |
78 | 103 |
79 // A dummy Extension object we create for the purposes of using | 104 // A dummy Extension object we create for the purposes of using |
80 // ExtensionInstallPrompt to prompt for confirmation of the install. | 105 // ExtensionInstallPrompt to prompt for confirmation of the install. |
81 scoped_refptr<Extension> dummy_extension_; | 106 scoped_refptr<Extension> dummy_extension_; |
82 | 107 |
83 // The class that displays the install prompt. | 108 // The class that displays the install prompt. |
84 scoped_ptr<ExtensionInstallPrompt> install_prompt_; | 109 scoped_ptr<ExtensionInstallPrompt> install_prompt_; |
| 110 }; |
| 111 |
| 112 class WebstorePrivateBeginInstallWithManifest3Function |
| 113 : public WebstorePrivateFunctionWithPermissionPrompt |
| 114 <api::webstore_private::BeginInstallWithManifest3::Params> { |
| 115 public: |
| 116 DECLARE_EXTENSION_FUNCTION("webstorePrivate.beginInstallWithManifest3", |
| 117 WEBSTOREPRIVATE_BEGININSTALLWITHMANIFEST3) |
| 118 |
| 119 WebstorePrivateBeginInstallWithManifest3Function(); |
| 120 |
| 121 private: |
| 122 ~WebstorePrivateBeginInstallWithManifest3Function() override; |
| 123 |
| 124 ExtensionFunction::ResponseValue RunExtraForResponse() override; |
| 125 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override; |
| 126 void InstallUIProceedHook() override; |
| 127 void InstallUIAbortHook(bool user_initiated) override; |
| 128 scoped_ptr<base::ListValue> CreateResults( |
| 129 api::webstore_private::Result result) const override; |
| 130 |
| 131 ChromeExtensionFunctionDetails chrome_details_; |
85 | 132 |
86 scoped_ptr<ScopedActiveInstall> scoped_active_install_; | 133 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 }; | 134 }; |
92 | 135 |
93 class WebstorePrivateCompleteInstallFunction | 136 class WebstorePrivateCompleteInstallFunction |
94 : public UIThreadExtensionFunction, | 137 : public UIThreadExtensionFunction, |
95 public WebstoreInstaller::Delegate { | 138 public WebstoreInstaller::Delegate { |
96 public: | 139 public: |
97 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", | 140 DECLARE_EXTENSION_FUNCTION("webstorePrivate.completeInstall", |
98 WEBSTOREPRIVATE_COMPLETEINSTALL) | 141 WEBSTOREPRIVATE_COMPLETEINSTALL) |
99 | 142 |
100 WebstorePrivateCompleteInstallFunction(); | 143 WebstorePrivateCompleteInstallFunction(); |
(...skipping 12 matching lines...) Expand all Loading... |
113 WebstoreInstaller::FailureReason reason) override; | 156 WebstoreInstaller::FailureReason reason) override; |
114 | 157 |
115 void OnInstallSuccess(const std::string& id); | 158 void OnInstallSuccess(const std::string& id); |
116 | 159 |
117 ChromeExtensionFunctionDetails chrome_details_; | 160 ChromeExtensionFunctionDetails chrome_details_; |
118 | 161 |
119 scoped_ptr<WebstoreInstaller::Approval> approval_; | 162 scoped_ptr<WebstoreInstaller::Approval> approval_; |
120 scoped_ptr<ScopedActiveInstall> scoped_active_install_; | 163 scoped_ptr<ScopedActiveInstall> scoped_active_install_; |
121 }; | 164 }; |
122 | 165 |
| 166 class WebstorePrivateShowPermissionPromptForDelegatedInstallFunction |
| 167 : public WebstorePrivateFunctionWithPermissionPrompt |
| 168 <api::webstore_private::ShowPermissionPromptForDelegatedInstall:: |
| 169 Params> { |
| 170 public: |
| 171 DECLARE_EXTENSION_FUNCTION( |
| 172 "webstorePrivate.showPermissionPromptForDelegatedInstall", |
| 173 WEBSTOREPRIVATE_SHOWPERMISSIONPROMPTFORDELEGATEDINSTALL) |
| 174 |
| 175 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction(); |
| 176 |
| 177 private: |
| 178 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() override; |
| 179 |
| 180 void ShowPrompt(ExtensionInstallPrompt* install_prompt) override; |
| 181 scoped_ptr<base::ListValue> CreateResults( |
| 182 api::webstore_private::Result result) const override; |
| 183 }; |
| 184 |
123 class WebstorePrivateEnableAppLauncherFunction | 185 class WebstorePrivateEnableAppLauncherFunction |
124 : public UIThreadExtensionFunction { | 186 : public UIThreadExtensionFunction { |
125 public: | 187 public: |
126 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", | 188 DECLARE_EXTENSION_FUNCTION("webstorePrivate.enableAppLauncher", |
127 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) | 189 WEBSTOREPRIVATE_ENABLEAPPLAUNCHER) |
128 | 190 |
129 WebstorePrivateEnableAppLauncherFunction(); | 191 WebstorePrivateEnableAppLauncherFunction(); |
130 | 192 |
131 private: | 193 private: |
132 ~WebstorePrivateEnableAppLauncherFunction() override; | 194 ~WebstorePrivateEnableAppLauncherFunction() override; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 private: | 338 private: |
277 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; | 339 ~WebstorePrivateGetEphemeralAppsEnabledFunction() override; |
278 | 340 |
279 // ExtensionFunction: | 341 // ExtensionFunction: |
280 ExtensionFunction::ResponseAction Run() override; | 342 ExtensionFunction::ResponseAction Run() override; |
281 }; | 343 }; |
282 | 344 |
283 } // namespace extensions | 345 } // namespace extensions |
284 | 346 |
285 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H
_ | 347 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBSTORE_PRIVATE_WEBSTORE_PRIVATE_API_H
_ |
OLD | NEW |