OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/renderer/net/net_error_helper.h" | 5 #include "chrome/renderer/net/net_error_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 const base::StringPiece template_html( | 195 const base::StringPiece template_html( |
196 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 196 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
197 if (template_html.empty()) { | 197 if (template_html.empty()) { |
198 NOTREACHED() << "unable to load template."; | 198 NOTREACHED() << "unable to load template."; |
199 } else { | 199 } else { |
200 base::DictionaryValue error_strings; | 200 base::DictionaryValue error_strings; |
201 LocalizedError::GetStrings( | 201 LocalizedError::GetStrings( |
202 error.reason, error.domain.utf8(), error.unreachableURL, is_failed_post, | 202 error.reason, error.domain.utf8(), error.unreachableURL, is_failed_post, |
203 error.staleCopyInCache, can_show_network_diagnostics_dialog, | 203 error.staleCopyInCache, can_show_network_diagnostics_dialog, |
204 has_offline_pages, RenderThread::Get()->GetLocale(), | 204 has_offline_pages, RenderThread::Get()->GetLocale(), |
205 render_frame()->GetRenderView()->GetAcceptLanguages(), | |
206 std::move(params), &error_strings); | 205 std::move(params), &error_strings); |
207 *reload_button_shown = error_strings.Get("reloadButton", nullptr); | 206 *reload_button_shown = error_strings.Get("reloadButton", nullptr); |
208 *show_saved_copy_button_shown = | 207 *show_saved_copy_button_shown = |
209 error_strings.Get("showSavedCopyButton", nullptr); | 208 error_strings.Get("showSavedCopyButton", nullptr); |
210 *show_cached_copy_button_shown = | 209 *show_cached_copy_button_shown = |
211 error_strings.Get("cacheButton", nullptr); | 210 error_strings.Get("cacheButton", nullptr); |
212 *show_offline_pages_button_shown = | 211 *show_offline_pages_button_shown = |
213 error_strings.Get("showOfflinePagesButton", nullptr); | 212 error_strings.Get("showOfflinePagesButton", nullptr); |
214 // "t" is the id of the template's root node. | 213 // "t" is the id of the template's root node. |
215 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 214 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
(...skipping 18 matching lines...) Expand all Loading... |
234 base::DictionaryValue error_strings; | 233 base::DictionaryValue error_strings; |
235 LocalizedError::GetStrings( | 234 LocalizedError::GetStrings( |
236 error.reason, | 235 error.reason, |
237 error.domain.utf8(), | 236 error.domain.utf8(), |
238 error.unreachableURL, | 237 error.unreachableURL, |
239 is_failed_post, | 238 is_failed_post, |
240 error.staleCopyInCache, | 239 error.staleCopyInCache, |
241 can_show_network_diagnostics_dialog, | 240 can_show_network_diagnostics_dialog, |
242 has_offline_pages, | 241 has_offline_pages, |
243 RenderThread::Get()->GetLocale(), | 242 RenderThread::Get()->GetLocale(), |
244 render_frame()->GetRenderView()->GetAcceptLanguages(), | |
245 scoped_ptr<ErrorPageParams>(), | 243 scoped_ptr<ErrorPageParams>(), |
246 &error_strings); | 244 &error_strings); |
247 | 245 |
248 std::string json; | 246 std::string json; |
249 JSONWriter::Write(error_strings, &json); | 247 JSONWriter::Write(error_strings, &json); |
250 | 248 |
251 std::string js = "if (window.updateForDnsProbe) " | 249 std::string js = "if (window.updateForDnsProbe) " |
252 "updateForDnsProbe(" + json + ");"; | 250 "updateForDnsProbe(" + json + ");"; |
253 base::string16 js16; | 251 base::string16 js16; |
254 if (!base::UTF8ToUTF16(js.c_str(), js.length(), &js16)) { | 252 if (!base::UTF8ToUTF16(js.c_str(), js.length(), &js16)) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 355 } |
358 | 356 |
359 void NetErrorHelper::OnNavigationCorrectionsFetched( | 357 void NetErrorHelper::OnNavigationCorrectionsFetched( |
360 const blink::WebURLResponse& response, | 358 const blink::WebURLResponse& response, |
361 const std::string& data) { | 359 const std::string& data) { |
362 // The fetcher may only be deleted after |data| is passed to |core_|. Move | 360 // The fetcher may only be deleted after |data| is passed to |core_|. Move |
363 // it to a temporary to prevent any potential re-entrancy issues. | 361 // it to a temporary to prevent any potential re-entrancy issues. |
364 scoped_ptr<content::ResourceFetcher> fetcher( | 362 scoped_ptr<content::ResourceFetcher> fetcher( |
365 correction_fetcher_.release()); | 363 correction_fetcher_.release()); |
366 bool success = (!response.isNull() && response.httpStatusCode() == 200); | 364 bool success = (!response.isNull() && response.httpStatusCode() == 200); |
367 core_->OnNavigationCorrectionsFetched( | 365 core_->OnNavigationCorrectionsFetched(success ? data : "", |
368 success ? data : "", | 366 base::i18n::IsRTL()); |
369 render_frame()->GetRenderView()->GetAcceptLanguages(), | |
370 base::i18n::IsRTL()); | |
371 } | 367 } |
372 | 368 |
373 void NetErrorHelper::OnTrackingRequestComplete( | 369 void NetErrorHelper::OnTrackingRequestComplete( |
374 const blink::WebURLResponse& response, | 370 const blink::WebURLResponse& response, |
375 const std::string& data) { | 371 const std::string& data) { |
376 tracking_fetcher_.reset(); | 372 tracking_fetcher_.reset(); |
377 } | 373 } |
378 | 374 |
379 #if defined(OS_ANDROID) | 375 #if defined(OS_ANDROID) |
380 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { | 376 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { |
381 core_->OnSetHasOfflinePages(has_offline_pages); | 377 core_->OnSetHasOfflinePages(has_offline_pages); |
382 } | 378 } |
383 #endif // defined(OS_ANDROID) | 379 #endif // defined(OS_ANDROID) |
OLD | NEW |