Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: ios/chrome/browser/tabs/tab.mm

Issue 2720613005: Refactor serialisation of openerId & openerNavigationIndex. (Closed)
Patch Set: Fix CRWSessionController's initializer comment. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/tabs/tab.h ('k') | ios/chrome/browser/tabs/tab_model.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/tabs/tab.mm
diff --git a/ios/chrome/browser/tabs/tab.mm b/ios/chrome/browser/tabs/tab.mm
index f669f1bfbc80ababda2f0e9c34eae5e1e1b9fb05..eb22c9ba6bb60c95a0413dea86f9821b108d9bd1 100644
--- a/ios/chrome/browser/tabs/tab.mm
+++ b/ios/chrome/browser/tabs/tab.mm
@@ -178,6 +178,14 @@ class TabInfoBarObserver;
// data.
NSString* const kTabIDKey = @"TabID";
+// The key under which the opener Tab ID is stored in the WebState's
+// serializable user data.
+NSString* const kOpenerIDKey = @"OpenerID";
+
+// The key under which the opener navigation index is stored in the WebState's
+// serializable user data.
+NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex";
+
// Name of histogram for recording the state of the tab when the renderer is
// terminated.
const char kRendererTerminationStateHistogram[] =
@@ -497,15 +505,18 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
openedByDOM:(BOOL)openedByDOM
model:(TabModel*)parentModel
browserState:(ios::ChromeBrowserState*)browserState {
- NSInteger openerIndex = -1;
- if ([opener navigationManager]) {
- NavigationManagerImpl* openerNavManager = [opener navigationManager];
- openerIndex = openerNavManager->GetLastCommittedItemIndex();
- }
std::unique_ptr<web::WebStateImpl> webState(
new web::WebStateImpl(browserState));
- webState->GetNavigationManagerImpl().InitializeSession(
- windowName, opener.tabId, openedByDOM, openerIndex);
+ webState->GetNavigationManagerImpl().InitializeSession(windowName,
+ openedByDOM);
+ if ([opener navigationManager]) {
+ web::SerializableUserDataManager* userDataManager =
+ web::SerializableUserDataManager::FromWebState(webState.get());
+ userDataManager->AddSerializableData(opener.tabId, kOpenerIDKey);
+ userDataManager->AddSerializableData(
+ @([opener navigationManager]->GetLastCommittedItemIndex()),
+ kOpenerNavigationIndexKey);
+ }
return [self initWithWebState:std::move(webState) model:parentModel];
}
@@ -799,6 +810,27 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
return base::mac::ObjCCastStrict<NSString>(tabID);
}
+- (NSString*)openerID {
+ DCHECK(self.webState);
+ web::SerializableUserDataManager* userDataManager =
+ web::SerializableUserDataManager::FromWebState(self.webState);
+ id<NSCoding> openerID =
+ userDataManager->GetValueForSerializationKey(kOpenerIDKey);
+ return base::mac::ObjCCastStrict<NSString>(openerID);
+}
+
+- (NSInteger)openerNavigationIndex {
+ DCHECK(self.webState);
+ web::SerializableUserDataManager* userDataManager =
+ web::SerializableUserDataManager::FromWebState(self.webState);
+ id<NSCoding> openerNavigationIndex =
+ userDataManager->GetValueForSerializationKey(kOpenerNavigationIndexKey);
+ if (!openerNavigationIndex)
+ return -1;
+ return base::mac::ObjCCastStrict<NSNumber>(openerNavigationIndex)
+ .integerValue;
+}
+
- (web::WebState*)webState {
return webStateImpl_.get();
}
« no previous file with comments | « ios/chrome/browser/tabs/tab.h ('k') | ios/chrome/browser/tabs/tab_model.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698