| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { | 139 bool NetErrorHelper::OnMessageReceived(const IPC::Message& message) { |
| 140 bool handled = true; | 140 bool handled = true; |
| 141 | 141 |
| 142 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) | 142 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) |
| 143 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) | 143 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) |
| 144 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, | 144 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCanShowNetworkDiagnosticsDialog, |
| 145 OnSetCanShowNetworkDiagnosticsDialog); | 145 OnSetCanShowNetworkDiagnosticsDialog); |
| 146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, | 146 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, |
| 147 OnSetNavigationCorrectionInfo); | 147 OnSetNavigationCorrectionInfo); |
| 148 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetHasOfflinePages, OnSetHasOfflinePages) |
| 148 IPC_MESSAGE_UNHANDLED(handled = false) | 149 IPC_MESSAGE_UNHANDLED(handled = false) |
| 149 IPC_END_MESSAGE_MAP() | 150 IPC_END_MESSAGE_MAP() |
| 150 | 151 |
| 151 return handled; | 152 return handled; |
| 152 } | 153 } |
| 153 | 154 |
| 154 void NetErrorHelper::NetworkStateChanged(bool enabled) { | 155 void NetErrorHelper::NetworkStateChanged(bool enabled) { |
| 155 core_->NetworkStateChanged(enabled); | 156 core_->NetworkStateChanged(enabled); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void NetErrorHelper::GetErrorHTML( | 159 void NetErrorHelper::GetErrorHTML( |
| 159 const blink::WebURLError& error, | 160 const blink::WebURLError& error, |
| 160 bool is_failed_post, | 161 bool is_failed_post, |
| 161 std::string* error_html) { | 162 std::string* error_html) { |
| 162 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, | 163 core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post, |
| 163 error_html); | 164 error_html); |
| 164 } | 165 } |
| 165 | 166 |
| 166 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { | 167 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) { |
| 167 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); | 168 return core_->ShouldSuppressErrorPage(GetFrameType(render_frame()), url); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void NetErrorHelper::GenerateLocalizedErrorPage( | 171 void NetErrorHelper::GenerateLocalizedErrorPage( |
| 171 const blink::WebURLError& error, | 172 const blink::WebURLError& error, |
| 172 bool is_failed_post, | 173 bool is_failed_post, |
| 173 bool can_show_network_diagnostics_dialog, | 174 bool can_show_network_diagnostics_dialog, |
| 175 bool has_offline_pages, |
| 174 scoped_ptr<ErrorPageParams> params, | 176 scoped_ptr<ErrorPageParams> params, |
| 175 bool* reload_button_shown, | 177 bool* reload_button_shown, |
| 176 bool* show_saved_copy_button_shown, | 178 bool* show_saved_copy_button_shown, |
| 177 bool* show_cached_copy_button_shown, | 179 bool* show_cached_copy_button_shown, |
| 180 bool* show_saved_pages_button_shown, |
| 178 std::string* error_html) const { | 181 std::string* error_html) const { |
| 179 error_html->clear(); | 182 error_html->clear(); |
| 180 | 183 |
| 181 int resource_id = IDR_NET_ERROR_HTML; | 184 int resource_id = IDR_NET_ERROR_HTML; |
| 182 const base::StringPiece template_html( | 185 const base::StringPiece template_html( |
| 183 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 186 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 184 if (template_html.empty()) { | 187 if (template_html.empty()) { |
| 185 NOTREACHED() << "unable to load template."; | 188 NOTREACHED() << "unable to load template."; |
| 186 } else { | 189 } else { |
| 187 base::DictionaryValue error_strings; | 190 base::DictionaryValue error_strings; |
| 188 LocalizedError::GetStrings(error.reason, error.domain.utf8(), | 191 LocalizedError::GetStrings(error.reason, error.domain.utf8(), |
| 189 error.unreachableURL, is_failed_post, | 192 error.unreachableURL, is_failed_post, |
| 190 error.staleCopyInCache, | 193 error.staleCopyInCache, |
| 191 can_show_network_diagnostics_dialog, | 194 can_show_network_diagnostics_dialog, |
| 195 has_offline_pages, |
| 192 RenderThread::Get()->GetLocale(), | 196 RenderThread::Get()->GetLocale(), |
| 193 render_frame()->GetRenderView()-> | 197 render_frame()->GetRenderView()-> |
| 194 GetAcceptLanguages(), | 198 GetAcceptLanguages(), |
| 195 params.Pass(), &error_strings); | 199 params.Pass(), &error_strings); |
| 196 *reload_button_shown = error_strings.Get("reloadButton", nullptr); | 200 *reload_button_shown = error_strings.Get("reloadButton", nullptr); |
| 197 *show_saved_copy_button_shown = | 201 *show_saved_copy_button_shown = |
| 198 error_strings.Get("showSavedCopyButton", nullptr); | 202 error_strings.Get("showSavedCopyButton", nullptr); |
| 199 *show_cached_copy_button_shown = | 203 *show_cached_copy_button_shown = |
| 200 error_strings.Get("cacheButton", nullptr); | 204 error_strings.Get("cacheButton", nullptr); |
| 205 *show_saved_pages_button_shown = |
| 206 error_strings.Get("showSavedPagesButton", nullptr); |
| 201 // "t" is the id of the template's root node. | 207 // "t" is the id of the template's root node. |
| 202 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); | 208 *error_html = webui::GetTemplatesHtml(template_html, &error_strings, "t"); |
| 203 } | 209 } |
| 204 } | 210 } |
| 205 | 211 |
| 206 void NetErrorHelper::LoadErrorPage(const std::string& html, | 212 void NetErrorHelper::LoadErrorPage(const std::string& html, |
| 207 const GURL& failed_url) { | 213 const GURL& failed_url) { |
| 208 render_frame()->GetWebFrame()->loadHTMLString( | 214 render_frame()->GetWebFrame()->loadHTMLString( |
| 209 html, GURL(kUnreachableWebDataURL), failed_url, true); | 215 html, GURL(kUnreachableWebDataURL), failed_url, true); |
| 210 } | 216 } |
| 211 | 217 |
| 212 void NetErrorHelper::EnablePageHelperFunctions() { | 218 void NetErrorHelper::EnablePageHelperFunctions() { |
| 213 NetErrorPageController::Install( | 219 NetErrorPageController::Install( |
| 214 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); | 220 render_frame(), weak_controller_delegate_factory_.GetWeakPtr()); |
| 215 } | 221 } |
| 216 | 222 |
| 217 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, | 223 void NetErrorHelper::UpdateErrorPage(const blink::WebURLError& error, |
| 218 bool is_failed_post, | 224 bool is_failed_post, |
| 219 bool can_show_network_diagnostics_dialog) { | 225 bool can_show_network_diagnostics_dialog, |
| 226 bool has_offline_pages) { |
| 220 base::DictionaryValue error_strings; | 227 base::DictionaryValue error_strings; |
| 221 LocalizedError::GetStrings(error.reason, | 228 LocalizedError::GetStrings(error.reason, |
| 222 error.domain.utf8(), | 229 error.domain.utf8(), |
| 223 error.unreachableURL, | 230 error.unreachableURL, |
| 224 is_failed_post, | 231 is_failed_post, |
| 225 error.staleCopyInCache, | 232 error.staleCopyInCache, |
| 226 can_show_network_diagnostics_dialog, | 233 can_show_network_diagnostics_dialog, |
| 234 has_offline_pages, |
| 227 RenderThread::Get()->GetLocale(), | 235 RenderThread::Get()->GetLocale(), |
| 228 render_frame()->GetRenderView()-> | 236 render_frame()->GetRenderView()-> |
| 229 GetAcceptLanguages(), | 237 GetAcceptLanguages(), |
| 230 scoped_ptr<ErrorPageParams>(), | 238 scoped_ptr<ErrorPageParams>(), |
| 231 &error_strings); | 239 &error_strings); |
| 232 | 240 |
| 233 std::string json; | 241 std::string json; |
| 234 JSONWriter::Write(error_strings, &json); | 242 JSONWriter::Write(error_strings, &json); |
| 235 | 243 |
| 236 std::string js = "if (window.updateForDnsProbe) " | 244 std::string js = "if (window.updateForDnsProbe) " |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad); | 311 request.setCachePolicy(blink::WebURLRequest::ReturnCacheDataDontLoad); |
| 304 | 312 |
| 305 web_frame->loadRequest(request); | 313 web_frame->loadRequest(request); |
| 306 } | 314 } |
| 307 | 315 |
| 308 void NetErrorHelper::DiagnoseError(const GURL& page_url) { | 316 void NetErrorHelper::DiagnoseError(const GURL& page_url) { |
| 309 render_frame()->Send(new ChromeViewHostMsg_RunNetworkDiagnostics( | 317 render_frame()->Send(new ChromeViewHostMsg_RunNetworkDiagnostics( |
| 310 render_frame()->GetRoutingID(), page_url)); | 318 render_frame()->GetRoutingID(), page_url)); |
| 311 } | 319 } |
| 312 | 320 |
| 321 void NetErrorHelper::ShowOfflinePages() { |
| 322 render_frame()->Send(new ChromeViewHostMsg_ShowOfflinePages( |
| 323 render_frame()->GetRoutingID())); |
| 324 } |
| 325 |
| 313 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 326 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
| 314 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); | 327 DCHECK(status_num >= 0 && status_num < error_page::DNS_PROBE_MAX); |
| 315 | 328 |
| 316 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 329 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
| 317 | 330 |
| 318 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); | 331 core_->OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); |
| 319 } | 332 } |
| 320 | 333 |
| 321 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( | 334 void NetErrorHelper::OnSetCanShowNetworkDiagnosticsDialog( |
| 322 bool can_use_local_diagnostics_service) { | 335 bool can_use_local_diagnostics_service) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 346 success ? data : "", | 359 success ? data : "", |
| 347 render_frame()->GetRenderView()->GetAcceptLanguages(), | 360 render_frame()->GetRenderView()->GetAcceptLanguages(), |
| 348 base::i18n::IsRTL()); | 361 base::i18n::IsRTL()); |
| 349 } | 362 } |
| 350 | 363 |
| 351 void NetErrorHelper::OnTrackingRequestComplete( | 364 void NetErrorHelper::OnTrackingRequestComplete( |
| 352 const blink::WebURLResponse& response, | 365 const blink::WebURLResponse& response, |
| 353 const std::string& data) { | 366 const std::string& data) { |
| 354 tracking_fetcher_.reset(); | 367 tracking_fetcher_.reset(); |
| 355 } | 368 } |
| 369 |
| 370 void NetErrorHelper::OnSetHasOfflinePages(bool has_offline_pages) { |
| 371 core_->OnSetHasOfflinePages(has_offline_pages); |
| 372 } |
| OLD | NEW |