Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: ios/web/public/crw_navigation_item_storage.mm

Issue 2664113003: Moved serialization out of CRWSessionEntry. (Closed)
Patch Set: Eugene's comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/web/public/crw_navigation_item_storage.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #import "ios/web/navigation/nscoder_util.h"
9 #import "net/base/mac/url_conversions.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace web {
16
17 // Keys used to serialize navigation properties.
18 NSString* const kNavigationItemStorageURLKey = @"virtualUrlString";
19 NSString* const kNavigationItemStorageURLDeperecatedKey = @"virtualUrl";
20 NSString* const kNavigationItemStorageReferrerURLKey = @"referrerUrlString";
21 NSString* const kNavigationItemStorageReferrerURLDeprecatedKey = @"referrer";
22 NSString* const kNavigationItemStorageReferrerPolicyKey = @"referrerPolicy";
23 NSString* const kNavigationItemStorageTimestampKey = @"timestamp";
24 NSString* const kNavigationItemStorageTitleKey = @"title";
25 NSString* const kNavigationItemStoragePageDisplayStateKey = @"state";
26 NSString* const kNavigationItemStoragePOSTDataKey = @"POSTData";
27 NSString* const kNavigationItemStorageHTTPRequestHeadersKey = @"httpHeaders";
28 NSString* const kNavigationItemStorageSkipRepostFormConfirmationKey =
29 @"skipResubmitDataConfirmation";
30 NSString* const kNavigationItemStorageUseDesktopUserAgentKey =
31 @"useDesktopUserAgent";
32
33 } // namespace web
34
35 @implementation CRWNavigationItemStorage
36
37 @synthesize virtualURL = _virtualURL;
38 @synthesize referrer = _referrer;
39 @synthesize timestamp = _timestamp;
40 @synthesize title = _title;
41 @synthesize displayState = _displayState;
42 @synthesize shouldSkipRepostFormConfirmation =
43 _shouldSkipRepostFormConfirmation;
44 @synthesize overridingUserAgent = _overridingUserAgent;
45 @synthesize POSTData = _POSTData;
46 @synthesize HTTPRequestHeaders = _HTTPRequestHeaders;
47
48 #pragma mark - NSObject
49
50 - (NSString*)description {
51 NSMutableString* description =
52 [NSMutableString stringWithString:[super description]];
53 [description appendFormat:@"virtualURL : %s, ", _virtualURL.spec().c_str()];
54 [description appendFormat:@"referrer : %s, ", _referrer.url.spec().c_str()];
55 [description appendFormat:@"timestamp : %f, ", _timestamp.ToCFAbsoluteTime()];
56 [description appendFormat:@"title : %@, ", base::SysUTF16ToNSString(_title)];
57 [description
58 appendFormat:@"displayState : %@", _displayState.GetDescription()];
59 [description appendFormat:@"skipRepostConfirmation : %@, ",
60 @(_shouldSkipRepostFormConfirmation)];
61 [description
62 appendFormat:@"overridingUserAgent : %@, ", @(_overridingUserAgent)];
63 [description appendFormat:@"POSTData : %@, ", _POSTData];
64 [description appendFormat:@"HTTPRequestHeaders : %@", _HTTPRequestHeaders];
65 return description;
66 }
67
68 #pragma mark - NSCoding
69
70 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
71 self = [super init];
72 if (self) {
73 // Desktop chrome only persists virtualUrl_ and uses it to feed the url
74 // when creating a NavigationEntry.
75 if ([aDecoder containsValueForKey:web::kNavigationItemStorageURLKey]) {
76 _virtualURL = GURL(web::nscoder_util::DecodeString(
77 aDecoder, web::kNavigationItemStorageURLKey));
78 } else {
79 // Backward compatibility.
80 _virtualURL = net::GURLWithNSURL([aDecoder
81 decodeObjectForKey:web::kNavigationItemStorageURLDeperecatedKey]);
82 }
83
84 if ([aDecoder
85 containsValueForKey:web::kNavigationItemStorageReferrerURLKey]) {
86 const std::string referrerString(web::nscoder_util::DecodeString(
87 aDecoder, web::kNavigationItemStorageReferrerURLKey));
88 web::ReferrerPolicy referrerPolicy =
89 static_cast<web::ReferrerPolicy>([aDecoder
90 decodeIntForKey:web::kNavigationItemStorageReferrerPolicyKey]);
91 _referrer = web::Referrer(GURL(referrerString), referrerPolicy);
92 } else {
93 // Backward compatibility.
94 NSURL* referrerURL =
95 [aDecoder decodeObjectForKey:
96 web::kNavigationItemStorageReferrerURLDeprecatedKey];
97 _referrer = web::Referrer(net::GURLWithNSURL(referrerURL),
98 web::ReferrerPolicyDefault);
99 }
100
101 if ([aDecoder
102 containsValueForKey:web::kNavigationItemStorageTimestampKey]) {
103 int64_t us =
104 [aDecoder decodeInt64ForKey:web::kNavigationItemStorageTimestampKey];
105 _timestamp = base::Time::FromInternalValue(us);
106 }
107
108 NSString* title =
109 [aDecoder decodeObjectForKey:web::kNavigationItemStorageTitleKey];
110 // Use a transition type of reload so that we don't incorrectly increase
111 // the typed count. This is what desktop chrome does.
112 _title = base::SysNSStringToUTF16(title);
113 NSDictionary* serializedDisplayState = [aDecoder
114 decodeObjectForKey:web::kNavigationItemStoragePageDisplayStateKey];
115 _displayState = web::PageDisplayState(serializedDisplayState);
116 _shouldSkipRepostFormConfirmation =
117 [aDecoder decodeBoolForKey:
118 web::kNavigationItemStorageSkipRepostFormConfirmationKey];
119 _overridingUserAgent = [aDecoder
120 decodeBoolForKey:web::kNavigationItemStorageUseDesktopUserAgentKey];
121 _POSTData =
122 [aDecoder decodeObjectForKey:web::kNavigationItemStoragePOSTDataKey];
123 _HTTPRequestHeaders = [aDecoder
124 decodeObjectForKey:web::kNavigationItemStorageHTTPRequestHeadersKey];
125 }
126 return self;
127 }
128
129 - (void)encodeWithCoder:(NSCoder*)aCoder {
130 // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only
131 // |virtualUrl_|.
132 web::nscoder_util::EncodeString(aCoder, web::kNavigationItemStorageURLKey,
133 _virtualURL.spec());
134 web::nscoder_util::EncodeString(
135 aCoder, web::kNavigationItemStorageReferrerURLKey, _referrer.url.spec());
136 [aCoder encodeInt:_referrer.policy
137 forKey:web::kNavigationItemStorageReferrerPolicyKey];
138 [aCoder encodeInt64:_timestamp.ToInternalValue()
139 forKey:web::kNavigationItemStorageTimestampKey];
140
141 [aCoder encodeObject:base::SysUTF16ToNSString(_title)
142 forKey:web::kNavigationItemStorageTitleKey];
143 [aCoder encodeObject:_displayState.GetSerialization()
144 forKey:web::kNavigationItemStoragePageDisplayStateKey];
145 [aCoder encodeBool:_shouldSkipRepostFormConfirmation
146 forKey:web::kNavigationItemStorageSkipRepostFormConfirmationKey];
147 [aCoder encodeBool:_overridingUserAgent
148 forKey:web::kNavigationItemStorageUseDesktopUserAgentKey];
149 [aCoder encodeObject:_POSTData forKey:web::kNavigationItemStoragePOSTDataKey];
150 [aCoder encodeObject:_HTTPRequestHeaders
151 forKey:web::kNavigationItemStorageHTTPRequestHeadersKey];
152 }
153
154 @end
OLDNEW
« no previous file with comments | « ios/web/public/crw_navigation_item_storage.h ('k') | ios/web/public/crw_navigation_manager_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698