| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 using content::DocumentState; | 46 using content::DocumentState; |
| 47 using content::RenderFrame; | 47 using content::RenderFrame; |
| 48 using content::RenderFrameObserver; | 48 using content::RenderFrameObserver; |
| 49 using content::RenderThread; | 49 using content::RenderThread; |
| 50 using content::kUnreachableWebDataURL; | 50 using content::kUnreachableWebDataURL; |
| 51 using error_page::DnsProbeStatus; | 51 using error_page::DnsProbeStatus; |
| 52 using error_page::DnsProbeStatusToString; | 52 using error_page::DnsProbeStatusToString; |
| 53 using error_page::ErrorPageParams; | 53 using error_page::ErrorPageParams; |
| 54 using error_page::LocalizedError; | 54 using error_page::LocalizedError; |
| 55 using error_page::NetErrorHelperCore; | 55 using error_page::NetErrorHelperCore; |
| 56 using error_page::OfflinePageStatus; | |
| 57 | 56 |
| 58 namespace { | 57 namespace { |
| 59 | 58 |
| 60 // Number of seconds to wait for the navigation correction service to return | 59 // Number of seconds to wait for the navigation correction service to return |
| 61 // suggestions. If it takes too long, just use the local error page. | 60 // suggestions. If it takes too long, just use the local error page. |
| 62 const int kNavigationCorrectionFetchTimeoutSec = 3; | 61 const int kNavigationCorrectionFetchTimeoutSec = 3; |
| 63 | 62 |
| 64 NetErrorHelperCore::PageType GetLoadingPageType(RenderFrame* render_frame) { | 63 NetErrorHelperCore::PageType GetLoadingPageType(RenderFrame* render_frame) { |
| 65 blink::WebFrame* web_frame = render_frame->GetWebFrame(); | 64 blink::WebFrame* web_frame = render_frame->GetWebFrame(); |
| 66 GURL url = web_frame->provisionalDataSource()->request().url(); | 65 GURL url = web_frame->provisionalDataSource()->request().url(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { | 147 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { |
| 149 bool handled = true; | 148 bool handled = true; |
| 150 | 149 |
| 151 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) | 150 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) |
| 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) | 151 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) |
| 153 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, | 152 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, |
| 154 OnSetCanShowNetworkDiagnosticsDialog); | 153 OnSetCanShowNetworkDiagnosticsDialog); |
| 155 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, | 154 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, |
| 156 OnSetNavigationCorrectionInfo); | 155 OnSetNavigationCorrectionInfo); |
| 157 #if defined(OS_ANDROID) | 156 #if defined(OS_ANDROID) |
| 158 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetOfflinePageInfo, OnSetOfflinePageInfo) | 157 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetHasOfflinePages, OnSetHasOfflinePages) |
| 159 #endif | 158 #endif |
| 160 IPC_MESSAGE_UNHANDLED(handled = false) | 159 IPC_MESSAGE_UNHANDLED(handled = false) |
| 161 IPC_END_MESSAGE_MAP() | 160 IPC_END_MESSAGE_MAP() |
| 162 | 161 |
| 163 return handled; | 162 return handled; |
| 164 } | 163 } |
| 165 | 164 |
| 166 void NetErrorHelper::NetworkStateChanged(bool enabled) { | 165 void NetErrorHelper::NetworkStateChanged(bool enabled) { |
| 167 core_->NetworkStateChanged(enabled); | 166 core_->NetworkStateChanged(enabled); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void NetErrorHelper::GetErrorHTML(const blink::WebURLError& error, | 169 void NetErrorHelper::GetErrorHTML(const blink::WebURLError& error, |
| 171 bool is_failed_post, | 170 bool is_failed_post, |
| 172 bool is_ignoring_cache, | 171 bool is_ignoring_cache, |
| 173 std::string* error_html) { | 172 std::string* error_html) { |
| 174 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, | 173 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, |
| 175 is_ignoring_cache, error_html); | 174 is_ignoring_cache, error_html); |
| 176 } | 175 } |
| 177 | 176 |
| 178 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { | 177 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { |
| 179 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); | 178 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void NetErrorHelper::GenerateLocalizedErrorPage( | 181 void NetErrorHelper::GenerateLocalizedErrorPage( |
| 183 const blink::WebURLError& error, | 182 const blink::WebURLError& error, |
| 184 bool is_failed_post, | 183 bool is_failed_post, |
| 185 bool can_show_network_diagnostics_dialog, | 184 bool can_show_network_diagnostics_dialog, |
| 186 OfflinePageStatus offline_page_status, | 185 bool has_offline_pages, |
| 187 scoped_ptr<ErrorPageParams> params, | 186 scoped_ptr<ErrorPageParams> params, |
| 188 bool* reload_button_shown, | 187 bool* reload_button_shown, |
| 189 bool* show_saved_copy_button_shown, | 188 bool* show_saved_copy_button_shown, |
| 190 bool* show_cached_copy_button_shown, | 189 bool* show_cached_copy_button_shown, |
| 191 bool* show_offline_pages_button_shown, | 190 bool* show_offline_pages_button_shown, |
| 192 bool* show_offline_copy_button_shown, | |
| 193 std::string* error_html) const { | 191 std::string* error_html) const { |
| 194 error_html->clear(); | 192 error_html->clear(); |
| 195 | 193 |
| 196 int resource_id = IDR_NET_ERROR_HTML; | 194 int resource_id = IDR_NET_ERROR_HTML; |
| 197 const base::StringPiece template_html( | 195 const base::StringPiece template_html( |
| 198 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 196 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 199 if (template_html.empty()) { | 197 if (template_html.empty()) { |
| 200 NOTREACHED() << "unable to load template."; | 198 NOTREACHED() << "unable to load template."; |
| 201 } else { | 199 } else { |
| 202 base::DictionaryValue error_strings; | 200 base::DictionaryValue error_strings; |
| 203 LocalizedError::GetStrings( | 201 LocalizedError::GetStrings( |
| 204 error.reason, error.domain.utf8(), error.unreachableURL, is_failed_post, | 202 error.reason, error.domain.utf8(), error.unreachableURL, is_failed_post, |
| 205 error.staleCopyInCache, can_show_network_diagnostics_dialog, | 203 error.staleCopyInCache, can_show_network_diagnostics_dialog, |
| 206 offline_page_status, RenderThread::Get()->GetLocale(), | 204 has_offline_pages, RenderThread::Get()->GetLocale(), |
| 207 render_frame()->GetRenderView()->GetAcceptLanguages(), | 205 render_frame()->GetRenderView()->GetAcceptLanguages(), |
| 208 std::move(params), &error_strings); | 206 std::move(params), &error_strings); |
| 209 *reload_button_shown = error_strings.Get("reloadButton", nullptr); | 207 *reload_button_shown = error_strings.Get("reloadButton", nullptr); |
| 210 *show_saved_copy_button_shown = | 208 *show_saved_copy_button_shown = |
| 211 error_strings.Get("showSavedCopyButton", nullptr); | 209 error_strings.Get("showSavedCopyButton", nullptr); |
| 212 *show_cached_copy_button_shown = | 210 *show_cached_copy_button_shown = |
| 213 error_strings.Get("cacheButton", nullptr); | 211 error_strings.Get("cacheButton", nullptr); |
| 214 *show_offline_pages_button_shown = | 212 *show_offline_pages_button_shown = |
| 215 error_strings.Get("showOfflinePagesButton", nullptr); | 213 error_strings.Get("showOfflinePagesButton", nullptr); |
| 216 *show_offline_copy_button_shown = | |
| 217 error_strings.Get("showOfflineCopyButton", nullptr); | |
| 218 // "t" is the id of the template's root node. | 214 // "t" is the id of the template's root node. |
| 219 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 215 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
| 220 } | 216 } |
| 221 } | 217 } |
| 222 | 218 |
| 223 void NetErrorHelper::LoadErrorPage(const std::string& html, | 219 void NetErrorHelper::LoadErrorPage(const std::string& html, |
| 224 const GURL& failed_url) { | 220 const GURL& failed_url) { |
| 225 render_frame()->GetWebFrame()->loadHTMLString( | 221 render_frame()->GetWebFrame()->loadHTMLString( |
| 226 html, GURL(kUnreachableWebDataURL), failed_url, true); | 222 html, GURL(kUnreachableWebDataURL), failed_url, true); |
| 227 } | 223 } |
| 228 | 224 |
| 229 void NetErrorHelper::EnablePageHelperFunctions() { | 225 void NetErrorHelper::EnablePageHelperFunctions() { |
| 230 NetErrorPageController::Install( | 226 NetErrorPageController::Install( |
| 231 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); | 227 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); |
| 232 } | 228 } |
| 233 | 229 |
| 234 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, | 230 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, |
| 235 bool is_failed_post, | 231 bool is_failed_post, |
| 236 bool can_show_network_diagnostics_dialog, | 232 bool can_show_network_diagnostics_dialog, |
| 237 OfflinePageStatus offline_page_status) { | 233 bool has_offline_pages) { |
| 238 base::DictionaryValue error_strings; | 234 base::DictionaryValue error_strings; |
| 239 LocalizedError::GetStrings( | 235 LocalizedError::GetStrings( |
| 240 error.reason, | 236 error.reason, |
| 241 error.domain.utf8(), | 237 error.domain.utf8(), |
| 242 error.unreachableURL, | 238 error.unreachableURL, |
| 243 is_failed_post, | 239 is_failed_post, |
| 244 error.staleCopyInCache, | 240 error.staleCopyInCache, |
| 245 can_show_network_diagnostics_dialog, | 241 can_show_network_diagnostics_dialog, |
| 246 offline_page_status, | 242 has_offline_pages, |
| 247 RenderThread::Get()->GetLocale(), | 243 RenderThread::Get()->GetLocale(), |
| 248 render_frame()->GetRenderView()->GetAcceptLanguages(), | 244 render_frame()->GetRenderView()->GetAcceptLanguages(), |
| 249 scoped_ptr<ErrorPageParams>(), | 245 scoped_ptr<ErrorPageParams>(), |
| 250 &error_strings); | 246 &error_strings); |
| 251 | 247 |
| 252 std::string json; | 248 std::string json; |
| 253 JSONWriter::Write(error_strings, &json); | 249 JSONWriter::Write(error_strings, &json); |
| 254 | 250 |
| 255 std::string js = "if (window.updateForDnsProbe) " | 251 std::string js = "if (window.updateForDnsProbe) " |
| 256 "updateForDnsProbe(" + json + ");"; | 252 "updateForDnsProbe(" + json + ");"; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 render_frame()->GetRoutingID(), page_url)); | 325 render_frame()->GetRoutingID(), page_url)); |
| 330 } | 326 } |
| 331 | 327 |
| 332 void NetErrorHelper::ShowOfflinePages() { | 328 void NetErrorHelper::ShowOfflinePages() { |
| 333 #if defined(OS_ANDROID) | 329 #if defined(OS_ANDROID) |
| 334 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages( | 330 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages( |
| 335 render_frame()->GetRoutingID())); | 331 render_frame()->GetRoutingID())); |
| 336 #endif // defined(OS_ANDROID) | 332 #endif // defined(OS_ANDROID) |
| 337 } | 333 } |
| 338 | 334 |
| 339 void NetErrorHelper::LoadOfflineCopy(const GURL& page_url) { | |
| 340 #if defined(OS_ANDROID) | |
| 341 render_frame()->Send(new ChromeViewHostMsg_LoadOfflineCopy( | |
| 342 render_frame()->GetRoutingID(), page_url)); | |
| 343 #endif // defined(OS_ANDROID) | |
| 344 } | |
| 345 | |
| 346 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 335 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
| 347 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); | 336 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); |
| 348 | 337 |
| 349 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 338 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
| 350 | 339 |
| 351 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); | 340 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); |
| 352 } | 341 } |
| 353 | 342 |
| 354 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( | 343 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( |
| 355 bool can_use_local_diagnostics_service) { | 344 bool can_use_local_diagnostics_service) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 381 base::i18n::IsRTL()); | 370 base::i18n::IsRTL()); |
| 382 } | 371 } |
| 383 | 372 |
| 384 void NetErrorHelper::OnTrackingRequestComplete( | 373 void NetErrorHelper::OnTrackingRequestComplete( |
| 385 const blink::WebURLResponse& response, | 374 const blink::WebURLResponse& response, |
| 386 const std::string& data) { | 375 const std::string& data) { |
| 387 tracking_fetcher_.reset(); | 376 tracking_fetcher_.reset(); |
| 388 } | 377 } |
| 389 | 378 |
| 390 #if defined(OS_ANDROID) | 379 #if defined(OS_ANDROID) |
| 391 void NetErrorHelper::OnSetOfflinePageInfo( | 380 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { |
| 392 OfflinePageStatus offline_page_status) { | 381 core_->OnSetHasOfflinePages(has_offline_pages); |
| 393 core_->OnSetOfflinePageInfo(offline_page_status); | |
| 394 } | 382 } |
| 395 #endif // defined(OS_ANDROID) | 383 #endif // defined(OS_ANDROID) |
| OLD | NEW |