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