Chromium Code Reviews| 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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 13 #include "chrome/common/localized_error.h" | 15 #include "chrome/common/localized_error.h" |
| 14 #include "chrome/common/net/net_error_info.h" | 16 #include "chrome/common/net/net_error_info.h" |
| 15 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "chrome/renderer/net/mockable_one_shot_timer.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" |
| 24 #include "ipc/ipc_message.h" | 27 #include "ipc/ipc_message.h" |
| 25 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 if (!frame->parent()) | 63 if (!frame->parent()) |
| 61 return NetErrorHelperCore::MAIN_FRAME; | 64 return NetErrorHelperCore::MAIN_FRAME; |
| 62 return NetErrorHelperCore::SUB_FRAME; | 65 return NetErrorHelperCore::SUB_FRAME; |
| 63 } | 66 } |
| 64 | 67 |
| 65 } // namespace | 68 } // namespace |
| 66 | 69 |
| 67 NetErrorHelper::NetErrorHelper(RenderFrame* render_view) | 70 NetErrorHelper::NetErrorHelper(RenderFrame* render_view) |
| 68 : RenderFrameObserver(render_view), | 71 : RenderFrameObserver(render_view), |
| 69 content::RenderFrameObserverTracker<NetErrorHelper>(render_view), | 72 content::RenderFrameObserverTracker<NetErrorHelper>(render_view), |
| 70 core_(this) { | 73 core_(this, |
| 74 scoped_ptr<MockableOneShotTimer>(new MockableOneShotTimer())) { | |
|
mmenke
2014/03/11 20:07:54
Optional: I think it's a little cleaner to to rem
Elly Fong-Jones
2014/03/12 15:08:58
Done.
| |
| 75 RenderThread::Get()->AddObserver(this); | |
| 76 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 77 bool auto_reload_enabled = | |
| 78 command_line->HasSwitch(switches::kEnableOfflineAutoReload); | |
| 79 core_.set_auto_reload_enabled(auto_reload_enabled); | |
| 71 } | 80 } |
| 72 | 81 |
| 73 NetErrorHelper::~NetErrorHelper() { | 82 NetErrorHelper::~NetErrorHelper() { |
| 83 RenderThread::Get()->RemoveObserver(this); | |
| 74 } | 84 } |
| 75 | 85 |
| 76 void NetErrorHelper::DidStartProvisionalLoad() { | 86 void NetErrorHelper::DidStartProvisionalLoad() { |
| 77 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 87 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 78 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); | 88 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); |
| 79 } | 89 } |
| 80 | 90 |
| 81 void NetErrorHelper::DidCommitProvisionalLoad(bool is_new_navigation) { | 91 void NetErrorHelper::DidCommitProvisionalLoad(bool is_new_navigation) { |
| 82 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 92 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 83 core_.OnCommitLoad(GetFrameType(frame)); | 93 core_.OnCommitLoad(GetFrameType(frame)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 97 | 107 |
| 98 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) | 108 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) |
| 99 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) | 109 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) |
| 100 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL); | 110 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL); |
| 101 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
| 102 IPC_END_MESSAGE_MAP() | 112 IPC_END_MESSAGE_MAP() |
| 103 | 113 |
| 104 return handled; | 114 return handled; |
| 105 } | 115 } |
| 106 | 116 |
| 117 void NetErrorHelper::NetworkStateChanged(bool enabled) { | |
| 118 core_.NetworkStateChanged(enabled); | |
| 119 } | |
| 120 | |
| 107 void NetErrorHelper::GetErrorHTML( | 121 void NetErrorHelper::GetErrorHTML( |
| 108 blink::WebFrame* frame, | 122 blink::WebFrame* frame, |
| 109 const blink::WebURLError& error, | 123 const blink::WebURLError& error, |
| 110 bool is_failed_post, | 124 bool is_failed_post, |
| 111 std::string* error_html) { | 125 std::string* error_html) { |
| 112 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html); | 126 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html); |
| 113 } | 127 } |
| 114 | 128 |
| 129 bool NetErrorHelper::ShouldSuppressErrorPage(blink::WebFrame* frame, | |
| 130 const GURL& url) { | |
| 131 return core_.ShouldSuppressErrorPage(GetFrameType(frame), url); | |
| 132 } | |
| 133 | |
| 115 void NetErrorHelper::GenerateLocalizedErrorPage(const blink::WebURLError& error, | 134 void NetErrorHelper::GenerateLocalizedErrorPage(const blink::WebURLError& error, |
| 116 bool is_failed_post, | 135 bool is_failed_post, |
| 117 std::string* error_html) const { | 136 std::string* error_html) const { |
| 118 error_html->clear(); | 137 error_html->clear(); |
| 119 | 138 |
| 120 int resource_id = IDR_NET_ERROR_HTML; | 139 int resource_id = IDR_NET_ERROR_HTML; |
| 121 const base::StringPiece template_html( | 140 const base::StringPiece template_html( |
| 122 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 141 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 123 if (template_html.empty()) { | 142 if (template_html.empty()) { |
| 124 NOTREACHED() << "unable to load template."; | 143 NOTREACHED() << "unable to load template."; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 base::Unretained(this))); | 208 base::Unretained(this))); |
| 190 | 209 |
| 191 alt_error_page_fetcher_->SetTimeout( | 210 alt_error_page_fetcher_->SetTimeout( |
| 192 base::TimeDelta::FromSeconds(kAlterErrorPageFetchTimeoutSec)); | 211 base::TimeDelta::FromSeconds(kAlterErrorPageFetchTimeoutSec)); |
| 193 } | 212 } |
| 194 | 213 |
| 195 void NetErrorHelper::CancelFetchErrorPage() { | 214 void NetErrorHelper::CancelFetchErrorPage() { |
| 196 alt_error_page_fetcher_.reset(); | 215 alt_error_page_fetcher_.reset(); |
| 197 } | 216 } |
| 198 | 217 |
| 218 void NetErrorHelper::ReloadPage() { | |
| 219 render_frame()->GetWebFrame()->reload(false); | |
| 220 } | |
| 221 | |
| 199 void NetErrorHelper::OnNetErrorInfo(int status_num) { | 222 void NetErrorHelper::OnNetErrorInfo(int status_num) { |
| 200 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); | 223 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); |
| 201 | 224 |
| 202 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); | 225 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); |
| 203 | 226 |
| 204 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); | 227 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); |
| 205 } | 228 } |
| 206 | 229 |
| 207 void NetErrorHelper::OnSetAltErrorPageURL(const GURL& alt_error_page_url) { | 230 void NetErrorHelper::OnSetAltErrorPageURL(const GURL& alt_error_page_url) { |
| 208 core_.set_alt_error_page_url(alt_error_page_url); | 231 core_.set_alt_error_page_url(alt_error_page_url); |
| 209 } | 232 } |
| 210 | 233 |
| 211 void NetErrorHelper::OnAlternateErrorPageRetrieved( | 234 void NetErrorHelper::OnAlternateErrorPageRetrieved( |
| 212 const blink::WebURLResponse& response, | 235 const blink::WebURLResponse& response, |
| 213 const std::string& data) { | 236 const std::string& data) { |
| 214 // The fetcher may only be deleted after |data| is passed to |core_|. Move | 237 // The fetcher may only be deleted after |data| is passed to |core_|. Move |
| 215 // it to a temporary to prevent any potential re-entrancy issues. | 238 // it to a temporary to prevent any potential re-entrancy issues. |
| 216 scoped_ptr<content::ResourceFetcher> fetcher( | 239 scoped_ptr<content::ResourceFetcher> fetcher( |
| 217 alt_error_page_fetcher_.release()); | 240 alt_error_page_fetcher_.release()); |
| 218 if (!response.isNull() && response.httpStatusCode() == 200) { | 241 if (!response.isNull() && response.httpStatusCode() == 200) { |
| 219 core_.OnAlternateErrorPageFetched(data); | 242 core_.OnAlternateErrorPageFetched(data); |
| 220 } else { | 243 } else { |
| 221 core_.OnAlternateErrorPageFetched(""); | 244 core_.OnAlternateErrorPageFetched(""); |
| 222 } | 245 } |
| 223 } | 246 } |
| OLD | NEW |