Index: ios/chrome/browser/tabs/tab_model.mm |
diff --git a/ios/chrome/browser/tabs/tab_model.mm b/ios/chrome/browser/tabs/tab_model.mm |
index 0f7a935377393285ea2013e64244b5d4740a73db..f72b5ea5c2d5843a8e5f221e910a1cc044673248 100644 |
--- a/ios/chrome/browser/tabs/tab_model.mm |
+++ b/ios/chrome/browser/tabs/tab_model.mm |
@@ -45,6 +45,7 @@ |
#import "ios/shared/chrome/browser/tabs/web_state_list_fast_enumeration_helper.h" |
#import "ios/shared/chrome/browser/tabs/web_state_list_metrics_observer.h" |
#import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
+#import "ios/shared/chrome/browser/tabs/web_state_opener.h" |
#import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
#import "ios/web/navigation/crw_session_controller.h" |
#include "ios/web/public/browser_state.h" |
@@ -445,8 +446,9 @@ Tab* GetOpenerForTab(id<NSFastEnumeration> tabs, Tab* tab) { |
if (index == WebStateList::kInvalidIndex) |
return nil; |
- web::WebState* opener = _webStateList->GetOpenerOfWebStateAt(index); |
- return opener ? LegacyTabHelper::GetTabForWebState(opener) : nil; |
+ WebStateOpener opener = _webStateList->GetOpenerOfWebStateAt(index); |
+ return opener.opener ? LegacyTabHelper::GetTabForWebState(opener.opener) |
+ : nil; |
} |
- (Tab*)insertTabWithURL:(const GURL&)URL |
@@ -526,12 +528,18 @@ Tab* GetOpenerForTab(id<NSFastEnumeration> tabs, Tab* tab) { |
[_tabRetainer addObject:tab]; |
if (index == TabModelConstants::kTabPositionAutomatically) { |
- _webStateList->AppendWebState(transition, tab.webState, parentTab.webState); |
+ _webStateList->AppendWebState( |
+ transition, tab.webState, |
+ WebStateOpener(parentTab.webState, tab.openerNavigationIndex)); |
} else { |
DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX)); |
const int insertion_index = static_cast<int>(index); |
- _webStateList->InsertWebState(insertion_index, tab.webState, |
- parentTab.webState); |
+ _webStateList->InsertWebState(insertion_index, tab.webState); |
+ if (parentTab.webState) { |
+ _webStateList->SetOpenerOfWebStateAt( |
+ insertion_index, |
+ WebStateOpener(parentTab.webState, tab.openerNavigationIndex)); |
+ } |
} |
// Persist the session due to a new tab being inserted. If this is a |
@@ -586,8 +594,14 @@ Tab* GetOpenerForTab(id<NSFastEnumeration> tabs, Tab* tab) { |
// object destroyed as expected, so it will fine to ignore the result then |
// too. See http://crbug.com/546222 for progress of changing the ownership |
// of the WebStates. |
- ignore_result(_webStateList->ReplaceWebStateAt( |
- index, newTab.webState, GetOpenerForTab(self, newTab).webState)); |
+ ignore_result(_webStateList->ReplaceWebStateAt(index, newTab.webState)); |
+ |
+ Tab* parentTab = GetOpenerForTab(self, newTab); |
+ if (parentTab) { |
+ _webStateList->SetOpenerOfWebStateAt( |
+ index, |
+ WebStateOpener(parentTab.webState, newTab.openerNavigationIndex)); |
+ } |
[oldTab setParentTabModel:nil]; |
[oldTab close]; |
@@ -884,7 +898,8 @@ Tab* GetOpenerForTab(id<NSFastEnumeration> tabs, Tab* tab) { |
Tab* opener = GetOpenerForTab(restoredTabs.get(), tab); |
if (opener) { |
DCHECK(opener.webState); |
- _webStateList->SetOpenerOfWebStateAt(index, opener.webState); |
+ _webStateList->SetOpenerOfWebStateAt( |
+ index, WebStateOpener(opener.webState, tab.openerNavigationIndex)); |
} |
} |