Commit 294074dc authored by mrefaat's avatar mrefaat Committed by Commit Bot

[IOS Tab Refactoring] Remove TabModel as a member of Tab

Update TabModelWebStateListDelegate so it doesn't need TabModel
 object as there is no need to set parentModel for the tab anymore.

Bug: 899839, 228575
Change-Id: I68ff2d4672423b36fbbb171d9f183f3506d39be5
Reviewed-on: https://chromium-review.googlesource.com/c/1320792
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611406}
parent 75a4dd59
......@@ -26,7 +26,6 @@ class GURL;
@class FormSuggestionController;
@protocol TabDialogDelegate;
@class Tab;
@class TabModel;
namespace ios {
class ChromeBrowserState;
......@@ -103,11 +102,6 @@ extern NSString* const kProxyPassthroughHeaderValue;
- (instancetype)init NS_UNAVAILABLE;
// Sets the parent tab model for this tab. Can only be called if the tab does
// not already have a parent tab model set.
// TODO(crbug.com/228575): Create a delegate interface and remove this.
- (void)setParentTabModel:(TabModel*)model;
// The view that generates print data when printing. It can be nil when printing
// is not supported with this tab. It can be different from |Tab view|.
- (UIView*)viewForPrinting;
......
......@@ -58,7 +58,6 @@
#import "ios/chrome/browser/tabs/legacy_tab_helper.h"
#import "ios/chrome/browser/tabs/tab_dialog_delegate.h"
#import "ios/chrome/browser/tabs/tab_helper_util.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/tabs/tab_private.h"
#include "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/u2f/u2f_controller.h"
......@@ -121,7 +120,6 @@ NSString* const kTabClosingCurrentDocumentNotificationForCrashReporting =
NSString* const kTabUrlKey = @"url";
@interface Tab ()<CRWWebStateObserver> {
__weak TabModel* _parentTabModel;
ios::ChromeBrowserState* _browserState;
OpenInController* _openInController;
......@@ -262,11 +260,6 @@ NSString* const kTabUrlKey = @"url";
#pragma mark - Public API
- (void)setParentTabModel:(TabModel*)model {
DCHECK(!model || !_parentTabModel);
_parentTabModel = model;
}
- (UIView*)viewForPrinting {
return self.webController.viewForPrinting;
}
......@@ -446,10 +439,6 @@ NSString* const kTabUrlKey = @"url";
@implementation Tab (TestingSupport)
- (TabModel*)parentTabModel {
return _parentTabModel;
}
// TODO(crbug.com/620465): this require the Tab's WebState to be a WebStateImpl,
// remove this helper once this is no longer true (and fix the unit tests).
- (CRWWebController*)webController {
......
......@@ -328,8 +328,7 @@ void RecordMainFrameNavigationMetric(web::WebState* web_state) {
if ((self = [super init])) {
_observers = [TabModelObservers observers];
_webStateListDelegate =
std::make_unique<TabModelWebStateListDelegate>(self);
_webStateListDelegate = std::make_unique<TabModelWebStateListDelegate>();
_webStateList = std::make_unique<WebStateList>(_webStateListDelegate.get());
_browserState = browserState;
......
......@@ -688,20 +688,6 @@ TEST_P(TabModelTest, MoveTabs) {
[tab_model_ removeObserver:tab_model_observer];
}
TEST_P(TabModelTest, ParentTabModel) {
std::unique_ptr<web::WebState> web_state = web::WebState::Create(
web::WebState::CreateParams(chrome_browser_state_.get()));
AttachTabHelpers(web_state.get(), /*for_prerender=*/false);
Tab* tab = LegacyTabHelper::GetTabForWebState(web_state.get());
EXPECT_NSEQ(nil, [tab parentTabModel]);
[tab_model_ webStateList]->InsertWebState(0, std::move(web_state),
WebStateList::INSERT_FORCE_INDEX,
WebStateOpener());
EXPECT_NSEQ(tab_model_, [tab parentTabModel]);
}
TEST_P(TabModelTest, TabCreatedOnInsertion) {
std::unique_ptr<web::WebState> web_state = web::WebState::Create(
web::WebState::CreateParams(chrome_browser_state_.get()));
......
......@@ -10,12 +10,11 @@
#include "base/macros.h"
#import "ios/chrome/browser/web_state_list/web_state_list_delegate.h"
@class TabModel;
// WebStateList delegate for the old architecture.
class TabModelWebStateListDelegate : public WebStateListDelegate {
public:
explicit TabModelWebStateListDelegate(TabModel* tab_model);
TabModelWebStateListDelegate();
~TabModelWebStateListDelegate() override;
// WebStateListDelegate implementation.
......@@ -23,8 +22,6 @@ class TabModelWebStateListDelegate : public WebStateListDelegate {
void WebStateDetached(web::WebState* web_state) override;
private:
__weak TabModel* tab_model_ = nil;
DISALLOW_COPY_AND_ASSIGN(TabModelWebStateListDelegate);
};
......
......@@ -4,19 +4,13 @@
#import "ios/chrome/browser/tabs/tab_model_web_state_list_delegate.h"
#include "base/logging.h"
#import "ios/chrome/browser/tabs/legacy_tab_helper.h"
#import "ios/chrome/browser/tabs/tab.h"
#import "ios/chrome/browser/tabs/tab_helper_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
TabModelWebStateListDelegate::TabModelWebStateListDelegate(TabModel* tab_model)
: tab_model_(tab_model) {
DCHECK(tab_model_);
}
TabModelWebStateListDelegate::TabModelWebStateListDelegate() = default;
TabModelWebStateListDelegate::~TabModelWebStateListDelegate() = default;
......@@ -25,14 +19,7 @@ void TabModelWebStateListDelegate::WillAddWebState(web::WebState* web_state) {
// the method is idempotent and this ensure that any WebState in a TabModel
// has all the expected tab helpers.
AttachTabHelpers(web_state, /*for_prerender=*/false);
DCHECK(LegacyTabHelper::FromWebState(web_state));
Tab* tab = LegacyTabHelper::GetTabForWebState(web_state);
[tab setParentTabModel:tab_model_];
}
void TabModelWebStateListDelegate::WebStateDetached(web::WebState* web_state) {
DCHECK(LegacyTabHelper::FromWebState(web_state));
Tab* tab = LegacyTabHelper::GetTabForWebState(web_state);
[tab setParentTabModel:nil];
}
......@@ -18,9 +18,6 @@
@interface Tab (TestingSupport)
// Returns the Tab owning TabModel.
- (TabModel*)parentTabModel;
// The CRWWebController from the Tab's WebState. This should only be used
// by tests and will be removed when Tab can wrap TestWebState (see issue
// crbug.com/620465 for progress).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment