Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / net / net_error_helper.h
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.
4
5 #ifndef CHROME_RENDERER_NET_NET_ERROR_HELPER_H_
6 #define CHROME_RENDERER_NET_NET_ERROR_HELPER_H_
7
8 #include <string>
9
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"
17
18 class GURL;
19
20 namespace content {
21 class ResourceFetcher;
22 }
23
24 namespace blink {
25 class WebFrame;
26 class WebURLResponse;
27 struct WebURLError;
28 }
29
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.
33 class NetErrorHelper
34     : public content::RenderFrameObserver,
35       public content::RenderFrameObserverTracker<NetErrorHelper>,
36       public content::RenderProcessObserver,
37       public NetErrorHelperCore::Delegate {
38  public:
39   explicit NetErrorHelper(content::RenderFrame* render_view);
40   virtual ~NetErrorHelper();
41
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;
47
48   // IPC::Listener implementation.
49   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
50
51   // RenderProcessObserver implementation.
52   virtual void NetworkStateChanged(bool online) OVERRIDE;
53
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.
59   //
60   // Updates the NetErrorHelper with the assumption the page will be loaded
61   // immediately.
62   void GetErrorHTML(blink::WebFrame* frame,
63                     const blink::WebURLError& error,
64                     bool is_failed_post,
65                     std::string* error_html);
66
67   // Returns whether a load for |url| in |frame| should have its error page
68   // suppressed.
69   bool ShouldSuppressErrorPage(blink::WebFrame* frame, const GURL& url);
70
71  private:
72   // NetErrorHelperCore::Delegate implementation:
73   virtual void GenerateLocalizedErrorPage(const blink::WebURLError& error,
74                                           bool is_failed_post,
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;
84
85   void OnNetErrorInfo(int status);
86   void OnSetAltErrorPageURL(const GURL& alternate_error_page_url);
87
88   void OnAlternateErrorPageRetrieved(const blink::WebURLResponse& response,
89                                      const std::string& data);
90
91   scoped_ptr<content::ResourceFetcher> alt_error_page_fetcher_;
92
93   NetErrorHelperCore core_;
94
95   DISALLOW_COPY_AND_ASSIGN(NetErrorHelper);
96 };
97
98 #endif  // CHROME_RENDERER_NET_NET_ERROR_HELPER_H_