Add ICU message format support
[chromium-blink-merge.git] / ios / web / navigation / navigation_manager_impl.h
blobc644f5148349259e84f053043d0eb17b235d2706
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_
8 #include <vector>
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"
15 #include "url/gurl.h"
17 @class CRWSessionController;
18 @class CRWSessionEntry;
20 namespace web {
21 class BrowserState;
22 class NavigationItem;
23 struct Referrer;
24 class NavigationManagerDelegate;
25 class NavigationManagerFacadeDelegate;
27 // Implementation of NavigationManager.
28 // Generally mirrors upstream's NavigationController.
29 class NavigationManagerImpl : public NavigationManager {
30 public:
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
42 // logic into it.
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
49 // none.
50 void InitializeSession(NSString* window_name,
51 NSString* opener_id,
52 BOOL opened_by_dom,
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,
59 int current_index);
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
67 // into this layer.
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 // Returns the committed NavigationItem at |index|.
77 NavigationItem* GetItemAtIndex(size_t index) const;
79 // Temporary accessors and content/ class pass-throughs.
80 // TODO(stuartmorgan): Re-evaluate this list once the refactorings have
81 // settled down.
82 CRWSessionController* GetSessionController();
83 int GetCurrentEntryIndex() const;
84 int GetLastCommittedEntryIndex() const;
85 int GetEntryCount() const;
86 bool RemoveEntryAtIndex(int index);
87 void DiscardNonCommittedEntries();
88 int GetPendingEntryIndex() const;
89 void LoadURL(const GURL& url,
90 const Referrer& referrer,
91 ui::PageTransition type);
92 bool CanGoBack() const;
93 bool CanGoForward() const;
94 void GoBack();
95 void GoForward();
97 // Convenience accessors to get the underlying NavigationItems from the
98 // SessionEntries returned from |session_controller_|'s -lastUserEntry and
99 // -previousEntry methods.
100 // TODO(marq):Evaluate the long-term utility of these methods.
101 NavigationItem* GetLastUserItem() const;
102 NavigationItem* GetPreviousItem() const;
104 // Temporary method. Returns a vector of NavigationItems corresponding to
105 // the SessionEntries of the uderlying CRWSessionController.
106 // TOOD(marq): Remove this method and unfork its caller,
107 // TabRestoreServiceHelper::PopulateTab
108 std::vector<NavigationItem*> GetItems();
110 // NavigationManager:
111 BrowserState* GetBrowserState() const override;
112 WebState* GetWebState() const override;
113 NavigationItem* GetVisibleItem() const override;
114 NavigationItem* GetLastCommittedItem() const override;
115 NavigationItem* GetPendingItem() const override;
116 void AddTransientURLRewriter(
117 BrowserURLRewriter::URLRewriter rewriter) override;
119 // Returns the current list of transient url rewriters, passing ownership to
120 // the caller.
121 // TODO(kkhorimoto): remove once NavigationItem creation occurs in this class.
122 scoped_ptr<std::vector<BrowserURLRewriter::URLRewriter>>
123 GetTransientURLRewriters();
125 // Called to reset the transient url rewriter list.
126 void RemoveTransientURLRewriters();
128 // Copy state from |navigation_manager|, including a copy of that object's
129 // CRWSessionController.
130 // TODO(marq): This doesn't deep-copy the SessionEntries in the
131 // CRWSessionController.
132 void CopyState(NavigationManagerImpl* navigation_manager);
133 private:
134 // The primary delegate for this manager.
135 NavigationManagerDelegate* delegate_;
137 // The BrowserState that is associated with this instance.
138 BrowserState* browser_state_;
140 // CRWSessionController that backs this instance.
141 // TODO(stuartmorgan): Fold CRWSessionController into this class.
142 base::scoped_nsobject<CRWSessionController> session_controller_;
144 // Weak pointer to the facade delegate.
145 NavigationManagerFacadeDelegate* facade_delegate_;
147 // List of transient url rewriters added by |AddTransientURLRewriter()|.
148 scoped_ptr<std::vector<BrowserURLRewriter::URLRewriter>>
149 transient_url_rewriters_;
151 DISALLOW_COPY_AND_ASSIGN(NavigationManagerImpl);
154 } // namespace web
156 #endif // IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_