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

Side by Side Diff: ios/chrome/browser/web_state_list/web_state_list.h

Issue 2812623002: Revert of [ios] Move WebStateList to ios/chrome/browser/web_state_list. (Closed)
Patch Set: Created 3 years, 8 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
(Empty)
1 // Copyright 2017 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.
4
5 #ifndef IOS_CHROME_BROWSER_WEB_STATE_LIST_WEB_STATE_LIST_H_
6 #define IOS_CHROME_BROWSER_WEB_STATE_LIST_WEB_STATE_LIST_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/observer_list.h"
14 #include "ui/base/page_transition_types.h"
15
16 class WebStateListDelegate;
17 class WebStateListObserver;
18 class WebStateListOrderController;
19 struct WebStateOpener;
20
21 namespace web {
22 class WebState;
23 }
24
25 // Manages a list of WebStates.
26 class WebStateList {
27 public:
28 explicit WebStateList(WebStateListDelegate* delegate);
29 ~WebStateList();
30
31 // Returns whether the model is empty or not.
32 bool empty() const { return web_state_wrappers_.empty(); }
33
34 // Returns the number of WebStates in the model.
35 int count() const { return static_cast<int>(web_state_wrappers_.size()); }
36
37 // Returns the index of the currently active WebState, or kInvalidIndex if
38 // there are no active WebState.
39 int active_index() const { return active_index_; }
40
41 // Returns true if the specified index is contained by the model.
42 bool ContainsIndex(int index) const;
43
44 // Returns the currently active WebState or null if there is none.
45 web::WebState* GetActiveWebState() const;
46
47 // Returns the WebState at the specified index. It is invalid to call this
48 // with an index such that |ContainsIndex(index)| returns false.
49 web::WebState* GetWebStateAt(int index) const;
50
51 // Returns the index of the specified WebState or kInvalidIndex if the
52 // WebState is not in the model.
53 int GetIndexOfWebState(const web::WebState* web_state) const;
54
55 // Returns information about the opener of the WebState at the specified
56 // index. The structure |opener| will be null if there is no opener.
57 WebStateOpener GetOpenerOfWebStateAt(int index) const;
58
59 // Stores information about the opener of the WebState at the specified
60 // index. The WebStateOpener |opener| must be non-null and the WebState
61 // must be in WebStateList.
62 void SetOpenerOfWebStateAt(int index, WebStateOpener opener);
63
64 // Returns the index of the next WebState in the sequence of WebStates opened
65 // from the specified WebState after |start_index|, or kInvalidIndex if there
66 // are no such WebState. If |use_group| is true, the opener's navigation index
67 // is used to detect navigation changes within the same session.
68 int GetIndexOfNextWebStateOpenedBy(const web::WebState* opener,
69 int start_index,
70 bool use_group) const;
71
72 // Returns the index of the last WebState in the sequence of WebStates opened
73 // from the specified WebState after |start_index|, or kInvalidIndex if there
74 // are no such WebState. If |use_group| is true, the opener's navigation index
75 // is used to detect navigation changes within the same session.
76 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener,
77 int start_index,
78 bool use_group) const;
79
80 // Inserts the specified WebState at the specified index.
81 void InsertWebState(int index, std::unique_ptr<web::WebState> web_state);
82
83 // Inserts the specified WebState at the best position in the WebStateList
84 // given the specified transition, opener, etc. It defaults to inserting the
85 // WebState at the end of the list.
86 void AppendWebState(ui::PageTransition transition,
87 std::unique_ptr<web::WebState> web_state,
88 WebStateOpener opener);
89
90 // Moves the WebState at the specified index to another index.
91 void MoveWebStateAt(int from_index, int to_index);
92
93 // Replaces the WebState at the specified index with new WebState. Returns
94 // the old WebState at that index to the caller (abandon ownership of the
95 // returned WebState).
96 std::unique_ptr<web::WebState> ReplaceWebStateAt(
97 int index,
98 std::unique_ptr<web::WebState> web_state);
99
100 // Detaches the WebState at the specified index. Returns the detached WebState
101 // to the caller (abandon ownership of the returned WebState).
102 std::unique_ptr<web::WebState> DetachWebStateAt(int index);
103
104 // Closes and destroys the WebState at the specified index.
105 void CloseWebStateAt(int index);
106
107 // Closes and destroys all WebStates.
108 void CloseAllWebStates();
109
110 // Makes the WebState at the specified index the active WebState.
111 void ActivateWebStateAt(int index);
112
113 // Adds an observer to the model.
114 void AddObserver(WebStateListObserver* observer);
115
116 // Removes an observer from the model.
117 void RemoveObserver(WebStateListObserver* observer);
118
119 // Invalid index.
120 static const int kInvalidIndex = -1;
121
122 private:
123 class WebStateWrapper;
124
125 // Sets the opener of any WebState that reference the WebState at the
126 // specified index to null.
127 void ClearOpenersReferencing(int index);
128
129 // Notify the observers if the active WebState change.
130 void NotifyIfActiveWebStateChanged(web::WebState* old_web_state,
131 bool user_action);
132
133 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of
134 // WebStates opened from the specified WebState after |start_index|, or
135 // kInvalidIndex if there are no such WebState. If |use_group| is true, the
136 // opener's navigation index is used to detect navigation changes within the
137 // same session.
138 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener,
139 int start_index,
140 bool use_group,
141 int n) const;
142
143 // The WebStateList delegate.
144 WebStateListDelegate* delegate_;
145
146 // Wrappers to the WebStates hosted by the WebStateList.
147 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_;
148
149 // An object that determines where new WebState should be inserted and where
150 // selection should move when a WebState is detached.
151 std::unique_ptr<WebStateListOrderController> order_controller_;
152
153 // List of observers notified of changes to the model.
154 base::ObserverList<WebStateListObserver, true> observers_;
155
156 // Index of the currently active WebState, kInvalidIndex if no such WebState.
157 int active_index_ = kInvalidIndex;
158
159 DISALLOW_COPY_AND_ASSIGN(WebStateList);
160 };
161
162 #endif // IOS_CHROME_BROWSER_WEB_STATE_LIST_WEB_STATE_LIST_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/web_state_list/fake_web_state_list_delegate.mm ('k') | ios/chrome/browser/web_state_list/web_state_list.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698