| 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/api/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // static | 208 // static |
| 209 scoped_ptr<WebstoreInstaller::Approval> | 209 scoped_ptr<WebstoreInstaller::Approval> |
| 210 WebstorePrivateApi::PopApprovalForTesting( | 210 WebstorePrivateApi::PopApprovalForTesting( |
| 211 Profile* profile, const std::string& extension_id) { | 211 Profile* profile, const std::string& extension_id) { |
| 212 return g_pending_approvals.Get().PopApproval(profile, extension_id); | 212 return g_pending_approvals.Get().PopApproval(profile, extension_id); |
| 213 } | 213 } |
| 214 | 214 |
| 215 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} | 215 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} |
| 216 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} | 216 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} |
| 217 | 217 |
| 218 bool WebstorePrivateInstallBundleFunction::RunImpl() { | 218 bool WebstorePrivateInstallBundleFunction::RunAsync() { |
| 219 scoped_ptr<InstallBundle::Params> params( | 219 scoped_ptr<InstallBundle::Params> params( |
| 220 InstallBundle::Params::Create(*args_)); | 220 InstallBundle::Params::Create(*args_)); |
| 221 EXTENSION_FUNCTION_VALIDATE(params); | 221 EXTENSION_FUNCTION_VALIDATE(params); |
| 222 | 222 |
| 223 BundleInstaller::ItemList items; | 223 BundleInstaller::ItemList items; |
| 224 if (!ReadBundleInfo(*params, &items)) | 224 if (!ReadBundleInfo(*params, &items)) |
| 225 return false; | 225 return false; |
| 226 | 226 |
| 227 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); | 227 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); |
| 228 | 228 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 254 | 254 |
| 255 void WebstorePrivateInstallBundleFunction::OnBundleInstallCanceled( | 255 void WebstorePrivateInstallBundleFunction::OnBundleInstallCanceled( |
| 256 bool user_initiated) { | 256 bool user_initiated) { |
| 257 if (user_initiated) | 257 if (user_initiated) |
| 258 error_ = "user_canceled"; | 258 error_ = "user_canceled"; |
| 259 else | 259 else |
| 260 error_ = "unknown_error"; | 260 error_ = "unknown_error"; |
| 261 | 261 |
| 262 SendResponse(false); | 262 SendResponse(false); |
| 263 | 263 |
| 264 Release(); // Balanced in RunImpl(). | 264 Release(); // Balanced in RunAsync(). |
| 265 } | 265 } |
| 266 | 266 |
| 267 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { | 267 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { |
| 268 SendResponse(true); | 268 SendResponse(true); |
| 269 | 269 |
| 270 Release(); // Balanced in RunImpl(). | 270 Release(); // Balanced in RunAsync(). |
| 271 } | 271 } |
| 272 | 272 |
| 273 WebstorePrivateBeginInstallWithManifest3Function:: | 273 WebstorePrivateBeginInstallWithManifest3Function:: |
| 274 WebstorePrivateBeginInstallWithManifest3Function() {} | 274 WebstorePrivateBeginInstallWithManifest3Function() {} |
| 275 | 275 |
| 276 WebstorePrivateBeginInstallWithManifest3Function:: | 276 WebstorePrivateBeginInstallWithManifest3Function:: |
| 277 ~WebstorePrivateBeginInstallWithManifest3Function() {} | 277 ~WebstorePrivateBeginInstallWithManifest3Function() {} |
| 278 | 278 |
| 279 bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { | 279 bool WebstorePrivateBeginInstallWithManifest3Function::RunAsync() { |
| 280 params_ = BeginInstallWithManifest3::Params::Create(*args_); | 280 params_ = BeginInstallWithManifest3::Params::Create(*args_); |
| 281 EXTENSION_FUNCTION_VALIDATE(params_); | 281 EXTENSION_FUNCTION_VALIDATE(params_); |
| 282 | 282 |
| 283 if (!extensions::Extension::IdIsValid(params_->details.id)) { | 283 if (!extensions::Extension::IdIsValid(params_->details.id)) { |
| 284 SetResultCode(INVALID_ID); | 284 SetResultCode(INVALID_ID); |
| 285 error_ = kInvalidIdError; | 285 error_ = kInvalidIdError; |
| 286 return false; | 286 return false; |
| 287 } | 287 } |
| 288 | 288 |
| 289 if (params_->details.icon_data && params_->details.icon_url) { | 289 if (params_->details.icon_data && params_->details.icon_url) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: | 427 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
| 428 SetResultCode(MANIFEST_ERROR); | 428 SetResultCode(MANIFEST_ERROR); |
| 429 break; | 429 break; |
| 430 default: | 430 default: |
| 431 CHECK(false); | 431 CHECK(false); |
| 432 } | 432 } |
| 433 error_ = error_message; | 433 error_ = error_message; |
| 434 g_pending_installs.Get().EraseInstall(GetProfile(), id); | 434 g_pending_installs.Get().EraseInstall(GetProfile(), id); |
| 435 SendResponse(false); | 435 SendResponse(false); |
| 436 | 436 |
| 437 // Matches the AddRef in RunImpl(). | 437 // Matches the AddRef in RunAsync(). |
| 438 Release(); | 438 Release(); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( | 441 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( |
| 442 const GoogleServiceAuthError& error) { | 442 const GoogleServiceAuthError& error) { |
| 443 signin_tracker_.reset(); | 443 signin_tracker_.reset(); |
| 444 | 444 |
| 445 SetResultCode(SIGNIN_FAILED); | 445 SetResultCode(SIGNIN_FAILED); |
| 446 error_ = error.ToString(); | 446 error_ = error.ToString(); |
| 447 g_pending_installs.Get().EraseInstall(GetProfile(), params_->details.id); | 447 g_pending_installs.Get().EraseInstall(GetProfile(), params_->details.id); |
| 448 SendResponse(false); | 448 SendResponse(false); |
| 449 | 449 |
| 450 // Matches the AddRef in RunImpl(). | 450 // Matches the AddRef in RunAsync(). |
| 451 Release(); | 451 Release(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() { | 454 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() { |
| 455 signin_tracker_.reset(); | 455 signin_tracker_.reset(); |
| 456 | 456 |
| 457 SigninCompletedOrNotNeeded(); | 457 SigninCompletedOrNotNeeded(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void WebstorePrivateBeginInstallWithManifest3Function::MergeSessionComplete( | 460 void WebstorePrivateBeginInstallWithManifest3Function::MergeSessionComplete( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 SetResultCode(ERROR_NONE); | 497 SetResultCode(ERROR_NONE); |
| 498 SendResponse(true); | 498 SendResponse(true); |
| 499 | 499 |
| 500 // The Permissions_Install histogram is recorded from the ExtensionService | 500 // The Permissions_Install histogram is recorded from the ExtensionService |
| 501 // for all extension installs, so we only need to record the web store | 501 // for all extension installs, so we only need to record the web store |
| 502 // specific histogram here. | 502 // specific histogram here. |
| 503 ExtensionService::RecordPermissionMessagesHistogram( | 503 ExtensionService::RecordPermissionMessagesHistogram( |
| 504 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall"); | 504 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall"); |
| 505 | 505 |
| 506 // Matches the AddRef in RunImpl(). | 506 // Matches the AddRef in RunAsync(). |
| 507 Release(); | 507 Release(); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( | 510 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( |
| 511 bool user_initiated) { | 511 bool user_initiated) { |
| 512 error_ = kUserCancelledError; | 512 error_ = kUserCancelledError; |
| 513 SetResultCode(USER_CANCELLED); | 513 SetResultCode(USER_CANCELLED); |
| 514 g_pending_installs.Get().EraseInstall(GetProfile(), params_->details.id); | 514 g_pending_installs.Get().EraseInstall(GetProfile(), params_->details.id); |
| 515 SendResponse(false); | 515 SendResponse(false); |
| 516 | 516 |
| 517 // The web store install histograms are a subset of the install histograms. | 517 // The web store install histograms are a subset of the install histograms. |
| 518 // We need to record both histograms here since CrxInstaller::InstallUIAbort | 518 // We need to record both histograms here since CrxInstaller::InstallUIAbort |
| 519 // is never called for web store install cancellations. | 519 // is never called for web store install cancellations. |
| 520 std::string histogram_name = user_initiated ? | 520 std::string histogram_name = user_initiated ? |
| 521 "Extensions.Permissions_WebStoreInstallCancel" : | 521 "Extensions.Permissions_WebStoreInstallCancel" : |
| 522 "Extensions.Permissions_WebStoreInstallAbort"; | 522 "Extensions.Permissions_WebStoreInstallAbort"; |
| 523 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 523 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 524 histogram_name.c_str()); | 524 histogram_name.c_str()); |
| 525 | 525 |
| 526 histogram_name = user_initiated ? | 526 histogram_name = user_initiated ? |
| 527 "Extensions.Permissions_InstallCancel" : | 527 "Extensions.Permissions_InstallCancel" : |
| 528 "Extensions.Permissions_InstallAbort"; | 528 "Extensions.Permissions_InstallAbort"; |
| 529 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 529 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
| 530 histogram_name.c_str()); | 530 histogram_name.c_str()); |
| 531 | 531 |
| 532 // Matches the AddRef in RunImpl(). | 532 // Matches the AddRef in RunAsync(). |
| 533 Release(); | 533 Release(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 WebstorePrivateCompleteInstallFunction:: | 536 WebstorePrivateCompleteInstallFunction:: |
| 537 WebstorePrivateCompleteInstallFunction() {} | 537 WebstorePrivateCompleteInstallFunction() {} |
| 538 | 538 |
| 539 WebstorePrivateCompleteInstallFunction:: | 539 WebstorePrivateCompleteInstallFunction:: |
| 540 ~WebstorePrivateCompleteInstallFunction() {} | 540 ~WebstorePrivateCompleteInstallFunction() {} |
| 541 | 541 |
| 542 bool WebstorePrivateCompleteInstallFunction::RunImpl() { | 542 bool WebstorePrivateCompleteInstallFunction::RunAsync() { |
| 543 scoped_ptr<CompleteInstall::Params> params( | 543 scoped_ptr<CompleteInstall::Params> params( |
| 544 CompleteInstall::Params::Create(*args_)); | 544 CompleteInstall::Params::Create(*args_)); |
| 545 EXTENSION_FUNCTION_VALIDATE(params); | 545 EXTENSION_FUNCTION_VALIDATE(params); |
| 546 if (!extensions::Extension::IdIsValid(params->expected_id)) { | 546 if (!extensions::Extension::IdIsValid(params->expected_id)) { |
| 547 error_ = kInvalidIdError; | 547 error_ = kInvalidIdError; |
| 548 return false; | 548 return false; |
| 549 } | 549 } |
| 550 | 550 |
| 551 approval_ = g_pending_approvals.Get() | 551 approval_ = g_pending_approvals.Get() |
| 552 .PopApproval(GetProfile(), params->expected_id) | 552 .PopApproval(GetProfile(), params->expected_id) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 const std::string& id) { | 594 const std::string& id) { |
| 595 if (test_webstore_installer_delegate) | 595 if (test_webstore_installer_delegate) |
| 596 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); | 596 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
| 597 | 597 |
| 598 VLOG(1) << "Install success, sending response"; | 598 VLOG(1) << "Install success, sending response"; |
| 599 g_pending_installs.Get().EraseInstall(GetProfile(), id); | 599 g_pending_installs.Get().EraseInstall(GetProfile(), id); |
| 600 SendResponse(true); | 600 SendResponse(true); |
| 601 | 601 |
| 602 RecordWebstoreExtensionInstallResult(true); | 602 RecordWebstoreExtensionInstallResult(true); |
| 603 | 603 |
| 604 // Matches the AddRef in RunImpl(). | 604 // Matches the AddRef in RunAsync(). |
| 605 Release(); | 605 Release(); |
| 606 } | 606 } |
| 607 | 607 |
| 608 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure( | 608 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure( |
| 609 const std::string& id, | 609 const std::string& id, |
| 610 const std::string& error, | 610 const std::string& error, |
| 611 WebstoreInstaller::FailureReason reason) { | 611 WebstoreInstaller::FailureReason reason) { |
| 612 if (test_webstore_installer_delegate) { | 612 if (test_webstore_installer_delegate) { |
| 613 test_webstore_installer_delegate->OnExtensionInstallFailure( | 613 test_webstore_installer_delegate->OnExtensionInstallFailure( |
| 614 id, error, reason); | 614 id, error, reason); |
| 615 } | 615 } |
| 616 | 616 |
| 617 error_ = error; | 617 error_ = error; |
| 618 VLOG(1) << "Install failed, sending response"; | 618 VLOG(1) << "Install failed, sending response"; |
| 619 g_pending_installs.Get().EraseInstall(GetProfile(), id); | 619 g_pending_installs.Get().EraseInstall(GetProfile(), id); |
| 620 SendResponse(false); | 620 SendResponse(false); |
| 621 | 621 |
| 622 RecordWebstoreExtensionInstallResult(false); | 622 RecordWebstoreExtensionInstallResult(false); |
| 623 | 623 |
| 624 // Matches the AddRef in RunImpl(). | 624 // Matches the AddRef in RunAsync(). |
| 625 Release(); | 625 Release(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 WebstorePrivateEnableAppLauncherFunction:: | 628 WebstorePrivateEnableAppLauncherFunction:: |
| 629 WebstorePrivateEnableAppLauncherFunction() {} | 629 WebstorePrivateEnableAppLauncherFunction() {} |
| 630 | 630 |
| 631 WebstorePrivateEnableAppLauncherFunction:: | 631 WebstorePrivateEnableAppLauncherFunction:: |
| 632 ~WebstorePrivateEnableAppLauncherFunction() {} | 632 ~WebstorePrivateEnableAppLauncherFunction() {} |
| 633 | 633 |
| 634 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { | 634 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 666 } |
| 667 | 667 |
| 668 WebstorePrivateGetWebGLStatusFunction:: | 668 WebstorePrivateGetWebGLStatusFunction:: |
| 669 ~WebstorePrivateGetWebGLStatusFunction() {} | 669 ~WebstorePrivateGetWebGLStatusFunction() {} |
| 670 | 670 |
| 671 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { | 671 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { |
| 672 results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results:: | 672 results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results:: |
| 673 ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked")); | 673 ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked")); |
| 674 } | 674 } |
| 675 | 675 |
| 676 bool WebstorePrivateGetWebGLStatusFunction::RunImpl() { | 676 bool WebstorePrivateGetWebGLStatusFunction::RunAsync() { |
| 677 feature_checker_->CheckGPUFeatureAvailability(); | 677 feature_checker_->CheckGPUFeatureAvailability(); |
| 678 return true; | 678 return true; |
| 679 } | 679 } |
| 680 | 680 |
| 681 void WebstorePrivateGetWebGLStatusFunction:: | 681 void WebstorePrivateGetWebGLStatusFunction:: |
| 682 OnFeatureCheck(bool feature_allowed) { | 682 OnFeatureCheck(bool feature_allowed) { |
| 683 CreateResult(feature_allowed); | 683 CreateResult(feature_allowed); |
| 684 SendResponse(true); | 684 SendResponse(true); |
| 685 } | 685 } |
| 686 | 686 |
| 687 bool WebstorePrivateGetIsLauncherEnabledFunction::RunSync() { | 687 bool WebstorePrivateGetIsLauncherEnabledFunction::RunSync() { |
| 688 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); | 688 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); |
| 689 return true; | 689 return true; |
| 690 } | 690 } |
| 691 | 691 |
| 692 bool WebstorePrivateIsInIncognitoModeFunction::RunSync() { | 692 bool WebstorePrivateIsInIncognitoModeFunction::RunSync() { |
| 693 results_ = IsInIncognitoMode::Results::Create( | 693 results_ = IsInIncognitoMode::Results::Create( |
| 694 GetProfile() != GetProfile()->GetOriginalProfile()); | 694 GetProfile() != GetProfile()->GetOriginalProfile()); |
| 695 return true; | 695 return true; |
| 696 } | 696 } |
| 697 | 697 |
| 698 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() | 698 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() |
| 699 : signin_manager_(NULL) {} | 699 : signin_manager_(NULL) {} |
| 700 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} | 700 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} |
| 701 | 701 |
| 702 bool WebstorePrivateSignInFunction::RunImpl() { | 702 bool WebstorePrivateSignInFunction::RunAsync() { |
| 703 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); | 703 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); |
| 704 EXTENSION_FUNCTION_VALIDATE(params); | 704 EXTENSION_FUNCTION_VALIDATE(params); |
| 705 | 705 |
| 706 // This API must be called only in response to a user gesture. | 706 // This API must be called only in response to a user gesture. |
| 707 if (!user_gesture()) { | 707 if (!user_gesture()) { |
| 708 error_ = "user_gesture_required"; | 708 error_ = "user_gesture_required"; |
| 709 SendResponse(false); | 709 SendResponse(false); |
| 710 return false; | 710 return false; |
| 711 } | 711 } |
| 712 | 712 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 if (manager == signin_manager_) | 765 if (manager == signin_manager_) |
| 766 SigninFailed(GoogleServiceAuthError::AuthErrorNone()); | 766 SigninFailed(GoogleServiceAuthError::AuthErrorNone()); |
| 767 } | 767 } |
| 768 | 768 |
| 769 void WebstorePrivateSignInFunction::SigninFailed( | 769 void WebstorePrivateSignInFunction::SigninFailed( |
| 770 const GoogleServiceAuthError& error) { | 770 const GoogleServiceAuthError& error) { |
| 771 error_ = "signin_failed"; | 771 error_ = "signin_failed"; |
| 772 SendResponse(false); | 772 SendResponse(false); |
| 773 | 773 |
| 774 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 774 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 775 Release(); // Balanced in RunImpl(). | 775 Release(); // Balanced in RunAsync(). |
| 776 } | 776 } |
| 777 | 777 |
| 778 void WebstorePrivateSignInFunction::SigninSuccess() { | 778 void WebstorePrivateSignInFunction::SigninSuccess() { |
| 779 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called. | 779 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called. |
| 780 } | 780 } |
| 781 | 781 |
| 782 void WebstorePrivateSignInFunction::MergeSessionComplete( | 782 void WebstorePrivateSignInFunction::MergeSessionComplete( |
| 783 const GoogleServiceAuthError& error) { | 783 const GoogleServiceAuthError& error) { |
| 784 if (error.state() == GoogleServiceAuthError::NONE) { | 784 if (error.state() == GoogleServiceAuthError::NONE) { |
| 785 SendResponse(true); | 785 SendResponse(true); |
| 786 } else { | 786 } else { |
| 787 error_ = "merge_session_failed"; | 787 error_ = "merge_session_failed"; |
| 788 SendResponse(false); | 788 SendResponse(false); |
| 789 } | 789 } |
| 790 | 790 |
| 791 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 791 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 792 Release(); // Balanced in RunImpl(). | 792 Release(); // Balanced in RunAsync(). |
| 793 } | 793 } |
| 794 | 794 |
| 795 } // namespace extensions | 795 } // namespace extensions |
| OLD | NEW |