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

Side by Side Diff: ios/web/navigation/crw_session_entry.mm

Issue 1132563002: CRWSessionEntry: Replaced hardcoded strings with constants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_session_entry.h" 5 #import "ios/web/navigation/crw_session_entry.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 #include "base/mac/scoped_nsobject.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "ios/web/navigation/navigation_item_impl.h" 11 #include "ios/web/navigation/navigation_item_impl.h"
12 #include "ios/web/navigation/nscoder_util.h" 12 #include "ios/web/navigation/nscoder_util.h"
13 #include "ios/web/public/navigation_item.h" 13 #include "ios/web/public/navigation_item.h"
14 #include "ios/web/public/web_state/page_scroll_state.h" 14 #include "ios/web/public/web_state/page_scroll_state.h"
15 #import "net/base/mac/url_conversions.h" 15 #import "net/base/mac/url_conversions.h"
16 16
17 namespace { 17 namespace web {
18 // Keys used to serialize web::PageScrollState properties. 18 // Keys used to serialize web::PageScrollState properties.
19 NSString* const kPageScrollStateKey = @"state";
19 NSString* const kScrollOffsetXKey = @"scrollX"; 20 NSString* const kScrollOffsetXKey = @"scrollX";
20 NSString* const kScrollOffsetYKey = @"scrollY"; 21 NSString* const kScrollOffsetYKey = @"scrollY";
21 NSString* const kMinimumZoomScaleKey = @"minZoom"; 22 NSString* const kMinimumZoomScaleKey = @"minZoom";
22 NSString* const kMaximumZoomScaleKey = @"maxZoom"; 23 NSString* const kMaximumZoomScaleKey = @"maxZoom";
23 NSString* const kZoomScaleKey = @"zoom"; 24 NSString* const kZoomScaleKey = @"zoom";
25
26 // Keys used to serialize navigation properties.
27 NSString* const kURLKey = @"virtualUrlString";
28 NSString* const kURLDeperecatedKey = @"virtualUrl";
29 NSString* const kReferrerURLKey = @"referrerUrlString";
30 NSString* const kReferrerURLDeprecatedKey = @"referrer";
31 NSString* const kReferrerPolicyKey = @"referrerPolicy";
32 NSString* const kTimestampKey = @"timestamp";
33 NSString* const kTitleKey = @"title";
34 NSString* const kPOSTDataKey = @"POSTData";
35 NSString* const kHTTPRequestHeadersKey = @"httpHeaders";
36 NSString* const kSkipResubmitConfirmationKey = @"skipResubmitDataConfirmation";
37 NSString* const kUseDesktopUserAgentKey = @"useDesktopUserAgent";
24 } 38 }
25 39
26 @interface CRWSessionEntry () { 40 @interface CRWSessionEntry () {
27 // The original URL of the page. In cases where a redirect occurred, |url_| 41 // The original URL of the page. In cases where a redirect occurred, |url_|
28 // will contain the final post-redirect URL, and |originalUrl_| will contain 42 // will contain the final post-redirect URL, and |originalUrl_| will contain
29 // the pre-redirect URL. This field is not persisted to disk. 43 // the pre-redirect URL. This field is not persisted to disk.
30 GURL _originalUrl; 44 GURL _originalUrl;
31 45
32 // The NavigationItemImpl corresponding to this CRWSessionEntry. 46 // The NavigationItemImpl corresponding to this CRWSessionEntry.
33 // TODO(stuartmorgan): Move ownership to NavigationManagerImpl. 47 // TODO(stuartmorgan): Move ownership to NavigationManagerImpl.
(...skipping 30 matching lines...) Expand all
64 78
65 - (instancetype)initWithCoder:(NSCoder*)aDecoder { 79 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
66 self = [super init]; 80 self = [super init];
67 if (self) { 81 if (self) {
68 _propertyReleaser_CRWSessionEntry.Init(self, [CRWSessionEntry class]); 82 _propertyReleaser_CRWSessionEntry.Init(self, [CRWSessionEntry class]);
69 _navigationItem.reset(new web::NavigationItemImpl()); 83 _navigationItem.reset(new web::NavigationItemImpl());
70 84
71 // Desktop chrome only persists virtualUrl_ and uses it to feed the url 85 // Desktop chrome only persists virtualUrl_ and uses it to feed the url
72 // when creating a NavigationEntry. 86 // when creating a NavigationEntry.
73 GURL url; 87 GURL url;
74 if ([aDecoder containsValueForKey:@"virtualUrlString"]) { 88 if ([aDecoder containsValueForKey:web::kURLKey]) {
75 url = GURL( 89 url = GURL(web::nscoder_util::DecodeString(aDecoder, web::kURLKey));
76 web::nscoder_util::DecodeString(aDecoder, @"virtualUrlString"));
77 } else { 90 } else {
78 // Backward compatibility. 91 // Backward compatibility.
79 url = net::GURLWithNSURL([aDecoder decodeObjectForKey:@"virtualUrl"]); 92 url = net::GURLWithNSURL(
93 [aDecoder decodeObjectForKey:web::kURLDeperecatedKey]);
80 } 94 }
81 _navigationItem->SetURL(url); 95 _navigationItem->SetURL(url);
82 self.originalUrl = url; 96 self.originalUrl = url;
83 97
84 if ([aDecoder containsValueForKey:@"referrerUrlString"]) { 98 if ([aDecoder containsValueForKey:web::kReferrerURLKey]) {
85 const std::string referrerString(web::nscoder_util::DecodeString( 99 const std::string referrerString(
86 aDecoder, @"referrerUrlString")); 100 web::nscoder_util::DecodeString(aDecoder, web::kReferrerURLKey));
87 web::ReferrerPolicy referrerPolicy = 101 web::ReferrerPolicy referrerPolicy = static_cast<web::ReferrerPolicy>(
88 static_cast<web::ReferrerPolicy>( 102 [aDecoder decodeIntForKey:web::kReferrerPolicyKey]);
89 [aDecoder decodeIntForKey:@"referrerPolicy"]);
90 _navigationItem->SetReferrer( 103 _navigationItem->SetReferrer(
91 web::Referrer(GURL(referrerString), referrerPolicy)); 104 web::Referrer(GURL(referrerString), referrerPolicy));
92 } else { 105 } else {
93 // Backward compatibility. 106 // Backward compatibility.
94 NSURL* referrer = [aDecoder decodeObjectForKey:@"referrer"]; 107 NSURL* referrer =
108 [aDecoder decodeObjectForKey:web::kReferrerURLDeprecatedKey];
95 _navigationItem->SetReferrer(web::Referrer( 109 _navigationItem->SetReferrer(web::Referrer(
96 net::GURLWithNSURL(referrer), web::ReferrerPolicyDefault)); 110 net::GURLWithNSURL(referrer), web::ReferrerPolicyDefault));
97 } 111 }
98 112
99 if ([aDecoder containsValueForKey:@"timestamp"]) { 113 if ([aDecoder containsValueForKey:web::kTimestampKey]) {
100 int64 us = [aDecoder decodeInt64ForKey:@"timestamp"]; 114 int64 us = [aDecoder decodeInt64ForKey:web::kTimestampKey];
101 _navigationItem->SetTimestamp(base::Time::FromInternalValue(us)); 115 _navigationItem->SetTimestamp(base::Time::FromInternalValue(us));
102 } 116 }
103 117
104 NSString* title = [aDecoder decodeObjectForKey:@"title"]; 118 NSString* title = [aDecoder decodeObjectForKey:web::kTitleKey];
105 // Use a transition type of reload so that we don't incorrectly increase 119 // Use a transition type of reload so that we don't incorrectly increase
106 // the typed count. This is what desktop chrome does. 120 // the typed count. This is what desktop chrome does.
107 _navigationItem->SetPageID(-1); 121 _navigationItem->SetPageID(-1);
108 _navigationItem->SetTitle(base::SysNSStringToUTF16(title)); 122 _navigationItem->SetTitle(base::SysNSStringToUTF16(title));
109 _navigationItem->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); 123 _navigationItem->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
110 _navigationItem->SetPageScrollState([[self class] 124 _navigationItem->SetPageScrollState([[self class]
111 scrollStateFromDictionary:[aDecoder decodeObjectForKey:@"state"]]); 125 scrollStateFromDictionary:
126 [aDecoder decodeObjectForKey:web::kPageScrollStateKey]]);
112 _navigationItem->SetShouldSkipResubmitDataConfirmation( 127 _navigationItem->SetShouldSkipResubmitDataConfirmation(
113 [aDecoder decodeBoolForKey:@"skipResubmitDataConfirmation"]); 128 [aDecoder decodeBoolForKey:web::kSkipResubmitConfirmationKey]);
114 _navigationItem->SetIsOverridingUserAgent( 129 _navigationItem->SetIsOverridingUserAgent(
115 [aDecoder decodeBoolForKey:@"useDesktopUserAgent"]); 130 [aDecoder decodeBoolForKey:web::kUseDesktopUserAgentKey]);
116 _navigationItem->SetPostData([aDecoder decodeObjectForKey:@"POSTData"]); 131 _navigationItem->SetPostData(
132 [aDecoder decodeObjectForKey:web::kPOSTDataKey]);
117 _navigationItem->AddHttpRequestHeaders( 133 _navigationItem->AddHttpRequestHeaders(
118 [aDecoder decodeObjectForKey:@"httpHeaders"]); 134 [aDecoder decodeObjectForKey:web::kHTTPRequestHeadersKey]);
119 } 135 }
120 return self; 136 return self;
121 } 137 }
122 138
123 - (void)encodeWithCoder:(NSCoder*)aCoder { 139 - (void)encodeWithCoder:(NSCoder*)aCoder {
124 // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only 140 // Desktop Chrome doesn't persist |url_| or |originalUrl_|, only
125 // |virtualUrl_|. 141 // |virtualUrl_|.
126 web::nscoder_util::EncodeString(aCoder, @"virtualUrlString", 142 web::nscoder_util::EncodeString(aCoder, web::kURLKey,
127 _navigationItem->GetVirtualURL().spec()); 143 _navigationItem->GetVirtualURL().spec());
128 web::nscoder_util::EncodeString(aCoder, @"referrerUrlString", 144 web::nscoder_util::EncodeString(aCoder, web::kReferrerURLKey,
129 _navigationItem->GetReferrer().url.spec()); 145 _navigationItem->GetReferrer().url.spec());
130 [aCoder encodeInt:_navigationItem->GetReferrer().policy 146 [aCoder encodeInt:_navigationItem->GetReferrer().policy
131 forKey:@"referrerPolicy"]; 147 forKey:web::kReferrerPolicyKey];
132 [aCoder encodeInt64:_navigationItem->GetTimestamp().ToInternalValue() 148 [aCoder encodeInt64:_navigationItem->GetTimestamp().ToInternalValue()
133 forKey:@"timestamp"]; 149 forKey:web::kTimestampKey];
134 150
135 [aCoder encodeObject:base::SysUTF16ToNSString(_navigationItem->GetTitle()) 151 [aCoder encodeObject:base::SysUTF16ToNSString(_navigationItem->GetTitle())
136 forKey:@"title"]; 152 forKey:web::kTitleKey];
137 [aCoder encodeObject:[[self class] dictionaryFromScrollState: 153 [aCoder encodeObject:[[self class] dictionaryFromScrollState:
138 _navigationItem->GetPageScrollState()] 154 _navigationItem->GetPageScrollState()]
139 forKey:@"state"]; 155 forKey:web::kPageScrollStateKey];
140 [aCoder encodeBool:_navigationItem->ShouldSkipResubmitDataConfirmation() 156 [aCoder encodeBool:_navigationItem->ShouldSkipResubmitDataConfirmation()
141 forKey:@"skipResubmitDataConfirmation"]; 157 forKey:web::kSkipResubmitConfirmationKey];
142 [aCoder encodeBool:_navigationItem->IsOverridingUserAgent() 158 [aCoder encodeBool:_navigationItem->IsOverridingUserAgent()
143 forKey:@"useDesktopUserAgent"]; 159 forKey:web::kUseDesktopUserAgentKey];
144 [aCoder encodeObject:_navigationItem->GetPostData() forKey:@"POSTData"]; 160 [aCoder encodeObject:_navigationItem->GetPostData() forKey:web::kPOSTDataKey];
145 [aCoder encodeObject:_navigationItem->GetHttpRequestHeaders() 161 [aCoder encodeObject:_navigationItem->GetHttpRequestHeaders()
146 forKey:@"httpHeaders"]; 162 forKey:web::kHTTPRequestHeadersKey];
147 } 163 }
148 164
149 // TODO(ios): Shall we overwrite EqualTo:? 165 // TODO(ios): Shall we overwrite EqualTo:?
150 166
151 - (instancetype)copyWithZone:(NSZone*)zone { 167 - (instancetype)copyWithZone:(NSZone*)zone {
152 CRWSessionEntry* copy = [[[self class] alloc] init]; 168 CRWSessionEntry* copy = [[[self class] alloc] init];
153 copy->_propertyReleaser_CRWSessionEntry.Init(copy, [CRWSessionEntry class]); 169 copy->_propertyReleaser_CRWSessionEntry.Init(copy, [CRWSessionEntry class]);
154 copy->_navigationItem.reset( 170 copy->_navigationItem.reset(
155 new web::NavigationItemImpl(*_navigationItem.get())); 171 new web::NavigationItemImpl(*_navigationItem.get()));
156 copy->_originalUrl = _originalUrl; 172 copy->_originalUrl = _originalUrl;
(...skipping 20 matching lines...) Expand all
177 193
178 - (web::NavigationItemImpl*)navigationItemImpl { 194 - (web::NavigationItemImpl*)navigationItemImpl {
179 return _navigationItem.get(); 195 return _navigationItem.get();
180 } 196 }
181 197
182 #pragma mark - Serialization helpers 198 #pragma mark - Serialization helpers
183 199
184 + (web::PageScrollState)scrollStateFromDictionary:(NSDictionary*)dictionary { 200 + (web::PageScrollState)scrollStateFromDictionary:(NSDictionary*)dictionary {
185 web::PageScrollState scrollState; 201 web::PageScrollState scrollState;
186 NSNumber* serializedValue = nil; 202 NSNumber* serializedValue = nil;
187 if ((serializedValue = dictionary[kScrollOffsetXKey])) 203 if ((serializedValue = dictionary[web::kScrollOffsetXKey]))
188 scrollState.set_scroll_offset_x([serializedValue doubleValue]); 204 scrollState.set_scroll_offset_x([serializedValue doubleValue]);
189 if ((serializedValue = dictionary[kScrollOffsetYKey])) 205 if ((serializedValue = dictionary[web::kScrollOffsetYKey]))
190 scrollState.set_scroll_offset_y([serializedValue doubleValue]); 206 scrollState.set_scroll_offset_y([serializedValue doubleValue]);
191 if ((serializedValue = dictionary[kMinimumZoomScaleKey])) 207 if ((serializedValue = dictionary[web::kMinimumZoomScaleKey]))
192 scrollState.set_minimum_zoom_scale([serializedValue doubleValue]); 208 scrollState.set_minimum_zoom_scale([serializedValue doubleValue]);
193 if ((serializedValue = dictionary[kMaximumZoomScaleKey])) 209 if ((serializedValue = dictionary[web::kMaximumZoomScaleKey]))
194 scrollState.set_maximum_zoom_scale([serializedValue doubleValue]); 210 scrollState.set_maximum_zoom_scale([serializedValue doubleValue]);
195 if ((serializedValue = dictionary[kZoomScaleKey])) 211 if ((serializedValue = dictionary[web::kZoomScaleKey]))
196 scrollState.set_zoom_scale([serializedValue doubleValue]); 212 scrollState.set_zoom_scale([serializedValue doubleValue]);
197 return scrollState; 213 return scrollState;
198 } 214 }
199 215
200 + (NSDictionary*)dictionaryFromScrollState: 216 + (NSDictionary*)dictionaryFromScrollState:
201 (const web::PageScrollState&)scrollState { 217 (const web::PageScrollState&)scrollState {
202 return @{ 218 return @{
203 kScrollOffsetXKey : @(scrollState.scroll_offset_x()), 219 web::kScrollOffsetXKey : @(scrollState.scroll_offset_x()),
204 kScrollOffsetYKey : @(scrollState.scroll_offset_y()), 220 web::kScrollOffsetYKey : @(scrollState.scroll_offset_y()),
205 kMinimumZoomScaleKey : @(scrollState.minimum_zoom_scale()), 221 web::kMinimumZoomScaleKey : @(scrollState.minimum_zoom_scale()),
206 kMaximumZoomScaleKey : @(scrollState.maximum_zoom_scale()), 222 web::kMaximumZoomScaleKey : @(scrollState.maximum_zoom_scale()),
207 kZoomScaleKey : @(scrollState.zoom_scale()) 223 web::kZoomScaleKey : @(scrollState.zoom_scale()),
208 }; 224 };
209 } 225 }
210 226
211 + (NSString*)scrollStateDescription:(const web::PageScrollState&)scrollState { 227 + (NSString*)scrollStateDescription:(const web::PageScrollState&)scrollState {
212 NSString* const kPageScrollStateDescriptionFormat = 228 NSString* const kPageScrollStateDescriptionFormat =
213 @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), " 229 @"{ scrollOffset:(%0.2f, %0.2f), zoomScaleRange:(%0.2f, %0.2f), "
214 @"zoomScale:%0.2f }"; 230 @"zoomScale:%0.2f }";
215 return [NSString stringWithFormat:kPageScrollStateDescriptionFormat, 231 return [NSString stringWithFormat:kPageScrollStateDescriptionFormat,
216 scrollState.scroll_offset_x(), 232 scrollState.scroll_offset_x(),
217 scrollState.scroll_offset_y(), 233 scrollState.scroll_offset_y(),
218 scrollState.minimum_zoom_scale(), 234 scrollState.minimum_zoom_scale(),
219 scrollState.maximum_zoom_scale(), 235 scrollState.maximum_zoom_scale(),
220 scrollState.zoom_scale()]; 236 scrollState.zoom_scale()];
221 } 237 }
222 238
223 @end 239 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698