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