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