| 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 kOpenedByDOMKey = @"openedByDOM"; | 19 NSString* const kHasOpenerKey = @"openedByDOM"; |
| 20 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | 20 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 @interface CRWSessionStorage () { | 23 @interface CRWSessionStorage () { |
| 24 // Backing object for property of same name. | 24 // Backing object for property of same name. |
| 25 std::unique_ptr<web::SerializableUserData> _userData; | 25 std::unique_ptr<web::SerializableUserData> _userData; |
| 26 } | 26 } |
| 27 | 27 |
| 28 @end | 28 @end |
| 29 | 29 |
| 30 @implementation CRWSessionStorage | 30 @implementation CRWSessionStorage |
| 31 | 31 |
| 32 @synthesize openedByDOM = _openedByDOM; | 32 @synthesize hasOpener = _hasOpener; |
| 33 @synthesize currentNavigationIndex = _currentNavigationIndex; | 33 @synthesize currentNavigationIndex = _currentNavigationIndex; |
| 34 @synthesize previousNavigationIndex = _previousNavigationIndex; | 34 @synthesize previousNavigationIndex = _previousNavigationIndex; |
| 35 @synthesize itemStorages = _itemStorages; | 35 @synthesize itemStorages = _itemStorages; |
| 36 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 36 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 37 | 37 |
| 38 #pragma mark - Accessors | 38 #pragma mark - Accessors |
| 39 | 39 |
| 40 - (web::SerializableUserData*)userData { | 40 - (web::SerializableUserData*)userData { |
| 41 return _userData.get(); | 41 return _userData.get(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 - (void)setSerializableUserData: | 44 - (void)setSerializableUserData: |
| 45 (std::unique_ptr<web::SerializableUserData>)userData { | 45 (std::unique_ptr<web::SerializableUserData>)userData { |
| 46 _userData = std::move(userData); | 46 _userData = std::move(userData); |
| 47 } | 47 } |
| 48 | 48 |
| 49 #pragma mark - NSCoding | 49 #pragma mark - NSCoding |
| 50 | 50 |
| 51 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { | 51 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { |
| 52 self = [super init]; | 52 self = [super init]; |
| 53 if (self) { | 53 if (self) { |
| 54 _openedByDOM = [decoder decodeBoolForKey:kOpenedByDOMKey]; | 54 _hasOpener = [decoder decodeBoolForKey:kHasOpenerKey]; |
| 55 _currentNavigationIndex = | 55 _currentNavigationIndex = |
| 56 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; | 56 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; |
| 57 _previousNavigationIndex = | 57 _previousNavigationIndex = |
| 58 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; | 58 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; |
| 59 _itemStorages = [[NSMutableArray alloc] | 59 _itemStorages = [[NSMutableArray alloc] |
| 60 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; | 60 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; |
| 61 // 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. |
| 62 if (!_itemStorages.count) | 62 if (!_itemStorages.count) |
| 63 _currentNavigationIndex = -1; | 63 _currentNavigationIndex = -1; |
| 64 _sessionCertificatePolicyManager = | 64 _sessionCertificatePolicyManager = |
| 65 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; | 65 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
| 66 if (!_sessionCertificatePolicyManager) { | 66 if (!_sessionCertificatePolicyManager) { |
| 67 _sessionCertificatePolicyManager = | 67 _sessionCertificatePolicyManager = |
| 68 [[CRWSessionCertificatePolicyManager alloc] init]; | 68 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 69 } | 69 } |
| 70 _userData = web::SerializableUserData::Create(); | 70 _userData = web::SerializableUserData::Create(); |
| 71 _userData->Decode(decoder); | 71 _userData->Decode(decoder); |
| 72 } | 72 } |
| 73 return self; | 73 return self; |
| 74 } | 74 } |
| 75 | 75 |
| 76 - (void)encodeWithCoder:(NSCoder*)coder { | 76 - (void)encodeWithCoder:(NSCoder*)coder { |
| 77 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; | 77 [coder encodeBool:self.hasOpener forKey:kHasOpenerKey]; |
| 78 [coder encodeInt:self.currentNavigationIndex | 78 [coder encodeInt:self.currentNavigationIndex |
| 79 forKey:kCurrentNavigationIndexKey]; | 79 forKey:kCurrentNavigationIndexKey]; |
| 80 [coder encodeInt:self.previousNavigationIndex | 80 [coder encodeInt:self.previousNavigationIndex |
| 81 forKey:kPreviousNavigationIndexKey]; | 81 forKey:kPreviousNavigationIndexKey]; |
| 82 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; | 82 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; |
| 83 [coder encodeObject:self.sessionCertificatePolicyManager | 83 [coder encodeObject:self.sessionCertificatePolicyManager |
| 84 forKey:kCertificatePolicyManagerKey]; | 84 forKey:kCertificatePolicyManagerKey]; |
| 85 if (_userData) | 85 if (_userData) |
| 86 _userData->Encode(coder); | 86 _userData->Encode(coder); |
| 87 } | 87 } |
| 88 | 88 |
| 89 @end | 89 @end |
| OLD | NEW |