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

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: More 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,
71 scoped_ptr<MockableOneShotTimer> reload_timer);
66 ~NetErrorHelperCore(); 72 ~NetErrorHelperCore();
67 73
68 // Examines |frame| and |error| to see if this is an error worthy of a DNS 74 // 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|, 75 // probe. If it is, initializes |error_strings| based on |error|,
70 // |is_failed_post|, and |locale| with suitable strings and returns true. 76 // |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 77 // If not, returns false, in which case the caller should look up error
72 // strings directly using LocalizedError::GetNavigationErrorStrings. 78 // strings directly using LocalizedError::GetNavigationErrorStrings.
73 // 79 //
74 // Updates the NetErrorHelper with the assumption the page will be loaded 80 // Updates the NetErrorHelper with the assumption the page will be loaded
75 // immediately. 81 // immediately.
76 void GetErrorHTML(FrameType frame_type, 82 void GetErrorHTML(FrameType frame_type,
77 const blink::WebURLError& error, 83 const blink::WebURLError& error,
78 bool is_failed_post, 84 bool is_failed_post,
79 std::string* error_html); 85 std::string* error_html);
80 86
81 // These methods handle tracking the actual state of the page. 87 // These methods handle tracking the actual state of the page.
82 void OnStartLoad(FrameType frame_type, PageType page_type); 88 void OnStartLoad(FrameType frame_type, PageType page_type);
83 void OnCommitLoad(FrameType frame_type); 89 void OnCommitLoad(FrameType frame_type);
84 void OnFinishLoad(FrameType frame_type); 90 void OnFinishLoad(FrameType frame_type);
85 void OnStop(); 91 void OnStop();
86 92
93 void CancelPendingFetches();
94
87 // Called when an error page have has been retrieved over the network. |html| 95 // Called when an error page have has been retrieved over the network. |html|
88 // must be an empty string on error. 96 // must be an empty string on error.
89 void OnAlternateErrorPageFetched(const std::string& html); 97 void OnAlternateErrorPageFetched(const std::string& html);
90 98
91 // Notifies |this| that network error information from the browser process 99 // Notifies |this| that network error information from the browser process
92 // has been received. 100 // has been received.
93 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); 101 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status);
94 102
103 // Notifies |this| that the network's online status changed.
104 void NetworkStateChanged(bool online);
105
95 void set_alt_error_page_url(const GURL& alt_error_page_url) { 106 void set_alt_error_page_url(const GURL& alt_error_page_url) {
96 alt_error_page_url_ = alt_error_page_url; 107 alt_error_page_url_ = alt_error_page_url;
97 } 108 }
98 109
110 void set_auto_reload_enabled(bool auto_reload_enabled) {
111 auto_reload_enabled_ = auto_reload_enabled;
112 }
113
114 int auto_reload_count() const { return auto_reload_count_; }
115
116 bool ShouldSuppressErrorPage(const GURL& url);
117
99 private: 118 private:
100 struct ErrorPageInfo; 119 struct ErrorPageInfo;
101 120
102 // Updates the currently displayed error page with a new error based on the 121 // 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 122 // most recently received DNS probe result. The page must have finished
104 // loading before this is called. 123 // loading before this is called.
105 void UpdateErrorPage(); 124 void UpdateErrorPage();
106 125
107 void GenerateLocalErrorPage( 126 void GenerateLocalErrorPage(
108 FrameType frame_type, 127 FrameType frame_type,
109 const blink::WebURLError& error, 128 const blink::WebURLError& error,
110 bool is_failed_post, 129 bool is_failed_post,
111 std::string* error_html); 130 std::string* error_html);
112 131
113 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; 132 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const;
114 133
134 void Reload();
135 bool MaybeStartAutoReloadTimer();
136 void StartAutoReloadTimer();
137
115 Delegate* delegate_; 138 Delegate* delegate_;
116 139
117 // The last DnsProbeStatus received from the browser. 140 // The last DnsProbeStatus received from the browser.
118 chrome_common_net::DnsProbeStatus last_probe_status_; 141 chrome_common_net::DnsProbeStatus last_probe_status_;
119 142
120 // Information for the provisional / "pre-provisional" error page. NULL when 143 // 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. 144 // there's no page pending, or the pending page is not an error page.
122 scoped_ptr<ErrorPageInfo> pending_error_page_info_; 145 scoped_ptr<ErrorPageInfo> pending_error_page_info_;
123 146
124 // Information for the committed error page. NULL when the committed page is 147 // Information for the committed error page. NULL when the committed page is
125 // not an error page. 148 // not an error page.
126 scoped_ptr<ErrorPageInfo> committed_error_page_info_; 149 scoped_ptr<ErrorPageInfo> committed_error_page_info_;
127 150
128 GURL alt_error_page_url_; 151 GURL alt_error_page_url_;
152
153 bool auto_reload_enabled_;
154 scoped_ptr<MockableOneShotTimer> auto_reload_timer_;
155
156 // Number of times we've kicked off |auto_reload_timer_|.
157 int auto_reload_count_;
158
159 // Is there a page we are trying to auto-reload?
160 bool auto_reload_pending_;
mmenke 2014/03/04 17:26:25 Think this variable is confusing. Maybe can_auto_
Elly Fong-Jones 2014/03/06 21:48:37 Done.
161
162 // Is the browser online?
163 bool online_;
129 }; 164 };
130 165
131 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ 166 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698