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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 #include "content/public/common/content_client.h" | 48 #include "content/public/common/content_client.h" |
49 #include "content/public/common/process_type.h" | 49 #include "content/public/common/process_type.h" |
50 #include "google_apis/gaia/google_service_auth_error.h" | 50 #include "google_apis/gaia/google_service_auth_error.h" |
51 #include "googleurl/src/gurl.h" | 51 #include "googleurl/src/gurl.h" |
52 #include "grit/browser_resources.h" | 52 #include "grit/browser_resources.h" |
53 #include "grit/chromium_strings.h" | 53 #include "grit/chromium_strings.h" |
54 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
55 #include "grit/locale_settings.h" | 55 #include "grit/locale_settings.h" |
56 #include "net/base/escape.h" | 56 #include "net/base/escape.h" |
57 #include "net/base/net_util.h" | 57 #include "net/base/net_util.h" |
58 #include "net/http/http_response_headers.h" | |
59 #include "net/url_request/url_fetcher.h" | |
60 #include "net/url_request/url_request_status.h" | |
58 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
59 #include "ui/base/resource/resource_bundle.h" | 62 #include "ui/base/resource/resource_bundle.h" |
60 #include "ui/webui/jstemplate_builder.h" | 63 #include "ui/webui/jstemplate_builder.h" |
61 #include "ui/webui/web_ui_util.h" | 64 #include "ui/webui/web_ui_util.h" |
62 | 65 |
63 #if defined(ENABLE_THEMES) | 66 #if defined(ENABLE_THEMES) |
64 #include "chrome/browser/ui/webui/theme_source.h" | 67 #include "chrome/browser/ui/webui/theme_source.h" |
65 #endif | 68 #endif |
66 | 69 |
67 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 70 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
(...skipping 21 matching lines...) Expand all Loading... | |
89 using content::BrowserThread; | 92 using content::BrowserThread; |
90 using content::WebContents; | 93 using content::WebContents; |
91 | 94 |
92 namespace { | 95 namespace { |
93 | 96 |
94 const char kCreditsJsPath[] = "credits.js"; | 97 const char kCreditsJsPath[] = "credits.js"; |
95 const char kMemoryJsPath[] = "memory.js"; | 98 const char kMemoryJsPath[] = "memory.js"; |
96 const char kMemoryCssPath[] = "about_memory.css"; | 99 const char kMemoryCssPath[] = "about_memory.css"; |
97 const char kStatsJsPath[] = "stats.js"; | 100 const char kStatsJsPath[] = "stats.js"; |
98 const char kStringsJsPath[] = "strings.js"; | 101 const char kStringsJsPath[] = "strings.js"; |
102 const int kOnlineTermsTimeout = 5; // seconds | |
Evan Stade
2013/04/15 19:35:08
two spaces before //. Also please document what th
Nikita (slow)
2013/04/16 04:36:35
nit: You could just rename it to kOnlineTermsTimeo
vasilii
2013/04/16 15:40:18
Done.
| |
99 | 103 |
100 // When you type about:memory, it actually loads this intermediate URL that | 104 // When you type about:memory, it actually loads this intermediate URL that |
101 // redirects you to the final page. This avoids the problem where typing | 105 // redirects you to the final page. This avoids the problem where typing |
102 // "about:memory" on the new tab page or any other page where a process | 106 // "about:memory" on the new tab page or any other page where a process |
103 // transition would occur to the about URL will cause some confusion. | 107 // transition would occur to the about URL will cause some confusion. |
104 // | 108 // |
105 // The problem is that during the processing of the memory page, there are two | 109 // The problem is that during the processing of the memory page, there are two |
106 // processes active, the original and the destination one. This can create the | 110 // processes active, the original and the destination one. This can create the |
107 // impression that we're using more resources than we actually are. This | 111 // impression that we're using more resources than we actually are. This |
108 // redirect solves the problem by eliminating the process transition during the | 112 // redirect solves the problem by eliminating the process transition during the |
(...skipping 21 matching lines...) Expand all Loading... | |
130 void BindProcessMetrics(DictionaryValue* data, | 134 void BindProcessMetrics(DictionaryValue* data, |
131 ProcessMemoryInformation* info); | 135 ProcessMemoryInformation* info); |
132 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); | 136 void AppendProcess(ListValue* child_data, ProcessMemoryInformation* info); |
133 | 137 |
134 content::URLDataSource::GotDataCallback callback_; | 138 content::URLDataSource::GotDataCallback callback_; |
135 | 139 |
136 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); | 140 DISALLOW_COPY_AND_ASSIGN(AboutMemoryHandler); |
137 }; | 141 }; |
138 | 142 |
139 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
144 // Helper class that fetches the online Chrome OS terms. | |
145 class ChromeOSOnlineTermsHandler : public net::URLFetcherDelegate { | |
146 public: | |
147 typedef base::Callback<void (ChromeOSOnlineTermsHandler*)> FetchCallback; | |
148 | |
149 explicit ChromeOSOnlineTermsHandler(const FetchCallback& callback): | |
150 fetch_callback_(callback) { | |
battre
2013/04/16 08:34:22
nit:
: in next line, +2 indentation
vasilii
2013/04/16 15:40:18
Done.
| |
151 // TODO(vasilii): request a real EULA specific to locale. | |
Nikita (slow)
2013/04/16 04:36:35
Is this part of the upcoming CL? I think this shou
vasilii
2013/04/16 15:40:18
Added localization support. But URL is still fake
| |
152 eula_fetcher_.reset(net::URLFetcher::Create( | |
153 GURL("https://www.google.com/intl/en/chrome/browser/" | |
154 "privacy/eula_text.html"), net::URLFetcher::GET, this)); | |
battre
2013/04/16 08:34:22
This should be an i18n-ized URL
vasilii
2013/04/16 15:40:18
Done.
| |
155 eula_fetcher_->SetRequestContext( | |
156 g_browser_process->system_request_context()); | |
157 eula_fetcher_->AddExtraRequestHeader("Accept: text/html"); | |
158 eula_fetcher_->Start(); | |
159 // Abort the download attempt if it takes longer than one minute. | |
Nikita (slow)
2013/04/16 04:36:35
What would be UX during this time? Is there some f
vasilii
2013/04/16 15:40:18
Changed timeout to 10 sec. Added "Loading" message
| |
160 download_timer_.Start(FROM_HERE, | |
161 base::TimeDelta::FromSeconds(kOnlineTermsTimeout), | |
162 this, | |
battre
2013/04/16 08:34:22
what's the lifetime of |this|? Is it guaranteed to
vasilii
2013/04/16 15:40:18
Object destroys itself in either OnURLFetchComplet
| |
163 &ChromeOSOnlineTermsHandler::OnDownloadTimeout); | |
164 } | |
165 | |
166 void GetResponseResult(std::string* response_string) { | |
167 std::string mime_type; | |
168 if (!eula_fetcher_ || | |
169 !eula_fetcher_->GetStatus().is_success() || | |
170 !eula_fetcher_->GetResponseHeaders()->GetMimeType(&mime_type) || | |
171 mime_type != "text/html" || | |
172 !eula_fetcher_->GetResponseAsString(response_string)) { | |
173 response_string->clear(); | |
174 } | |
175 } | |
176 | |
177 private: | |
178 // This object is to be allocated on the heap only. | |
battre
2013/04/16 08:34:22
I don't understand this comment. I think what you
vasilii
2013/04/16 15:40:18
Done.
| |
179 virtual ~ChromeOSOnlineTermsHandler() {} | |
180 | |
181 // net::URLFetcherDelegate: | |
182 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE { | |
183 if (source != eula_fetcher_.get()) { | |
184 NOTREACHED() << "Callback from foreign URL fetcher"; | |
185 return; | |
186 } | |
187 fetch_callback_.Run(this); | |
188 delete this; | |
189 } | |
190 | |
191 void OnDownloadTimeout() { | |
192 eula_fetcher_.reset(); | |
193 fetch_callback_.Run(this); | |
194 delete this; | |
195 } | |
battre
2013/04/16 08:34:22
nit newline.
vasilii
2013/04/16 15:40:18
Done.
| |
196 // Timer that enforces a timeout on the attempt to download the | |
197 // ChromeOS Terms. | |
198 base::OneShotTimer<ChromeOSOnlineTermsHandler> download_timer_; | |
battre
2013/04/16 08:34:22
nit: newline.
vasilii
2013/04/16 15:40:18
Done.
| |
199 // |fetch_callback_| called when fetching succeeded or failed. | |
200 FetchCallback fetch_callback_; | |
battre
2013/04/16 08:34:22
nit: newline.
vasilii
2013/04/16 15:40:18
Done.
| |
201 // Helper to fetch online eula. | |
202 scoped_ptr<net::URLFetcher> eula_fetcher_; | |
203 | |
204 DISALLOW_COPY_AND_ASSIGN(ChromeOSOnlineTermsHandler); | |
205 }; | |
206 | |
140 class ChromeOSTermsHandler | 207 class ChromeOSTermsHandler |
141 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { | 208 : public base::RefCountedThreadSafe<ChromeOSTermsHandler> { |
142 public: | 209 public: |
143 static void Start(const std::string& path, | 210 static void Start(const std::string& path, |
144 const content::URLDataSource::GotDataCallback& callback) { | 211 const content::URLDataSource::GotDataCallback& callback) { |
145 scoped_refptr<ChromeOSTermsHandler> handler( | 212 scoped_refptr<ChromeOSTermsHandler> handler( |
146 new ChromeOSTermsHandler(path, callback)); | 213 new ChromeOSTermsHandler(path, callback)); |
147 handler->StartOnUIThread(); | 214 handler->StartOnUIThread(); |
148 } | 215 } |
149 | 216 |
150 private: | 217 private: |
151 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; | 218 friend class base::RefCountedThreadSafe<ChromeOSTermsHandler>; |
152 | 219 |
153 ChromeOSTermsHandler(const std::string& path, | 220 ChromeOSTermsHandler(const std::string& path, |
154 const content::URLDataSource::GotDataCallback& callback) | 221 const content::URLDataSource::GotDataCallback& callback) |
155 : path_(path), | 222 : path_(path), |
156 callback_(callback), | 223 callback_(callback), |
157 // Previously we were using "initial locale" http://crbug.com/145142 | 224 // Previously we were using "initial locale" http://crbug.com/145142 |
158 locale_(g_browser_process->GetApplicationLocale()) { | 225 locale_(g_browser_process->GetApplicationLocale()) { |
159 } | 226 } |
160 | 227 |
161 ~ChromeOSTermsHandler() {} | 228 virtual ~ChromeOSTermsHandler() {} |
162 | 229 |
163 void StartOnUIThread() { | 230 void StartOnUIThread() { |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
165 BrowserThread::PostTask( | 232 if (path_ == chrome::kOemEulaURLPath) { |
166 BrowserThread::FILE, FROM_HERE, | 233 // Load local OEM EULA from the disk. |
167 base::Bind(&ChromeOSTermsHandler::LoadFileOnFileThread, this)); | 234 BrowserThread::PostTask( |
235 BrowserThread::FILE, FROM_HERE, | |
236 base::Bind(&ChromeOSTermsHandler::LoadOemEulaFileOnFileThread, this)); | |
237 } else { | |
238 // Try to load online version of ChromeOS terms first. | |
239 // ChromeOSOnlineTermsHandler object destroys itself. | |
240 new ChromeOSOnlineTermsHandler( | |
241 base::Bind(&ChromeOSTermsHandler::OnOnlineEULAFetched, this)); | |
battre
2013/04/16 08:34:22
Is it guaranteed that |this| survives the callback
vasilii
2013/04/16 15:40:18
ChromeOSTermsHandler is ref-counted class. base::B
| |
242 } | |
168 } | 243 } |
169 | 244 |
170 void LoadFileOnFileThread() { | 245 void OnOnlineEULAFetched(ChromeOSOnlineTermsHandler* loader) { |
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
247 loader->GetResponseResult(&contents_); | |
248 if (contents_.empty()) { | |
249 // Load local ChromeOS terms from the file. | |
250 BrowserThread::PostTask( | |
251 BrowserThread::FILE, FROM_HERE, | |
252 base::Bind(&ChromeOSTermsHandler::LoadEulaFileOnFileThread, this)); | |
253 } else { | |
254 ResponseOnUIThread(); | |
255 } | |
256 } | |
257 | |
258 void LoadOemEulaFileOnFileThread() { | |
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
172 if (path_ == chrome::kOemEulaURLPath) { | 260 const chromeos::StartupCustomizationDocument* customization = |
173 const chromeos::StartupCustomizationDocument* customization = | 261 chromeos::StartupCustomizationDocument::GetInstance(); |
174 chromeos::StartupCustomizationDocument::GetInstance(); | 262 if (customization->IsReady()) { |
175 if (customization->IsReady()) { | 263 base::FilePath oem_eula_file_path; |
176 base::FilePath oem_eula_file_path; | 264 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), |
177 if (net::FileURLToFilePath(GURL(customization->GetEULAPage(locale_)), | 265 &oem_eula_file_path)) { |
178 &oem_eula_file_path)) { | 266 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) { |
179 if (!file_util::ReadFileToString(oem_eula_file_path, &contents_)) { | |
180 contents_.clear(); | |
181 } | |
182 } | |
183 } | |
184 } else { | |
185 std::string file_path = | |
186 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); | |
187 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) { | |
188 // No EULA for given language - try en-US as default. | |
189 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US"); | |
190 if (!file_util::ReadFileToString(base::FilePath(file_path), | |
191 &contents_)) { | |
192 // File with EULA not found, ResponseOnUIThread will load EULA from | |
193 // resources if contents_ is empty. | |
194 contents_.clear(); | 267 contents_.clear(); |
195 } | 268 } |
196 } | 269 } |
197 } | 270 } |
198 BrowserThread::PostTask( | 271 BrowserThread::PostTask( |
199 BrowserThread::UI, FROM_HERE, | 272 BrowserThread::UI, FROM_HERE, |
200 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); | 273 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); |
201 } | 274 } |
202 | 275 |
276 void LoadEulaFileOnFileThread() { | |
277 std::string file_path = | |
278 base::StringPrintf(chrome::kEULAPathFormat, locale_.c_str()); | |
279 if (!file_util::ReadFileToString(base::FilePath(file_path), &contents_)) { | |
280 // No EULA for given language - try en-US as default. | |
281 file_path = base::StringPrintf(chrome::kEULAPathFormat, "en-US"); | |
282 if (!file_util::ReadFileToString(base::FilePath(file_path), | |
283 &contents_)) { | |
284 // File with EULA not found, ResponseOnUIThread will load EULA from | |
285 // resources if contents_ is empty. | |
286 contents_.clear(); | |
287 } | |
288 } | |
289 BrowserThread::PostTask( | |
290 BrowserThread::UI, FROM_HERE, | |
291 base::Bind(&ChromeOSTermsHandler::ResponseOnUIThread, this)); | |
292 } | |
293 | |
203 void ResponseOnUIThread() { | 294 void ResponseOnUIThread() { |
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
205 // If we fail to load Chrome OS EULA from disk, load it from resources. | 296 // If we fail to load Chrome OS EULA from disk, load it from resources. |
206 // Do nothing if OEM EULA load failed. | 297 // Do nothing if OEM EULA load failed. |
207 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) | 298 if (contents_.empty() && path_ != chrome::kOemEulaURLPath) |
208 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); | 299 contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); |
209 callback_.Run(base::RefCountedString::TakeString(&contents_)); | 300 callback_.Run(base::RefCountedString::TakeString(&contents_)); |
210 } | 301 } |
211 | 302 |
212 // Path in the URL. | 303 // Path in the URL. |
213 std::string path_; | 304 const std::string path_; |
214 | 305 |
215 // Callback to run with the response. | 306 // Callback to run with the response. |
216 content::URLDataSource::GotDataCallback callback_; | 307 content::URLDataSource::GotDataCallback callback_; |
217 | 308 |
218 // Locale of the EULA. | 309 // Locale of the EULA. |
219 std::string locale_; | 310 const std::string locale_; |
220 | 311 |
221 // EULA contents that was loaded from file. | 312 // EULA contents that was loaded from file. |
222 std::string contents_; | 313 std::string contents_; |
223 | 314 |
224 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); | 315 DISALLOW_COPY_AND_ASSIGN(ChromeOSTermsHandler); |
225 }; | 316 }; |
226 | 317 |
227 #endif | 318 #endif |
228 | 319 |
229 } // namespace | 320 } // namespace |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 Profile* profile = Profile::FromWebUI(web_ui); | 1158 Profile* profile = Profile::FromWebUI(web_ui); |
1068 | 1159 |
1069 #if defined(ENABLE_THEMES) | 1160 #if defined(ENABLE_THEMES) |
1070 // Set up the chrome://theme/ source. | 1161 // Set up the chrome://theme/ source. |
1071 ThemeSource* theme = new ThemeSource(profile); | 1162 ThemeSource* theme = new ThemeSource(profile); |
1072 content::URLDataSource::Add(profile, theme); | 1163 content::URLDataSource::Add(profile, theme); |
1073 #endif | 1164 #endif |
1074 | 1165 |
1075 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); | 1166 content::URLDataSource::Add(profile, new AboutUIHTMLSource(name, profile)); |
1076 } | 1167 } |
OLD | NEW |