| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 namespace { | 172 namespace { |
| 173 class TabHistoryContext; | 173 class TabHistoryContext; |
| 174 class FaviconDriverObserverBridge; | 174 class FaviconDriverObserverBridge; |
| 175 class TabInfoBarObserver; | 175 class TabInfoBarObserver; |
| 176 | 176 |
| 177 // The key under which the Tab ID is stored in the WebState's serializable user | 177 // The key under which the Tab ID is stored in the WebState's serializable user |
| 178 // data. | 178 // data. |
| 179 NSString* const kTabIDKey = @"TabID"; | 179 NSString* const kTabIDKey = @"TabID"; |
| 180 | 180 |
| 181 // The key under which the opener Tab ID is stored in the WebState's |
| 182 // serializable user data. |
| 183 NSString* const kOpenerIDKey = @"OpenerID"; |
| 184 |
| 185 // The key under which the opener navigation index is stored in the WebState's |
| 186 // serializable user data. |
| 187 NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex"; |
| 188 |
| 181 // Name of histogram for recording the state of the tab when the renderer is | 189 // Name of histogram for recording the state of the tab when the renderer is |
| 182 // terminated. | 190 // terminated. |
| 183 const char kRendererTerminationStateHistogram[] = | 191 const char kRendererTerminationStateHistogram[] = |
| 184 "Tab.StateAtRendererTermination"; | 192 "Tab.StateAtRendererTermination"; |
| 185 | 193 |
| 186 // Referrer used for clicks on article suggestions on the NTP. | 194 // Referrer used for clicks on article suggestions on the NTP. |
| 187 const char kChromeContentSuggestionsReferrer[] = | 195 const char kChromeContentSuggestionsReferrer[] = |
| 188 "https://www.googleapis.com/auth/chrome-content-suggestions"; | 196 "https://www.googleapis.com/auth/chrome-content-suggestions"; |
| 189 | 197 |
| 190 // Enum corresponding to UMA's TabForegroundState, for | 198 // Enum corresponding to UMA's TabForegroundState, for |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; | 498 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; |
| 491 @synthesize delegate = delegate_; | 499 @synthesize delegate = delegate_; |
| 492 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; | 500 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; |
| 493 @synthesize tabHeadersDelegate = tabHeadersDelegate_; | 501 @synthesize tabHeadersDelegate = tabHeadersDelegate_; |
| 494 | 502 |
| 495 - (instancetype)initWithWindowName:(NSString*)windowName | 503 - (instancetype)initWithWindowName:(NSString*)windowName |
| 496 opener:(Tab*)opener | 504 opener:(Tab*)opener |
| 497 openedByDOM:(BOOL)openedByDOM | 505 openedByDOM:(BOOL)openedByDOM |
| 498 model:(TabModel*)parentModel | 506 model:(TabModel*)parentModel |
| 499 browserState:(ios::ChromeBrowserState*)browserState { | 507 browserState:(ios::ChromeBrowserState*)browserState { |
| 500 NSInteger openerIndex = -1; | |
| 501 if ([opener navigationManager]) { | |
| 502 NavigationManagerImpl* openerNavManager = [opener navigationManager]; | |
| 503 openerIndex = openerNavManager->GetLastCommittedItemIndex(); | |
| 504 } | |
| 505 std::unique_ptr<web::WebStateImpl> webState( | 508 std::unique_ptr<web::WebStateImpl> webState( |
| 506 new web::WebStateImpl(browserState)); | 509 new web::WebStateImpl(browserState)); |
| 507 webState->GetNavigationManagerImpl().InitializeSession( | 510 webState->GetNavigationManagerImpl().InitializeSession(windowName, |
| 508 windowName, opener.tabId, openedByDOM, openerIndex); | 511 openedByDOM); |
| 512 if ([opener navigationManager]) { |
| 513 web::SerializableUserDataManager* userDataManager = |
| 514 web::SerializableUserDataManager::FromWebState(webState.get()); |
| 515 userDataManager->AddSerializableData(opener.tabId, kOpenerIDKey); |
| 516 userDataManager->AddSerializableData( |
| 517 @([opener navigationManager]->GetLastCommittedItemIndex()), |
| 518 kOpenerNavigationIndexKey); |
| 519 } |
| 509 | 520 |
| 510 return [self initWithWebState:std::move(webState) model:parentModel]; | 521 return [self initWithWebState:std::move(webState) model:parentModel]; |
| 511 } | 522 } |
| 512 | 523 |
| 513 - (instancetype)initWithWebState:(std::unique_ptr<web::WebState>)webState | 524 - (instancetype)initWithWebState:(std::unique_ptr<web::WebState>)webState |
| 514 model:(TabModel*)parentModel { | 525 model:(TabModel*)parentModel { |
| 515 return [self initWithWebState:std::move(webState) | 526 return [self initWithWebState:std::move(webState) |
| 516 model:parentModel | 527 model:parentModel |
| 517 attachTabHelpers:YES]; | 528 attachTabHelpers:YES]; |
| 518 } | 529 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 web::SerializableUserDataManager* userDataManager = | 803 web::SerializableUserDataManager* userDataManager = |
| 793 web::SerializableUserDataManager::FromWebState(self.webState); | 804 web::SerializableUserDataManager::FromWebState(self.webState); |
| 794 id<NSCoding> tabID = userDataManager->GetValueForSerializationKey(kTabIDKey); | 805 id<NSCoding> tabID = userDataManager->GetValueForSerializationKey(kTabIDKey); |
| 795 if (!tabID) { | 806 if (!tabID) { |
| 796 tabID = [[NSUUID UUID] UUIDString]; | 807 tabID = [[NSUUID UUID] UUIDString]; |
| 797 userDataManager->AddSerializableData(tabID, kTabIDKey); | 808 userDataManager->AddSerializableData(tabID, kTabIDKey); |
| 798 } | 809 } |
| 799 return base::mac::ObjCCastStrict<NSString>(tabID); | 810 return base::mac::ObjCCastStrict<NSString>(tabID); |
| 800 } | 811 } |
| 801 | 812 |
| 813 - (NSString*)openerID { |
| 814 DCHECK(self.webState); |
| 815 web::SerializableUserDataManager* userDataManager = |
| 816 web::SerializableUserDataManager::FromWebState(self.webState); |
| 817 id<NSCoding> openerID = |
| 818 userDataManager->GetValueForSerializationKey(kOpenerIDKey); |
| 819 return base::mac::ObjCCastStrict<NSString>(openerID); |
| 820 } |
| 821 |
| 822 - (NSInteger)openerNavigationIndex { |
| 823 DCHECK(self.webState); |
| 824 web::SerializableUserDataManager* userDataManager = |
| 825 web::SerializableUserDataManager::FromWebState(self.webState); |
| 826 id<NSCoding> openerNavigationIndex = |
| 827 userDataManager->GetValueForSerializationKey(kOpenerNavigationIndexKey); |
| 828 if (!openerNavigationIndex) |
| 829 return -1; |
| 830 return base::mac::ObjCCastStrict<NSNumber>(openerNavigationIndex) |
| 831 .integerValue; |
| 832 } |
| 833 |
| 802 - (web::WebState*)webState { | 834 - (web::WebState*)webState { |
| 803 return webStateImpl_.get(); | 835 return webStateImpl_.get(); |
| 804 } | 836 } |
| 805 | 837 |
| 806 - (void)fetchFavicon { | 838 - (void)fetchFavicon { |
| 807 const GURL& url = self.url; | 839 const GURL& url = self.url; |
| 808 if (!url.is_valid()) | 840 if (!url.is_valid()) |
| 809 return; | 841 return; |
| 810 | 842 |
| 811 favicon::FaviconDriver* faviconDriver = | 843 favicon::FaviconDriver* faviconDriver = |
| (...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 | 2241 |
| 2210 - (TabModel*)parentTabModel { | 2242 - (TabModel*)parentTabModel { |
| 2211 return parentTabModel_; | 2243 return parentTabModel_; |
| 2212 } | 2244 } |
| 2213 | 2245 |
| 2214 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 2246 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 2215 return inputAccessoryViewController_.get(); | 2247 return inputAccessoryViewController_.get(); |
| 2216 } | 2248 } |
| 2217 | 2249 |
| 2218 @end | 2250 @end |
| OLD | NEW |