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