| 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 <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "ios/web/navigation/time_smoother.h" | 25 #include "ios/web/navigation/time_smoother.h" |
| 26 #include "ios/web/public/browser_state.h" | 26 #include "ios/web/public/browser_state.h" |
| 27 #include "ios/web/public/browser_url_rewriter.h" | 27 #include "ios/web/public/browser_url_rewriter.h" |
| 28 #include "ios/web/public/referrer.h" | 28 #include "ios/web/public/referrer.h" |
| 29 #include "ios/web/public/ssl_status.h" | 29 #include "ios/web/public/ssl_status.h" |
| 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 namespace { |
| 36 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; |
| 37 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; |
| 38 NSString* const kEntriesKey = @"entries"; |
| 39 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; |
| 40 NSString* const kOpenerIdKey = @"openerId"; |
| 41 NSString* const kOpenedByDOMKey = @"openedByDOM"; |
| 42 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; |
| 43 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
| 44 NSString* const kTabIdKey = @"tabId"; |
| 45 NSString* const kWindowNameKey = @"windowName"; |
| 46 } // namespace |
| 47 |
| 35 @interface CRWSessionController () { | 48 @interface CRWSessionController () { |
| 36 // Weak pointer back to the owning NavigationManager. This is to facilitate | 49 // Weak pointer back to the owning NavigationManager. This is to facilitate |
| 37 // the incremental merging of the two classes. | 50 // the incremental merging of the two classes. |
| 38 web::NavigationManagerImpl* _navigationManager; | 51 web::NavigationManagerImpl* _navigationManager; |
| 39 | 52 |
| 40 NSString* _tabId; // Unique id of the tab. | 53 NSString* _tabId; // Unique id of the tab. |
| 41 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. | 54 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 | 55 // 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 | 56 // 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. | 57 // an opener, as both 0 and -1 are used as navigationIndex values. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Redefine as readwrite. | 103 // Redefine as readwrite. |
| 91 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 104 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
| 92 | 105 |
| 93 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 106 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
| 94 // clang bug. crbug.com/228650 | 107 // clang bug. crbug.com/228650 |
| 95 @property(nonatomic, readwrite, copy) NSString* tabId; | 108 @property(nonatomic, readwrite, copy) NSString* tabId; |
| 96 @property(nonatomic, readwrite, strong) NSArray* entries; | 109 @property(nonatomic, readwrite, strong) NSArray* entries; |
| 97 @property(nonatomic, readwrite, strong) | 110 @property(nonatomic, readwrite, strong) |
| 98 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 111 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
| 99 | 112 |
| 100 // Expose setters for serialization properties. These are exposed in a category | |
| 101 // in NavigationManagerStorageBuilder, and will be removed as ownership of | |
| 102 // their backing ivars moves to NavigationManagerImpl. | |
| 103 @property(nonatomic, readwrite, copy) NSString* openerId; | |
| 104 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; | |
| 105 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; | |
| 106 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; | |
| 107 | |
| 108 - (NSString*)uniqueID; | 113 - (NSString*)uniqueID; |
| 109 // Removes all entries after currentNavigationIndex_. | 114 // Removes all entries after currentNavigationIndex_. |
| 110 - (void)clearForwardEntries; | 115 - (void)clearForwardEntries; |
| 111 // Discards the transient entry, if any. | 116 // Discards the transient entry, if any. |
| 112 - (void)discardTransientEntry; | 117 - (void)discardTransientEntry; |
| 113 // Create a new autoreleased session entry. | 118 // Create a new autoreleased session entry. |
| 114 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 119 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| 115 referrer:(const web::Referrer&)referrer | 120 referrer:(const web::Referrer&)referrer |
| 116 transition:(ui::PageTransition)transition | 121 transition:(ui::PageTransition)transition |
| 117 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 122 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 191 } |
| 187 _previousNavigationIndex = -1; | 192 _previousNavigationIndex = -1; |
| 188 _pendingEntryIndex = -1; | 193 _pendingEntryIndex = -1; |
| 189 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 194 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
| 190 _sessionCertificatePolicyManager = | 195 _sessionCertificatePolicyManager = |
| 191 [[CRWSessionCertificatePolicyManager alloc] init]; | 196 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 192 } | 197 } |
| 193 return self; | 198 return self; |
| 194 } | 199 } |
| 195 | 200 |
| 201 - (id)initWithCoder:(NSCoder*)aDecoder { |
| 202 self = [super init]; |
| 203 if (self) { |
| 204 NSString* uuid = [aDecoder decodeObjectForKey:kTabIdKey]; |
| 205 if (!uuid) |
| 206 uuid = [self uniqueID]; |
| 207 |
| 208 self.windowName = [aDecoder decodeObjectForKey:kWindowNameKey]; |
| 209 _tabId = [uuid copy]; |
| 210 _openerId = [[aDecoder decodeObjectForKey:kOpenerIdKey] copy]; |
| 211 _openedByDOM = [aDecoder decodeBoolForKey:kOpenedByDOMKey]; |
| 212 _openerNavigationIndex = |
| 213 [aDecoder decodeIntForKey:kOpenerNavigationIndexKey]; |
| 214 _currentNavigationIndex = |
| 215 [aDecoder decodeIntForKey:kCurrentNavigationIndexKey]; |
| 216 _previousNavigationIndex = |
| 217 [aDecoder decodeIntForKey:kPreviousNavigationIndexKey]; |
| 218 _pendingEntryIndex = -1; |
| 219 _lastVisitedTimestamp = |
| 220 [aDecoder decodeDoubleForKey:kLastVisitedTimestampKey]; |
| 221 NSMutableArray* temp = |
| 222 [NSMutableArray arrayWithArray: |
| 223 [aDecoder decodeObjectForKey:kEntriesKey]]; |
| 224 _entries = temp; |
| 225 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
| 226 if (![_entries count]) |
| 227 _currentNavigationIndex = -1; |
| 228 _sessionCertificatePolicyManager = |
| 229 [aDecoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
| 230 if (!_sessionCertificatePolicyManager) { |
| 231 _sessionCertificatePolicyManager = |
| 232 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 233 } |
| 234 } |
| 235 return self; |
| 236 } |
| 237 |
| 238 - (void)encodeWithCoder:(NSCoder*)aCoder { |
| 239 [aCoder encodeObject:_tabId forKey:kTabIdKey]; |
| 240 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; |
| 241 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; |
| 242 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; |
| 243 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; |
| 244 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; |
| 245 [aCoder encodeInt:_previousNavigationIndex |
| 246 forKey:kPreviousNavigationIndexKey]; |
| 247 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; |
| 248 [aCoder encodeObject:_entries forKey:kEntriesKey]; |
| 249 [aCoder encodeObject:_sessionCertificatePolicyManager |
| 250 forKey:kCertificatePolicyManagerKey]; |
| 251 // rendererInitiated is deliberately not preserved, as upstream. |
| 252 } |
| 253 |
| 196 - (id)copyWithZone:(NSZone*)zone { | 254 - (id)copyWithZone:(NSZone*)zone { |
| 197 CRWSessionController* copy = [[[self class] alloc] init]; | 255 CRWSessionController* copy = [[[self class] alloc] init]; |
| 198 copy->_tabId = [_tabId copy]; | 256 copy->_tabId = [_tabId copy]; |
| 199 copy->_openerId = [_openerId copy]; | 257 copy->_openerId = [_openerId copy]; |
| 200 copy->_openedByDOM = _openedByDOM; | 258 copy->_openedByDOM = _openedByDOM; |
| 201 copy->_openerNavigationIndex = _openerNavigationIndex; | 259 copy->_openerNavigationIndex = _openerNavigationIndex; |
| 202 copy.windowName = self.windowName; | 260 copy.windowName = self.windowName; |
| 203 copy->_currentNavigationIndex = _currentNavigationIndex; | 261 copy->_currentNavigationIndex = _currentNavigationIndex; |
| 204 copy->_previousNavigationIndex = _previousNavigationIndex; | 262 copy->_previousNavigationIndex = _previousNavigationIndex; |
| 205 copy->_pendingEntryIndex = _pendingEntryIndex; | 263 copy->_pendingEntryIndex = _pendingEntryIndex; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; | 743 return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]; |
| 686 } | 744 } |
| 687 | 745 |
| 688 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { | 746 - (BOOL)isRedirectTransitionForEntryAtIndex:(NSInteger)index { |
| 689 ui::PageTransition transition = | 747 ui::PageTransition transition = |
| 690 [_entries[index] navigationItem]->GetTransitionType(); | 748 [_entries[index] navigationItem]->GetTransitionType(); |
| 691 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 749 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 692 } | 750 } |
| 693 | 751 |
| 694 @end | 752 @end |
| OLD | NEW |