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 "components/error_page/common/net_error_info.h"
13 #include "components/error_page/renderer/net_error_helper_core.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "content/public/renderer/render_frame_observer_tracker.h"
16 #include "content/public/renderer/render_process_observer.h"
27 class ResourceFetcher
;
30 namespace error_page
{
31 struct ErrorPageParams
;
34 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the
35 // browser side and updates the error page with more details (currently, just
36 // DNS probe results) if/when available.
38 : public content::RenderFrameObserver
,
39 public content::RenderFrameObserverTracker
<NetErrorHelper
>,
40 public content::RenderProcessObserver
,
41 public error_page::NetErrorHelperCore::Delegate
{
43 explicit NetErrorHelper(content::RenderFrame
* render_view
);
44 ~NetErrorHelper() override
;
46 // Button press notification from error page.
47 void ButtonPressed(error_page::NetErrorHelperCore::Button button
);
49 // RenderFrameObserver implementation.
50 void DidStartProvisionalLoad() override
;
51 void DidCommitProvisionalLoad(bool is_new_navigation
,
52 bool is_same_page_navigation
) override
;
53 void DidFinishLoad() override
;
54 void OnStop() override
;
55 void WasShown() override
;
56 void WasHidden() override
;
58 // IPC::Listener implementation.
59 bool OnMessageReceived(const IPC::Message
& message
) override
;
61 // RenderProcessObserver implementation.
62 void NetworkStateChanged(bool online
) override
;
64 // Examines |frame| and |error| to see if this is an error worthy of a DNS
65 // probe. If it is, initializes |error_strings| based on |error|,
66 // |is_failed_post|, and |locale| with suitable strings and returns true.
67 // If not, returns false, in which case the caller should look up error
68 // strings directly using LocalizedError::GetNavigationErrorStrings.
70 // Updates the NetErrorHelper with the assumption the page will be loaded
72 void GetErrorHTML(blink::WebFrame
* frame
,
73 const blink::WebURLError
& error
,
75 std::string
* error_html
);
77 // Returns whether a load for |url| in |frame| should have its error page
79 bool ShouldSuppressErrorPage(blink::WebFrame
* frame
, const GURL
& url
);
81 // Called when a link with the given tracking ID is pressed.
82 void TrackClick(int tracking_id
);
85 // NetErrorHelperCore::Delegate implementation:
86 void GenerateLocalizedErrorPage(
87 const blink::WebURLError
& error
,
89 scoped_ptr
<error_page::ErrorPageParams
> params
,
90 bool* reload_button_shown
,
91 bool* show_saved_copy_button_shown
,
92 std::string
* html
) const override
;
93 void LoadErrorPageInMainFrame(const std::string
& html
,
94 const GURL
& failed_url
) override
;
95 void EnablePageHelperFunctions() override
;
96 void UpdateErrorPage(const blink::WebURLError
& error
,
97 bool is_failed_post
) override
;
98 void FetchNavigationCorrections(
99 const GURL
& navigation_correction_url
,
100 const std::string
& navigation_correction_request_body
) override
;
101 void CancelFetchNavigationCorrections() override
;
102 void SendTrackingRequest(const GURL
& tracking_url
,
103 const std::string
& tracking_request_body
) override
;
104 void ReloadPage() override
;
105 void LoadPageFromCache(const GURL
& page_url
) override
;
107 void OnNetErrorInfo(int status
);
108 void OnSetNavigationCorrectionInfo(const GURL
& navigation_correction_url
,
109 const std::string
& language
,
110 const std::string
& country_code
,
111 const std::string
& api_key
,
112 const GURL
& search_url
);
114 void OnNavigationCorrectionsFetched(const blink::WebURLResponse
& response
,
115 const std::string
& data
);
117 void OnTrackingRequestComplete(const blink::WebURLResponse
& response
,
118 const std::string
& data
);
120 scoped_ptr
<content::ResourceFetcher
> correction_fetcher_
;
121 scoped_ptr
<content::ResourceFetcher
> tracking_fetcher_
;
123 scoped_ptr
<error_page::NetErrorHelperCore
> core_
;
125 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper
);
128 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_