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