navigator.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
12class GURL;
13struct FrameHostMsg_DidCommitProvisionalLoad_Params;
14struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
15
16namespace base {
17class TimeTicks;
18}
19
20namespace content {
21
22class NavigationControllerImpl;
23class NavigationEntryImpl;
24class NavigatorDelegate;
25class RenderFrameHostImpl;
26
27// Implementations of this interface are responsible for performing navigations
28// in a node of the FrameTree. Its lifetime is bound to all FrameTreeNode
29// objects that are using it and will be released once all nodes that use it are
30// freed. The Navigator is bound to a single frame tree and cannot be used by
31// multiple instances of FrameTree.
32// TODO(nasko): Move all navigation methods, such as didStartProvisionalLoad
33// from WebContentsImpl to this interface.
34class CONTENT_EXPORT Navigator : public base::RefCounted<Navigator> {
35 public:
36  // The RenderFrameHostImpl started a provisional load.
37  virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
38                                       int64 frame_id,
39                                       int64 parent_frame_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      int64 frame_id,
52      const GURL& url,
53      bool is_main_frame,
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  // Causes the Navigator to navigate in the right render frame to |entry|,
74  // which must be already part of the entries in the navigation controller.
75  // This does not change the NavigationController state.
76  virtual bool NavigateToEntry(
77      RenderFrameHostImpl* render_frame_host,
78      const NavigationEntryImpl& entry,
79      NavigationController::ReloadType reload_type);
80
81  // Called by the NavigationController to cause the Navigator to navigate
82  // to the current pending entry. The NavigationController should be called
83  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
84  // The callbacks can be inside of this function, or at some future time.
85  //
86  // The entry has a PageID of -1 if newly created (corresponding to navigation
87  // to a new URL).
88  //
89  // If this method returns false, then the navigation is discarded (equivalent
90  // to calling DiscardPendingEntry on the NavigationController).
91  //
92  // TODO(nasko): Remove this method from the interface, since Navigator and
93  // NavigationController know about each other. This will be possible once
94  // initialization of Navigator and NavigationController is properly done.
95  virtual bool NavigateToPendingEntry(
96      RenderFrameHostImpl* render_frame_host,
97      NavigationController::ReloadType reload_type);
98
99  virtual base::TimeTicks GetCurrentLoadStart();
100
101 protected:
102  friend class base::RefCounted<Navigator>;
103  virtual ~Navigator() {}
104};
105
106}  // namespace content
107
108#endif  // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
109