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

Side by Side Diff: chrome/browser/signin/signin_promo.cc

Issue 579033002: [Clean-up] Remove some dead code for handling Webstore sign-in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore incorrectly deleted code Created 6 years, 3 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
« no previous file with comments | « chrome/browser/signin/signin_promo.h ('k') | chrome/browser/signin/signin_promo_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19 matching lines...) Expand all
30 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h" 31 #include "content/public/browser/web_ui.h"
32 #include "content/public/browser/web_ui_data_source.h" 32 #include "content/public/browser/web_ui_data_source.h"
33 #include "google_apis/gaia/gaia_urls.h" 33 #include "google_apis/gaia/gaia_urls.h"
34 #include "net/base/escape.h" 34 #include "net/base/escape.h"
35 #include "net/base/network_change_notifier.h" 35 #include "net/base/network_change_notifier.h"
36 #include "net/base/url_util.h" 36 #include "net/base/url_util.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 38
39 using content::WebContents; 39 using content::WebContents;
40 using net::GetValueForKeyInQuery;
41 40
42 namespace { 41 namespace {
43 42
44 // Gaia cannot support about:blank as a continue URL, so using a hosted blank 43 // Gaia cannot support about:blank as a continue URL, so using a hosted blank
45 // page instead. 44 // page instead.
46 const char kSignInLandingUrlPrefix[] = 45 const char kSignInLandingUrlPrefix[] =
47 "https://www.google.com/intl/%s/chrome/blank.html"; 46 "https://www.google.com/intl/%s/chrome/blank.html";
48 47
49 // The maximum number of times we want to show the sign in promo at startup. 48 // The maximum number of times we want to show the sign in promo at startup.
50 const int kSignInPromoShowAtStartupMaximum = 10; 49 const int kSignInPromoShowAtStartupMaximum = 10;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 169 }
171 base::StringAppendF(&url, "?%s=%d", option, value); 170 base::StringAppendF(&url, "?%s=%d", option, value);
172 return GURL(url); 171 return GURL(url);
173 } 172 }
174 173
175 GURL GetPromoURL(Source source, bool auto_close) { 174 GURL GetPromoURL(Source source, bool auto_close) {
176 return GetPromoURL(source, auto_close, false /* is_constrained */); 175 return GetPromoURL(source, auto_close, false /* is_constrained */);
177 } 176 }
178 177
179 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained) { 178 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained) {
180 return GetPromoURLWithContinueURL(source, auto_close, is_constrained, GURL());
181 }
182
183 GURL GetPromoURLWithContinueURL(Source source,
184 bool auto_close,
185 bool is_constrained,
186 GURL continue_url) {
187 DCHECK_NE(SOURCE_UNKNOWN, source); 179 DCHECK_NE(SOURCE_UNKNOWN, source);
188 180
189 if (!switches::IsEnableWebBasedSignin()) { 181 if (!switches::IsEnableWebBasedSignin()) {
190 std::string url(chrome::kChromeUIChromeSigninURL); 182 std::string url(chrome::kChromeUIChromeSigninURL);
191 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); 183 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source);
192 if (auto_close) 184 if (auto_close)
193 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); 185 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose);
194 if (is_constrained) 186 if (is_constrained)
195 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); 187 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained);
196 if (!continue_url.is_empty()) {
197 DCHECK(continue_url.is_valid());
198 std::string escaped_continue_url =
199 net::EscapeQueryParamValue(continue_url.spec(), false);
200 base::StringAppendF(&url,
201 "&%s=%s",
202 kSignInPromoQueryKeyContinue,
203 escaped_continue_url.c_str());
204 }
205 return GURL(url); 188 return GURL(url);
206 } 189 }
207 190
208 // Build a Gaia-based URL that can be used to sign the user into chrome. 191 // Build a Gaia-based URL that can be used to sign the user into chrome.
209 // There are required request parameters: 192 // There are required request parameters:
210 // 193 //
211 // - tell Gaia which service the user is signing into. In this case, 194 // - tell Gaia which service the user is signing into. In this case,
212 // a chrome sign in uses the service "chromiumsync" 195 // a chrome sign in uses the service "chromiumsync"
213 // - provide a continue URL. This is the URL that Gaia will redirect to 196 // - provide a continue URL. This is the URL that Gaia will redirect to
214 // once the sign is complete. 197 // once the sign is complete.
215 // 198 //
216 // The continue URL includes a source parameter that can be extracted using 199 // The continue URL includes a source parameter that can be extracted using
217 // the function GetSourceForSignInPromoURL() below. This is used to know 200 // the function GetSourceForSignInPromoURL() below. This is used to know
218 // which of the chrome sign in access points was used to sign the user in. 201 // which of the chrome sign in access points was used to sign the user in.
219 // It is also parsed for the |auto_close| flag, which indicates that the tab 202 // It is also parsed for the |auto_close| flag, which indicates that the tab
220 // must be closed after sync setup is successful. 203 // must be closed after sync setup is successful.
221 // See OneClickSigninHelper for details. 204 // See OneClickSigninHelper for details.
222 std::string query_string = "?service=chromiumsync&sarp=1"; 205 std::string query_string = "?service=chromiumsync&sarp=1";
223 206
224 DCHECK(continue_url.is_empty()); 207 std::string continue_url = GetLandingURL(kSignInPromoQueryKeySource,
225 std::string continue_url_str = GetLandingURL(kSignInPromoQueryKeySource, 208 static_cast<int>(source)).spec();
226 static_cast<int>(source)).spec(); 209 if (auto_close)
227 if (auto_close) { 210 base::StringAppendF(&continue_url, "&%s=1", kSignInPromoQueryKeyAutoClose);
228 base::StringAppendF(
229 &continue_url_str, "&%s=1", kSignInPromoQueryKeyAutoClose);
230 }
231 211
232 base::StringAppendF( 212 base::StringAppendF(
233 &query_string, 213 &query_string,
234 "&%s=%s", 214 "&%s=%s",
235 kSignInPromoQueryKeyContinue, 215 kSignInPromoQueryKeyContinue,
236 net::EscapeQueryParamValue(continue_url_str, false).c_str()); 216 net::EscapeQueryParamValue(continue_url, false).c_str());
237 217
238 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string); 218 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string);
239 } 219 }
240 220
241 GURL GetReauthURL(Profile* profile, const std::string& account_id) { 221 GURL GetReauthURL(Profile* profile, const std::string& account_id) {
242 if (switches::IsEnableWebBasedSignin()) { 222 if (switches::IsEnableWebBasedSignin()) {
243 return net::AppendQueryParameter( 223 return net::AppendQueryParameter(
244 signin::GetPromoURL(signin::SOURCE_SETTINGS, true), 224 signin::GetPromoURL(signin::SOURCE_SETTINGS, true),
245 "Email", 225 "Email",
246 account_id); 226 account_id);
247 } 227 }
248 228
249 signin::Source source = switches::IsNewAvatarMenu() ? 229 signin::Source source = switches::IsNewAvatarMenu() ?
250 signin::SOURCE_REAUTH : signin::SOURCE_SETTINGS; 230 signin::SOURCE_REAUTH : signin::SOURCE_SETTINGS;
251 231
252 GURL url = signin::GetPromoURL( 232 GURL url = signin::GetPromoURL(
253 source, true /* auto_close */, 233 source, true /* auto_close */,
254 switches::IsNewAvatarMenu() /* is_constrained */); 234 switches::IsNewAvatarMenu() /* is_constrained */);
255 url = net::AppendQueryParameter(url, "email", account_id); 235 url = net::AppendQueryParameter(url, "email", account_id);
256 url = net::AppendQueryParameter(url, "validateEmail", "1"); 236 url = net::AppendQueryParameter(url, "validateEmail", "1");
257 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); 237 return net::AppendQueryParameter(url, "readOnlyEmail", "1");
258 } 238 }
259 239
260 GURL GetNextPageURLForPromoURL(const GURL& url) { 240 GURL GetNextPageURLForPromoURL(const GURL& url) {
261 std::string value; 241 std::string value;
262 if (GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { 242 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) {
263 GURL continue_url = GURL(value); 243 GURL continue_url = GURL(value);
264 if (continue_url.is_valid()) 244 if (continue_url.is_valid())
265 return continue_url; 245 return continue_url;
266 } 246 }
267 247
268 return GURL(); 248 return GURL();
269 } 249 }
270 250
271 Source GetSourceForPromoURL(const GURL& url) { 251 Source GetSourceForPromoURL(const GURL& url) {
272 std::string value; 252 std::string value;
273 if (GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { 253 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) {
274 int source = 0; 254 int source = 0;
275 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && 255 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE &&
276 source < SOURCE_UNKNOWN) { 256 source < SOURCE_UNKNOWN) {
277 return static_cast<Source>(source); 257 return static_cast<Source>(source);
278 } 258 }
279 } 259 }
280 return SOURCE_UNKNOWN; 260 return SOURCE_UNKNOWN;
281 } 261 }
282 262
283 bool IsAutoCloseEnabledInURL(const GURL& url) { 263 bool IsAutoCloseEnabledInURL(const GURL& url) {
284 std::string value; 264 std::string value;
285 if (GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { 265 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) {
286 int enabled = 0; 266 int enabled = 0;
287 if (base::StringToInt(value, &enabled) && enabled == 1) 267 if (base::StringToInt(value, &enabled) && enabled == 1)
288 return true; 268 return true;
289 } 269 }
290 return false; 270 return false;
291 } 271 }
292 272
293 bool ShouldShowAccountManagement(const GURL& url) { 273 bool ShouldShowAccountManagement(const GURL& url) {
294 std::string value; 274 std::string value;
295 if (GetValueForKeyInQuery( 275 if (net::GetValueForKeyInQuery(
296 url, kSignInPromoQueryKeyShowAccountManagement, &value)) { 276 url, kSignInPromoQueryKeyShowAccountManagement, &value)) {
297 int enabled = 0; 277 int enabled = 0;
298 if (base::StringToInt(value, &enabled) && enabled == 1) 278 if (base::StringToInt(value, &enabled) && enabled == 1)
299 return true; 279 return true;
300 } 280 }
301 return false; 281 return false;
302 } 282 }
303 283
304 bool IsContinueUrlForWebBasedSigninFlow(const GURL& url) { 284 bool IsContinueUrlForWebBasedSigninFlow(const GURL& url) {
305 GURL::Replacements replacements; 285 GURL::Replacements replacements;
(...skipping 28 matching lines...) Expand all
334 prefs::kSignInPromoShowOnFirstRunAllowed, 314 prefs::kSignInPromoShowOnFirstRunAllowed,
335 true, 315 true,
336 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 316 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
337 registry->RegisterBooleanPref( 317 registry->RegisterBooleanPref(
338 prefs::kSignInPromoShowNTPBubble, 318 prefs::kSignInPromoShowNTPBubble,
339 false, 319 false,
340 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 320 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
341 } 321 }
342 322
343 } // namespace signin 323 } // namespace signin
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_promo.h ('k') | chrome/browser/signin/signin_promo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698