| 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" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 struct WebURLError; | 16 struct WebURLError; |
| 16 } | 17 } |
| 17 | 18 |
| 18 // Class that contains the logic for how the NetErrorHelper. This allows for | 19 // 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 | 20 // testing the logic without a RenderView or WebFrame, which are difficult to |
| 20 // mock, and for testing races which are impossible to reliably reproduce | 21 // mock, and for testing races which are impossible to reliably reproduce |
| 21 // with real RenderViews or WebFrames. | 22 // with real RenderViews or WebFrames. |
| 22 class NetErrorHelperCore { | 23 class NetErrorHelperCore { |
| 23 public: | 24 public: |
| 24 enum FrameType { | 25 enum FrameType { |
| 25 MAIN_FRAME, | 26 MAIN_FRAME, |
| 26 SUB_FRAME, | 27 SUB_FRAME, |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 enum PageType { | 30 enum PageType { |
| 30 NON_ERROR_PAGE, | 31 NON_ERROR_PAGE, |
| 31 ERROR_PAGE, | 32 ERROR_PAGE, |
| 32 }; | 33 }; |
| 33 | 34 |
| 35 class MockableOneShotTimer { |
| 36 public: |
| 37 virtual void Start(const tracked_objects::Location& posted_from, |
| 38 base::TimeDelta delay, |
| 39 const base::Closure& user_task) = 0; |
| 40 virtual void Stop() = 0; |
| 41 virtual bool IsRunning() const = 0; |
| 42 }; |
| 43 |
| 34 // The Delegate handles all interaction with the RenderView, WebFrame, and | 44 // The Delegate handles all interaction with the RenderView, WebFrame, and |
| 35 // the network, as well as the generation of error pages. | 45 // the network, as well as the generation of error pages. |
| 36 class Delegate { | 46 class Delegate { |
| 37 public: | 47 public: |
| 38 // Generates an error page's HTML for the given error. | 48 // Generates an error page's HTML for the given error. |
| 39 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error, | 49 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error, |
| 40 bool is_failed_post, | 50 bool is_failed_post, |
| 41 std::string* html) const = 0; | 51 std::string* html) const = 0; |
| 42 | 52 |
| 43 // Loads the given HTML in the main frame for use as an error page. | 53 // Loads the given HTML in the main frame for use as an error page. |
| 44 virtual void LoadErrorPageInMainFrame(const std::string& html, | 54 virtual void LoadErrorPageInMainFrame(const std::string& html, |
| 45 const GURL& failed_url) = 0; | 55 const GURL& failed_url) = 0; |
| 46 | 56 |
| 47 // Updates the currently displayed error page with a new error code. The | 57 // Updates the currently displayed error page with a new error code. The |
| 48 // currently displayed error page must have finished loading, and must have | 58 // currently displayed error page must have finished loading, and must have |
| 49 // been generated by a call to GenerateLocalizedErrorPage. | 59 // been generated by a call to GenerateLocalizedErrorPage. |
| 50 virtual void UpdateErrorPage(const blink::WebURLError& error, | 60 virtual void UpdateErrorPage(const blink::WebURLError& error, |
| 51 bool is_failed_post) = 0; | 61 bool is_failed_post) = 0; |
| 52 | 62 |
| 53 // Fetches an error page and calls into OnErrorPageFetched when done. Any | 63 // Fetches an error page and calls into OnErrorPageFetched when done. Any |
| 54 // previous fetch must either be canceled or finished before calling. Can't | 64 // previous fetch must either be canceled or finished before calling. Can't |
| 55 // be called synchronously after a previous fetch completes. | 65 // be called synchronously after a previous fetch completes. |
| 56 virtual void FetchErrorPage(const GURL& url) = 0; | 66 virtual void FetchErrorPage(const GURL& url) = 0; |
| 57 | 67 |
| 58 // Cancels an error page fetch. Does nothing if no fetch is ongoing. | 68 // Cancels an error page fetch. Does nothing if no fetch is ongoing. |
| 59 virtual void CancelFetchErrorPage() = 0; | 69 virtual void CancelFetchErrorPage() = 0; |
| 60 | 70 |
| 71 // Starts a fetch of |url| for autoreload. |
| 72 virtual void FetchAutoReloadPage(const GURL& url) = 0; |
| 73 |
| 74 // Cancels an autoreload fetch. |
| 75 virtual void CancelFetchAutoReloadPage() = 0; |
| 76 |
| 77 // Allocates a new MockableOneShotTimer. |
| 78 virtual MockableOneShotTimer* NewMockableOneShotTimer() = 0; |
| 79 |
| 61 protected: | 80 protected: |
| 62 virtual ~Delegate() {} | 81 virtual ~Delegate() {} |
| 63 }; | 82 }; |
| 64 | 83 |
| 65 explicit NetErrorHelperCore(Delegate* delegate); | 84 explicit NetErrorHelperCore(Delegate* delegate); |
| 66 ~NetErrorHelperCore(); | 85 ~NetErrorHelperCore(); |
| 67 | 86 |
| 68 // Examines |frame| and |error| to see if this is an error worthy of a DNS | 87 // 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|, | 88 // probe. If it is, initializes |error_strings| based on |error|, |
| 70 // |is_failed_post|, and |locale| with suitable strings and returns true. | 89 // |is_failed_post|, and |locale| with suitable strings and returns true. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 89 void OnAlternateErrorPageFetched(const std::string& html); | 108 void OnAlternateErrorPageFetched(const std::string& html); |
| 90 | 109 |
| 91 // Notifies |this| that network error information from the browser process | 110 // Notifies |this| that network error information from the browser process |
| 92 // has been received. | 111 // has been received. |
| 93 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); | 112 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status); |
| 94 | 113 |
| 95 void set_alt_error_page_url(const GURL& alt_error_page_url) { | 114 void set_alt_error_page_url(const GURL& alt_error_page_url) { |
| 96 alt_error_page_url_ = alt_error_page_url; | 115 alt_error_page_url_ = alt_error_page_url; |
| 97 } | 116 } |
| 98 | 117 |
| 118 void set_auto_reload_enabled(bool auto_reload_enabled) { |
| 119 auto_reload_enabled_ = auto_reload_enabled; |
| 120 } |
| 121 |
| 122 virtual void StartAutoReload(); |
| 123 virtual bool IsAutoReloading() const; |
| 124 |
| 99 private: | 125 private: |
| 100 struct ErrorPageInfo; | 126 struct ErrorPageInfo; |
| 101 | 127 |
| 102 // Updates the currently displayed error page with a new error based on the | 128 // 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 | 129 // most recently received DNS probe result. The page must have finished |
| 104 // loading before this is called. | 130 // loading before this is called. |
| 105 void UpdateErrorPage(); | 131 void UpdateErrorPage(); |
| 106 | 132 |
| 107 void GenerateLocalErrorPage( | 133 void GenerateLocalErrorPage( |
| 108 FrameType frame_type, | 134 FrameType frame_type, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 119 | 145 |
| 120 // Information for the provisional / "pre-provisional" error page. NULL when | 146 // 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. | 147 // there's no page pending, or the pending page is not an error page. |
| 122 scoped_ptr<ErrorPageInfo> pending_error_page_info_; | 148 scoped_ptr<ErrorPageInfo> pending_error_page_info_; |
| 123 | 149 |
| 124 // Information for the committed error page. NULL when the committed page is | 150 // Information for the committed error page. NULL when the committed page is |
| 125 // not an error page. | 151 // not an error page. |
| 126 scoped_ptr<ErrorPageInfo> committed_error_page_info_; | 152 scoped_ptr<ErrorPageInfo> committed_error_page_info_; |
| 127 | 153 |
| 128 GURL alt_error_page_url_; | 154 GURL alt_error_page_url_; |
| 155 |
| 156 bool auto_reload_enabled_; |
| 157 scoped_ptr<MockableOneShotTimer> auto_reload_timer_; |
| 158 int auto_reload_count_; |
| 159 |
| 160 void AutoReload(); |
| 129 }; | 161 }; |
| 130 | 162 |
| 131 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ | 163 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_ |
| OLD | NEW |