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" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
30 #include "googleurl/src/url_util.h" | 31 #include "googleurl/src/url_util.h" |
31 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
33 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 | 36 |
36 using content::WebContents; | 37 using content::WebContents; |
37 | 38 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }; | 73 }; |
73 | 74 |
74 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) | 75 SyncPromoUIHTMLSource::SyncPromoUIHTMLSource(content::WebUI* web_ui) |
75 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { | 76 : ChromeWebUIDataSource(chrome::kChromeUISyncPromoHost) { |
76 DictionaryValue localized_strings; | 77 DictionaryValue localized_strings; |
77 options2::CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); | 78 options2::CoreOptionsHandler::GetStaticLocalizedValues(&localized_strings); |
78 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); | 79 SyncSetupHandler::GetStaticLocalizedValues(&localized_strings, web_ui); |
79 AddLocalizedStrings(localized_strings); | 80 AddLocalizedStrings(localized_strings); |
80 } | 81 } |
81 | 82 |
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 | |
105 } // namespace | 83 } // namespace |
106 | 84 |
107 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 85 SyncPromoUI::SyncPromoUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
108 SyncPromoHandler* handler = new SyncPromoHandler( | 86 SyncPromoHandler* handler = new SyncPromoHandler( |
109 g_browser_process->profile_manager()); | 87 g_browser_process->profile_manager()); |
110 web_ui->AddMessageHandler(handler); | 88 web_ui->AddMessageHandler(handler); |
111 | 89 |
112 // Set up the chrome://theme/ source. | 90 // Set up the chrome://theme/ source. |
113 Profile* profile = Profile::FromWebUI(web_ui); | 91 Profile* profile = Profile::FromWebUI(web_ui); |
114 ThemeSource* theme = new ThemeSource(profile); | 92 ThemeSource* theme = new ThemeSource(profile); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 std::string escaped_spec(output.data(), output.length()); | 219 std::string escaped_spec(output.data(), output.length()); |
242 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; | 220 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; |
243 } | 221 } |
244 | 222 |
245 return GURL(stream.str()); | 223 return GURL(stream.str()); |
246 } | 224 } |
247 | 225 |
248 // static | 226 // static |
249 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { | 227 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { |
250 std::string value; | 228 std::string value; |
251 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { | 229 if (chrome_common_net::GetValueForKeyInQuery( |
252 url_canon::RawCanonOutputT<char16> output; | 230 url, kSyncPromoQueryKeyNextPage, &value)) { |
253 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); | 231 return GURL(value); |
254 std::string url; | |
255 UTF16ToUTF8(output.data(), output.length(), &url); | |
256 return GURL(url); | |
257 } | 232 } |
258 return GURL(); | 233 return GURL(); |
259 } | 234 } |
260 | 235 |
261 // static | 236 // static |
262 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { | 237 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { |
263 std::string value; | 238 std::string value; |
264 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeySource, &value)) { | 239 if (chrome_common_net::GetValueForKeyInQuery( |
| 240 url, kSyncPromoQueryKeySource, &value)) { |
265 int source = 0; | 241 int source = 0; |
266 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && | 242 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && |
267 source < SOURCE_UNKNOWN) { | 243 source < SOURCE_UNKNOWN) { |
268 return static_cast<Source>(source); | 244 return static_cast<Source>(source); |
269 } | 245 } |
270 } | 246 } |
271 return SOURCE_UNKNOWN; | 247 return SOURCE_UNKNOWN; |
272 } | 248 } |
OLD | NEW |