| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #import "ios/web/navigation/navigation_manager_impl.h" | 22 #import "ios/web/navigation/navigation_manager_impl.h" |
| 23 #include "ios/web/navigation/time_smoother.h" | 23 #include "ios/web/navigation/time_smoother.h" |
| 24 #include "ios/web/public/browser_state.h" | 24 #include "ios/web/public/browser_state.h" |
| 25 #include "ios/web/public/browser_url_rewriter.h" | 25 #include "ios/web/public/browser_url_rewriter.h" |
| 26 #include "ios/web/public/referrer.h" | 26 #include "ios/web/public/referrer.h" |
| 27 #include "ios/web/public/ssl_status.h" | 27 #include "ios/web/public/ssl_status.h" |
| 28 #include "ios/web/public/user_metrics.h" | 28 #include "ios/web/public/user_metrics.h" |
| 29 | 29 |
| 30 using base::UserMetricsAction; | 30 using base::UserMetricsAction; |
| 31 | 31 |
| 32 namespace { | |
| 33 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; | |
| 34 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; | |
| 35 NSString* const kEntriesKey = @"entries"; | |
| 36 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; | |
| 37 NSString* const kOpenerIdKey = @"openerId"; | |
| 38 NSString* const kOpenedByDOMKey = @"openedByDOM"; | |
| 39 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; | |
| 40 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | |
| 41 NSString* const kTabIdKey = @"tabId"; | |
| 42 NSString* const kWindowNameKey = @"windowName"; | |
| 43 NSString* const kXCallbackParametersKey = @"xCallbackParameters"; | |
| 44 } // anonymous namespace | |
| 45 | |
| 46 @interface CRWSessionController () { | 32 @interface CRWSessionController () { |
| 47 // Weak pointer back to the owning NavigationManager. This is to facilitate | 33 // Weak pointer back to the owning NavigationManager. This is to facilitate |
| 48 // the incremental merging of the two classes. | 34 // the incremental merging of the two classes. |
| 49 web::NavigationManagerImpl* _navigationManager; | 35 web::NavigationManagerImpl* _navigationManager; |
| 50 | 36 |
| 51 NSString* _tabId; // Unique id of the tab. | 37 NSString* _tabId; // Unique id of the tab. |
| 52 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. | 38 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. |
| 53 // Navigation index of the tab which opened this tab. Do not rely on the | 39 // Navigation index of the tab which opened this tab. Do not rely on the |
| 54 // value of this member variable to indicate whether or not this tab has | 40 // value of this member variable to indicate whether or not this tab has |
| 55 // an opener, as both 0 and -1 are used as navigationIndex values. | 41 // an opener, as both 0 and -1 are used as navigationIndex values. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Redefine as readwrite. | 92 // Redefine as readwrite. |
| 107 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; | 93 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; |
| 108 | 94 |
| 109 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 95 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
| 110 // clang bug. crbug.com/228650 | 96 // clang bug. crbug.com/228650 |
| 111 @property(nonatomic, readwrite, retain) NSString* tabId; | 97 @property(nonatomic, readwrite, retain) NSString* tabId; |
| 112 @property(nonatomic, readwrite, retain) NSArray* entries; | 98 @property(nonatomic, readwrite, retain) NSArray* entries; |
| 113 @property(nonatomic, readwrite, retain) | 99 @property(nonatomic, readwrite, retain) |
| 114 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 100 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
| 115 | 101 |
| 102 // Expose setters for serialization properties. These are exposed in a category |
| 103 // in SerializedNavigationManagerBuilder, and will be removed as ownership of |
| 104 // their backing ivars moves to NavigationManagerImpl. |
| 105 @property(nonatomic, readwrite, copy) NSString* openerId; |
| 106 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; |
| 107 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; |
| 108 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; |
| 109 |
| 116 - (NSString*)uniqueID; | 110 - (NSString*)uniqueID; |
| 117 // Removes all entries after currentNavigationIndex_. | 111 // Removes all entries after currentNavigationIndex_. |
| 118 - (void)clearForwardEntries; | 112 - (void)clearForwardEntries; |
| 119 // Discards the transient entry, if any. | 113 // Discards the transient entry, if any. |
| 120 - (void)discardTransientEntry; | 114 - (void)discardTransientEntry; |
| 121 // Create a new autoreleased session entry. | 115 // Create a new autoreleased session entry. |
| 122 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 116 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
| 123 referrer:(const web::Referrer&)referrer | 117 referrer:(const web::Referrer&)referrer |
| 124 transition:(ui::PageTransition)transition | 118 transition:(ui::PageTransition)transition |
| 125 useDesktopUserAgent:(BOOL)useDesktopUserAgent | 119 useDesktopUserAgent:(BOOL)useDesktopUserAgent |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; | 192 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; |
| 199 } | 193 } |
| 200 _previousNavigationIndex = -1; | 194 _previousNavigationIndex = -1; |
| 201 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 195 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
| 202 _sessionCertificatePolicyManager = | 196 _sessionCertificatePolicyManager = |
| 203 [[CRWSessionCertificatePolicyManager alloc] init]; | 197 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 204 } | 198 } |
| 205 return self; | 199 return self; |
| 206 } | 200 } |
| 207 | 201 |
| 208 - (id)initWithCoder:(NSCoder*)aDecoder { | |
| 209 self = [super init]; | |
| 210 if (self) { | |
| 211 _propertyReleaser_CRWSessionController.Init(self, | |
| 212 [CRWSessionController class]); | |
| 213 NSString* uuid = [aDecoder decodeObjectForKey:kTabIdKey]; | |
| 214 if (!uuid) | |
| 215 uuid = [self uniqueID]; | |
| 216 | |
| 217 self.windowName = [aDecoder decodeObjectForKey:kWindowNameKey]; | |
| 218 _tabId = [uuid retain]; | |
| 219 _openerId = [[aDecoder decodeObjectForKey:kOpenerIdKey] copy]; | |
| 220 _openedByDOM = [aDecoder decodeBoolForKey:kOpenedByDOMKey]; | |
| 221 _openerNavigationIndex = | |
| 222 [aDecoder decodeIntForKey:kOpenerNavigationIndexKey]; | |
| 223 _currentNavigationIndex = | |
| 224 [aDecoder decodeIntForKey:kCurrentNavigationIndexKey]; | |
| 225 _previousNavigationIndex = | |
| 226 [aDecoder decodeIntForKey:kPreviousNavigationIndexKey]; | |
| 227 _lastVisitedTimestamp = | |
| 228 [aDecoder decodeDoubleForKey:kLastVisitedTimestampKey]; | |
| 229 NSMutableArray* temp = | |
| 230 [NSMutableArray arrayWithArray: | |
| 231 [aDecoder decodeObjectForKey:kEntriesKey]]; | |
| 232 _entries = [temp retain]; | |
| 233 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | |
| 234 if (![_entries count]) | |
| 235 _currentNavigationIndex = -1; | |
| 236 _sessionCertificatePolicyManager = | |
| 237 [[aDecoder decodeObjectForKey:kCertificatePolicyManagerKey] retain]; | |
| 238 if (!_sessionCertificatePolicyManager) { | |
| 239 _sessionCertificatePolicyManager = | |
| 240 [[CRWSessionCertificatePolicyManager alloc] init]; | |
| 241 } | |
| 242 | |
| 243 _xCallbackParameters = | |
| 244 [[aDecoder decodeObjectForKey:kXCallbackParametersKey] retain]; | |
| 245 } | |
| 246 return self; | |
| 247 } | |
| 248 | |
| 249 - (void)encodeWithCoder:(NSCoder*)aCoder { | |
| 250 [aCoder encodeObject:_tabId forKey:kTabIdKey]; | |
| 251 [aCoder encodeObject:_openerId forKey:kOpenerIdKey]; | |
| 252 [aCoder encodeBool:_openedByDOM forKey:kOpenedByDOMKey]; | |
| 253 [aCoder encodeInt:_openerNavigationIndex forKey:kOpenerNavigationIndexKey]; | |
| 254 [aCoder encodeObject:_windowName forKey:kWindowNameKey]; | |
| 255 [aCoder encodeInt:_currentNavigationIndex forKey:kCurrentNavigationIndexKey]; | |
| 256 [aCoder encodeInt:_previousNavigationIndex | |
| 257 forKey:kPreviousNavigationIndexKey]; | |
| 258 [aCoder encodeDouble:_lastVisitedTimestamp forKey:kLastVisitedTimestampKey]; | |
| 259 [aCoder encodeObject:_entries forKey:kEntriesKey]; | |
| 260 [aCoder encodeObject:_sessionCertificatePolicyManager | |
| 261 forKey:kCertificatePolicyManagerKey]; | |
| 262 [aCoder encodeObject:_xCallbackParameters forKey:kXCallbackParametersKey]; | |
| 263 // rendererInitiated is deliberately not preserved, as upstream. | |
| 264 } | |
| 265 | |
| 266 - (id)copyWithZone:(NSZone*)zone { | 202 - (id)copyWithZone:(NSZone*)zone { |
| 267 CRWSessionController* copy = [[[self class] alloc] init]; | 203 CRWSessionController* copy = [[[self class] alloc] init]; |
| 268 copy->_propertyReleaser_CRWSessionController.Init( | 204 copy->_propertyReleaser_CRWSessionController.Init( |
| 269 copy, [CRWSessionController class]); | 205 copy, [CRWSessionController class]); |
| 270 copy->_tabId = [_tabId copy]; | 206 copy->_tabId = [_tabId copy]; |
| 271 copy->_openerId = [_openerId copy]; | 207 copy->_openerId = [_openerId copy]; |
| 272 copy->_openedByDOM = _openedByDOM; | 208 copy->_openedByDOM = _openedByDOM; |
| 273 copy->_openerNavigationIndex = _openerNavigationIndex; | 209 copy->_openerNavigationIndex = _openerNavigationIndex; |
| 274 copy.windowName = self.windowName; | 210 copy.windowName = self.windowName; |
| 275 copy->_currentNavigationIndex = _currentNavigationIndex; | 211 copy->_currentNavigationIndex = _currentNavigationIndex; |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 item->SetURL(loaded_url); | 828 item->SetURL(loaded_url); |
| 893 item->SetReferrer(referrer); | 829 item->SetReferrer(referrer); |
| 894 item->SetTransitionType(transition); | 830 item->SetTransitionType(transition); |
| 895 item->SetIsOverridingUserAgent(useDesktopUserAgent); | 831 item->SetIsOverridingUserAgent(useDesktopUserAgent); |
| 896 item->set_is_renderer_initiated(rendererInitiated); | 832 item->set_is_renderer_initiated(rendererInitiated); |
| 897 return [ | 833 return [ |
| 898 [[CRWSessionEntry alloc] initWithNavigationItem:item.Pass()] autorelease]; | 834 [[CRWSessionEntry alloc] initWithNavigationItem:item.Pass()] autorelease]; |
| 899 } | 835 } |
| 900 | 836 |
| 901 @end | 837 @end |
| OLD | NEW |