OLD | NEW |
1 // Copyright (c) 2011 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/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" |
11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
| 12 #include "chrome/browser/net/browser_url_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
17 #include "chrome/browser/ui/webui/options/core_options_handler.h" | 18 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" | 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" |
19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 20 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
20 #include "chrome/browser/ui/webui/theme_source.h" | 21 #include "chrome/browser/ui/webui/theme_source.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 }; | 75 }; |
75 | 76 |
76 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) | 77 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) |
77 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { | 78 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { |
78 DictionaryValue localized_strings; | 79 DictionaryValue localized_strings; |
79 CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); | 80 CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); |
80 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); | 81 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); |
81 AddLocalizedStrings(localized_strings); | 82 AddLocalizedStrings(localized_strings); |
82 } | 83 } |
83 | 84 |
84 // Looks for |search_key| in the query portion of |url|. Returns true if the | |
85 // key is found and sets |out_value| to the value for the key. Returns false if | |
86 // the key is not found. | |
87 bool GetValueForKeyInQuery(const GURL& url, const std::string& search_key, | |
88 std::string* out_value) { | |
89 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; | |
90 url_parse::Component key, value; | |
91 while (url_parse::ExtractQueryKeyValue( | |
92 url.spec().c_str(), &query, &key, &value)) { | |
93 if (key.is_nonempty()) { | |
94 std::string key_string = url.spec().substr(key.begin, key.len); | |
95 if (key_string == search_key) { | |
96 if (value.is_nonempty()) | |
97 *out_value = url.spec().substr(value.begin, value.len); | |
98 else | |
99 *out_value = ""; | |
100 return true; | |
101 } | |
102 } | |
103 } | |
104 return false; | |
105 } | |
106 | |
107 } // namespace | 85 } // namespace |
108 | 86 |
109 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 87 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
110 web_ui->HideURL(); | 88 web_ui->HideURL(); |
111 | 89 |
112 SyncPromoHandler* handler = new SyncPromoHandler( | 90 SyncPromoHandler* handler = new SyncPromoHandler( |
113 g_browser_process->profile_manager()); | 91 g_browser_process->profile_manager()); |
114 web_ui->AddMessageHandler(handler); | 92 web_ui->AddMessageHandler(handler); |
115 | 93 |
116 // Set up the chrome://theme/ source. | 94 // Set up the chrome://theme/ source. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 226 } |
249 | 227 |
250 return GURL(stream.str()); | 228 return GURL(stream.str()); |
251 } | 229 } |
252 | 230 |
253 // static | 231 // static |
254 bool SyncPromoUI::GetIsLaunchPageForSyncPromoURL(const GURL& url) { | 232 bool SyncPromoUI::GetIsLaunchPageForSyncPromoURL(const GURL& url) { |
255 std::string value; | 233 std::string value; |
256 // Show the title if the promo is currently the Chrome launch page (and not | 234 // Show the title if the promo is currently the Chrome launch page (and not |
257 // the page accessed through the NTP). | 235 // the page accessed through the NTP). |
258 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyIsLaunchPage, &value)) | 236 if (chrome_browser_net::GetValueForKeyInQuery(url, |
| 237 kSyncPromoQueryKeyIsLaunchPage, &value)) { |
259 return value == "true"; | 238 return value == "true"; |
| 239 } |
260 return false; | 240 return false; |
261 } | 241 } |
262 | 242 |
263 // static | 243 // static |
264 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { | 244 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { |
265 std::string value; | 245 std::string value; |
266 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { | 246 if (chrome_browser_net::GetValueForKeyInQuery(url, |
267 url_canon::RawCanonOutputT<char16> output; | 247 kSyncPromoQueryKeyNextPage, &value)) { |
268 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); | 248 return GURL(value); |
269 std::string url; | |
270 UTF16ToUTF8(output.data(), output.length(), &url); | |
271 return GURL(url); | |
272 } | 249 } |
273 return GURL(); | 250 return GURL(); |
274 } | 251 } |
275 | 252 |
276 // static | 253 // static |
277 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { | 254 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { |
278 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; | 255 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; |
279 } | 256 } |
OLD | NEW |