Chromium Code Reviews| 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/navigation/crw_serialized_navigation_manager.h" | 5 #import "ios/web/navigation/crw_serialized_navigation_manager.h" |
| 6 | 6 |
| 7 #include "base/mac/objc_property_releaser.h" | 7 #include "base/mac/objc_property_releaser.h" |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 8 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 9 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 // Serialization keys used in NSCoding functions. | 12 // Serialization keys used in NSCoding functions. |
| 12 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; | 13 NSString* const kCertificatePolicyManagerKey = @"certificatePolicyManager"; |
| 13 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; | 14 NSString* const kCurrentNavigationIndexKey = @"currentNavigationIndex"; |
| 14 NSString* const kEntriesKey = @"entries"; | 15 NSString* const kEntriesKey = @"entries"; |
| 15 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; | 16 NSString* const kLastVisitedTimestampKey = @"lastVisitedTimestamp"; |
| 16 NSString* const kOpenerIDKey = @"openerId"; | 17 NSString* const kOpenerIDKey = @"openerId"; |
| 17 NSString* const kOpenedByDOMKey = @"openedByDOM"; | 18 NSString* const kOpenedByDOMKey = @"openedByDOM"; |
| 18 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; | 19 NSString* const kOpenerNavigationIndexKey = @"openerNavigationIndex"; |
| 19 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; | 20 NSString* const kPreviousNavigationIndexKey = @"previousNavigationIndex"; |
| 20 NSString* const kTabIDKey = @"tabId"; | 21 NSString* const kTabIDKey = @"tabId"; |
| 21 NSString* const kWindowNameKey = @"windowName"; | 22 NSString* const kWindowNameKey = @"windowName"; |
| 22 NSString* const kXCallbackParametersKey = @"xCallbackParameters"; | 23 NSString* const kXCallbackParametersKey = @"xCallbackParameters"; |
| 24 NSString* const kSerializedUserDataKey = @"serializedUserData"; | |
| 23 } | 25 } |
| 24 | 26 |
| 25 @interface CRWSerializedNavigationManager () { | 27 @interface CRWSerializedNavigationManager () { |
| 28 // |serializedUserData| is backed with an NSMutableDictionary so that | |
| 29 // NavigationManager's legacy properties can be decoded and added directly to | |
| 30 // the dictionary. | |
| 31 base::scoped_nsobject<NSMutableDictionary> _serializedUserData; | |
| 32 | |
| 26 base::mac::ObjCPropertyReleaser | 33 base::mac::ObjCPropertyReleaser |
| 27 _propertyReleaser_CRWSerializedNavigationManager; | 34 _propertyReleaser_CRWSerializedNavigationManager; |
| 28 } | 35 } |
| 29 @end | 36 @end |
| 30 | 37 |
| 31 @implementation CRWSerializedNavigationManager | 38 @implementation CRWSerializedNavigationManager |
| 32 | 39 |
| 33 @synthesize tabID = _tabID; | 40 @synthesize tabID = _tabID; |
| 34 @synthesize openerID = _openerID; | 41 @synthesize openerID = _openerID; |
| 35 @synthesize openedByDOM = _openedByDOM; | 42 @synthesize openedByDOM = _openedByDOM; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 if (!_entries.count) | 79 if (!_entries.count) |
| 73 _currentNavigationIndex = -1; | 80 _currentNavigationIndex = -1; |
| 74 _sessionCertificatePolicyManager = | 81 _sessionCertificatePolicyManager = |
| 75 [[decoder decodeObjectForKey:kCertificatePolicyManagerKey] retain]; | 82 [[decoder decodeObjectForKey:kCertificatePolicyManagerKey] retain]; |
| 76 if (!_sessionCertificatePolicyManager) { | 83 if (!_sessionCertificatePolicyManager) { |
| 77 _sessionCertificatePolicyManager = | 84 _sessionCertificatePolicyManager = |
| 78 [[CRWSessionCertificatePolicyManager alloc] init]; | 85 [[CRWSessionCertificatePolicyManager alloc] init]; |
| 79 } | 86 } |
| 80 _XCallbackParameters = | 87 _XCallbackParameters = |
| 81 [[decoder decodeObjectForKey:kXCallbackParametersKey] retain]; | 88 [[decoder decodeObjectForKey:kXCallbackParametersKey] retain]; |
| 89 _serializedUserData.reset([[NSMutableDictionary alloc] initWithDictionary: | |
| 90 [decoder decodeObjectForKey:kSerializedUserDataKey]]); | |
| 82 } | 91 } |
| 83 return self; | 92 return self; |
| 84 } | 93 } |
| 85 | 94 |
| 86 - (void)encodeWithCoder:(NSCoder*)coder { | 95 - (void)encodeWithCoder:(NSCoder*)coder { |
| 87 [coder encodeObject:self.tabID forKey:kTabIDKey]; | 96 [coder encodeObject:self.tabID forKey:kTabIDKey]; |
| 88 [coder encodeObject:self.openerID forKey:kOpenerIDKey]; | 97 [coder encodeObject:self.openerID forKey:kOpenerIDKey]; |
| 89 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; | 98 [coder encodeBool:self.openedByDOM forKey:kOpenedByDOMKey]; |
| 90 [coder encodeInt:self.openerNavigationIndex forKey:kOpenerNavigationIndexKey]; | 99 [coder encodeInt:self.openerNavigationIndex forKey:kOpenerNavigationIndexKey]; |
| 91 [coder encodeObject:self.windowName forKey:kWindowNameKey]; | 100 [coder encodeObject:self.windowName forKey:kWindowNameKey]; |
| 92 [coder encodeInt:self.currentNavigationIndex | 101 [coder encodeInt:self.currentNavigationIndex |
| 93 forKey:kCurrentNavigationIndexKey]; | 102 forKey:kCurrentNavigationIndexKey]; |
| 94 [coder encodeInt:self.previousNavigationIndex | 103 [coder encodeInt:self.previousNavigationIndex |
| 95 forKey:kPreviousNavigationIndexKey]; | 104 forKey:kPreviousNavigationIndexKey]; |
| 96 [coder encodeDouble:self.lastVisitedTimestamp | 105 [coder encodeDouble:self.lastVisitedTimestamp |
| 97 forKey:kLastVisitedTimestampKey]; | 106 forKey:kLastVisitedTimestampKey]; |
| 98 [coder encodeObject:self.entries forKey:kEntriesKey]; | 107 [coder encodeObject:self.entries forKey:kEntriesKey]; |
| 99 [coder encodeObject:self.sessionCertificatePolicyManager | 108 [coder encodeObject:self.sessionCertificatePolicyManager |
| 100 forKey:kCertificatePolicyManagerKey]; | 109 forKey:kCertificatePolicyManagerKey]; |
| 101 [coder encodeObject:self.XCallbackParameters forKey:kXCallbackParametersKey]; | 110 [coder encodeObject:self.XCallbackParameters forKey:kXCallbackParametersKey]; |
| 102 // rendererInitiated is deliberately not preserved, as upstream. | 111 // rendererInitiated is deliberately not preserved, as upstream. |
| 112 [coder encodeObject:self.serializedUserData forKey:kSerializedUserDataKey]; | |
| 113 } | |
| 114 | |
| 115 - (void)setSerializedUserData:(NSDictionary*)serializedUserData { | |
| 116 _serializedUserData.reset( | |
| 117 [[NSMutableDictionary alloc] initWithDictionary:serializedUserData]); | |
| 118 } | |
| 119 | |
| 120 - (NSDictionary*)serializedUserData { | |
| 121 return _serializedUserData; | |
|
Eugene But (OOO till 7-30)
2015/09/24 21:39:25
NIT: Maybe return an autoreleased copy here (same
| |
| 103 } | 122 } |
| 104 | 123 |
| 105 @end | 124 @end |
| OLD | NEW |