| 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/web/navigation/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) | 31 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." | 32 #error "This file requires ARC support." |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 @interface CRWSessionController () { | 35 @interface CRWSessionController () { |
| 36 // Weak pointer back to the owning NavigationManager. This is to facilitate | 36 // Weak pointer back to the owning NavigationManager. This is to facilitate |
| 37 // the incremental merging of the two classes. | 37 // the incremental merging of the two classes. |
| 38 web::NavigationManagerImpl* _navigationManager; | 38 web::NavigationManagerImpl* _navigationManager; |
| 39 | 39 |
| 40 NSString* _tabId; // Unique id of the tab. | |
| 41 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. | 40 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. |
| 42 // Navigation index of the tab which opened this tab. Do not rely on the | 41 // Navigation index of the tab which opened this tab. Do not rely on the |
| 43 // value of this member variable to indicate whether or not this tab has | 42 // value of this member variable to indicate whether or not this tab has |
| 44 // an opener, as both 0 and -1 are used as navigationIndex values. | 43 // an opener, as both 0 and -1 are used as navigationIndex values. |
| 45 NSInteger _openerNavigationIndex; | 44 NSInteger _openerNavigationIndex; |
| 46 // Identifies the index of the current navigation in the CRWSessionEntry | 45 // Identifies the index of the current navigation in the CRWSessionEntry |
| 47 // array. | 46 // array. |
| 48 NSInteger _currentNavigationIndex; | 47 NSInteger _currentNavigationIndex; |
| 49 // Identifies the index of the previous navigation in the CRWSessionEntry | 48 // Identifies the index of the previous navigation in the CRWSessionEntry |
| 50 // array. | 49 // array. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 79 // |_items|. | 78 // |_items|. |
| 80 std::unique_ptr<web::NavigationItemImpl> _pendingItem; | 79 std::unique_ptr<web::NavigationItemImpl> _pendingItem; |
| 81 std::unique_ptr<web::NavigationItemImpl> _transientItem; | 80 std::unique_ptr<web::NavigationItemImpl> _transientItem; |
| 82 } | 81 } |
| 83 | 82 |
| 84 // Redefine as readwrite. | 83 // Redefine as readwrite. |
| 85 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 84 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
| 86 | 85 |
| 87 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 86 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
| 88 // clang bug. crbug.com/228650 | 87 // clang bug. crbug.com/228650 |
| 89 @property(nonatomic, readwrite, copy) NSString* tabId; | |
| 90 @property(nonatomic, readwrite, strong) | 88 @property(nonatomic, readwrite, strong) |
| 91 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 89 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
| 92 | 90 |
| 93 // Expose setters for serialization properties. These are exposed in a category | 91 // Expose setters for serialization properties. These are exposed in a category |
| 94 // in SessionStorageBuilder, and will be removed as ownership of | 92 // in SessionStorageBuilder, and will be removed as ownership of |
| 95 // their backing ivars moves to NavigationManagerImpl. | 93 // their backing ivars moves to NavigationManagerImpl. |
| 96 @property(nonatomic, readwrite, copy) NSString* openerId; | 94 @property(nonatomic, readwrite, copy) NSString* openerId; |
| 97 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; | 95 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; |
| 98 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; | 96 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; |
| 99 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; | 97 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; |
| 100 | 98 |
| 101 - (NSString*)uniqueID; | |
| 102 // Removes all items after currentNavigationIndex_. | 99 // Removes all items after currentNavigationIndex_. |
| 103 - (void)clearForwardItems; | 100 - (void)clearForwardItems; |
| 104 // Discards the transient item, if any. | 101 // Discards the transient item, if any. |
| 105 - (void)discardTransientItem; | 102 - (void)discardTransientItem; |
| 106 // Creates a NavigationItemImpl with the specified properties. | 103 // Creates a NavigationItemImpl with the specified properties. |
| 107 - (std::unique_ptr<web::NavigationItemImpl>) | 104 - (std::unique_ptr<web::NavigationItemImpl>) |
| 108 itemWithURL:(const GURL&)url | 105 itemWithURL:(const GURL&)url |
| 109 referrer:(const web::Referrer&)referrer | 106 referrer:(const web::Referrer&)referrer |
| 110 transition:(ui::PageTransition)transition | 107 transition:(ui::PageTransition)transition |
| 111 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 108 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
| 112 rendererInitiated:(BOOL)rendererInitiated; | 109 rendererInitiated:(BOOL)rendererInitiated; |
| 113 // Returns YES if the PageTransition for the underlying navigationItem at | 110 // Returns YES if the PageTransition for the underlying navigationItem at |
| 114 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. | 111 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
| 115 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index; | 112 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index; |
| 116 // Returns the CRWSessionEntry corresponding with |item|. | 113 // Returns the CRWSessionEntry corresponding with |item|. |
| 117 - (CRWSessionEntry*)entryForItem:(web::NavigationItemImpl*)item; | 114 - (CRWSessionEntry*)entryForItem:(web::NavigationItemImpl*)item; |
| 118 // Returns an autoreleased NSArray containing CRWSessionEntries corresponding | 115 // Returns an autoreleased NSArray containing CRWSessionEntries corresponding |
| 119 // with the NavigationItems in |itemList|. | 116 // with the NavigationItems in |itemList|. |
| 120 - (NSArray*)entryListForItemList:(const web::NavigationItemList&)itemList; | 117 - (NSArray*)entryListForItemList:(const web::NavigationItemList&)itemList; |
| 121 | 118 |
| 122 @end | 119 @end |
| 123 | 120 |
| 124 @implementation CRWSessionController | 121 @implementation CRWSessionController |
| 125 | 122 |
| 126 @synthesize tabId = _tabId; | |
| 127 @synthesize currentNavigationIndex = _currentNavigationIndex; | 123 @synthesize currentNavigationIndex = _currentNavigationIndex; |
| 128 @synthesize previousNavigationIndex = _previousNavigationIndex; | 124 @synthesize previousNavigationIndex = _previousNavigationIndex; |
| 129 @synthesize pendingItemIndex = _pendingItemIndex; | 125 @synthesize pendingItemIndex = _pendingItemIndex; |
| 130 @synthesize windowName = _windowName; | 126 @synthesize windowName = _windowName; |
| 131 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | 127 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
| 132 @synthesize openerId = _openerId; | 128 @synthesize openerId = _openerId; |
| 133 @synthesize openedByDOM = _openedByDOM; | 129 @synthesize openedByDOM = _openedByDOM; |
| 134 @synthesize openerNavigationIndex = _openerNavigationIndex; | 130 @synthesize openerNavigationIndex = _openerNavigationIndex; |
| 135 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 131 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 136 | 132 |
| 137 - (id)initWithWindowName:(NSString*)windowName | 133 - (id)initWithWindowName:(NSString*)windowName |
| 138 openerId:(NSString*)openerId | 134 openerId:(NSString*)openerId |
| 139 openedByDOM:(BOOL)openedByDOM | 135 openedByDOM:(BOOL)openedByDOM |
| 140 openerNavigationIndex:(NSInteger)openerIndex | 136 openerNavigationIndex:(NSInteger)openerIndex |
| 141 browserState:(web::BrowserState*)browserState { | 137 browserState:(web::BrowserState*)browserState { |
| 142 self = [super init]; | 138 self = [super init]; |
| 143 if (self) { | 139 if (self) { |
| 144 self.windowName = windowName; | 140 self.windowName = windowName; |
| 145 _tabId = [[self uniqueID] copy]; | |
| 146 _openerId = [openerId copy]; | 141 _openerId = [openerId copy]; |
| 147 _openedByDOM = openedByDOM; | 142 _openedByDOM = openedByDOM; |
| 148 _openerNavigationIndex = openerIndex; | 143 _openerNavigationIndex = openerIndex; |
| 149 _browserState = browserState; | 144 _browserState = browserState; |
| 150 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 145 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
| 151 _currentNavigationIndex = -1; | 146 _currentNavigationIndex = -1; |
| 152 _previousNavigationIndex = -1; | 147 _previousNavigationIndex = -1; |
| 153 _pendingItemIndex = -1; | 148 _pendingItemIndex = -1; |
| 154 _sessionCertificatePolicyManager = | 149 _sessionCertificatePolicyManager = |
| 155 [[CRWSessionCertificatePolicyManager alloc] init]; | 150 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 156 } | 151 } |
| 157 return self; | 152 return self; |
| 158 } | 153 } |
| 159 | 154 |
| 160 - (id)initWithNavigationItems:(web::ScopedNavigationItemList)items | 155 - (id)initWithNavigationItems:(web::ScopedNavigationItemList)items |
| 161 currentIndex:(NSUInteger)currentIndex | 156 currentIndex:(NSUInteger)currentIndex |
| 162 browserState:(web::BrowserState*)browserState { | 157 browserState:(web::BrowserState*)browserState { |
| 163 self = [super init]; | 158 self = [super init]; |
| 164 if (self) { | 159 if (self) { |
| 165 _tabId = [[self uniqueID] copy]; | |
| 166 _openerId = nil; | 160 _openerId = nil; |
| 167 _browserState = browserState; | 161 _browserState = browserState; |
| 168 _items = web::CreateScopedNavigationItemImplList(std::move(items)); | 162 _items = web::CreateScopedNavigationItemImplList(std::move(items)); |
| 169 self.currentNavigationIndex = currentIndex; | 163 self.currentNavigationIndex = currentIndex; |
| 170 if (_items.empty()) | 164 if (_items.empty()) |
| 171 self.currentNavigationIndex = -1; | 165 self.currentNavigationIndex = -1; |
| 172 _currentNavigationIndex = std::min( | 166 _currentNavigationIndex = std::min( |
| 173 _currentNavigationIndex, static_cast<NSInteger>(_items.size() - 1)); | 167 _currentNavigationIndex, static_cast<NSInteger>(_items.size() - 1)); |
| 174 _previousNavigationIndex = -1; | 168 _previousNavigationIndex = -1; |
| 175 _pendingItemIndex = -1; | 169 _pendingItemIndex = -1; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 318 |
| 325 // DEPRECATED | 319 // DEPRECATED |
| 326 - (NSArray*)forwardEntries { | 320 - (NSArray*)forwardEntries { |
| 327 return [self entryListForItemList:self.forwardItems]; | 321 return [self entryListForItemList:self.forwardItems]; |
| 328 } | 322 } |
| 329 | 323 |
| 330 #pragma mark - NSObject | 324 #pragma mark - NSObject |
| 331 | 325 |
| 332 - (NSString*)description { | 326 - (NSString*)description { |
| 333 return [NSString | 327 return [NSString |
| 334 stringWithFormat: | 328 stringWithFormat:@"name: %@\nlast visit: %f\ncurrent index: %" PRIdNS |
| 335 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS | 329 @"\nprevious index: %" PRIdNS |
| 336 @"\nprevious index: %" PRIdNS @"\npending index: %" PRIdNS | 330 @"\npending index: %" PRIdNS |
| 337 @"\n%@\npending: %@\ntransient: %@\n", | 331 @"\n%@\npending: %@\ntransient: %@\n", |
| 338 _tabId, self.windowName, _lastVisitedTimestamp, | 332 self.windowName, _lastVisitedTimestamp, |
| 339 _currentNavigationIndex, _previousNavigationIndex, _pendingItemIndex, | 333 _currentNavigationIndex, _previousNavigationIndex, |
| 340 self.entries, self.pendingEntry, self.transientEntry]; | 334 _pendingItemIndex, self.entries, self.pendingEntry, |
| 335 self.transientEntry]; |
| 341 } | 336 } |
| 342 | 337 |
| 343 #pragma mark - NSCopying | 338 #pragma mark - NSCopying |
| 344 | 339 |
| 345 - (id)copyWithZone:(NSZone*)zone { | 340 - (id)copyWithZone:(NSZone*)zone { |
| 346 CRWSessionController* copy = [[[self class] alloc] init]; | 341 CRWSessionController* copy = [[[self class] alloc] init]; |
| 347 copy->_tabId = [_tabId copy]; | |
| 348 copy->_openerId = [_openerId copy]; | 342 copy->_openerId = [_openerId copy]; |
| 349 copy->_openedByDOM = _openedByDOM; | 343 copy->_openedByDOM = _openedByDOM; |
| 350 copy->_openerNavigationIndex = _openerNavigationIndex; | 344 copy->_openerNavigationIndex = _openerNavigationIndex; |
| 351 copy.windowName = self.windowName; | 345 copy.windowName = self.windowName; |
| 352 copy->_currentNavigationIndex = _currentNavigationIndex; | 346 copy->_currentNavigationIndex = _currentNavigationIndex; |
| 353 copy->_previousNavigationIndex = _previousNavigationIndex; | 347 copy->_previousNavigationIndex = _previousNavigationIndex; |
| 354 copy->_pendingItemIndex = _pendingItemIndex; | 348 copy->_pendingItemIndex = _pendingItemIndex; |
| 355 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | 349 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
| 356 copy->_sessionCertificatePolicyManager = | 350 copy->_sessionCertificatePolicyManager = |
| 357 [_sessionCertificatePolicyManager copy]; | 351 [_sessionCertificatePolicyManager copy]; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 for (size_t index = 0; index < self.items.size(); ++index) { | 665 for (size_t index = 0; index < self.items.size(); ++index) { |
| 672 if (self.items[index].get() == item) | 666 if (self.items[index].get() == item) |
| 673 return index; | 667 return index; |
| 674 } | 668 } |
| 675 return NSNotFound; | 669 return NSNotFound; |
| 676 } | 670 } |
| 677 | 671 |
| 678 #pragma mark - | 672 #pragma mark - |
| 679 #pragma mark Private methods | 673 #pragma mark Private methods |
| 680 | 674 |
| 681 - (NSString*)uniqueID { | |
| 682 CFUUIDRef uuidRef = CFUUIDCreate(NULL); | |
| 683 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); | |
| 684 CFRelease(uuidRef); | |
| 685 | |
| 686 NSString* uuid = | |
| 687 [NSString stringWithString:base::mac::ObjCCastStrict<NSString>( | |
| 688 CFBridgingRelease(uuidStringRef))]; | |
| 689 return uuid; | |
| 690 } | |
| 691 | |
| 692 - (std::unique_ptr<web::NavigationItemImpl>) | 675 - (std::unique_ptr<web::NavigationItemImpl>) |
| 693 itemWithURL:(const GURL&)url | 676 itemWithURL:(const GURL&)url |
| 694 referrer:(const web::Referrer&)referrer | 677 referrer:(const web::Referrer&)referrer |
| 695 transition:(ui::PageTransition)transition | 678 transition:(ui::PageTransition)transition |
| 696 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 679 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
| 697 rendererInitiated:(BOOL)rendererInitiated { | 680 rendererInitiated:(BOOL)rendererInitiated { |
| 698 GURL loaded_url(url); | 681 GURL loaded_url(url); |
| 699 BOOL urlWasRewritten = NO; | 682 BOOL urlWasRewritten = NO; |
| 700 if (_navigationManager) { | 683 if (_navigationManager) { |
| 701 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> | 684 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 [[NSMutableArray alloc] initWithCapacity:itemList.size()]; | 723 [[NSMutableArray alloc] initWithCapacity:itemList.size()]; |
| 741 for (web::NavigationItem* item : itemList) { | 724 for (web::NavigationItem* item : itemList) { |
| 742 CRWSessionEntry* entry = | 725 CRWSessionEntry* entry = |
| 743 [self entryForItem:static_cast<web::NavigationItemImpl*>(item)]; | 726 [self entryForItem:static_cast<web::NavigationItemImpl*>(item)]; |
| 744 [entryList addObject:entry]; | 727 [entryList addObject:entry]; |
| 745 } | 728 } |
| 746 return entryList; | 729 return entryList; |
| 747 } | 730 } |
| 748 | 731 |
| 749 @end | 732 @end |
| OLD | NEW |