navigator.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/ref_counted.h"
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/common/content_export.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/base/window_open_disposition.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class GURL;
1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)struct FrameHostMsg_BeginNavigation_Params;
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct FrameHostMsg_DidCommitProvisionalLoad_Params;
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TimeTicks;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace content {
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class NavigationControllerImpl;
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NavigationEntryImpl;
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class NavigatorDelegate;
27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class RenderFrameHostImpl;
2803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)struct NavigationBeforeCommitInfo;
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Implementations of this interface are responsible for performing navigations
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// in a node of the FrameTree. Its lifetime is bound to all FrameTreeNode
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// objects that are using it and will be released once all nodes that use it are
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// freed. The Navigator is bound to a single frame tree and cannot be used by
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// multiple instances of FrameTree.
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// TODO(nasko): Move all navigation methods, such as didStartProvisionalLoad
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// from WebContentsImpl to this interface.
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class CONTENT_EXPORT Navigator : public base::RefCounted<Navigator> {
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Returns the NavigationController associated with this Navigator.
405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  virtual NavigationController* GetController();
415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Notifications coming from the RenderFrameHosts ----------------------------
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The RenderFrameHostImpl started a provisional load.
45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                       const GURL& url,
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                       bool is_transition_navigation) {};
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The RenderFrameHostImpl has failed a provisional load.
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidFailProvisionalLoadWithError(
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {};
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The RenderFrameHostImpl has failed to load the document.
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidFailLoadWithError(
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GURL& url,
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      int error_code,
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::string16& error_description) {}
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The RenderFrameHostImpl processed a redirect during a provisional load.
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(creis): Remove this method and have the pre-rendering code listen to
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // WebContentsObserver::DidGetRedirectForResourceRequest instead.
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // See http://crbug.com/78512.
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidRedirectProvisionalLoad(
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      int32 page_id,
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GURL& source_url,
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const GURL& target_url) {}
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The RenderFrameHostImpl has committed a navigation.
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidNavigate(
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by the NavigationController to cause the Navigator to navigate
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to the current pending entry. The NavigationController should be called
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The callbacks can be inside of this function, or at some future time.
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The entry has a PageID of -1 if newly created (corresponding to navigation
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to a new URL).
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If this method returns false, then the navigation is discarded (equivalent
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to calling DiscardPendingEntry on the NavigationController).
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(nasko): Remove this method from the interface, since Navigator and
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // NavigationController know about each other. This will be possible once
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // initialization of Navigator and NavigationController is properly done.
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool NavigateToPendingEntry(
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NavigationController::ReloadType reload_type);
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Navigation requests -------------------------------------------------------
97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::TimeTicks GetCurrentLoadStart();
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The RenderFrameHostImpl has received a request to open a URL with the
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // specified |disposition|.
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              const GURL& url,
104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              const Referrer& referrer,
105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              WindowOpenDisposition disposition,
106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              bool should_replace_current_entry,
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              bool user_gesture) {}
108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The RenderFrameHostImpl wants to transfer the request to a new renderer.
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // before the transfer.
112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void RequestTransferURL(
113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const GURL& url,
115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const std::vector<GURL>& redirect_chain,
116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const Referrer& referrer,
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      PageTransition page_transition,
118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      WindowOpenDisposition disposition,
119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const GlobalRequestID& transferred_global_request_id,
120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      bool should_replace_current_entry,
121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      bool user_gesture) {}
122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
12303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // PlzNavigate
12403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Signal |render_frame_host| that a navigation is ready to commit (the
12503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // response to the navigation request has been received).
12603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void CommitNavigation(RenderFrameHostImpl* render_frame_host,
12703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                const NavigationBeforeCommitInfo& info) {};
12803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
129a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) protected:
130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend class base::RefCounted<Navigator>;
131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ~Navigator() {}
132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace content
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
137