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 ReloadButtonPressed();
48 void LoadStaleButtonPressed();
49 void MoreButtonPressed();
51 // RenderFrameObserver implementation.
52 void DidStartProvisionalLoad() override
;
53 void DidCommitProvisionalLoad(bool is_new_navigation
) override
;
54 void DidFinishLoad() override
;
55 void OnStop() override
;
56 void WasShown() override
;
57 void WasHidden() override
;
59 // IPC::Listener implementation.
60 bool OnMessageReceived(const IPC::Message
& message
) override
;
62 // RenderProcessObserver implementation.
63 void NetworkStateChanged(bool online
) override
;
65 // Examines |frame| and |error| to see if this is an error worthy of a DNS
66 // probe. If it is, initializes |error_strings| based on |error|,
67 // |is_failed_post|, and |locale| with suitable strings and returns true.
68 // If not, returns false, in which case the caller should look up error
69 // strings directly using LocalizedError::GetNavigationErrorStrings.
71 // Updates the NetErrorHelper with the assumption the page will be loaded
73 void GetErrorHTML(blink::WebFrame
* frame
,
74 const blink::WebURLError
& error
,
76 std::string
* error_html
);
78 // Returns whether a load for |url| in |frame| should have its error page
80 bool ShouldSuppressErrorPage(blink::WebFrame
* frame
, const GURL
& url
);
82 // Called when a link with the given tracking ID is pressed.
83 void TrackClick(int tracking_id
);
86 // NetErrorHelperCore::Delegate implementation:
87 void GenerateLocalizedErrorPage(
88 const blink::WebURLError
& error
,
90 scoped_ptr
<error_page::ErrorPageParams
> params
,
91 bool* reload_button_shown
,
92 bool* load_stale_button_shown
,
93 std::string
* html
) const override
;
94 void LoadErrorPageInMainFrame(const std::string
& html
,
95 const GURL
& failed_url
) override
;
96 void EnablePageHelperFunctions() override
;
97 void UpdateErrorPage(const blink::WebURLError
& error
,
98 bool is_failed_post
) override
;
99 void FetchNavigationCorrections(
100 const GURL
& navigation_correction_url
,
101 const std::string
& navigation_correction_request_body
) override
;
102 void CancelFetchNavigationCorrections() override
;
103 void SendTrackingRequest(const GURL
& tracking_url
,
104 const std::string
& tracking_request_body
) override
;
105 void ReloadPage() override
;
106 void LoadPageFromCache(const GURL
& page_url
) override
;
108 void OnNetErrorInfo(int status
);
109 void OnSetNavigationCorrectionInfo(const GURL
& navigation_correction_url
,
110 const std::string
& language
,
111 const std::string
& country_code
,
112 const std::string
& api_key
,
113 const GURL
& search_url
);
115 void OnNavigationCorrectionsFetched(const blink::WebURLResponse
& response
,
116 const std::string
& data
);
118 void OnTrackingRequestComplete(const blink::WebURLResponse
& response
,
119 const std::string
& data
);
121 scoped_ptr
<content::ResourceFetcher
> correction_fetcher_
;
122 scoped_ptr
<content::ResourceFetcher
> tracking_fetcher_
;
124 scoped_ptr
<error_page::NetErrorHelperCore
> core_
;
126 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper
);
129 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_