OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_navigation_item_storage.h" | 5 #import "ios/web/public/crw_navigation_item_storage.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #import "ios/web/navigation/nscoder_util.h" | 8 #import "ios/web/navigation/nscoder_util.h" |
| 9 #import "ios/web/public/web_client.h" |
9 #import "net/base/mac/url_conversions.h" | 10 #import "net/base/mac/url_conversions.h" |
10 | 11 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
13 #endif | 14 #endif |
14 | 15 |
15 namespace web { | 16 namespace web { |
16 | 17 |
17 // Keys used to serialize navigation properties. | 18 // Keys used to serialize navigation properties. |
18 NSString* const kNavigationItemStorageURLKey = @"virtualUrlString"; | 19 NSString* const kNavigationItemStorageURLKey = @"virtualUrlString"; |
19 NSString* const kNavigationItemStorageURLDeperecatedKey = @"virtualUrl"; | 20 NSString* const kNavigationItemStorageURLDeperecatedKey = @"virtualUrl"; |
20 NSString* const kNavigationItemStorageReferrerURLKey = @"referrerUrlString"; | 21 NSString* const kNavigationItemStorageReferrerURLKey = @"referrerUrlString"; |
21 NSString* const kNavigationItemStorageReferrerURLDeprecatedKey = @"referrer"; | 22 NSString* const kNavigationItemStorageReferrerURLDeprecatedKey = @"referrer"; |
22 NSString* const kNavigationItemStorageReferrerPolicyKey = @"referrerPolicy"; | 23 NSString* const kNavigationItemStorageReferrerPolicyKey = @"referrerPolicy"; |
23 NSString* const kNavigationItemStorageTimestampKey = @"timestamp"; | 24 NSString* const kNavigationItemStorageTimestampKey = @"timestamp"; |
24 NSString* const kNavigationItemStorageTitleKey = @"title"; | 25 NSString* const kNavigationItemStorageTitleKey = @"title"; |
25 NSString* const kNavigationItemStoragePageDisplayStateKey = @"state"; | 26 NSString* const kNavigationItemStoragePageDisplayStateKey = @"state"; |
26 NSString* const kNavigationItemStoragePOSTDataKey = @"POSTData"; | 27 NSString* const kNavigationItemStoragePOSTDataKey = @"POSTData"; |
27 NSString* const kNavigationItemStorageHTTPRequestHeadersKey = @"httpHeaders"; | 28 NSString* const kNavigationItemStorageHTTPRequestHeadersKey = @"httpHeaders"; |
28 NSString* const kNavigationItemStorageSkipRepostFormConfirmationKey = | 29 NSString* const kNavigationItemStorageSkipRepostFormConfirmationKey = |
29 @"skipResubmitDataConfirmation"; | 30 @"skipResubmitDataConfirmation"; |
30 NSString* const kNavigationItemStorageUseDesktopUserAgentKey = | 31 NSString* const kNavigationItemStorageUserAgentTypeKey = @"userAgentType"; |
| 32 NSString* const kNavigationItemStorageUseDesktopUserAgentDeprecatedKey = |
31 @"useDesktopUserAgent"; | 33 @"useDesktopUserAgent"; |
32 | 34 |
33 } // namespace web | 35 } // namespace web |
34 | 36 |
35 @implementation CRWNavigationItemStorage | 37 @implementation CRWNavigationItemStorage |
36 | 38 |
37 @synthesize virtualURL = _virtualURL; | 39 @synthesize virtualURL = _virtualURL; |
38 @synthesize referrer = _referrer; | 40 @synthesize referrer = _referrer; |
39 @synthesize timestamp = _timestamp; | 41 @synthesize timestamp = _timestamp; |
40 @synthesize title = _title; | 42 @synthesize title = _title; |
41 @synthesize displayState = _displayState; | 43 @synthesize displayState = _displayState; |
42 @synthesize shouldSkipRepostFormConfirmation = | 44 @synthesize shouldSkipRepostFormConfirmation = |
43 _shouldSkipRepostFormConfirmation; | 45 _shouldSkipRepostFormConfirmation; |
44 @synthesize overridingUserAgent = _overridingUserAgent; | 46 @synthesize userAgentType = _userAgentType; |
45 @synthesize POSTData = _POSTData; | 47 @synthesize POSTData = _POSTData; |
46 @synthesize HTTPRequestHeaders = _HTTPRequestHeaders; | 48 @synthesize HTTPRequestHeaders = _HTTPRequestHeaders; |
47 | 49 |
48 #pragma mark - NSObject | 50 #pragma mark - NSObject |
49 | 51 |
50 - (NSString*)description { | 52 - (NSString*)description { |
51 NSMutableString* description = | 53 NSMutableString* description = |
52 [NSMutableString stringWithString:[super description]]; | 54 [NSMutableString stringWithString:[super description]]; |
53 [description appendFormat:@"virtualURL : %s, ", _virtualURL.spec().c_str()]; | 55 [description appendFormat:@"virtualURL : %s, ", _virtualURL.spec().c_str()]; |
54 [description appendFormat:@"referrer : %s, ", _referrer.url.spec().c_str()]; | 56 [description appendFormat:@"referrer : %s, ", _referrer.url.spec().c_str()]; |
55 [description appendFormat:@"timestamp : %f, ", _timestamp.ToCFAbsoluteTime()]; | 57 [description appendFormat:@"timestamp : %f, ", _timestamp.ToCFAbsoluteTime()]; |
56 [description appendFormat:@"title : %@, ", base::SysUTF16ToNSString(_title)]; | 58 [description appendFormat:@"title : %@, ", base::SysUTF16ToNSString(_title)]; |
57 [description | 59 [description |
58 appendFormat:@"displayState : %@", _displayState.GetDescription()]; | 60 appendFormat:@"displayState : %@", _displayState.GetDescription()]; |
59 [description appendFormat:@"skipRepostConfirmation : %@, ", | 61 [description appendFormat:@"skipRepostConfirmation : %@, ", |
60 @(_shouldSkipRepostFormConfirmation)]; | 62 @(_shouldSkipRepostFormConfirmation)]; |
61 [description | 63 [description |
62 appendFormat:@"overridingUserAgent : %@, ", @(_overridingUserAgent)]; | 64 appendFormat:@"userAgentType : %s, ", |
| 65 web::GetUserAgentTypeDescription(_userAgentType).c_str()]; |
63 [description appendFormat:@"POSTData : %@, ", _POSTData]; | 66 [description appendFormat:@"POSTData : %@, ", _POSTData]; |
64 [description appendFormat:@"HTTPRequestHeaders : %@", _HTTPRequestHeaders]; | 67 [description appendFormat:@"HTTPRequestHeaders : %@", _HTTPRequestHeaders]; |
65 return description; | 68 return description; |
66 } | 69 } |
67 | 70 |
68 #pragma mark - NSCoding | 71 #pragma mark - NSCoding |
69 | 72 |
70 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 73 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
71 self = [super init]; | 74 self = [super init]; |
72 if (self) { | 75 if (self) { |
(...skipping 25 matching lines...) Expand all Loading... |
98 web::ReferrerPolicyDefault); | 101 web::ReferrerPolicyDefault); |
99 } | 102 } |
100 | 103 |
101 if ([aDecoder | 104 if ([aDecoder |
102 containsValueForKey:web::kNavigationItemStorageTimestampKey]) { | 105 containsValueForKey:web::kNavigationItemStorageTimestampKey]) { |
103 int64_t us = | 106 int64_t us = |
104 [aDecoder decodeInt64ForKey:web::kNavigationItemStorageTimestampKey]; | 107 [aDecoder decodeInt64ForKey:web::kNavigationItemStorageTimestampKey]; |
105 _timestamp = base::Time::FromInternalValue(us); | 108 _timestamp = base::Time::FromInternalValue(us); |
106 } | 109 } |
107 | 110 |
| 111 if ([aDecoder |
| 112 containsValueForKey:web::kNavigationItemStorageUserAgentTypeKey]) { |
| 113 std::string userAgentDescription = web::nscoder_util::DecodeString( |
| 114 aDecoder, web::kNavigationItemStorageUserAgentTypeKey); |
| 115 _userAgentType = |
| 116 web::GetUserAgentTypeWithDescription(userAgentDescription); |
| 117 } else if (web::GetWebClient()->IsAppSpecificURL(_virtualURL)) { |
| 118 // Legacy CRWNavigationItemStorages didn't have the concept of a NONE |
| 119 // user agent for app-specific URLs, so check decoded virtual URL before |
| 120 // attempting to decode the deprecated key. |
| 121 _userAgentType = web::UserAgentType::NONE; |
| 122 } else { |
| 123 // The user agent type was previously recorded as a BOOL, where YES meant |
| 124 // desktop user agent, and NO meant mobile user agent. |
| 125 BOOL useDesktopUA = [aDecoder |
| 126 decodeBoolForKey: |
| 127 web::kNavigationItemStorageUseDesktopUserAgentDeprecatedKey]; |
| 128 _userAgentType = useDesktopUA ? web::UserAgentType::DESKTOP |
| 129 : web::UserAgentType::MOBILE; |
| 130 } |
| 131 |
108 NSString* title = | 132 NSString* title = |
109 [aDecoder decodeObjectForKey:web::kNavigationItemStorageTitleKey]; | 133 [aDecoder decodeObjectForKey:web::kNavigationItemStorageTitleKey]; |
110 // Use a transition type of reload so that we don't incorrectly increase | 134 // Use a transition type of reload so that we don't incorrectly increase |
111 // the typed count. This is what desktop chrome does. | 135 // the typed count. This is what desktop chrome does. |
112 _title = base::SysNSStringToUTF16(title); | 136 _title = base::SysNSStringToUTF16(title); |
113 NSDictionary* serializedDisplayState = [aDecoder | 137 NSDictionary* serializedDisplayState = [aDecoder |
114 decodeObjectForKey:web::kNavigationItemStoragePageDisplayStateKey]; | 138 decodeObjectForKey:web::kNavigationItemStoragePageDisplayStateKey]; |
115 _displayState = web::PageDisplayState(serializedDisplayState); | 139 _displayState = web::PageDisplayState(serializedDisplayState); |
116 _shouldSkipRepostFormConfirmation = | 140 _shouldSkipRepostFormConfirmation = |
117 [aDecoder decodeBoolForKey: | 141 [aDecoder decodeBoolForKey: |
118 web::kNavigationItemStorageSkipRepostFormConfirmationKey]; | 142 web::kNavigationItemStorageSkipRepostFormConfirmationKey]; |
119 _overridingUserAgent = [aDecoder | |
120 decodeBoolForKey:web::kNavigationItemStorageUseDesktopUserAgentKey]; | |
121 _POSTData = | 143 _POSTData = |
122 [aDecoder decodeObjectForKey:web::kNavigationItemStoragePOSTDataKey]; | 144 [aDecoder decodeObjectForKey:web::kNavigationItemStoragePOSTDataKey]; |
123 _HTTPRequestHeaders = [aDecoder | 145 _HTTPRequestHeaders = [aDecoder |
124 decodeObjectForKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; | 146 decodeObjectForKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; |
125 } | 147 } |
126 return self; | 148 return self; |
127 } | 149 } |
128 | 150 |
129 - (void)encodeWithCoder:(NSCoder*)aCoder { | 151 - (void)encodeWithCoder:(NSCoder*)aCoder { |
130 // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only | 152 // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only |
131 // |virtualUrl_|. | 153 // |virtualUrl_|. |
132 web::nscoder_util::EncodeString(aCoder, web::kNavigationItemStorageURLKey, | 154 web::nscoder_util::EncodeString(aCoder, web::kNavigationItemStorageURLKey, |
133 _virtualURL.spec()); | 155 _virtualURL.spec()); |
134 web::nscoder_util::EncodeString( | 156 web::nscoder_util::EncodeString( |
135 aCoder, web::kNavigationItemStorageReferrerURLKey, _referrer.url.spec()); | 157 aCoder, web::kNavigationItemStorageReferrerURLKey, _referrer.url.spec()); |
136 [aCoder encodeInt:_referrer.policy | 158 [aCoder encodeInt:_referrer.policy |
137 forKey:web::kNavigationItemStorageReferrerPolicyKey]; | 159 forKey:web::kNavigationItemStorageReferrerPolicyKey]; |
138 [aCoder encodeInt64:_timestamp.ToInternalValue() | 160 [aCoder encodeInt64:_timestamp.ToInternalValue() |
139 forKey:web::kNavigationItemStorageTimestampKey]; | 161 forKey:web::kNavigationItemStorageTimestampKey]; |
140 | 162 |
141 [aCoder encodeObject:base::SysUTF16ToNSString(_title) | 163 [aCoder encodeObject:base::SysUTF16ToNSString(_title) |
142 forKey:web::kNavigationItemStorageTitleKey]; | 164 forKey:web::kNavigationItemStorageTitleKey]; |
143 [aCoder encodeObject:_displayState.GetSerialization() | 165 [aCoder encodeObject:_displayState.GetSerialization() |
144 forKey:web::kNavigationItemStoragePageDisplayStateKey]; | 166 forKey:web::kNavigationItemStoragePageDisplayStateKey]; |
145 [aCoder encodeBool:_shouldSkipRepostFormConfirmation | 167 [aCoder encodeBool:_shouldSkipRepostFormConfirmation |
146 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey]; | 168 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey]; |
147 [aCoder encodeBool:_overridingUserAgent | 169 web::nscoder_util::EncodeString( |
148 forKey:web::kNavigationItemStorageUseDesktopUserAgentKey]; | 170 aCoder, web::kNavigationItemStorageUserAgentTypeKey, |
| 171 web::GetUserAgentTypeDescription(_userAgentType)); |
149 [aCoder encodeObject:_POSTData forKey:web::kNavigationItemStoragePOSTDataKey]; | 172 [aCoder encodeObject:_POSTData forKey:web::kNavigationItemStoragePOSTDataKey]; |
150 [aCoder encodeObject:_HTTPRequestHeaders | 173 [aCoder encodeObject:_HTTPRequestHeaders |
151 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; | 174 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey]; |
152 } | 175 } |
153 | 176 |
154 @end | 177 @end |
OLD | NEW |