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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 one_click_signin::HISTOGRAM_MAX); | 195 one_click_signin::HISTOGRAM_MAX); |
184 } | 196 } |
185 | 197 |
186 // Start syncing with the given user information. | 198 // Start syncing with the given user information. |
187 void StartSync(const StartSyncArgs& args, | 199 void StartSync(const StartSyncArgs& args, |
188 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 200 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
189 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { | 201 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { |
190 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); | 202 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); |
191 return; | 203 return; |
192 } | 204 } |
| 205 |
| 206 // If we are giving the user the option to configure sync, then that will |
| 207 // suffice as a confirmation. |
| 208 OneClickSigninSyncStarter::ConfirmationRequired confirmation = |
| 209 args.confirmation_required; |
| 210 if (start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST && |
| 211 confirmation == OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN) { |
| 212 confirmation = OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
| 213 } |
| 214 |
193 // The starter deletes itself once its done. | 215 // The starter deletes itself once its done. |
194 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, | 216 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, |
195 args.email, args.password, start_mode, | 217 args.email, args.password, start_mode, |
196 args.force_same_tab_navigation, | 218 args.force_same_tab_navigation, |
197 args.confirmation_required); | 219 confirmation); |
198 | 220 |
199 int action = one_click_signin::HISTOGRAM_MAX; | 221 int action = one_click_signin::HISTOGRAM_MAX; |
200 switch (args.auto_accept) { | 222 switch (args.auto_accept) { |
201 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: | 223 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: |
202 break; | 224 break; |
203 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: | 225 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: |
204 action = | 226 action = |
205 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? | 227 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? |
206 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : | 228 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : |
207 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 229 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); | 492 DEFINE_WEB_CONTENTS_USER_DATA_KEY(OneClickSigninHelper); |
471 | 493 |
472 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 494 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
473 : content::WebContentsObserver(web_contents), | 495 : content::WebContentsObserver(web_contents), |
474 showing_signin_(false), | 496 showing_signin_(false), |
475 auto_accept_(AUTO_ACCEPT_NONE), | 497 auto_accept_(AUTO_ACCEPT_NONE), |
476 source_(SyncPromoUI::SOURCE_UNKNOWN), | 498 source_(SyncPromoUI::SOURCE_UNKNOWN), |
477 switched_to_advanced_(false), | 499 switched_to_advanced_(false), |
478 original_source_(SyncPromoUI::SOURCE_UNKNOWN), | 500 original_source_(SyncPromoUI::SOURCE_UNKNOWN), |
479 untrusted_navigations_since_signin_visit_(0), | 501 untrusted_navigations_since_signin_visit_(0), |
480 confirmation_required_(false) { | 502 untrusted_confirmation_required_(false) { |
481 } | 503 } |
482 | 504 |
483 OneClickSigninHelper::~OneClickSigninHelper() { | 505 OneClickSigninHelper::~OneClickSigninHelper() { |
484 content::WebContents* contents = web_contents(); | 506 content::WebContents* contents = web_contents(); |
485 if (contents) { | 507 if (contents) { |
486 Profile* profile = | 508 Profile* profile = |
487 Profile::FromBrowserContext(contents->GetBrowserContext()); | 509 Profile::FromBrowserContext(contents->GetBrowserContext()); |
488 ProfileSyncService* sync_service = | 510 ProfileSyncService* sync_service = |
489 ProfileSyncServiceFactory::GetForProfile(profile); | 511 ProfileSyncServiceFactory::GetForProfile(profile); |
490 if (sync_service && sync_service->HasObserver(this)) | 512 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 = | 846 CanOfferFor can_offer_for = |
825 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 847 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
826 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 848 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
827 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 849 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
828 | 850 |
829 std::string error_message; | 851 std::string error_message; |
830 | 852 |
831 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 853 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
832 &error_message)) { | 854 &error_message)) { |
833 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 855 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
| 856 // TODO(rogerta): Can we just display our error now instead of keeping it |
| 857 // around and doing it later? |
834 if (helper && helper->error_message_.empty() && !error_message.empty()) | 858 if (helper && helper->error_message_.empty() && !error_message.empty()) |
835 helper->error_message_ = error_message; | 859 helper->error_message_ = error_message; |
836 | 860 |
837 return; | 861 return; |
838 } | 862 } |
839 | 863 |
840 // Only allow the dedicated signin process to sign the user into | 864 // Only allow the dedicated signin process to sign the user into |
841 // Chrome without intervention, because it doesn't load any untrusted | 865 // Chrome without intervention, because it doesn't load any untrusted |
842 // pages. If at any point an untrusted page is detected, chrome will | 866 // pages. If at any point an untrusted page is detected, chrome will |
843 // show a modal dialog asking the user to confirm. | 867 // show a modal dialog asking the user to confirm. |
844 Profile* profile = | 868 Profile* profile = |
845 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 869 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
846 SigninManager* manager = profile ? | 870 SigninManager* manager = profile ? |
847 SigninManagerFactory::GetForProfile(profile) : NULL; | 871 SigninManagerFactory::GetForProfile(profile) : NULL; |
848 helper->confirmation_required_ |= (manager && | 872 helper->untrusted_confirmation_required_ |= |
849 !manager->IsSigninProcess(child_id)); | 873 (manager && !manager->IsSigninProcess(child_id)); |
850 | 874 |
851 // Save the email in the one-click signin manager. The manager may | 875 // 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 | 876 // not exist if the contents is incognito or if the profile is already |
853 // connected to a Google account. | 877 // connected to a Google account. |
854 if (!session_index.empty()) | 878 if (!session_index.empty()) |
855 helper->session_index_ = session_index; | 879 helper->session_index_ = session_index; |
856 | 880 |
857 if (!email.empty()) | 881 if (!email.empty()) |
858 helper->email_ = email; | 882 helper->email_ = email; |
859 | 883 |
860 if (continue_url.is_valid()) | 884 if (continue_url.is_valid()) |
861 helper->continue_url_ = continue_url; | 885 helper->continue_url_ = continue_url; |
862 } | 886 } |
863 | 887 |
864 // static | 888 // static |
865 void OneClickSigninHelper::RemoveCurrentHistoryItem( | 889 void OneClickSigninHelper::RemoveCurrentHistoryItem( |
866 content::WebContents* web_contents) { | 890 content::WebContents* web_contents) { |
867 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished | 891 new CurrentHistoryCleaner(web_contents); // will self-destruct when finished |
868 } | 892 } |
869 | 893 |
870 void OneClickSigninHelper::ShowSyncConfirmationBubble(bool show_bubble) { | 894 void OneClickSigninHelper::ShowSigninErrorBubble(const std::string& error) { |
871 if (show_bubble) { | 895 DCHECK(!error.empty()); |
872 content::WebContents* contents = web_contents(); | 896 content::WebContents* contents = web_contents(); |
873 Profile* profile = | 897 Profile* profile = |
874 Profile::FromBrowserContext(contents->GetBrowserContext()); | 898 Profile::FromBrowserContext(contents->GetBrowserContext()); |
875 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 899 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
876 | 900 |
877 browser->window()->ShowOneClickSigninBubble( | 901 browser->window()->ShowOneClickSigninBubble( |
878 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 902 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
879 string16(), /* no SAML email */ | 903 string16(), /* no SAML email */ |
880 UTF8ToUTF16(error_message_), | 904 UTF8ToUTF16(error), |
881 base::Bind(&StartSync, | 905 // This callback is never invoked. |
882 StartSyncArgs(profile, browser, AUTO_ACCEPT_ACCEPTED, | 906 // TODO(rogerta): Separate out the bubble API so we don't have to pass |
883 session_index_, email_, password_, | 907 // ignored |email| and |callback| params. |
884 false, confirmation_required_))); | 908 base::Bind(&StartSync, |
885 } | 909 StartSyncArgs(profile, browser, AUTO_ACCEPT_ACCEPTED, |
886 error_message_.clear(); | 910 session_index_, email_, password_, |
| 911 false, untrusted_confirmation_required_, |
| 912 source_))); |
887 } | 913 } |
888 | 914 |
889 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) { | 915 void OneClickSigninHelper::RedirectToNtpOrAppsPage() { |
890 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; | 916 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage"; |
891 | |
892 // Redirect to NTP/Apps page and display a confirmation bubble | 917 // Redirect to NTP/Apps page and display a confirmation bubble |
893 content::WebContents* contents = web_contents(); | 918 content::WebContents* contents = web_contents(); |
894 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? | 919 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? |
895 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | 920 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); |
896 content::OpenURLParams params(url, | 921 content::OpenURLParams params(url, |
897 content::Referrer(), | 922 content::Referrer(), |
898 CURRENT_TAB, | 923 CURRENT_TAB, |
899 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 924 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
900 false); | 925 false); |
901 contents->OpenURL(params); | 926 contents->OpenURL(params); |
902 | |
903 ShowSyncConfirmationBubble(show_bubble); | |
904 } | 927 } |
905 | 928 |
906 void OneClickSigninHelper::RedirectToSignin() { | 929 void OneClickSigninHelper::RedirectToSignin() { |
907 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; | 930 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; |
908 | 931 |
909 // Extract the existing sounce=X value. Default to "2" if missing. | 932 // Extract the existing sounce=X value. Default to "2" if missing. |
910 SyncPromoUI::Source source = | 933 SyncPromoUI::Source source = |
911 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); | 934 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); |
912 if (source == SyncPromoUI::SOURCE_UNKNOWN) | 935 if (source == SyncPromoUI::SOURCE_UNKNOWN) |
913 source = SyncPromoUI::SOURCE_MENU; | 936 source = SyncPromoUI::SOURCE_MENU; |
(...skipping 10 matching lines...) Expand all Loading... |
924 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 947 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
925 showing_signin_ = false; | 948 showing_signin_ = false; |
926 email_.clear(); | 949 email_.clear(); |
927 password_.clear(); | 950 password_.clear(); |
928 auto_accept_ = AUTO_ACCEPT_NONE; | 951 auto_accept_ = AUTO_ACCEPT_NONE; |
929 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 952 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
930 switched_to_advanced_ = false; | 953 switched_to_advanced_ = false; |
931 original_source_ = SyncPromoUI::SOURCE_UNKNOWN; | 954 original_source_ = SyncPromoUI::SOURCE_UNKNOWN; |
932 continue_url_ = GURL(); | 955 continue_url_ = GURL(); |
933 untrusted_navigations_since_signin_visit_ = 0; | 956 untrusted_navigations_since_signin_visit_ = 0; |
934 confirmation_required_ = false; | 957 untrusted_confirmation_required_ = false; |
| 958 error_message_.clear(); |
935 | 959 |
936 // Post to IO thread to clear pending email. | 960 // Post to IO thread to clear pending email. |
937 Profile* profile = | 961 Profile* profile = |
938 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 962 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
939 content::BrowserThread::PostTask( | 963 content::BrowserThread::PostTask( |
940 content::BrowserThread::IO, FROM_HERE, | 964 content::BrowserThread::IO, FROM_HERE, |
941 base::Bind(&ClearPendingEmailOnIOThread, | 965 base::Bind(&ClearPendingEmailOnIOThread, |
942 base::Unretained(profile->GetResourceContext()))); | 966 base::Unretained(profile->GetResourceContext()))); |
943 } | 967 } |
944 | 968 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 // TODO(rogerta): might need to allow some youtube URLs. | 1023 // TODO(rogerta): might need to allow some youtube URLs. |
1000 content::WebContents* contents = web_contents(); | 1024 content::WebContents* contents = web_contents(); |
1001 const GURL url = contents->GetURL(); | 1025 const GURL url = contents->GetURL(); |
1002 Profile* profile = | 1026 Profile* profile = |
1003 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1027 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1004 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); | 1028 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); |
1005 | 1029 |
1006 // If an error has already occured during the sign in flow, make sure to | 1030 // 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 | 1031 // display it to the user and abort the process. Do this only for |
1008 // explicit sign ins. | 1032 // explicit sign ins. |
| 1033 // TODO(rogerta): Could we move this code back up to ShowInfoBarUIThread()? |
1009 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1034 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
1010 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1035 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
1011 RemoveCurrentHistoryItem(contents); | 1036 RemoveCurrentHistoryItem(contents); |
1012 RedirectToNtpOrAppsPage(true); | 1037 // Redirect to the landing page and display an error popup. |
| 1038 RedirectToNtpOrAppsPage(); |
| 1039 ShowSigninErrorBubble(error_message_); |
| 1040 CleanTransientState(); |
1013 return; | 1041 return; |
1014 } | 1042 } |
1015 | 1043 |
1016 if (AreWeShowingSignin(url, source_, email_)) { | 1044 if (AreWeShowingSignin(url, source_, email_)) { |
1017 if (!showing_signin_) { | 1045 if (!showing_signin_) { |
1018 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) | 1046 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) |
1019 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); | 1047 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); |
1020 else | 1048 else |
1021 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); | 1049 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); |
1022 } | 1050 } |
(...skipping 14 matching lines...) Expand all Loading... |
1037 // password is allowed to be empty, since its no longer required to setup | 1065 // password is allowed to be empty, since its no longer required to setup |
1038 // sync. | 1066 // sync. |
1039 if (email_.empty()) { | 1067 if (email_.empty()) { |
1040 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; | 1068 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; |
1041 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) | 1069 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) |
1042 RedirectToSignin(); | 1070 RedirectToSignin(); |
1043 std::string unused_value; | 1071 std::string unused_value; |
1044 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { | 1072 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { |
1045 SyncPromoUI::SetUserSkippedSyncPromo(profile); | 1073 SyncPromoUI::SetUserSkippedSyncPromo(profile); |
1046 RemoveCurrentHistoryItem(contents); | 1074 RemoveCurrentHistoryItem(contents); |
1047 RedirectToNtpOrAppsPage(false); | 1075 RedirectToNtpOrAppsPage(); |
1048 } | 1076 } |
1049 | 1077 |
1050 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && | 1078 if (!continue_url_match && !IsValidGaiaSigninRedirectOrResponseURL(url) && |
1051 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { | 1079 ++untrusted_navigations_since_signin_visit_ > kMaxNavigationsSince) { |
1052 CleanTransientState(); | 1080 CleanTransientState(); |
1053 } | 1081 } |
1054 | 1082 |
1055 return; | 1083 return; |
1056 } | 1084 } |
1057 | 1085 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 | 1144 |
1117 switch (auto_accept_) { | 1145 switch (auto_accept_) { |
1118 case AUTO_ACCEPT_NONE: | 1146 case AUTO_ACCEPT_NONE: |
1119 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) | 1147 if (SyncPromoUI::UseWebBasedSigninFlow() && showing_signin_) |
1120 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); | 1148 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
1121 break; | 1149 break; |
1122 case AUTO_ACCEPT_ACCEPTED: | 1150 case AUTO_ACCEPT_ACCEPTED: |
1123 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1151 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1124 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1152 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1125 SigninManager::DisableOneClickSignIn(profile); | 1153 SigninManager::DisableOneClickSignIn(profile); |
1126 browser->window()->ShowOneClickSigninBubble( | 1154 // Start syncing with the default settings - prompt the user to sign in |
1127 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG, | 1155 // first. |
1128 UTF8ToUTF16(email_), | 1156 StartSync(StartSyncArgs(profile, browser, auto_accept_, |
1129 string16(), /* no error message to display */ | 1157 session_index_, email_, password_, |
1130 base::Bind(&StartSync, | 1158 false /* force_same_tab_navigation */, |
1131 StartSyncArgs(profile, browser, auto_accept_, | 1159 true /* confirmation_required */, source_), |
1132 session_index_, email_, password_, | 1160 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
1133 false /* force_same_tab_navigation */, | |
1134 confirmation_required_))); | |
1135 break; | 1161 break; |
1136 case AUTO_ACCEPT_CONFIGURE: | 1162 case AUTO_ACCEPT_CONFIGURE: |
1137 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | 1163 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); |
1138 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1164 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1139 SigninManager::DisableOneClickSignIn(profile); | 1165 SigninManager::DisableOneClickSignIn(profile); |
| 1166 // Don't bother displaying an extra confirmation (even in the SAML case) |
| 1167 // since the user will get prompted to setup sync anyway. |
1140 StartSync( | 1168 StartSync( |
1141 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1169 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, |
1142 password_, false /* force_same_tab_navigation */, | 1170 password_, false /* force_same_tab_navigation */, |
1143 confirmation_required_), | 1171 false /* confirmation_required */, source_), |
1144 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1172 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
1145 break; | 1173 break; |
1146 case AUTO_ACCEPT_EXPLICIT: { | 1174 case AUTO_ACCEPT_EXPLICIT: { |
1147 if (switched_to_advanced_) { | 1175 if (switched_to_advanced_) { |
1148 LogHistogramValue(original_source_, | 1176 LogHistogramValue(original_source_, |
1149 one_click_signin::HISTOGRAM_WITH_ADVANCED); | 1177 one_click_signin::HISTOGRAM_WITH_ADVANCED); |
1150 LogHistogramValue(original_source_, | 1178 LogHistogramValue(original_source_, |
1151 one_click_signin::HISTOGRAM_ACCEPTED); | 1179 one_click_signin::HISTOGRAM_ACCEPTED); |
1152 } else { | 1180 } else { |
1153 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); | 1181 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); |
1154 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); | 1182 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); |
1155 } | 1183 } |
1156 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1184 OneClickSigninSyncStarter::StartSyncMode start_mode = |
1157 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 1185 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
1158 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1186 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
1159 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1187 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
1160 | 1188 |
1161 std::string last_email = | 1189 std::string last_email = |
1162 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1190 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
1163 | 1191 |
1164 if (!last_email.empty() && last_email != email_) { | 1192 if (!last_email.empty() && last_email != email_) { |
1165 // If the new email address is different from the email address that | 1193 // If the new email address is different from the email address that |
1166 // just signed in, show a confirmation dialog. | 1194 // just signed in, show a confirmation dialog. |
1167 | 1195 |
1168 // No need to display a second confirmation. | 1196 // No need to display a second confirmation so pass false below. |
1169 confirmation_required_ = false; | 1197 // TODO(atwilson): Move this into OneClickSigninSyncStarter. |
1170 ConfirmEmailDialogDelegate::AskForConfirmation( | 1198 ConfirmEmailDialogDelegate::AskForConfirmation( |
1171 contents, | 1199 contents, |
1172 last_email, | 1200 last_email, |
1173 email_, | 1201 email_, |
1174 base::Bind( | 1202 base::Bind( |
1175 &StartExplicitSync, | 1203 &StartExplicitSync, |
1176 StartSyncArgs(profile, browser, auto_accept_, | 1204 StartSyncArgs(profile, browser, auto_accept_, |
1177 session_index_, email_, password_, | 1205 session_index_, email_, password_, |
1178 force_same_tab_navigation, | 1206 force_same_tab_navigation, |
1179 confirmation_required_), | 1207 false /* confirmation_required */, source_), |
1180 contents, | 1208 contents, |
1181 start_mode)); | 1209 start_mode)); |
1182 } else { | 1210 } else { |
1183 StartExplicitSync( | 1211 StartSync( |
1184 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1212 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
1185 email_, password_, force_same_tab_navigation, | 1213 email_, password_, force_same_tab_navigation, |
1186 confirmation_required_), | 1214 untrusted_confirmation_required_, source_), |
1187 contents, | 1215 start_mode); |
1188 start_mode, | |
1189 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | |
1190 } | 1216 } |
1191 | 1217 |
1192 if (source_ == SyncPromoUI::SOURCE_SETTINGS && | 1218 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
1193 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1219 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
1194 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1220 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1195 redirect_url_ = continue_url_; | 1221 redirect_url_ = continue_url_; |
1196 ProfileSyncService* sync_service = | 1222 ProfileSyncService* sync_service = |
1197 ProfileSyncServiceFactory::GetForProfile(profile); | 1223 ProfileSyncServiceFactory::GetForProfile(profile); |
1198 if (sync_service) | 1224 if (sync_service) |
1199 sync_service->AddObserver(this); | 1225 sync_service->AddObserver(this); |
1200 } | 1226 } |
1201 | 1227 |
1202 // If this explicit sign in is not from settings page/webstore, show the | 1228 // 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 | 1229 // 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, | 1230 // page, it will get closed by SyncSetupHandler. In the case of webstore, |
1205 // it will redirect back to webstore. | 1231 // it will redirect back to webstore. |
1206 if (source_ != SyncPromoUI::SOURCE_SETTINGS && | 1232 if (source_ != SyncPromoUI::SOURCE_SETTINGS && |
1207 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1233 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1208 signin_tracker_.reset(new SigninTracker(profile, this)); | |
1209 RemoveCurrentHistoryItem(contents); | 1234 RemoveCurrentHistoryItem(contents); |
1210 RedirectToNtpOrAppsPage(false); | 1235 RedirectToNtpOrAppsPage(); |
1211 } | 1236 } |
1212 break; | 1237 break; |
1213 } | 1238 } |
1214 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1239 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
1215 AddEmailToOneClickRejectedList(profile, email_); | 1240 AddEmailToOneClickRejectedList(profile, email_); |
1216 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); | 1241 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
1217 break; | 1242 break; |
1218 default: | 1243 default: |
1219 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1244 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
1220 break; | 1245 break; |
1221 } | 1246 } |
1222 | 1247 |
1223 CleanTransientState(); | 1248 CleanTransientState(); |
1224 } | 1249 } |
1225 | 1250 |
1226 void OneClickSigninHelper::GaiaCredentialsValid() { | |
1227 } | |
1228 | |
1229 void OneClickSigninHelper::OnStateChanged() { | 1251 void OneClickSigninHelper::OnStateChanged() { |
1230 // No redirect url after sync setup is set, thus no need to watch for sync | 1252 // No redirect url after sync setup is set, thus no need to watch for sync |
1231 // state changes. | 1253 // state changes. |
1232 if (redirect_url_.is_empty()) | 1254 if (redirect_url_.is_empty()) |
1233 return; | 1255 return; |
1234 | 1256 |
1235 content::WebContents* contents = web_contents(); | 1257 content::WebContents* contents = web_contents(); |
1236 Profile* profile = | 1258 Profile* profile = |
1237 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1259 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1238 ProfileSyncService* sync_service = | 1260 ProfileSyncService* sync_service = |
1239 ProfileSyncServiceFactory::GetForProfile(profile); | 1261 ProfileSyncServiceFactory::GetForProfile(profile); |
1240 | 1262 |
1241 // Sync setup not completed yet. | 1263 // Sync setup not completed yet. |
1242 if (sync_service->FirstSetupInProgress()) | 1264 if (sync_service->FirstSetupInProgress()) |
1243 return; | 1265 return; |
1244 | 1266 |
1245 if (sync_service->sync_initialized()) { | 1267 if (sync_service->sync_initialized()) { |
1246 contents->GetController().LoadURL(redirect_url_, | 1268 contents->GetController().LoadURL(redirect_url_, |
1247 content::Referrer(), | 1269 content::Referrer(), |
1248 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1270 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1249 std::string()); | 1271 std::string()); |
1250 } | 1272 } |
1251 | 1273 |
1252 // Clear the redirect URL. | 1274 // Clear the redirect URL. |
1253 redirect_url_ = GURL(); | 1275 redirect_url_ = GURL(); |
1254 sync_service->RemoveObserver(this); | 1276 sync_service->RemoveObserver(this); |
1255 } | 1277 } |
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 |