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); |
200 | 201 |
201 if (!(last_fail_was_dns_error_ || forwarding_probe_results_)) { | 202 if (!(last_fail_was_dns_error_ || forwarding_probe_results_)) { |
202 DVLOG(1) << "Ignoring NetErrorInfo: no DNS error"; | 203 DVLOG(1) << "Ignoring NetErrorInfo: no DNS error"; |
203 return; | 204 return; |
204 } | 205 } |
205 | 206 |
206 last_probe_status_ = status; | 207 last_probe_status_ = status; |
207 | 208 |
208 if (forwarding_probe_results_) | 209 if (forwarding_probe_results_) |
209 UpdateErrorPage(); | 210 UpdateErrorPage(); |
210 } | 211 } |
211 | 212 |
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; |
218 const std::string accept_languages = | |
219 render_view() ? render_view()->GetAcceptLanguages() : std::string(); | |
mmenke
2013/09/26 16:23:01
The test that render_view() isn't NULL isn't neede
yuusuke
2013/09/27 14:16:52
Done.
| |
217 LocalizedError::GetStrings(error.reason, | 220 LocalizedError::GetStrings(error.reason, |
218 error.domain.utf8(), | 221 error.domain.utf8(), |
219 error.unreachableURL, | 222 error.unreachableURL, |
220 is_failed_post_, | 223 is_failed_post_, |
221 RenderThread::Get()->GetLocale(), | 224 RenderThread::Get()->GetLocale(), |
225 accept_languages, | |
222 &error_strings); | 226 &error_strings); |
223 | 227 |
224 std::string json; | 228 std::string json; |
225 JSONWriter::Write(&error_strings, &json); | 229 JSONWriter::Write(&error_strings, &json); |
226 | 230 |
227 std::string js = "if (window.updateForDnsProbe) " | 231 std::string js = "if (window.updateForDnsProbe) " |
228 "updateForDnsProbe(" + json + ");"; | 232 "updateForDnsProbe(" + json + ");"; |
229 string16 js16; | 233 string16 js16; |
230 if (!UTF8ToUTF16(js.c_str(), js.length(), &js16)) { | 234 if (!UTF8ToUTF16(js.c_str(), js.length(), &js16)) { |
231 NOTREACHED(); | 235 NOTREACHED(); |
(...skipping 21 matching lines...) Expand all Loading... | |
253 } | 257 } |
254 | 258 |
255 WebKit::WebURLError error; | 259 WebKit::WebURLError error; |
256 error.domain = WebKit::WebString::fromUTF8( | 260 error.domain = WebKit::WebString::fromUTF8( |
257 chrome_common_net::kDnsProbeErrorDomain); | 261 chrome_common_net::kDnsProbeErrorDomain); |
258 error.reason = last_probe_status_; | 262 error.reason = last_probe_status_; |
259 error.unreachableURL = last_error_.unreachableURL; | 263 error.unreachableURL = last_error_.unreachableURL; |
260 | 264 |
261 return error; | 265 return error; |
262 } | 266 } |
OLD | NEW |