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