| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/localized_error.h" |
| 14 #include "chrome/common/net/net_error_info.h" | 17 #include "chrome/common/net/net_error_info.h" |
| 15 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 16 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 18 #include "content/public/renderer/content_renderer_client.h" | 21 #include "content/public/renderer/content_renderer_client.h" |
| 19 #include "content/public/renderer/render_frame.h" | 22 #include "content/public/renderer/render_frame.h" |
| 20 #include "content/public/renderer/render_thread.h" | 23 #include "content/public/renderer/render_thread.h" |
| 21 #include "content/public/renderer/render_view.h" | 24 #include "content/public/renderer/render_view.h" |
| 22 #include "content/public/renderer/resource_fetcher.h" | 25 #include "content/public/renderer/resource_fetcher.h" |
| 23 #include "grit/renderer_resources.h" | 26 #include "grit/renderer_resources.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return base::i18n::IsRTL(); | 76 return base::i18n::IsRTL(); |
| 74 #endif | 77 #endif |
| 75 } | 78 } |
| 76 | 79 |
| 77 } // namespace | 80 } // namespace |
| 78 | 81 |
| 79 NetErrorHelper::NetErrorHelper(RenderFrame* render_view) | 82 NetErrorHelper::NetErrorHelper(RenderFrame* render_view) |
| 80 : RenderFrameObserver(render_view), | 83 : RenderFrameObserver(render_view), |
| 81 content::RenderFrameObserverTracker<NetErrorHelper>(render_view), | 84 content::RenderFrameObserverTracker<NetErrorHelper>(render_view), |
| 82 core_(this) { | 85 core_(this) { |
| 86 RenderThread::Get()->AddObserver(this); |
| 87 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 88 bool auto_reload_enabled = |
| 89 command_line->HasSwitch(switches::kEnableOfflineAutoReload); |
| 90 core_.set_auto_reload_enabled(auto_reload_enabled); |
| 83 } | 91 } |
| 84 | 92 |
| 85 NetErrorHelper::~NetErrorHelper() { | 93 NetErrorHelper::~NetErrorHelper() { |
| 94 RenderThread::Get()->RemoveObserver(this); |
| 86 } | 95 } |
| 87 | 96 |
| 88 void NetErrorHelper::DidStartProvisionalLoad() { | 97 void NetErrorHelper::DidStartProvisionalLoad() { |
| 89 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 98 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 90 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); | 99 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); |
| 91 } | 100 } |
| 92 | 101 |
| 93 void NetErrorHelper::DidCommitProvisionalLoad(bool is_new_navigation) { | 102 void NetErrorHelper::DidCommitProvisionalLoad(bool is_new_navigation) { |
| 94 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 103 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 95 core_.OnCommitLoad(GetFrameType(frame)); | 104 core_.OnCommitLoad(GetFrameType(frame)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 110 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) | 119 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) |
| 111 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) | 120 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) |
| 112 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, | 121 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetNavigationCorrectionInfo, |
| 113 OnSetNavigationCorrectionInfo); | 122 OnSetNavigationCorrectionInfo); |
| 114 IPC_MESSAGE_UNHANDLED(handled = false) | 123 IPC_MESSAGE_UNHANDLED(handled = false) |
| 115 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
| 116 | 125 |
| 117 return handled; | 126 return handled; |
| 118 } | 127 } |
| 119 | 128 |
| 129 void NetErrorHelper::NetworkStateChanged(bool enabled) { |
| 130 core_.NetworkStateChanged(enabled); |
| 131 } |
| 132 |
| 120 void NetErrorHelper::GetErrorHTML( | 133 void NetErrorHelper::GetErrorHTML( |
| 121 blink::WebFrame* frame, | 134 blink::WebFrame* frame, |
| 122 const blink::WebURLError& error, | 135 const blink::WebURLError& error, |
| 123 bool is_failed_post, | 136 bool is_failed_post, |
| 124 std::string* error_html) { | 137 std::string* error_html) { |
| 125 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html); | 138 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html); |
| 126 } | 139 } |
| 127 | 140 |
| 141 bool NetErrorHelper::ShouldSuppressErrorPage(blink::WebFrame* frame, |
| 142 const GURL& url) { |
| 143 return core_.ShouldSuppressErrorPage(GetFrameType(frame), url); |
| 144 } |
| 145 |
| 128 void NetErrorHelper::GenerateLocalizedErrorPage( | 146 void NetErrorHelper::GenerateLocalizedErrorPage( |
| 129 const blink::WebURLError& error, | 147 const blink::WebURLError& error, |
| 130 bool is_failed_post, | 148 bool is_failed_post, |
| 131 scoped_ptr<LocalizedError::ErrorPageParams> params, | 149 scoped_ptr<LocalizedError::ErrorPageParams> params, |
| 132 std::string* error_html) const { | 150 std::string* error_html) const { |
| 133 error_html->clear(); | 151 error_html->clear(); |
| 134 | 152 |
| 135 int resource_id = IDR_NET_ERROR_HTML; | 153 int resource_id = IDR_NET_ERROR_HTML; |
| 136 const base::StringPiece template_html( | 154 const base::StringPiece template_html( |
| 137 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 155 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 base::Unretained(this))); | 228 base::Unretained(this))); |
| 211 | 229 |
| 212 correction_fetcher_->SetTimeout( | 230 correction_fetcher_->SetTimeout( |
| 213 base::TimeDelta::FromSeconds(kNavigationCorrectionFetchTimeoutSec)); | 231 base::TimeDelta::FromSeconds(kNavigationCorrectionFetchTimeoutSec)); |
| 214 } | 232 } |
| 215 | 233 |
| 216 void NetErrorHelper::CancelFetchNavigationCorrections() { | 234 void NetErrorHelper::CancelFetchNavigationCorrections() { |
| 217 correction_fetcher_.reset(); | 235 correction_fetcher_.reset(); |
| 218 } | 236 } |
| 219 | 237 |
| 238 void NetErrorHelper::ReloadPage() { |
| 239 render_frame()->GetWebFrame()->reload(false); |
| 240 } |
| 241 |
| 220 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 242 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
| 221 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); | 243 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); |
| 222 | 244 |
| 223 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 245 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
| 224 | 246 |
| 225 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); | 247 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); |
| 226 } | 248 } |
| 227 | 249 |
| 228 void NetErrorHelper::OnSetNavigationCorrectionInfo( | 250 void NetErrorHelper::OnSetNavigationCorrectionInfo( |
| 229 const GURL& navigation_correction_url, | 251 const GURL& navigation_correction_url, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 245 if (!response.isNull() && response.httpStatusCode() == 200) { | 267 if (!response.isNull() && response.httpStatusCode() == 200) { |
| 246 core_.OnNavigationCorrectionsFetched( | 268 core_.OnNavigationCorrectionsFetched( |
| 247 data, render_frame()->GetRenderView()->GetAcceptLanguages(), | 269 data, render_frame()->GetRenderView()->GetAcceptLanguages(), |
| 248 LocaleIsRTL()); | 270 LocaleIsRTL()); |
| 249 } else { | 271 } else { |
| 250 core_.OnNavigationCorrectionsFetched( | 272 core_.OnNavigationCorrectionsFetched( |
| 251 "", render_frame()->GetRenderView()->GetAcceptLanguages(), | 273 "", render_frame()->GetRenderView()->GetAcceptLanguages(), |
| 252 LocaleIsRTL()); | 274 LocaleIsRTL()); |
| 253 } | 275 } |
| 254 } | 276 } |
| OLD | NEW |