1 // Copyright 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_CORE_H_
6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/common/net/net_error_info.h"
18 // Class that contains the logic for how the NetErrorHelper. This allows for
19 // testing the logic without a RenderView or WebFrame, which are difficult to
20 // mock, and for testing races which are impossible to reliably reproduce
21 // with real RenderViews or WebFrames.
22 class NetErrorHelperCore
{
34 // The Delegate handles all interaction with the RenderView, WebFrame, and
35 // the network, as well as the generation of error pages.
38 // Generates an error page's HTML for the given error.
39 virtual void GenerateLocalizedErrorPage(const blink::WebURLError
& error
,
41 std::string
* html
) const = 0;
43 // Loads the given HTML in the main frame for use as an error page.
44 virtual void LoadErrorPageInMainFrame(const std::string
& html
,
45 const GURL
& failed_url
) = 0;
47 // Updates the currently displayed error page with a new error code. The
48 // currently displayed error page must have finished loading, and must have
49 // been generated by a call to GenerateLocalizedErrorPage.
50 virtual void UpdateErrorPage(const blink::WebURLError
& error
,
51 bool is_failed_post
) = 0;
53 // Fetches an error page and calls into OnErrorPageFetched when done. Any
54 // previous fetch must either be canceled or finished before calling. Can't
55 // be called synchronously after a previous fetch completes.
56 virtual void FetchErrorPage(const GURL
& url
) = 0;
58 // Cancels an error page fetch. Does nothing if no fetch is ongoing.
59 virtual void CancelFetchErrorPage() = 0;
62 virtual ~Delegate() {}
65 explicit NetErrorHelperCore(Delegate
* delegate
);
66 ~NetErrorHelperCore();
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(FrameType frame_type
,
77 const blink::WebURLError
& error
,
79 std::string
* error_html
);
81 // These methods handle tracking the actual state of the page.
82 void OnStartLoad(FrameType frame_type
, PageType page_type
);
83 void OnCommitLoad(FrameType frame_type
);
84 void OnFinishLoad(FrameType frame_type
);
87 // Called when an error page have has been retrieved over the network. |html|
88 // must be an empty string on error.
89 void OnAlternateErrorPageFetched(const std::string
& html
);
91 // Notifies |this| that network error information from the browser process
93 void OnNetErrorInfo(chrome_common_net::DnsProbeStatus status
);
95 void set_alt_error_page_url(const GURL
& alt_error_page_url
) {
96 alt_error_page_url_
= alt_error_page_url
;
100 struct ErrorPageInfo
;
102 // Updates the currently displayed error page with a new error based on the
103 // most recently received DNS probe result. The page must have finished
104 // loading before this is called.
105 void UpdateErrorPage();
107 void GenerateLocalErrorPage(
108 FrameType frame_type
,
109 const blink::WebURLError
& error
,
111 std::string
* error_html
);
113 blink::WebURLError
GetUpdatedError(const blink::WebURLError
& error
) const;
117 // The last DnsProbeStatus received from the browser.
118 chrome_common_net::DnsProbeStatus last_probe_status_
;
120 // Information for the provisional / "pre-provisional" error page. NULL when
121 // there's no page pending, or the pending page is not an error page.
122 scoped_ptr
<ErrorPageInfo
> pending_error_page_info_
;
124 // Information for the committed error page. NULL when the committed page is
125 // not an error page.
126 scoped_ptr
<ErrorPageInfo
> committed_error_page_info_
;
128 GURL alt_error_page_url_
;
131 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_CORE_H_