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 "chrome/common/net/net_error_info.h"
13 #include "chrome/renderer/net/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"
21 class ResourceFetcher;
30 // Listens for NetErrorInfo messages from the NetErrorTabHelper on the
31 // browser side and updates the error page with more details (currently, just
32 // DNS probe results) if/when available.
34 : public content::RenderFrameObserver,
35 public content::RenderFrameObserverTracker<NetErrorHelper>,
36 public content::RenderProcessObserver,
37 public NetErrorHelperCore::Delegate {
39 explicit NetErrorHelper(content::RenderFrame* render_view);
40 virtual ~NetErrorHelper();
42 // RenderFrameObserver implementation.
43 virtual void DidStartProvisionalLoad() OVERRIDE;
44 virtual void DidCommitProvisionalLoad(bool is_new_navigation) OVERRIDE;
45 virtual void DidFinishLoad() OVERRIDE;
46 virtual void OnStop() OVERRIDE;
48 // IPC::Listener implementation.
49 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
51 // RenderProcessObserver implementation.
52 virtual void NetworkStateChanged(bool online) OVERRIDE;
54 // Examines |frame| and |error| to see if this is an error worthy of a DNS
55 // probe. If it is, initializes |error_strings| based on |error|,
56 // |is_failed_post|, and |locale| with suitable strings and returns true.
57 // If not, returns false, in which case the caller should look up error
58 // strings directly using LocalizedError::GetNavigationErrorStrings.
60 // Updates the NetErrorHelper with the assumption the page will be loaded
62 void GetErrorHTML(blink::WebFrame* frame,
63 const blink::WebURLError& error,
65 std::string* error_html);
67 // Returns whether a load for |url| in |frame| should have its error page
69 bool ShouldSuppressErrorPage(blink::WebFrame* frame, const GURL& url);
72 // NetErrorHelperCore::Delegate implementation:
73 virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error,
75 std::string* html) const OVERRIDE;
76 virtual void LoadErrorPageInMainFrame(const std::string& html,
77 const GURL& failed_url) OVERRIDE;
78 virtual void EnableStaleLoadBindings(const GURL& page_url) OVERRIDE;
79 virtual void UpdateErrorPage(const blink::WebURLError& error,
80 bool is_failed_post) OVERRIDE;
81 virtual void FetchErrorPage(const GURL& url) OVERRIDE;
82 virtual void CancelFetchErrorPage() OVERRIDE;
83 virtual void ReloadPage() OVERRIDE;
85 void OnNetErrorInfo(int status);
86 void OnSetAltErrorPageURL(const GURL& alternate_error_page_url);
88 void OnAlternateErrorPageRetrieved(const blink::WebURLResponse& response,
89 const std::string& data);
91 scoped_ptr<content::ResourceFetcher> alt_error_page_fetcher_;
93 NetErrorHelperCore core_;
95 DISALLOW_COPY_AND_ASSIGN(NetErrorHelper);
98 #endif // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_