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/ui/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 #include "ui/base/resource/resource_bundle.h" | 77 #include "ui/base/resource/resource_bundle.h" |
78 | 78 |
79 | 79 |
80 namespace { | 80 namespace { |
81 | 81 |
82 // StartSyncArgs -------------------------------------------------------------- | 82 // StartSyncArgs -------------------------------------------------------------- |
83 | 83 |
84 // Arguments used with StartSync function. base::Bind() cannot support too | 84 // Arguments used with StartSync function. base::Bind() cannot support too |
85 // many args for performance reasons, so they are packaged up into a struct. | 85 // many args for performance reasons, so they are packaged up into a struct. |
86 struct StartSyncArgs { | 86 struct StartSyncArgs { |
87 StartSyncArgs(Profile* profile, | 87 StartSyncArgs( |
88 Browser* browser, | 88 Profile* profile, |
89 OneClickSigninHelper::AutoAccept auto_accept, | 89 Browser* browser, |
90 const std::string& session_index, | 90 OneClickSigninHelper::AutoAccept auto_accept, |
91 const std::string& email, | 91 const std::string& session_index, |
92 const std::string& password, | 92 const std::string& email, |
93 bool force_same_tab_navigation, | 93 const std::string& password, |
94 bool confirmation_required); | 94 bool force_same_tab_navigation, |
95 bool untrusted_confirmation_required, | |
96 SyncPromoUI::Source source); | |
95 | 97 |
96 Profile* profile; | 98 Profile* profile; |
97 Browser* browser; | 99 Browser* browser; |
98 OneClickSigninHelper::AutoAccept auto_accept; | 100 OneClickSigninHelper::AutoAccept auto_accept; |
99 std::string session_index; | 101 std::string session_index; |
100 std::string email; | 102 std::string email; |
101 std::string password; | 103 std::string password; |
102 bool force_same_tab_navigation; | 104 bool force_same_tab_navigation; |
103 bool confirmation_required; | 105 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required; |
104 }; | 106 }; |
105 | 107 |
106 StartSyncArgs::StartSyncArgs(Profile* profile, | 108 StartSyncArgs::StartSyncArgs( |
107 Browser* browser, | 109 Profile* profile, |
108 OneClickSigninHelper::AutoAccept auto_accept, | 110 Browser* browser, |
109 const std::string& session_index, | 111 OneClickSigninHelper::AutoAccept auto_accept, |
110 const std::string& email, | 112 const std::string& session_index, |
111 const std::string& password, | 113 const std::string& email, |
112 bool force_same_tab_navigation, | 114 const std::string& password, |
113 bool confirmation_required) | 115 bool force_same_tab_navigation, |
116 bool untrusted_confirmation_required, | |
117 SyncPromoUI::Source source) | |
114 : profile(profile), | 118 : profile(profile), |
115 browser(browser), | 119 browser(browser), |
116 auto_accept(auto_accept), | 120 auto_accept(auto_accept), |
117 session_index(session_index), | 121 session_index(session_index), |
118 email(email), | 122 email(email), |
119 password(password), | 123 password(password), |
120 force_same_tab_navigation(force_same_tab_navigation), | 124 force_same_tab_navigation(force_same_tab_navigation) { |
121 confirmation_required(confirmation_required) { | 125 if (untrusted_confirmation_required) { |
126 confirmation_required = OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN; | |
127 } else if (source == SyncPromoUI::SOURCE_SETTINGS || | |
128 source == SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | |
129 // Do not display a status confirmation for webstore installs or re-auth. | |
130 confirmation_required = OneClickSigninSyncStarter::NO_CONFIRMATION; | |
131 } else { | |
132 confirmation_required = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | |
133 } | |
122 } | 134 } |
123 | 135 |
124 | 136 |
125 // Helpers -------------------------------------------------------------------- | 137 // Helpers -------------------------------------------------------------------- |
126 | 138 |
127 // Add a specific email to the list of emails rejected for one-click | 139 // Add a specific email to the list of emails rejected for one-click |
128 // sign-in, for this profile. | 140 // sign-in, for this profile. |
129 void AddEmailToOneClickRejectedList(Profile* profile, | 141 void AddEmailToOneClickRejectedList(Profile* profile, |
130 const std::string& email) { | 142 const std::string& email) { |
131 PrefService* pref_service = profile->GetPrefs(); | 143 PrefService* pref_service = profile->GetPrefs(); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 482 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
471 | 483 |
472 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 484 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
473 : content::WebContentsObserver(web_contents), | 485 : content::WebContentsObserver(web_contents), |
474 showing_signin_(false), | 486 showing_signin_(false), |
475 auto_accept_(AUTO_ACCEPT_NONE), | 487 auto_accept_(AUTO_ACCEPT_NONE), |
476 source_(SyncPromoUI::SOURCE_UNKNOWN), | 488 source_(SyncPromoUI::SOURCE_UNKNOWN), |
477 switched_to_advanced_(false), | 489 switched_to_advanced_(false), |
478 original_source_(SyncPromoUI::SOURCE_UNKNOWN), | 490 original_source_(SyncPromoUI::SOURCE_UNKNOWN), |
479 untrusted_navigations_since_signin_visit_(0), | 491 untrusted_navigations_since_signin_visit_(0), |
480 confirmation_required_(false) { | 492 untrusted_confirmation_required_(false) { |
481 } | 493 } |
482 | 494 |
483 OneClickSigninHelper::~OneClickSigninHelper() { | 495 OneClickSigninHelper::~OneClickSigninHelper() { |
484 content::WebContents* contents = web_contents(); | 496 content::WebContents* contents = web_contents(); |
485 if (contents) { | 497 if (contents) { |
486 Profile* profile = | 498 Profile* profile = |
487 Profile::FromBrowserContext(contents->GetBrowserContext()); | 499 Profile::FromBrowserContext(contents->GetBrowserContext()); |
488 ProfileSyncService* sync_service = | 500 ProfileSyncService* sync_service = |
489 ProfileSyncServiceFactory::GetForProfile(profile); | 501 ProfileSyncServiceFactory::GetForProfile(profile); |
490 if (sync_service && sync_service->HasObserver(this)) | 502 if (sync_service && sync_service->HasObserver(this)) |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 CanOfferFor can_offer_for = | 836 CanOfferFor can_offer_for = |
825 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 837 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
826 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 838 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
827 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 839 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
828 | 840 |
829 std::string error_message; | 841 std::string error_message; |
830 | 842 |
831 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 843 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
832 &error_message)) { | 844 &error_message)) { |
833 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 845 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
846 // TODO(rogerta): Can we just display our error now instead of keeping it | |
847 // around and doing it later? | |
834 if (helper && helper->error_message_.empty() && !error_message.empty()) | 848 if (helper && helper->error_message_.empty() && !error_message.empty()) |
835 helper->error_message_ = error_message; | 849 helper->error_message_ = error_message; |
836 | 850 |
837 return; | 851 return; |
838 } | 852 } |
839 | 853 |
840 // Only allow the dedicated signin process to sign the user into | 854 // Only allow the dedicated signin process to sign the user into |
841 // Chrome without intervention, because it doesn't load any untrusted | 855 // Chrome without intervention, because it doesn't load any untrusted |
842 // pages. If at any point an untrusted page is detected, chrome will | 856 // pages. If at any point an untrusted page is detected, chrome will |
843 // show a modal dialog asking the user to confirm. | 857 // show a modal dialog asking the user to confirm. |
844 Profile* profile = | 858 Profile* profile = |
845 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 859 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
846 SigninManager* manager = profile ? | 860 SigninManager* manager = profile ? |
847 SigninManagerFactory::GetForProfile(profile) : NULL; | 861 SigninManagerFactory::GetForProfile(profile) : NULL; |
848 helper->confirmation_required_ |= (manager && | 862 helper->untrusted_confirmation_required_ |= |
849 !manager->IsSigninProcess(child_id)); | 863 (manager && !manager->IsSigninProcess(child_id)); |
850 | 864 |
851 // Save the email in the one-click signin manager. The manager may | 865 // Save the email in the one-click signin manager. The manager may |
852 // not exist if the contents is incognito or if the profile is already | 866 // not exist if the contents is incognito or if the profile is already |
853 // connected to a Google account. | 867 // connected to a Google account. |
854 if (!session_index.empty()) | 868 if (!session_index.empty()) |
855 helper->session_index_ = session_index; | 869 helper->session_index_ = session_index; |
856 | 870 |
857 if (!email.empty()) | 871 if (!email.empty()) |
858 helper->email_ = email; | 872 helper->email_ = email; |
859 | 873 |
860 if (continue_url.is_valid()) | 874 if (continue_url.is_valid()) |
861 helper->continue_url_ = continue_url; | 875 helper->continue_url_ = continue_url; |
862 } | 876 } |
863 | 877 |
864 // static | 878 // static |
865 void OneClickSigninHelper::RemoveCurrentHistoryItem( | 879 void OneClickSigninHelper::RemoveCurrentHistoryItem( |
866 content::WebContents* web_contents) { | 880 content::WebContents* web_contents) { |
867 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished | 881 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished |
868 } | 882 } |
869 | 883 |
870 void OneClickSigninHelper::ShowSyncConfirmationBubble(bool show_bubble) { | 884 void OneClickSigninHelper::ShowSigninErrorBubble(const std::string& error) { |
871 if (show_bubble) { | 885 DCHECK(!error.empty()); |
872 content::WebContents* contents = web_contents(); | 886 content::WebContents* contents = web_contents(); |
873 Profile* profile = | 887 Profile* profile = |
874 Profile::FromBrowserContext(contents->GetBrowserContext()); | 888 Profile::FromBrowserContext(contents->GetBrowserContext()); |
875 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 889 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
876 | 890 |
877 browser->window()->ShowOneClickSigninBubble( | 891 browser->window()->ShowOneClickSigninBubble( |
878 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 892 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
879 string16(), /* no SAML email */ | 893 string16(), /* no SAML email */ |
880 UTF8ToUTF16(error_message_), | 894 UTF8ToUTF16(error), |
881 base::Bind(&StartSync, | 895 // This callback is never invoked. |
882 StartSyncArgs(profile, browser, AUTO_ACCEPT_ACCEPTED, | 896 // TODO(rogerta): Separate out the bubble API so we don't have to pass |
883 session_index_, email_, password_, | 897 // ignored |email| and |callback| params. |
884 false, confirmation_required_))); | 898 base::Bind(&StartSync, |
885 } | 899 StartSyncArgs(profile, browser, AUTO_ACCEPT_ACCEPTED, |
886 error_message_.clear(); | 900 session_index_, email_, password_, |
901 false, untrusted_confirmation_required_, | |
902 source_))); | |
887 } | 903 } |
888 | 904 |
889 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { | 905 void OneClickSigninHelper::RedirectToNtpOrAppsPage() { |
890 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; | 906 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; |
891 | |
892 // Redirect to NTP/Apps page and display a confirmation bubble | 907 // Redirect to NTP/Apps page and display a confirmation bubble |
893 content::WebContents* contents = web_contents(); | 908 content::WebContents* contents = web_contents(); |
894 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? | 909 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? |
895 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | 910 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); |
896 content::OpenURLParams params(url, | 911 content::OpenURLParams params(url, |
897 content::Referrer(), | 912 content::Referrer(), |
898 CURRENT_TAB, | 913 CURRENT_TAB, |
899 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 914 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
900 false); | 915 false); |
901 contents->OpenURL(params); | 916 contents->OpenURL(params); |
902 | |
903 ShowSyncConfirmationBubble(show_bubble); | |
904 } | 917 } |
905 | 918 |
906 void OneClickSigninHelper::RedirectToSignin() { | 919 void OneClickSigninHelper::RedirectToSignin() { |
907 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; | 920 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; |
908 | 921 |
909 // Extract the existing sounce=X value. Default to "2" if missing. | 922 // Extract the existing sounce=X value. Default to "2" if missing. |
910 SyncPromoUI::Source source = | 923 SyncPromoUI::Source source = |
911 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); | 924 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); |
912 if (source == SyncPromoUI::SOURCE_UNKNOWN) | 925 if (source == SyncPromoUI::SOURCE_UNKNOWN) |
913 source = SyncPromoUI::SOURCE_MENU; | 926 source = SyncPromoUI::SOURCE_MENU; |
(...skipping 10 matching lines...) Expand all Loading... | |
924 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 937 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
925 showing_signin_ = false; | 938 showing_signin_ = false; |
926 email_.clear(); | 939 email_.clear(); |
927 password_.clear(); | 940 password_.clear(); |
928 auto_accept_ = AUTO_ACCEPT_NONE; | 941 auto_accept_ = AUTO_ACCEPT_NONE; |
929 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 942 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
930 switched_to_advanced_ = false; | 943 switched_to_advanced_ = false; |
931 original_source_ = SyncPromoUI::SOURCE_UNKNOWN; | 944 original_source_ = SyncPromoUI::SOURCE_UNKNOWN; |
932 continue_url_ = GURL(); | 945 continue_url_ = GURL(); |
933 untrusted_navigations_since_signin_visit_ = 0; | 946 untrusted_navigations_since_signin_visit_ = 0; |
934 confirmation_required_ = false; | 947 untrusted_confirmation_required_ = false; |
948 error_message_.clear(); | |
935 | 949 |
936 // Post to IO thread to clear pending email. | 950 // Post to IO thread to clear pending email. |
937 Profile* profile = | 951 Profile* profile = |
938 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 952 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
939 content::BrowserThread::PostTask( | 953 content::BrowserThread::PostTask( |
940 content::BrowserThread::IO, FROM_HERE, | 954 content::BrowserThread::IO, FROM_HERE, |
941 base::Bind(&ClearPendingEmailOnIOThread, | 955 base::Bind(&ClearPendingEmailOnIOThread, |
942 base::Unretained(profile->GetResourceContext()))); | 956 base::Unretained(profile->GetResourceContext()))); |
943 } | 957 } |
944 | 958 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 // TODO(rogerta): might need to allow some youtube URLs. | 1013 // TODO(rogerta): might need to allow some youtube URLs. |
1000 content::WebContents* contents = web_contents(); | 1014 content::WebContents* contents = web_contents(); |
1001 const GURL url = contents->GetURL(); | 1015 const GURL url = contents->GetURL(); |
1002 Profile* profile = | 1016 Profile* profile = |
1003 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1017 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1004 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); | 1018 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); |
1005 | 1019 |
1006 // If an error has already occured during the sign in flow, make sure to | 1020 // If an error has already occured during the sign in flow, make sure to |
1007 // display it to the user and abort the process. Do this only for | 1021 // display it to the user and abort the process. Do this only for |
1008 // explicit sign ins. | 1022 // explicit sign ins. |
1023 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? | |
1009 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1024 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
1010 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1025 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
1011 RemoveCurrentHistoryItem(contents); | 1026 RemoveCurrentHistoryItem(contents); |
1012 RedirectToNtpOrAppsPage(true); | 1027 // Redirect to the landing page and display an error popup. |
1028 RedirectToNtpOrAppsPage(); | |
1029 ShowSigninErrorBubble(error_message_); | |
1030 CleanTransientState(); | |
1013 return; | 1031 return; |
1014 } | 1032 } |
1015 | 1033 |
1016 if (AreWeShowingSignin(url, source_, email_)) { | 1034 if (AreWeShowingSignin(url, source_, email_)) { |
1017 if (!showing_signin_) { | 1035 if (!showing_signin_) { |
1018 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) | 1036 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) |
1019 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); | 1037 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); |
1020 else | 1038 else |
1021 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); | 1039 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); |
1022 } | 1040 } |
(...skipping 14 matching lines...) Expand all Loading... | |
1037 // password is allowed to be empty, since its no longer required to setup | 1055 // password is allowed to be empty, since its no longer required to setup |
1038 // sync. | 1056 // sync. |
1039 if (email_.empty()) { | 1057 if (email_.empty()) { |
1040 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; | 1058 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; |
1041 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) | 1059 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) |
1042 RedirectToSignin(); | 1060 RedirectToSignin(); |
1043 std::string unused_value; | 1061 std::string unused_value; |
1044 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { | 1062 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { |
1045 SyncPromoUI::SetUserSkippedSyncPromo(profile); | 1063 SyncPromoUI::SetUserSkippedSyncPromo(profile); |
1046 RemoveCurrentHistoryItem(contents); | 1064 RemoveCurrentHistoryItem(contents); |
1047 RedirectToNtpOrAppsPage(false); | 1065 RedirectToNtpOrAppsPage(); |
1048 } | 1066 } |
1049 | 1067 |
1050 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && | 1068 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && |
1051 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { | 1069 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { |
1052 CleanTransientState(); | 1070 CleanTransientState(); |
1053 } | 1071 } |
1054 | 1072 |
1055 return; | 1073 return; |
1056 } | 1074 } |
1057 | 1075 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 | 1134 |
1117 switch (auto_accept_) { | 1135 switch (auto_accept_) { |
1118 case AUTO_ACCEPT_NONE: | 1136 case AUTO_ACCEPT_NONE: |
1119 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) | 1137 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) |
1120 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); | 1138 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
1121 break; | 1139 break; |
1122 case AUTO_ACCEPT_ACCEPTED: | 1140 case AUTO_ACCEPT_ACCEPTED: |
1123 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1141 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1124 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1142 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1125 SigninManager::DisableOneClickSignIn(profile); | 1143 SigninManager::DisableOneClickSignIn(profile); |
1144 // No need to display a second confirmation since we're displaying one | |
1145 // already. | |
1146 untrusted_confirmation_required_ = false; | |
1126 browser->window()->ShowOneClickSigninBubble( | 1147 browser->window()->ShowOneClickSigninBubble( |
1127 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG, | 1148 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG, |
1128 UTF8ToUTF16(email_), | 1149 UTF8ToUTF16(email_), |
1129 string16(), /* no error message to display */ | 1150 string16(), /* no error message to display */ |
1130 base::Bind(&StartSync, | 1151 base::Bind(&StartSync, |
1131 StartSyncArgs(profile, browser, auto_accept_, | 1152 StartSyncArgs(profile, browser, auto_accept_, |
1132 session_index_, email_, password_, | 1153 session_index_, email_, password_, |
1133 false /* force_same_tab_navigation */, | 1154 false /* force_same_tab_navigation */, |
1134 confirmation_required_))); | 1155 untrusted_confirmation_required_, source_))); |
1135 break; | 1156 break; |
1136 case AUTO_ACCEPT_CONFIGURE: | 1157 case AUTO_ACCEPT_CONFIGURE: |
1137 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1158 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1138 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1159 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1139 SigninManager::DisableOneClickSignIn(profile); | 1160 SigninManager::DisableOneClickSignIn(profile); |
1140 StartSync( | 1161 StartSync( |
1141 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1162 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, |
1142 password_, false /* force_same_tab_navigation */, | 1163 password_, false /* force_same_tab_navigation */, |
1143 confirmation_required_), | 1164 untrusted_confirmation_required_, source_), |
Roger Tawa OOO till Jul 10th
2013/05/06 15:46:39
I think |untrusted_confirmation_required| should b
Andrew T Wilson (Slow)
2013/05/06 17:00:13
I'm slightly nervous about this since the user isn
Roger Tawa OOO till Jul 10th
2013/05/06 20:14:01
OK.
| |
1144 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1165 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
1145 break; | 1166 break; |
1146 case AUTO_ACCEPT_EXPLICIT: { | 1167 case AUTO_ACCEPT_EXPLICIT: { |
1147 if (switched_to_advanced_) { | 1168 if (switched_to_advanced_) { |
1148 LogHistogramValue(original_source_, | 1169 LogHistogramValue(original_source_, |
1149 one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1170 one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1150 LogHistogramValue(original_source_, | 1171 LogHistogramValue(original_source_, |
1151 one_click_signin::HISTOGRAM_ACCEPTED); | 1172 one_click_signin::HISTOGRAM_ACCEPTED); |
1152 } else { | 1173 } else { |
1153 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); | 1174 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); |
1154 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1175 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1155 } | 1176 } |
1156 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1177 OneClickSigninSyncStarter::StartSyncMode start_mode = |
1157 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 1178 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
1158 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1179 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
1159 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1180 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
1160 | 1181 |
1161 std::string last_email = | 1182 std::string last_email = |
1162 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1183 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
1163 | 1184 |
1164 if (!last_email.empty() && last_email != email_) { | 1185 if (!last_email.empty() && last_email != email_) { |
1165 // If the new email address is different from the email address that | 1186 // If the new email address is different from the email address that |
1166 // just signed in, show a confirmation dialog. | 1187 // just signed in, show a confirmation dialog. |
1167 | 1188 |
1168 // No need to display a second confirmation. | 1189 // No need to display a second confirmation. |
1169 confirmation_required_ = false; | 1190 untrusted_confirmation_required_ = false; |
1170 ConfirmEmailDialogDelegate::AskForConfirmation( | 1191 ConfirmEmailDialogDelegate::AskForConfirmation( |
1171 contents, | 1192 contents, |
1172 last_email, | 1193 last_email, |
1173 email_, | 1194 email_, |
1174 base::Bind( | 1195 base::Bind( |
1175 &StartExplicitSync, | 1196 &StartExplicitSync, |
1176 StartSyncArgs(profile, browser, auto_accept_, | 1197 StartSyncArgs(profile, browser, auto_accept_, |
1177 session_index_, email_, password_, | 1198 session_index_, email_, password_, |
1178 force_same_tab_navigation, | 1199 force_same_tab_navigation, |
1179 confirmation_required_), | 1200 untrusted_confirmation_required_, source_), |
1180 contents, | 1201 contents, |
1181 start_mode)); | 1202 start_mode)); |
1182 } else { | 1203 } else { |
1183 StartExplicitSync( | 1204 StartExplicitSync( |
1184 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1205 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
1185 email_, password_, force_same_tab_navigation, | 1206 email_, password_, force_same_tab_navigation, |
1186 confirmation_required_), | 1207 untrusted_confirmation_required_, source_), |
1187 contents, | 1208 contents, |
1188 start_mode, | 1209 start_mode, |
1189 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | 1210 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); |
1190 } | 1211 } |
1191 | 1212 |
1192 if (source_ == SyncPromoUI::SOURCE_SETTINGS && | 1213 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
1193 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1214 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
1194 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1215 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1195 redirect_url_ = continue_url_; | 1216 redirect_url_ = continue_url_; |
1196 ProfileSyncService* sync_service = | 1217 ProfileSyncService* sync_service = |
1197 ProfileSyncServiceFactory::GetForProfile(profile); | 1218 ProfileSyncServiceFactory::GetForProfile(profile); |
1198 if (sync_service) | 1219 if (sync_service) |
1199 sync_service->AddObserver(this); | 1220 sync_service->AddObserver(this); |
1200 } | 1221 } |
1201 | 1222 |
1202 // If this explicit sign in is not from settings page/webstore, show the | 1223 // If this explicit sign in is not from settings page/webstore, show the |
1203 // NTP/Apps page after sign in completes. In the case of the settings | 1224 // NTP/Apps page after sign in completes. In the case of the settings |
1204 // page, it will get closed by SyncSetupHandler. In the case of webstore, | 1225 // page, it will get closed by SyncSetupHandler. In the case of webstore, |
1205 // it will redirect back to webstore. | 1226 // it will redirect back to webstore. |
1206 if (source_ != SyncPromoUI::SOURCE_SETTINGS && | 1227 if (source_ != SyncPromoUI::SOURCE_SETTINGS && |
1207 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1228 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1208 signin_tracker_.reset(new SigninTracker(profile, this)); | |
1209 RemoveCurrentHistoryItem(contents); | 1229 RemoveCurrentHistoryItem(contents); |
1210 RedirectToNtpOrAppsPage(false); | 1230 RedirectToNtpOrAppsPage(); |
1211 } | 1231 } |
1212 break; | 1232 break; |
1213 } | 1233 } |
1214 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1234 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1215 AddEmailToOneClickRejectedList(profile, email_); | 1235 AddEmailToOneClickRejectedList(profile, email_); |
1216 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1236 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1217 break; | 1237 break; |
1218 default: | 1238 default: |
1219 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1239 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1220 break; | 1240 break; |
1221 } | 1241 } |
1222 | 1242 |
1223 CleanTransientState(); | 1243 CleanTransientState(); |
1224 } | 1244 } |
1225 | 1245 |
1226 void OneClickSigninHelper::GaiaCredentialsValid() { | |
1227 } | |
1228 | |
1229 void OneClickSigninHelper::OnStateChanged() { | 1246 void OneClickSigninHelper::OnStateChanged() { |
1230 // No redirect url after sync setup is set, thus no need to watch for sync | 1247 // No redirect url after sync setup is set, thus no need to watch for sync |
1231 // state changes. | 1248 // state changes. |
1232 if (redirect_url_.is_empty()) | 1249 if (redirect_url_.is_empty()) |
1233 return; | 1250 return; |
1234 | 1251 |
1235 content::WebContents* contents = web_contents(); | 1252 content::WebContents* contents = web_contents(); |
1236 Profile* profile = | 1253 Profile* profile = |
1237 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1254 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1238 ProfileSyncService* sync_service = | 1255 ProfileSyncService* sync_service = |
1239 ProfileSyncServiceFactory::GetForProfile(profile); | 1256 ProfileSyncServiceFactory::GetForProfile(profile); |
1240 | 1257 |
1241 // Sync setup not completed yet. | 1258 // Sync setup not completed yet. |
1242 if (sync_service->FirstSetupInProgress()) | 1259 if (sync_service->FirstSetupInProgress()) |
1243 return; | 1260 return; |
1244 | 1261 |
1245 if (sync_service->sync_initialized()) { | 1262 if (sync_service->sync_initialized()) { |
1246 contents->GetController().LoadURL(redirect_url_, | 1263 contents->GetController().LoadURL(redirect_url_, |
1247 content::Referrer(), | 1264 content::Referrer(), |
1248 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1265 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1249 std::string()); | 1266 std::string()); |
1250 } | 1267 } |
1251 | 1268 |
1252 // Clear the redirect URL. | 1269 // Clear the redirect URL. |
1253 redirect_url_ = GURL(); | 1270 redirect_url_ = GURL(); |
1254 sync_service->RemoveObserver(this); | 1271 sync_service->RemoveObserver(this); |
1255 } | 1272 } |
1256 | |
1257 void OneClickSigninHelper::SigninFailed(const GoogleServiceAuthError& error) { | |
1258 if (error_message_.empty() && !error.error_message().empty()) | |
1259 error_message_ = error.error_message(); | |
1260 | |
1261 bool display_bubble = true; | |
1262 if (error_message_.empty()) { | |
1263 switch (error.state()) { | |
1264 case GoogleServiceAuthError::NONE: | |
1265 error_message_.clear(); | |
1266 break; | |
1267 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | |
1268 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_UNRECOVERABLE_ERROR); | |
1269 break; | |
1270 case GoogleServiceAuthError::REQUEST_CANCELED: | |
1271 // If the user cancelled signin, then no need to display any error | |
1272 // messages or anything - just go back to the NTP. | |
1273 error_message_.clear(); | |
1274 display_bubble = false; | |
1275 break; | |
1276 default: | |
1277 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_ERROR_SIGNING_IN); | |
1278 break; | |
1279 } | |
1280 } | |
1281 ShowSyncConfirmationBubble(display_bubble); | |
1282 signin_tracker_.reset(); | |
1283 } | |
1284 | |
1285 void OneClickSigninHelper::SigninSuccess() { | |
1286 ShowSyncConfirmationBubble(true); | |
1287 signin_tracker_.reset(); | |
1288 } | |
OLD | NEW |