| 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_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 5 #ifndef IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| 6 #define IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 6 #define IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #import "base/ios/weak_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #import "ios/web/public/web_state/web_state_user_data.h" | 10 #import "ios/web/public/web_state/web_state_user_data.h" |
| 11 | 11 |
| 12 @class Tab; | 12 @class Tab; |
| 13 | 13 |
| 14 // LegacyTabHelper allows to access to the Tab owning a given WebState for | 14 // LegacyTabHelper associates a Tab instance to a WebState object. |
| 15 // interoperability of code using WebStates with legacy code using Tabs. | |
| 16 class LegacyTabHelper : public web::WebStateUserData<LegacyTabHelper> { | 15 class LegacyTabHelper : public web::WebStateUserData<LegacyTabHelper> { |
| 17 public: | 16 public: |
| 18 // Creates the LegacyTabHelper to record the association of |web_state| | 17 // Creates the LegacyTabHelper. This immediately creates the Tab object. |
| 19 // with |tab|. It is an error if |web_state| is already associated with | 18 static void CreateForWebState(web::WebState* web_state); |
| 20 // another Tab. | |
| 21 static void CreateForWebState(web::WebState* web_state, Tab* tab); | |
| 22 | 19 |
| 23 // Returns the Tab associated with |web_state| if it exists or nil. | 20 // Returns the Tab associated with |web_state| or nil. |
| 24 static Tab* GetTabForWebState(web::WebState* web_state); | 21 static Tab* GetTabForWebState(web::WebState* web_state); |
| 25 | 22 |
| 26 private: | 23 private: |
| 27 LegacyTabHelper(web::WebState* web_state, Tab* tab); | 24 explicit LegacyTabHelper(web::WebState* web_state); |
| 28 ~LegacyTabHelper() override; | 25 ~LegacyTabHelper() override; |
| 29 | 26 |
| 30 // The Tab instance associated with the WebState. The Tab currently owns | 27 // The Tab instance associated with the WebState. |
| 31 // the WebState, so this should only be nil between the call to -[Tab close] | 28 base::scoped_nsobject<Tab> tab_; |
| 32 // and the object is deallocated. | |
| 33 base::WeakNSObject<Tab> tab_; | |
| 34 | 29 |
| 35 DISALLOW_COPY_AND_ASSIGN(LegacyTabHelper); | 30 DISALLOW_COPY_AND_ASSIGN(LegacyTabHelper); |
| 36 }; | 31 }; |
| 37 | 32 |
| 38 #endif // IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 33 #endif // IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| OLD | NEW |