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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/first_run/first_run.h" | 11 #include "chrome/browser/first_run/first_run.h" |
12 #include "chrome/browser/google/google_util.h" | 12 #include "chrome/browser/google/google_util.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
19 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 19 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
21 #include "chrome/browser/ui/webui/options2/core_options_handler2.h" | 21 #include "chrome/browser/ui/webui/options2/core_options_handler2.h" |
22 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" | 22 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" |
23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
24 #include "chrome/browser/ui/webui/theme_source.h" | 24 #include "chrome/browser/ui/webui/theme_source.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
28 #include "chrome/common/net/url_util.h" | |
29 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
30 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
31 #include "googleurl/src/url_util.h" | 30 #include "googleurl/src/url_util.h" |
32 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
33 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
34 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
36 | 35 |
37 using content::WebContents; | 36 using content::WebContents; |
38 | 37 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 }; | 72 }; |
74 | 73 |
75 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) | 74 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) |
76 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { | 75 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { |
77 DictionaryValue localized_strings; | 76 DictionaryValue localized_strings; |
78 options2::CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); | 77 options2::CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); |
79 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); | 78 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); |
80 AddLocalizedStrings(localized_strings); | 79 AddLocalizedStrings(localized_strings); |
81 } | 80 } |
82 | 81 |
| 82 // Looks for |search_key| in the query portion of |url|. Returns true if the |
| 83 // key is found and sets |out_value| to the value for the key. Returns false if |
| 84 // the key is not found. |
| 85 bool GetValueForKeyInQuery(const GURL& url, const std::string& search_key, |
| 86 std::string* out_value) { |
| 87 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; |
| 88 url_parse::Component key, value; |
| 89 while (url_parse::ExtractQueryKeyValue( |
| 90 url.spec().c_str(), &query, &key, &value)) { |
| 91 if (key.is_nonempty()) { |
| 92 std::string key_string = url.spec().substr(key.begin, key.len); |
| 93 if (key_string == search_key) { |
| 94 if (value.is_nonempty()) |
| 95 *out_value = url.spec().substr(value.begin, value.len); |
| 96 else |
| 97 *out_value = ""; |
| 98 return true; |
| 99 } |
| 100 } |
| 101 } |
| 102 return false; |
| 103 } |
| 104 |
83 } // namespace | 105 } // namespace |
84 | 106 |
85 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 107 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
86 SyncPromoHandler* handler = new SyncPromoHandler( | 108 SyncPromoHandler* handler = new SyncPromoHandler( |
87 g_browser_process->profile_manager()); | 109 g_browser_process->profile_manager()); |
88 web_ui->AddMessageHandler(handler); | 110 web_ui->AddMessageHandler(handler); |
89 | 111 |
90 // Set up the chrome://theme/ source. | 112 // Set up the chrome://theme/ source. |
91 Profile* profile = Profile::FromWebUI(web_ui); | 113 Profile* profile = Profile::FromWebUI(web_ui); |
92 ThemeSource* theme = new ThemeSource(profile); | 114 ThemeSource* theme = new ThemeSource(profile); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 std::string escaped_spec(output.data(), output.length()); | 241 std::string escaped_spec(output.data(), output.length()); |
220 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; | 242 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; |
221 } | 243 } |
222 | 244 |
223 return GURL(stream.str()); | 245 return GURL(stream.str()); |
224 } | 246 } |
225 | 247 |
226 // static | 248 // static |
227 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { | 249 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { |
228 std::string value; | 250 std::string value; |
229 if (chrome_common_net::GetValueForKeyInQuery( | 251 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { |
230 url, kSyncPromoQueryKeyNextPage, &value)) { | 252 url_canon::RawCanonOutputT<char16> output; |
231 return GURL(value); | 253 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); |
| 254 std::string url; |
| 255 UTF16ToUTF8(output.data(), output.length(), &url); |
| 256 return GURL(url); |
232 } | 257 } |
233 return GURL(); | 258 return GURL(); |
234 } | 259 } |
235 | 260 |
236 // static | 261 // static |
237 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { | 262 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { |
238 std::string value; | 263 std::string value; |
239 if (chrome_common_net::GetValueForKeyInQuery( | 264 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeySource, &value)) { |
240 url, kSyncPromoQueryKeySource, &value)) { | |
241 int source = 0; | 265 int source = 0; |
242 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && | 266 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && |
243 source < SOURCE_UNKNOWN) { | 267 source < SOURCE_UNKNOWN) { |
244 return static_cast<Source>(source); | 268 return static_cast<Source>(source); |
245 } | 269 } |
246 } | 270 } |
247 return SOURCE_UNKNOWN; | 271 return SOURCE_UNKNOWN; |
248 } | 272 } |
OLD | NEW |