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 23 matching lines...) Expand all Loading... |
34 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
35 #include "components/signin/core/common/profile_management_switches.h" | 35 #include "components/signin/core/common/profile_management_switches.h" |
36 #include "content/public/browser/gpu_data_manager.h" | 36 #include "content/public/browser/gpu_data_manager.h" |
37 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
38 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
40 #include "content/public/common/page_transition_types.h" | 40 #include "content/public/common/page_transition_types.h" |
41 #include "content/public/common/referrer.h" | 41 #include "content/public/common/referrer.h" |
42 #include "extensions/browser/extension_function_dispatcher.h" | 42 #include "extensions/browser/extension_function_dispatcher.h" |
43 #include "extensions/browser/extension_prefs.h" | 43 #include "extensions/browser/extension_prefs.h" |
| 44 #include "extensions/browser/extension_registry.h" |
44 #include "extensions/browser/extension_system.h" | 45 #include "extensions/browser/extension_system.h" |
45 #include "extensions/browser/extension_util.h" | 46 #include "extensions/browser/extension_util.h" |
46 #include "extensions/common/error_utils.h" | 47 #include "extensions/common/error_utils.h" |
47 #include "extensions/common/extension.h" | 48 #include "extensions/common/extension.h" |
48 #include "extensions/common/extension_l10n_util.h" | 49 #include "extensions/common/extension_l10n_util.h" |
49 #include "google_apis/gaia/google_service_auth_error.h" | 50 #include "google_apis/gaia/google_service_auth_error.h" |
50 #include "grit/chromium_strings.h" | 51 #include "grit/chromium_strings.h" |
51 #include "grit/generated_resources.h" | 52 #include "grit/generated_resources.h" |
52 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
53 #include "url/gurl.h" | 54 #include "url/gurl.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 558 |
558 approval_ = g_pending_approvals.Get() | 559 approval_ = g_pending_approvals.Get() |
559 .PopApproval(GetProfile(), params->expected_id) | 560 .PopApproval(GetProfile(), params->expected_id) |
560 .Pass(); | 561 .Pass(); |
561 if (!approval_) { | 562 if (!approval_) { |
562 error_ = ErrorUtils::FormatErrorMessage( | 563 error_ = ErrorUtils::FormatErrorMessage( |
563 kNoPreviousBeginInstallWithManifestError, params->expected_id); | 564 kNoPreviousBeginInstallWithManifestError, params->expected_id); |
564 return false; | 565 return false; |
565 } | 566 } |
566 | 567 |
567 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). | |
568 AddRef(); | |
569 AppListService* app_list_service = | 568 AppListService* app_list_service = |
570 AppListService::Get(GetCurrentBrowser()->host_desktop_type()); | 569 AppListService::Get(GetCurrentBrowser()->host_desktop_type()); |
571 | 570 |
572 if (approval_->enable_launcher) { | 571 if (approval_->enable_launcher) { |
573 app_list_service->EnableAppList(GetProfile(), | 572 app_list_service->EnableAppList(GetProfile(), |
574 AppListService::ENABLE_FOR_APP_INSTALL); | 573 AppListService::ENABLE_FOR_APP_INSTALL); |
575 } | 574 } |
576 | 575 |
577 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) { | 576 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) { |
578 // Show the app list to show download is progressing. Don't show the app | 577 // Show the app list to show download is progressing. Don't show the app |
579 // list on first app install so users can be trained to open it themselves. | 578 // list on first app install so users can be trained to open it themselves. |
580 if (approval_->enable_launcher) | 579 if (approval_->enable_launcher) |
581 app_list_service->CreateForProfile(GetProfile()); | 580 app_list_service->CreateForProfile(GetProfile()); |
582 else | 581 else |
583 app_list_service->AutoShowForProfile(GetProfile()); | 582 app_list_service->AutoShowForProfile(GetProfile()); |
584 } | 583 } |
585 | 584 |
| 585 // If the target extension has already been installed ephemerally, it can |
| 586 // be promoted to a regular installed extension and downloading from the Web |
| 587 // Store is not necessary. |
| 588 const Extension* extension = ExtensionRegistry::Get(GetProfile())-> |
| 589 GetExtensionById(params->expected_id, ExtensionRegistry::EVERYTHING); |
| 590 if (extension && util::IsEphemeralApp(extension->id(), GetProfile())) { |
| 591 ExtensionService* extension_service = |
| 592 ExtensionSystem::Get(GetProfile())->extension_service(); |
| 593 extension_service->PromoteEphemeralApp(extension, false); |
| 594 OnInstallSuccess(extension->id()); |
| 595 return true; |
| 596 } |
| 597 |
| 598 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). |
| 599 AddRef(); |
| 600 |
586 // The extension will install through the normal extension install flow, but | 601 // The extension will install through the normal extension install flow, but |
587 // the whitelist entry will bypass the normal permissions install dialog. | 602 // the whitelist entry will bypass the normal permissions install dialog. |
588 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 603 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
589 GetProfile(), | 604 GetProfile(), |
590 this, | 605 this, |
591 dispatcher()->delegate()->GetAssociatedWebContents(), | 606 dispatcher()->delegate()->GetAssociatedWebContents(), |
592 params->expected_id, | 607 params->expected_id, |
593 approval_.Pass(), | 608 approval_.Pass(), |
594 WebstoreInstaller::INSTALL_SOURCE_OTHER); | 609 WebstoreInstaller::INSTALL_SOURCE_OTHER); |
595 installer->Start(); | 610 installer->Start(); |
596 | 611 |
597 return true; | 612 return true; |
598 } | 613 } |
599 | 614 |
600 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( | 615 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( |
601 const std::string& id) { | 616 const std::string& id) { |
602 if (test_webstore_installer_delegate) | 617 OnInstallSuccess(id); |
603 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); | |
604 | |
605 VLOG(1) << "Install success, sending response"; | |
606 g_pending_installs.Get().EraseInstall(GetProfile(), id); | |
607 SendResponse(true); | |
608 | |
609 RecordWebstoreExtensionInstallResult(true); | 618 RecordWebstoreExtensionInstallResult(true); |
610 | 619 |
611 // Matches the AddRef in RunAsync(). | 620 // Matches the AddRef in RunAsync(). |
612 Release(); | 621 Release(); |
613 } | 622 } |
614 | 623 |
615 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure( | 624 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallFailure( |
616 const std::string& id, | 625 const std::string& id, |
617 const std::string& error, | 626 const std::string& error, |
618 WebstoreInstaller::FailureReason reason) { | 627 WebstoreInstaller::FailureReason reason) { |
619 if (test_webstore_installer_delegate) { | 628 if (test_webstore_installer_delegate) { |
620 test_webstore_installer_delegate->OnExtensionInstallFailure( | 629 test_webstore_installer_delegate->OnExtensionInstallFailure( |
621 id, error, reason); | 630 id, error, reason); |
622 } | 631 } |
623 | 632 |
624 error_ = error; | 633 error_ = error; |
625 VLOG(1) << "Install failed, sending response"; | 634 VLOG(1) << "Install failed, sending response"; |
626 g_pending_installs.Get().EraseInstall(GetProfile(), id); | 635 g_pending_installs.Get().EraseInstall(GetProfile(), id); |
627 SendResponse(false); | 636 SendResponse(false); |
628 | 637 |
629 RecordWebstoreExtensionInstallResult(false); | 638 RecordWebstoreExtensionInstallResult(false); |
630 | 639 |
631 // Matches the AddRef in RunAsync(). | 640 // Matches the AddRef in RunAsync(). |
632 Release(); | 641 Release(); |
633 } | 642 } |
634 | 643 |
| 644 void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( |
| 645 const std::string& id) { |
| 646 if (test_webstore_installer_delegate) |
| 647 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
| 648 |
| 649 VLOG(1) << "Install success, sending response"; |
| 650 g_pending_installs.Get().EraseInstall(GetProfile(), id); |
| 651 SendResponse(true); |
| 652 } |
| 653 |
635 WebstorePrivateEnableAppLauncherFunction:: | 654 WebstorePrivateEnableAppLauncherFunction:: |
636 WebstorePrivateEnableAppLauncherFunction() {} | 655 WebstorePrivateEnableAppLauncherFunction() {} |
637 | 656 |
638 WebstorePrivateEnableAppLauncherFunction:: | 657 WebstorePrivateEnableAppLauncherFunction:: |
639 ~WebstorePrivateEnableAppLauncherFunction() {} | 658 ~WebstorePrivateEnableAppLauncherFunction() {} |
640 | 659 |
641 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { | 660 bool WebstorePrivateEnableAppLauncherFunction::RunSync() { |
642 AppListService::Get(GetCurrentBrowser()->host_desktop_type()) | 661 AppListService::Get(GetCurrentBrowser()->host_desktop_type()) |
643 ->EnableAppList(GetProfile(), AppListService::ENABLE_VIA_WEBSTORE_LINK); | 662 ->EnableAppList(GetProfile(), AppListService::ENABLE_VIA_WEBSTORE_LINK); |
644 return true; | 663 return true; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 } else { | 812 } else { |
794 error_ = "merge_session_failed"; | 813 error_ = "merge_session_failed"; |
795 SendResponse(false); | 814 SendResponse(false); |
796 } | 815 } |
797 | 816 |
798 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 817 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
799 Release(); // Balanced in RunAsync(). | 818 Release(); // Balanced in RunAsync(). |
800 } | 819 } |
801 | 820 |
802 } // namespace extensions | 821 } // namespace extensions |
OLD | NEW |