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
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_H_
6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/renderer/net/net_error_page_controller.h"
14 #include "components/error_page/common/net_error_info.h"
15 #include "components/error_page/renderer/net_error_helper_core.h"
16 #include "content/public/renderer/render_frame_observer.h"
17 #include "content/public/renderer/render_frame_observer_tracker.h"
18 #include "content/public/renderer/render_process_observer.h"
29 class ResourceFetcher
;
32 namespace error_page
{
33 struct ErrorPageParams
;
36 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the
37 // browser side and updates the error page with more details (currently, just
38 // DNS probe results) if/when available.
40 : public content::RenderFrameObserver
,
41 public content::RenderFrameObserverTracker
<NetErrorHelper
>,
42 public content::RenderProcessObserver
,
43 public error_page::NetErrorHelperCore::Delegate
,
44 public NetErrorPageController::Delegate
{
46 explicit NetErrorHelper(content::RenderFrame
* render_view
);
47 ~NetErrorHelper() override
;
49 // NetErrorPageController::Delegate implementation
50 void ButtonPressed(error_page::NetErrorHelperCore::Button button
) override
;
51 void TrackClick(int tracking_id
) override
;
53 // RenderFrameObserver implementation.
54 void DidStartProvisionalLoad() override
;
55 void DidCommitProvisionalLoad(bool is_new_navigation
,
56 bool is_same_page_navigation
) override
;
57 void DidFinishLoad() override
;
58 void OnStop() override
;
59 void WasShown() override
;
60 void WasHidden() override
;
62 // IPC::Listener implementation.
63 bool OnMessageReceived(const IPC::Message
& message
) override
;
65 // RenderProcessObserver implementation.
66 void NetworkStateChanged(bool online
) override
;
68 // 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|,
70 // |is_failed_post|, and |locale| with suitable strings and returns true.
71 // If not, returns false, in which case the caller should look up error
72 // strings directly using LocalizedError::GetNavigationErrorStrings.
74 // Updates the NetErrorHelper with the assumption the page will be loaded
76 void GetErrorHTML(blink::WebFrame
* frame
,
77 const blink::WebURLError
& error
,
79 std::string
* error_html
);
81 // Returns whether a load for |url| in |frame| should have its error page
83 bool ShouldSuppressErrorPage(blink::WebFrame
* frame
, const GURL
& url
);
86 // NetErrorHelperCore::Delegate implementation:
87 void GenerateLocalizedErrorPage(
88 const blink::WebURLError
& error
,
90 bool can_use_local_diagnostics_service
,
91 scoped_ptr
<error_page::ErrorPageParams
> params
,
92 bool* reload_button_shown
,
93 bool* show_saved_copy_button_shown
,
94 bool* show_cached_copy_button_shown
,
95 bool* show_cached_page_button_shown
,
96 std::string
* html
) const override
;
97 void LoadErrorPageInMainFrame(const std::string
& html
,
98 const GURL
& failed_url
) override
;
99 void EnablePageHelperFunctions() override
;
100 void UpdateErrorPage(const blink::WebURLError
& error
,
102 bool can_use_local_diagnostics_service
) override
;
103 void FetchNavigationCorrections(
104 const GURL
& navigation_correction_url
,
105 const std::string
& navigation_correction_request_body
) override
;
106 void CancelFetchNavigationCorrections() override
;
107 void SendTrackingRequest(const GURL
& tracking_url
,
108 const std::string
& tracking_request_body
) override
;
109 void ReloadPage() override
;
110 void LoadPageFromCache(const GURL
& page_url
) override
;
111 void DiagnoseError(const GURL
& page_url
) override
;
113 void OnNetErrorInfo(int status
);
114 void OnSetCanShowNetworkDiagnosticsDialog(
115 bool can_use_local_diagnostics_service
);
116 void OnSetNavigationCorrectionInfo(const GURL
& navigation_correction_url
,
117 const std::string
& language
,
118 const std::string
& country_code
,
119 const std::string
& api_key
,
120 const GURL
& search_url
);
122 void OnNavigationCorrectionsFetched(const blink::WebURLResponse
& response
,
123 const std::string
& data
);
125 void OnTrackingRequestComplete(const blink::WebURLResponse
& response
,
126 const std::string
& data
);
128 scoped_ptr
<content::ResourceFetcher
> correction_fetcher_
;
129 scoped_ptr
<content::ResourceFetcher
> tracking_fetcher_
;
131 scoped_ptr
<error_page::NetErrorHelperCore
> core_
;
133 // Weak factory for vending a weak pointer to a NetErrorPageController. Weak
134 // pointers are invalidated on each commit, to prevent getting messages from
135 // Controllers used for the previous commit that haven't yet been cleaned up.
136 base::WeakPtrFactory
<NetErrorPageController::Delegate
>
137 weak_controller_delegate_factory_
;
139 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper
);
142 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_