Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); | 48 navigation.original_request_url_ = entry.GetOriginalRequestURL(); |
| 49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 49 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); |
| 50 navigation.timestamp_ = entry.GetTimestamp(); | 50 navigation.timestamp_ = entry.GetTimestamp(); |
| 51 // If you want to navigate a named frame in Chrome, you will first need to | 51 // 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. | 52 // add support for persisting it. It is currently only used for layout tests. |
| 53 CHECK(entry.GetFrameToNavigate().empty()); | 53 CHECK(entry.GetFrameToNavigate().empty()); |
| 54 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); | 54 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); |
| 55 if (entry.GetFavicon().valid) | 55 if (entry.GetFavicon().valid) |
| 56 navigation.favicon_url_ = entry.GetFavicon().url; | 56 navigation.favicon_url_ = entry.GetFavicon().url; |
| 57 navigation.http_status_code_ = entry.GetHttpStatusCode(); | 57 navigation.http_status_code_ = entry.GetHttpStatusCode(); |
| 58 navigation.redirect_chain_ = entry.GetRedirectChain(); | |
| 58 | 59 |
| 59 return navigation; | 60 return navigation; |
| 60 } | 61 } |
| 61 | 62 |
| 62 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( | 63 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( |
| 63 int index, | 64 int index, |
| 64 const sync_pb::TabNavigation& sync_data) { | 65 const sync_pb::TabNavigation& sync_data) { |
| 65 SerializedNavigationEntry navigation; | 66 SerializedNavigationEntry navigation; |
| 66 navigation.index_ = index; | 67 navigation.index_ = index; |
| 67 navigation.unique_id_ = sync_data.unique_id(); | 68 navigation.unique_id_ = sync_data.unique_id(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 navigation.transition_type_ = | 141 navigation.transition_type_ = |
| 141 static_cast<content::PageTransition>(transition); | 142 static_cast<content::PageTransition>(transition); |
| 142 | 143 |
| 143 navigation.timestamp_ = base::Time(); | 144 navigation.timestamp_ = base::Time(); |
| 144 navigation.search_terms_ = base::UTF8ToUTF16(sync_data.search_terms()); | 145 navigation.search_terms_ = base::UTF8ToUTF16(sync_data.search_terms()); |
| 145 if (sync_data.has_favicon_url()) | 146 if (sync_data.has_favicon_url()) |
| 146 navigation.favicon_url_ = GURL(sync_data.favicon_url()); | 147 navigation.favicon_url_ = GURL(sync_data.favicon_url()); |
| 147 | 148 |
| 148 navigation.http_status_code_ = sync_data.http_status_code(); | 149 navigation.http_status_code_ = sync_data.http_status_code(); |
| 149 | 150 |
| 151 // The redirect chain does not need to be synced down. | |
|
haitaol1
2014/01/17 23:52:23
I think the comment should be on redirect_chain_ s
Donn Denman
2014/01/18 01:30:19
Done.
| |
| 152 | |
| 150 // We shouldn't sync session data for managed users down at the moment. | 153 // We shouldn't sync session data for managed users down at the moment. |
| 151 DCHECK(!sync_data.has_blocked_state()); | 154 DCHECK(!sync_data.has_blocked_state()); |
| 152 DCHECK_EQ(0, sync_data.content_pack_categories_size()); | 155 DCHECK_EQ(0, sync_data.content_pack_categories_size()); |
| 153 | 156 |
| 154 return navigation; | 157 return navigation; |
| 155 } | 158 } |
| 156 | 159 |
| 157 namespace { | 160 namespace { |
| 158 | 161 |
| 159 // Helper used by SerializedNavigationEntry::WriteToPickle(). It writes |str| to | 162 // Helper used by SerializedNavigationEntry::WriteToPickle(). It writes |str| to |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 // | 217 // |
| 215 // Added on later: | 218 // Added on later: |
| 216 // | 219 // |
| 217 // type_mask (has_post_data_) | 220 // type_mask (has_post_data_) |
| 218 // referrer_ | 221 // referrer_ |
| 219 // original_request_url_ | 222 // original_request_url_ |
| 220 // is_overriding_user_agent_ | 223 // is_overriding_user_agent_ |
| 221 // timestamp_ | 224 // timestamp_ |
| 222 // search_terms_ | 225 // search_terms_ |
| 223 // http_status_code_ | 226 // http_status_code_ |
| 227 // redirect_chain_ | |
| 224 | 228 |
| 225 void SerializedNavigationEntry::WriteToPickle(int max_size, | 229 void SerializedNavigationEntry::WriteToPickle(int max_size, |
| 226 Pickle* pickle) const { | 230 Pickle* pickle) const { |
| 227 pickle->WriteInt(index_); | 231 pickle->WriteInt(index_); |
| 228 | 232 |
| 229 int bytes_written = 0; | 233 int bytes_written = 0; |
| 230 | 234 |
| 231 WriteStringToPickle(pickle, &bytes_written, max_size, | 235 WriteStringToPickle(pickle, &bytes_written, max_size, |
| 232 virtual_url_.spec()); | 236 virtual_url_.spec()); |
| 233 | 237 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 255 WriteStringToPickle( | 259 WriteStringToPickle( |
| 256 pickle, &bytes_written, max_size, | 260 pickle, &bytes_written, max_size, |
| 257 original_request_url_.is_valid() ? | 261 original_request_url_.is_valid() ? |
| 258 original_request_url_.spec() : std::string()); | 262 original_request_url_.spec() : std::string()); |
| 259 pickle->WriteBool(is_overriding_user_agent_); | 263 pickle->WriteBool(is_overriding_user_agent_); |
| 260 pickle->WriteInt64(timestamp_.ToInternalValue()); | 264 pickle->WriteInt64(timestamp_.ToInternalValue()); |
| 261 | 265 |
| 262 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); | 266 WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_); |
| 263 | 267 |
| 264 pickle->WriteInt(http_status_code_); | 268 pickle->WriteInt(http_status_code_); |
| 269 | |
| 270 // Redirect chain has variable number of entries. | |
| 271 pickle->WriteUInt16(redirect_chain_.size()); | |
| 272 for (size_t i = 0; i < redirect_chain_.size(); i++) { | |
| 273 GURL redirect_url = redirect_chain_.at(i); | |
| 274 WriteStringToPickle(pickle, &bytes_written, max_size, | |
| 275 redirect_url.is_valid() ? redirect_url.spec() : std::string()); | |
| 276 } | |
| 265 } | 277 } |
| 266 | 278 |
| 267 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { | 279 bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { |
| 268 *this = SerializedNavigationEntry(); | 280 *this = SerializedNavigationEntry(); |
| 269 std::string virtual_url_spec, page_state_data; | 281 std::string virtual_url_spec, page_state_data; |
| 270 int transition_type_int = 0; | 282 int transition_type_int = 0; |
| 271 if (!iterator->ReadInt(&index_) || | 283 if (!iterator->ReadInt(&index_) || |
| 272 !iterator->ReadString(&virtual_url_spec) || | 284 !iterator->ReadString(&virtual_url_spec) || |
| 273 !iterator->ReadString16(&title_) || | 285 !iterator->ReadString16(&title_) || |
| 274 !iterator->ReadString(&page_state_data) || | 286 !iterator->ReadString(&page_state_data) || |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } else { | 328 } else { |
| 317 timestamp_ = base::Time(); | 329 timestamp_ = base::Time(); |
| 318 } | 330 } |
| 319 | 331 |
| 320 // If the search terms field can't be found, leave it empty. | 332 // If the search terms field can't be found, leave it empty. |
| 321 if (!iterator->ReadString16(&search_terms_)) | 333 if (!iterator->ReadString16(&search_terms_)) |
| 322 search_terms_.clear(); | 334 search_terms_.clear(); |
| 323 | 335 |
| 324 if (!iterator->ReadInt(&http_status_code_)) | 336 if (!iterator->ReadInt(&http_status_code_)) |
| 325 http_status_code_ = 0; | 337 http_status_code_ = 0; |
| 338 | |
| 339 // The redirect chain is only in newer pickle streams. | |
| 340 unsigned short redirect_chain_length = 0; | |
| 341 if (iterator->ReadUInt16(&redirect_chain_length)) { | |
| 342 std::vector<GURL> full_redirect_chain; | |
| 343 bool was_full_chain_read_successfully = true; | |
| 344 for (size_t i = 0; i < redirect_chain_length; i++) { | |
| 345 std::string a_redirect; | |
| 346 if (iterator->ReadString(&a_redirect)) { | |
| 347 full_redirect_chain.push_back(GURL(a_redirect)); | |
| 348 } else { | |
| 349 was_full_chain_read_successfully = false; | |
| 350 } | |
| 351 } | |
| 352 if (was_full_chain_read_successfully) { | |
| 353 redirect_chain_ = full_redirect_chain; | |
| 354 } | |
| 355 } | |
| 326 } | 356 } |
| 327 | 357 |
| 328 return true; | 358 return true; |
| 329 } | 359 } |
| 330 | 360 |
| 331 scoped_ptr<NavigationEntry> SerializedNavigationEntry::ToNavigationEntry( | 361 scoped_ptr<NavigationEntry> SerializedNavigationEntry::ToNavigationEntry( |
| 332 int page_id, | 362 int page_id, |
| 333 content::BrowserContext* browser_context) const { | 363 content::BrowserContext* browser_context) const { |
| 334 scoped_ptr<NavigationEntry> entry( | 364 scoped_ptr<NavigationEntry> entry( |
| 335 content::NavigationController::CreateNavigationEntry( | 365 content::NavigationController::CreateNavigationEntry( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 346 entry->SetTitle(title_); | 376 entry->SetTitle(title_); |
| 347 entry->SetPageState(page_state_); | 377 entry->SetPageState(page_state_); |
| 348 entry->SetPageID(page_id); | 378 entry->SetPageID(page_id); |
| 349 entry->SetHasPostData(has_post_data_); | 379 entry->SetHasPostData(has_post_data_); |
| 350 entry->SetPostID(post_id_); | 380 entry->SetPostID(post_id_); |
| 351 entry->SetOriginalRequestURL(original_request_url_); | 381 entry->SetOriginalRequestURL(original_request_url_); |
| 352 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 382 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
| 353 entry->SetTimestamp(timestamp_); | 383 entry->SetTimestamp(timestamp_); |
| 354 entry->SetExtraData(kSearchTermsKey, search_terms_); | 384 entry->SetExtraData(kSearchTermsKey, search_terms_); |
| 355 entry->SetHttpStatusCode(http_status_code_); | 385 entry->SetHttpStatusCode(http_status_code_); |
| 386 entry->SetRedirectChain(redirect_chain_); | |
| 356 | 387 |
| 357 // These fields should have default values. | 388 // These fields should have default values. |
| 358 DCHECK_EQ(STATE_INVALID, blocked_state_); | 389 DCHECK_EQ(STATE_INVALID, blocked_state_); |
| 359 DCHECK_EQ(0u, content_pack_categories_.size()); | 390 DCHECK_EQ(0u, content_pack_categories_.size()); |
| 360 | 391 |
| 361 return entry.Pass(); | 392 return entry.Pass(); |
| 362 } | 393 } |
| 363 | 394 |
| 364 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 395 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
| 365 // See http://crbug.com/67068. | 396 // See http://crbug.com/67068. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 sync_data.set_blocked_state( | 491 sync_data.set_blocked_state( |
| 461 static_cast<sync_pb::TabNavigation_BlockedState>(blocked_state_)); | 492 static_cast<sync_pb::TabNavigation_BlockedState>(blocked_state_)); |
| 462 } | 493 } |
| 463 | 494 |
| 464 for (std::set<std::string>::const_iterator it = | 495 for (std::set<std::string>::const_iterator it = |
| 465 content_pack_categories_.begin(); | 496 content_pack_categories_.begin(); |
| 466 it != content_pack_categories_.end(); ++it) { | 497 it != content_pack_categories_.end(); ++it) { |
| 467 sync_data.add_content_pack_categories(*it); | 498 sync_data.add_content_pack_categories(*it); |
| 468 } | 499 } |
| 469 | 500 |
| 501 // Copy all redirect chain entries except the last URL. | |
| 502 for (size_t i = 0; i < redirect_chain_.size(); i++) { | |
| 503 bool is_last_url = (i == redirect_chain_.size() - 1); | |
| 504 if (is_last_url) { | |
| 505 bool did_redirect = redirect_chain_.size() > 1; | |
| 506 if (did_redirect && | |
| 507 sync_data.virtual_url() != redirect_chain_.at(i).spec()) { | |
| 508 sync_data.set_last_navigation_redirect_url( | |
| 509 redirect_chain_.at(i).spec()); | |
| 510 } | |
| 511 } else { | |
| 512 sync_pb::NavigationRedirect *navigation_redirect = | |
| 513 sync_data.add_navigation_redirect(); | |
| 514 navigation_redirect->set_url(redirect_chain_.at(i).spec()); | |
| 515 } | |
| 516 } | |
| 470 return sync_data; | 517 return sync_data; |
| 471 } | 518 } |
| 472 | 519 |
| 473 // static | 520 // static |
| 474 std::vector<NavigationEntry*> SerializedNavigationEntry::ToNavigationEntries( | 521 std::vector<NavigationEntry*> SerializedNavigationEntry::ToNavigationEntries( |
| 475 const std::vector<SerializedNavigationEntry>& navigations, | 522 const std::vector<SerializedNavigationEntry>& navigations, |
| 476 content::BrowserContext* browser_context) { | 523 content::BrowserContext* browser_context) { |
| 477 int page_id = 0; | 524 int page_id = 0; |
| 478 std::vector<NavigationEntry*> entries; | 525 std::vector<NavigationEntry*> entries; |
| 479 for (std::vector<SerializedNavigationEntry>::const_iterator | 526 for (std::vector<SerializedNavigationEntry>::const_iterator |
| 480 it = navigations.begin(); it != navigations.end(); ++it) { | 527 it = navigations.begin(); it != navigations.end(); ++it) { |
| 481 entries.push_back( | 528 entries.push_back( |
| 482 it->ToNavigationEntry(page_id, browser_context).release()); | 529 it->ToNavigationEntry(page_id, browser_context).release()); |
| 483 ++page_id; | 530 ++page_id; |
| 484 } | 531 } |
| 485 return entries; | 532 return entries; |
| 486 } | 533 } |
| 487 | 534 |
| 488 } // namespace sessions | 535 } // namespace sessions |
| OLD | NEW |