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.
5 #ifndef IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_
6 #define IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/scoped_vector.h"
13 #include "ios/web/public/navigation_manager.h"
14 #include "ui/base/page_transition_types.h"
17 @
class CRWSessionController
;
18 @
class CRWSessionEntry
;
24 class NavigationManagerDelegate
;
25 class NavigationManagerFacadeDelegate
;
27 // Implementation of NavigationManager.
28 // Generally mirrors upstream's NavigationController.
29 class NavigationManagerImpl
: public NavigationManager
{
31 NavigationManagerImpl(NavigationManagerDelegate
* delegate
,
32 BrowserState
* browser_state
);
33 ~NavigationManagerImpl() override
;
35 // Sets the CRWSessionController that backs this object.
36 // Keeps a strong reference to |session_controller|.
37 // This method should only be called when deserializing |session_controller|
38 // and joining it with its NavigationManager. Other cases should call
39 // InitializeSession() or ReplaceSessionHistory().
40 // TODO(stuartmorgan): Also move deserialization of CRWSessionControllers
41 // under the control of this class, and move the bulk of CRWSessionController
43 void SetSessionController(CRWSessionController
* session_controller
);
45 // Initializes a new session history, supplying a unique |window_name| for the
46 // window (or nil). |opener_id| is the id of opener, or nil if there is none.
47 // |opened_by_dom| is YES if the page was opened by DOM.
48 // |opener_index| is the navigation index of the opener, or -1 if there is
50 void InitializeSession(NSString
* window_name
,
53 int opener_navigation_index
);
55 // Replace the session history with a new one, where |items| is the
56 // complete set of navigation items in the new history, and |current_index|
57 // is the index of the currently active item.
58 void ReplaceSessionHistory(ScopedVector
<NavigationItem
> items
,
61 // Sets the delegate used to drive the navigation controller facade.
62 void SetFacadeDelegate(NavigationManagerFacadeDelegate
* facade_delegate
);
63 NavigationManagerFacadeDelegate
* GetFacadeDelegate() const;
65 // Helper functions for communicating with the facade layer.
66 // TODO(stuartmorgan): Make these private once the logic triggering them moves
68 void OnNavigationItemChanged();
69 void OnNavigationItemCommitted();
71 // Returns the transient item if any. This is an item which is removed and
72 // discarded if any navigation occurs. Note that the returned item is owned
73 // by the navigation manager and may be deleted at any time.
74 NavigationItem
* GetTransientItem() const;
76 // Temporary accessors and content/ class pass-throughs.
77 // TODO(stuartmorgan): Re-evaluate this list once the refactorings have
79 CRWSessionController
* GetSessionController();
80 int GetLastCommittedEntryIndex() const;
81 bool RemoveEntryAtIndex(int index
);
82 void LoadURL(const GURL
& url
,
83 const Referrer
& referrer
,
84 ui::PageTransition type
);
85 bool CanGoBack() const;
86 bool CanGoForward() const;
90 // Convenience accessors to get the underlying NavigationItems from the
91 // SessionEntries returned from |session_controller_|'s -lastUserEntry and
92 // -previousEntry methods.
93 // TODO(marq):Evaluate the long-term utility of these methods.
94 NavigationItem
* GetLastUserItem() const;
95 NavigationItem
* GetPreviousItem() const;
97 // Temporary method. Returns a vector of NavigationItems corresponding to
98 // the SessionEntries of the uderlying CRWSessionController.
99 // TOOD(marq): Remove this method and unfork its caller,
100 // TabRestoreServiceHelper::PopulateTab
101 std::vector
<NavigationItem
*> GetItems();
103 // NavigationManager:
104 BrowserState
* GetBrowserState() const override
;
105 WebState
* GetWebState() const override
;
106 NavigationItem
* GetVisibleItem() const override
;
107 NavigationItem
* GetLastCommittedItem() const override
;
108 NavigationItem
* GetPendingItem() const override
;
109 void DiscardNonCommittedItems() override
;
110 void LoadIfNecessary() override
;
111 void AddTransientURLRewriter(
112 BrowserURLRewriter::URLRewriter rewriter
) override
;
113 int GetEntryCount() const override
;
114 NavigationItem
* GetItemAtIndex(size_t index
) const override
;
115 int GetCurrentEntryIndex() const override
;
116 int GetPendingItemIndex() const override
;
118 // Returns the current list of transient url rewriters, passing ownership to
120 // TODO(kkhorimoto): remove once NavigationItem creation occurs in this class.
121 scoped_ptr
<std::vector
<BrowserURLRewriter::URLRewriter
>>
122 GetTransientURLRewriters();
124 // Called to reset the transient url rewriter list.
125 void RemoveTransientURLRewriters();
127 // Copy state from |navigation_manager|, including a copy of that object's
128 // CRWSessionController.
129 // TODO(marq): This doesn't deep-copy the SessionEntries in the
130 // CRWSessionController.
131 void CopyState(NavigationManagerImpl
* navigation_manager
);
133 // The primary delegate for this manager.
134 NavigationManagerDelegate
* delegate_
;
136 // The BrowserState that is associated with this instance.
137 BrowserState
* browser_state_
;
139 // CRWSessionController that backs this instance.
140 // TODO(stuartmorgan): Fold CRWSessionController into this class.
141 base::scoped_nsobject
<CRWSessionController
> session_controller_
;
143 // Weak pointer to the facade delegate.
144 NavigationManagerFacadeDelegate
* facade_delegate_
;
146 // List of transient url rewriters added by |AddTransientURLRewriter()|.
147 scoped_ptr
<std::vector
<BrowserURLRewriter::URLRewriter
>>
148 transient_url_rewriters_
;
150 DISALLOW_COPY_AND_ASSIGN(NavigationManagerImpl
);
155 #endif // IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_