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/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "chrome/common/localized_error.h" | |
15 #include "chrome/common/net/net_error_info.h" | 14 #include "chrome/common/net/net_error_info.h" |
16 #include "url/gurl.h" | 15 #include "url/gurl.h" |
17 | 16 |
18 namespace base { | |
19 class ListValue; | |
20 } | |
21 | |
22 namespace blink { | 17 namespace blink { |
23 struct WebURLError; | 18 struct WebURLError; |
24 } | 19 } |
25 | 20 |
26 // Class that contains the logic for how the NetErrorHelper. This allows for | 21 // Class that contains the logic for how the NetErrorHelper. This allows for |
27 // testing the logic without a RenderView or WebFrame, which are difficult to | 22 // testing the logic without a RenderView or WebFrame, which are difficult to |
28 // mock, and for testing races which are impossible to reliably reproduce | 23 // mock, and for testing races which are impossible to reliably reproduce |
29 // with real RenderViews or WebFrames. | 24 // with real RenderViews or WebFrames. |
30 class NetErrorHelperCore { | 25 class NetErrorHelperCore { |
31 public: | 26 public: |
32 enum FrameType { | 27 enum FrameType { |
33 MAIN_FRAME, | 28 MAIN_FRAME, |
34 SUB_FRAME, | 29 SUB_FRAME, |
35 }; | 30 }; |
36 | 31 |
37 enum PageType { | 32 enum PageType { |
38 NON_ERROR_PAGE, | 33 NON_ERROR_PAGE, |
39 ERROR_PAGE, | 34 ERROR_PAGE, |
40 }; | 35 }; |
41 | 36 |
42 // The Delegate handles all interaction with the RenderView, WebFrame, and | 37 // The Delegate handles all interaction with the RenderView, WebFrame, and |
43 // the network, as well as the generation of error pages. | 38 // the network, as well as the generation of error pages. |
44 class Delegate { | 39 class Delegate { |
45 public: | 40 public: |
46 // Generates an error page's HTML for the given error. | 41 // Generates an error page's HTML for the given error. |
47 virtual void GenerateLocalizedErrorPage( | 42 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error, |
48 const blink::WebURLError& error, | 43 bool is_failed_post, |
49 bool is_failed_post, | 44 std::string* html) const = 0; |
50 scoped_ptr<LocalizedError::ErrorPageParams> params, | |
51 std::string* html) const = 0; | |
52 | 45 |
53 // Loads the given HTML in the main frame for use as an error page. | 46 // Loads the given HTML in the main frame for use as an error page. |
54 virtual void LoadErrorPageInMainFrame(const std::string& html, | 47 virtual void LoadErrorPageInMainFrame(const std::string& html, |
55 const GURL& failed_url) = 0; | 48 const GURL& failed_url) = 0; |
56 | 49 |
57 // Create extra Javascript bindings in the error page. | 50 // Create extra Javascript bindings in the error page. |
58 virtual void EnableStaleLoadBindings(const GURL& page_url) = 0; | 51 virtual void EnableStaleLoadBindings(const GURL& page_url) = 0; |
59 | 52 |
60 // Updates the currently displayed error page with a new error code. The | 53 // Updates the currently displayed error page with a new error code. The |
61 // currently displayed error page must have finished loading, and must have | 54 // currently displayed error page must have finished loading, and must have |
62 // been generated by a call to GenerateLocalizedErrorPage. | 55 // been generated by a call to GenerateLocalizedErrorPage. |
63 virtual void UpdateErrorPage(const blink::WebURLError& error, | 56 virtual void UpdateErrorPage(const blink::WebURLError& error, |
64 bool is_failed_post) = 0; | 57 bool is_failed_post) = 0; |
65 | 58 |
66 // Fetches an error page and calls into OnErrorPageFetched when done. Any | 59 // Fetches an error page and calls into OnErrorPageFetched when done. Any |
67 // previous fetch must either be canceled or finished before calling. Can't | 60 // previous fetch must either be canceled or finished before calling. Can't |
68 // be called synchronously after a previous fetch completes. | 61 // be called synchronously after a previous fetch completes. |
69 virtual void FetchNavigationCorrections( | 62 virtual void FetchErrorPage(const GURL& url) = 0; |
70 const GURL& navigation_correction_url, | |
71 const std::string& navigation_correction_request_body) = 0; | |
72 | 63 |
73 // Cancels fetching navigation corrections. Does nothing if no fetch is | 64 // Cancels an error page fetch. Does nothing if no fetch is ongoing. |
74 // ongoing. | 65 virtual void CancelFetchErrorPage() = 0; |
75 virtual void CancelFetchNavigationCorrections() = 0; | |
76 | 66 |
77 // Starts a reload of the page in the observed frame. | 67 // Starts a reload of the page in the observed frame. |
78 virtual void ReloadPage() = 0; | 68 virtual void ReloadPage() = 0; |
79 | 69 |
80 protected: | 70 protected: |
81 virtual ~Delegate() {} | 71 virtual ~Delegate() {} |
82 }; | 72 }; |
83 | 73 |
84 explicit NetErrorHelperCore(Delegate* delegate); | 74 explicit NetErrorHelperCore(Delegate* delegate); |
85 ~NetErrorHelperCore(); | 75 ~NetErrorHelperCore(); |
(...skipping 14 matching lines...) Expand all Loading... |
100 // These methods handle tracking the actual state of the page. | 90 // These methods handle tracking the actual state of the page. |
101 void OnStartLoad(FrameType frame_type, PageType page_type); | 91 void OnStartLoad(FrameType frame_type, PageType page_type); |
102 void OnCommitLoad(FrameType frame_type); | 92 void OnCommitLoad(FrameType frame_type); |
103 void OnFinishLoad(FrameType frame_type); | 93 void OnFinishLoad(FrameType frame_type); |
104 void OnStop(); | 94 void OnStop(); |
105 | 95 |
106 void CancelPendingFetches(); | 96 void CancelPendingFetches(); |
107 | 97 |
108 // Called when an error page have has been retrieved over the network. |html| | 98 // Called when an error page have has been retrieved over the network. |html| |
109 // must be an empty string on error. | 99 // must be an empty string on error. |
110 void OnNavigationCorrectionsFetched(const std::string& corrections, | 100 void OnAlternateErrorPageFetched(const std::string& html); |
111 const std::string& accept_languages, | |
112 bool is_rtl); | |
113 | 101 |
114 // Notifies |this| that network error information from the browser process | 102 // Notifies |this| that network error information from the browser process |
115 // has been received. | 103 // has been received. |
116 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); | 104 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); |
117 | 105 |
118 void OnSetNavigationCorrectionInfo(const GURL& navigation_correction_url, | 106 void set_alt_error_page_url(const GURL& alt_error_page_url) { |
119 const std::string& language, | 107 alt_error_page_url_ = alt_error_page_url; |
120 const std::string& country_code, | 108 } |
121 const std::string& api_key, | |
122 const GURL& search_url); | |
123 // Notifies |this| that the network's online status changed. | 109 // Notifies |this| that the network's online status changed. |
124 // Handler for NetworkStateChanged notification from the browser process. If | 110 // Handler for NetworkStateChanged notification from the browser process. If |
125 // the network state changes to online, this method is responsible for | 111 // the network state changes to online, this method is responsible for |
126 // starting the auto-reload process. | 112 // starting the auto-reload process. |
127 // | 113 // |
128 // Warning: if there are many tabs sitting at an error page, this handler will | 114 // Warning: if there are many tabs sitting at an error page, this handler will |
129 // be run at the same time for each of their top-level renderframes, which can | 115 // be run at the same time for each of their top-level renderframes, which can |
130 // cause many requests to be started at the same time. There's no current | 116 // cause many requests to be started at the same time. There's no current |
131 // protection against this kind of "reload storm". | 117 // protection against this kind of "reload storm". |
132 // | 118 // |
(...skipping 17 matching lines...) Expand all Loading... |
150 | 136 |
151 // Updates the currently displayed error page with a new error based on the | 137 // Updates the currently displayed error page with a new error based on the |
152 // most recently received DNS probe result. The page must have finished | 138 // most recently received DNS probe result. The page must have finished |
153 // loading before this is called. | 139 // loading before this is called. |
154 void UpdateErrorPage(); | 140 void UpdateErrorPage(); |
155 | 141 |
156 void GenerateLocalErrorPage( | 142 void GenerateLocalErrorPage( |
157 FrameType frame_type, | 143 FrameType frame_type, |
158 const blink::WebURLError& error, | 144 const blink::WebURLError& error, |
159 bool is_failed_post, | 145 bool is_failed_post, |
160 scoped_ptr<LocalizedError::ErrorPageParams> params, | |
161 std::string* error_html); | 146 std::string* error_html); |
162 | 147 |
163 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; | 148 blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const; |
164 | 149 |
165 void Reload(); | 150 void Reload(); |
166 bool MaybeStartAutoReloadTimer(); | 151 bool MaybeStartAutoReloadTimer(); |
167 void StartAutoReloadTimer(); | 152 void StartAutoReloadTimer(); |
168 | 153 |
169 static bool IsReloadableError(const ErrorPageInfo& info); | 154 static bool IsReloadableError(const ErrorPageInfo& info); |
170 | 155 |
171 Delegate* delegate_; | 156 Delegate* delegate_; |
172 | 157 |
173 // The last DnsProbeStatus received from the browser. | 158 // The last DnsProbeStatus received from the browser. |
174 chrome_common_net::DnsProbeStatus last_probe_status_; | 159 chrome_common_net::DnsProbeStatus last_probe_status_; |
175 | 160 |
176 // Information for the provisional / "pre-provisional" error page. NULL when | 161 // Information for the provisional / "pre-provisional" error page. NULL when |
177 // there's no page pending, or the pending page is not an error page. | 162 // there's no page pending, or the pending page is not an error page. |
178 scoped_ptr<ErrorPageInfo> pending_error_page_info_; | 163 scoped_ptr<ErrorPageInfo> pending_error_page_info_; |
179 | 164 |
180 // Information for the committed error page. NULL when the committed page is | 165 // Information for the committed error page. NULL when the committed page is |
181 // not an error page. | 166 // not an error page. |
182 scoped_ptr<ErrorPageInfo> committed_error_page_info_; | 167 scoped_ptr<ErrorPageInfo> committed_error_page_info_; |
183 | 168 |
184 GURL navigation_correction_url_; | 169 GURL alt_error_page_url_; |
185 std::string language_; | |
186 std::string country_code_; | |
187 std::string api_key_; | |
188 GURL search_url_; | |
189 | 170 |
190 bool auto_reload_enabled_; | 171 bool auto_reload_enabled_; |
191 scoped_ptr<base::Timer> auto_reload_timer_; | 172 scoped_ptr<base::Timer> auto_reload_timer_; |
192 | 173 |
193 // Is the browser online? | 174 // Is the browser online? |
194 bool online_; | 175 bool online_; |
195 | 176 |
196 int auto_reload_count_; | 177 int auto_reload_count_; |
197 bool can_auto_reload_page_; | 178 bool can_auto_reload_page_; |
198 }; | 179 }; |
199 | 180 |
200 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ | 181 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ |
OLD | NEW |