Chromium Code Reviews| 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/webui/sync_promo/sync_promo_ui.h" | 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const char kStringsJsFile[] = "strings.js"; | 45 const char kStringsJsFile[] = "strings.js"; |
| 46 const char kSyncPromoJsFile[] = "sync_promo.js"; | 46 const char kSyncPromoJsFile[] = "sync_promo.js"; |
| 47 | 47 |
| 48 const char kSyncPromoQueryKeyAutoClose[] = "auto_close"; | 48 const char kSyncPromoQueryKeyAutoClose[] = "auto_close"; |
| 49 const char kSyncPromoQueryKeyContinue[] = "continue"; | 49 const char kSyncPromoQueryKeyContinue[] = "continue"; |
| 50 const char kSyncPromoQueryKeyNextPage[] = "next_page"; | 50 const char kSyncPromoQueryKeyNextPage[] = "next_page"; |
| 51 const char kSyncPromoQueryKeySource[] = "source"; | 51 const char kSyncPromoQueryKeySource[] = "source"; |
| 52 | 52 |
| 53 // TODO(rogerta): It would be better to use about:blank, but until that is | 53 // Gaia cannot support about:blank as a continue URL, so using a hosted blank |
| 54 // supported by Gaia this blank continue URL will be used. | 54 // page instead. |
| 55 const char kContinueUrl[] = "http://www.google.com/gen_204"; | 55 const char kContinueUrl[] = |
| 56 "https://www.google.com/intl/%s/chrome/blank.html?%s=%d"; | |
| 56 | 57 |
| 57 // The maximum number of times we want to show the sync promo at startup. | 58 // The maximum number of times we want to show the sync promo at startup. |
| 58 const int kSyncPromoShowAtStartupMaximum = 10; | 59 const int kSyncPromoShowAtStartupMaximum = 10; |
| 59 | 60 |
| 60 // Checks we want to show the sync promo for the given brand. | 61 // Checks we want to show the sync promo for the given brand. |
| 61 bool AllowPromoAtStartupForCurrentBrand() { | 62 bool AllowPromoAtStartupForCurrentBrand() { |
| 62 std::string brand; | 63 std::string brand; |
| 63 google_util::GetBrand(&brand); | 64 google_util::GetBrand(&brand); |
| 64 | 65 |
| 65 if (brand.empty()) | 66 if (brand.empty()) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // - tell Gaia which service the user is signing into. In this case, | 234 // - tell Gaia which service the user is signing into. In this case, |
| 234 // a chrome sign in uses the service "chromiumsync" | 235 // a chrome sign in uses the service "chromiumsync" |
| 235 // - provide a continue URL. This is the URL that Gaia will redirect to | 236 // - provide a continue URL. This is the URL that Gaia will redirect to |
| 236 // once the sign is complete. | 237 // once the sign is complete. |
| 237 // | 238 // |
| 238 // The continue URL includes a source parameter that can be extracted using | 239 // The continue URL includes a source parameter that can be extracted using |
| 239 // the function GetSourceForSyncPromoURL() below. This is used to know | 240 // the function GetSourceForSyncPromoURL() below. This is used to know |
| 240 // which of the chrome sign in access points was used to sign the userr in. | 241 // which of the chrome sign in access points was used to sign the userr in. |
| 241 // See OneClickSigninHelper for details. | 242 // See OneClickSigninHelper for details. |
| 242 url_string = GaiaUrls::GetInstance()->service_login_url(); | 243 url_string = GaiaUrls::GetInstance()->service_login_url(); |
| 243 url_string.append("?service=chromiumsync"); | 244 url_string.append("?service=chromiumsync&sarp=1&rm=hide&fpc=1"); |
|
James Hawkins
2012/12/18 22:26:07
nit: Document these params for the sake of posteri
| |
| 244 | 245 |
| 245 std::string continue_url = base::StringPrintf("%s?%s=%d", | 246 const std::string& locale = g_browser_process->GetApplicationLocale(); |
| 246 kContinueUrl, kSyncPromoQueryKeySource, static_cast<int>(source)); | 247 std::string continue_url = base::StringPrintf(kContinueUrl, locale.c_str(), |
| 248 kSyncPromoQueryKeySource, static_cast<int>(source)); | |
| 247 | 249 |
| 248 base::StringAppendF(&url_string, "&%s=%s", kSyncPromoQueryKeyContinue, | 250 base::StringAppendF(&url_string, "&%s=%s", kSyncPromoQueryKeyContinue, |
| 249 net::EscapeQueryParamValue( | 251 net::EscapeQueryParamValue( |
| 250 continue_url, false).c_str()); | 252 continue_url, false).c_str()); |
| 251 } else { | 253 } else { |
| 252 url_string = base::StringPrintf("%s?%s=%d", chrome::kChromeUISyncPromoURL, | 254 url_string = base::StringPrintf("%s?%s=%d", chrome::kChromeUISyncPromoURL, |
| 253 kSyncPromoQueryKeySource, | 255 kSyncPromoQueryKeySource, |
| 254 static_cast<int>(source)); | 256 static_cast<int>(source)); |
| 255 | 257 |
| 256 if (auto_close) | 258 if (auto_close) |
| 257 base::StringAppendF(&url_string, "&%s=1", kSyncPromoQueryKeyAutoClose); | 259 base::StringAppendF(&url_string, "&%s=1", kSyncPromoQueryKeyAutoClose); |
| 258 | 260 |
| 259 if (!next_page.spec().empty()) { | 261 if (!next_page.spec().empty()) { |
| 260 base::StringAppendF(&url_string, "&%s=%s", kSyncPromoQueryKeyNextPage, | 262 base::StringAppendF(&url_string, "&%s=%s", kSyncPromoQueryKeyNextPage, |
| 261 net::EscapeQueryParamValue(next_page.spec(), | 263 net::EscapeQueryParamValue(next_page.spec(), |
| 262 false).c_str()); | 264 false).c_str()); |
| 263 } | 265 } |
| 264 } | 266 } |
| 265 | 267 |
| 266 return GURL(url_string); | 268 return GURL(url_string); |
| 267 } | 269 } |
| 268 | 270 |
| 269 // static | 271 // static |
| 270 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { | 272 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { |
| 273 const char* key_name = UseWebBasedSigninFlow() ? kSyncPromoQueryKeyContinue : | |
| 274 kSyncPromoQueryKeyNextPage; | |
| 271 std::string value; | 275 std::string value; |
| 272 if (chrome_common_net::GetValueForKeyInQuery( | 276 if (chrome_common_net::GetValueForKeyInQuery(url, key_name, &value)) { |
| 273 url, kSyncPromoQueryKeyNextPage, &value)) { | |
| 274 return GURL(value); | 277 return GURL(value); |
| 275 } | 278 } |
| 276 return GURL(); | 279 return GURL(); |
| 277 } | 280 } |
| 278 | 281 |
| 279 // static | 282 // static |
| 280 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { | 283 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { |
| 281 std::string value; | 284 std::string value; |
| 282 if (chrome_common_net::GetValueForKeyInQuery( | 285 if (chrome_common_net::GetValueForKeyInQuery( |
| 283 url, kSyncPromoQueryKeySource, &value)) { | 286 url, kSyncPromoQueryKeySource, &value)) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 304 | 307 |
| 305 // static | 308 // static |
| 306 bool SyncPromoUI::UseWebBasedSigninFlow() { | 309 bool SyncPromoUI::UseWebBasedSigninFlow() { |
| 307 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 310 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 308 return CommandLine::ForCurrentProcess()->HasSwitch( | 311 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 309 switches::kUseWebBasedSigninFlow); | 312 switches::kUseWebBasedSigninFlow); |
| 310 #else | 313 #else |
| 311 return false; | 314 return false; |
| 312 #endif | 315 #endif |
| 313 } | 316 } |
| OLD | NEW |