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 |
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 | 20 |
20 namespace web { | 21 namespace web { |
21 class WebState; | 22 class WebState; |
22 } | 23 } |
23 | 24 |
24 // Manages a list of WebStates. May owns the WebState depending on the ownership | 25 // Manages a list of WebStates. May owns the WebState depending on the ownership |
25 // setting (initialised during construction, should eventually always be "owned" | 26 // setting (initialised during construction, should eventually always be "owned" |
26 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). | 27 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). |
27 class WebStateList { | 28 class WebStateList { |
28 public: | 29 public: |
(...skipping 22 matching lines...) Expand all Loading... |
51 web::WebState* GetActiveWebState() const; | 52 web::WebState* GetActiveWebState() const; |
52 | 53 |
53 // Returns the WebState at the specified index. It is invalid to call this | 54 // Returns the WebState at the specified index. It is invalid to call this |
54 // with an index such that |ContainsIndex(index)| returns false. | 55 // with an index such that |ContainsIndex(index)| returns false. |
55 web::WebState* GetWebStateAt(int index) const; | 56 web::WebState* GetWebStateAt(int index) const; |
56 | 57 |
57 // Returns the index of the specified WebState or kInvalidIndex if the | 58 // Returns the index of the specified WebState or kInvalidIndex if the |
58 // WebState is not in the model. | 59 // WebState is not in the model. |
59 int GetIndexOfWebState(const web::WebState* web_state) const; | 60 int GetIndexOfWebState(const web::WebState* web_state) const; |
60 | 61 |
61 // Returns the WebState that opened the WebState at the specified index or | 62 // Returns information about the opener of the WebState at the specified |
62 // null if there is no opener on record. | 63 // index. The structure |opener| will be null if there is no opener. |
63 web::WebState* GetOpenerOfWebStateAt(int index) const; | 64 WebStateOpener GetOpenerOfWebStateAt(int index) const; |
64 | 65 |
65 // Sets the opener for WebState at the specified index. The |opener| must be | 66 // Stores information about the opener of the WebState at the specified |
66 // in the WebStateList. | 67 // index. The WebStateOpener |opener| must be non-null and the WebState |
67 void SetOpenerOfWebStateAt(int index, web::WebState* opener); | 68 // must be in WebStateList. |
| 69 void SetOpenerOfWebStateAt(int index, WebStateOpener opener); |
68 | 70 |
69 // Returns the index of the next WebState in the sequence of WebStates opened | 71 // Returns the index of the next WebState in the sequence of WebStates opened |
70 // from the specified WebState after |start_index|, or kInvalidIndex if there | 72 // from the specified WebState after |start_index|, or kInvalidIndex if there |
71 // are no such WebState. If |use_group| is true, the opener's navigation index | 73 // are no such WebState. If |use_group| is true, the opener's navigation index |
72 // is used to detect navigation changes within the same session. | 74 // is used to detect navigation changes within the same session. |
73 int GetIndexOfNextWebStateOpenedBy(const web::WebState* opener, | 75 int GetIndexOfNextWebStateOpenedBy(const web::WebState* opener, |
74 int start_index, | 76 int start_index, |
75 bool use_group) const; | 77 bool use_group) const; |
76 | 78 |
77 // Returns the index of the last WebState in the sequence of WebStates opened | 79 // Returns the index of the last WebState in the sequence of WebStates opened |
78 // from the specified WebState after |start_index|, or kInvalidIndex if there | 80 // from the specified WebState after |start_index|, or kInvalidIndex if there |
79 // are no such WebState. If |use_group| is true, the opener's navigation index | 81 // are no such WebState. If |use_group| is true, the opener's navigation index |
80 // is used to detect navigation changes within the same session. | 82 // is used to detect navigation changes within the same session. |
81 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, | 83 int GetIndexOfLastWebStateOpenedBy(const web::WebState* opener, |
82 int start_index, | 84 int start_index, |
83 bool use_group) const; | 85 bool use_group) const; |
84 | 86 |
85 // Inserts the specified WebState at the specified index with an optional | 87 // Inserts the specified WebState at the specified index. |
86 // opener (null if there is no opener). | 88 void InsertWebState(int index, web::WebState* web_state); |
87 void InsertWebState(int index, | |
88 web::WebState* web_state, | |
89 web::WebState* opener); | |
90 | 89 |
91 // Inserts the specified WebState at the best position in the WebStateList | 90 // Inserts the specified WebState at the best position in the WebStateList |
92 // given the specified transition, opener (optional, may be null), etc. It | 91 // given the specified transition, opener, etc. It defaults to inserting the |
93 // defaults to inserting the WebState at the end of the list. | 92 // WebState at the end of the list. |
94 void AppendWebState(ui::PageTransition transition, | 93 void AppendWebState(ui::PageTransition transition, |
95 web::WebState* web_state, | 94 web::WebState* web_state, |
96 web::WebState* opener); | 95 WebStateOpener opener); |
97 | 96 |
98 // Moves the WebState at the specified index to another index. | 97 // Moves the WebState at the specified index to another index. |
99 void MoveWebStateAt(int from_index, int to_index); | 98 void MoveWebStateAt(int from_index, int to_index); |
100 | 99 |
101 // Replaces the WebState at the specified index with new WebState. Returns | 100 // Replaces the WebState at the specified index with new WebState. Returns |
102 // the old WebState at that index to the caller (abandon ownership of the | 101 // the old WebState at that index to the caller (abandon ownership of the |
103 // returned WebState). An optional opener for the new WebState may be passed. | 102 // returned WebState). |
104 web::WebState* ReplaceWebStateAt(int index, | 103 web::WebState* ReplaceWebStateAt(int index, |
105 web::WebState* web_state, | 104 web::WebState* web_state) WARN_UNUSED_RESULT; |
106 web::WebState* opener) WARN_UNUSED_RESULT; | |
107 | 105 |
108 // Detaches the WebState at the specified index. Returns the detached WebState | 106 // Detaches the WebState at the specified index. Returns the detached WebState |
109 // to the caller (abandon ownership of the returned WebState). | 107 // to the caller (abandon ownership of the returned WebState). |
110 web::WebState* DetachWebStateAt(int index) WARN_UNUSED_RESULT; | 108 web::WebState* DetachWebStateAt(int index) WARN_UNUSED_RESULT; |
111 | 109 |
112 // Makes the WebState at the specified index the active WebState. | 110 // Makes the WebState at the specified index the active WebState. |
113 void ActivateWebStateAt(int index); | 111 void ActivateWebStateAt(int index); |
114 | 112 |
115 // Adds an observer to the model. | 113 // Adds an observer to the model. |
116 void AddObserver(WebStateListObserver* observer); | 114 void AddObserver(WebStateListObserver* observer); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // List of observers notified of changes to the model. | 157 // List of observers notified of changes to the model. |
160 base::ObserverList<WebStateListObserver, true> observers_; | 158 base::ObserverList<WebStateListObserver, true> observers_; |
161 | 159 |
162 // Index of the currently active WebState, kInvalidIndex if no such WebState. | 160 // Index of the currently active WebState, kInvalidIndex if no such WebState. |
163 int active_index_ = kInvalidIndex; | 161 int active_index_ = kInvalidIndex; |
164 | 162 |
165 DISALLOW_COPY_AND_ASSIGN(WebStateList); | 163 DISALLOW_COPY_AND_ASSIGN(WebStateList); |
166 }; | 164 }; |
167 | 165 |
168 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 166 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
OLD | NEW |