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

Side by Side Diff: chrome/browser/ui/webui/about_ui.cc

Issue 14990003: CrOS online EULA: support localization, change timeout (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nits, added Hebrew mapping Created 7 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
« no previous file with comments | « chrome/app/chromeos_strings.grdp ('k') | chrome/common/url_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/about_ui.h" 5 #include "chrome/browser/ui/webui/about_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 using content::WebContents; 96 using content::WebContents;
97 97
98 namespace { 98 namespace {
99 99
100 const char kCreditsJsPath[] = "credits.js"; 100 const char kCreditsJsPath[] = "credits.js";
101 const char kMemoryJsPath[] = "memory.js"; 101 const char kMemoryJsPath[] = "memory.js";
102 const char kMemoryCssPath[] = "about_memory.css"; 102 const char kMemoryCssPath[] = "about_memory.css";
103 const char kStatsJsPath[] = "stats.js"; 103 const char kStatsJsPath[] = "stats.js";
104 const char kStringsJsPath[] = "strings.js"; 104 const char kStringsJsPath[] = "strings.js";
105 // chrome://terms falls back to offline page after kOnlineTermsTimeoutSec. 105 // chrome://terms falls back to offline page after kOnlineTermsTimeoutSec.
106 const int kOnlineTermsTimeoutSec = 10; 106 const int kOnlineTermsTimeoutSec = 7;
107 107
108 // When you type about:memory, it actually loads this intermediate URL that 108 // When you type about:memory, it actually loads this intermediate URL that
109 // redirects you to the final page. This avoids the problem where typing 109 // redirects you to the final page. This avoids the problem where typing
110 // "about:memory" on the new tab page or any other page where a process 110 // "about:memory" on the new tab page or any other page where a process
111 // transition would occur to the about URL will cause some confusion. 111 // transition would occur to the about URL will cause some confusion.
112 // 112 //
113 // The problem is that during the processing of the memory page, there are two 113 // The problem is that during the processing of the memory page, there are two
114 // processes active, the original and the destination one. This can create the 114 // processes active, the original and the destination one. This can create the
115 // impression that we're using more resources than we actually are. This 115 // impression that we're using more resources than we actually are. This
116 // redirect solves the problem by eliminating the process transition during the 116 // redirect solves the problem by eliminating the process transition during the
(...skipping 21 matching lines...) Expand all
138 void BindProcessMetrics(DictionaryValue* data, 138 void BindProcessMetrics(DictionaryValue* data,
139 ProcessMemoryInformation* info); 139 ProcessMemoryInformation* info);
140 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); 140 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info);
141 141
142 content::URLDataSource::GotDataCallback callback_; 142 content::URLDataSource::GotDataCallback callback_;
143 143
144 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); 144 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler);
145 }; 145 };
146 146
147 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
148
149 // Contains pairs of corresponding locales for Chrome and Google URLs.
150 struct Chrome2GoogleLocaleMapping {
151 const char* chrome_locale;
152 const char* google_locale;
153 };
154
155 // List of locales constant which are different for Google URL
156 const Chrome2GoogleLocaleMapping locale_mapping[] = {
Evan Stade 2013/05/06 18:06:05 When I launch (desktop) Chrome in a foreign locale
Nikita (slow) 2013/05/06 18:10:15 Evan, per my understanding it seems to be that thi
157 {"de-AT", "de"},
158 {"de-CH", "de"},
159 {"de-DE", "de"},
160 {"en-GB", "en_uk"},
161 {"fr-CA", "fr"},
162 {"fr-CH", "fr"},
163 {"fr-FR", "fr"},
164 {"he", "iw"},
165 {"it-CH", "it"},
166 {"it-IT", "it"}
167 };
168
169 // Returns server side locale if it's different from the Chrome one.
170 // Otherwise, returns NULL.
171 const char* TranslateChromeLangToGoogle(const char* chrome_locale) {
172 for (std::size_t i = 0; i < arraysize(locale_mapping); ++i) {
173 if (LowerCaseEqualsASCII(chrome_locale,
174 locale_mapping[i].chrome_locale)) {
175 return locale_mapping[i].google_locale;
176 }
177 }
178 return NULL;
179 }
180
148 // Helper class that fetches the online Chrome OS terms. Empty string is 181 // Helper class that fetches the online Chrome OS terms. Empty string is
149 // returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|. 182 // returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|.
150 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate { 183 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate {
151 public: 184 public:
152 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback; 185 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback;
153 186
154 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback) 187 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback,
188 const std::string& locale)
155 : fetch_callback_(callback) { 189 : fetch_callback_(callback) {
156 eula_fetcher_.reset(net::URLFetcher::Create( 190 const char* google_lang = TranslateChromeLangToGoogle(locale.c_str());
157 GURL(l10n_util::GetStringUTF16(IDS_EULA_POLICY_URL)), 191 if (!google_lang)
158 net::URLFetcher::GET, 192 google_lang = locale.c_str();
159 this)); 193 std::string eula_URL = base::StringPrintf(chrome::kOnlineEulaURLPath,
194 google_lang);
195 eula_fetcher_.reset(net::URLFetcher::Create(GURL(eula_URL),
196 net::URLFetcher::GET,
197 this));
160 eula_fetcher_->SetRequestContext( 198 eula_fetcher_->SetRequestContext(
161 g_browser_process->system_request_context()); 199 g_browser_process->system_request_context());
162 eula_fetcher_->AddExtraRequestHeader("Accept: text/html"); 200 eula_fetcher_->AddExtraRequestHeader("Accept: text/html");
163 eula_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 201 eula_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
164 net::LOAD_DO_NOT_SAVE_COOKIES | 202 net::LOAD_DO_NOT_SAVE_COOKIES |
165 net::LOAD_DISABLE_CACHE); 203 net::LOAD_DISABLE_CACHE);
166 eula_fetcher_->Start(); 204 eula_fetcher_->Start();
167 // Abort the download attempt if it takes longer than one minute. 205 // Abort the download attempt if it takes longer than one minute.
168 download_timer_.Start(FROM_HERE, 206 download_timer_.Start(FROM_HERE,
169 base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec), 207 base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } else if (CommandLine::ForCurrentProcess()->HasSwitch( 288 } else if (CommandLine::ForCurrentProcess()->HasSwitch(
251 chromeos::switches::kDisableOnlineEULA)) { 289 chromeos::switches::kDisableOnlineEULA)) {
252 // Fallback to the local file. 290 // Fallback to the local file.
253 BrowserThread::PostTask( 291 BrowserThread::PostTask(
254 BrowserThread::FILE, FROM_HERE, 292 BrowserThread::FILE, FROM_HERE,
255 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this)); 293 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this));
256 } else { 294 } else {
257 // Try to load online version of ChromeOS terms first. 295 // Try to load online version of ChromeOS terms first.
258 // ChromeOSOnlineTermsHandler object destroys itself. 296 // ChromeOSOnlineTermsHandler object destroys itself.
259 new ChromeOSOnlineTermsHandler( 297 new ChromeOSOnlineTermsHandler(
260 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this)); 298 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this),
299 locale_);
261 } 300 }
262 } 301 }
263 302
264 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) { 303 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
266 loader->GetResponseResult(&contents_); 305 loader->GetResponseResult(&contents_);
267 if (contents_.empty()) { 306 if (contents_.empty()) {
268 // Load local ChromeOS terms from the file. 307 // Load local ChromeOS terms from the file.
269 BrowserThread::PostTask( 308 BrowserThread::PostTask(
270 BrowserThread::FILE, FROM_HERE, 309 BrowserThread::FILE, FROM_HERE,
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 Profile* profile = Profile::FromWebUI(web_ui); 1223 Profile* profile = Profile::FromWebUI(web_ui);
1185 1224
1186 #if defined(ENABLE_THEMES) 1225 #if defined(ENABLE_THEMES)
1187 // Set up the chrome://theme/ source. 1226 // Set up the chrome://theme/ source.
1188 ThemeSource* theme = new ThemeSource(profile); 1227 ThemeSource* theme = new ThemeSource(profile);
1189 content::URLDataSource::Add(profile, theme); 1228 content::URLDataSource::Add(profile, theme);
1190 #endif 1229 #endif
1191 1230
1192 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); 1231 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile));
1193 } 1232 }
OLDNEW
« no previous file with comments | « chrome/app/chromeos_strings.grdp ('k') | chrome/common/url_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698