OLD | NEW |
---|---|
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 |
(...skipping 29 matching lines...) Expand all Loading... | |
40 bool ContainsIndex(int index) const; | 40 bool ContainsIndex(int index) const; |
41 | 41 |
42 // Returns the WebState at the specified index. It is invalid to call this | 42 // Returns the WebState at the specified index. It is invalid to call this |
43 // with an index such that |ContainsIndex(index)| returns false. | 43 // with an index such that |ContainsIndex(index)| returns false. |
44 web::WebState* GetWebStateAt(int index) const; | 44 web::WebState* GetWebStateAt(int index) const; |
45 | 45 |
46 // Returns the index of the specified WebState or kInvalidIndex if the | 46 // Returns the index of the specified WebState or kInvalidIndex if the |
47 // WebState is not in the model. | 47 // WebState is not in the model. |
48 int GetIndexOfWebState(const web::WebState* web_state) const; | 48 int GetIndexOfWebState(const web::WebState* web_state) const; |
49 | 49 |
50 // Inserts the specified WebState at the specified index. | 50 // Returns the WebState that opened the WebState at the specified index or |
51 void InsertWebState(int index, web::WebState* web_state); | 51 // null if there is no opener on record. |
52 web::WebState* GetOpenerOfWebStateAt(int index) const; | |
53 | |
54 // Returns the index of the next WebState in the sequence of WebStates opened | |
55 // from the specified WebState after |start_index|, or kInvalidIndex if there | |
56 // are no such WebState. If |use_group| is true, the opener's navigation index | |
57 // is used to detect navigation changes within the same session. | |
58 int GetIndexOfNextWebStateOpenedBy(const web::WebState* opener, | |
59 int start_index, | |
60 bool use_group) const; | |
61 | |
62 // Returns the index of the last WebState in the sequence of WebStates opened | |
63 // from the specified WebState after |start_index|, or kInvalidIndex if there | |
64 // are no such WebState. If |use_group| is true, the opener's navigation index | |
65 // is used to detect navigation changes within the same session. | |
66 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, | |
67 int start_index, | |
68 bool use_group) const; | |
69 | |
70 // Inserts the specified WebState at the specified index with an optional | |
71 // opener (null if there is no opener). | |
72 void InsertWebState(int index, | |
73 web::WebState* web_state, | |
74 web::WebState* opener); | |
52 | 75 |
53 // Moves the WebState at the specified index to another index. | 76 // Moves the WebState at the specified index to another index. |
54 void MoveWebStateAt(int from_index, int to_index); | 77 void MoveWebStateAt(int from_index, int to_index); |
55 | 78 |
56 // Replaces the WebState at the specified index with new WebState. Returns | 79 // Replaces the WebState at the specified index with new WebState. Returns |
57 // the old WebState at that index to the caller (abandon ownership of the | 80 // the old WebState at that index to the caller (abandon ownership of the |
58 // returned WebState). | 81 // returned WebState). An optional opener for the new WebState may be passed. |
59 web::WebState* ReplaceWebStateAt(int index, web::WebState* web_state); | 82 web::WebState* ReplaceWebStateAt(int index, |
83 web::WebState* web_state, | |
84 web::WebState* opener); | |
60 | 85 |
61 // Detaches the WebState at the specified index. | 86 // Detaches the WebState at the specified index. |
62 void DetachWebStateAt(int index); | 87 void DetachWebStateAt(int index); |
63 | 88 |
64 // Adds an observer to the model. | 89 // Adds an observer to the model. |
65 void AddObserver(WebStateListObserver* observer); | 90 void AddObserver(WebStateListObserver* observer); |
66 | 91 |
67 // Removes an observer from the model. | 92 // Removes an observer from the model. |
68 void RemoveObserver(WebStateListObserver* observer); | 93 void RemoveObserver(WebStateListObserver* observer); |
69 | 94 |
70 // Invalid index. | 95 // Invalid index. |
71 static const int kInvalidIndex = -1; | 96 static const int kInvalidIndex = -1; |
72 | 97 |
73 private: | 98 private: |
99 // Sets the opener for WebState at the specified index. | |
100 void SetOpenerOfWebStateAt(int index, web::WebState* opener); | |
101 | |
102 // Sets the opener of any WebState that reference the WebState at the | |
103 // specified index to null. | |
104 void FixOpenersReferencing(int index); | |
105 | |
106 // Returns the index of the n-th WebState in the sequence of WebStates opened | |
107 // from the specified WebState after |start_index|, or kInvalidIndex if there | |
108 // are no such WebState. If |use_group| is true, the opener's navigation index | |
109 // is used to detect navigation changes within the same session. | |
110 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, | |
111 int start_index, | |
112 int skip_up_to, | |
marq (ping after 24h)
2017/02/16 15:19:17
Can you document how |skip_up_to| relates to the '
sdefresne
2017/02/16 15:42:01
Renamed the parameter to n as discussed offline, a
| |
113 bool use_group) const; | |
114 | |
74 class WebStateWrapper; | 115 class WebStateWrapper; |
75 const WebStateOwnership web_state_ownership_; | 116 const WebStateOwnership web_state_ownership_; |
76 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; | 117 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; |
77 | 118 |
78 // List of observers notified of changes to the model. | 119 // List of observers notified of changes to the model. |
79 base::ObserverList<WebStateListObserver, true> observers_; | 120 base::ObserverList<WebStateListObserver, true> observers_; |
80 | 121 |
81 DISALLOW_COPY_AND_ASSIGN(WebStateList); | 122 DISALLOW_COPY_AND_ASSIGN(WebStateList); |
82 }; | 123 }; |
83 | 124 |
84 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 125 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
OLD | NEW |