navigator.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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.
4
5#ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
6#define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
7
8#include "base/memory/ref_counted.h"
9#include "content/common/content_export.h"
10#include "content/public/browser/navigation_controller.h"
11#include "ui/base/window_open_disposition.h"
12
13class GURL;
14struct FrameHostMsg_DidCommitProvisionalLoad_Params;
15struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
16
17namespace base {
18class TimeTicks;
19}
20
21namespace content {
22
23class NavigationControllerImpl;
24class NavigationEntryImpl;
25class NavigatorDelegate;
26class RenderFrameHostImpl;
27
28// Implementations of this interface are responsible for performing navigations
29// in a node of the FrameTree. Its lifetime is bound to all FrameTreeNode
30// objects that are using it and will be released once all nodes that use it are
31// freed. The Navigator is bound to a single frame tree and cannot be used by
32// multiple instances of FrameTree.
33// TODO(nasko): Move all navigation methods, such as didStartProvisionalLoad
34// from WebContentsImpl to this interface.
35class CONTENT_EXPORT Navigator : public base::RefCounted<Navigator> {
36 public:
37  // Returns the NavigationController associated with this Navigator.
38  virtual NavigationController* GetController();
39
40  // The RenderFrameHostImpl started a provisional load.
41  virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
42                                       int parent_routing_id,
43                                       const GURL& url) {};
44
45  // The RenderFrameHostImpl has failed a provisional load.
46  virtual void DidFailProvisionalLoadWithError(
47      RenderFrameHostImpl* render_frame_host,
48      const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {};
49
50  // The RenderFrameHostImpl has failed to load the document.
51  virtual void DidFailLoadWithError(
52      RenderFrameHostImpl* render_frame_host,
53      const GURL& url,
54      int error_code,
55      const base::string16& error_description) {}
56
57  // The RenderFrameHostImpl processed a redirect during a provisional load.
58  //
59  // TODO(creis): Remove this method and have the pre-rendering code listen to
60  // WebContentsObserver::DidGetRedirectForResourceRequest instead.
61  // See http://crbug.com/78512.
62  virtual void DidRedirectProvisionalLoad(
63      RenderFrameHostImpl* render_frame_host,
64      int32 page_id,
65      const GURL& source_url,
66      const GURL& target_url) {}
67
68  // The RenderFrameHostImpl has committed a navigation.
69  virtual void DidNavigate(
70      RenderFrameHostImpl* render_frame_host,
71      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
72
73  // Called by the NavigationController to cause the Navigator to navigate
74  // to the current pending entry. The NavigationController should be called
75  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
76  // The callbacks can be inside of this function, or at some future time.
77  //
78  // The entry has a PageID of -1 if newly created (corresponding to navigation
79  // to a new URL).
80  //
81  // If this method returns false, then the navigation is discarded (equivalent
82  // to calling DiscardPendingEntry on the NavigationController).
83  //
84  // TODO(nasko): Remove this method from the interface, since Navigator and
85  // NavigationController know about each other. This will be possible once
86  // initialization of Navigator and NavigationController is properly done.
87  virtual bool NavigateToPendingEntry(
88      RenderFrameHostImpl* render_frame_host,
89      NavigationController::ReloadType reload_type);
90
91  virtual base::TimeTicks GetCurrentLoadStart();
92
93  // The RenderFrameHostImpl has received a request to open a URL with the
94  // specified |disposition|.
95  virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
96                              const GURL& url,
97                              const Referrer& referrer,
98                              WindowOpenDisposition disposition,
99                              bool should_replace_current_entry,
100                              bool user_gesture) {}
101
102  // The RenderFrameHostImpl wants to transfer the request to a new renderer.
103  // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
104  // before the transfer.
105  virtual void RequestTransferURL(
106      RenderFrameHostImpl* render_frame_host,
107      const GURL& url,
108      const std::vector<GURL>& redirect_chain,
109      const Referrer& referrer,
110      PageTransition page_transition,
111      WindowOpenDisposition disposition,
112      const GlobalRequestID& transferred_global_request_id,
113      bool should_replace_current_entry,
114      bool user_gesture) {}
115
116 protected:
117  friend class base::RefCounted<Navigator>;
118  virtual ~Navigator() {}
119};
120
121}  // namespace content
122
123#endif  // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
124