Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: ios/web/navigation/navigation_manager_impl.h

Issue 2944093002: Extract NavigationManagerImpl interface for navigation experiment. (Closed)
Patch Set: Patch for landing Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_ 5 #ifndef IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_
6 #define IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_ 6 #define IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #import "base/mac/scoped_nsobject.h" 13 #import "base/mac/scoped_nsobject.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #import "ios/web/navigation/navigation_item_impl.h"
15 #import "ios/web/public/navigation_item_list.h" 16 #import "ios/web/public/navigation_item_list.h"
16 #import "ios/web/public/navigation_manager.h" 17 #import "ios/web/public/navigation_manager.h"
17 #include "ios/web/public/reload_type.h" 18 #include "ios/web/public/reload_type.h"
18 #include "ui/base/page_transition_types.h" 19 #include "ui/base/page_transition_types.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 @class CRWSessionController; 22 @class CRWSessionController;
22 23
23 namespace web { 24 namespace web {
24 class BrowserState; 25 class BrowserState;
25 class NavigationItem; 26 class NavigationItem;
26 struct Referrer;
27 class NavigationManagerDelegate; 27 class NavigationManagerDelegate;
28 class SessionStorageBuilder; 28 class SessionStorageBuilder;
29 29
30 // Defines the ways how a pending navigation can be initiated. 30 // Defines the ways how a pending navigation can be initiated.
31 enum class NavigationInitiationType { 31 enum class NavigationInitiationType {
32 // Navigation initiation type is only valid for pending navigations, use NONE 32 // Navigation initiation type is only valid for pending navigations, use NONE
33 // if a navigation is already committed. 33 // if a navigation is already committed.
34 NONE = 0, 34 NONE = 0,
35 35
36 // Navigation was initiated by actual user action. 36 // Navigation was initiated by actual user action.
37 USER_INITIATED, 37 USER_INITIATED,
38 38
39 // Navigation was initiated by renderer. Examples of renderer-initiated 39 // Navigation was initiated by renderer. Examples of renderer-initiated
40 // navigations include: 40 // navigations include:
41 // * <a> link click 41 // * <a> link click
42 // * changing window.location.href 42 // * changing window.location.href
43 // * redirect via the <meta http-equiv="refresh"> tag 43 // * redirect via the <meta http-equiv="refresh"> tag
44 // * using window.history.pushState 44 // * using window.history.pushState
45 RENDERER_INITIATED, 45 RENDERER_INITIATED,
46 }; 46 };
47 47
48 // Implementation of NavigationManager. 48 // Implementation of NavigationManager.
49 // Generally mirrors upstream's NavigationController. 49 // Generally mirrors upstream's NavigationController.
50 class NavigationManagerImpl : public NavigationManager { 50 class NavigationManagerImpl : public NavigationManager {
51 public: 51 public:
52 NavigationManagerImpl(); 52 ~NavigationManagerImpl() override {}
53 ~NavigationManagerImpl() override;
54 53
55 // Setters for NavigationManagerDelegate and BrowserState. 54 // Setters for NavigationManagerDelegate and BrowserState.
56 void SetDelegate(NavigationManagerDelegate* delegate); 55 virtual void SetDelegate(NavigationManagerDelegate* delegate) = 0;
57 void SetBrowserState(BrowserState* browser_state); 56 virtual void SetBrowserState(BrowserState* browser_state) = 0;
58 57
59 // Sets the CRWSessionController that backs this object. 58 // Sets the CRWSessionController that backs this object.
60 // Keeps a strong reference to |session_controller|. 59 // Keeps a strong reference to |session_controller|.
61 // This method should only be called when deserializing |session_controller| 60 // This method should only be called when deserializing |session_controller|
62 // and joining it with its NavigationManager. Other cases should call 61 // and joining it with its NavigationManager. Other cases should call
63 // InitializeSession() or ReplaceSessionHistory(). 62 // InitializeSession() or ReplaceSessionHistory().
64 // TODO(stuartmorgan): Also move deserialization of CRWSessionControllers 63 // TODO(stuartmorgan): Also move deserialization of CRWSessionControllers
65 // under the control of this class, and move the bulk of CRWSessionController 64 // under the control of this class, and move the bulk of CRWSessionController
66 // logic into it. 65 // logic into it.
67 void SetSessionController(CRWSessionController* session_controller); 66 virtual void SetSessionController(
67 CRWSessionController* session_controller) = 0;
68 68
69 // Initializes a new session history. 69 // Initializes a new session history.
70 void InitializeSession(); 70 virtual void InitializeSession() = 0;
71 71
72 // Replace the session history with a new one, where |items| is the 72 // Replace the session history with a new one, where |items| is the
73 // complete set of navigation items in the new history, and |current_index| 73 // complete set of navigation items in the new history, and |current_index|
74 // is the index of the currently active item. 74 // is the index of the currently active item.
75 void ReplaceSessionHistory(std::vector<std::unique_ptr<NavigationItem>> items, 75 virtual void ReplaceSessionHistory(
76 int current_index); 76 std::vector<std::unique_ptr<NavigationItem>> items,
77 int current_index) = 0;
77 78
78 // Helper functions for notifying WebStateObservers of changes. 79 // Helper functions for notifying WebStateObservers of changes.
79 // TODO(stuartmorgan): Make these private once the logic triggering them moves 80 // TODO(stuartmorgan): Make these private once the logic triggering them moves
80 // into this layer. 81 // into this layer.
81 void OnNavigationItemsPruned(size_t pruned_item_count); 82 virtual void OnNavigationItemsPruned(size_t pruned_item_count) = 0;
82 void OnNavigationItemChanged(); 83 virtual void OnNavigationItemChanged() = 0;
83 void OnNavigationItemCommitted(); 84 virtual void OnNavigationItemCommitted() = 0;
84 85
85 // Temporary accessors and content/ class pass-throughs. 86 // Temporary accessors and content/ class pass-throughs.
86 // TODO(stuartmorgan): Re-evaluate this list once the refactorings have 87 // TODO(stuartmorgan): Re-evaluate this list once the refactorings have
87 // settled down. 88 // settled down.
88 CRWSessionController* GetSessionController(); 89 virtual CRWSessionController* GetSessionController() const = 0;
89 90
90 // Adds a transient item with the given URL. A transient item will be 91 // Adds a transient item with the given URL. A transient item will be
91 // discarded on any navigation. 92 // discarded on any navigation.
92 void AddTransientItem(const GURL& url); 93 virtual void AddTransientItem(const GURL& url) = 0;
93 94
94 // Adds a new item with the given url, referrer, navigation type, initiation 95 // Adds a new item with the given url, referrer, navigation type, initiation
95 // type and user agent override option, making it the pending item. If pending 96 // type and user agent override option, making it the pending item. If pending
96 // item is the same as the current item, this does nothing. |referrer| may be 97 // item is the same as the current item, this does nothing. |referrer| may be
97 // nil if there isn't one. The item starts out as pending, and will be lost 98 // nil if there isn't one. The item starts out as pending, and will be lost
98 // unless |-commitPendingItem| is called. 99 // unless |-commitPendingItem| is called.
99 void AddPendingItem(const GURL& url, 100 virtual void AddPendingItem(
100 const web::Referrer& referrer, 101 const GURL& url,
101 ui::PageTransition navigation_type, 102 const web::Referrer& referrer,
102 NavigationInitiationType initiation_type, 103 ui::PageTransition navigation_type,
103 UserAgentOverrideOption user_agent_override_option); 104 NavigationInitiationType initiation_type,
105 UserAgentOverrideOption user_agent_override_option) = 0;
104 106
105 // Commits the pending item, if any. 107 // Commits the pending item, if any.
106 void CommitPendingItem(); 108 virtual void CommitPendingItem() = 0;
107
108 // NavigationManager:
109 BrowserState* GetBrowserState() const override;
110 WebState* GetWebState() const override;
111 NavigationItem* GetVisibleItem() const override;
112 NavigationItem* GetLastCommittedItem() const override;
113 NavigationItem* GetPendingItem() const override;
114 NavigationItem* GetTransientItem() const override;
115 void DiscardNonCommittedItems() override;
116 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override;
117 void AddTransientURLRewriter(
118 BrowserURLRewriter::URLRewriter rewriter) override;
119 int GetItemCount() const override;
120 NavigationItem* GetItemAtIndex(size_t index) const override;
121 int GetIndexOfItem(const NavigationItem* item) const override;
122 int GetPendingItemIndex() const override;
123 int GetLastCommittedItemIndex() const override;
124 bool RemoveItemAtIndex(int index) override;
125 bool CanGoBack() const override;
126 bool CanGoForward() const override;
127 bool CanGoToOffset(int offset) const override;
128 void GoBack() override;
129 void GoForward() override;
130 void GoToIndex(int index) override;
131 void Reload(ReloadType reload_type, bool check_for_reposts) override;
132 NavigationItemList GetBackwardItems() const override;
133 NavigationItemList GetForwardItems() const override;
134 void CopyStateFromAndPrune(const NavigationManager* source) override;
135 bool CanPruneAllButLastCommittedItem() const override;
136 109
137 // Returns the current list of transient url rewriters, passing ownership to 110 // Returns the current list of transient url rewriters, passing ownership to
138 // the caller. 111 // the caller.
139 // TODO(crbug.com/546197): remove once NavigationItem creation occurs in this 112 // TODO(crbug.com/546197): remove once NavigationItem creation occurs in this
140 // class. 113 // class.
141 std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>> 114 virtual std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>>
142 GetTransientURLRewriters(); 115 GetTransientURLRewriters() = 0;
143 116
144 // Called to reset the transient url rewriter list. 117 // Called to reset the transient url rewriter list.
145 void RemoveTransientURLRewriters(); 118 virtual void RemoveTransientURLRewriters() = 0;
146 119
147 // Returns the navigation index that differs from the current item (or pending 120 // Returns the navigation index that differs from the current item (or pending
148 // item if it exists) by the specified |offset|, skipping redirect navigation 121 // item if it exists) by the specified |offset|, skipping redirect navigation
149 // items. The index returned is not guaranteed to be valid. 122 // items. The index returned is not guaranteed to be valid.
150 // TODO(crbug.com/661316): Make this method private once navigation code is 123 // TODO(crbug.com/661316): Make this method private once navigation code is
151 // moved from CRWWebController to NavigationManagerImpl. 124 // moved from CRWWebController to NavigationManagerImpl.
152 int GetIndexForOffset(int offset) const; 125 virtual int GetIndexForOffset(int offset) const = 0;
153 126
154 private: 127 protected:
155 // The SessionStorageBuilder functions require access to private variables of 128 // The SessionStorageBuilder functions require access to private variables of
156 // NavigationManagerImpl. 129 // NavigationManagerImpl.
157 friend SessionStorageBuilder; 130 friend SessionStorageBuilder;
158 131
159 // Returns true if the PageTransition for the underlying navigation item at 132 // Identical to GetItemAtIndex() but returns the underlying NavigationItemImpl
160 // |index| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. 133 // instead of the public NavigationItem interface. This is used by
161 bool IsRedirectItemAtIndex(int index) const; 134 // SessionStorageBuilder to persist session state.
135 virtual NavigationItemImpl* GetNavigationItemImplAtIndex(
136 size_t index) const = 0;
162 137
163 // Returns the most recent NavigationItem that does not have an app-specific 138 // Returns the index of the previous item. Only used by SessionStorageBuilder.
164 // URL. 139 virtual size_t GetPreviousItemIndex() const = 0;
165 NavigationItem* GetLastCommittedNonAppSpecificItem() const;
166
167 // The primary delegate for this manager.
168 NavigationManagerDelegate* delegate_;
169
170 // The BrowserState that is associated with this instance.
171 BrowserState* browser_state_;
172
173 // CRWSessionController that backs this instance.
174 // TODO(stuartmorgan): Fold CRWSessionController into this class.
175 base::scoped_nsobject<CRWSessionController> session_controller_;
176
177 // List of transient url rewriters added by |AddTransientURLRewriter()|.
178 std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>>
179 transient_url_rewriters_;
180
181 DISALLOW_COPY_AND_ASSIGN(NavigationManagerImpl);
182 }; 140 };
183 141
184 } // namespace web 142 } // namespace web
185 143
186 #endif // IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_ 144 #endif // IOS_WEB_NAVIGATION_NAVIGATION_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « ios/web/navigation/legacy_navigation_manager_impl.mm ('k') | ios/web/navigation/navigation_manager_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698