diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-24 22:00:59 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-24 22:00:59 +0000 |
commit | f66375e4d724f5da1a406d553259685451cdf55d (patch) | |
tree | 25ecde7778c92926a814fd6ae4bc1acc42a2ae38 /chrome/browser/sessions | |
parent | 28b81067d7fa71d061d807267a1ac09f5e4fbd12 (diff) | |
download | chromium_src-f66375e4d724f5da1a406d553259685451cdf55d.zip chromium_src-f66375e4d724f5da1a406d553259685451cdf55d.tar.gz chromium_src-f66375e4d724f5da1a406d553259685451cdf55d.tar.bz2 |
Introduce content::PageState.
This is a concrete class wrapping a string that contains the
data of a serialized WebKit::WebHistoryItem class. Previously,
we've just passed around these as strings, giving them names
like "state", "content_state" or "history_state". It has been
hard to identify all of the places in the code where these
strings get passed around. A concrete class should make usage
more apparent. Plus, instead of manipulating the strings using
methods from webkit/glue/glue_serialize.h, we can just declare
methods on the PageState class. This makes the code much cleaner.
This first pass just implements PageState in terms of glue_serialize.
It also adds content/public/renderer/history_item_serialization.h
as the home for PageState to WebKit::WebHistoryItem conversion,
which should ideally only be usable from the renderer process.
(This bit is a step toward resolving bug 237243.)
page_state.h declares operator==() to support DCHECK_EQ, which
seems consistent with the idea of PageState being a replacement
for std::string. I didn't want to litter tests with calls to
PageState::ToEncodedData(). That would get cumbersome.
BUG=240426
R=brettw@chromium.org, tsepez@chromium.org
Review URL: https://codereview.chromium.org/14985014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202188 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r-- | chrome/browser/sessions/session_restore.cc | 7 | ||||
-rw-r--r-- | chrome/browser/sessions/session_service_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/sessions/session_types_unittest.cc | 7 |
3 files changed, 25 insertions, 38 deletions
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 479338b..940ccb6 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -49,7 +49,6 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "net/base/network_change_notifier.h" -#include "webkit/glue/glue_serialize.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/boot_times_loader.h" @@ -1040,10 +1039,10 @@ class SessionRestoreImpl : public content::NotificationObserver { base::PLATFORM_FILE_READ | base::PLATFORM_FILE_EXCLUSIVE_READ | base::PLATFORM_FILE_ASYNC; - const std::string& state = - tab.navigations.at(selected_index).content_state(); + const content::PageState& page_state = + tab.navigations.at(selected_index).page_state(); const std::vector<base::FilePath>& file_paths = - webkit_glue::FilePathsFromHistoryState(state); + page_state.GetReferencedFiles(); for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); file != file_paths.end(); ++file) { content::ChildProcessSecurityPolicy::GetInstance()-> diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc index 82d5486..6037ac7 100644 --- a/chrome/browser/sessions/session_service_unittest.cc +++ b/chrome/browser/sessions/session_service_unittest.cc @@ -27,11 +27,11 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" +#include "content/public/common/page_state.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" -#include "webkit/glue/glue_serialize.h" using content::NavigationEntry; using sessions::SerializedNavigationEntry; @@ -781,30 +781,24 @@ TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { SessionID tab_id; ASSERT_NE(window_id.id(), tab_id.id()); - // Create a content state representing a HTTP body without posted passwords. - WebKit::WebHTTPBody http_body; - http_body.initialize(); - const char char_data[] = "data"; - http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); - WebKit::WebHistoryItem history_item; - history_item.initialize(); - history_item.setHTTPBody(http_body); - std::string content_state = webkit_glue::HistoryItemToString(history_item); - - // Create a TabNavigation containing content_state and representing a POST + // Create a page state representing a HTTP body without posted passwords. + content::PageState page_state = + content::PageState::CreateForTesting(GURL(), false, "data", NULL); + + // Create a TabNavigation containing page_state and representing a POST // request. SerializedNavigationEntry nav1 = SerializedNavigationEntryTestHelper::CreateNavigation( "http://google.com", "title"); - SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); + SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav1); SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); - // Create a TabNavigation containing content_state and representing a normal + // Create a TabNavigation containing page_state and representing a normal // request. SerializedNavigationEntry nav2 = SerializedNavigationEntryTestHelper::CreateNavigation( "http://google.com/nopost", "title"); - SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav2); + SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav2); nav2.set_index(1); helper_.PrepareTabInWindow(window_id, tab_id, 0, true); @@ -816,7 +810,7 @@ TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); - // Expected: the content state of both navigations was saved and restored. + // Expected: the page state of both navigations was saved and restored. ASSERT_EQ(2u, windows[0]->tabs[0]->navigations.size()); helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); @@ -826,23 +820,16 @@ TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { SessionID tab_id; ASSERT_NE(window_id.id(), tab_id.id()); - // Create a content state representing a HTTP body with posted passwords. - WebKit::WebHTTPBody http_body; - http_body.initialize(); - const char char_data[] = "data"; - http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1)); - http_body.setContainsPasswordData(true); - WebKit::WebHistoryItem history_item; - history_item.initialize(); - history_item.setHTTPBody(http_body); - std::string content_state = webkit_glue::HistoryItemToString(history_item); - - // Create a TabNavigation containing content_state and representing a POST + // Create a page state representing a HTTP body with posted passwords. + content::PageState page_state = + content::PageState::CreateForTesting(GURL(), true, "data", NULL); + + // Create a TabNavigation containing page_state and representing a POST // request with passwords. SerializedNavigationEntry nav1 = SerializedNavigationEntryTestHelper::CreateNavigation( "http://google.com", "title"); - SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); + SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav1); SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); helper_.PrepareTabInWindow(window_id, tab_id, 0, true); UpdateNavigation(window_id, tab_id, nav1, true); @@ -852,9 +839,9 @@ TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); - // Expected: the HTTP body was removed from the content state of the POST + // Expected: the HTTP body was removed from the page state of the POST // navigation with passwords. - EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].content_state()); + EXPECT_NE(page_state, windows[0]->tabs[0]->navigations[0].page_state()); } // This test is only applicable to chromeos. diff --git a/chrome/browser/sessions/session_types_unittest.cc b/chrome/browser/sessions/session_types_unittest.cc index a1f786f..3dd4510 100644 --- a/chrome/browser/sessions/session_types_unittest.cc +++ b/chrome/browser/sessions/session_types_unittest.cc @@ -34,7 +34,8 @@ const content::Referrer kReferrer = WebKit::WebReferrerPolicyAlways); const GURL kVirtualURL("http://www.virtual-url.com"); const string16 kTitle = ASCIIToUTF16("title"); -const std::string kContentState = "content state"; +const content::PageState kPageState = + content::PageState::CreateFromEncodedData("page state"); const content::PageTransition kTransitionType = static_cast<content::PageTransition>( content::PAGE_TRANSITION_AUTO_SUBFRAME | @@ -57,7 +58,7 @@ scoped_ptr<content::NavigationEntry> MakeNavigationEntryForTest() { navigation_entry->SetReferrer(kReferrer); navigation_entry->SetVirtualURL(kVirtualURL); navigation_entry->SetTitle(kTitle); - navigation_entry->SetContentState(kContentState); + navigation_entry->SetPageState(kPageState); navigation_entry->SetTransitionType(kTransitionType); navigation_entry->SetHasPostData(kHasPostData); navigation_entry->SetPostID(kPostID); @@ -76,7 +77,7 @@ sync_pb::TabNavigation MakeSyncDataForTest() { sync_data.set_virtual_url(kVirtualURL.spec()); sync_data.set_referrer(kReferrer.url.spec()); sync_data.set_title(UTF16ToUTF8(kTitle)); - sync_data.set_state(kContentState); + sync_data.set_state(kPageState.ToEncodedData()); sync_data.set_page_transition( sync_pb::SyncEnums_PageTransition_AUTO_SUBFRAME); sync_data.set_unique_id(kUniqueID); |