Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a spurious diff Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_factory.h" 25 #include "chrome/browser/signin/signin_manager_factory.h"
26 #include "chrome/browser/signin/signin_promo.h"
26 #include "chrome/browser/signin/signin_tracker_factory.h" 27 #include "chrome/browser/signin/signin_tracker_factory.h"
27 #include "chrome/browser/sync/profile_sync_service.h" 28 #include "chrome/browser/sync/profile_sync_service.h"
28 #include "chrome/browser/sync/profile_sync_service_factory.h" 29 #include "chrome/browser/sync/profile_sync_service_factory.h"
29 #include "chrome/browser/ui/app_list/app_list_service.h" 30 #include "chrome/browser/ui/app_list/app_list_service.h"
30 #include "chrome/browser/ui/app_list/app_list_util.h" 31 #include "chrome/browser/ui/app_list/app_list_util.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
32 #include "chrome/common/extensions/extension_constants.h" 33 #include "chrome/common/extensions/extension_constants.h"
33 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
34 #include "components/signin/core/browser/signin_manager.h" 35 #include "components/signin/core/browser/signin_manager.h"
36 #include "components/signin/core/common/profile_management_switches.h"
35 #include "content/public/browser/gpu_data_manager.h" 37 #include "content/public/browser/gpu_data_manager.h"
36 #include "content/public/browser/notification_details.h" 38 #include "content/public/browser/notification_details.h"
37 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
38 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
41 #include "content/public/common/page_transition_types.h"
42 #include "content/public/common/referrer.h"
39 #include "extensions/browser/extension_function_dispatcher.h" 43 #include "extensions/browser/extension_function_dispatcher.h"
40 #include "extensions/browser/extension_prefs.h" 44 #include "extensions/browser/extension_prefs.h"
41 #include "extensions/browser/extension_system.h" 45 #include "extensions/browser/extension_system.h"
42 #include "extensions/common/error_utils.h" 46 #include "extensions/common/error_utils.h"
43 #include "extensions/common/extension.h" 47 #include "extensions/common/extension.h"
44 #include "extensions/common/extension_l10n_util.h" 48 #include "extensions/common/extension_l10n_util.h"
49 #include "google_apis/gaia/google_service_auth_error.h"
45 #include "grit/chromium_strings.h" 50 #include "grit/chromium_strings.h"
46 #include "grit/generated_resources.h" 51 #include "grit/generated_resources.h"
47 #include "ui/base/l10n/l10n_util.h" 52 #include "ui/base/l10n/l10n_util.h"
53 #include "url/gurl.h"
48 54
49 using content::GpuDataManager; 55 using content::GpuDataManager;
50 56
51 namespace extensions { 57 namespace extensions {
52 58
53 namespace BeginInstallWithManifest3 = 59 namespace BeginInstallWithManifest3 =
54 api::webstore_private::BeginInstallWithManifest3; 60 api::webstore_private::BeginInstallWithManifest3;
55 namespace CompleteInstall = api::webstore_private::CompleteInstall; 61 namespace CompleteInstall = api::webstore_private::CompleteInstall;
56 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; 62 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
57 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; 63 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
58 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; 64 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
59 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; 65 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
60 namespace InstallBundle = api::webstore_private::InstallBundle; 66 namespace InstallBundle = api::webstore_private::InstallBundle;
61 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; 67 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
68 namespace SignIn = api::webstore_private::SignIn;
62 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; 69 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
63 70
64 namespace { 71 namespace {
65 72
73 bool g_ignore_user_gesture_for_tests = false;
74
66 // Holds the Approvals between the time we prompt and start the installs. 75 // Holds the Approvals between the time we prompt and start the installs.
67 class PendingApprovals { 76 class PendingApprovals {
68 public: 77 public:
69 PendingApprovals(); 78 PendingApprovals();
70 ~PendingApprovals(); 79 ~PendingApprovals();
71 80
72 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); 81 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval);
73 scoped_ptr<WebstoreInstaller::Approval> PopApproval( 82 scoped_ptr<WebstoreInstaller::Approval> PopApproval(
74 Profile* profile, const std::string& id); 83 Profile* profile, const std::string& id);
75 private: 84 private:
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); 690 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled());
682 return true; 691 return true;
683 } 692 }
684 693
685 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { 694 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() {
686 results_ = IsInIncognitoMode::Results::Create( 695 results_ = IsInIncognitoMode::Results::Create(
687 GetProfile() != GetProfile()->GetOriginalProfile()); 696 GetProfile() != GetProfile()->GetOriginalProfile());
688 return true; 697 return true;
689 } 698 }
690 699
700 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction()
701 : signin_manager_(NULL) {}
702 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {}
703
704 // static
705 void WebstorePrivateSignInFunction::SetIgnoreUserGestureForTests(bool ignore) {
706 g_ignore_user_gesture_for_tests = ignore;
707 }
708
709 bool WebstorePrivateSignInFunction::RunImpl() {
710 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_);
711 EXTENSION_FUNCTION_VALIDATE(params);
712
713 // This API must be called only in response to a user gesture.
714 if (!user_gesture() && !g_ignore_user_gesture_for_tests) {
715 error_ = "user_gesture_required";
716 SendResponse(false);
717 return false;
718 }
719
720 // The |continue_url| is required, and must be hosted on the same origin as
721 // the calling page.
722 GURL continue_url(params->continue_url);
723 content::WebContents* web_contents = GetAssociatedWebContents();
724 if (!continue_url.is_valid() ||
725 continue_url.GetOrigin() !=
726 web_contents->GetLastCommittedURL().GetOrigin()) {
727 error_ = "invalid_continue_url";
728 SendResponse(false);
729 return false;
730 }
731
732 // If sign-in is disallowed, give up.
733 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile());
734 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() ||
735 switches::IsEnableWebBasedSignin()) {
736 error_ = "signin_is_disallowed";
737 SendResponse(false);
738 return false;
739 }
740
741 // If the user is already signed in, there's nothing else to do.
742 if (!signin_manager_->GetAuthenticatedUsername().empty()) {
743 SendResponse(true);
744 return false;
745 }
746
747 // If an authentication is currently in progress, wait for it to complete.
748 if (signin_manager_->AuthInProgress()) {
749 SigninManagerFactory::GetInstance()->AddObserver(this);
750 signin_tracker_ =
751 SigninTrackerFactory::CreateForProfile(GetProfile(), this).Pass();
752 AddRef(); // Balanced in the sign-in observer methods below.
753 return true;
not at google - send to devlin 2014/04/21 18:04:42 true means to reply straight away. you should retu
Ilya Sherman 2014/04/22 05:02:32 Hmm, I tried changing this to |return false|, and
not at google - send to devlin 2014/04/22 16:22:21 I'm wrong, sorry about that. I filed bug 365732 ab
754 }
755
756 GURL signin_url =
757 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL,
758 false /* auto_close */,
759 false /* is_constrained */,
760 continue_url);
761 web_contents->GetController().LoadURL(signin_url,
762 content::Referrer(),
763 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
764 std::string());
765
766 SendResponse(true);
767 return true;
768 }
769
770 void WebstorePrivateSignInFunction::SigninManagerShutdown(
771 SigninManagerBase* manager) {
772 if (manager == signin_manager_)
773 SigninFailed(GoogleServiceAuthError::AuthErrorNone());
774 }
775
776 void WebstorePrivateSignInFunction::SigninFailed(
777 const GoogleServiceAuthError& error) {
778 error_ = "signin_failed";
779 SendResponse(false);
780
781 SigninManagerFactory::GetInstance()->RemoveObserver(this);
782 Release(); // Balanced in RunImpl().
783 }
784
785 void WebstorePrivateSignInFunction::SigninSuccess() {
786 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called.
787 }
788
789 void WebstorePrivateSignInFunction::MergeSessionComplete(
790 const GoogleServiceAuthError& error) {
791 if (error.state() == GoogleServiceAuthError::NONE) {
792 SendResponse(true);
793 } else {
794 error_ = "merge_session_failed";
795 SendResponse(false);
796 }
797
798 SigninManagerFactory::GetInstance()->RemoveObserver(this);
799 Release(); // Balanced in RunImpl().
800 }
801
691 } // namespace extensions 802 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698