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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 50 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); |
51 navigation.timestamp_ = entry.GetTimestamp(); | 51 navigation.timestamp_ = entry.GetTimestamp(); |
52 navigation.is_restored_ = entry.IsRestored(); | 52 navigation.is_restored_ = entry.IsRestored(); |
53 // If you want to navigate a named frame in Chrome, you will first need to | 53 // If you want to navigate a named frame in Chrome, you will first need to |
54 // add support for persisting it. It is currently only used for layout tests. | 54 // add support for persisting it. It is currently only used for layout tests. |
55 CHECK(entry.GetFrameToNavigate().empty()); | 55 CHECK(entry.GetFrameToNavigate().empty()); |
56 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); | 56 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); |
57 if (entry.GetFavicon().valid) | 57 if (entry.GetFavicon().valid) |
58 navigation.favicon_url_ = entry.GetFavicon().url; | 58 navigation.favicon_url_ = entry.GetFavicon().url; |
59 navigation.http_status_code_ = entry.GetHttpStatusCode(); | 59 navigation.http_status_code_ = entry.GetHttpStatusCode(); |
60 navigation.redirect_chain_ = entry.GetRedirectChain(); | |
60 | 61 |
61 return navigation; | 62 return navigation; |
62 } | 63 } |
63 | 64 |
64 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( | 65 SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( |
65 int index, | 66 int index, |
66 const sync_pb::TabNavigation& sync_data) { | 67 const sync_pb::TabNavigation& sync_data) { |
67 SerializedNavigationEntry navigation; | 68 SerializedNavigationEntry navigation; |
68 navigation.index_ = index; | 69 navigation.index_ = index; |
69 navigation.unique_id_ = sync_data.unique_id(); | 70 navigation.unique_id_ = sync_data.unique_id(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 entry->SetTitle(title_); | 357 entry->SetTitle(title_); |
357 entry->SetPageState(page_state_); | 358 entry->SetPageState(page_state_); |
358 entry->SetPageID(page_id); | 359 entry->SetPageID(page_id); |
359 entry->SetHasPostData(has_post_data_); | 360 entry->SetHasPostData(has_post_data_); |
360 entry->SetPostID(post_id_); | 361 entry->SetPostID(post_id_); |
361 entry->SetOriginalRequestURL(original_request_url_); | 362 entry->SetOriginalRequestURL(original_request_url_); |
362 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); | 363 entry->SetIsOverridingUserAgent(is_overriding_user_agent_); |
363 entry->SetTimestamp(timestamp_); | 364 entry->SetTimestamp(timestamp_); |
364 entry->SetExtraData(kSearchTermsKey, search_terms_); | 365 entry->SetExtraData(kSearchTermsKey, search_terms_); |
365 entry->SetHttpStatusCode(http_status_code_); | 366 entry->SetHttpStatusCode(http_status_code_); |
367 entry->SetRedirectChain(redirect_chain_); | |
366 | 368 |
367 // These fields should have default values. | 369 // These fields should have default values. |
368 DCHECK_EQ(STATE_INVALID, blocked_state_); | 370 DCHECK_EQ(STATE_INVALID, blocked_state_); |
369 DCHECK_EQ(0u, content_pack_categories_.size()); | 371 DCHECK_EQ(0u, content_pack_categories_.size()); |
370 | 372 |
371 return entry.Pass(); | 373 return entry.Pass(); |
372 } | 374 } |
373 | 375 |
374 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? | 376 // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well? |
375 // See http://crbug.com/67068. | 377 // See http://crbug.com/67068. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 sync_data.set_blocked_state( | 472 sync_data.set_blocked_state( |
471 static_cast<sync_pb::TabNavigation_BlockedState>(blocked_state_)); | 473 static_cast<sync_pb::TabNavigation_BlockedState>(blocked_state_)); |
472 } | 474 } |
473 | 475 |
474 for (std::set<std::string>::const_iterator it = | 476 for (std::set<std::string>::const_iterator it = |
475 content_pack_categories_.begin(); | 477 content_pack_categories_.begin(); |
476 it != content_pack_categories_.end(); ++it) { | 478 it != content_pack_categories_.end(); ++it) { |
477 sync_data.add_content_pack_categories(*it); | 479 sync_data.add_content_pack_categories(*it); |
478 } | 480 } |
479 | 481 |
482 // Copy all redirect chain entries except the last URL. | |
sky
2014/02/20 22:12:26
Document why the last isn't copied.
Donn Denman
2014/02/21 08:18:56
Done.
| |
483 for (size_t i = 0; i < redirect_chain_.size(); i++) { | |
sky
2014/02/20 22:12:26
Why don't you have a loop for the first n-1 and th
Donn Denman
2014/02/21 08:18:56
Done. I'm ashamed I didn't see that - it's much m
| |
484 bool is_last_url = (i == redirect_chain_.size() - 1); | |
485 if (is_last_url) { | |
486 bool did_redirect = redirect_chain_.size() > 1; | |
487 if (did_redirect && | |
488 sync_data.virtual_url() != redirect_chain_.at(i).spec()) { | |
489 // If the last URL didn't match the virtual_url, record it separately. | |
490 sync_data.set_last_navigation_redirect_url( | |
491 redirect_chain_.at(i).spec()); | |
492 } | |
493 } else { | |
494 sync_pb::NavigationRedirect *navigation_redirect = | |
sky
2014/02/20 22:12:26
NavigationRedirect*
Donn Denman
2014/02/21 08:18:56
Done.
| |
495 sync_data.add_navigation_redirect(); | |
496 navigation_redirect->set_url(redirect_chain_.at(i).spec()); | |
sky
2014/02/20 22:12:26
at->[]
Donn Denman
2014/02/21 08:18:56
Done.
| |
497 } | |
498 } | |
499 | |
480 sync_data.set_is_restored(is_restored_); | 500 sync_data.set_is_restored(is_restored_); |
481 | 501 |
482 return sync_data; | 502 return sync_data; |
483 } | 503 } |
484 | 504 |
485 // static | 505 // static |
486 std::vector<NavigationEntry*> SerializedNavigationEntry::ToNavigationEntries( | 506 std::vector<NavigationEntry*> SerializedNavigationEntry::ToNavigationEntries( |
487 const std::vector<SerializedNavigationEntry>& navigations, | 507 const std::vector<SerializedNavigationEntry>& navigations, |
488 content::BrowserContext* browser_context) { | 508 content::BrowserContext* browser_context) { |
489 int page_id = 0; | 509 int page_id = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 } | 543 } |
524 | 544 |
525 if (referrer_.url != old_referrer.url || | 545 if (referrer_.url != old_referrer.url || |
526 referrer_.policy != old_referrer.policy) { | 546 referrer_.policy != old_referrer.policy) { |
527 referrer_ = content::Referrer(); | 547 referrer_ = content::Referrer(); |
528 page_state_ = page_state_.RemoveReferrer(); | 548 page_state_ = page_state_.RemoveReferrer(); |
529 } | 549 } |
530 } | 550 } |
531 | 551 |
532 } // namespace sessions | 552 } // namespace sessions |
OLD | NEW |