Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: chrome/renderer/net/net_error_helper.cc

Issue 136203009: Support auto-reload on errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add experiment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/common/localized_error.h" 13 #include "chrome/common/localized_error.h"
14 #include "chrome/common/net/net_error_info.h" 14 #include "chrome/common/net/net_error_info.h"
15 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
16 #include "chrome/renderer/net/mockable_one_shot_timer.h"
16 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
17 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
18 #include "content/public/renderer/content_renderer_client.h" 19 #include "content/public/renderer/content_renderer_client.h"
19 #include "content/public/renderer/render_frame.h" 20 #include "content/public/renderer/render_frame.h"
20 #include "content/public/renderer/render_thread.h" 21 #include "content/public/renderer/render_thread.h"
21 #include "content/public/renderer/render_view.h" 22 #include "content/public/renderer/render_view.h"
22 #include "content/public/renderer/resource_fetcher.h" 23 #include "content/public/renderer/resource_fetcher.h"
23 #include "grit/renderer_resources.h" 24 #include "grit/renderer_resources.h"
24 #include "ipc/ipc_message.h" 25 #include "ipc/ipc_message.h"
25 #include "ipc/ipc_message_macros.h" 26 #include "ipc/ipc_message_macros.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 58 }
58 59
59 NetErrorHelperCore::FrameType GetFrameType(const blink::WebFrame* frame) { 60 NetErrorHelperCore::FrameType GetFrameType(const blink::WebFrame* frame) {
60 if (!frame->parent()) 61 if (!frame->parent())
61 return NetErrorHelperCore::MAIN_FRAME; 62 return NetErrorHelperCore::MAIN_FRAME;
62 return NetErrorHelperCore::SUB_FRAME; 63 return NetErrorHelperCore::SUB_FRAME;
63 } 64 }
64 65
65 } // namespace 66 } // namespace
66 67
67 NetErrorHelper::NetErrorHelper(RenderFrame* render_view) 68 NetErrorHelper::NetErrorHelper(RenderFrame* render_view,
69 bool auto_reload_enabled)
68 : RenderFrameObserver(render_view), 70 : RenderFrameObserver(render_view),
69 content::RenderFrameObserverTracker<NetErrorHelper>(render_view), 71 content::RenderFrameObserverTracker<NetErrorHelper>(render_view),
70 core_(this) { 72 core_(this,
73 scoped_ptr<MockableOneShotTimer>(new MockableOneShotTimer())) {
74 core_.set_auto_reload_enabled(auto_reload_enabled);
Randy Smith (Not in Mondays) 2014/02/26 00:07:38 See earlier comment; why not directly into the con
Elly Fong-Jones 2014/03/03 19:31:07 so test fixtures can construct the NetErrorHelperC
71 } 75 }
72 76
73 NetErrorHelper::~NetErrorHelper() { 77 NetErrorHelper::~NetErrorHelper() {
74 } 78 }
75 79
76 void NetErrorHelper::DidStartProvisionalLoad() { 80 void NetErrorHelper::DidStartProvisionalLoad() {
77 blink::WebFrame* frame = render_frame()->GetWebFrame(); 81 blink::WebFrame* frame = render_frame()->GetWebFrame();
78 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame)); 82 core_.OnStartLoad(GetFrameType(frame), GetLoadingPageType(frame));
79 } 83 }
80 84
(...skipping 16 matching lines...) Expand all
97 101
98 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message) 102 IPC_BEGIN_MESSAGE_MAP(NetErrorHelper, message)
99 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo) 103 IPC_MESSAGE_HANDLER(ChromeViewMsg_NetErrorInfo, OnNetErrorInfo)
100 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL); 104 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL);
101 IPC_MESSAGE_UNHANDLED(handled = false) 105 IPC_MESSAGE_UNHANDLED(handled = false)
102 IPC_END_MESSAGE_MAP() 106 IPC_END_MESSAGE_MAP()
103 107
104 return handled; 108 return handled;
105 } 109 }
106 110
111 void NetErrorHelper::NetworkStateChanged(bool enabled) {
112 core_.NetworkStateChanged(enabled);
113 }
114
107 void NetErrorHelper::GetErrorHTML( 115 void NetErrorHelper::GetErrorHTML(
108 blink::WebFrame* frame, 116 blink::WebFrame* frame,
109 const blink::WebURLError& error, 117 const blink::WebURLError& error,
110 bool is_failed_post, 118 bool is_failed_post,
111 std::string* error_html) { 119 std::string* error_html) {
112 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html); 120 core_.GetErrorHTML(GetFrameType(frame), error, is_failed_post, error_html);
113 } 121 }
114 122
123 bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) {
124 return core_.ShouldSuppressErrorPage(url);
125 }
126
115 void NetErrorHelper::GenerateLocalizedErrorPage(const blink::WebURLError& error, 127 void NetErrorHelper::GenerateLocalizedErrorPage(const blink::WebURLError& error,
116 bool is_failed_post, 128 bool is_failed_post,
117 std::string* error_html) const { 129 std::string* error_html) const {
118 error_html->clear(); 130 error_html->clear();
119 131
120 int resource_id = IDR_NET_ERROR_HTML; 132 int resource_id = IDR_NET_ERROR_HTML;
121 const base::StringPiece template_html( 133 const base::StringPiece template_html(
122 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); 134 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id));
123 if (template_html.empty()) { 135 if (template_html.empty()) {
124 NOTREACHED() << "unable to load template."; 136 NOTREACHED() << "unable to load template.";
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 base::Unretained(this))); 199 base::Unretained(this)));
188 200
189 alt_error_page_fetcher_->SetTimeout( 201 alt_error_page_fetcher_->SetTimeout(
190 base::TimeDelta::FromSeconds(kAlterErrorPageFetchTimeoutSec)); 202 base::TimeDelta::FromSeconds(kAlterErrorPageFetchTimeoutSec));
191 } 203 }
192 204
193 void NetErrorHelper::CancelFetchErrorPage() { 205 void NetErrorHelper::CancelFetchErrorPage() {
194 alt_error_page_fetcher_.reset(); 206 alt_error_page_fetcher_.reset();
195 } 207 }
196 208
209 void NetErrorHelper::ReloadPage() {
210 render_frame()->GetWebFrame()->reload(false);
211 }
212
197 void NetErrorHelper::OnNetErrorInfo(int status_num) { 213 void NetErrorHelper::OnNetErrorInfo(int status_num) {
198 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX); 214 DCHECK(status_num >= 0 && status_num < chrome_common_net::DNS_PROBE_MAX);
199 215
200 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num); 216 DVLOG(1) << "Received status " << DnsProbeStatusToString(status_num);
201 217
202 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num)); 218 core_.OnNetErrorInfo(static_cast<DnsProbeStatus>(status_num));
203 } 219 }
204 220
205 void NetErrorHelper::OnSetAltErrorPageURL(const GURL& alt_error_page_url) { 221 void NetErrorHelper::OnSetAltErrorPageURL(const GURL& alt_error_page_url) {
206 core_.set_alt_error_page_url(alt_error_page_url); 222 core_.set_alt_error_page_url(alt_error_page_url);
207 } 223 }
208 224
209 void NetErrorHelper::OnAlternateErrorPageRetrieved( 225 void NetErrorHelper::OnAlternateErrorPageRetrieved(
210 const blink::WebURLResponse& response, 226 const blink::WebURLResponse& response,
211 const std::string& data) { 227 const std::string& data) {
212 // The fetcher may only be deleted after |data| is passed to |core_|. Move 228 // The fetcher may only be deleted after |data| is passed to |core_|. Move
213 // it to a temporary to prevent any potential re-entrancy issues. 229 // it to a temporary to prevent any potential re-entrancy issues.
214 scoped_ptr<content::ResourceFetcher> fetcher( 230 scoped_ptr<content::ResourceFetcher> fetcher(
215 alt_error_page_fetcher_.release()); 231 alt_error_page_fetcher_.release());
216 if (!response.isNull() && response.httpStatusCode() == 200) { 232 if (!response.isNull() && response.httpStatusCode() == 200) {
217 core_.OnAlternateErrorPageFetched(data); 233 core_.OnAlternateErrorPageFetched(data);
218 } else { 234 } else {
219 core_.OnAlternateErrorPageFetched(""); 235 core_.OnAlternateErrorPageFetched("");
220 } 236 }
221 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698