| Index: components/sessions/serialized_navigation_entry.cc
|
| diff --git a/chrome/browser/sessions/session_types.cc b/components/sessions/serialized_navigation_entry.cc
|
| similarity index 78%
|
| copy from chrome/browser/sessions/session_types.cc
|
| copy to components/sessions/serialized_navigation_entry.cc
|
| index 3ab9fce88218eddad63fe3ceb84c5c2b7245c7de..cd0d8077995d5ff35233efc2229e9ea4bf830e3a 100644
|
| --- a/chrome/browser/sessions/session_types.cc
|
| +++ b/components/sessions/serialized_navigation_entry.cc
|
| @@ -1,17 +1,11 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/sessions/session_types.h"
|
| +#include "components/sessions/serialized_navigation_entry.h"
|
|
|
| -#include "base/basictypes.h"
|
| #include "base/pickle.h"
|
| -#include "base/stl_util.h"
|
| -#include "base/string_util.h"
|
| #include "base/utf_string_conversions.h"
|
| -#include "chrome/browser/search/search.h"
|
| -#include "chrome/browser/sessions/session_command.h"
|
| -#include "chrome/browser/ui/browser.h"
|
| #include "content/public/browser/favicon_status.h"
|
| #include "content/public/browser/navigation_controller.h"
|
| #include "content/public/browser/navigation_entry.h"
|
| @@ -21,9 +15,11 @@
|
|
|
| using content::NavigationEntry;
|
|
|
| -// TabNavigation --------------------------------------------------------------
|
| +namespace sessions {
|
|
|
| -TabNavigation::TabNavigation()
|
| +const char kSearchTermsKey[] = "search_terms";
|
| +
|
| +SerializedNavigationEntry::SerializedNavigationEntry()
|
| : index_(-1),
|
| unique_id_(0),
|
| transition_type_(content::PAGE_TRANSITION_TYPED),
|
| @@ -31,13 +27,13 @@ TabNavigation::TabNavigation()
|
| post_id_(-1),
|
| is_overriding_user_agent_(false) {}
|
|
|
| -TabNavigation::~TabNavigation() {}
|
| +SerializedNavigationEntry::~SerializedNavigationEntry() {}
|
|
|
| // static
|
| -TabNavigation TabNavigation::FromNavigationEntry(
|
| +SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry(
|
| int index,
|
| const NavigationEntry& entry) {
|
| - TabNavigation navigation;
|
| + SerializedNavigationEntry navigation;
|
| navigation.index_ = index;
|
| navigation.unique_id_ = entry.GetUniqueID();
|
| navigation.referrer_ = entry.GetReferrer();
|
| @@ -53,18 +49,17 @@ TabNavigation TabNavigation::FromNavigationEntry(
|
| // If you want to navigate a named frame in Chrome, you will first need to
|
| // add support for persisting it. It is currently only used for layout tests.
|
| CHECK(entry.GetFrameToNavigate().empty());
|
| - navigation.search_terms_ =
|
| - chrome::GetSearchTermsFromNavigationEntry(&entry);
|
| + entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
|
| if (entry.GetFavicon().valid)
|
| navigation.favicon_url_ = entry.GetFavicon().url;
|
|
|
| return navigation;
|
| }
|
|
|
| -TabNavigation TabNavigation::FromSyncData(
|
| +SerializedNavigationEntry SerializedNavigationEntry::FromSyncData(
|
| int index,
|
| const sync_pb::TabNavigation& sync_data) {
|
| - TabNavigation navigation;
|
| + SerializedNavigationEntry navigation;
|
| navigation.index_ = index;
|
| navigation.unique_id_ = sync_data.unique_id();
|
| navigation.referrer_ =
|
| @@ -151,7 +146,7 @@ TabNavigation TabNavigation::FromSyncData(
|
|
|
| namespace {
|
|
|
| -// Helper used by TabNavigation::WriteToPickle(). It writes |str| to
|
| +// Helper used by SerializedNavigationEntry::WriteToPickle(). It writes |str| to
|
| // |pickle|, if and only if |str| fits within (|max_bytes| -
|
| // |*bytes_written|). |bytes_written| is incremented to reflect the
|
| // data written.
|
| @@ -216,30 +211,23 @@ enum TypeMask {
|
| // timestamp_
|
| // search_terms_
|
|
|
| -void TabNavigation::WriteToPickle(Pickle* pickle) const {
|
| +void SerializedNavigationEntry::WriteToPickle(int max_size,
|
| + Pickle* pickle) const {
|
| pickle->WriteInt(index_);
|
|
|
| - // We only allow navigations up to 63k (which should be completely
|
| - // reasonable). On the off chance we get one that is too big, try to
|
| - // keep the url.
|
| -
|
| - // Bound the string data (which is variable length) to
|
| - // |max_state_size bytes| bytes.
|
| - static const size_t max_state_size =
|
| - std::numeric_limits<SessionCommand::size_type>::max() - 1024;
|
| int bytes_written = 0;
|
|
|
| - WriteStringToPickle(pickle, &bytes_written, max_state_size,
|
| + WriteStringToPickle(pickle, &bytes_written, max_size,
|
| virtual_url_.spec());
|
|
|
| - WriteString16ToPickle(pickle, &bytes_written, max_state_size, title_);
|
| + WriteString16ToPickle(pickle, &bytes_written, max_size, title_);
|
|
|
| std::string content_state = content_state_;
|
| if (has_post_data_) {
|
| content_state =
|
| webkit_glue::RemovePasswordDataFromHistoryState(content_state);
|
| }
|
| - WriteStringToPickle(pickle, &bytes_written, max_state_size, content_state);
|
| + WriteStringToPickle(pickle, &bytes_written, max_size, content_state);
|
|
|
| pickle->WriteInt(transition_type_);
|
|
|
| @@ -247,24 +235,24 @@ void TabNavigation::WriteToPickle(Pickle* pickle) const {
|
| pickle->WriteInt(type_mask);
|
|
|
| WriteStringToPickle(
|
| - pickle, &bytes_written, max_state_size,
|
| + pickle, &bytes_written, max_size,
|
| referrer_.url.is_valid() ? referrer_.url.spec() : std::string());
|
|
|
| pickle->WriteInt(referrer_.policy);
|
|
|
| // Save info required to override the user agent.
|
| WriteStringToPickle(
|
| - pickle, &bytes_written, max_state_size,
|
| + pickle, &bytes_written, max_size,
|
| original_request_url_.is_valid() ?
|
| original_request_url_.spec() : std::string());
|
| pickle->WriteBool(is_overriding_user_agent_);
|
| pickle->WriteInt64(timestamp_.ToInternalValue());
|
|
|
| - WriteString16ToPickle(pickle, &bytes_written, max_state_size, search_terms_);
|
| + WriteString16ToPickle(pickle, &bytes_written, max_size, search_terms_);
|
| }
|
|
|
| -bool TabNavigation::ReadFromPickle(PickleIterator* iterator) {
|
| - *this = TabNavigation();
|
| +bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) {
|
| + *this = SerializedNavigationEntry();
|
| std::string virtual_url_spec;
|
| int transition_type_int = 0;
|
| if (!iterator->ReadInt(&index_) ||
|
| @@ -323,7 +311,7 @@ bool TabNavigation::ReadFromPickle(PickleIterator* iterator) {
|
| return true;
|
| }
|
|
|
| -scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry(
|
| +scoped_ptr<NavigationEntry> SerializedNavigationEntry::ToNavigationEntry(
|
| int page_id,
|
| content::BrowserContext* browser_context) const {
|
| scoped_ptr<NavigationEntry> entry(
|
| @@ -346,14 +334,14 @@ scoped_ptr<NavigationEntry> TabNavigation::ToNavigationEntry(
|
| entry->SetOriginalRequestURL(original_request_url_);
|
| entry->SetIsOverridingUserAgent(is_overriding_user_agent_);
|
| entry->SetTimestamp(timestamp_);
|
| - entry->SetExtraData(chrome::kInstantExtendedSearchTermsKey, search_terms_);
|
| + entry->SetExtraData(kSearchTermsKey, search_terms_);
|
|
|
| return entry.Pass();
|
| }
|
|
|
| // TODO(zea): perhaps sync state (scroll position, form entries, etc.) as well?
|
| // See http://crbug.com/67068.
|
| -sync_pb::TabNavigation TabNavigation::ToSyncData() const {
|
| +sync_pb::TabNavigation SerializedNavigationEntry::ToSyncData() const {
|
| sync_pb::TabNavigation sync_data;
|
| sync_data.set_virtual_url(virtual_url_.spec());
|
| // FIXME(zea): Support referrer policy?
|
| @@ -448,14 +436,13 @@ sync_pb::TabNavigation TabNavigation::ToSyncData() const {
|
| }
|
|
|
| // static
|
| -std::vector<NavigationEntry*>
|
| -TabNavigation::CreateNavigationEntriesFromTabNavigations(
|
| - const std::vector<TabNavigation>& navigations,
|
| +std::vector<NavigationEntry*> SerializedNavigationEntry::ToNavigationEntries(
|
| + const std::vector<SerializedNavigationEntry>& navigations,
|
| content::BrowserContext* browser_context) {
|
| int page_id = 0;
|
| std::vector<NavigationEntry*> entries;
|
| - for (std::vector<TabNavigation>::const_iterator it = navigations.begin();
|
| - it != navigations.end(); ++it) {
|
| + for (std::vector<SerializedNavigationEntry>::const_iterator
|
| + it = navigations.begin(); it != navigations.end(); ++it) {
|
| entries.push_back(
|
| it->ToNavigationEntry(page_id, browser_context).release());
|
| ++page_id;
|
| @@ -463,59 +450,4 @@ TabNavigation::CreateNavigationEntriesFromTabNavigations(
|
| return entries;
|
| }
|
|
|
| -// SessionTab -----------------------------------------------------------------
|
| -
|
| -SessionTab::SessionTab()
|
| - : tab_visual_index(-1),
|
| - current_navigation_index(-1),
|
| - pinned(false) {
|
| -}
|
| -
|
| -SessionTab::~SessionTab() {
|
| -}
|
| -
|
| -void SessionTab::SetFromSyncData(const sync_pb::SessionTab& sync_data,
|
| - base::Time timestamp) {
|
| - window_id.set_id(sync_data.window_id());
|
| - tab_id.set_id(sync_data.tab_id());
|
| - tab_visual_index = sync_data.tab_visual_index();
|
| - current_navigation_index = sync_data.current_navigation_index();
|
| - pinned = sync_data.pinned();
|
| - extension_app_id = sync_data.extension_app_id();
|
| - user_agent_override.clear();
|
| - this->timestamp = timestamp;
|
| - navigations.clear();
|
| - for (int i = 0; i < sync_data.navigation_size(); ++i) {
|
| - navigations.push_back(
|
| - TabNavigation::FromSyncData(i, sync_data.navigation(i)));
|
| - }
|
| - session_storage_persistent_id.clear();
|
| -}
|
| -
|
| -sync_pb::SessionTab SessionTab::ToSyncData() const {
|
| - sync_pb::SessionTab sync_data;
|
| - sync_data.set_tab_id(tab_id.id());
|
| - sync_data.set_window_id(window_id.id());
|
| - sync_data.set_tab_visual_index(tab_visual_index);
|
| - sync_data.set_current_navigation_index(current_navigation_index);
|
| - sync_data.set_pinned(pinned);
|
| - sync_data.set_extension_app_id(extension_app_id);
|
| - for (std::vector<TabNavigation>::const_iterator it = navigations.begin();
|
| - it != navigations.end(); ++it) {
|
| - *sync_data.add_navigation() = it->ToSyncData();
|
| - }
|
| - return sync_data;
|
| -}
|
| -
|
| -// SessionWindow ---------------------------------------------------------------
|
| -
|
| -SessionWindow::SessionWindow()
|
| - : selected_tab_index(-1),
|
| - type(Browser::TYPE_TABBED),
|
| - is_constrained(true),
|
| - show_state(ui::SHOW_STATE_DEFAULT) {
|
| -}
|
| -
|
| -SessionWindow::~SessionWindow() {
|
| - STLDeleteElements(&tabs);
|
| -}
|
| +} // namespace sessions
|
|
|