| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/public/crw_session_storage.h" | 5 #import "ios/web/public/crw_session_storage.h" |
| 6 | 6 |
| 7 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 7 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
| 8 #import "ios/web/public/serializable_user_data_manager.h" | 8 #import "ios/web/public/serializable_user_data_manager.h" |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." | 11 #error "This file requires ARC support." |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // Serialization keys used in NSCoding functions. | 15 // Serialization keys used in NSCoding functions. |
| 16 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; | 16 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; |
| 17 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; | 17 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; |
| 18 NSString* const kItemStoragesKey = @"entries"; | 18 NSString* const kItemStoragesKey = @"entries"; |
| 19 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; | |
| 20 NSString* const kOpenedByDOMKey = @"openedByDOM"; | 19 NSString* const kOpenedByDOMKey = @"openedByDOM"; |
| 21 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | 20 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
| 22 } | 21 } |
| 23 | 22 |
| 24 @interface CRWSessionStorage () { | 23 @interface CRWSessionStorage () { |
| 25 // Backing object for property of same name. | 24 // Backing object for property of same name. |
| 26 std::unique_ptr<web::SerializableUserData> _userData; | 25 std::unique_ptr<web::SerializableUserData> _userData; |
| 27 } | 26 } |
| 28 | 27 |
| 29 @end | 28 @end |
| 30 | 29 |
| 31 @implementation CRWSessionStorage | 30 @implementation CRWSessionStorage |
| 32 | 31 |
| 33 @synthesize openedByDOM = _openedByDOM; | 32 @synthesize openedByDOM = _openedByDOM; |
| 34 @synthesize currentNavigationIndex = _currentNavigationIndex; | 33 @synthesize currentNavigationIndex = _currentNavigationIndex; |
| 35 @synthesize previousNavigationIndex = _previousNavigationIndex; | 34 @synthesize previousNavigationIndex = _previousNavigationIndex; |
| 36 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | |
| 37 @synthesize itemStorages = _itemStorages; | 35 @synthesize itemStorages = _itemStorages; |
| 38 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 36 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 39 | 37 |
| 40 #pragma mark - Accessors | 38 #pragma mark - Accessors |
| 41 | 39 |
| 42 - (web::SerializableUserData*)userData { | 40 - (web::SerializableUserData*)userData { |
| 43 return _userData.get(); | 41 return _userData.get(); |
| 44 } | 42 } |
| 45 | 43 |
| 46 - (void)setSerializableUserData: | 44 - (void)setSerializableUserData: |
| 47 (std::unique_ptr<web::SerializableUserData>)userData { | 45 (std::unique_ptr<web::SerializableUserData>)userData { |
| 48 _userData = std::move(userData); | 46 _userData = std::move(userData); |
| 49 } | 47 } |
| 50 | 48 |
| 51 #pragma mark - NSCoding | 49 #pragma mark - NSCoding |
| 52 | 50 |
| 53 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { | 51 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { |
| 54 self = [super init]; | 52 self = [super init]; |
| 55 if (self) { | 53 if (self) { |
| 56 _openedByDOM = [decoder decodeBoolForKey:kOpenedByDOMKey]; | 54 _openedByDOM = [decoder decodeBoolForKey:kOpenedByDOMKey]; |
| 57 _currentNavigationIndex = | 55 _currentNavigationIndex = |
| 58 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; | 56 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; |
| 59 _previousNavigationIndex = | 57 _previousNavigationIndex = |
| 60 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; | 58 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; |
| 61 _lastVisitedTimestamp = | |
| 62 [decoder decodeDoubleForKey:kLastVisitedTimestampKey]; | |
| 63 _itemStorages = [[NSMutableArray alloc] | 59 _itemStorages = [[NSMutableArray alloc] |
| 64 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; | 60 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; |
| 65 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 61 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
| 66 if (!_itemStorages.count) | 62 if (!_itemStorages.count) |
| 67 _currentNavigationIndex = -1; | 63 _currentNavigationIndex = -1; |
| 68 _sessionCertificatePolicyManager = | 64 _sessionCertificatePolicyManager = |
| 69 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; | 65 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
| 70 if (!_sessionCertificatePolicyManager) { | 66 if (!_sessionCertificatePolicyManager) { |
| 71 _sessionCertificatePolicyManager = | 67 _sessionCertificatePolicyManager = |
| 72 [[CRWSessionCertificatePolicyManager alloc] init]; | 68 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 73 } | 69 } |
| 74 _userData = web::SerializableUserData::Create(); | 70 _userData = web::SerializableUserData::Create(); |
| 75 _userData->Decode(decoder); | 71 _userData->Decode(decoder); |
| 76 } | 72 } |
| 77 return self; | 73 return self; |
| 78 } | 74 } |
| 79 | 75 |
| 80 - (void)encodeWithCoder:(NSCoder*)coder { | 76 - (void)encodeWithCoder:(NSCoder*)coder { |
| 81 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; | 77 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; |
| 82 [coder encodeInt:self.currentNavigationIndex | 78 [coder encodeInt:self.currentNavigationIndex |
| 83 forKey:kCurrentNavigationIndexKey]; | 79 forKey:kCurrentNavigationIndexKey]; |
| 84 [coder encodeInt:self.previousNavigationIndex | 80 [coder encodeInt:self.previousNavigationIndex |
| 85 forKey:kPreviousNavigationIndexKey]; | 81 forKey:kPreviousNavigationIndexKey]; |
| 86 [coder encodeDouble:self.lastVisitedTimestamp | |
| 87 forKey:kLastVisitedTimestampKey]; | |
| 88 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; | 82 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; |
| 89 [coder encodeObject:self.sessionCertificatePolicyManager | 83 [coder encodeObject:self.sessionCertificatePolicyManager |
| 90 forKey:kCertificatePolicyManagerKey]; | 84 forKey:kCertificatePolicyManagerKey]; |
| 91 if (_userData) | 85 if (_userData) |
| 92 _userData->Encode(coder); | 86 _userData->Encode(coder); |
| 93 } | 87 } |
| 94 | 88 |
| 95 @end | 89 @end |
| OLD | NEW |