| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/about_flags.h" | 16 #include "chrome/browser/about_flags.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/extensions/crx_installer.h" | 19 #include "chrome/browser/extensions/crx_installer.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/webstore_installer.h" | 22 #include "chrome/browser/extensions/webstore_installer.h" |
| 23 #include "chrome/browser/gpu/gpu_feature_checker.h" | 23 #include "chrome/browser/gpu/gpu_feature_checker.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/signin/signin_manager.h" | 25 #include "chrome/browser/signin/signin_manager.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_promo.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/browser/ui/app_list/app_list_service.h" | 29 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 30 #include "chrome/browser/ui/app_list/app_list_util.h" | 30 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
| 33 #include "chrome/common/extensions/extension_l10n_util.h" | 33 #include "chrome/common/extensions/extension_l10n_util.h" |
| 34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/profile_management_switches.h" |
| 35 #include "content/public/browser/gpu_data_manager.h" | 36 #include "content/public/browser/gpu_data_manager.h" |
| 36 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
| 37 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/page_transition_types.h" |
| 41 #include "content/public/common/referrer.h" |
| 39 #include "extensions/browser/extension_function_dispatcher.h" | 42 #include "extensions/browser/extension_function_dispatcher.h" |
| 40 #include "extensions/browser/extension_prefs.h" | 43 #include "extensions/browser/extension_prefs.h" |
| 41 #include "extensions/browser/extension_system.h" | 44 #include "extensions/browser/extension_system.h" |
| 42 #include "extensions/common/error_utils.h" | 45 #include "extensions/common/error_utils.h" |
| 43 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
| 47 #include "google_apis/gaia/google_service_auth_error.h" |
| 44 #include "grit/chromium_strings.h" | 48 #include "grit/chromium_strings.h" |
| 45 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "url/gurl.h" |
| 47 | 52 |
| 48 using content::GpuDataManager; | 53 using content::GpuDataManager; |
| 49 | 54 |
| 50 namespace extensions { | 55 namespace extensions { |
| 51 | 56 |
| 52 namespace BeginInstallWithManifest3 = | 57 namespace BeginInstallWithManifest3 = |
| 53 api::webstore_private::BeginInstallWithManifest3; | 58 api::webstore_private::BeginInstallWithManifest3; |
| 54 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 59 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
| 55 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 60 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
| 56 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 61 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
| 57 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 62 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
| 58 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 63 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
| 59 namespace InstallBundle = api::webstore_private::InstallBundle; | 64 namespace InstallBundle = api::webstore_private::InstallBundle; |
| 60 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 65 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 66 namespace SignIn = api::webstore_private::SignIn; |
| 61 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 67 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
| 62 | 68 |
| 63 namespace { | 69 namespace { |
| 64 | 70 |
| 65 // Holds the Approvals between the time we prompt and start the installs. | 71 // Holds the Approvals between the time we prompt and start the installs. |
| 66 class PendingApprovals { | 72 class PendingApprovals { |
| 67 public: | 73 public: |
| 68 PendingApprovals(); | 74 PendingApprovals(); |
| 69 ~PendingApprovals(); | 75 ~PendingApprovals(); |
| 70 | 76 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); | 685 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); |
| 680 return true; | 686 return true; |
| 681 } | 687 } |
| 682 | 688 |
| 683 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { | 689 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
| 684 results_ = IsInIncognitoMode::Results::Create( | 690 results_ = IsInIncognitoMode::Results::Create( |
| 685 GetProfile() != GetProfile()->GetOriginalProfile()); | 691 GetProfile() != GetProfile()->GetOriginalProfile()); |
| 686 return true; | 692 return true; |
| 687 } | 693 } |
| 688 | 694 |
| 695 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() |
| 696 : signin_manager_(NULL) {} |
| 697 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} |
| 698 |
| 699 bool WebstorePrivateSignInFunction::RunImpl() { |
| 700 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); |
| 701 EXTENSION_FUNCTION_VALIDATE(params); |
| 702 |
| 703 // The |continue_url| is required, and must be hosted on the same origin as |
| 704 // the calling page. |
| 705 GURL continue_url(params->continue_url); |
| 706 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 707 if (!continue_url.is_valid() || |
| 708 continue_url.GetOrigin() != |
| 709 web_contents->GetLastCommittedURL().GetOrigin()) { |
| 710 // TODO(isherman): Is it better to pass the error message to the callback, |
| 711 // or to set it as the last |error_|? |
| 712 error_ = "invalid_continue_url"; |
| 713 SendResponse(false); |
| 714 return false; |
| 715 } |
| 716 |
| 717 // If sign-in is disallowed, give up. |
| 718 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile()); |
| 719 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() || |
| 720 switches::IsEnableWebBasedSignin()) { |
| 721 error_ = "signin_is_disallowed"; |
| 722 SendResponse(false); |
| 723 return false; |
| 724 } |
| 725 |
| 726 // If the user is already signed in, there's nothing else to do. |
| 727 if (!signin_manager_->GetAuthenticatedUsername().empty()) { |
| 728 error_ = "user_is_already_signed_in"; |
| 729 SendResponse(false); |
| 730 return false; |
| 731 } |
| 732 |
| 733 // If an authentication is currently in progress, wait for it to complete. |
| 734 if (signin_manager_->AuthInProgress()) { |
| 735 SigninManagerFactory::GetInstance()->AddObserver(this); |
| 736 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); |
| 737 AddRef(); // Balanced in the sign-in observer methods below. |
| 738 return true; |
| 739 } |
| 740 |
| 741 GURL signin_url = |
| 742 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL, |
| 743 false /* auto_close */, |
| 744 false /* is_constrained */, |
| 745 continue_url); |
| 746 web_contents->GetController().LoadURL(signin_url, |
| 747 content::Referrer(), |
| 748 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 749 std::string()); |
| 750 |
| 751 SendResponse(true); |
| 752 return true; |
| 753 } |
| 754 |
| 755 void WebstorePrivateSignInFunction::SigninManagerShutdown( |
| 756 SigninManagerBase* manager) { |
| 757 if (manager == signin_manager_) |
| 758 SigninFailed(GoogleServiceAuthError::AuthErrorNone()); |
| 759 } |
| 760 |
| 761 void WebstorePrivateSignInFunction::SigninFailed( |
| 762 const GoogleServiceAuthError& error) { |
| 763 error_ = "signin_failed"; |
| 764 SendResponse(false); |
| 765 |
| 766 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 767 Release(); // Balanced in RunImpl(). |
| 768 } |
| 769 |
| 770 void WebstorePrivateSignInFunction::SigninSuccess() { |
| 771 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called. |
| 772 } |
| 773 |
| 774 void WebstorePrivateSignInFunction::MergeSessionComplete( |
| 775 const GoogleServiceAuthError& error) { |
| 776 if (error.state() == GoogleServiceAuthError::NONE) { |
| 777 SendResponse(true); |
| 778 } else { |
| 779 error_ = "merge_session_failed"; |
| 780 SendResponse(false); |
| 781 } |
| 782 |
| 783 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 784 Release(); // Balanced in RunImpl(). |
| 785 } |
| 786 |
| 689 } // namespace extensions | 787 } // namespace extensions |
| OLD | NEW |