| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/common/network_diagnostics.mojom.h" |
| 14 #include "chrome/renderer/net/net_error_page_controller.h" | 15 #include "chrome/renderer/net/net_error_page_controller.h" |
| 15 #include "components/error_page/common/net_error_info.h" | 16 #include "components/error_page/common/net_error_info.h" |
| 16 #include "components/error_page/renderer/net_error_helper_core.h" | 17 #include "components/error_page/renderer/net_error_helper_core.h" |
| 17 #include "content/public/renderer/render_frame_observer.h" | 18 #include "content/public/renderer/render_frame_observer.h" |
| 18 #include "content/public/renderer/render_frame_observer_tracker.h" | 19 #include "content/public/renderer/render_frame_observer_tracker.h" |
| 19 #include "content/public/renderer/render_thread_observer.h" | 20 #include "content/public/renderer/render_thread_observer.h" |
| 21 #include "mojo/public/cpp/bindings/associated_binding.h" |
| 20 | 22 |
| 21 class GURL; | 23 class GURL; |
| 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 namespace content { | 31 namespace content { |
| 30 class ResourceFetcher; | 32 class ResourceFetcher; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace error_page { | 35 namespace error_page { |
| 34 struct ErrorPageParams; | 36 struct ErrorPageParams; |
| 35 } | 37 } |
| 36 | 38 |
| 37 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the | 39 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the |
| 38 // browser side and updates the error page with more details (currently, just | 40 // browser side and updates the error page with more details (currently, just |
| 39 // DNS probe results) if/when available. | 41 // DNS probe results) if/when available. |
| 40 // TODO(crbug.com/578770): Should this class be moved into the error_page | 42 // TODO(crbug.com/578770): Should this class be moved into the error_page |
| 41 // component? | 43 // component? |
| 42 class NetErrorHelper | 44 class NetErrorHelper |
| 43 : public content::RenderFrameObserver, | 45 : public content::RenderFrameObserver, |
| 44 public content::RenderFrameObserverTracker<NetErrorHelper>, | 46 public content::RenderFrameObserverTracker<NetErrorHelper>, |
| 45 public content::RenderThreadObserver, | 47 public content::RenderThreadObserver, |
| 46 public error_page::NetErrorHelperCore::Delegate, | 48 public error_page::NetErrorHelperCore::Delegate, |
| 47 public NetErrorPageController::Delegate { | 49 public NetErrorPageController::Delegate, |
| 50 public mojom::NetworkDiagnosticsClient { |
| 48 public: | 51 public: |
| 49 explicit NetErrorHelper(content::RenderFrame* render_frame); | 52 explicit NetErrorHelper(content::RenderFrame* render_frame); |
| 50 ~NetErrorHelper() override; | 53 ~NetErrorHelper() override; |
| 51 | 54 |
| 52 // NetErrorPageController::Delegate implementation | 55 // NetErrorPageController::Delegate implementation |
| 53 void ButtonPressed(error_page::NetErrorHelperCore::Button button) override; | 56 void ButtonPressed(error_page::NetErrorHelperCore::Button button) override; |
| 54 void TrackClick(int tracking_id) override; | 57 void TrackClick(int tracking_id) override; |
| 55 | 58 |
| 56 // RenderFrameObserver implementation. | 59 // RenderFrameObserver implementation. |
| 57 void DidStartProvisionalLoad() override; | 60 void DidStartProvisionalLoad() override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 void GetErrorHTML(const blink::WebURLError& error, | 78 void GetErrorHTML(const blink::WebURLError& error, |
| 76 bool is_failed_post, | 79 bool is_failed_post, |
| 77 bool is_ignoring_cache, | 80 bool is_ignoring_cache, |
| 78 std::string* error_html); | 81 std::string* error_html); |
| 79 | 82 |
| 80 // Returns whether a load for |url| in the |frame| the NetErrorHelper is | 83 // Returns whether a load for |url| in the |frame| the NetErrorHelper is |
| 81 // attached to should have its error page suppressed. | 84 // attached to should have its error page suppressed. |
| 82 bool ShouldSuppressErrorPage(const GURL& url); | 85 bool ShouldSuppressErrorPage(const GURL& url); |
| 83 | 86 |
| 84 private: | 87 private: |
| 88 mojom::NetworkDiagnostics* GetRemoteNetworkDiagnostics(); |
| 89 |
| 85 // NetErrorHelperCore::Delegate implementation: | 90 // NetErrorHelperCore::Delegate implementation: |
| 86 void GenerateLocalizedErrorPage( | 91 void GenerateLocalizedErrorPage( |
| 87 const blink::WebURLError& error, | 92 const blink::WebURLError& error, |
| 88 bool is_failed_post, | 93 bool is_failed_post, |
| 89 bool can_use_local_diagnostics_service, | 94 bool can_use_local_diagnostics_service, |
| 90 bool has_offline_pages, | 95 bool has_offline_pages, |
| 91 std::unique_ptr<error_page::ErrorPageParams> params, | 96 std::unique_ptr<error_page::ErrorPageParams> params, |
| 92 bool* reload_button_shown, | 97 bool* reload_button_shown, |
| 93 bool* show_saved_copy_button_shown, | 98 bool* show_saved_copy_button_shown, |
| 94 bool* show_cached_copy_button_shown, | 99 bool* show_cached_copy_button_shown, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 105 const std::string& navigation_correction_request_body) override; | 110 const std::string& navigation_correction_request_body) override; |
| 106 void CancelFetchNavigationCorrections() override; | 111 void CancelFetchNavigationCorrections() override; |
| 107 void SendTrackingRequest(const GURL& tracking_url, | 112 void SendTrackingRequest(const GURL& tracking_url, |
| 108 const std::string& tracking_request_body) override; | 113 const std::string& tracking_request_body) override; |
| 109 void ReloadPage(bool bypass_cache) override; | 114 void ReloadPage(bool bypass_cache) override; |
| 110 void LoadPageFromCache(const GURL& page_url) override; | 115 void LoadPageFromCache(const GURL& page_url) override; |
| 111 void DiagnoseError(const GURL& page_url) override; | 116 void DiagnoseError(const GURL& page_url) override; |
| 112 void ShowOfflinePages() override; | 117 void ShowOfflinePages() override; |
| 113 | 118 |
| 114 void OnNetErrorInfo(int status); | 119 void OnNetErrorInfo(int status); |
| 115 void OnSetCanShowNetworkDiagnosticsDialog( | |
| 116 bool can_use_local_diagnostics_service); | |
| 117 void OnSetNavigationCorrectionInfo(const GURL& navigation_correction_url, | 120 void OnSetNavigationCorrectionInfo(const GURL& navigation_correction_url, |
| 118 const std::string& language, | 121 const std::string& language, |
| 119 const std::string& country_code, | 122 const std::string& country_code, |
| 120 const std::string& api_key, | 123 const std::string& api_key, |
| 121 const GURL& search_url); | 124 const GURL& search_url); |
| 122 | 125 |
| 123 void OnNavigationCorrectionsFetched(const blink::WebURLResponse& response, | 126 void OnNavigationCorrectionsFetched(const blink::WebURLResponse& response, |
| 124 const std::string& data); | 127 const std::string& data); |
| 125 | 128 |
| 126 void OnTrackingRequestComplete(const blink::WebURLResponse& response, | 129 void OnTrackingRequestComplete(const blink::WebURLResponse& response, |
| 127 const std::string& data); | 130 const std::string& data); |
| 128 | 131 |
| 132 void OnNetworkDiagnosticsClientRequest( |
| 133 mojom::NetworkDiagnosticsClientAssociatedRequest request); |
| 134 |
| 135 // mojom::NetworkDiagnosticsClient: |
| 136 void SetCanShowNetworkDiagnosticsDialog(bool can_show) override; |
| 137 |
| 129 #if defined(OS_ANDROID) | 138 #if defined(OS_ANDROID) |
| 130 // Called to set whether offline pages exists, which will be used to decide | 139 // Called to set whether offline pages exists, which will be used to decide |
| 131 // if offline related button will be provided in the error page. | 140 // if offline related button will be provided in the error page. |
| 132 void OnSetHasOfflinePages(bool has_offline_pages); | 141 void OnSetHasOfflinePages(bool has_offline_pages); |
| 133 #endif | 142 #endif |
| 134 | 143 |
| 135 std::unique_ptr<content::ResourceFetcher> correction_fetcher_; | 144 std::unique_ptr<content::ResourceFetcher> correction_fetcher_; |
| 136 std::unique_ptr<content::ResourceFetcher> tracking_fetcher_; | 145 std::unique_ptr<content::ResourceFetcher> tracking_fetcher_; |
| 137 | 146 |
| 138 std::unique_ptr<error_page::NetErrorHelperCore> core_; | 147 std::unique_ptr<error_page::NetErrorHelperCore> core_; |
| 139 | 148 |
| 149 mojo::AssociatedBinding<mojom::NetworkDiagnosticsClient> |
| 150 network_diagnostics_client_binding_; |
| 151 mojom::NetworkDiagnosticsAssociatedPtr remote_network_diagnostics_; |
| 152 |
| 140 // Weak factory for vending a weak pointer to a NetErrorPageController. Weak | 153 // Weak factory for vending a weak pointer to a NetErrorPageController. Weak |
| 141 // pointers are invalidated on each commit, to prevent getting messages from | 154 // pointers are invalidated on each commit, to prevent getting messages from |
| 142 // Controllers used for the previous commit that haven't yet been cleaned up. | 155 // Controllers used for the previous commit that haven't yet been cleaned up. |
| 143 base::WeakPtrFactory<NetErrorPageController::Delegate> | 156 base::WeakPtrFactory<NetErrorPageController::Delegate> |
| 144 weak_controller_delegate_factory_; | 157 weak_controller_delegate_factory_; |
| 145 | 158 |
| 146 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper); | 159 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper); |
| 147 }; | 160 }; |
| 148 | 161 |
| 149 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ | 162 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_ |
| OLD | NEW |