[email protected] | bdb74a2 | 2012-01-25 20:33:33 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 5 | #include "chrome/browser/extensions/webstore_standalone_installer.h" |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 6 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 9 | #include "base/values.h" |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 10 | #include "base/version.h" |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 11 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_install_prompt.h" |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 14 | #include "chrome/browser/extensions/install_tracker.h" |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 15 | #include "chrome/browser/extensions/webstore_data_fetcher.h" |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 17 | #include "components/crx_file/id_util.h" |
Mark Pilgrim | 445bb78 | 2017-12-08 19:47:12 | [diff] [blame] | 18 | #include "content/public/browser/storage_partition.h" |
[email protected] | 10c2d69 | 2012-05-11 05:32:23 | [diff] [blame] | 19 | #include "content/public/browser/web_contents.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 20 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 21 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 22 | #include "extensions/browser/extension_system.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 23 | #include "extensions/common/extension.h" |
rockot | 9065985 | 2014-09-18 19:31:52 | [diff] [blame] | 24 | #include "extensions/common/extension_urls.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 25 | #include "url/gurl.h" |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 26 | |
[email protected] | 26b5e32 | 2011-12-23 01:36:47 | [diff] [blame] | 27 | using content::WebContents; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 28 | |
[email protected] | 3d61a7f | 2012-07-12 19:11:25 | [diff] [blame] | 29 | namespace extensions { |
| 30 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 31 | WebstoreStandaloneInstaller::WebstoreStandaloneInstaller( |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 32 | const std::string& webstore_item_id, |
[email protected] | c1b2d04 | 2013-02-23 00:31:04 | [diff] [blame] | 33 | Profile* profile, |
[email protected] | c1b2d04 | 2013-02-23 00:31:04 | [diff] [blame] | 34 | const Callback& callback) |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 35 | : id_(webstore_item_id), |
[email protected] | d2a639e | 2012-09-17 07:41:21 | [diff] [blame] | 36 | callback_(callback), |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 37 | profile_(profile), |
[email protected] | 084e3548 | 2013-09-25 02:46:19 | [diff] [blame] | 38 | install_source_(WebstoreInstaller::INSTALL_SOURCE_INLINE), |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 39 | show_user_count_(true), |
[email protected] | c7bf745 | 2011-09-12 21:31:50 | [diff] [blame] | 40 | average_rating_(0.0), |
[email protected] | 5f2a475 | 2012-04-27 22:18:58 | [diff] [blame] | 41 | rating_count_(0) { |
[email protected] | c1b2d04 | 2013-02-23 00:31:04 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 44 | void WebstoreStandaloneInstaller::BeginInstall() { |
[email protected] | 3d6d67652 | 2013-10-14 20:44:55 | [diff] [blame] | 45 | // Add a ref to keep this alive for WebstoreDataFetcher. |
| 46 | // All code paths from here eventually lead to either CompleteInstall or |
| 47 | // AbortInstall, which both release this ref. |
| 48 | AddRef(); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 49 | |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 50 | if (!crx_file::id_util::IdIsValid(id_)) { |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 51 | CompleteInstall(webstore_install::INVALID_ID, |
| 52 | webstore_install::kInvalidWebstoreItemId); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | |
[email protected] | ced522c | 2014-07-23 20:23:59 | [diff] [blame] | 56 | webstore_install::Result result = webstore_install::OTHER_ERROR; |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 57 | std::string error; |
| 58 | if (!EnsureUniqueInstall(&result, &error)) { |
| 59 | CompleteInstall(result, error); |
| 60 | return; |
| 61 | } |
| 62 | |
[email protected] | b4574c0 | 2011-11-17 06:19:13 | [diff] [blame] | 63 | // Use the requesting page as the referrer both since that is more correct |
| 64 | // (it is the page that caused this request to happen) and so that we can |
| 65 | // track top sites that trigger inline install requests. |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 66 | webstore_data_fetcher_.reset( |
| 67 | new WebstoreDataFetcher(this, GetRequestorURL(), id_)); |
robertshield | 1fc1a4a | 2017-02-01 15:18:33 | [diff] [blame] | 68 | |
Jialiu Lin | 9aa277c | 2018-05-08 00:02:19 | [diff] [blame] | 69 | webstore_data_fetcher_->SetPostData(GetPostData()); |
robertshield | 1fc1a4a | 2017-02-01 15:18:33 | [diff] [blame] | 70 | |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 71 | webstore_data_fetcher_->Start( |
| 72 | content::BrowserContext::GetDefaultStoragePartition(profile_) |
| 73 | ->GetURLLoaderFactoryForBrowserProcess() |
| 74 | .get()); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 77 | // |
| 78 | // Private interface implementation. |
| 79 | // |
| 80 | |
| 81 | WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() { |
| 82 | } |
| 83 | |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 84 | void WebstoreStandaloneInstaller::RunCallback(bool success, |
| 85 | const std::string& error, |
| 86 | webstore_install::Result result) { |
| 87 | callback_.Run(success, error, result); |
| 88 | } |
| 89 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 90 | void WebstoreStandaloneInstaller::AbortInstall() { |
| 91 | callback_.Reset(); |
| 92 | // Abort any in-progress fetches. |
| 93 | if (webstore_data_fetcher_) { |
| 94 | webstore_data_fetcher_.reset(); |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 95 | scoped_active_install_.reset(); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 96 | Release(); // Matches the AddRef in BeginInstall. |
| 97 | } |
| 98 | } |
| 99 | |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 100 | bool WebstoreStandaloneInstaller::EnsureUniqueInstall( |
| 101 | webstore_install::Result* reason, |
| 102 | std::string* error) { |
| 103 | InstallTracker* tracker = InstallTracker::Get(profile_); |
| 104 | DCHECK(tracker); |
| 105 | |
| 106 | const ActiveInstallData* existing_install_data = |
| 107 | tracker->GetActiveInstall(id_); |
| 108 | if (existing_install_data) { |
benwells | cb4422c1 | 2015-10-13 23:38:46 | [diff] [blame] | 109 | *reason = webstore_install::INSTALL_IN_PROGRESS; |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 110 | *error = webstore_install::kInstallInProgressError; |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 111 | return false; |
| 112 | } |
| 113 | |
| 114 | ActiveInstallData install_data(id_); |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 115 | scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); |
| 116 | return true; |
| 117 | } |
| 118 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 119 | void WebstoreStandaloneInstaller::CompleteInstall( |
| 120 | webstore_install::Result result, |
| 121 | const std::string& error) { |
[email protected] | 773272b | 2014-07-18 05:48:35 | [diff] [blame] | 122 | scoped_active_install_.reset(); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 123 | if (!callback_.is_null()) |
[email protected] | ced522c | 2014-07-23 20:23:59 | [diff] [blame] | 124 | callback_.Run(result == webstore_install::SUCCESS, error, result); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 125 | Release(); // Matches the AddRef in BeginInstall. |
| 126 | } |
| 127 | |
| 128 | void WebstoreStandaloneInstaller::ProceedWithInstallPrompt() { |
| 129 | install_prompt_ = CreateInstallPrompt(); |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 130 | if (install_prompt_.get()) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 131 | ShowInstallUI(); |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 132 | // Control flow finishes up in OnInstallPromptDone(). |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 133 | } else { |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 134 | OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | scoped_refptr<const Extension> |
| 139 | WebstoreStandaloneInstaller::GetLocalizedExtensionForDisplay() { |
| 140 | if (!localized_extension_for_display_.get()) { |
| 141 | DCHECK(manifest_.get()); |
| 142 | if (!manifest_.get()) |
| 143 | return NULL; |
| 144 | |
| 145 | std::string error; |
| 146 | localized_extension_for_display_ = |
| 147 | ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 148 | manifest_.get(), |
| 149 | Extension::REQUIRE_KEY | Extension::FROM_WEBSTORE, |
| 150 | id_, |
| 151 | localized_name_, |
| 152 | localized_description_, |
| 153 | &error); |
| 154 | } |
| 155 | return localized_extension_for_display_.get(); |
| 156 | } |
| 157 | |
Jialiu Lin | 9aa277c | 2018-05-08 00:02:19 | [diff] [blame] | 158 | std::string WebstoreStandaloneInstaller::GetPostData() { |
robertshield | 1fc1a4a | 2017-02-01 15:18:33 | [diff] [blame] | 159 | return std::string(); |
| 160 | } |
| 161 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 162 | void WebstoreStandaloneInstaller::OnManifestParsed() { |
| 163 | ProceedWithInstallPrompt(); |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 164 | } |
| 165 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 166 | std::unique_ptr<ExtensionInstallPrompt> |
[email protected] | f8b23b4 | 2013-06-27 20:12:14 | [diff] [blame] | 167 | WebstoreStandaloneInstaller::CreateInstallUI() { |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 168 | return std::make_unique<ExtensionInstallPrompt>(GetWebContents()); |
[email protected] | f8b23b4 | 2013-06-27 20:12:14 | [diff] [blame] | 169 | } |
| 170 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 171 | std::unique_ptr<WebstoreInstaller::Approval> |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 172 | WebstoreStandaloneInstaller::CreateApproval() const { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 173 | std::unique_ptr<WebstoreInstaller::Approval> approval( |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 174 | WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 175 | profile_, id_, |
rdevlin.cronin | 165732a4 | 2016-07-18 22:25:08 | [diff] [blame] | 176 | std::unique_ptr<base::DictionaryValue>(manifest_->DeepCopy()), true)); |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 177 | approval->skip_post_install_ui = !ShouldShowPostInstallUI(); |
| 178 | approval->use_app_installed_bubble = ShouldShowAppInstalledBubble(); |
| 179 | approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 180 | return approval; |
[email protected] | ce35418b | 2013-11-25 01:22:33 | [diff] [blame] | 181 | } |
| 182 | |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 183 | void WebstoreStandaloneInstaller::OnInstallPromptDone( |
| 184 | ExtensionInstallPrompt::Result result) { |
| 185 | if (result == ExtensionInstallPrompt::Result::USER_CANCELED) { |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 186 | CompleteInstall(webstore_install::USER_CANCELLED, |
| 187 | webstore_install::kUserCancelledError); |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
| 191 | if (result == ExtensionInstallPrompt::Result::ABORTED || |
| 192 | !CheckRequestorAlive()) { |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 193 | CompleteInstall(webstore_install::ABORTED, std::string()); |
| 194 | return; |
| 195 | } |
| 196 | |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 197 | DCHECK(result == ExtensionInstallPrompt::Result::ACCEPTED); |
| 198 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 199 | std::unique_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 200 | |
| 201 | ExtensionService* extension_service = |
| 202 | ExtensionSystem::Get(profile_)->extension_service(); |
| 203 | const Extension* installed_extension = |
| 204 | extension_service->GetExtensionById(id_, true /* include disabled */); |
| 205 | if (installed_extension) { |
| 206 | std::string install_message; |
| 207 | webstore_install::Result install_result = webstore_install::SUCCESS; |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 208 | |
| 209 | if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { |
| 210 | // Don't install a blacklisted extension. |
| 211 | install_result = webstore_install::BLACKLISTED; |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 212 | install_message = webstore_install::kExtensionIsBlacklisted; |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 213 | } else if (!extension_service->IsExtensionEnabled(id_)) { |
| 214 | // If the extension is installed but disabled, and not blacklisted, |
| 215 | // enable it. |
| 216 | extension_service->EnableExtension(id_); |
| 217 | } // else extension is installed and enabled; no work to be done. |
| 218 | |
lazyboy | 39a52e7c | 2017-04-06 18:18:38 | [diff] [blame] | 219 | CompleteInstall(install_result, install_message); |
| 220 | return; |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 221 | } |
| 222 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 223 | scoped_refptr<WebstoreInstaller> installer = |
| 224 | new WebstoreInstaller(profile_, this, GetWebContents(), id_, |
| 225 | std::move(approval), install_source_); |
rdevlin.cronin | 5f6b69d | 2014-09-20 01:23:35 | [diff] [blame] | 226 | installer->Start(); |
| 227 | } |
| 228 | |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 229 | void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() { |
[email protected] | e263a6b6 | 2014-06-05 23:19:49 | [diff] [blame] | 230 | OnWebStoreDataFetcherDone(); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 231 | CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 232 | webstore_install::kWebstoreRequestError); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 233 | } |
| 234 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 235 | void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess( |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 236 | std::unique_ptr<base::DictionaryValue> webstore_data) { |
[email protected] | e263a6b6 | 2014-06-05 23:19:49 | [diff] [blame] | 237 | OnWebStoreDataFetcherDone(); |
| 238 | |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 239 | if (!CheckRequestorAlive()) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 240 | CompleteInstall(webstore_install::ABORTED, std::string()); |
[email protected] | 4693243e | 2011-09-09 23:52:37 | [diff] [blame] | 241 | return; |
| 242 | } |
| 243 | |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 244 | std::string error; |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 245 | |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 246 | if (!CheckInlineInstallPermitted(*webstore_data, &error)) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 247 | CompleteInstall(webstore_install::NOT_PERMITTED, error); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 248 | return; |
| 249 | } |
| 250 | |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 251 | if (!CheckRequestorPermitted(*webstore_data, &error)) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 252 | CompleteInstall(webstore_install::NOT_PERMITTED, error); |
[email protected] | dd5161a | 2011-09-14 17:40:17 | [diff] [blame] | 253 | return; |
| 254 | } |
| 255 | |
| 256 | // Manifest, number of users, average rating and rating count are required. |
| 257 | std::string manifest; |
| 258 | if (!webstore_data->GetString(kManifestKey, &manifest) || |
| 259 | !webstore_data->GetString(kUsersKey, &localized_user_count_) || |
[email protected] | 5fdbd6f | 2011-09-01 17:33:04 | [diff] [blame] | 260 | !webstore_data->GetDouble(kAverageRatingKey, &average_rating_) || |
| 261 | !webstore_data->GetInteger(kRatingCountKey, &rating_count_)) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 262 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 263 | webstore_install::kInvalidWebstoreResponseError); |
[email protected] | 5fdbd6f | 2011-09-01 17:33:04 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
[email protected] | dcde34b3 | 2013-07-31 02:28:45 | [diff] [blame] | 267 | // Optional. |
| 268 | show_user_count_ = true; |
| 269 | webstore_data->GetBoolean(kShowUserCountKey, &show_user_count_); |
| 270 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 271 | if (average_rating_ < ExtensionInstallPrompt::kMinExtensionRating || |
| 272 | average_rating_ > ExtensionInstallPrompt::kMaxExtensionRating) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 273 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 274 | webstore_install::kInvalidWebstoreResponseError); |
[email protected] | 5fdbd6f | 2011-09-01 17:33:04 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | |
| 278 | // Localized name and description are optional. |
| 279 | if ((webstore_data->HasKey(kLocalizedNameKey) && |
| 280 | !webstore_data->GetString(kLocalizedNameKey, &localized_name_)) || |
| 281 | (webstore_data->HasKey(kLocalizedDescriptionKey) && |
| 282 | !webstore_data->GetString( |
| 283 | kLocalizedDescriptionKey, &localized_description_))) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 284 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 285 | webstore_install::kInvalidWebstoreResponseError); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 286 | return; |
| 287 | } |
| 288 | |
| 289 | // Icon URL is optional. |
| 290 | GURL icon_url; |
| 291 | if (webstore_data->HasKey(kIconUrlKey)) { |
| 292 | std::string icon_url_string; |
| 293 | if (!webstore_data->GetString(kIconUrlKey, &icon_url_string)) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 294 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 295 | webstore_install::kInvalidWebstoreResponseError); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 296 | return; |
| 297 | } |
csharrison | 5d1f214 | 2016-11-22 20:25:47 | [diff] [blame] | 298 | icon_url = extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 299 | if (!icon_url.is_valid()) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 300 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 301 | webstore_install::kInvalidWebstoreResponseError); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | } |
| 305 | |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 306 | // Assume ownership of webstore_data. |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 307 | webstore_data_ = std::move(webstore_data); |
[email protected] | a221ef09 | 2011-09-07 01:34:10 | [diff] [blame] | 308 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 309 | scoped_refptr<WebstoreInstallHelper> helper = |
Mark Pilgrim | 445bb78 | 2017-12-08 19:47:12 | [diff] [blame] | 310 | new WebstoreInstallHelper(this, id_, manifest, icon_url); |
thestig | 144c0c9 | 2017-05-18 05:58:02 | [diff] [blame] | 311 | // The helper will call us back via OnWebstoreParseSuccess() or |
| 312 | // OnWebstoreParseFailure(). |
Mark Pilgrim | 445bb78 | 2017-12-08 19:47:12 | [diff] [blame] | 313 | helper->Start(content::BrowserContext::GetDefaultStoragePartition(profile_) |
John Abd-El-Malek | a728915 | 2018-02-17 00:16:19 | [diff] [blame] | 314 | ->GetURLLoaderFactoryForBrowserProcess() |
| 315 | .get()); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 316 | } |
| 317 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 318 | void WebstoreStandaloneInstaller::OnWebstoreResponseParseFailure( |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 319 | const std::string& error) { |
[email protected] | e263a6b6 | 2014-06-05 23:19:49 | [diff] [blame] | 320 | OnWebStoreDataFetcherDone(); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 321 | CompleteInstall(webstore_install::INVALID_WEBSTORE_RESPONSE, error); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 322 | } |
| 323 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 324 | void WebstoreStandaloneInstaller::OnWebstoreParseSuccess( |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 325 | const std::string& id, |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 326 | const SkBitmap& icon, |
| 327 | base::DictionaryValue* manifest) { |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 328 | CHECK_EQ(id_, id); |
| 329 | |
| 330 | if (!CheckRequestorAlive()) { |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 331 | CompleteInstall(webstore_install::ABORTED, std::string()); |
[email protected] | 2fd920fb | 2011-09-08 23:33:00 | [diff] [blame] | 332 | return; |
| 333 | } |
| 334 | |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 335 | manifest_.reset(manifest); |
| 336 | icon_ = icon; |
| 337 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 338 | OnManifestParsed(); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 339 | } |
| 340 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 341 | void WebstoreStandaloneInstaller::OnWebstoreParseFailure( |
[email protected] | 98e4e52 | 2011-10-25 13:00:16 | [diff] [blame] | 342 | const std::string& id, |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 343 | InstallHelperResultCode result_code, |
| 344 | const std::string& error_message) { |
[email protected] | ced522c | 2014-07-23 20:23:59 | [diff] [blame] | 345 | webstore_install::Result install_result = webstore_install::OTHER_ERROR; |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 346 | switch (result_code) { |
| 347 | case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
| 348 | install_result = webstore_install::INVALID_MANIFEST; |
| 349 | break; |
| 350 | case WebstoreInstallHelper::Delegate::ICON_ERROR: |
| 351 | install_result = webstore_install::ICON_ERROR; |
| 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | CompleteInstall(install_result, error_message); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 358 | } |
| 359 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 360 | void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( |
| 361 | const std::string& id) { |
[email protected] | cb08ba2 | 2011-10-19 21:41:40 | [diff] [blame] | 362 | CHECK_EQ(id_, id); |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 363 | CompleteInstall(webstore_install::SUCCESS, std::string()); |
[email protected] | cb08ba2 | 2011-10-19 21:41:40 | [diff] [blame] | 364 | } |
| 365 | |
[email protected] | 734bcec | 2012-10-08 20:29:05 | [diff] [blame] | 366 | void WebstoreStandaloneInstaller::OnExtensionInstallFailure( |
[email protected] | bcd1eaf7 | 2012-10-03 05:42:29 | [diff] [blame] | 367 | const std::string& id, |
| 368 | const std::string& error, |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 369 | WebstoreInstaller::FailureReason reason) { |
[email protected] | cb08ba2 | 2011-10-19 21:41:40 | [diff] [blame] | 370 | CHECK_EQ(id_, id); |
[email protected] | cb08ba2 | 2011-10-19 21:41:40 | [diff] [blame] | 371 | |
[email protected] | ced522c | 2014-07-23 20:23:59 | [diff] [blame] | 372 | webstore_install::Result install_result = webstore_install::OTHER_ERROR; |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 373 | switch (reason) { |
| 374 | case WebstoreInstaller::FAILURE_REASON_CANCELLED: |
| 375 | install_result = webstore_install::USER_CANCELLED; |
| 376 | break; |
| 377 | case WebstoreInstaller::FAILURE_REASON_DEPENDENCY_NOT_FOUND: |
| 378 | case WebstoreInstaller::FAILURE_REASON_DEPENDENCY_NOT_SHARED_MODULE: |
| 379 | install_result = webstore_install::MISSING_DEPENDENCIES; |
| 380 | break; |
| 381 | default: |
| 382 | break; |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 383 | } |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 384 | |
[email protected] | 9c7b309 | 2014-06-21 01:19:03 | [diff] [blame] | 385 | CompleteInstall(install_result, error); |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 386 | } |
[email protected] | 5f2a475 | 2012-04-27 22:18:58 | [diff] [blame] | 387 | |
[email protected] | e263a6b6 | 2014-06-05 23:19:49 | [diff] [blame] | 388 | void WebstoreStandaloneInstaller::ShowInstallUI() { |
dcheng | c704794 | 2014-08-26 05:05:31 | [diff] [blame] | 389 | scoped_refptr<const Extension> localized_extension = |
| 390 | GetLocalizedExtensionForDisplay(); |
dcheng | 40eae71 | 2014-08-27 16:56:10 | [diff] [blame] | 391 | if (!localized_extension.get()) { |
rdevlin.cronin | d30a8bd | 2016-06-30 16:02:29 | [diff] [blame] | 392 | CompleteInstall(webstore_install::INVALID_MANIFEST, |
| 393 | webstore_install::kInvalidManifestError); |
[email protected] | d44ec7b | 2013-03-15 04:34:34 | [diff] [blame] | 394 | return; |
[email protected] | 5f2a475 | 2012-04-27 22:18:58 | [diff] [blame] | 395 | } |
[email protected] | 5f2a475 | 2012-04-27 22:18:58 | [diff] [blame] | 396 | |
[email protected] | f8b23b4 | 2013-06-27 20:12:14 | [diff] [blame] | 397 | install_ui_ = CreateInstallUI(); |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 398 | install_ui_->ShowDialog( |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 399 | base::Bind(&WebstoreStandaloneInstaller::OnInstallPromptDone, this), |
| 400 | localized_extension.get(), &icon_, std::move(install_prompt_), |
rdevlin.cronin | f84cab7 | 2015-12-12 03:45:23 | [diff] [blame] | 401 | ExtensionInstallPrompt::GetDefaultShowDialogCallback()); |
[email protected] | 5f2a475 | 2012-04-27 22:18:58 | [diff] [blame] | 402 | } |
[email protected] | 3d61a7f | 2012-07-12 19:11:25 | [diff] [blame] | 403 | |
[email protected] | e263a6b6 | 2014-06-05 23:19:49 | [diff] [blame] | 404 | void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { |
| 405 | // An instance of this class is passed in as a delegate for the |
| 406 | // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and |
| 407 | // therefore needs to remain alive until they are done. Clear the webstore |
| 408 | // data fetcher to avoid calling Release in AbortInstall while any of these |
| 409 | // operations are in progress. |
| 410 | webstore_data_fetcher_.reset(); |
| 411 | } |
| 412 | |
[email protected] | 3d61a7f | 2012-07-12 19:11:25 | [diff] [blame] | 413 | } // namespace extensions |