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 std::string
* html
) const override
;
96 void LoadErrorPageInMainFrame(const std::string
& html
,
97 const GURL
& failed_url
) override
;
98 void EnablePageHelperFunctions() override
;
99 void UpdateErrorPage(const blink::WebURLError
& error
,
101 bool can_use_local_diagnostics_service
) override
;
102 void FetchNavigationCorrections(
103 const GURL
& navigation_correction_url
,
104 const std::string
& navigation_correction_request_body
) override
;
105 void CancelFetchNavigationCorrections() override
;
106 void SendTrackingRequest(const GURL
& tracking_url
,
107 const std::string
& tracking_request_body
) override
;
108 void ReloadPage() override
;
109 void LoadPageFromCache(const GURL
& page_url
) override
;
110 void DiagnoseError(const GURL
& page_url
) override
;
112 void OnNetErrorInfo(int status
);
113 void OnSetCanShowNetworkDiagnosticsDialog(
114 bool can_use_local_diagnostics_service
);
115 void OnSetNavigationCorrectionInfo(const GURL
& navigation_correction_url
,
116 const std::string
& language
,
117 const std::string
& country_code
,
118 const std::string
& api_key
,
119 const GURL
& search_url
);
121 void OnNavigationCorrectionsFetched(const blink::WebURLResponse
& response
,
122 const std::string
& data
);
124 void OnTrackingRequestComplete(const blink::WebURLResponse
& response
,
125 const std::string
& data
);
127 scoped_ptr
<content::ResourceFetcher
> correction_fetcher_
;
128 scoped_ptr
<content::ResourceFetcher
> tracking_fetcher_
;
130 scoped_ptr
<error_page::NetErrorHelperCore
> core_
;
132 // Weak factory for vending a weak pointer to a NetErrorPageController. Weak
133 // pointers are invalidated on each commit, to prevent getting messages from
134 // Controllers used for the previous commit that haven't yet been cleaned up.
135 base::WeakPtrFactory
<NetErrorPageController::Delegate
>
136 weak_controller_delegate_factory_
;
138 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper
);
141 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_