| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_H_ | 5 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ |
| 6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ | 6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "chrome/common/net/net_error_info.h" | 10 #include "chrome/common/net/net_error_info.h" |
| 11 #include "chrome/renderer/net/net_error_helper_core.h" | 11 #include "chrome/renderer/net/net_error_helper_core.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" | 12 #include "content/public/renderer/render_frame_observer.h" |
| 13 #include "content/public/renderer/render_frame_observer_tracker.h" | 13 #include "content/public/renderer/render_frame_observer_tracker.h" |
| 14 #include "content/public/renderer/render_process_observer.h" |
| 14 | 15 |
| 15 class GURL; | 16 class GURL; |
| 17 class MockableOneShotTimer; |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 class ResourceFetcher; | 20 class ResourceFetcher; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace blink { | 23 namespace blink { |
| 22 class WebFrame; | 24 class WebFrame; |
| 23 class WebURLResponse; | 25 class WebURLResponse; |
| 24 struct WebURLError; | 26 struct WebURLError; |
| 25 } | 27 } |
| 26 | 28 |
| 27 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the | 29 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the |
| 28 // browser side and updates the error page with more details (currently, just | 30 // browser side and updates the error page with more details (currently, just |
| 29 // DNS probe results) if/when available. | 31 // DNS probe results) if/when available. |
| 30 class NetErrorHelper | 32 class NetErrorHelper |
| 31 : public content::RenderFrameObserver, | 33 : public content::RenderFrameObserver, |
| 32 public content::RenderFrameObserverTracker<NetErrorHelper>, | 34 public content::RenderFrameObserverTracker<NetErrorHelper>, |
| 35 public content::RenderProcessObserver, |
| 33 public NetErrorHelperCore::Delegate { | 36 public NetErrorHelperCore::Delegate { |
| 34 public: | 37 public: |
| 35 explicit NetErrorHelper(content::RenderFrame* render_view); | 38 explicit NetErrorHelper(content::RenderFrame* render_view, |
| 39 bool auto_reload_enabled); |
| 36 virtual ~NetErrorHelper(); | 40 virtual ~NetErrorHelper(); |
| 37 | 41 |
| 38 // RenderFrameObserver implementation. | 42 // RenderFrameObserver implementation. |
| 39 virtual void DidStartProvisionalLoad() OVERRIDE; | 43 virtual void DidStartProvisionalLoad() OVERRIDE; |
| 40 virtual void DidCommitProvisionalLoad(bool is_new_navigation) OVERRIDE; | 44 virtual void DidCommitProvisionalLoad(bool is_new_navigation) OVERRIDE; |
| 41 virtual void DidFinishLoad() OVERRIDE; | 45 virtual void DidFinishLoad() OVERRIDE; |
| 42 virtual void OnStop() OVERRIDE; | 46 virtual void OnStop() OVERRIDE; |
| 43 | 47 |
| 44 // IPC::Listener implementation. | 48 // IPC::Listener implementation. |
| 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 46 | 50 |
| 51 // RenderProcessObserver implementation. |
| 52 virtual void NetworkStateChanged(bool online) OVERRIDE; |
| 53 |
| 47 // Examines |frame| and |error| to see if this is an error worthy of a DNS | 54 // Examines |frame| and |error| to see if this is an error worthy of a DNS |
| 48 // probe. If it is, initializes |error_strings| based on |error|, | 55 // probe. If it is, initializes |error_strings| based on |error|, |
| 49 // |is_failed_post|, and |locale| with suitable strings and returns true. | 56 // |is_failed_post|, and |locale| with suitable strings and returns true. |
| 50 // If not, returns false, in which case the caller should look up error | 57 // If not, returns false, in which case the caller should look up error |
| 51 // strings directly using LocalizedError::GetNavigationErrorStrings. | 58 // strings directly using LocalizedError::GetNavigationErrorStrings. |
| 52 // | 59 // |
| 53 // Updates the NetErrorHelper with the assumption the page will be loaded | 60 // Updates the NetErrorHelper with the assumption the page will be loaded |
| 54 // immediately. | 61 // immediately. |
| 55 void GetErrorHTML(blink::WebFrame* frame, | 62 void GetErrorHTML(blink::WebFrame* frame, |
| 56 const blink::WebURLError& error, | 63 const blink::WebURLError& error, |
| 57 bool is_failed_post, | 64 bool is_failed_post, |
| 58 std::string* error_html); | 65 std::string* error_html); |
| 59 | 66 |
| 67 // Returns whether a load for |url| should have its error page suppressed. |
| 68 bool ShouldSuppressErrorPage(const GURL& url); |
| 69 |
| 60 private: | 70 private: |
| 61 // NetErrorHelperCore::Delegate implementation: | 71 // NetErrorHelperCore::Delegate implementation: |
| 62 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error, | 72 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error, |
| 63 bool is_failed_post, | 73 bool is_failed_post, |
| 64 std::string* html) const OVERRIDE; | 74 std::string* html) const OVERRIDE; |
| 65 virtual void LoadErrorPageInMainFrame(const std::string& html, | 75 virtual void LoadErrorPageInMainFrame(const std::string& html, |
| 66 const GURL& failed_url) OVERRIDE; | 76 const GURL& failed_url) OVERRIDE; |
| 67 virtual void UpdateErrorPage(const blink::WebURLError& error, | 77 virtual void UpdateErrorPage(const blink::WebURLError& error, |
| 68 bool is_failed_post) OVERRIDE; | 78 bool is_failed_post) OVERRIDE; |
| 69 virtual void FetchErrorPage(const GURL& url) OVERRIDE; | 79 virtual void FetchErrorPage(const GURL& url) OVERRIDE; |
| 70 virtual void CancelFetchErrorPage() OVERRIDE; | 80 virtual void CancelFetchErrorPage() OVERRIDE; |
| 81 virtual void ReloadPage() OVERRIDE; |
| 71 | 82 |
| 72 void OnNetErrorInfo(int status); | 83 void OnNetErrorInfo(int status); |
| 73 void OnSetAltErrorPageURL(const GURL& alternate_error_page_url); | 84 void OnSetAltErrorPageURL(const GURL& alternate_error_page_url); |
| 74 | 85 |
| 75 void OnAlternateErrorPageRetrieved(const blink::WebURLResponse& response, | 86 void OnAlternateErrorPageRetrieved(const blink::WebURLResponse& response, |
| 76 const std::string& data); | 87 const std::string& data); |
| 77 | 88 |
| 78 scoped_ptr<content::ResourceFetcher> alt_error_page_fetcher_; | 89 scoped_ptr<content::ResourceFetcher> alt_error_page_fetcher_; |
| 79 | 90 |
| 80 NetErrorHelperCore core_; | 91 NetErrorHelperCore core_; |
| 81 }; | 92 }; |
| 82 | 93 |
| 83 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ | 94 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ |
| OLD | NEW |