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