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/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 Loading... | |
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 Loading... | |
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 languages for Chrome and Google URLs. | |
150 struct Chrome2GoogleLanguageMapping { | |
Nikita (slow)
2013/05/06 14:22:25
nit: Please rename language to locale to match ter
vasilii
2013/05/06 15:36:33
Done.
| |
151 const char* chrome_language; | |
152 const char* google_language; | |
153 }; | |
154 | |
155 // List of languages constant which are different for Google URL | |
156 const Chrome2GoogleLanguageMapping language_mapping[] = { | |
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 {"it-CH", "it"}, | |
165 {"it-IT", "it"} | |
166 }; | |
167 | |
168 // Returns language in Google format if it's different from the Chrome one. | |
Nikita (slow)
2013/05/06 14:22:25
nit: Change "Google format" to something like "ser
vasilii
2013/05/06 15:36:33
Done.
| |
169 // Otherwise, returns NULL. | |
170 const char* TranslateChromeLangToGoogle(const char* chrome_language) { | |
171 for (std::size_t i = 0; i < arraysize(language_mapping); ++i) { | |
172 if (LowerCaseEqualsASCII(chrome_language, | |
173 language_mapping[i].chrome_language)) | |
174 return language_mapping[i].google_language; | |
Nikita (slow)
2013/05/06 14:22:25
nit: Add {}
vasilii
2013/05/06 15:36:33
Done.
| |
175 } | |
176 return NULL; | |
177 } | |
178 | |
148 // Helper class that fetches the online Chrome OS terms. Empty string is | 179 // Helper class that fetches the online Chrome OS terms. Empty string is |
149 // returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|. | 180 // returned once fetching failed or exceeded |kOnlineTermsTimeoutSec|. |
150 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate { | 181 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate { |
151 public: | 182 public: |
152 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback; | 183 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback; |
153 | 184 |
154 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback) | 185 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback, |
186 const std::string& locale) | |
155 : fetch_callback_(callback) { | 187 : fetch_callback_(callback) { |
156 eula_fetcher_.reset(net::URLFetcher::Create( | 188 const char* google_lang = TranslateChromeLangToGoogle(locale.c_str()); |
157 GURL(l10n_util::GetStringUTF16(IDS_EULA_POLICY_URL)), | 189 if (!google_lang) |
158 net::URLFetcher::GET, | 190 google_lang = locale.c_str(); |
159 this)); | 191 std::string eula_URL = base::StringPrintf(chrome::kOnlineEulaURLPath, |
192 google_lang); | |
193 eula_fetcher_.reset(net::URLFetcher::Create(GURL(eula_URL), | |
194 net::URLFetcher::GET, | |
195 this)); | |
160 eula_fetcher_->SetRequestContext( | 196 eula_fetcher_->SetRequestContext( |
161 g_browser_process->system_request_context()); | 197 g_browser_process->system_request_context()); |
162 eula_fetcher_->AddExtraRequestHeader("Accept: text/html"); | 198 eula_fetcher_->AddExtraRequestHeader("Accept: text/html"); |
163 eula_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 199 eula_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
164 net::LOAD_DO_NOT_SAVE_COOKIES | | 200 net::LOAD_DO_NOT_SAVE_COOKIES | |
165 net::LOAD_DISABLE_CACHE); | 201 net::LOAD_DISABLE_CACHE); |
166 eula_fetcher_->Start(); | 202 eula_fetcher_->Start(); |
167 // Abort the download attempt if it takes longer than one minute. | 203 // Abort the download attempt if it takes longer than one minute. |
168 download_timer_.Start(FROM_HERE, | 204 download_timer_.Start(FROM_HERE, |
169 base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec), | 205 base::TimeDelta::FromSeconds(kOnlineTermsTimeoutSec), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 } else if (CommandLine::ForCurrentProcess()->HasSwitch( | 286 } else if (CommandLine::ForCurrentProcess()->HasSwitch( |
251 chromeos::switches::kDisableOnlineEULA)) { | 287 chromeos::switches::kDisableOnlineEULA)) { |
252 // Fallback to the local file. | 288 // Fallback to the local file. |
253 BrowserThread::PostTask( | 289 BrowserThread::PostTask( |
254 BrowserThread::FILE, FROM_HERE, | 290 BrowserThread::FILE, FROM_HERE, |
255 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this)); | 291 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this)); |
256 } else { | 292 } else { |
257 // Try to load online version of ChromeOS terms first. | 293 // Try to load online version of ChromeOS terms first. |
258 // ChromeOSOnlineTermsHandler object destroys itself. | 294 // ChromeOSOnlineTermsHandler object destroys itself. |
259 new ChromeOSOnlineTermsHandler( | 295 new ChromeOSOnlineTermsHandler( |
260 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this)); | 296 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this), |
297 locale_); | |
261 } | 298 } |
262 } | 299 } |
263 | 300 |
264 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) { | 301 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
266 loader->GetResponseResult(&contents_); | 303 loader->GetResponseResult(&contents_); |
267 if (contents_.empty()) { | 304 if (contents_.empty()) { |
268 // Load local ChromeOS terms from the file. | 305 // Load local ChromeOS terms from the file. |
269 BrowserThread::PostTask( | 306 BrowserThread::PostTask( |
270 BrowserThread::FILE, FROM_HERE, | 307 BrowserThread::FILE, FROM_HERE, |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 Profile* profile = Profile::FromWebUI(web_ui); | 1221 Profile* profile = Profile::FromWebUI(web_ui); |
1185 | 1222 |
1186 #if defined(ENABLE_THEMES) | 1223 #if defined(ENABLE_THEMES) |
1187 // Set up the chrome://theme/ source. | 1224 // Set up the chrome://theme/ source. |
1188 ThemeSource* theme = new ThemeSource(profile); | 1225 ThemeSource* theme = new ThemeSource(profile); |
1189 content::URLDataSource::Add(profile, theme); | 1226 content::URLDataSource::Add(profile, theme); |
1190 #endif | 1227 #endif |
1191 | 1228 |
1192 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); | 1229 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); |
1193 } | 1230 } |
OLD | NEW |