| 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"; | 19 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; |
| 20 NSString* const kOpenerIDKey = @"openerId"; | 20 NSString* const kOpenerIDKey = @"openerId"; |
| 21 NSString* const kOpenedByDOMKey = @"openedByDOM"; | 21 NSString* const kOpenedByDOMKey = @"openedByDOM"; |
| 22 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; | 22 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; |
| 23 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | 23 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
| 24 NSString* const kTabIDKey = @"tabId"; | |
| 25 NSString* const kWindowNameKey = @"windowName"; | 24 NSString* const kWindowNameKey = @"windowName"; |
| 26 } | 25 } |
| 27 | 26 |
| 28 @interface CRWSessionStorage () { | 27 @interface CRWSessionStorage () { |
| 29 // Backing object for property of same name. | 28 // Backing object for property of same name. |
| 30 std::unique_ptr<web::SerializableUserData> _userData; | 29 std::unique_ptr<web::SerializableUserData> _userData; |
| 31 } | 30 } |
| 32 | 31 |
| 33 @end | 32 @end |
| 34 | 33 |
| 35 @implementation CRWSessionStorage | 34 @implementation CRWSessionStorage |
| 36 | 35 |
| 37 @synthesize tabID = _tabID; | |
| 38 @synthesize openerID = _openerID; | 36 @synthesize openerID = _openerID; |
| 39 @synthesize openedByDOM = _openedByDOM; | 37 @synthesize openedByDOM = _openedByDOM; |
| 40 @synthesize openerNavigationIndex = _openerNavigationIndex; | 38 @synthesize openerNavigationIndex = _openerNavigationIndex; |
| 41 @synthesize windowName = _windowName; | 39 @synthesize windowName = _windowName; |
| 42 @synthesize currentNavigationIndex = _currentNavigationIndex; | 40 @synthesize currentNavigationIndex = _currentNavigationIndex; |
| 43 @synthesize previousNavigationIndex = _previousNavigationIndex; | 41 @synthesize previousNavigationIndex = _previousNavigationIndex; |
| 44 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | 42 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
| 45 @synthesize itemStorages = _itemStorages; | 43 @synthesize itemStorages = _itemStorages; |
| 46 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 44 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
| 47 | 45 |
| 48 #pragma mark - Accessors | 46 #pragma mark - Accessors |
| 49 | 47 |
| 50 - (web::SerializableUserData*)userData { | 48 - (web::SerializableUserData*)userData { |
| 51 return _userData.get(); | 49 return _userData.get(); |
| 52 } | 50 } |
| 53 | 51 |
| 54 - (void)setSerializableUserData: | 52 - (void)setSerializableUserData: |
| 55 (std::unique_ptr<web::SerializableUserData>)userData { | 53 (std::unique_ptr<web::SerializableUserData>)userData { |
| 56 _userData = std::move(userData); | 54 _userData = std::move(userData); |
| 57 } | 55 } |
| 58 | 56 |
| 59 #pragma mark - NSCoding | 57 #pragma mark - NSCoding |
| 60 | 58 |
| 61 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { | 59 - (instancetype)initWithCoder:(nonnull NSCoder*)decoder { |
| 62 self = [super init]; | 60 self = [super init]; |
| 63 if (self) { | 61 if (self) { |
| 64 _tabID = [[decoder decodeObjectForKey:kTabIDKey] copy]; | |
| 65 _windowName = [[decoder decodeObjectForKey:kWindowNameKey] copy]; | 62 _windowName = [[decoder decodeObjectForKey:kWindowNameKey] copy]; |
| 66 _openerID = [[decoder decodeObjectForKey:kOpenerIDKey] copy]; | 63 _openerID = [[decoder decodeObjectForKey:kOpenerIDKey] copy]; |
| 67 _openedByDOM = [decoder decodeBoolForKey:kOpenedByDOMKey]; | 64 _openedByDOM = [decoder decodeBoolForKey:kOpenedByDOMKey]; |
| 68 _openerNavigationIndex = | 65 _openerNavigationIndex = |
| 69 [decoder decodeIntForKey:kOpenerNavigationIndexKey]; | 66 [decoder decodeIntForKey:kOpenerNavigationIndexKey]; |
| 70 _currentNavigationIndex = | 67 _currentNavigationIndex = |
| 71 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; | 68 [decoder decodeIntForKey:kCurrentNavigationIndexKey]; |
| 72 _previousNavigationIndex = | 69 _previousNavigationIndex = |
| 73 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; | 70 [decoder decodeIntForKey:kPreviousNavigationIndexKey]; |
| 74 _lastVisitedTimestamp = | 71 _lastVisitedTimestamp = |
| 75 [decoder decodeDoubleForKey:kLastVisitedTimestampKey]; | 72 [decoder decodeDoubleForKey:kLastVisitedTimestampKey]; |
| 76 _itemStorages = [[NSMutableArray alloc] | 73 _itemStorages = [[NSMutableArray alloc] |
| 77 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; | 74 initWithArray:[decoder decodeObjectForKey:kItemStoragesKey]]; |
| 78 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 75 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
| 79 if (!_itemStorages.count) | 76 if (!_itemStorages.count) |
| 80 _currentNavigationIndex = -1; | 77 _currentNavigationIndex = -1; |
| 81 _sessionCertificatePolicyManager = | 78 _sessionCertificatePolicyManager = |
| 82 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; | 79 [decoder decodeObjectForKey:kCertificatePolicyManagerKey]; |
| 83 if (!_sessionCertificatePolicyManager) { | 80 if (!_sessionCertificatePolicyManager) { |
| 84 _sessionCertificatePolicyManager = | 81 _sessionCertificatePolicyManager = |
| 85 [[CRWSessionCertificatePolicyManager alloc] init]; | 82 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 86 } | 83 } |
| 87 _userData = web::SerializableUserData::Create(); | 84 _userData = web::SerializableUserData::Create(); |
| 88 _userData->Decode(decoder); | 85 _userData->Decode(decoder); |
| 89 } | 86 } |
| 90 return self; | 87 return self; |
| 91 } | 88 } |
| 92 | 89 |
| 93 - (void)encodeWithCoder:(NSCoder*)coder { | 90 - (void)encodeWithCoder:(NSCoder*)coder { |
| 94 [coder encodeObject:self.tabID forKey:kTabIDKey]; | |
| 95 [coder encodeObject:self.openerID forKey:kOpenerIDKey]; | 91 [coder encodeObject:self.openerID forKey:kOpenerIDKey]; |
| 96 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; | 92 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; |
| 97 [coder encodeInt:self.openerNavigationIndex forKey:kOpenerNavigationIndexKey]; | 93 [coder encodeInt:self.openerNavigationIndex forKey:kOpenerNavigationIndexKey]; |
| 98 [coder encodeObject:self.windowName forKey:kWindowNameKey]; | 94 [coder encodeObject:self.windowName forKey:kWindowNameKey]; |
| 99 [coder encodeInt:self.currentNavigationIndex | 95 [coder encodeInt:self.currentNavigationIndex |
| 100 forKey:kCurrentNavigationIndexKey]; | 96 forKey:kCurrentNavigationIndexKey]; |
| 101 [coder encodeInt:self.previousNavigationIndex | 97 [coder encodeInt:self.previousNavigationIndex |
| 102 forKey:kPreviousNavigationIndexKey]; | 98 forKey:kPreviousNavigationIndexKey]; |
| 103 [coder encodeDouble:self.lastVisitedTimestamp | 99 [coder encodeDouble:self.lastVisitedTimestamp |
| 104 forKey:kLastVisitedTimestampKey]; | 100 forKey:kLastVisitedTimestampKey]; |
| 105 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; | 101 [coder encodeObject:self.itemStorages forKey:kItemStoragesKey]; |
| 106 [coder encodeObject:self.sessionCertificatePolicyManager | 102 [coder encodeObject:self.sessionCertificatePolicyManager |
| 107 forKey:kCertificatePolicyManagerKey]; | 103 forKey:kCertificatePolicyManagerKey]; |
| 108 if (_userData) | 104 if (_userData) |
| 109 _userData->Encode(coder); | 105 _userData->Encode(coder); |
| 110 // rendererInitiated is deliberately not preserved, as upstream. | 106 // rendererInitiated is deliberately not preserved, as upstream. |
| 111 } | 107 } |
| 112 | 108 |
| 113 @end | 109 @end |
| OLD | NEW |