OLD | NEW |
---|---|
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 Loading... | |
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 // Handler for NetworkStateChanged notification from the browser process. If | |
105 // the network state changes to online, this method is responsible for | |
106 // starting the auto-reload process. | |
107 // | |
108 // Warning: if there are many tabs sitting at an error page, this handler will | |
109 // be run at the same time for each of their top-level renderframes, which can | |
110 // cause many requests to be started at the same time. There's no current | |
111 // protection against this kind of "reload storm". | |
112 // | |
113 // TODO(rdsmith): prevent the reload storm. | |
114 void NetworkStateChanged(bool online); | |
115 | |
95 void set_alt_error_page_url(const GURL& alt_error_page_url) { | 116 void set_alt_error_page_url(const GURL& alt_error_page_url) { |
96 alt_error_page_url_ = alt_error_page_url; | 117 alt_error_page_url_ = alt_error_page_url; |
97 } | 118 } |
98 | 119 |
120 void set_auto_reload_enabled(bool auto_reload_enabled) { | |
121 auto_reload_enabled_ = auto_reload_enabled; | |
122 } | |
123 | |
124 int GetAutoReloadCount() const; | |
mmenke
2014/03/11 20:07:54
Think you can just rename this to auto_reload_coun
Elly Fong-Jones
2014/03/12 15:08:58
Done.
| |
125 | |
126 bool ShouldSuppressErrorPage(FrameType frame_type, const GURL& url); | |
127 | |
99 private: | 128 private: |
100 struct ErrorPageInfo; | 129 struct ErrorPageInfo; |
101 | 130 |
102 // Updates the currently displayed error page with a new error based on the | 131 // 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 | 132 // most recently received DNS probe result. The page must have finished |
104 // loading before this is called. | 133 // loading before this is called. |
105 void UpdateErrorPage(); | 134 void UpdateErrorPage(); |
106 | 135 |
107 void GenerateLocalErrorPage( | 136 void GenerateLocalErrorPage( |
108 FrameType frame_type, | 137 FrameType frame_type, |
109 const blink::WebURLError& error, | 138 const blink::WebURLError& error, |
110 bool is_failed_post, | 139 bool is_failed_post, |
111 std::string* error_html); | 140 std::string* error_html); |
112 | 141 |
113 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; | 142 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; |
114 | 143 |
144 void Reload(); | |
145 bool MaybeStartAutoReloadTimer(); | |
146 void StartAutoReloadTimer(); | |
147 | |
148 static bool IsReloadableError(const ErrorPageInfo& info); | |
149 | |
115 Delegate* delegate_; | 150 Delegate* delegate_; |
116 | 151 |
117 // The last DnsProbeStatus received from the browser. | 152 // The last DnsProbeStatus received from the browser. |
118 chrome_common_net::DnsProbeStatus last_probe_status_; | 153 chrome_common_net::DnsProbeStatus last_probe_status_; |
119 | 154 |
120 // Information for the provisional / "pre-provisional" error page. NULL when | 155 // 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. | 156 // there's no page pending, or the pending page is not an error page. |
122 scoped_ptr<ErrorPageInfo> pending_error_page_info_; | 157 scoped_ptr<ErrorPageInfo> pending_error_page_info_; |
123 | 158 |
124 // Information for the committed error page. NULL when the committed page is | 159 // Information for the committed error page. NULL when the committed page is |
125 // not an error page. | 160 // not an error page. |
126 scoped_ptr<ErrorPageInfo> committed_error_page_info_; | 161 scoped_ptr<ErrorPageInfo> committed_error_page_info_; |
127 | 162 |
128 GURL alt_error_page_url_; | 163 GURL alt_error_page_url_; |
164 | |
165 bool auto_reload_enabled_; | |
166 scoped_ptr<MockableOneShotTimer> auto_reload_timer_; | |
167 | |
168 // Is the browser online? | |
169 bool online_; | |
170 | |
171 int auto_reload_count_; | |
172 bool can_auto_reload_page_; | |
129 }; | 173 }; |
130 | 174 |
131 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ | 175 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ |
OLD | NEW |