| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/signin_promo.h" | 5 #include "chrome/browser/signin/signin_promo.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "google_apis/gaia/gaia_urls.h" | 35 #include "google_apis/gaia/gaia_urls.h" |
| 36 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| 37 #include "net/base/network_change_notifier.h" | 37 #include "net/base/network_change_notifier.h" |
| 38 #include "net/base/url_util.h" | 38 #include "net/base/url_util.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 using content::WebContents; | 41 using content::WebContents; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Gaia cannot support about:blank as a continue URL, so using a hosted blank | |
| 46 // page instead. | |
| 47 const char kSignInLandingUrlPrefix[] = | |
| 48 "https://www.google.com/intl/%s/chrome/blank.html"; | |
| 49 | |
| 50 // The maximum number of times we want to show the sign in promo at startup. | 45 // The maximum number of times we want to show the sign in promo at startup. |
| 51 const int kSignInPromoShowAtStartupMaximum = 10; | 46 const int kSignInPromoShowAtStartupMaximum = 10; |
| 52 | 47 |
| 53 // Forces the web based signin flow when set. | 48 // Forces the web based signin flow when set. |
| 54 bool g_force_web_based_signin_flow = false; | 49 bool g_force_web_based_signin_flow = false; |
| 55 | 50 |
| 56 // Checks we want to show the sign in promo for the given brand. | 51 // Checks we want to show the sign in promo for the given brand. |
| 57 bool AllowPromoAtStartupForCurrentBrand() { | 52 bool AllowPromoAtStartupForCurrentBrand() { |
| 58 std::string brand; | 53 std::string brand; |
| 59 google_brand::GetBrand(&brand); | 54 google_brand::GetBrand(&brand); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 prefs::kSignInPromoStartupCount); | 149 prefs::kSignInPromoStartupCount); |
| 155 show_count++; | 150 show_count++; |
| 156 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count); | 151 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count); |
| 157 } | 152 } |
| 158 | 153 |
| 159 void SetUserSkippedPromo(Profile* profile) { | 154 void SetUserSkippedPromo(Profile* profile) { |
| 160 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true); | 155 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true); |
| 161 } | 156 } |
| 162 | 157 |
| 163 GURL GetLandingURL(const char* option, int value) { | 158 GURL GetLandingURL(const char* option, int value) { |
| 164 std::string url; | 159 std::string url = base::StringPrintf("%s/success.html?%s=%d", |
| 165 if (switches::IsEnableWebBasedSignin()) { | 160 extensions::kGaiaAuthExtensionOrigin, |
| 166 const std::string& locale = g_browser_process->GetApplicationLocale(); | 161 option, |
| 167 url = base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str()); | 162 value); |
| 168 } else { | |
| 169 url = base::StringPrintf( | |
| 170 "%s/success.html", extensions::kGaiaAuthExtensionOrigin); | |
| 171 } | |
| 172 base::StringAppendF(&url, "?%s=%d", option, value); | |
| 173 return GURL(url); | 163 return GURL(url); |
| 174 } | 164 } |
| 175 | 165 |
| 176 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { | 166 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { |
| 177 return GetPromoURL(source, auto_close, false /* is_constrained */); | 167 return GetPromoURL(source, auto_close, false /* is_constrained */); |
| 178 } | 168 } |
| 179 | 169 |
| 180 GURL GetPromoURL(signin_metrics::Source source, | 170 GURL GetPromoURL(signin_metrics::Source source, |
| 181 bool auto_close, | 171 bool auto_close, |
| 182 bool is_constrained) { | 172 bool is_constrained) { |
| 183 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); | 173 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); |
| 184 | 174 |
| 185 if (!switches::IsEnableWebBasedSignin()) { | 175 std::string url(chrome::kChromeUIChromeSigninURL); |
| 186 std::string url(chrome::kChromeUIChromeSigninURL); | 176 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); |
| 187 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); | |
| 188 if (auto_close) | |
| 189 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); | |
| 190 if (is_constrained) | |
| 191 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); | |
| 192 return GURL(url); | |
| 193 } | |
| 194 | |
| 195 // Build a Gaia-based URL that can be used to sign the user into chrome. | |
| 196 // There are required request parameters: | |
| 197 // | |
| 198 // - tell Gaia which service the user is signing into. In this case, | |
| 199 // a chrome sign in uses the service "chromiumsync" | |
| 200 // - provide a continue URL. This is the URL that Gaia will redirect to | |
| 201 // once the sign is complete. | |
| 202 // | |
| 203 // The continue URL includes a source parameter that can be extracted using | |
| 204 // the function GetSourceForSignInPromoURL() below. This is used to know | |
| 205 // which of the chrome sign in access points was used to sign the user in. | |
| 206 // It is also parsed for the |auto_close| flag, which indicates that the tab | |
| 207 // must be closed after sync setup is successful. | |
| 208 // See OneClickSigninHelper for details. | |
| 209 std::string query_string = "?service=chromiumsync&sarp=1"; | |
| 210 | |
| 211 std::string continue_url = GetLandingURL(kSignInPromoQueryKeySource, | |
| 212 static_cast<int>(source)).spec(); | |
| 213 if (auto_close) | 177 if (auto_close) |
| 214 base::StringAppendF(&continue_url, "&%s=1", kSignInPromoQueryKeyAutoClose); | 178 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); |
| 215 | 179 if (is_constrained) |
| 216 base::StringAppendF( | 180 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); |
| 217 &query_string, | 181 return GURL(url); |
| 218 "&%s=%s", | |
| 219 kSignInPromoQueryKeyContinue, | |
| 220 net::EscapeQueryParamValue(continue_url, false).c_str()); | |
| 221 | |
| 222 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string); | |
| 223 } | 182 } |
| 224 | 183 |
| 225 GURL GetReauthURL(Profile* profile, const std::string& account_id) { | 184 GURL GetReauthURL(Profile* profile, const std::string& account_id) { |
| 226 AccountTrackerService::AccountInfo info = | 185 AccountTrackerService::AccountInfo info = |
| 227 AccountTrackerServiceFactory::GetForProfile(profile)-> | 186 AccountTrackerServiceFactory::GetForProfile(profile)-> |
| 228 GetAccountInfo(account_id); | 187 GetAccountInfo(account_id); |
| 229 | 188 |
| 230 if (switches::IsEnableWebBasedSignin()) { | |
| 231 return net::AppendQueryParameter( | |
| 232 signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true), | |
| 233 "Email", | |
| 234 account_id); | |
| 235 } | |
| 236 | |
| 237 signin_metrics::Source source = switches::IsNewAvatarMenu() ? | 189 signin_metrics::Source source = switches::IsNewAvatarMenu() ? |
| 238 signin_metrics::SOURCE_REAUTH : signin_metrics::SOURCE_SETTINGS; | 190 signin_metrics::SOURCE_REAUTH : signin_metrics::SOURCE_SETTINGS; |
| 239 | 191 |
| 240 GURL url = signin::GetPromoURL( | 192 GURL url = signin::GetPromoURL( |
| 241 source, true /* auto_close */, | 193 source, true /* auto_close */, |
| 242 switches::IsNewAvatarMenu() /* is_constrained */); | 194 switches::IsNewAvatarMenu() /* is_constrained */); |
| 243 url = net::AppendQueryParameter(url, "email", info.email); | 195 url = net::AppendQueryParameter(url, "email", info.email); |
| 244 url = net::AppendQueryParameter(url, "validateEmail", "1"); | 196 url = net::AppendQueryParameter(url, "validateEmail", "1"); |
| 245 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); | 197 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); |
| 246 } | 198 } |
| 247 | 199 |
| 248 GURL GetNextPageURLForPromoURL(const GURL& url) { | 200 GURL GetNextPageURLForPromoURL(const GURL& url) { |
| 249 std::string value; | 201 std::string value; |
| 250 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { | 202 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { |
| 251 GURL continue_url = GURL(value); | 203 GURL continue_url = GURL(value); |
| 252 if (continue_url.is_valid()) | 204 if (continue_url.is_valid()) |
| 253 return continue_url; | 205 return continue_url; |
| 254 } | 206 } |
| 255 | 207 |
| 256 return GURL(); | 208 return GURL(); |
| 257 } | 209 } |
| 258 | 210 |
| 259 GURL GetSigninPartitionURL() { | 211 GURL GetSigninPartitionURL() { |
| 260 return GURL(switches::IsEnableWebviewBasedSignin() ? | 212 return GURL("chrome-guest://chrome-signin/?"); |
| 261 "chrome-guest://chrome-signin/?" : | |
| 262 chrome::kChromeUIChromeSigninURL); | |
| 263 } | 213 } |
| 264 | 214 |
| 265 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { | 215 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { |
| 266 std::string value; | 216 std::string value; |
| 267 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { | 217 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { |
| 268 int source = 0; | 218 int source = 0; |
| 269 if (base::StringToInt(value, &source) && | 219 if (base::StringToInt(value, &source) && |
| 270 source >= signin_metrics::SOURCE_START_PAGE && | 220 source >= signin_metrics::SOURCE_START_PAGE && |
| 271 source < signin_metrics::SOURCE_UNKNOWN) { | 221 source < signin_metrics::SOURCE_UNKNOWN) { |
| 272 return static_cast<signin_metrics::Source>(source); | 222 return static_cast<signin_metrics::Source>(source); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 std::string value; | 239 std::string value; |
| 290 if (net::GetValueForKeyInQuery( | 240 if (net::GetValueForKeyInQuery( |
| 291 url, kSignInPromoQueryKeyShowAccountManagement, &value)) { | 241 url, kSignInPromoQueryKeyShowAccountManagement, &value)) { |
| 292 int enabled = 0; | 242 int enabled = 0; |
| 293 if (base::StringToInt(value, &enabled) && enabled == 1) | 243 if (base::StringToInt(value, &enabled) && enabled == 1) |
| 294 return true; | 244 return true; |
| 295 } | 245 } |
| 296 return false; | 246 return false; |
| 297 } | 247 } |
| 298 | 248 |
| 299 bool IsContinueUrlForWebBasedSigninFlow(const GURL& url) { | |
| 300 GURL::Replacements replacements; | |
| 301 replacements.ClearQuery(); | |
| 302 const std::string& locale = g_browser_process->GetApplicationLocale(); | |
| 303 GURL continue_url = | |
| 304 GURL(base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str())); | |
| 305 return ( | |
| 306 google_util::IsGoogleDomainUrl( | |
| 307 url, | |
| 308 google_util::ALLOW_SUBDOMAIN, | |
| 309 google_util::DISALLOW_NON_STANDARD_PORTS) && | |
| 310 url.ReplaceComponents(replacements).path() == | |
| 311 continue_url.ReplaceComponents(replacements).path()); | |
| 312 } | |
| 313 | |
| 314 void ForceWebBasedSigninFlowForTesting(bool force) { | 249 void ForceWebBasedSigninFlowForTesting(bool force) { |
| 315 g_force_web_based_signin_flow = force; | 250 g_force_web_based_signin_flow = force; |
| 316 } | 251 } |
| 317 | 252 |
| 318 void RegisterProfilePrefs( | 253 void RegisterProfilePrefs( |
| 319 user_prefs::PrefRegistrySyncable* registry) { | 254 user_prefs::PrefRegistrySyncable* registry) { |
| 320 registry->RegisterIntegerPref( | 255 registry->RegisterIntegerPref( |
| 321 prefs::kSignInPromoStartupCount, | 256 prefs::kSignInPromoStartupCount, |
| 322 0, | 257 0, |
| 323 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 258 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 324 registry->RegisterBooleanPref( | 259 registry->RegisterBooleanPref( |
| 325 prefs::kSignInPromoUserSkipped, | 260 prefs::kSignInPromoUserSkipped, |
| 326 false, | 261 false, |
| 327 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 262 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 328 registry->RegisterBooleanPref( | 263 registry->RegisterBooleanPref( |
| 329 prefs::kSignInPromoShowOnFirstRunAllowed, | 264 prefs::kSignInPromoShowOnFirstRunAllowed, |
| 330 true, | 265 true, |
| 331 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 266 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 332 registry->RegisterBooleanPref( | 267 registry->RegisterBooleanPref( |
| 333 prefs::kSignInPromoShowNTPBubble, | 268 prefs::kSignInPromoShowNTPBubble, |
| 334 false, | 269 false, |
| 335 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 270 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 336 } | 271 } |
| 337 | 272 |
| 338 } // namespace signin | 273 } // namespace signin |
| OLD | NEW |