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

Side by Side Diff: chrome/renderer/net/net_error_helper_core.h

Issue 136203009: Support auto-reload on errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fixes Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 5 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "chrome/common/net/net_error_info.h" 12 #include "chrome/common/net/net_error_info.h"
13 #include "chrome/renderer/net/mockable_one_shot_timer.h"
12 #include "url/gurl.h" 14 #include "url/gurl.h"
13 15
14 namespace blink { 16 namespace blink {
15 struct WebURLError; 17 struct WebURLError;
16 } 18 }
17 19
18 // Class that contains the logic for how the NetErrorHelper. This allows for 20 // Class that contains the logic for how the NetErrorHelper. This allows for
19 // testing the logic without a RenderView or WebFrame, which are difficult to 21 // testing the logic without a RenderView or WebFrame, which are difficult to
20 // mock, and for testing races which are impossible to reliably reproduce 22 // mock, and for testing races which are impossible to reliably reproduce
21 // with real RenderViews or WebFrames. 23 // with real RenderViews or WebFrames.
(...skipping 29 matching lines...) Expand all
51 bool is_failed_post) = 0; 53 bool is_failed_post) = 0;
52 54
53 // Fetches an error page and calls into OnErrorPageFetched when done. Any 55 // Fetches an error page and calls into OnErrorPageFetched when done. Any
54 // previous fetch must either be canceled or finished before calling. Can't 56 // previous fetch must either be canceled or finished before calling. Can't
55 // be called synchronously after a previous fetch completes. 57 // be called synchronously after a previous fetch completes.
56 virtual void FetchErrorPage(const GURL& url) = 0; 58 virtual void FetchErrorPage(const GURL& url) = 0;
57 59
58 // Cancels an error page fetch. Does nothing if no fetch is ongoing. 60 // Cancels an error page fetch. Does nothing if no fetch is ongoing.
59 virtual void CancelFetchErrorPage() = 0; 61 virtual void CancelFetchErrorPage() = 0;
60 62
63 // Starts a reload of the page in the observed frame.
64 virtual void ReloadPage() = 0;
65
61 protected: 66 protected:
62 virtual ~Delegate() {} 67 virtual ~Delegate() {}
63 }; 68 };
64 69
65 explicit NetErrorHelperCore(Delegate* delegate); 70 NetErrorHelperCore(Delegate* delegate);
66 ~NetErrorHelperCore(); 71 ~NetErrorHelperCore();
67 72
68 // Examines |frame| and |error| to see if this is an error worthy of a DNS 73 // Examines |frame| and |error| to see if this is an error worthy of a DNS
69 // probe. If it is, initializes |error_strings| based on |error|, 74 // probe. If it is, initializes |error_strings| based on |error|,
70 // |is_failed_post|, and |locale| with suitable strings and returns true. 75 // |is_failed_post|, and |locale| with suitable strings and returns true.
71 // If not, returns false, in which case the caller should look up error 76 // If not, returns false, in which case the caller should look up error
72 // strings directly using LocalizedError::GetNavigationErrorStrings. 77 // strings directly using LocalizedError::GetNavigationErrorStrings.
73 // 78 //
74 // Updates the NetErrorHelper with the assumption the page will be loaded 79 // Updates the NetErrorHelper with the assumption the page will be loaded
75 // immediately. 80 // immediately.
76 void GetErrorHTML(FrameType frame_type, 81 void GetErrorHTML(FrameType frame_type,
77 const blink::WebURLError& error, 82 const blink::WebURLError& error,
78 bool is_failed_post, 83 bool is_failed_post,
79 std::string* error_html); 84 std::string* error_html);
80 85
81 // These methods handle tracking the actual state of the page. 86 // These methods handle tracking the actual state of the page.
82 void OnStartLoad(FrameType frame_type, PageType page_type); 87 void OnStartLoad(FrameType frame_type, PageType page_type);
83 void OnCommitLoad(FrameType frame_type); 88 void OnCommitLoad(FrameType frame_type);
84 void OnFinishLoad(FrameType frame_type); 89 void OnFinishLoad(FrameType frame_type);
85 void OnStop(); 90 void OnStop();
86 91
92 void CancelPendingFetches();
93
87 // Called when an error page have has been retrieved over the network. |html| 94 // Called when an error page have has been retrieved over the network. |html|
88 // must be an empty string on error. 95 // must be an empty string on error.
89 void OnAlternateErrorPageFetched(const std::string& html); 96 void OnAlternateErrorPageFetched(const std::string& html);
90 97
91 // Notifies |this| that network error information from the browser process 98 // Notifies |this| that network error information from the browser process
92 // has been received. 99 // has been received.
93 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); 100 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status);
94 101
102 // Notifies |this| that the network's online status changed.
103 // Handler for NetworkStateChanged notification from the browser process. If
104 // the network state changes to online, this method is responsible for
105 // starting the auto-reload process.
106 //
107 // Warning: if there are many tabs sitting at an error page, this handler will
108 // be run at the same time for each of their top-level renderframes, which can
109 // cause many requests to be started at the same time. There's no current
110 // protection against this kind of "reload storm".
111 //
112 // TODO(rdsmith): prevent the reload storm.
113 void NetworkStateChanged(bool online);
114
95 void set_alt_error_page_url(const GURL& alt_error_page_url) { 115 void set_alt_error_page_url(const GURL& alt_error_page_url) {
96 alt_error_page_url_ = alt_error_page_url; 116 alt_error_page_url_ = alt_error_page_url;
97 } 117 }
98 118
119 void set_auto_reload_enabled(bool auto_reload_enabled) {
120 auto_reload_enabled_ = auto_reload_enabled;
121 }
122
123 int auto_reload_count() const { return auto_reload_count_; }
124
125 bool ShouldSuppressErrorPage(FrameType frame_type, const GURL& url);
126
127 void set_timer_for_testing(scoped_ptr<MockableOneShotTimer> timer) {
128 auto_reload_timer_.reset(timer.release());
129 }
130
99 private: 131 private:
100 struct ErrorPageInfo; 132 struct ErrorPageInfo;
101 133
102 // Updates the currently displayed error page with a new error based on the 134 // Updates the currently displayed error page with a new error based on the
103 // most recently received DNS probe result. The page must have finished 135 // most recently received DNS probe result. The page must have finished
104 // loading before this is called. 136 // loading before this is called.
105 void UpdateErrorPage(); 137 void UpdateErrorPage();
106 138
107 void GenerateLocalErrorPage( 139 void GenerateLocalErrorPage(
108 FrameType frame_type, 140 FrameType frame_type,
109 const blink::WebURLError& error, 141 const blink::WebURLError& error,
110 bool is_failed_post, 142 bool is_failed_post,
111 std::string* error_html); 143 std::string* error_html);
112 144
113 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; 145 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const;
114 146
147 void Reload();
148 bool MaybeStartAutoReloadTimer();
149 void StartAutoReloadTimer();
150
151 static bool IsReloadableError(const ErrorPageInfo& info);
152
115 Delegate* delegate_; 153 Delegate* delegate_;
116 154
117 // The last DnsProbeStatus received from the browser. 155 // The last DnsProbeStatus received from the browser.
118 chrome_common_net::DnsProbeStatus last_probe_status_; 156 chrome_common_net::DnsProbeStatus last_probe_status_;
119 157
120 // Information for the provisional / "pre-provisional" error page. NULL when 158 // Information for the provisional / "pre-provisional" error page. NULL when
121 // there's no page pending, or the pending page is not an error page. 159 // there's no page pending, or the pending page is not an error page.
122 scoped_ptr<ErrorPageInfo> pending_error_page_info_; 160 scoped_ptr<ErrorPageInfo> pending_error_page_info_;
123 161
124 // Information for the committed error page. NULL when the committed page is 162 // Information for the committed error page. NULL when the committed page is
125 // not an error page. 163 // not an error page.
126 scoped_ptr<ErrorPageInfo> committed_error_page_info_; 164 scoped_ptr<ErrorPageInfo> committed_error_page_info_;
127 165
128 GURL alt_error_page_url_; 166 GURL alt_error_page_url_;
167
168 bool auto_reload_enabled_;
169 scoped_ptr<MockableOneShotTimer> auto_reload_timer_;
170
171 // Is the browser online?
172 bool online_;
173
174 int auto_reload_count_;
175 bool can_auto_reload_page_;
129 }; 176 };
130 177
131 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 178 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698