| 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 WebStateListObserver; | 17 class WebStateListObserver; |
| 17 class WebStateListOrderController; | 18 class WebStateListOrderController; |
| 18 | 19 |
| 19 namespace web { | 20 namespace web { |
| 20 class WebState; | 21 class WebState; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // Manages a list of WebStates. May owns the WebState depending on the ownership | 24 // Manages a list of WebStates. May owns the WebState depending on the ownership |
| 24 // setting (initialised during construction, should eventually always be "owned" | 25 // setting (initialised during construction, should eventually always be "owned" |
| 25 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). | 26 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). |
| 26 class WebStateList { | 27 class WebStateList { |
| 27 public: | 28 public: |
| 28 enum WebStateOwnership { | 29 enum WebStateOwnership { |
| 29 WebStateBorrowed, | 30 WebStateBorrowed, |
| 30 WebStateOwned, | 31 WebStateOwned, |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); | 34 WebStateList(WebStateListDelegate* delegate, WebStateOwnership ownership); |
| 34 ~WebStateList(); | 35 ~WebStateList(); |
| 35 | 36 |
| 36 // Returns whether the model is empty or not. | 37 // Returns whether the model is empty or not. |
| 37 bool empty() const { return web_state_wrappers_.empty(); } | 38 bool empty() const { return web_state_wrappers_.empty(); } |
| 38 | 39 |
| 39 // Returns the number of WebStates in the model. | 40 // Returns the number of WebStates in the model. |
| 40 int count() const { return static_cast<int>(web_state_wrappers_.size()); } | 41 int count() const { return static_cast<int>(web_state_wrappers_.size()); } |
| 41 | 42 |
| 42 // Returns the index of the currently active WebState, or kInvalidIndex if | 43 // Returns the index of the currently active WebState, or kInvalidIndex if |
| 43 // there are no active WebState. | 44 // there are no active WebState. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Adds an observer to the model. | 115 // Adds an observer to the model. |
| 115 void AddObserver(WebStateListObserver* observer); | 116 void AddObserver(WebStateListObserver* observer); |
| 116 | 117 |
| 117 // Removes an observer from the model. | 118 // Removes an observer from the model. |
| 118 void RemoveObserver(WebStateListObserver* observer); | 119 void RemoveObserver(WebStateListObserver* observer); |
| 119 | 120 |
| 120 // Invalid index. | 121 // Invalid index. |
| 121 static const int kInvalidIndex = -1; | 122 static const int kInvalidIndex = -1; |
| 122 | 123 |
| 123 private: | 124 private: |
| 125 class WebStateWrapper; |
| 126 |
| 124 // Sets the opener of any WebState that reference the WebState at the | 127 // Sets the opener of any WebState that reference the WebState at the |
| 125 // specified index to null. | 128 // specified index to null. |
| 126 void ClearOpenersReferencing(int index); | 129 void ClearOpenersReferencing(int index); |
| 127 | 130 |
| 128 // Notify the observers if the active WebState change. | 131 // Notify the observers if the active WebState change. |
| 129 void NotifyIfActiveWebStateChanged(web::WebState* old_web_state, | 132 void NotifyIfActiveWebStateChanged(web::WebState* old_web_state, |
| 130 bool user_action); | 133 bool user_action); |
| 131 | 134 |
| 132 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of | 135 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of |
| 133 // WebStates opened from the specified WebState after |start_index|, or | 136 // WebStates opened from the specified WebState after |start_index|, or |
| 134 // kInvalidIndex if there are no such WebState. If |use_group| is true, the | 137 // kInvalidIndex if there are no such WebState. If |use_group| is true, the |
| 135 // opener's navigation index is used to detect navigation changes within the | 138 // opener's navigation index is used to detect navigation changes within the |
| 136 // same session. | 139 // same session. |
| 137 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, | 140 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, |
| 138 int start_index, | 141 int start_index, |
| 139 bool use_group, | 142 bool use_group, |
| 140 int n) const; | 143 int n) const; |
| 141 | 144 |
| 142 class WebStateWrapper; | 145 // The WebStateList delegate. |
| 146 WebStateListDelegate* delegate_; |
| 147 |
| 148 // Whether this WebStateList owns the WebState it hosts. |
| 149 // TODO(crbug.com/546222): remove once this is always "owned". |
| 143 const WebStateOwnership web_state_ownership_; | 150 const WebStateOwnership web_state_ownership_; |
| 151 |
| 152 // Wrappers to the WebStates hosted by the WebStateList. |
| 144 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; | 153 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; |
| 145 | 154 |
| 146 // An object that determines where new WebState should be inserted and where | 155 // An object that determines where new WebState should be inserted and where |
| 147 // selection should move when a WebState is detached. | 156 // selection should move when a WebState is detached. |
| 148 std::unique_ptr<WebStateListOrderController> order_controller_; | 157 std::unique_ptr<WebStateListOrderController> order_controller_; |
| 149 | 158 |
| 150 // List of observers notified of changes to the model. | 159 // List of observers notified of changes to the model. |
| 151 base::ObserverList<WebStateListObserver, true> observers_; | 160 base::ObserverList<WebStateListObserver, true> observers_; |
| 152 | 161 |
| 153 // Index of the currently active WebState, kInvalidIndex if no such WebState. | 162 // Index of the currently active WebState, kInvalidIndex if no such WebState. |
| 154 int active_index_ = kInvalidIndex; | 163 int active_index_ = kInvalidIndex; |
| 155 | 164 |
| 156 DISALLOW_COPY_AND_ASSIGN(WebStateList); | 165 DISALLOW_COPY_AND_ASSIGN(WebStateList); |
| 157 }; | 166 }; |
| 158 | 167 |
| 159 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 168 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
| OLD | NEW |