| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/tabs/tab.h" | 5 #import "ios/chrome/browser/tabs/tab.h" |
| 6 | 6 |
| 7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 namespace { | 164 namespace { |
| 165 class TabHistoryContext; | 165 class TabHistoryContext; |
| 166 class FaviconDriverObserverBridge; | 166 class FaviconDriverObserverBridge; |
| 167 class TabInfoBarObserver; | 167 class TabInfoBarObserver; |
| 168 | 168 |
| 169 // The key under which the Tab ID is stored in the WebState's serializable user | 169 // The key under which the Tab ID is stored in the WebState's serializable user |
| 170 // data. | 170 // data. |
| 171 NSString* const kTabIDKey = @"TabID"; | 171 NSString* const kTabIDKey = @"TabID"; |
| 172 | 172 |
| 173 // The key under which the opener Tab ID is stored in the WebState's | |
| 174 // serializable user data. | |
| 175 NSString* const kOpenerIDKey = @"OpenerID"; | |
| 176 | |
| 177 // The key under which the opener navigation index is stored in the WebState's | |
| 178 // serializable user data. | |
| 179 NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex"; | |
| 180 | |
| 181 // Name of histogram for recording the state of the tab when the renderer is | 173 // Name of histogram for recording the state of the tab when the renderer is |
| 182 // terminated. | 174 // terminated. |
| 183 const char kRendererTerminationStateHistogram[] = | 175 const char kRendererTerminationStateHistogram[] = |
| 184 "Tab.StateAtRendererTermination"; | 176 "Tab.StateAtRendererTermination"; |
| 185 | 177 |
| 186 // Referrer used for clicks on article suggestions on the NTP. | 178 // Referrer used for clicks on article suggestions on the NTP. |
| 187 const char kChromeContentSuggestionsReferrer[] = | 179 const char kChromeContentSuggestionsReferrer[] = |
| 188 "https://www.googleapis.com/auth/chrome-content-suggestions"; | 180 "https://www.googleapis.com/auth/chrome-content-suggestions"; |
| 189 | 181 |
| 190 // Enum corresponding to UMA's TabForegroundState, for | 182 // Enum corresponding to UMA's TabForegroundState, for |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 base::scoped_nsobject<WebControllerSnapshotHelper> | 280 base::scoped_nsobject<WebControllerSnapshotHelper> |
| 289 webControllerSnapshotHelper_; | 281 webControllerSnapshotHelper_; |
| 290 | 282 |
| 291 // Handles support for window.print JavaScript calls. | 283 // Handles support for window.print JavaScript calls. |
| 292 std::unique_ptr<PrintObserver> printObserver_; | 284 std::unique_ptr<PrintObserver> printObserver_; |
| 293 | 285 |
| 294 // AutoReloadBridge for this tab. | 286 // AutoReloadBridge for this tab. |
| 295 base::scoped_nsobject<AutoReloadBridge> autoReloadBridge_; | 287 base::scoped_nsobject<AutoReloadBridge> autoReloadBridge_; |
| 296 | 288 |
| 297 // WebStateImpl for this tab. | 289 // WebStateImpl for this tab. |
| 298 std::unique_ptr<web::WebStateImpl> webStateImpl_; | 290 web::WebStateImpl* webStateImpl_; |
| 299 | 291 |
| 300 // Allows Tab to conform CRWWebStateDelegate protocol. | 292 // Allows Tab to conform CRWWebStateDelegate protocol. |
| 301 std::unique_ptr<web::WebStateObserverBridge> webStateObserver_; | 293 std::unique_ptr<web::WebStateObserverBridge> webStateObserver_; |
| 302 | 294 |
| 303 // Context used by history to scope the lifetime of navigation entry | 295 // Context used by history to scope the lifetime of navigation entry |
| 304 // references to Tab. | 296 // references to Tab. |
| 305 std::unique_ptr<TabHistoryContext> tabHistoryContext_; | 297 std::unique_ptr<TabHistoryContext> tabHistoryContext_; |
| 306 | 298 |
| 307 // The controller for everything related to reader mode. | 299 // The controller for everything related to reader mode. |
| 308 base::scoped_nsobject<ReaderModeController> readerModeController_; | 300 base::scoped_nsobject<ReaderModeController> readerModeController_; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 463 |
| 472 @synthesize browserState = browserState_; | 464 @synthesize browserState = browserState_; |
| 473 @synthesize useGreyImageCache = useGreyImageCache_; | 465 @synthesize useGreyImageCache = useGreyImageCache_; |
| 474 @synthesize isPrerenderTab = isPrerenderTab_; | 466 @synthesize isPrerenderTab = isPrerenderTab_; |
| 475 @synthesize isLinkLoadingPrerenderTab = isLinkLoadingPrerenderTab_; | 467 @synthesize isLinkLoadingPrerenderTab = isLinkLoadingPrerenderTab_; |
| 476 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; | 468 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; |
| 477 @synthesize delegate = delegate_; | 469 @synthesize delegate = delegate_; |
| 478 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; | 470 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; |
| 479 @synthesize tabHeadersDelegate = tabHeadersDelegate_; | 471 @synthesize tabHeadersDelegate = tabHeadersDelegate_; |
| 480 | 472 |
| 481 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 473 - (instancetype)initWithWebState:(web::WebState*)webState { |
| 482 opener:(Tab*)opener | |
| 483 openedByDOM:(BOOL)openedByDOM | |
| 484 model:(TabModel*)parentModel { | |
| 485 web::WebState::CreateParams params(browserState); | |
| 486 params.created_with_opener = openedByDOM; | |
| 487 std::unique_ptr<web::WebState> webState = web::WebState::Create(params); | |
| 488 if ([opener navigationManager]) { | |
| 489 web::SerializableUserDataManager* userDataManager = | |
| 490 web::SerializableUserDataManager::FromWebState(webState.get()); | |
| 491 userDataManager->AddSerializableData(opener.tabId, kOpenerIDKey); | |
| 492 userDataManager->AddSerializableData( | |
| 493 @([opener navigationManager]->GetLastCommittedItemIndex()), | |
| 494 kOpenerNavigationIndexKey); | |
| 495 } | |
| 496 | |
| 497 return [self initWithWebState:std::move(webState) model:parentModel]; | |
| 498 } | |
| 499 | |
| 500 - (instancetype)initWithWebState:(std::unique_ptr<web::WebState>)webState | |
| 501 model:(TabModel*)parentModel { | |
| 502 return [self initWithWebState:std::move(webState) | |
| 503 model:parentModel | |
| 504 attachTabHelpers:YES]; | |
| 505 } | |
| 506 | |
| 507 - (instancetype)initWithWebState:(std::unique_ptr<web::WebState>)webState | |
| 508 model:(TabModel*)parentModel | |
| 509 attachTabHelpers:(BOOL)attachTabHelpers { | |
| 510 DCHECK(webState); | 474 DCHECK(webState); |
| 511 self = [super init]; | 475 self = [super init]; |
| 512 if (self) { | 476 if (self) { |
| 513 propertyReleaser_Tab_.Init(self, [Tab class]); | 477 propertyReleaser_Tab_.Init(self, [Tab class]); |
| 514 tabHistoryContext_.reset(new TabHistoryContext()); | 478 |
| 515 parentTabModel_ = parentModel; | 479 // TODO(crbug.com/620465): Tab should only use public API of WebState. |
| 480 // Remove this cast once this is the case. |
| 481 webStateImpl_ = static_cast<web::WebStateImpl*>(webState); |
| 516 browserState_ = | 482 browserState_ = |
| 517 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); | 483 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); |
| 518 | 484 |
| 519 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); | |
| 520 webStateObserver_.reset( | |
| 521 new web::WebStateObserverBridge(self.webState, self)); | |
| 522 [self updateLastVisitedTimestamp]; | 485 [self updateLastVisitedTimestamp]; |
| 523 | 486 |
| 524 // Do not respect |attachTabHelpers| as this tab helper is required for | 487 tabHistoryContext_ = base::MakeUnique<TabHistoryContext>(); |
| 525 // proper conversion from WebState to Tab. | 488 webStateObserver_ = |
| 526 LegacyTabHelper::CreateForWebState(self.webState, self); | 489 base::MakeUnique<web::WebStateObserverBridge>(webState, self); |
| 527 | |
| 528 [self.webController setDelegate:self]; | |
| 529 | 490 |
| 530 snapshotManager_.reset([[SnapshotManager alloc] init]); | 491 snapshotManager_.reset([[SnapshotManager alloc] init]); |
| 531 webControllerSnapshotHelper_.reset([[WebControllerSnapshotHelper alloc] | 492 webControllerSnapshotHelper_.reset([[WebControllerSnapshotHelper alloc] |
| 532 initWithSnapshotManager:snapshotManager_ | 493 initWithSnapshotManager:snapshotManager_ |
| 533 tab:self]); | 494 tab:self]); |
| 534 | 495 |
| 535 [self initNativeAppNavigationController]; | 496 [self initNativeAppNavigationController]; |
| 536 | 497 |
| 537 if (attachTabHelpers) { | |
| 538 AttachTabHelpers(self.webState); | |
| 539 | |
| 540 tabInfoBarObserver_.reset(new TabInfoBarObserver(self)); | |
| 541 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); | |
| 542 | |
| 543 if (experimental_flags::IsAutoReloadEnabled()) { | |
| 544 autoReloadBridge_.reset([[AutoReloadBridge alloc] initWithTab:self]); | |
| 545 } | |
| 546 printObserver_.reset(new PrintObserver(self.webState)); | |
| 547 | |
| 548 base::scoped_nsprotocol<id<PasswordsUiDelegate>> passwordsUiDelegate( | |
| 549 [[PasswordsUiDelegateImpl alloc] init]); | |
| 550 passwordController_.reset([[PasswordController alloc] | |
| 551 initWithWebState:self.webState | |
| 552 passwordsUiDelegate:passwordsUiDelegate]); | |
| 553 password_manager::PasswordGenerationManager* passwordGenerationManager = | |
| 554 [passwordController_ passwordGenerationManager]; | |
| 555 autofillController_.reset([[AutofillController alloc] | |
| 556 initWithBrowserState:browserState_ | |
| 557 passwordGenerationManager:passwordGenerationManager | |
| 558 webState:self.webState]); | |
| 559 suggestionController_.reset([[FormSuggestionController alloc] | |
| 560 initWithWebState:self.webState | |
| 561 providers:[self suggestionProviders]]); | |
| 562 inputAccessoryViewController_.reset( | |
| 563 [[FormInputAccessoryViewController alloc] | |
| 564 initWithWebState:self.webState | |
| 565 providers:[self accessoryViewProviders]]); | |
| 566 | |
| 567 [self setShouldObserveFaviconChanges:YES]; | |
| 568 | |
| 569 if (parentModel && parentModel.syncedWindowDelegate) { | |
| 570 IOSChromeSessionTabHelper::FromWebState(self.webState) | |
| 571 ->SetWindowID(parentModel.sessionID); | |
| 572 } | |
| 573 | |
| 574 // Create the ReaderModeController immediately so it can register for | |
| 575 // WebState changes. | |
| 576 if (experimental_flags::IsReaderModeEnabled()) { | |
| 577 readerModeController_.reset([[ReaderModeController alloc] | |
| 578 initWithWebState:self.webState | |
| 579 delegate:self]); | |
| 580 } | |
| 581 } | |
| 582 | |
| 583 [[NSNotificationCenter defaultCenter] | 498 [[NSNotificationCenter defaultCenter] |
| 584 addObserver:self | 499 addObserver:self |
| 585 selector:@selector(applicationDidBecomeActive) | 500 selector:@selector(applicationDidBecomeActive) |
| 586 name:UIApplicationDidBecomeActiveNotification | 501 name:UIApplicationDidBecomeActiveNotification |
| 587 object:nil]; | 502 object:nil]; |
| 588 } | 503 } |
| 589 return self; | 504 return self; |
| 590 } | 505 } |
| 591 | 506 |
| 507 - (void)attachTabHelpers { |
| 508 tabInfoBarObserver_.reset(new TabInfoBarObserver(self)); |
| 509 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); |
| 510 |
| 511 if (experimental_flags::IsAutoReloadEnabled()) { |
| 512 autoReloadBridge_.reset([[AutoReloadBridge alloc] initWithTab:self]); |
| 513 } |
| 514 printObserver_ = base::MakeUnique<PrintObserver>(self.webState); |
| 515 |
| 516 base::scoped_nsprotocol<id<PasswordsUiDelegate>> passwordsUiDelegate( |
| 517 [[PasswordsUiDelegateImpl alloc] init]); |
| 518 passwordController_.reset([[PasswordController alloc] |
| 519 initWithWebState:self.webState |
| 520 passwordsUiDelegate:passwordsUiDelegate]); |
| 521 password_manager::PasswordGenerationManager* passwordGenerationManager = |
| 522 [passwordController_ passwordGenerationManager]; |
| 523 autofillController_.reset([[AutofillController alloc] |
| 524 initWithBrowserState:browserState_ |
| 525 passwordGenerationManager:passwordGenerationManager |
| 526 webState:self.webState]); |
| 527 suggestionController_.reset([[FormSuggestionController alloc] |
| 528 initWithWebState:self.webState |
| 529 providers:[self suggestionProviders]]); |
| 530 inputAccessoryViewController_.reset([[FormInputAccessoryViewController alloc] |
| 531 initWithWebState:self.webState |
| 532 providers:[self accessoryViewProviders]]); |
| 533 |
| 534 [self setShouldObserveFaviconChanges:YES]; |
| 535 |
| 536 // Create the ReaderModeController immediately so it can register for |
| 537 // WebState changes. |
| 538 if (experimental_flags::IsReaderModeEnabled()) { |
| 539 readerModeController_.reset([[ReaderModeController alloc] |
| 540 initWithWebState:self.webState |
| 541 delegate:self]); |
| 542 } |
| 543 } |
| 544 |
| 592 - (NSArray*)accessoryViewProviders { | 545 - (NSArray*)accessoryViewProviders { |
| 593 NSMutableArray* providers = [NSMutableArray array]; | 546 NSMutableArray* providers = [NSMutableArray array]; |
| 594 id<FormInputAccessoryViewProvider> provider = | 547 id<FormInputAccessoryViewProvider> provider = |
| 595 [passwordController_ accessoryViewProvider]; | 548 [passwordController_ accessoryViewProvider]; |
| 596 if (provider) | 549 if (provider) |
| 597 [providers addObject:provider]; | 550 [providers addObject:provider]; |
| 598 [providers addObject:[suggestionController_ accessoryViewProvider]]; | 551 [providers addObject:[suggestionController_ accessoryViewProvider]]; |
| 599 return providers; | 552 return providers; |
| 600 } | 553 } |
| 601 | 554 |
| 602 - (NSArray*)suggestionProviders { | 555 - (NSArray*)suggestionProviders { |
| 603 NSMutableArray* providers = [NSMutableArray array]; | 556 NSMutableArray* providers = [NSMutableArray array]; |
| 604 [providers addObject:[passwordController_ suggestionProvider]]; | 557 [providers addObject:[passwordController_ suggestionProvider]]; |
| 605 [providers addObject:[autofillController_ suggestionProvider]]; | 558 [providers addObject:[autofillController_ suggestionProvider]]; |
| 606 return providers; | 559 return providers; |
| 607 } | 560 } |
| 608 | 561 |
| 609 - (id<FindInPageControllerDelegate>)findInPageControllerDelegate { | 562 - (id<FindInPageControllerDelegate>)findInPageControllerDelegate { |
| 610 return self; | 563 return self; |
| 611 } | 564 } |
| 612 | 565 |
| 613 + (Tab*)preloadingTabWithBrowserState:(ios::ChromeBrowserState*)browserState | |
| 614 url:(const GURL&)URL | |
| 615 referrer:(const web::Referrer&)referrer | |
| 616 transition:(ui::PageTransition)transition | |
| 617 provider:(id<CRWNativeContentProvider>)provider | |
| 618 opener:(Tab*)opener | |
| 619 desktopUserAgent:(BOOL)desktopUserAgent | |
| 620 configuration:(void (^)(Tab*))configuration { | |
| 621 Tab* tab = [[[Tab alloc] initWithBrowserState:browserState | |
| 622 opener:opener | |
| 623 openedByDOM:NO | |
| 624 model:nil] autorelease]; | |
| 625 if (desktopUserAgent) | |
| 626 [tab enableDesktopUserAgent]; | |
| 627 [[tab webController] setNativeProvider:provider]; | |
| 628 [[tab webController] setWebUsageEnabled:YES]; | |
| 629 | |
| 630 if (configuration) | |
| 631 configuration(tab); | |
| 632 | |
| 633 web::NavigationManager::WebLoadParams params(URL); | |
| 634 params.transition_type = transition; | |
| 635 params.referrer = referrer; | |
| 636 [[tab webController] loadWithParams:params]; | |
| 637 | |
| 638 return tab; | |
| 639 } | |
| 640 | |
| 641 - (void)dealloc { | |
| 642 DCHECK([NSThread isMainThread]); | |
| 643 // Note that -[CRWWebController close] has already been called, so nothing | |
| 644 // significant should be done with it in this method. | |
| 645 DCHECK_NE(self.webController.delegate, self); | |
| 646 [super dealloc]; | |
| 647 } | |
| 648 | 566 |
| 649 - (void)setParentTabModel:(TabModel*)model { | 567 - (void)setParentTabModel:(TabModel*)model { |
| 650 DCHECK(!model || !parentTabModel_); | 568 DCHECK(!model || !parentTabModel_); |
| 651 parentTabModel_ = model; | 569 parentTabModel_ = model; |
| 652 | 570 |
| 653 if (parentTabModel_.syncedWindowDelegate) { | 571 if (parentTabModel_.syncedWindowDelegate) { |
| 654 IOSChromeSessionTabHelper::FromWebState(self.webState) | 572 IOSChromeSessionTabHelper::FromWebState(self.webState) |
| 655 ->SetWindowID(model.sessionID); | 573 ->SetWindowID(model.sessionID); |
| 656 } | 574 } |
| 657 } | 575 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 658 |
| 741 if (!tabId || ![tabId length]) { | 659 if (!tabId || ![tabId length]) { |
| 742 tabId = [[NSUUID UUID] UUIDString]; | 660 tabId = [[NSUUID UUID] UUIDString]; |
| 743 userDataManager->AddSerializableData(tabId, kTabIDKey); | 661 userDataManager->AddSerializableData(tabId, kTabIDKey); |
| 744 } | 662 } |
| 745 | 663 |
| 746 tabId_.reset([tabId copy]); | 664 tabId_.reset([tabId copy]); |
| 747 return tabId_.get(); | 665 return tabId_.get(); |
| 748 } | 666 } |
| 749 | 667 |
| 750 - (NSString*)openerID { | |
| 751 DCHECK(self.webState); | |
| 752 web::SerializableUserDataManager* userDataManager = | |
| 753 web::SerializableUserDataManager::FromWebState(self.webState); | |
| 754 id<NSCoding> openerID = | |
| 755 userDataManager->GetValueForSerializationKey(kOpenerIDKey); | |
| 756 return base::mac::ObjCCastStrict<NSString>(openerID); | |
| 757 } | |
| 758 | |
| 759 - (NSInteger)openerNavigationIndex { | |
| 760 DCHECK(self.webState); | |
| 761 web::SerializableUserDataManager* userDataManager = | |
| 762 web::SerializableUserDataManager::FromWebState(self.webState); | |
| 763 id<NSCoding> openerNavigationIndex = | |
| 764 userDataManager->GetValueForSerializationKey(kOpenerNavigationIndexKey); | |
| 765 if (!openerNavigationIndex) | |
| 766 return -1; | |
| 767 return base::mac::ObjCCastStrict<NSNumber>(openerNavigationIndex) | |
| 768 .integerValue; | |
| 769 } | |
| 770 | |
| 771 - (web::WebState*)webState { | 668 - (web::WebState*)webState { |
| 772 return webStateImpl_.get(); | 669 return webStateImpl_; |
| 773 } | 670 } |
| 774 | 671 |
| 775 - (void)fetchFavicon { | 672 - (void)fetchFavicon { |
| 776 const GURL& url = self.url; | 673 const GURL& url = self.url; |
| 777 if (!url.is_valid()) | 674 if (!url.is_valid()) |
| 778 return; | 675 return; |
| 779 | 676 |
| 780 favicon::FaviconDriver* faviconDriver = | 677 favicon::FaviconDriver* faviconDriver = |
| 781 favicon::WebFaviconDriver::FromWebState(self.webState); | 678 favicon::WebFaviconDriver::FromWebState(self.webState); |
| 782 if (faviconDriver) { | 679 if (faviconDriver) { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 // Equivalent to the user pressing 'stop', or a window.stop() command. | 1026 // Equivalent to the user pressing 'stop', or a window.stop() command. |
| 1130 - (void)stopLoading { | 1027 - (void)stopLoading { |
| 1131 [self.webController stopLoading]; | 1028 [self.webController stopLoading]; |
| 1132 } | 1029 } |
| 1133 | 1030 |
| 1134 // Halt the tab, which amounts to halting its webController. | 1031 // Halt the tab, which amounts to halting its webController. |
| 1135 - (void)terminateNetworkActivity { | 1032 - (void)terminateNetworkActivity { |
| 1136 [self.webController terminateNetworkActivity]; | 1033 [self.webController terminateNetworkActivity]; |
| 1137 } | 1034 } |
| 1138 | 1035 |
| 1139 // This can't be done in dealloc in case someone holds an extra strong | 1036 - (void)onWebStateDestroyed { |
| 1140 // reference to the Tab, which would cause the close sequence to fire at a | |
| 1141 // random time. | |
| 1142 - (void)close { | |
| 1143 self.fullScreenControllerDelegate = nil; | 1037 self.fullScreenControllerDelegate = nil; |
| 1144 self.overscrollActionsControllerDelegate = nil; | 1038 self.overscrollActionsControllerDelegate = nil; |
| 1145 self.passKitDialogProvider = nil; | 1039 self.passKitDialogProvider = nil; |
| 1146 self.snapshotOverlayProvider = nil; | 1040 self.snapshotOverlayProvider = nil; |
| 1147 | 1041 |
| 1148 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 1042 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1149 | 1043 |
| 1150 [passwordController_ detach]; | 1044 [passwordController_ detach]; |
| 1151 passwordController_.reset(); | 1045 passwordController_.reset(); |
| 1152 tabInfoBarObserver_.reset(); | 1046 tabInfoBarObserver_.reset(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1169 | 1063 |
| 1170 // Invalidate any snapshot stored for this session. | 1064 // Invalidate any snapshot stored for this session. |
| 1171 DCHECK(self.tabId); | 1065 DCHECK(self.tabId); |
| 1172 [snapshotManager_ removeImageWithSessionID:self.tabId]; | 1066 [snapshotManager_ removeImageWithSessionID:self.tabId]; |
| 1173 // Reset association with the webController. | 1067 // Reset association with the webController. |
| 1174 [self.webController setDelegate:nil]; | 1068 [self.webController setDelegate:nil]; |
| 1175 | 1069 |
| 1176 // Cancel any queued dialogs. | 1070 // Cancel any queued dialogs. |
| 1177 [self.dialogDelegate cancelDialogForTab:self]; | 1071 [self.dialogDelegate cancelDialogForTab:self]; |
| 1178 | 1072 |
| 1179 // These steps must be done last, and must be done in this order; nothing | |
| 1180 // involving the tab should be done after didCloseTab:, and the | |
| 1181 // CRWWebController backing the tab should outlive anything done during tab | |
| 1182 // closure (since -[CRWWebController close] is what begins tearing down the | |
| 1183 // web/ layer, and tab closure may trigger operations that need to query the | |
| 1184 // web/ layer). The scoped strong ref is because didCloseTab: is often the | |
| 1185 // trigger for deallocating the tab, but that can in turn cause | |
| 1186 // CRWWebController to be deallocated before its close is called. The facade | |
| 1187 // delegate should be torn down after |-didCloseTab:| so components triggered | |
| 1188 // by tab closure can use the content facade, and it should be deleted before | |
| 1189 // the web controller since the web controller owns the facade's backing | |
| 1190 // objects. |parentTabModel_| is reset after calling |-didCloseTab:| to | |
| 1191 // prevent propagating WebState notifications that happen during WebState | |
| 1192 // destruction. | |
| 1193 // TODO(crbug.com/546222): Fix the need for this; TabModel should be | |
| 1194 // responsible for making the lifetime of Tab sane, rather than allowing Tab | |
| 1195 // to drive its own destruction. | |
| 1196 base::scoped_nsobject<Tab> kungFuDeathGrip([self retain]); | |
| 1197 [parentTabModel_ didCloseTab:self]; // Inform parent of tab closure. | |
| 1198 parentTabModel_ = nil; | |
| 1199 | |
| 1200 // Destroy the WebState but first stop listening to WebState events (as |self| | |
| 1201 // is in no state to respond to the notifications if |webStateImpl_| is null). | |
| 1202 LegacyTabHelper::RemoveFromWebState(self.webState); | |
| 1203 webStateObserver_.reset(); | 1073 webStateObserver_.reset(); |
| 1204 webStateImpl_.reset(); | |
| 1205 } | 1074 } |
| 1206 | 1075 |
| 1207 - (void)dismissModals { | 1076 - (void)dismissModals { |
| 1208 [openInController_ disable]; | 1077 [openInController_ disable]; |
| 1209 [self.webController dismissModals]; | 1078 [self.webController dismissModals]; |
| 1210 } | 1079 } |
| 1211 | 1080 |
| 1212 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { | 1081 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { |
| 1213 tabInfoBarObserver_->SetShouldObserveInfoBarManager( | 1082 tabInfoBarObserver_->SetShouldObserveInfoBarManager( |
| 1214 shouldObserveInfoBarManager); | 1083 shouldObserveInfoBarManager); |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 | 1956 |
| 2088 - (TabModel*)parentTabModel { | 1957 - (TabModel*)parentTabModel { |
| 2089 return parentTabModel_; | 1958 return parentTabModel_; |
| 2090 } | 1959 } |
| 2091 | 1960 |
| 2092 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1961 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 2093 return inputAccessoryViewController_.get(); | 1962 return inputAccessoryViewController_.get(); |
| 2094 } | 1963 } |
| 2095 | 1964 |
| 2096 @end | 1965 @end |
| OLD | NEW |