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 has committed a navigation.
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void DidNavigate(
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by the NavigationController to cause the Navigator to navigate
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to the current pending entry. The NavigationController should be called
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The callbacks can be inside of this function, or at some future time.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The entry has a PageID of -1 if newly created (corresponding to navigation
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to a new URL).
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If this method returns false, then the navigation is discarded (equivalent
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to calling DiscardPendingEntry on the NavigationController).
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(nasko): Remove this method from the interface, since Navigator and
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // NavigationController know about each other. This will be possible once
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // initialization of Navigator and NavigationController is properly done.
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool NavigateToPendingEntry(
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NavigationController::ReloadType reload_type);
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Navigation requests -------------------------------------------------------
86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::TimeTicks GetCurrentLoadStart();
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The RenderFrameHostImpl has received a request to open a URL with the
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // specified |disposition|.
91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              const GURL& url,
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              const Referrer& referrer,
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              WindowOpenDisposition disposition,
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              bool should_replace_current_entry,
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                              bool user_gesture) {}
97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The RenderFrameHostImpl wants to transfer the request to a new renderer.
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // before the transfer.
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void RequestTransferURL(
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      RenderFrameHostImpl* render_frame_host,
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const GURL& url,
104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const std::vector<GURL>& redirect_chain,
105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const Referrer& referrer,
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ui::PageTransition page_transition,
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      WindowOpenDisposition disposition,
108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const GlobalRequestID& transferred_global_request_id,
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      bool should_replace_current_entry,
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      bool user_gesture) {}
111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // PlzNavigate
11303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Signal |render_frame_host| that a navigation is ready to commit (the
11403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // response to the navigation request has been received).
11503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void CommitNavigation(RenderFrameHostImpl* render_frame_host,
11603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                const NavigationBeforeCommitInfo& info) {};
11703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) protected:
119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend class base::RefCounted<Navigator>;
120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ~Navigator() {}
121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace content
124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
126