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

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

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Remove Tab -willClose method (Tab implements CRWWebControllerObserver protocol). 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ 5 #ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_
6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ 6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "ui/base/page_transition_types.h" 14 #include "ui/base/page_transition_types.h"
15 15
16 class WebStateListDelegate; 16 class WebStateListDelegate;
17 class WebStateListObserver; 17 class WebStateListObserver;
18 class WebStateListOrderController; 18 class WebStateListOrderController;
19 struct WebStateOpener; 19 struct WebStateOpener;
20 20
21 namespace web { 21 namespace web {
22 class WebState; 22 class WebState;
23 } 23 }
24 24
25 // Manages a list of WebStates. May owns the WebState depending on the ownership 25 // Manages a list of WebStates.
26 // setting (initialised during construction, should eventually always be "owned"
27 // once ownership of Tab is sane, see http://crbug.com/546222 for progress).
28 class WebStateList { 26 class WebStateList {
29 public: 27 public:
30 enum WebStateOwnership { 28 explicit WebStateList(WebStateListDelegate* delegate);
rohitrao (ping after 24h) 2017/04/03 17:49:35 This is potentially a change that could be split o
sdefresne 2017/04/04 13:47:57 When rebasing, I had conflict with code that added
31 WebStateBorrowed,
32 WebStateOwned,
33 };
34
35 WebStateList(WebStateListDelegate* delegate, WebStateOwnership ownership);
36 ~WebStateList(); 29 ~WebStateList();
37 30
38 // Returns whether the model is empty or not. 31 // Returns whether the model is empty or not.
39 bool empty() const { return web_state_wrappers_.empty(); } 32 bool empty() const { return web_state_wrappers_.empty(); }
40 33
41 // Returns the number of WebStates in the model. 34 // Returns the number of WebStates in the model.
42 int count() const { return static_cast<int>(web_state_wrappers_.size()); } 35 int count() const { return static_cast<int>(web_state_wrappers_.size()); }
43 36
44 // Returns the index of the currently active WebState, or kInvalidIndex if 37 // Returns the index of the currently active WebState, or kInvalidIndex if
45 // there are no active WebState. 38 // there are no active WebState.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 71
79 // Returns the index of the last WebState in the sequence of WebStates opened 72 // Returns the index of the last WebState in the sequence of WebStates opened
80 // from the specified WebState after |start_index|, or kInvalidIndex if there 73 // from the specified WebState after |start_index|, or kInvalidIndex if there
81 // are no such WebState. If |use_group| is true, the opener's navigation index 74 // are no such WebState. If |use_group| is true, the opener's navigation index
82 // is used to detect navigation changes within the same session. 75 // is used to detect navigation changes within the same session.
83 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, 76 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener,
84 int start_index, 77 int start_index,
85 bool use_group) const; 78 bool use_group) const;
86 79
87 // Inserts the specified WebState at the specified index. 80 // Inserts the specified WebState at the specified index.
88 void InsertWebState(int index, web::WebState* web_state); 81 void InsertWebState(int index, std::unique_ptr<web::WebState> web_state);
89 82
90 // Inserts the specified WebState at the best position in the WebStateList 83 // Inserts the specified WebState at the best position in the WebStateList
91 // given the specified transition, opener, etc. It defaults to inserting the 84 // given the specified transition, opener, etc. It defaults to inserting the
92 // WebState at the end of the list. 85 // WebState at the end of the list.
93 void AppendWebState(ui::PageTransition transition, 86 void AppendWebState(ui::PageTransition transition,
94 web::WebState* web_state, 87 std::unique_ptr<web::WebState> web_state,
95 WebStateOpener opener); 88 WebStateOpener opener);
96 89
97 // Moves the WebState at the specified index to another index. 90 // Moves the WebState at the specified index to another index.
98 void MoveWebStateAt(int from_index, int to_index); 91 void MoveWebStateAt(int from_index, int to_index);
99 92
100 // Replaces the WebState at the specified index with new WebState. Returns 93 // Replaces the WebState at the specified index with new WebState. Returns
101 // the old WebState at that index to the caller (abandon ownership of the 94 // the old WebState at that index to the caller (abandon ownership of the
102 // returned WebState). 95 // returned WebState).
103 web::WebState* ReplaceWebStateAt(int index, 96 std::unique_ptr<web::WebState> ReplaceWebStateAt(
104 web::WebState* web_state) WARN_UNUSED_RESULT; 97 int index,
98 std::unique_ptr<web::WebState> web_state);
105 99
106 // Detaches the WebState at the specified index. Returns the detached WebState 100 // Detaches the WebState at the specified index. Returns the detached WebState
107 // to the caller (abandon ownership of the returned WebState). 101 // to the caller (abandon ownership of the returned WebState).
108 web::WebState* DetachWebStateAt(int index) WARN_UNUSED_RESULT; 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 109
110 // Makes the WebState at the specified index the active WebState. 110 // Makes the WebState at the specified index the active WebState.
111 void ActivateWebStateAt(int index); 111 void ActivateWebStateAt(int index);
112 112
113 // Adds an observer to the model. 113 // Adds an observer to the model.
114 void AddObserver(WebStateListObserver* observer); 114 void AddObserver(WebStateListObserver* observer);
115 115
116 // Removes an observer from the model. 116 // Removes an observer from the model.
117 void RemoveObserver(WebStateListObserver* observer); 117 void RemoveObserver(WebStateListObserver* observer);
118 118
(...skipping 17 matching lines...) Expand all
136 // opener's navigation index is used to detect navigation changes within the 136 // opener's navigation index is used to detect navigation changes within the
137 // same session. 137 // same session.
138 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, 138 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener,
139 int start_index, 139 int start_index,
140 bool use_group, 140 bool use_group,
141 int n) const; 141 int n) const;
142 142
143 // The WebStateList delegate. 143 // The WebStateList delegate.
144 WebStateListDelegate* delegate_; 144 WebStateListDelegate* delegate_;
145 145
146 // Whether this WebStateList owns the WebState it hosts.
147 // TODO(crbug.com/546222): remove once this is always "owned".
148 const WebStateOwnership web_state_ownership_;
149
150 // Wrappers to the WebStates hosted by the WebStateList. 146 // Wrappers to the WebStates hosted by the WebStateList.
151 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; 147 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_;
152 148
153 // An object that determines where new WebState should be inserted and where 149 // An object that determines where new WebState should be inserted and where
154 // selection should move when a WebState is detached. 150 // selection should move when a WebState is detached.
155 std::unique_ptr<WebStateListOrderController> order_controller_; 151 std::unique_ptr<WebStateListOrderController> order_controller_;
156 152
157 // List of observers notified of changes to the model. 153 // List of observers notified of changes to the model.
158 base::ObserverList<WebStateListObserver, true> observers_; 154 base::ObserverList<WebStateListObserver, true> observers_;
159 155
160 // Index of the currently active WebState, kInvalidIndex if no such WebState. 156 // Index of the currently active WebState, kInvalidIndex if no such WebState.
161 int active_index_ = kInvalidIndex; 157 int active_index_ = kInvalidIndex;
162 158
163 DISALLOW_COPY_AND_ASSIGN(WebStateList); 159 DISALLOW_COPY_AND_ASSIGN(WebStateList);
164 }; 160 };
165 161
166 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ 162 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698