OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ui.h" | 5 #include "chrome/browser/ui/webui/sync_promo_ui.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const char kStringsJsFile[] = "strings.js"; | 32 const char kStringsJsFile[] = "strings.js"; |
33 const char kSyncPromoJsFile[] = "sync_promo.js"; | 33 const char kSyncPromoJsFile[] = "sync_promo.js"; |
34 | 34 |
35 const char kSyncPromoQueryKeyShowTitle[] = "show_title"; | 35 const char kSyncPromoQueryKeyLaunchPage[] = "launch_page"; |
sail
2011/11/28 16:34:25
same, is launch page?
SteveT
2011/11/28 20:07:32
Done.
| |
36 const char kSyncPromoQueryKeyNextPage[] = "next_page"; | 36 const char kSyncPromoQueryKeyNextPage[] = "next_page"; |
37 | 37 |
38 // The maximum number of times we want to show the sync promo at startup. | 38 // The maximum number of times we want to show the sync promo at startup. |
39 const int kSyncPromoShowAtStartupMaximum = 10; | 39 const int kSyncPromoShowAtStartupMaximum = 10; |
40 | 40 |
41 // Checks we want to show the sync promo for the given brand. | 41 // Checks we want to show the sync promo for the given brand. |
42 bool AllowPromoAtStartupForCurrentBrand() { | 42 bool AllowPromoAtStartupForCurrentBrand() { |
43 std::string brand; | 43 std::string brand; |
44 google_util::GetBrand(&brand); | 44 google_util::GetBrand(&brand); |
45 | 45 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped); | 207 return profile->GetPrefs()->GetBoolean(prefs::kSyncPromoUserSkipped); |
208 } | 208 } |
209 | 209 |
210 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) { | 210 void SyncPromoUI::SetUserSkippedSyncPromo(Profile* profile) { |
211 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true); | 211 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoUserSkipped, true); |
212 } | 212 } |
213 | 213 |
214 // static | 214 // static |
215 GURL SyncPromoUI::GetSyncPromoURL(const GURL& next_page, bool show_title) { | 215 GURL SyncPromoUI::GetSyncPromoURL(const GURL& next_page, bool show_title) { |
216 std::stringstream stream; | 216 std::stringstream stream; |
217 stream << chrome::kChromeUISyncPromoURL << "?" << kSyncPromoQueryKeyShowTitle | 217 stream << chrome::kChromeUISyncPromoURL << "?" << kSyncPromoQueryKeyLaunchPage |
218 << "=" << (show_title ? "true" : "false"); | 218 << "=" << (show_title ? "true" : "false"); |
219 | 219 |
220 if (!next_page.spec().empty()) { | 220 if (!next_page.spec().empty()) { |
221 url_canon::RawCanonOutputT<char> output; | 221 url_canon::RawCanonOutputT<char> output; |
222 url_util::EncodeURIComponent( | 222 url_util::EncodeURIComponent( |
223 next_page.spec().c_str(), next_page.spec().length(), &output); | 223 next_page.spec().c_str(), next_page.spec().length(), &output); |
224 std::string escaped_spec(output.data(), output.length()); | 224 std::string escaped_spec(output.data(), output.length()); |
225 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; | 225 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; |
226 } | 226 } |
227 | 227 |
228 return GURL(stream.str()); | 228 return GURL(stream.str()); |
229 } | 229 } |
230 | 230 |
231 // static | 231 // static |
232 bool SyncPromoUI::GetShowTitleForSyncPromoURL(const GURL& url) { | 232 bool SyncPromoUI::GetLaunchPageForSyncPromoURL(const GURL& url) { |
233 std::string value; | 233 std::string value; |
234 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyShowTitle, &value)) | 234 // Show the title if the promo is currently the Chrome launch page (and not |
235 // the page accessed through the NTP). | |
236 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyLaunchPage, &value)) | |
235 return value == "true"; | 237 return value == "true"; |
236 return false; | 238 return false; |
237 } | 239 } |
238 | 240 |
239 // static | 241 // static |
240 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { | 242 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { |
241 std::string value; | 243 std::string value; |
242 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { | 244 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { |
243 url_canon::RawCanonOutputT<char16> output; | 245 url_canon::RawCanonOutputT<char16> output; |
244 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); | 246 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); |
245 std::string url; | 247 std::string url; |
246 UTF16ToUTF8(output.data(), output.length(), &url); | 248 UTF16ToUTF8(output.data(), output.length(), &url); |
247 return GURL(url); | 249 return GURL(url); |
248 } | 250 } |
249 return GURL(); | 251 return GURL(); |
250 } | 252 } |
251 | 253 |
252 // static | 254 // static |
253 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { | 255 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { |
254 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; | 256 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; |
255 } | 257 } |
OLD | NEW |