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

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

Issue 16162003: Introduce content::PageState (again). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 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 blocked_state_(STATE_INVALID) {} 29 blocked_state_(STATE_INVALID) {}
31 30
32 SerializedNavigationEntry::~SerializedNavigationEntry() {} 31 SerializedNavigationEntry::~SerializedNavigationEntry() {}
33 32
34 // static 33 // static
35 SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry( 34 SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry(
36 int index, 35 int index,
37 const NavigationEntry& entry) { 36 const NavigationEntry& entry) {
38 SerializedNavigationEntry navigation; 37 SerializedNavigationEntry navigation;
39 navigation.index_ = index; 38 navigation.index_ = index;
40 navigation.unique_id_ = entry.GetUniqueID(); 39 navigation.unique_id_ = entry.GetUniqueID();
41 navigation.referrer_ = entry.GetReferrer(); 40 navigation.referrer_ = entry.GetReferrer();
42 navigation.virtual_url_ = entry.GetVirtualURL(); 41 navigation.virtual_url_ = entry.GetVirtualURL();
43 navigation.title_ = entry.GetTitle(); 42 navigation.title_ = entry.GetTitle();
44 navigation.content_state_ = entry.GetContentState(); 43 navigation.page_state_ = entry.GetPageState();
45 navigation.transition_type_ = entry.GetTransitionType(); 44 navigation.transition_type_ = entry.GetTransitionType();
46 navigation.has_post_data_ = entry.GetHasPostData(); 45 navigation.has_post_data_ = entry.GetHasPostData();
47 navigation.post_id_ = entry.GetPostID(); 46 navigation.post_id_ = entry.GetPostID();
48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); 47 navigation.original_request_url_ = entry.GetOriginalRequestURL();
49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); 48 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent();
50 navigation.timestamp_ = entry.GetTimestamp(); 49 navigation.timestamp_ = entry.GetTimestamp();
51 // If you want to navigate a named frame in Chrome, you will first need to 50 // If you want to navigate a named frame in Chrome, you will first need to
52 // add support for persisting it. It is currently only used for layout tests. 51 // add support for persisting it. It is currently only used for layout tests.
53 CHECK(entry.GetFrameToNavigate().empty()); 52 CHECK(entry.GetFrameToNavigate().empty());
54 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); 53 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
55 if (entry.GetFavicon().valid) 54 if (entry.GetFavicon().valid)
56 navigation.favicon_url_ = entry.GetFavicon().url; 55 navigation.favicon_url_ = entry.GetFavicon().url;
57 56
58 return navigation; 57 return navigation;
59 } 58 }
60 59
61 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( 60 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData(
62 int index, 61 int index,
63 const sync_pb::TabNavigation& sync_data) { 62 const sync_pb::TabNavigation& sync_data) {
64 SerializedNavigationEntry navigation; 63 SerializedNavigationEntry navigation;
65 navigation.index_ = index; 64 navigation.index_ = index;
66 navigation.unique_id_ = sync_data.unique_id(); 65 navigation.unique_id_ = sync_data.unique_id();
67 navigation.referrer_ = 66 navigation.referrer_ =
68 content::Referrer(GURL(sync_data.referrer()), 67 content::Referrer(GURL(sync_data.referrer()),
69 WebKit::WebReferrerPolicyDefault); 68 WebKit::WebReferrerPolicyDefault);
70 navigation.virtual_url_ = GURL(sync_data.virtual_url()); 69 navigation.virtual_url_ = GURL(sync_data.virtual_url());
71 navigation.title_ = UTF8ToUTF16(sync_data.title()); 70 navigation.title_ = UTF8ToUTF16(sync_data.title());
72 navigation.content_state_ = sync_data.state(); 71 navigation.page_state_ =
72 content::PageState::CreateFromEncodedData(sync_data.state());
73 73
74 uint32 transition = 0; 74 uint32 transition = 0;
75 if (sync_data.has_page_transition()) { 75 if (sync_data.has_page_transition()) {
76 switch (sync_data.page_transition()) { 76 switch (sync_data.page_transition()) {
77 case sync_pb::SyncEnums_PageTransition_LINK: 77 case sync_pb::SyncEnums_PageTransition_LINK:
78 transition = content::PAGE_TRANSITION_LINK; 78 transition = content::PAGE_TRANSITION_LINK;
79 break; 79 break;
80 case sync_pb::SyncEnums_PageTransition_TYPED: 80 case sync_pb::SyncEnums_PageTransition_TYPED:
81 transition = content::PAGE_TRANSITION_TYPED; 81 transition = content::PAGE_TRANSITION_TYPED;
82 break; 82 break;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 HAS_POST_DATA = 1 198 HAS_POST_DATA = 1
199 }; 199 };
200 200
201 } // namespace 201 } // namespace
202 202
203 // Pickle order: 203 // Pickle order:
204 // 204 //
205 // index_ 205 // index_
206 // virtual_url_ 206 // virtual_url_
207 // title_ 207 // title_
208 // content_state_ 208 // page_state_
209 // transition_type_ 209 // transition_type_
210 // 210 //
211 // Added on later: 211 // Added on later:
212 // 212 //
213 // type_mask (has_post_data_) 213 // type_mask (has_post_data_)
214 // referrer_ 214 // referrer_
215 // original_request_url_ 215 // original_request_url_
216 // is_overriding_user_agent_ 216 // is_overriding_user_agent_
217 // timestamp_ 217 // timestamp_
218 // search_terms_ 218 // search_terms_
219 219
220 void SerializedNavigationEntry::WriteToPickle(int max_size, 220 void SerializedNavigationEntry::WriteToPickle(int max_size,
221 Pickle* pickle) const { 221 Pickle* pickle) const {
222 pickle->WriteInt(index_); 222 pickle->WriteInt(index_);
223 223
224 int bytes_written = 0; 224 int bytes_written = 0;
225 225
226 WriteStringToPickle(pickle, &bytes_written, max_size, 226 WriteStringToPickle(pickle, &bytes_written, max_size,
227 virtual_url_.spec()); 227 virtual_url_.spec());
228 228
229 WriteString16ToPickle(pickle, &bytes_written, max_size, title_); 229 WriteString16ToPickle(pickle, &bytes_written, max_size, title_);
230 230
231 std::string content_state = content_state_; 231 content::PageState page_state = page_state_;
232 if (has_post_data_) { 232 if (has_post_data_)
233 content_state = 233 page_state = page_state.RemovePasswordData();
234 webkit_glue::RemovePasswordDataFromHistoryState(content_state); 234
235 } 235 WriteStringToPickle(pickle, &bytes_written, max_size,
236 WriteStringToPickle(pickle, &bytes_written, max_size, content_state); 236 page_state.ToEncodedData());
237 237
238 pickle->WriteInt(transition_type_); 238 pickle->WriteInt(transition_type_);
239 239
240 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0; 240 const int type_mask = has_post_data_ ? HAS_POST_DATA : 0;
241 pickle->WriteInt(type_mask); 241 pickle->WriteInt(type_mask);
242 242
243 WriteStringToPickle( 243 WriteStringToPickle(
244 pickle, &bytes_written, max_size, 244 pickle, &bytes_written, max_size,
245 referrer_.url.is_valid() ? referrer_.url.spec() : std::string()); 245 referrer_.url.is_valid() ? referrer_.url.spec() : std::string());
246 246
247 pickle->WriteInt(referrer_.policy); 247 pickle->WriteInt(referrer_.policy);
248 248
249 // Save info required to override the user agent. 249 // Save info required to override the user agent.
250 WriteStringToPickle( 250 WriteStringToPickle(
251 pickle, &bytes_written, max_size, 251 pickle, &bytes_written, max_size,
252 original_request_url_.is_valid() ? 252 original_request_url_.is_valid() ?
253 original_request_url_.spec() : std::string()); 253 original_request_url_.spec() : std::string());
254 pickle->WriteBool(is_overriding_user_agent_); 254 pickle->WriteBool(is_overriding_user_agent_);
255 pickle->WriteInt64(timestamp_.ToInternalValue()); 255 pickle->WriteInt64(timestamp_.ToInternalValue());
256 256
257 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); 257 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_);
258 } 258 }
259 259
260 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { 260 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) {
261 *this = SerializedNavigationEntry(); 261 *this = SerializedNavigationEntry();
262 std::string virtual_url_spec; 262 std::string virtual_url_spec, page_state_data;
263 int transition_type_int = 0; 263 int transition_type_int = 0;
264 if (!iterator->ReadInt(&index_) || 264 if (!iterator->ReadInt(&index_) ||
265 !iterator->ReadString(&virtual_url_spec) || 265 !iterator->ReadString(&virtual_url_spec) ||
266 !iterator->ReadString16(&title_) || 266 !iterator->ReadString16(&title_) ||
267 !iterator->ReadString(&content_state_) || 267 !iterator->ReadString(&page_state_data) ||
268 !iterator->ReadInt(&transition_type_int)) 268 !iterator->ReadInt(&transition_type_int))
269 return false; 269 return false;
270 virtual_url_ = GURL(virtual_url_spec); 270 virtual_url_ = GURL(virtual_url_spec);
271 page_state_ = content::PageState::CreateFromEncodedData(page_state_data);
271 transition_type_ = static_cast<content::PageTransition>(transition_type_int); 272 transition_type_ = static_cast<content::PageTransition>(transition_type_int);
272 273
273 // type_mask did not always exist in the written stream. As such, we 274 // type_mask did not always exist in the written stream. As such, we
274 // don't fail if it can't be read. 275 // don't fail if it can't be read.
275 int type_mask = 0; 276 int type_mask = 0;
276 bool has_type_mask = iterator->ReadInt(&type_mask); 277 bool has_type_mask = iterator->ReadInt(&type_mask);
277 278
278 if (has_type_mask) { 279 if (has_type_mask) {
279 has_post_data_ = type_mask & HAS_POST_DATA; 280 has_post_data_ = type_mask & HAS_POST_DATA;
280 // the "referrer" property was added after type_mask to the written 281 // the "referrer" property was added after type_mask to the written
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 referrer_, 327 referrer_,
327 // Use a transition type of reload so that we don't incorrectly 328 // Use a transition type of reload so that we don't incorrectly
328 // increase the typed count. 329 // increase the typed count.
329 content::PAGE_TRANSITION_RELOAD, 330 content::PAGE_TRANSITION_RELOAD,
330 false, 331 false,
331 // The extra headers are not sync'ed across sessions. 332 // The extra headers are not sync'ed across sessions.
332 std::string(), 333 std::string(),
333 browser_context)); 334 browser_context));
334 335
335 entry->SetTitle(title_); 336 entry->SetTitle(title_);
336 entry->SetContentState(content_state_); 337 entry->SetPageState(page_state_);
337 entry->SetPageID(page_id); 338 entry->SetPageID(page_id);
338 entry->SetHasPostData(has_post_data_); 339 entry->SetHasPostData(has_post_data_);
339 entry->SetPostID(post_id_); 340 entry->SetPostID(post_id_);
340 entry->SetOriginalRequestURL(original_request_url_); 341 entry->SetOriginalRequestURL(original_request_url_);
341 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); 342 entry->SetIsOverridingUserAgent(is_overriding_user_agent_);
342 entry->SetTimestamp(timestamp_); 343 entry->SetTimestamp(timestamp_);
343 entry->SetExtraData(kSearchTermsKey, search_terms_); 344 entry->SetExtraData(kSearchTermsKey, search_terms_);
344 345
345 // These fields should have default values. 346 // These fields should have default values.
346 DCHECK_EQ(STATE_INVALID, blocked_state_); 347 DCHECK_EQ(STATE_INVALID, blocked_state_);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 for (std::vector<SerializedNavigationEntry>::const_iterator 466 for (std::vector<SerializedNavigationEntry>::const_iterator
466 it = navigations.begin(); it != navigations.end(); ++it) { 467 it = navigations.begin(); it != navigations.end(); ++it) {
467 entries.push_back( 468 entries.push_back(
468 it->ToNavigationEntry(page_id, browser_context).release()); 469 it->ToNavigationEntry(page_id, browser_context).release());
469 ++page_id; 470 ++page_id;
470 } 471 }
471 return entries; 472 return entries;
472 } 473 }
473 474
474 } // namespace sessions 475 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698