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

Side by Side Diff: chrome/browser/signin/signin_promo.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: Redirect to the continue URL when Sync is disabled Created 6 years, 9 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 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 27 matching lines...) Expand all
38 #include "net/base/network_change_notifier.h" 38 #include "net/base/network_change_notifier.h"
39 #include "net/base/url_util.h" 39 #include "net/base/url_util.h"
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 41
42 using content::WebContents; 42 using content::WebContents;
43 43
44 namespace { 44 namespace {
45 45
46 const char kSignInPromoQueryKeyAutoClose[] = "auto_close"; 46 const char kSignInPromoQueryKeyAutoClose[] = "auto_close";
47 const char kSignInPromoQueryKeyContinue[] = "continue"; 47 const char kSignInPromoQueryKeyContinue[] = "continue";
48 const char kSignInPromoQueryKeyContinueUrl[] = "continueUrl";
guohui 2014/03/24 20:55:58 for better consistency with other param names such
Ilya Sherman 2014/03/26 08:21:39 Done.
48 const char kSignInPromoQueryKeySource[] = "source"; 49 const char kSignInPromoQueryKeySource[] = "source";
49 const char kSignInPromoQueryKeyConstrained[] = "constrained"; 50 const char kSignInPromoQueryKeyConstrained[] = "constrained";
50 51
51 // Gaia cannot support about:blank as a continue URL, so using a hosted blank 52 // Gaia cannot support about:blank as a continue URL, so using a hosted blank
52 // page instead. 53 // page instead.
53 const char kSignInLandingUrlPrefix[] = 54 const char kSignInLandingUrlPrefix[] =
54 "https://www.google.com/intl/%s/chrome/blank.html"; 55 "https://www.google.com/intl/%s/chrome/blank.html";
55 56
56 // The maximum number of times we want to show the sign in promo at startup. 57 // The maximum number of times we want to show the sign in promo at startup.
57 const int kSignInPromoShowAtStartupMaximum = 10; 58 const int kSignInPromoShowAtStartupMaximum = 10;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 std::string url = base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str()); 172 std::string url = base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str());
172 base::StringAppendF(&url, "?%s=%d", option, value); 173 base::StringAppendF(&url, "?%s=%d", option, value);
173 return GURL(url); 174 return GURL(url);
174 } 175 }
175 176
176 GURL GetPromoURL(Source source, bool auto_close) { 177 GURL GetPromoURL(Source source, bool auto_close) {
177 return GetPromoURL(source, auto_close, false /* is_constrained */); 178 return GetPromoURL(source, auto_close, false /* is_constrained */);
178 } 179 }
179 180
180 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained) { 181 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained) {
182 return GetPromoURLWithContinueURL(source, auto_close, is_constrained, GURL());
183 }
184
185 GURL GetPromoURLWithContinueURL(Source source,
186 bool auto_close,
187 bool is_constrained,
188 GURL continue_url) {
181 DCHECK_NE(SOURCE_UNKNOWN, source); 189 DCHECK_NE(SOURCE_UNKNOWN, source);
182 190
183 if (!switches::IsEnableWebBasedSignin()) { 191 if (!switches::IsEnableWebBasedSignin()) {
184 std::string url(chrome::kChromeUIChromeSigninURL); 192 std::string url(chrome::kChromeUIChromeSigninURL);
185 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); 193 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source);
186 if (auto_close) 194 if (auto_close)
187 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); 195 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose);
188 if (is_constrained) 196 if (is_constrained)
189 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); 197 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained);
198 if (!continue_url.is_empty()) {
199 DCHECK(continue_url.is_valid());
200 std::string escaped_continue_url =
201 net::EscapeQueryParamValue(continue_url.spec(), false);
202 base::StringAppendF(&url,
203 "&%s=%s",
204 kSignInPromoQueryKeyContinueUrl,
205 escaped_continue_url.c_str());
206 }
190 return GURL(url); 207 return GURL(url);
191 } 208 }
192 209
193 // Build a Gaia-based URL that can be used to sign the user into chrome. 210 // Build a Gaia-based URL that can be used to sign the user into chrome.
194 // There are required request parameters: 211 // There are required request parameters:
195 // 212 //
196 // - tell Gaia which service the user is signing into. In this case, 213 // - tell Gaia which service the user is signing into. In this case,
197 // a chrome sign in uses the service "chromiumsync" 214 // a chrome sign in uses the service "chromiumsync"
198 // - provide a continue URL. This is the URL that Gaia will redirect to 215 // - provide a continue URL. This is the URL that Gaia will redirect to
199 // once the sign is complete. 216 // once the sign is complete.
200 // 217 //
201 // The continue URL includes a source parameter that can be extracted using 218 // The continue URL includes a source parameter that can be extracted using
202 // the function GetSourceForSignInPromoURL() below. This is used to know 219 // the function GetSourceForSignInPromoURL() below. This is used to know
203 // which of the chrome sign in access points was used to sign the user in. 220 // which of the chrome sign in access points was used to sign the user in.
204 // It is also parsed for the |auto_close| flag, which indicates that the tab 221 // It is also parsed for the |auto_close| flag, which indicates that the tab
205 // must be closed after sync setup is successful. 222 // must be closed after sync setup is successful.
206 // See OneClickSigninHelper for details. 223 // See OneClickSigninHelper for details.
207 std::string query_string = "?service=chromiumsync&sarp=1"; 224 std::string query_string = "?service=chromiumsync&sarp=1";
208 225
209 std::string continue_url = GetLandingURL(kSignInPromoQueryKeySource, 226 DCHECK(continue_url.is_empty());
210 static_cast<int>(source)).spec(); 227 std::string continue_url_str = GetLandingURL(kSignInPromoQueryKeySource,
211 if (auto_close) 228 static_cast<int>(source)).spec();
212 base::StringAppendF(&continue_url, "&%s=1", kSignInPromoQueryKeyAutoClose); 229 if (auto_close) {
230 base::StringAppendF(
231 &continue_url_str, "&%s=1", kSignInPromoQueryKeyAutoClose);
232 }
213 233
214 base::StringAppendF(&query_string, "&%s=%s", kSignInPromoQueryKeyContinue, 234 base::StringAppendF(
215 net::EscapeQueryParamValue( 235 &query_string,
216 continue_url, false).c_str()); 236 "&%s=%s",
237 kSignInPromoQueryKeyContinue,
238 net::EscapeQueryParamValue(continue_url_str, false).c_str());
217 239
218 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string); 240 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string);
219 } 241 }
220 242
221 GURL GetReauthURL(Profile* profile, const std::string& account_id) { 243 GURL GetReauthURL(Profile* profile, const std::string& account_id) {
222 if (switches::IsEnableWebBasedSignin()) { 244 if (switches::IsEnableWebBasedSignin()) {
223 return net::AppendQueryParameter( 245 return net::AppendQueryParameter(
224 signin::GetPromoURL(signin::SOURCE_SETTINGS, true), 246 signin::GetPromoURL(signin::SOURCE_SETTINGS, true),
225 "Email", 247 "Email",
226 account_id); 248 account_id);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 prefs::kSignInPromoShowOnFirstRunAllowed, 323 prefs::kSignInPromoShowOnFirstRunAllowed,
302 true, 324 true,
303 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 325 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
304 registry->RegisterBooleanPref( 326 registry->RegisterBooleanPref(
305 prefs::kSignInPromoShowNTPBubble, 327 prefs::kSignInPromoShowNTPBubble,
306 false, 328 false,
307 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 329 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
308 } 330 }
309 331
310 } // namespace signin 332 } // namespace signin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698