Chromium Code Reviews| 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_function_dispatcher.h" | 20 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/extensions/extension_util.h" | 22 #include "chrome/browser/extensions/extension_util.h" |
| 23 #include "chrome/browser/extensions/webstore_installer.h" | 23 #include "chrome/browser/extensions/webstore_installer.h" |
| 24 #include "chrome/browser/gpu/gpu_feature_checker.h" | 24 #include "chrome/browser/gpu/gpu_feature_checker.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/signin/signin_manager.h" | 26 #include "chrome/browser/signin/signin_manager.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_promo.h" |
| 28 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 30 #include "chrome/browser/ui/app_list/app_list_service.h" | 30 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 31 #include "chrome/browser/ui/app_list/app_list_util.h" | 31 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 32 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
| 34 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
| 33 #include "chrome/common/extensions/extension_constants.h" | 35 #include "chrome/common/extensions/extension_constants.h" |
| 34 #include "chrome/common/extensions/extension_l10n_util.h" | 36 #include "chrome/common/extensions/extension_l10n_util.h" |
| 35 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/profile_management_switches.h" | |
| 36 #include "content/public/browser/gpu_data_manager.h" | 39 #include "content/public/browser/gpu_data_manager.h" |
| 37 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
| 38 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 39 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/page_transition_types.h" | |
| 44 #include "content/public/common/referrer.h" | |
| 40 #include "extensions/browser/extension_prefs.h" | 45 #include "extensions/browser/extension_prefs.h" |
| 41 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 42 #include "extensions/common/error_utils.h" | 47 #include "extensions/common/error_utils.h" |
| 43 #include "extensions/common/extension.h" | 48 #include "extensions/common/extension.h" |
| 49 #include "google_apis/gaia/google_service_auth_error.h" | |
| 44 #include "grit/chromium_strings.h" | 50 #include "grit/chromium_strings.h" |
| 45 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "url/gurl.h" | |
| 47 | 54 |
| 48 using content::GpuDataManager; | 55 using content::GpuDataManager; |
| 49 | 56 |
| 50 namespace extensions { | 57 namespace extensions { |
| 51 | 58 |
| 52 namespace BeginInstallWithManifest3 = | 59 namespace BeginInstallWithManifest3 = |
| 53 api::webstore_private::BeginInstallWithManifest3; | 60 api::webstore_private::BeginInstallWithManifest3; |
| 54 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 61 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
| 55 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 62 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
| 56 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 63 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
| 57 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 64 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
| 58 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 65 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
| 59 namespace InstallBundle = api::webstore_private::InstallBundle; | 66 namespace InstallBundle = api::webstore_private::InstallBundle; |
| 60 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 67 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 68 namespace SignIn = api::webstore_private::SignIn; | |
| 61 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 69 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
| 62 | 70 |
| 63 namespace { | 71 namespace { |
| 64 | 72 |
| 65 // 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. |
| 66 class PendingApprovals { | 74 class PendingApprovals { |
| 67 public: | 75 public: |
| 68 PendingApprovals(); | 76 PendingApprovals(); |
| 69 ~PendingApprovals(); | 77 ~PendingApprovals(); |
| 70 | 78 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); | 687 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); |
| 680 return true; | 688 return true; |
| 681 } | 689 } |
| 682 | 690 |
| 683 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { | 691 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
| 684 results_ = IsInIncognitoMode::Results::Create( | 692 results_ = IsInIncognitoMode::Results::Create( |
| 685 GetProfile() != GetProfile()->GetOriginalProfile()); | 693 GetProfile() != GetProfile()->GetOriginalProfile()); |
| 686 return true; | 694 return true; |
| 687 } | 695 } |
| 688 | 696 |
| 697 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() | |
| 698 : signin_manager_(NULL) {} | |
| 699 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} | |
| 700 | |
| 701 bool WebstorePrivateSignInFunction::RunImpl() { | |
| 702 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); | |
| 703 EXTENSION_FUNCTION_VALIDATE(params); | |
| 704 | |
| 705 // The |continue_url| is required, and must be hosted on the same origin as | |
| 706 // the calling page. | |
| 707 // TODO(isherman): Is it better to pass the error message to the callback, or | |
| 708 // to set it as the last |error_|? | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
i think it is better to pass the error to callback
| |
| 709 GURL continue_url(params->continue_url); | |
| 710 content::WebContents* web_contents = GetAssociatedWebContents(); | |
| 711 if (!continue_url.is_valid() || | |
| 712 continue_url.GetOrigin() != | |
| 713 web_contents->GetLastCommittedURL().GetOrigin()) { | |
| 714 error_ = "invalid_continue_url"; | |
| 715 SendResponse(false); | |
| 716 return false; | |
| 717 } | |
| 718 | |
| 719 // If sign-in is disallowed, give up. | |
| 720 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile()); | |
| 721 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() || | |
| 722 switches::IsEnableWebBasedSignin()) { | |
| 723 error_ = "signin_is_disallowed"; | |
| 724 SendResponse(false); | |
| 725 return false; | |
| 726 } | |
| 727 | |
| 728 // If the user is already signed in, there's nothing else to do. | |
| 729 if (!signin_manager_->GetAuthenticatedUsername().empty()) { | |
| 730 error_ = "user_is_already_signed_in"; | |
| 731 SendResponse(false); | |
| 732 return false; | |
| 733 } | |
| 734 | |
| 735 // If an authentication is currently in progress, wait for it to complete. | |
| 736 // TODO(isherman): Is this worth the added complexity, or would it be better | |
| 737 // to simply fail immediately and require the webstore to retry? (Seems | |
| 738 // possibly tricky for the webstore to know when to retry. I guess there's | |
| 739 // always the option of exponential backoff or something...) | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
definitely better to wait for it to complete, as y
| |
| 740 if (signin_manager_->AuthInProgress()) { | |
| 741 // TODO(isherman): Should we send a message to the page immediately to | |
| 742 // indicate that we're waiting? (I'd prefer not to, since the API call is | |
| 743 // already asynchronous... but if it's possible that the reply will be | |
| 744 // significantly delayed, then the extra message is probably needed.) | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
hmm i think webstore could have a timeout on their
| |
| 745 SigninManagerFactory::GetInstance()->AddObserver(this); | |
| 746 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); | |
| 747 AddRef(); // Balanced in the sign-in observer methods below. | |
| 748 return true; | |
| 749 } | |
| 750 | |
| 751 GURL signin_url = | |
| 752 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL, | |
| 753 false /* auto_close */, | |
| 754 false /* is_constrained */, | |
| 755 continue_url); | |
| 756 web_contents->GetController().LoadURL(signin_url, | |
| 757 content::Referrer(), | |
| 758 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 759 std::string()); | |
| 760 | |
| 761 SendResponse(true); | |
| 762 return true; | |
| 763 } | |
| 764 | |
| 765 void WebstorePrivateSignInFunction::SigninManagerShutdown( | |
| 766 SigninManagerBase* manager) { | |
| 767 SigninManagerFactory::GetInstance()->RemoveObserver(this); | |
| 768 // TODO(isherman): Probably a good idea to move these three lines into a | |
| 769 // shared function. Holding off on that for now in case we actually want to | |
| 770 // send different error strings depending on the exact codepath hit or | |
| 771 // anything like that. | |
|
Ilya Sherman
2014/03/14 05:42:56
Do you think we should try to have a smaller set o
guohui
2014/03/14 22:09:44
i think it is better to have a smaller set of erro
| |
| 772 error_ = "signin_failed"; | |
| 773 SendResponse(false); | |
| 774 Release(); // Balanced in RunImpl(). | |
| 775 } | |
| 776 | |
| 777 void WebstorePrivateSignInFunction::SigninFailed( | |
| 778 const GoogleServiceAuthError& error) { | |
| 779 // TODO(isherman): Would it be helpful to navigate to a sign-in page at this | |
| 780 // point, or is it better to have the Webstore re-issue the request if | |
| 781 // desired? | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
i don't have a strong preference. Since this is an
| |
| 782 error_ = "signin_failed"; | |
| 783 SendResponse(false); | |
| 784 Release(); // Balanced in RunImpl(). | |
| 785 } | |
| 786 | |
| 787 // TODO(isherman): Is this right? Specifically: | |
| 788 // (a) Do we need to wait for the session to be merged, or are we ready to | |
| 789 // continue as soon as we get this sign-in success? | |
| 790 // (b) Is a sign-in success guaranteed to be followed by a merge session | |
| 791 // complete? If not, is there a way to listen for a failure? | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
yes we should wait for mergeSession to complete ot
| |
| 792 void WebstorePrivateSignInFunction::SigninSuccess() { | |
| 793 // Nothing to do in this case. Keep waiting until MergeSessionComplete() is | |
| 794 // called. | |
| 795 } | |
| 796 | |
| 797 void WebstorePrivateSignInFunction::MergeSessionComplete( | |
| 798 const GoogleServiceAuthError& error) { | |
| 799 // TODO(isherman): Am I handling the |error| parameter correctly? Why can | |
| 800 // merging the session fail? | |
|
Ilya Sherman
2014/03/14 05:42:56
^^^
guohui
2014/03/14 22:09:44
you may return a specific error 'merge_session_fai
| |
| 801 if (error.state() == GoogleServiceAuthError::NONE) { | |
| 802 SendResponse(true); | |
| 803 } else { | |
| 804 error_ = "signin_failed"; | |
| 805 SendResponse(false); | |
| 806 } | |
| 807 Release(); // Balanced in RunImpl(). | |
| 808 } | |
| 809 | |
| 689 } // namespace extensions | 810 } // namespace extensions |
| OLD | NEW |