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 /android_webview | |
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 'android_webview')
-rw-r--r-- | android_webview/native/state_serializer.cc | 6 | ||||
-rw-r--r-- | android_webview/native/state_serializer_unittests.cc | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/android_webview/native/state_serializer.cc b/android_webview/native/state_serializer.cc index 656b2d0..5abc929 100644 --- a/android_webview/native/state_serializer.cc +++ b/android_webview/native/state_serializer.cc @@ -12,6 +12,7 @@ #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/web_contents.h" +#include "content/public/common/page_state.h" // Reasons for not re-using TabNavigation under chrome/ as of 20121116: // * Android WebView has different requirements for fields to store since @@ -146,7 +147,7 @@ bool WriteNavigationEntryToPickle(const content::NavigationEntry& entry, if (!pickle->WriteString16(entry.GetTitle())) return false; - if (!pickle->WriteString(entry.GetContentState())) + if (!pickle->WriteString(entry.GetPageState().ToEncodedData())) return false; if (!pickle->WriteBool(static_cast<int>(entry.GetHasPostData()))) @@ -211,7 +212,8 @@ bool RestoreNavigationEntryFromPickle(PickleIterator* iterator, string content_state; if (!iterator->ReadString(&content_state)) return false; - entry->SetContentState(content_state); + entry->SetPageState( + content::PageState::CreateFromEncodedData(content_state)); } { diff --git a/android_webview/native/state_serializer_unittests.cc b/android_webview/native/state_serializer_unittests.cc index 53c4087..539ee54 100644 --- a/android_webview/native/state_serializer_unittests.cc +++ b/android_webview/native/state_serializer_unittests.cc @@ -13,6 +13,7 @@ #include "content/public/browser/content_browser_client.h" #include "content/public/browser/navigation_entry.h" #include "content/public/common/content_client.h" +#include "content/public/common/page_state.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -46,7 +47,8 @@ TEST(AndroidWebViewStateSerializerTest, TestNavigationEntrySerialization) { referrer.url = GURL("http://referrer_url"); referrer.policy = WebKit::WebReferrerPolicyOrigin; const string16 title(UTF8ToUTF16("title")); - const string content_state("completely bogus state"); + const content::PageState page_state = + content::PageState::CreateFromEncodedData("completely bogus state"); const bool has_post_data = true; const GURL original_request_url("http://original_request_url"); const GURL base_url_for_data_url("http://base_url"); @@ -57,7 +59,7 @@ TEST(AndroidWebViewStateSerializerTest, TestNavigationEntrySerialization) { entry->SetVirtualURL(virtual_url); entry->SetReferrer(referrer); entry->SetTitle(title); - entry->SetContentState(content_state); + entry->SetPageState(page_state); entry->SetHasPostData(has_post_data); entry->SetOriginalRequestURL(original_request_url); entry->SetBaseURLForDataURL(base_url_for_data_url); @@ -78,7 +80,7 @@ TEST(AndroidWebViewStateSerializerTest, TestNavigationEntrySerialization) { EXPECT_EQ(referrer.url, copy->GetReferrer().url); EXPECT_EQ(referrer.policy, copy->GetReferrer().policy); EXPECT_EQ(title, copy->GetTitle()); - EXPECT_EQ(content_state, copy->GetContentState()); + EXPECT_EQ(page_state, copy->GetPageState()); EXPECT_EQ(has_post_data, copy->GetHasPostData()); EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL()); EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL()); |