| 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 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 return handled; | 168 return handled; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // static | 171 // static |
| 172 bool NetErrorHelper::GetErrorStringsForDnsProbe( | 172 bool NetErrorHelper::GetErrorStringsForDnsProbe( |
| 173 WebKit::WebFrame* frame, | 173 WebKit::WebFrame* frame, |
| 174 const WebKit::WebURLError& error, | 174 const WebKit::WebURLError& error, |
| 175 bool is_failed_post, | 175 bool is_failed_post, |
| 176 const std::string& locale, | 176 const std::string& locale, |
| 177 const std::string& accept_languages, |
| 177 base::DictionaryValue* error_strings) { | 178 base::DictionaryValue* error_strings) { |
| 178 if (!IsMainFrame(frame)) | 179 if (!IsMainFrame(frame)) |
| 179 return false; | 180 return false; |
| 180 | 181 |
| 181 if (!IsDnsError(error)) | 182 if (!IsDnsError(error)) |
| 182 return false; | 183 return false; |
| 183 | 184 |
| 184 // Get the strings for a fake "DNS probe possible" error. | 185 // Get the strings for a fake "DNS probe possible" error. |
| 185 LocalizedError::GetStrings( | 186 LocalizedError::GetStrings( |
| 186 chrome_common_net::DNS_PROBE_POSSIBLE, | 187 chrome_common_net::DNS_PROBE_POSSIBLE, |
| 187 chrome_common_net::kDnsProbeErrorDomain, | 188 chrome_common_net::kDnsProbeErrorDomain, |
| 188 error.unreachableURL, | 189 error.unreachableURL, |
| 189 is_failed_post, locale, error_strings); | 190 is_failed_post, locale, accept_languages, error_strings); |
| 190 return true; | 191 return true; |
| 191 } | 192 } |
| 192 | 193 |
| 193 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 194 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
| 194 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); | 195 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); |
| 195 | 196 |
| 196 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 197 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
| 197 | 198 |
| 198 DnsProbeStatus status = static_cast<DnsProbeStatus>(status_num); | 199 DnsProbeStatus status = static_cast<DnsProbeStatus>(status_num); |
| 199 DCHECK_NE(chrome_common_net::DNS_PROBE_POSSIBLE, status); | 200 DCHECK_NE(chrome_common_net::DNS_PROBE_POSSIBLE, status); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 212 void NetErrorHelper::UpdateErrorPage() { | 213 void NetErrorHelper::UpdateErrorPage() { |
| 213 DCHECK(forwarding_probe_results_); | 214 DCHECK(forwarding_probe_results_); |
| 214 | 215 |
| 215 WebKit::WebURLError error = GetUpdatedError(); | 216 WebKit::WebURLError error = GetUpdatedError(); |
| 216 base::DictionaryValue error_strings; | 217 base::DictionaryValue error_strings; |
| 217 LocalizedError::GetStrings(error.reason, | 218 LocalizedError::GetStrings(error.reason, |
| 218 error.domain.utf8(), | 219 error.domain.utf8(), |
| 219 error.unreachableURL, | 220 error.unreachableURL, |
| 220 is_failed_post_, | 221 is_failed_post_, |
| 221 RenderThread::Get()->GetLocale(), | 222 RenderThread::Get()->GetLocale(), |
| 223 render_view()->GetAcceptLanguages(), |
| 222 &error_strings); | 224 &error_strings); |
| 223 | 225 |
| 224 std::string json; | 226 std::string json; |
| 225 JSONWriter::Write(&error_strings, &json); | 227 JSONWriter::Write(&error_strings, &json); |
| 226 | 228 |
| 227 std::string js = "if (window.updateForDnsProbe) " | 229 std::string js = "if (window.updateForDnsProbe) " |
| 228 "updateForDnsProbe(" + json + ");"; | 230 "updateForDnsProbe(" + json + ");"; |
| 229 string16 js16; | 231 string16 js16; |
| 230 if (!UTF8ToUTF16(js.c_str(), js.length(), &js16)) { | 232 if (!UTF8ToUTF16(js.c_str(), js.length(), &js16)) { |
| 231 NOTREACHED(); | 233 NOTREACHED(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 253 } | 255 } |
| 254 | 256 |
| 255 WebKit::WebURLError error; | 257 WebKit::WebURLError error; |
| 256 error.domain = WebKit::WebString::fromUTF8( | 258 error.domain = WebKit::WebString::fromUTF8( |
| 257 chrome_common_net::kDnsProbeErrorDomain); | 259 chrome_common_net::kDnsProbeErrorDomain); |
| 258 error.reason = last_probe_status_; | 260 error.reason = last_probe_status_; |
| 259 error.unreachableURL = last_error_.unreachableURL; | 261 error.unreachableURL = last_error_.unreachableURL; |
| 260 | 262 |
| 261 return error; | 263 return error; |
| 262 } | 264 } |
| OLD | NEW |