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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 api::webstore_private::GetEphemeralAppsEnabled; | 58 api::webstore_private::GetEphemeralAppsEnabled; |
59 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 59 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
60 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 60 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
61 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 61 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
62 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 62 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
63 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 63 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
64 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 64 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
65 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; | 65 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; |
66 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results; | 66 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results; |
67 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 67 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
| 68 namespace ShowPermissionPromptForDelegatedInstall = |
| 69 api::webstore_private::ShowPermissionPromptForDelegatedInstall; |
68 | 70 |
69 namespace { | 71 namespace { |
70 | 72 |
71 // Holds the Approvals between the time we prompt and start the installs. | 73 // Holds the Approvals between the time we prompt and start the installs. |
72 class PendingApprovals { | 74 class PendingApprovals { |
73 public: | 75 public: |
74 PendingApprovals(); | 76 PendingApprovals(); |
75 ~PendingApprovals(); | 77 ~PendingApprovals(); |
76 | 78 |
77 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); | 79 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 504 |
503 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( | 505 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( |
504 const std::string& id) { | 506 const std::string& id) { |
505 if (test_webstore_installer_delegate) | 507 if (test_webstore_installer_delegate) |
506 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); | 508 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
507 | 509 |
508 VLOG(1) << "Install success, sending response"; | 510 VLOG(1) << "Install success, sending response"; |
509 SendResponse(true); | 511 SendResponse(true); |
510 } | 512 } |
511 | 513 |
| 514 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 515 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
| 516 } |
| 517 |
| 518 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 519 ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
| 520 } |
| 521 |
| 522 bool WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 523 RunAsync() { |
| 524 params_ = ShowPermissionPromptForDelegatedInstall::Params::Create(*args_); |
| 525 EXTENSION_FUNCTION_VALIDATE(params_); |
| 526 |
| 527 if (!crx_file::id_util::IdIsValid(params_->details.id)) { |
| 528 SetResultCode(INVALID_ID); |
| 529 error_ = kInvalidIdError; |
| 530 return false; |
| 531 } |
| 532 |
| 533 if (params_->details.icon_data && params_->details.icon_url) { |
| 534 SetResultCode(ICON_ERROR); |
| 535 error_ = kCannotSpecifyIconDataAndUrlError; |
| 536 return false; |
| 537 } |
| 538 |
| 539 GURL icon_url; |
| 540 if (params_->details.icon_url) { |
| 541 std::string tmp_url; |
| 542 icon_url = source_url().Resolve(*params_->details.icon_url); |
| 543 if (!icon_url.is_valid()) { |
| 544 SetResultCode(INVALID_ICON_URL); |
| 545 error_ = kInvalidIconUrlError; |
| 546 return false; |
| 547 } |
| 548 } |
| 549 |
| 550 std::string icon_data = params_->details.icon_data ? |
| 551 *params_->details.icon_data : std::string(); |
| 552 |
| 553 net::URLRequestContextGetter* context_getter = NULL; |
| 554 if (!icon_url.is_empty()) |
| 555 context_getter = GetProfile()->GetRequestContext(); |
| 556 |
| 557 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
| 558 this, params_->details.id, params_->details.manifest, icon_data, icon_url, |
| 559 context_getter); |
| 560 |
| 561 // The helper will call us back via OnWebstoreParseSuccess or |
| 562 // OnWebstoreParseFailure. |
| 563 helper->Start(); |
| 564 |
| 565 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
| 566 AddRef(); |
| 567 |
| 568 // The response is sent asynchronously in OnWebstoreParseSuccess/ |
| 569 // OnWebstoreParseFailure. |
| 570 return true; |
| 571 } |
| 572 |
| 573 const char* WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 574 ResultCodeToString(ResultCode code) { |
| 575 switch (code) { |
| 576 case ERROR_NONE: |
| 577 return ""; |
| 578 case UNKNOWN_ERROR: |
| 579 return "unknown_error"; |
| 580 case USER_CANCELLED: |
| 581 return "user_cancelled"; |
| 582 case MANIFEST_ERROR: |
| 583 return "manifest_error"; |
| 584 case ICON_ERROR: |
| 585 return "icon_error"; |
| 586 case INVALID_ID: |
| 587 return "invalid_id"; |
| 588 case INVALID_ICON_URL: |
| 589 return "invalid_icon_url"; |
| 590 } |
| 591 NOTREACHED(); |
| 592 return ""; |
| 593 } |
| 594 |
| 595 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 596 SetResultCode(ResultCode code) { |
| 597 results_ = ShowPermissionPromptForDelegatedInstall::Results::Create( |
| 598 ResultCodeToString(code)); |
| 599 } |
| 600 |
| 601 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 602 OnWebstoreParseSuccess(const std::string& id, |
| 603 const SkBitmap& icon, |
| 604 base::DictionaryValue* parsed_manifest) { |
| 605 CHECK_EQ(params_->details.id, id); |
| 606 CHECK(parsed_manifest); |
| 607 icon_ = icon; |
| 608 parsed_manifest_.reset(parsed_manifest); |
| 609 |
| 610 std::string localized_name = params_->details.localized_name ? |
| 611 *params_->details.localized_name : std::string(); |
| 612 |
| 613 std::string error; |
| 614 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 615 parsed_manifest_.get(), |
| 616 Extension::FROM_WEBSTORE, |
| 617 id, |
| 618 localized_name, |
| 619 std::string(), |
| 620 &error); |
| 621 |
| 622 if (!dummy_extension_.get()) { |
| 623 OnWebstoreParseFailure(params_->details.id, |
| 624 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
| 625 kInvalidManifestError); |
| 626 return; |
| 627 } |
| 628 |
| 629 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 630 if (!web_contents) // The browser window has gone away. |
| 631 return; |
| 632 install_prompt_.reset(new ExtensionInstallPrompt(web_contents)); |
| 633 install_prompt_->ConfirmPermissionsForDelegatedInstall( |
| 634 this, dummy_extension_.get(), params_->details.delegated_user, &icon_); |
| 635 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 636 } |
| 637 |
| 638 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 639 OnWebstoreParseFailure( |
| 640 const std::string& id, |
| 641 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
| 642 const std::string& error_message) { |
| 643 CHECK_EQ(params_->details.id, id); |
| 644 |
| 645 // Map from WebstoreInstallHelper's result codes to ours. |
| 646 switch (result_code) { |
| 647 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
| 648 SetResultCode(UNKNOWN_ERROR); |
| 649 break; |
| 650 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
| 651 SetResultCode(ICON_ERROR); |
| 652 break; |
| 653 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
| 654 SetResultCode(MANIFEST_ERROR); |
| 655 break; |
| 656 default: |
| 657 CHECK(false); |
| 658 } |
| 659 error_ = error_message; |
| 660 SendResponse(false); |
| 661 |
| 662 // Matches the AddRef in RunAsync(). |
| 663 Release(); |
| 664 } |
| 665 |
| 666 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 667 InstallUIProceed() { |
| 668 SetResultCode(ERROR_NONE); |
| 669 SendResponse(true); |
| 670 |
| 671 // Matches the AddRef in RunAsync(). |
| 672 Release(); |
| 673 } |
| 674 |
| 675 void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
| 676 InstallUIAbort(bool user_initiated) { |
| 677 error_ = kUserCancelledError; |
| 678 SetResultCode(USER_CANCELLED); |
| 679 SendResponse(false); |
| 680 |
| 681 // Matches the AddRef in RunAsync(). |
| 682 Release(); |
| 683 } |
| 684 |
512 WebstorePrivateEnableAppLauncherFunction:: | 685 WebstorePrivateEnableAppLauncherFunction:: |
513 WebstorePrivateEnableAppLauncherFunction() {} | 686 WebstorePrivateEnableAppLauncherFunction() {} |
514 | 687 |
515 WebstorePrivateEnableAppLauncherFunction:: | 688 WebstorePrivateEnableAppLauncherFunction:: |
516 ~WebstorePrivateEnableAppLauncherFunction() {} | 689 ~WebstorePrivateEnableAppLauncherFunction() {} |
517 | 690 |
518 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { | 691 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { |
519 AppListService* app_list_service = AppListService::Get( | 692 AppListService* app_list_service = AppListService::Get( |
520 GetHostDesktopTypeForWebContents(GetAssociatedWebContents())); | 693 GetHostDesktopTypeForWebContents(GetAssociatedWebContents())); |
521 app_list_service->EnableAppList(GetProfile(), | 694 app_list_service->EnableAppList(GetProfile(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 874 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
702 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 875 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
703 | 876 |
704 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { | 877 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { |
705 results_ = GetEphemeralAppsEnabled::Results::Create( | 878 results_ = GetEphemeralAppsEnabled::Results::Create( |
706 EphemeralAppLauncher::IsFeatureEnabledInWebstore()); | 879 EphemeralAppLauncher::IsFeatureEnabledInWebstore()); |
707 return true; | 880 return true; |
708 } | 881 } |
709 | 882 |
710 } // namespace extensions | 883 } // namespace extensions |
OLD | NEW |