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