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 // Sets the opener for WebState at the specified index. The |opener| must be |
| 55 // in the WebStateList. |
| 56 void SetOpenerOfWebStateAt(int index, web::WebState* opener); |
| 57 |
| 58 // Returns the index of the next WebState in the sequence of WebStates opened |
| 59 // from the specified WebState after |start_index|, or kInvalidIndex if there |
| 60 // are no such WebState. If |use_group| is true, the opener's navigation index |
| 61 // is used to detect navigation changes within the same session. |
| 62 int GetIndexOfNextWebStateOpenedBy(const web::WebState* opener, |
| 63 int start_index, |
| 64 bool use_group) const; |
| 65 |
| 66 // Returns the index of the last WebState in the sequence of WebStates opened |
| 67 // from the specified WebState after |start_index|, or kInvalidIndex if there |
| 68 // are no such WebState. If |use_group| is true, the opener's navigation index |
| 69 // is used to detect navigation changes within the same session. |
| 70 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, |
| 71 int start_index, |
| 72 bool use_group) const; |
| 73 |
| 74 // Inserts the specified WebState at the specified index with an optional |
| 75 // opener (null if there is no opener). |
| 76 void InsertWebState(int index, |
| 77 web::WebState* web_state, |
| 78 web::WebState* opener); |
52 | 79 |
53 // Moves the WebState at the specified index to another index. | 80 // Moves the WebState at the specified index to another index. |
54 void MoveWebStateAt(int from_index, int to_index); | 81 void MoveWebStateAt(int from_index, int to_index); |
55 | 82 |
56 // Replaces the WebState at the specified index with new WebState. Returns | 83 // 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 | 84 // the old WebState at that index to the caller (abandon ownership of the |
58 // returned WebState). | 85 // returned WebState). An optional opener for the new WebState may be passed. |
59 web::WebState* ReplaceWebStateAt(int index, web::WebState* web_state); | 86 web::WebState* ReplaceWebStateAt(int index, |
| 87 web::WebState* web_state, |
| 88 web::WebState* opener); |
60 | 89 |
61 // Detaches the WebState at the specified index. | 90 // Detaches the WebState at the specified index. |
62 void DetachWebStateAt(int index); | 91 void DetachWebStateAt(int index); |
63 | 92 |
64 // Adds an observer to the model. | 93 // Adds an observer to the model. |
65 void AddObserver(WebStateListObserver* observer); | 94 void AddObserver(WebStateListObserver* observer); |
66 | 95 |
67 // Removes an observer from the model. | 96 // Removes an observer from the model. |
68 void RemoveObserver(WebStateListObserver* observer); | 97 void RemoveObserver(WebStateListObserver* observer); |
69 | 98 |
70 // Invalid index. | 99 // Invalid index. |
71 static const int kInvalidIndex = -1; | 100 static const int kInvalidIndex = -1; |
72 | 101 |
73 private: | 102 private: |
| 103 // Sets the opener of any WebState that reference the WebState at the |
| 104 // specified index to null. |
| 105 void ClearOpenersReferencing(int index); |
| 106 |
| 107 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of |
| 108 // WebStates opened from the specified WebState after |start_index|, or |
| 109 // kInvalidIndex if there are no such WebState. If |use_group| is true, the |
| 110 // opener's navigation index is used to detect navigation changes within the |
| 111 // same session. |
| 112 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, |
| 113 int start_index, |
| 114 bool use_group, |
| 115 int n) const; |
| 116 |
74 class WebStateWrapper; | 117 class WebStateWrapper; |
75 const WebStateOwnership web_state_ownership_; | 118 const WebStateOwnership web_state_ownership_; |
76 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; | 119 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; |
77 | 120 |
78 // List of observers notified of changes to the model. | 121 // List of observers notified of changes to the model. |
79 base::ObserverList<WebStateListObserver, true> observers_; | 122 base::ObserverList<WebStateListObserver, true> observers_; |
80 | 123 |
81 DISALLOW_COPY_AND_ASSIGN(WebStateList); | 124 DISALLOW_COPY_AND_ASSIGN(WebStateList); |
82 }; | 125 }; |
83 | 126 |
84 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 127 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
OLD | NEW |