| 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 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 5 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "base/version.h" | 8 #include "base/version.h" |
| 9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 webstore_data_fetcher_->Start(); | 80 webstore_data_fetcher_->Start(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // | 83 // |
| 84 // Private interface implementation. | 84 // Private interface implementation. |
| 85 // | 85 // |
| 86 | 86 |
| 87 WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() { | 87 WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() { |
| 88 } | 88 } |
| 89 | 89 |
| 90 void WebstoreStandaloneInstaller::RunCallback(bool success, |
| 91 const std::string& error, |
| 92 webstore_install::Result result) { |
| 93 callback_.Run(success, error, result); |
| 94 } |
| 95 |
| 90 void WebstoreStandaloneInstaller::AbortInstall() { | 96 void WebstoreStandaloneInstaller::AbortInstall() { |
| 91 callback_.Reset(); | 97 callback_.Reset(); |
| 92 // Abort any in-progress fetches. | 98 // Abort any in-progress fetches. |
| 93 if (webstore_data_fetcher_) { | 99 if (webstore_data_fetcher_) { |
| 94 webstore_data_fetcher_.reset(); | 100 webstore_data_fetcher_.reset(); |
| 95 scoped_active_install_.reset(); | 101 scoped_active_install_.reset(); |
| 96 Release(); // Matches the AddRef in BeginInstall. | 102 Release(); // Matches the AddRef in BeginInstall. |
| 97 } | 103 } |
| 98 } | 104 } |
| 99 | 105 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 profile_, | 188 profile_, |
| 183 id_, | 189 id_, |
| 184 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()), | 190 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()), |
| 185 true)); | 191 true)); |
| 186 approval->skip_post_install_ui = !ShouldShowPostInstallUI(); | 192 approval->skip_post_install_ui = !ShouldShowPostInstallUI(); |
| 187 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble(); | 193 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble(); |
| 188 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); | 194 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
| 189 return approval.Pass(); | 195 return approval.Pass(); |
| 190 } | 196 } |
| 191 | 197 |
| 198 void WebstoreStandaloneInstaller::InstallUIProceed() { |
| 199 if (!CheckRequestorAlive()) { |
| 200 CompleteInstall(webstore_install::ABORTED, std::string()); |
| 201 return; |
| 202 } |
| 203 |
| 204 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); |
| 205 |
| 206 ExtensionService* extension_service = |
| 207 ExtensionSystem::Get(profile_)->extension_service(); |
| 208 const Extension* installed_extension = |
| 209 extension_service->GetExtensionById(id_, true /* include disabled */); |
| 210 if (installed_extension) { |
| 211 std::string install_message; |
| 212 webstore_install::Result install_result = webstore_install::SUCCESS; |
| 213 bool done = true; |
| 214 |
| 215 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { |
| 216 // Don't install a blacklisted extension. |
| 217 install_result = webstore_install::BLACKLISTED; |
| 218 install_message = kExtensionIsBlacklisted; |
| 219 } else if (util::IsEphemeralApp(installed_extension->id(), profile_) && |
| 220 !approval->is_ephemeral) { |
| 221 // If the target extension has already been installed ephemerally and is |
| 222 // up to date, it can be promoted to a regular installed extension and |
| 223 // downloading from the Web Store is not necessary. |
| 224 scoped_refptr<const Extension> extension_to_install = |
| 225 GetLocalizedExtensionForDisplay(); |
| 226 if (!extension_to_install.get()) { |
| 227 CompleteInstall(webstore_install::INVALID_MANIFEST, |
| 228 kInvalidManifestError); |
| 229 return; |
| 230 } |
| 231 |
| 232 if (installed_extension->version()->CompareTo( |
| 233 *extension_to_install->version()) < 0) { |
| 234 // If the existing extension is out of date, proceed with the install |
| 235 // to update the extension. |
| 236 done = false; |
| 237 } else { |
| 238 install_ui::ShowPostInstallUIForApproval( |
| 239 profile_, *approval, installed_extension); |
| 240 extension_service->PromoteEphemeralApp(installed_extension, false); |
| 241 } |
| 242 } else if (!extension_service->IsExtensionEnabled(id_)) { |
| 243 // If the extension is installed but disabled, and not blacklisted, |
| 244 // enable it. |
| 245 extension_service->EnableExtension(id_); |
| 246 } // else extension is installed and enabled; no work to be done. |
| 247 |
| 248 if (done) { |
| 249 CompleteInstall(install_result, install_message); |
| 250 return; |
| 251 } |
| 252 } |
| 253 |
| 254 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 255 profile_, |
| 256 this, |
| 257 GetWebContents(), |
| 258 id_, |
| 259 approval.Pass(), |
| 260 install_source_); |
| 261 installer->Start(); |
| 262 } |
| 263 |
| 264 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) { |
| 265 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError); |
| 266 } |
| 267 |
| 192 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() { | 268 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() { |
| 193 OnWebStoreDataFetcherDone(); | 269 OnWebStoreDataFetcherDone(); |
| 194 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR, | 270 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR, |
| 195 kWebstoreRequestError); | 271 kWebstoreRequestError); |
| 196 } | 272 } |
| 197 | 273 |
| 198 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess( | 274 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess( |
| 199 scoped_ptr<base::DictionaryValue> webstore_data) { | 275 scoped_ptr<base::DictionaryValue> webstore_data) { |
| 200 OnWebStoreDataFetcherDone(); | 276 OnWebStoreDataFetcherDone(); |
| 201 | 277 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 case WebstoreInstallHelper::Delegate::ICON_ERROR: | 393 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
| 318 install_result = webstore_install::ICON_ERROR; | 394 install_result = webstore_install::ICON_ERROR; |
| 319 break; | 395 break; |
| 320 default: | 396 default: |
| 321 break; | 397 break; |
| 322 } | 398 } |
| 323 | 399 |
| 324 CompleteInstall(install_result, error_message); | 400 CompleteInstall(install_result, error_message); |
| 325 } | 401 } |
| 326 | 402 |
| 327 void WebstoreStandaloneInstaller::InstallUIProceed() { | |
| 328 if (!CheckRequestorAlive()) { | |
| 329 CompleteInstall(webstore_install::ABORTED, std::string()); | |
| 330 return; | |
| 331 } | |
| 332 | |
| 333 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); | |
| 334 | |
| 335 ExtensionService* extension_service = | |
| 336 ExtensionSystem::Get(profile_)->extension_service(); | |
| 337 const Extension* installed_extension = | |
| 338 extension_service->GetExtensionById(id_, true /* include disabled */); | |
| 339 if (installed_extension) { | |
| 340 std::string install_message; | |
| 341 webstore_install::Result install_result = webstore_install::SUCCESS; | |
| 342 bool done = true; | |
| 343 | |
| 344 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { | |
| 345 // Don't install a blacklisted extension. | |
| 346 install_result = webstore_install::BLACKLISTED; | |
| 347 install_message = kExtensionIsBlacklisted; | |
| 348 } else if (util::IsEphemeralApp(installed_extension->id(), profile_) && | |
| 349 !approval->is_ephemeral) { | |
| 350 // If the target extension has already been installed ephemerally and is | |
| 351 // up to date, it can be promoted to a regular installed extension and | |
| 352 // downloading from the Web Store is not necessary. | |
| 353 scoped_refptr<const Extension> extension_to_install = | |
| 354 GetLocalizedExtensionForDisplay(); | |
| 355 if (!extension_to_install.get()) { | |
| 356 CompleteInstall(webstore_install::INVALID_MANIFEST, | |
| 357 kInvalidManifestError); | |
| 358 return; | |
| 359 } | |
| 360 | |
| 361 if (installed_extension->version()->CompareTo( | |
| 362 *extension_to_install->version()) < 0) { | |
| 363 // If the existing extension is out of date, proceed with the install | |
| 364 // to update the extension. | |
| 365 done = false; | |
| 366 } else { | |
| 367 install_ui::ShowPostInstallUIForApproval( | |
| 368 profile_, *approval, installed_extension); | |
| 369 extension_service->PromoteEphemeralApp(installed_extension, false); | |
| 370 } | |
| 371 } else if (!extension_service->IsExtensionEnabled(id_)) { | |
| 372 // If the extension is installed but disabled, and not blacklisted, | |
| 373 // enable it. | |
| 374 extension_service->EnableExtension(id_); | |
| 375 } // else extension is installed and enabled; no work to be done. | |
| 376 | |
| 377 if (done) { | |
| 378 CompleteInstall(install_result, install_message); | |
| 379 return; | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | |
| 384 profile_, | |
| 385 this, | |
| 386 GetWebContents(), | |
| 387 id_, | |
| 388 approval.Pass(), | |
| 389 install_source_); | |
| 390 installer->Start(); | |
| 391 } | |
| 392 | |
| 393 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) { | |
| 394 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError); | |
| 395 } | |
| 396 | |
| 397 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( | 403 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( |
| 398 const std::string& id) { | 404 const std::string& id) { |
| 399 CHECK_EQ(id_, id); | 405 CHECK_EQ(id_, id); |
| 400 CompleteInstall(webstore_install::SUCCESS, std::string()); | 406 CompleteInstall(webstore_install::SUCCESS, std::string()); |
| 401 } | 407 } |
| 402 | 408 |
| 403 void WebstoreStandaloneInstaller::OnExtensionInstallFailure( | 409 void WebstoreStandaloneInstaller::OnExtensionInstallFailure( |
| 404 const std::string& id, | 410 const std::string& id, |
| 405 const std::string& error, | 411 const std::string& error, |
| 406 WebstoreInstaller::FailureReason reason) { | 412 WebstoreInstaller::FailureReason reason) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { | 444 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { |
| 439 // An instance of this class is passed in as a delegate for the | 445 // An instance of this class is passed in as a delegate for the |
| 440 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and | 446 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and |
| 441 // therefore needs to remain alive until they are done. Clear the webstore | 447 // therefore needs to remain alive until they are done. Clear the webstore |
| 442 // data fetcher to avoid calling Release in AbortInstall while any of these | 448 // data fetcher to avoid calling Release in AbortInstall while any of these |
| 443 // operations are in progress. | 449 // operations are in progress. |
| 444 webstore_data_fetcher_.reset(); | 450 webstore_data_fetcher_.reset(); |
| 445 } | 451 } |
| 446 | 452 |
| 447 } // namespace extensions | 453 } // namespace extensions |
| OLD | NEW |