navigator.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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  // The RenderFrameHostImpl started a provisional load.
38  virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
39                                       int parent_routing_id,
40                                       bool main_frame,
41                                       const GURL& url) {};
42
43  // The RenderFrameHostImpl has failed a provisional load.
44  virtual void DidFailProvisionalLoadWithError(
45      RenderFrameHostImpl* render_frame_host,
46      const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {};
47
48  // The RenderFrameHostImpl has failed to load the document.
49  virtual void DidFailLoadWithError(
50      RenderFrameHostImpl* render_frame_host,
51      const GURL& url,
52      bool is_main_frame,
53      int error_code,
54      const base::string16& error_description) {}
55
56  // The RenderFrameHostImpl processed a redirect during a provisional load.
57  //
58  // TODO(creis): Remove this method and have the pre-rendering code listen to
59  // WebContentsObserver::DidGetRedirectForResourceRequest instead.
60  // See http://crbug.com/78512.
61  virtual void DidRedirectProvisionalLoad(
62      RenderFrameHostImpl* render_frame_host,
63      int32 page_id,
64      const GURL& source_url,
65      const GURL& target_url) {}
66
67  // The RenderFrameHostImpl has committed a navigation.
68  virtual void DidNavigate(
69      RenderFrameHostImpl* render_frame_host,
70      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
71
72  // Called by the NavigationController to cause the Navigator to navigate
73  // to the current pending entry. The NavigationController should be called
74  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
75  // The callbacks can be inside of this function, or at some future time.
76  //
77  // The entry has a PageID of -1 if newly created (corresponding to navigation
78  // to a new URL).
79  //
80  // If this method returns false, then the navigation is discarded (equivalent
81  // to calling DiscardPendingEntry on the NavigationController).
82  //
83  // TODO(nasko): Remove this method from the interface, since Navigator and
84  // NavigationController know about each other. This will be possible once
85  // initialization of Navigator and NavigationController is properly done.
86  virtual bool NavigateToPendingEntry(
87      RenderFrameHostImpl* render_frame_host,
88      NavigationController::ReloadType reload_type);
89
90  virtual base::TimeTicks GetCurrentLoadStart();
91
92  // The RenderFrameHostImpl has received a request to open a URL with the
93  // specified |disposition|.
94  virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
95                              const GURL& url,
96                              const Referrer& referrer,
97                              WindowOpenDisposition disposition,
98                              bool should_replace_current_entry,
99                              bool user_gesture) {}
100
101  // The RenderFrameHostImpl wants to transfer the request to a new renderer.
102  // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
103  // before the transfer.
104  virtual void RequestTransferURL(
105      RenderFrameHostImpl* render_frame_host,
106      const GURL& url,
107      const std::vector<GURL>& redirect_chain,
108      const Referrer& referrer,
109      PageTransition page_transition,
110      WindowOpenDisposition disposition,
111      const GlobalRequestID& transferred_global_request_id,
112      bool should_replace_current_entry,
113      bool user_gesture) {}
114
115 protected:
116  friend class base::RefCounted<Navigator>;
117  virtual ~Navigator() {}
118};
119
120}  // namespace content
121
122#endif  // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
123