Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/webui/sync_promo/sync_promo_ui.cc

Issue 10382077: Update all GAIA URLs to accounts.google.com/... from www.google.com/accounts/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/net/browser_url_util.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_info_cache.h" 16 #include "chrome/browser/profiles/profile_info_cache.h"
16 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/sync/profile_sync_service.h" 18 #include "chrome/browser/sync/profile_sync_service.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
20 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 21 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
21 #include "chrome/browser/ui/webui/options2/core_options_handler2.h" 22 #include "chrome/browser/ui/webui/options2/core_options_handler2.h"
22 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" 23 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 std::string escaped_spec(output.data(), output.length()); 218 std::string escaped_spec(output.data(), output.length());
241 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec; 219 stream << "&" << kSyncPromoQueryKeyNextPage << "=" << escaped_spec;
242 } 220 }
243 221
244 return GURL(stream.str()); 222 return GURL(stream.str());
245 } 223 }
246 224
247 // static 225 // static
248 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) { 226 GURL SyncPromoUI::GetNextPageURLForSyncPromoURL(const GURL& url) {
249 std::string value; 227 std::string value;
250 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeyNextPage, &value)) { 228 if (chrome_browser_net::GetValueForKeyInQuery(
251 url_canon::RawCanonOutputT<char16> output; 229 url, kSyncPromoQueryKeyNextPage, &value)) {
252 url_util::DecodeURLEscapeSequences(value.c_str(), value.length(), &output); 230 return GURL(value);
253 std::string url;
254 UTF16ToUTF8(output.data(), output.length(), &url);
255 return GURL(url);
256 } 231 }
257 return GURL(); 232 return GURL();
258 } 233 }
259 234
260 // static 235 // static
261 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) { 236 SyncPromoUI::Source SyncPromoUI::GetSourceForSyncPromoURL(const GURL& url) {
262 std::string value; 237 std::string value;
263 if (GetValueForKeyInQuery(url, kSyncPromoQueryKeySource, &value)) { 238 if (chrome_browser_net::GetValueForKeyInQuery(
239 url, kSyncPromoQueryKeySource, &value)) {
264 int source = 0; 240 int source = 0;
265 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && 241 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE &&
266 source < SOURCE_UNKNOWN) { 242 source < SOURCE_UNKNOWN) {
267 return static_cast<Source>(source); 243 return static_cast<Source>(source);
268 } 244 }
269 } 245 }
270 return SOURCE_UNKNOWN; 246 return SOURCE_UNKNOWN;
271 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698