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

Side by Side Diff: components/sessions/serialized_navigation_entry.cc

Issue 14985014: Introduce content::PageState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comments to the top of page_state.h Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "components/sessions/serialized_navigation_entry.h" 5 #include "components/sessions/serialized_navigation_entry.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "content/public/browser/favicon_status.h" 9 #include "content/public/browser/favicon_status.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "sync/protocol/session_specifics.pb.h" 12 #include "sync/protocol/session_specifics.pb.h"
13 #include "sync/util/time.h" 13 #include "sync/util/time.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h " 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h "
15 #include "webkit/glue/glue_serialize.h"
16 15
17 using content::NavigationEntry; 16 using content::NavigationEntry;
18 17
19 namespace sessions { 18 namespace sessions {
20 19
21 const char kSearchTermsKey[] = "search_terms"; 20 const char kSearchTermsKey[] = "search_terms";
22 21
23 SerializedNavigationEntry::SerializedNavigationEntry() 22 SerializedNavigationEntry::SerializedNavigationEntry()
24 : index_(-1), 23 : index_(-1),
25 unique_id_(0), 24 unique_id_(0),
26 transition_type_(content::PAGE_TRANSITION_TYPED), 25 transition_type_(content::PAGE_TRANSITION_TYPED),
27 has_post_data_(false), 26 has_post_data_(false),
28 post_id_(-1), 27 post_id_(-1),
29 is_overriding_user_agent_(false) {} 28 is_overriding_user_agent_(false) {}
30 29
31 SerializedNavigationEntry::~SerializedNavigationEntry() {} 30 SerializedNavigationEntry::~SerializedNavigationEntry() {}
32 31
33 // static 32 // static
34 SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry( 33 SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry(
35 int index, 34 int index,
36 const NavigationEntry& entry) { 35 const NavigationEntry& entry) {
37 SerializedNavigationEntry navigation; 36 SerializedNavigationEntry navigation;
38 navigation.index_ = index; 37 navigation.index_ = index;
39 navigation.unique_id_ = entry.GetUniqueID(); 38 navigation.unique_id_ = entry.GetUniqueID();
40 navigation.referrer_ = entry.GetReferrer(); 39 navigation.referrer_ = entry.GetReferrer();
41 navigation.virtual_url_ = entry.GetVirtualURL(); 40 navigation.virtual_url_ = entry.GetVirtualURL();
42 navigation.title_ = entry.GetTitle(); 41 navigation.title_ = entry.GetTitle();
43 navigation.content_state_ = entry.GetContentState(); 42 navigation.page_state_ = entry.GetPageState();
44 navigation.transition_type_ = entry.GetTransitionType(); 43 navigation.transition_type_ = entry.GetTransitionType();
45 navigation.has_post_data_ = entry.GetHasPostData(); 44 navigation.has_post_data_ = entry.GetHasPostData();
46 navigation.post_id_ = entry.GetPostID(); 45 navigation.post_id_ = entry.GetPostID();
47 navigation.original_request_url_ = entry.GetOriginalRequestURL(); 46 navigation.original_request_url_ = entry.GetOriginalRequestURL();
48 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); 47 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent();
49 navigation.timestamp_ = entry.GetTimestamp(); 48 navigation.timestamp_ = entry.GetTimestamp();
50 // If you want to navigate a named frame in Chrome, you will first need to 49 // If you want to navigate a named frame in Chrome, you will first need to
51 // add support for persisting it. It is currently only used for layout tests. 50 // add support for persisting it. It is currently only used for layout tests.
52 CHECK(entry.GetFrameToNavigate().empty()); 51 CHECK(entry.GetFrameToNavigate().empty());
53 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); 52 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
54 if (entry.GetFavicon().valid) 53 if (entry.GetFavicon().valid)
55 navigation.favicon_url_ = entry.GetFavicon().url; 54 navigation.favicon_url_ = entry.GetFavicon().url;
56 55
57 return navigation; 56 return navigation;
58 } 57 }
59 58
60 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( 59 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData(
61 int index, 60 int index,
62 const sync_pb::TabNavigation& sync_data) { 61 const sync_pb::TabNavigation& sync_data) {
63 SerializedNavigationEntry navigation; 62 SerializedNavigationEntry navigation;
64 navigation.index_ = index; 63 navigation.index_ = index;
65 navigation.unique_id_ = sync_data.unique_id(); 64 navigation.unique_id_ = sync_data.unique_id();
66 navigation.referrer_ = 65 navigation.referrer_ =
67 content::Referrer(GURL(sync_data.referrer()), 66 content::Referrer(GURL(sync_data.referrer()),
68 WebKit::WebReferrerPolicyDefault); 67 WebKit::WebReferrerPolicyDefault);
69 navigation.virtual_url_ = GURL(sync_data.virtual_url()); 68 navigation.virtual_url_ = GURL(sync_data.virtual_url());
70 navigation.title_ = UTF8ToUTF16(sync_data.title()); 69 navigation.title_ = UTF8ToUTF16(sync_data.title());
71 navigation.content_state_ = sync_data.state(); 70 navigation.page_state_ =
71 content::PageState::CreateFromEncodedData(sync_data.state());
72 72
73 uint32 transition = 0; 73 uint32 transition = 0;
74 if (sync_data.has_page_transition()) { 74 if (sync_data.has_page_transition()) {
75 switch (sync_data.page_transition()) { 75 switch (sync_data.page_transition()) {
76 case sync_pb::SyncEnums_PageTransition_LINK: 76 case sync_pb::SyncEnums_PageTransition_LINK:
77 transition = content::PAGE_TRANSITION_LINK; 77 transition = content::PAGE_TRANSITION_LINK;
78 break; 78 break;
79 case sync_pb::SyncEnums_PageTransition_TYPED: 79 case sync_pb::SyncEnums_PageTransition_TYPED:
80 transition = content::PAGE_TRANSITION_TYPED; 80 transition = content::PAGE_TRANSITION_TYPED;
81 break; 81 break;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 HAS_POST_DATA = 1 193 HAS_POST_DATA = 1
194 }; 194 };
195 195
196 } // namespace 196 } // namespace
197 197
198 // Pickle order: 198 // Pickle order:
199 // 199 //
200 // index_ 200 // index_
201 // virtual_url_ 201 // virtual_url_
202 // title_ 202 // title_
203 // content_state_ 203 // page_state_
204 // transition_type_ 204 // transition_type_
205 // 205 //
206 // Added on later: 206 // Added on later:
207 // 207 //
208 // type_mask (has_post_data_) 208 // type_mask (has_post_data_)
209 // referrer_ 209 // referrer_
210 // original_request_url_ 210 // original_request_url_
211 // is_overriding_user_agent_ 211 // is_overriding_user_agent_
212 // timestamp_ 212 // timestamp_
213 // search_terms_ 213 // search_terms_
214 214
215 void SerializedNavigationEntry::WriteToPickle(int max_size, 215 void SerializedNavigationEntry::WriteToPickle(int max_size,
216 Pickle* pickle) const { 216 Pickle* pickle) const {
217 pickle->WriteInt(index_); 217 pickle->WriteInt(index_);
218 218
219 int bytes_written = 0; 219 int bytes_written = 0;
220 220
221 WriteStringToPickle(pickle, &bytes_written, max_size, 221 WriteStringToPickle(pickle, &bytes_written, max_size,
222 virtual_url_.spec()); 222 virtual_url_.spec());
223 223
224 WriteString16ToPickle(pickle, &bytes_written, max_size, title_); 224 WriteString16ToPickle(pickle, &bytes_written, max_size, title_);
225 225
226 std::string content_state = content_state_; 226 content::PageState page_state = page_state_;
227 if (has_post_data_) { 227 if (has_post_data_)
228 content_state = 228 page_state = page_state.RemovePasswordData();
229 webkit_glue::RemovePasswordDataFromHistoryState(content_state); 229
230 } 230 WriteStringToPickle(pickle, &bytes_written, max_size,
231 WriteStringToPickle(pickle, &bytes_written, max_size, content_state); 231 page_state.ToEncodedData());
232 232
233 pickle->WriteInt(transition_type_); 233 pickle->WriteInt(transition_type_);
234 234
235 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0; 235 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0;
236 pickle->WriteInt(type_mask); 236 pickle->WriteInt(type_mask);
237 237
238 WriteStringToPickle( 238 WriteStringToPickle(
239 pickle, &bytes_written, max_size, 239 pickle, &bytes_written, max_size,
240 referrer_.url.is_valid() ? referrer_.url.spec() : std::string()); 240 referrer_.url.is_valid() ? referrer_.url.spec() : std::string());
241 241
242 pickle->WriteInt(referrer_.policy); 242 pickle->WriteInt(referrer_.policy);
243 243
244 // Save info required to override the user agent. 244 // Save info required to override the user agent.
245 WriteStringToPickle( 245 WriteStringToPickle(
246 pickle, &bytes_written, max_size, 246 pickle, &bytes_written, max_size,
247 original_request_url_.is_valid() ? 247 original_request_url_.is_valid() ?
248 original_request_url_.spec() : std::string()); 248 original_request_url_.spec() : std::string());
249 pickle->WriteBool(is_overriding_user_agent_); 249 pickle->WriteBool(is_overriding_user_agent_);
250 pickle->WriteInt64(timestamp_.ToInternalValue()); 250 pickle->WriteInt64(timestamp_.ToInternalValue());
251 251
252 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); 252 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_);
253 } 253 }
254 254
255 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { 255 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) {
256 *this = SerializedNavigationEntry(); 256 *this = SerializedNavigationEntry();
257 std::string virtual_url_spec; 257 std::string virtual_url_spec, page_state_data;
258 int transition_type_int = 0; 258 int transition_type_int = 0;
259 if (!iterator->ReadInt(&index_) || 259 if (!iterator->ReadInt(&index_) ||
260 !iterator->ReadString(&virtual_url_spec) || 260 !iterator->ReadString(&virtual_url_spec) ||
261 !iterator->ReadString16(&title_) || 261 !iterator->ReadString16(&title_) ||
262 !iterator->ReadString(&content_state_) || 262 !iterator->ReadString(&page_state_data) ||
263 !iterator->ReadInt(&transition_type_int)) 263 !iterator->ReadInt(&transition_type_int))
264 return false; 264 return false;
265 virtual_url_ = GURL(virtual_url_spec); 265 virtual_url_ = GURL(virtual_url_spec);
266 page_state_ = content::PageState::CreateFromEncodedData(page_state_data);
266 transition_type_ = static_cast<content::PageTransition>(transition_type_int); 267 transition_type_ = static_cast<content::PageTransition>(transition_type_int);
267 268
268 // type_mask did not always exist in the written stream. As such, we 269 // type_mask did not always exist in the written stream. As such, we
269 // don't fail if it can't be read. 270 // don't fail if it can't be read.
270 int type_mask = 0; 271 int type_mask = 0;
271 bool has_type_mask = iterator->ReadInt(&type_mask); 272 bool has_type_mask = iterator->ReadInt(&type_mask);
272 273
273 if (has_type_mask) { 274 if (has_type_mask) {
274 has_post_data_ = type_mask & HAS_POST_DATA; 275 has_post_data_ = type_mask & HAS_POST_DATA;
275 // the "referrer" property was added after type_mask to the written 276 // the "referrer" property was added after type_mask to the written
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 referrer_, 322 referrer_,
322 // Use a transition type of reload so that we don't incorrectly 323 // Use a transition type of reload so that we don't incorrectly
323 // increase the typed count. 324 // increase the typed count.
324 content::PAGE_TRANSITION_RELOAD, 325 content::PAGE_TRANSITION_RELOAD,
325 false, 326 false,
326 // The extra headers are not sync'ed across sessions. 327 // The extra headers are not sync'ed across sessions.
327 std::string(), 328 std::string(),
328 browser_context)); 329 browser_context));
329 330
330 entry->SetTitle(title_); 331 entry->SetTitle(title_);
331 entry->SetContentState(content_state_); 332 entry->SetPageState(page_state_);
332 entry->SetPageID(page_id); 333 entry->SetPageID(page_id);
333 entry->SetHasPostData(has_post_data_); 334 entry->SetHasPostData(has_post_data_);
334 entry->SetPostID(post_id_); 335 entry->SetPostID(post_id_);
335 entry->SetOriginalRequestURL(original_request_url_); 336 entry->SetOriginalRequestURL(original_request_url_);
336 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); 337 entry->SetIsOverridingUserAgent(is_overriding_user_agent_);
337 entry->SetTimestamp(timestamp_); 338 entry->SetTimestamp(timestamp_);
338 entry->SetExtraData(kSearchTermsKey, search_terms_); 339 entry->SetExtraData(kSearchTermsKey, search_terms_);
339 340
340 return entry.Pass(); 341 return entry.Pass();
341 } 342 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 for (std::vector<SerializedNavigationEntry>::const_iterator 446 for (std::vector<SerializedNavigationEntry>::const_iterator
446 it = navigations.begin(); it != navigations.end(); ++it) { 447 it = navigations.begin(); it != navigations.end(); ++it) {
447 entries.push_back( 448 entries.push_back(
448 it->ToNavigationEntry(page_id, browser_context).release()); 449 it->ToNavigationEntry(page_id, browser_context).release());
449 ++page_id; 450 ++page_id;
450 } 451 }
451 return entries; 452 return entries;
452 } 453 }
453 454
454 } // namespace sessions 455 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698