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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/localized_error.h" | 16 #include "chrome/common/localized_error.h" |
17 #include "chrome/common/net/net_error_info.h" | |
18 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
19 #include "chrome/grit/renderer_resources.h" | 18 #include "chrome/grit/renderer_resources.h" |
20 #include "chrome/renderer/net/net_error_page_controller.h" | 19 #include "chrome/renderer/net/net_error_page_controller.h" |
| 20 #include "components/error_page/common/error_page_params.h" |
| 21 #include "components/error_page/common/net_error_info.h" |
21 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
23 #include "content/public/renderer/content_renderer_client.h" | 24 #include "content/public/renderer/content_renderer_client.h" |
24 #include "content/public/renderer/document_state.h" | 25 #include "content/public/renderer/document_state.h" |
25 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_thread.h" | 27 #include "content/public/renderer/render_thread.h" |
27 #include "content/public/renderer/render_view.h" | 28 #include "content/public/renderer/render_view.h" |
28 #include "content/public/renderer/resource_fetcher.h" | 29 #include "content/public/renderer/resource_fetcher.h" |
29 #include "ipc/ipc_message.h" | 30 #include "ipc/ipc_message.h" |
30 #include "ipc/ipc_message_macros.h" | 31 #include "ipc/ipc_message_macros.h" |
(...skipping 10 matching lines...) Expand all Loading... |
41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
42 | 43 |
43 using base::JSONWriter; | 44 using base::JSONWriter; |
44 using chrome_common_net::DnsProbeStatus; | 45 using chrome_common_net::DnsProbeStatus; |
45 using chrome_common_net::DnsProbeStatusToString; | 46 using chrome_common_net::DnsProbeStatusToString; |
46 using content::DocumentState; | 47 using content::DocumentState; |
47 using content::RenderFrame; | 48 using content::RenderFrame; |
48 using content::RenderFrameObserver; | 49 using content::RenderFrameObserver; |
49 using content::RenderThread; | 50 using content::RenderThread; |
50 using content::kUnreachableWebDataURL; | 51 using content::kUnreachableWebDataURL; |
| 52 using error_page::ErrorPageParams; |
| 53 using error_page::NetErrorHelperCore; |
51 | 54 |
52 namespace { | 55 namespace { |
53 | 56 |
54 // Number of seconds to wait for the navigation correction service to return | 57 // Number of seconds to wait for the navigation correction service to return |
55 // suggestions. If it takes too long, just use the local error page. | 58 // suggestions. If it takes too long, just use the local error page. |
56 static const int kNavigationCorrectionFetchTimeoutSec = 3; | 59 static const int kNavigationCorrectionFetchTimeoutSec = 3; |
57 | 60 |
58 NetErrorHelperCore::PageType GetLoadingPageType(const blink::WebFrame* frame) { | 61 NetErrorHelperCore::PageType GetLoadingPageType(const blink::WebFrame* frame) { |
59 GURL url = frame->provisionalDataSource()->request().url(); | 62 GURL url = frame->provisionalDataSource()->request().url(); |
60 if (!url.is_valid() || url.spec() != kUnreachableWebDataURL) | 63 if (!url.is_valid() || url.spec() != kUnreachableWebDataURL) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return core_->ShouldSuppressErrorPage(GetFrameType(frame), url); | 161 return core_->ShouldSuppressErrorPage(GetFrameType(frame), url); |
159 } | 162 } |
160 | 163 |
161 void NetErrorHelper::TrackClick(int tracking_id) { | 164 void NetErrorHelper::TrackClick(int tracking_id) { |
162 core_->TrackClick(tracking_id); | 165 core_->TrackClick(tracking_id); |
163 } | 166 } |
164 | 167 |
165 void NetErrorHelper::GenerateLocalizedErrorPage( | 168 void NetErrorHelper::GenerateLocalizedErrorPage( |
166 const blink::WebURLError& error, | 169 const blink::WebURLError& error, |
167 bool is_failed_post, | 170 bool is_failed_post, |
168 scoped_ptr<LocalizedError::ErrorPageParams> params, | 171 scoped_ptr<ErrorPageParams> params, |
169 bool* reload_button_shown, | 172 bool* reload_button_shown, |
170 bool* load_stale_button_shown, | 173 bool* load_stale_button_shown, |
171 std::string* error_html) const { | 174 std::string* error_html) const { |
172 error_html->clear(); | 175 error_html->clear(); |
173 | 176 |
174 int resource_id = IDR_NET_ERROR_HTML; | 177 int resource_id = IDR_NET_ERROR_HTML; |
175 const base::StringPiece template_html( | 178 const base::StringPiece template_html( |
176 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 179 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
177 if (template_html.empty()) { | 180 if (template_html.empty()) { |
178 NOTREACHED() << "unable to load template."; | 181 NOTREACHED() << "unable to load template."; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 base::DictionaryValue error_strings; | 223 base::DictionaryValue error_strings; |
221 LocalizedError::GetStrings(error.reason, | 224 LocalizedError::GetStrings(error.reason, |
222 error.domain.utf8(), | 225 error.domain.utf8(), |
223 error.unreachableURL, | 226 error.unreachableURL, |
224 is_failed_post, | 227 is_failed_post, |
225 (load_stale_cache_enabled && | 228 (load_stale_cache_enabled && |
226 error.staleCopyInCache && !is_failed_post), | 229 error.staleCopyInCache && !is_failed_post), |
227 RenderThread::Get()->GetLocale(), | 230 RenderThread::Get()->GetLocale(), |
228 render_frame()->GetRenderView()-> | 231 render_frame()->GetRenderView()-> |
229 GetAcceptLanguages(), | 232 GetAcceptLanguages(), |
230 scoped_ptr<LocalizedError::ErrorPageParams>(), | 233 scoped_ptr<ErrorPageParams>(), |
231 &error_strings); | 234 &error_strings); |
232 | 235 |
233 std::string json; | 236 std::string json; |
234 JSONWriter::Write(&error_strings, &json); | 237 JSONWriter::Write(&error_strings, &json); |
235 | 238 |
236 std::string js = "if (window.updateForDnsProbe) " | 239 std::string js = "if (window.updateForDnsProbe) " |
237 "updateForDnsProbe(" + json + ");"; | 240 "updateForDnsProbe(" + json + ");"; |
238 base::string16 js16; | 241 base::string16 js16; |
239 if (!base::UTF8ToUTF16(js.c_str(), js.length(), &js16)) { | 242 if (!base::UTF8ToUTF16(js.c_str(), js.length(), &js16)) { |
240 NOTREACHED(); | 243 NOTREACHED(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 success ? data : "", | 346 success ? data : "", |
344 render_frame()->GetRenderView()->GetAcceptLanguages(), | 347 render_frame()->GetRenderView()->GetAcceptLanguages(), |
345 base::i18n::IsRTL()); | 348 base::i18n::IsRTL()); |
346 } | 349 } |
347 | 350 |
348 void NetErrorHelper::OnTrackingRequestComplete( | 351 void NetErrorHelper::OnTrackingRequestComplete( |
349 const blink::WebURLResponse& response, | 352 const blink::WebURLResponse& response, |
350 const std::string& data) { | 353 const std::string& data) { |
351 tracking_fetcher_.reset(); | 354 tracking_fetcher_.reset(); |
352 } | 355 } |
OLD | NEW |