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 | |
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
57 files changed, 542 insertions, 256 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()); 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); diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 145559f..a1e7146 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1775,7 +1775,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: source_web_contents_->ViewFrameSource(params_.frame_url, - params_.frame_content_state); + params_.frame_page_state); break; case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: { diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 2477f6b..9cb4c5f 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1409,9 +1409,9 @@ void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { void Browser::ViewSourceForFrame(WebContents* source, const GURL& frame_url, - const std::string& frame_content_state) { + const content::PageState& frame_page_state) { DCHECK(source); - chrome::ViewSource(this, source, frame_url, frame_content_state); + chrome::ViewSource(this, source, frame_url, frame_page_state); } void Browser::ShowRepostFormWarningDialog(WebContents* source) { diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index d239b2a..a8f7331 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -71,6 +71,7 @@ class UnloadController; namespace content { class NavigationController; +class PageState; class SessionStorageNamespace; } @@ -554,7 +555,7 @@ class Browser : public TabStripModelObserver, virtual void ViewSourceForFrame( content::WebContents* source, const GURL& frame_url, - const std::string& frame_content_state) OVERRIDE; + const content::PageState& frame_page_state) OVERRIDE; virtual void ShowRepostFormWarningDialog( content::WebContents* source) OVERRIDE; virtual bool ShouldCreateWebContents( diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 4000083..fd1c0ad 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -73,7 +73,6 @@ #include "content/public/common/url_utils.h" #include "net/base/escape.h" #include "webkit/common/user_agent/user_agent_util.h" -#include "webkit/glue/glue_serialize.h" #if defined(OS_MACOSX) #include "ui/base/cocoa/find_pasteboard.h" @@ -996,13 +995,13 @@ void ViewSource(Browser* browser, WebContents* contents) { if (!entry) return; - ViewSource(browser, contents, entry->GetURL(), entry->GetContentState()); + ViewSource(browser, contents, entry->GetURL(), entry->GetPageState()); } void ViewSource(Browser* browser, WebContents* contents, const GURL& url, - const std::string& content_state) { + const content::PageState& page_state) { content::RecordAction(UserMetricsAction("ViewSource")); DCHECK(contents); @@ -1020,8 +1019,7 @@ void ViewSource(Browser* browser, active_entry->SetVirtualURL(view_source_url); // Do not restore scroller position. - active_entry->SetContentState( - webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); + active_entry->SetPageState(page_state.RemoveScrollOffset()); // Do not restore title, derive it from the url. active_entry->SetTitle(string16()); diff --git a/chrome/browser/ui/browser_commands.h b/chrome/browser/ui/browser_commands.h index f78b9c3..f144d8c7 100644 --- a/chrome/browser/ui/browser_commands.h +++ b/chrome/browser/ui/browser_commands.h @@ -19,6 +19,7 @@ class GURL; class Profile; namespace content { +class PageState; class WebContents; struct SSLStatus; } @@ -152,7 +153,7 @@ void ViewSource(Browser* browser, content::WebContents* tab); void ViewSource(Browser* browser, content::WebContents* tab, const GURL& url, - const std::string& content_state); + const content::PageState& page_state); void ViewSelectedSource(Browser* browser); bool CanViewSource(const Browser* browser); diff --git a/components/sessions/serialized_navigation_entry.cc b/components/sessions/serialized_navigation_entry.cc index 6ba7533..e322830 100644 --- a/components/sessions/serialized_navigation_entry.cc +++ b/components/sessions/serialized_navigation_entry.cc @@ -12,7 +12,6 @@ #include "sync/protocol/session_specifics.pb.h" #include "sync/util/time.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h" -#include "webkit/glue/glue_serialize.h" using content::NavigationEntry; @@ -41,7 +40,7 @@ SerializedNavigationEntry SerializedNavigationEntry::FromNavigationEntry( navigation.referrer_ = entry.GetReferrer(); navigation.virtual_url_ = entry.GetVirtualURL(); navigation.title_ = entry.GetTitle(); - navigation.content_state_ = entry.GetContentState(); + navigation.page_state_ = entry.GetPageState(); navigation.transition_type_ = entry.GetTransitionType(); navigation.has_post_data_ = entry.GetHasPostData(); navigation.post_id_ = entry.GetPostID(); @@ -69,7 +68,8 @@ SerializedNavigationEntry SerializedNavigationEntry::FromSyncData( WebKit::WebReferrerPolicyDefault); navigation.virtual_url_ = GURL(sync_data.virtual_url()); navigation.title_ = UTF8ToUTF16(sync_data.title()); - navigation.content_state_ = sync_data.state(); + navigation.page_state_ = + content::PageState::CreateFromEncodedData(sync_data.state()); uint32 transition = 0; if (sync_data.has_page_transition()) { @@ -205,7 +205,7 @@ enum TypeMask { // index_ // virtual_url_ // title_ -// content_state_ +// page_state_ // transition_type_ // // Added on later: @@ -228,12 +228,12 @@ void SerializedNavigationEntry::WriteToPickle(int max_size, 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_size, content_state); + content::PageState page_state = page_state_; + if (has_post_data_) + page_state = page_state.RemovePasswordData(); + + WriteStringToPickle(pickle, &bytes_written, max_size, + page_state.ToEncodedData()); pickle->WriteInt(transition_type_); @@ -259,15 +259,16 @@ void SerializedNavigationEntry::WriteToPickle(int max_size, bool SerializedNavigationEntry::ReadFromPickle(PickleIterator* iterator) { *this = SerializedNavigationEntry(); - std::string virtual_url_spec; + std::string virtual_url_spec, page_state_data; int transition_type_int = 0; if (!iterator->ReadInt(&index_) || !iterator->ReadString(&virtual_url_spec) || !iterator->ReadString16(&title_) || - !iterator->ReadString(&content_state_) || + !iterator->ReadString(&page_state_data) || !iterator->ReadInt(&transition_type_int)) return false; virtual_url_ = GURL(virtual_url_spec); + page_state_ = content::PageState::CreateFromEncodedData(page_state_data); transition_type_ = static_cast<content::PageTransition>(transition_type_int); // type_mask did not always exist in the written stream. As such, we @@ -333,7 +334,7 @@ scoped_ptr<NavigationEntry> SerializedNavigationEntry::ToNavigationEntry( browser_context)); entry->SetTitle(title_); - entry->SetContentState(content_state_); + entry->SetPageState(page_state_); entry->SetPageID(page_id); entry->SetHasPostData(has_post_data_); entry->SetPostID(post_id_); diff --git a/components/sessions/serialized_navigation_entry.h b/components/sessions/serialized_navigation_entry.h index bc72700..f76642b 100644 --- a/components/sessions/serialized_navigation_entry.h +++ b/components/sessions/serialized_navigation_entry.h @@ -14,6 +14,7 @@ #include "base/string16.h" #include "base/time.h" #include "components/sessions/sessions_export.h" +#include "content/public/common/page_state.h" #include "content/public/common/page_transition_types.h" #include "content/public/common/referrer.h" #include "googleurl/src/gurl.h" @@ -96,7 +97,7 @@ class SESSIONS_EXPORT SerializedNavigationEntry { int unique_id() const { return unique_id_; } const GURL& virtual_url() const { return virtual_url_; } const string16& title() const { return title_; } - const std::string& content_state() const { return content_state_; } + const content::PageState& page_state() const { return page_state_; } const string16& search_terms() const { return search_terms_; } const GURL& favicon_url() const { return favicon_url_; } const content::Referrer& referrer() const { return referrer_; } @@ -139,7 +140,7 @@ class SESSIONS_EXPORT SerializedNavigationEntry { content::Referrer referrer_; GURL virtual_url_; string16 title_; - std::string content_state_; + content::PageState page_state_; content::PageTransition transition_type_; bool has_post_data_; int64 post_id_; diff --git a/components/sessions/serialized_navigation_entry_test_helper.cc b/components/sessions/serialized_navigation_entry_test_helper.cc index 0c26e46..b1e2c00 100644 --- a/components/sessions/serialized_navigation_entry_test_helper.cc +++ b/components/sessions/serialized_navigation_entry_test_helper.cc @@ -21,7 +21,7 @@ void SerializedNavigationEntryTestHelper::ExpectNavigationEquals( EXPECT_EQ(expected.referrer_.policy, actual.referrer_.policy); EXPECT_EQ(expected.virtual_url_, actual.virtual_url_); EXPECT_EQ(expected.title_, actual.title_); - EXPECT_EQ(expected.content_state_, actual.content_state_); + EXPECT_EQ(expected.page_state_, actual.page_state_); EXPECT_EQ(expected.transition_type_, actual.transition_type_); EXPECT_EQ(expected.has_post_data_, actual.has_post_data_); EXPECT_EQ(expected.original_request_url_, actual.original_request_url_); @@ -40,16 +40,17 @@ SerializedNavigationEntry SerializedNavigationEntryTestHelper::CreateNavigation( WebKit::WebReferrerPolicyDefault); navigation.virtual_url_ = GURL(virtual_url); navigation.title_ = UTF8ToUTF16(title); - navigation.content_state_ = "fake_state"; + navigation.page_state_ = + content::PageState::CreateFromEncodedData("fake_state"); navigation.timestamp_ = base::Time::Now(); return navigation; } // static -void SerializedNavigationEntryTestHelper::SetContentState( - const std::string& content_state, +void SerializedNavigationEntryTestHelper::SetPageState( + const content::PageState& page_state, SerializedNavigationEntry* navigation) { - navigation->content_state_ = content_state; + navigation->page_state_ = page_state; } // static diff --git a/components/sessions/serialized_navigation_entry_test_helper.h b/components/sessions/serialized_navigation_entry_test_helper.h index 43b49eb..a653f22 100644 --- a/components/sessions/serialized_navigation_entry_test_helper.h +++ b/components/sessions/serialized_navigation_entry_test_helper.h @@ -17,6 +17,7 @@ class Time; } namespace content { +class PageState; struct Referrer; } @@ -38,8 +39,8 @@ class SerializedNavigationEntryTestHelper { const std::string& virtual_url, const std::string& title); - static void SetContentState(const std::string& content_state, - SerializedNavigationEntry* navigation); + static void SetPageState(const content::PageState& page_state, + SerializedNavigationEntry* navigation); static void SetHasPostData(bool has_post_data, SerializedNavigationEntry* navigation); diff --git a/components/sessions/serialized_navigation_entry_unittest.cc b/components/sessions/serialized_navigation_entry_unittest.cc index 2f439da..f8e5c3f 100644 --- a/components/sessions/serialized_navigation_entry_unittest.cc +++ b/components/sessions/serialized_navigation_entry_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); @@ -98,7 +99,7 @@ TEST(SerializedNavigationEntryTest, DefaultInitializer) { EXPECT_EQ(WebKit::WebReferrerPolicyDefault, navigation.referrer().policy); EXPECT_EQ(GURL(), navigation.virtual_url()); EXPECT_TRUE(navigation.title().empty()); - EXPECT_TRUE(navigation.content_state().empty()); + EXPECT_FALSE(navigation.page_state().IsValid()); EXPECT_EQ(content::PAGE_TRANSITION_TYPED, navigation.transition_type()); EXPECT_FALSE(navigation.has_post_data()); EXPECT_EQ(-1, navigation.post_id()); @@ -125,7 +126,7 @@ TEST(SerializedNavigationEntryTest, FromNavigationEntry) { EXPECT_EQ(kReferrer.policy, navigation.referrer().policy); EXPECT_EQ(kVirtualURL, navigation.virtual_url()); EXPECT_EQ(kTitle, navigation.title()); - EXPECT_EQ(kContentState, navigation.content_state()); + EXPECT_EQ(kPageState, navigation.page_state()); EXPECT_EQ(kTransitionType, navigation.transition_type()); EXPECT_EQ(kHasPostData, navigation.has_post_data()); EXPECT_EQ(kPostID, navigation.post_id()); @@ -150,7 +151,7 @@ TEST(SerializedNavigationEntryTest, FromSyncData) { EXPECT_EQ(WebKit::WebReferrerPolicyDefault, navigation.referrer().policy); EXPECT_EQ(kVirtualURL, navigation.virtual_url()); EXPECT_EQ(kTitle, navigation.title()); - EXPECT_EQ(kContentState, navigation.content_state()); + EXPECT_EQ(kPageState, navigation.page_state()); EXPECT_EQ(kTransitionType, navigation.transition_type()); EXPECT_FALSE(navigation.has_post_data()); EXPECT_EQ(-1, navigation.post_id()); @@ -183,7 +184,7 @@ TEST(SerializedNavigationEntryTest, Pickle) { EXPECT_EQ(kReferrer.policy, new_navigation.referrer().policy); EXPECT_EQ(kVirtualURL, new_navigation.virtual_url()); EXPECT_EQ(kTitle, new_navigation.title()); - EXPECT_TRUE(new_navigation.content_state().empty()); + EXPECT_FALSE(new_navigation.page_state().IsValid()); EXPECT_EQ(kTransitionType, new_navigation.transition_type()); EXPECT_EQ(kHasPostData, new_navigation.has_post_data()); EXPECT_EQ(-1, new_navigation.post_id()); @@ -212,7 +213,7 @@ TEST(SerializedNavigationEntryTest, ToNavigationEntry) { EXPECT_EQ(kReferrer.policy, new_navigation_entry->GetReferrer().policy); EXPECT_EQ(kVirtualURL, new_navigation_entry->GetVirtualURL()); EXPECT_EQ(kTitle, new_navigation_entry->GetTitle()); - EXPECT_EQ(kContentState, new_navigation_entry->GetContentState()); + EXPECT_EQ(kPageState, new_navigation_entry->GetPageState()); EXPECT_EQ(kPageID, new_navigation_entry->GetPageID()); EXPECT_EQ(content::PAGE_TRANSITION_RELOAD, new_navigation_entry->GetTransitionType()); diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h index f2be7e1..d9ad8ef 100644 --- a/content/browser/renderer_host/render_view_host_delegate.h +++ b/content/browser/renderer_host/render_view_host_delegate.h @@ -47,6 +47,7 @@ class Size; namespace content { class BrowserContext; +class PageState; class RenderViewHost; class RenderViewHostDelegateView; class SessionStorageNamespace; @@ -170,7 +171,7 @@ class CONTENT_EXPORT RenderViewHostDelegate { // The state for the page changed and should be updated. virtual void UpdateState(RenderViewHost* render_view_host, int32 page_id, - const std::string& state) {} + const PageState& state) {} // The page's title was changed and should be updated. virtual void UpdateTitle(RenderViewHost* render_view_host, diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 4bb53f4..4ab7821 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -68,7 +68,6 @@ #include "ui/shell_dialogs/selected_file_info.h" #include "ui/snapshot/snapshot.h" #include "webkit/browser/fileapi/isolated_context.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webkit_glue.h" @@ -1235,7 +1234,7 @@ void RenderViewHostImpl::OnNavigate(const IPC::Message& msg) { // Without this check, the renderer can trick the browser into using // filenames it can't access in a future session restore. - if (!CanAccessFilesOfSerializedState(validated_params.content_state)) { + if (!CanAccessFilesOfPageState(validated_params.page_state)) { GetProcess()->ReceivedBadMessage(); return; } @@ -1243,11 +1242,10 @@ void RenderViewHostImpl::OnNavigate(const IPC::Message& msg) { delegate_->DidNavigate(this, validated_params); } -void RenderViewHostImpl::OnUpdateState(int32 page_id, - const std::string& state) { +void RenderViewHostImpl::OnUpdateState(int32 page_id, const PageState& state) { // Without this check, the renderer can trick the browser into using // filenames it can't access in a future session restore. - if (!CanAccessFilesOfSerializedState(state)) { + if (!CanAccessFilesOfPageState(state)) { GetProcess()->ReceivedBadMessage(); return; } @@ -2074,12 +2072,12 @@ void RenderViewHostImpl::ClearPowerSaveBlockers() { STLDeleteValues(&power_save_blockers_); } -bool RenderViewHostImpl::CanAccessFilesOfSerializedState( - const std::string& state) const { +bool RenderViewHostImpl::CanAccessFilesOfPageState( + const PageState& state) const { ChildProcessSecurityPolicyImpl* policy = ChildProcessSecurityPolicyImpl::GetInstance(); - const std::vector<base::FilePath>& file_paths = - webkit_glue::FilePathsFromHistoryState(state); + + const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); file != file_paths.end(); ++file) { if (!policy->CanReadFile(GetProcess()->GetID(), *file)) diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index d4a6e5d..2d5249f 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -60,6 +60,7 @@ class MediaPlayerManager; namespace content { class ChildProcessSecurityPolicyImpl; +class PageState; class PowerSaveBlocker; class RenderViewHostObserver; class RenderWidgetHostDelegate; @@ -481,7 +482,7 @@ class CONTENT_EXPORT RenderViewHostImpl void OnDidFailProvisionalLoadWithError( const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params); void OnNavigate(const IPC::Message& msg); - void OnUpdateState(int32 page_id, const std::string& state); + void OnUpdateState(int32 page_id, const PageState& state); void OnUpdateTitle(int32 page_id, const string16& title, WebKit::WebTextDirection title_direction); @@ -573,7 +574,7 @@ class CONTENT_EXPORT RenderViewHostImpl void ClearPowerSaveBlockers(); - bool CanAccessFilesOfSerializedState(const std::string& state) const; + bool CanAccessFilesOfPageState(const PageState& state) const; // Our delegate, which wants to know about changes in the RenderView. RenderViewHostDelegate* delegate_; diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc index a84f4dc..315927c 100644 --- a/content/browser/renderer_host/test_render_view_host.cc +++ b/content/browser/renderer_host/test_render_view_host.cc @@ -13,12 +13,12 @@ #include "content/public/browser/navigation_controller.h" #include "content/public/browser/storage_partition.h" #include "content/public/common/content_client.h" +#include "content/public/common/page_state.h" #include "content/public/common/password_form.h" #include "content/test/test_web_contents.h" #include "media/base/video_frame.h" #include "ui/gfx/rect.h" #include "webkit/dom_storage/dom_storage_types.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webpreferences.h" namespace content { @@ -58,7 +58,7 @@ void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, params->gesture = NavigationGestureUser; params->was_within_same_page = false; params->is_post = false; - params->content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params->page_state = PageState::CreateFromURL(url); } TestRenderWidgetHostView::TestRenderWidgetHostView(RenderWidgetHost* rwh) @@ -337,20 +337,11 @@ void TestRenderViewHost::SendNavigateWithParameters( params.history_list_was_cleared = simulate_history_list_was_cleared_; params.original_request_url = original_request_url; - WebKit::WebHTTPBody http_body; - http_body.initialize(); - - WebKit::WebHistoryItem history_item; - history_item.initialize(); - history_item.setURLString(WebKit::WebString::fromUTF8(url.spec())); - if (file_path_for_history_item) { - const char char_data[] = "data"; - http_body.appendData(WebKit::WebData(char_data, arraysize(char_data)-1)); - http_body.appendFile(WebKit::WebString::fromUTF8( - file_path_for_history_item->MaybeAsASCII())); - history_item.setHTTPBody(http_body); - } - params.content_state = webkit_glue::HistoryItemToString(history_item); + params.page_state = PageState::CreateForTesting( + url, + false, + file_path_for_history_item ? "data" : NULL, + file_path_for_history_item); ViewHostMsg_FrameNavigate msg(1, params); OnNavigate(msg); @@ -388,17 +379,11 @@ void TestRenderViewHost::TestOnStartDragging( void TestRenderViewHost::TestOnUpdateStateWithFile( int process_id, const base::FilePath& file_path) { - WebKit::WebHTTPBody http_body; - http_body.initialize(); - const char char_data[] = "data"; - http_body.appendData(WebKit::WebData(char_data, arraysize(char_data)-1)); - http_body.appendFile(WebKit::WebString::fromUTF8(file_path.MaybeAsASCII())); - - WebKit::WebHistoryItem history_item; - history_item.initialize(); - history_item.setURLString("http://www.google.com"); - history_item.setHTTPBody(http_body); - OnUpdateState(process_id, webkit_glue::HistoryItemToString(history_item)); + OnUpdateState(process_id, + PageState::CreateForTesting(GURL("http://www.google.com"), + false, + "data", + &file_path)); } void TestRenderViewHost::set_simulate_fetch_via_proxy(bool proxy) { diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc index 5488c6c..8bd29ee 100644 --- a/content/browser/web_contents/navigation_controller_impl.cc +++ b/content/browser/web_contents/navigation_controller_impl.cc @@ -40,7 +40,6 @@ #include "net/base/mime_util.h" #include "net/base/net_util.h" #include "skia/ext/platform_canvas.h" -#include "webkit/glue/glue_serialize.h" namespace content { namespace { @@ -69,11 +68,9 @@ void NotifyPrunedEntries(NavigationControllerImpl* nav_controller, // losing the navigation entries and generating a new navigation entry after // this one. We don't want that. To avoid this we create a valid state which // WebKit will not treat as a new navigation. -void SetContentStateIfEmpty(NavigationEntryImpl* entry) { - if (entry->GetContentState().empty()) { - entry->SetContentState( - webkit_glue::CreateHistoryStateForURL(entry->GetURL())); - } +void SetPageStateIfEmpty(NavigationEntryImpl* entry) { + if (!entry->GetPageState().IsValid()) + entry->SetPageState(PageState::CreateFromURL(entry->GetURL())); } NavigationEntryImpl::RestoreType ControllerRestoreTypeToEntryType( @@ -101,7 +98,7 @@ void ConfigureEntriesForRestore( (*entries)[i]->SetTransitionType(PAGE_TRANSITION_RELOAD); (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type)); // NOTE(darin): This code is only needed for backwards compat. - SetContentStateIfEmpty((*entries)[i].get()); + SetPageStateIfEmpty((*entries)[i].get()); } } @@ -769,11 +766,11 @@ bool NavigationControllerImpl::RendererDidNavigate( // All committed entries should have nonempty content state so WebKit doesn't // get confused when we go back to them (see the function for details). - DCHECK(!params.content_state.empty()); + DCHECK(params.page_state.IsValid()); NavigationEntryImpl* active_entry = NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); active_entry->SetTimestamp(timestamp); - active_entry->SetContentState(params.content_state); + active_entry->SetPageState(params.page_state); // No longer needed since content state will hold the post data if any. active_entry->SetBrowserInitiatedPostData(NULL); diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc index 4a51897e..f9c2372 100644 --- a/content/browser/web_contents/navigation_controller_impl_unittest.cc +++ b/content/browser/web_contents/navigation_controller_impl_unittest.cc @@ -32,6 +32,7 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host_observer.h" #include "content/public/browser/web_contents_delegate.h" +#include "content/public/common/page_state.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_notification_tracker.h" #include "content/public/test/test_utils.h" @@ -39,7 +40,6 @@ #include "net/base/net_util.h" #include "skia/ext/platform_canvas.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/glue_serialize.h" using base::Time; @@ -1493,7 +1493,7 @@ TEST_F(NavigationControllerTest, Redirect) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); LoadCommittedDetails details; @@ -1548,7 +1548,7 @@ TEST_F(NavigationControllerTest, PostThenRedirect) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); LoadCommittedDetails details; @@ -1594,7 +1594,7 @@ TEST_F(NavigationControllerTest, ImmediateRedirect) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); LoadCommittedDetails details; @@ -1633,7 +1633,7 @@ TEST_F(NavigationControllerTest, NewSubframe) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); LoadCommittedDetails details; EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); @@ -1668,7 +1668,7 @@ TEST_F(NavigationControllerTest, SubframeOnEmptyPage) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); LoadCommittedDetails details; EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); @@ -1694,7 +1694,7 @@ TEST_F(NavigationControllerTest, AutoSubframe) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); // Navigating should do nothing. LoadCommittedDetails details; @@ -1725,7 +1725,7 @@ TEST_F(NavigationControllerTest, BackSubframe) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); // This should generate a new entry. LoadCommittedDetails details; @@ -1808,7 +1808,7 @@ TEST_F(NavigationControllerTest, InPage) { self_params.should_update_history = false; self_params.gesture = NavigationGestureUser; self_params.is_post = false; - self_params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1)); + self_params.page_state = PageState::CreateFromURL(url1); self_params.was_within_same_page = true; LoadCommittedDetails details; @@ -1827,7 +1827,7 @@ TEST_F(NavigationControllerTest, InPage) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); // This should generate a new entry. EXPECT_TRUE(controller.RendererDidNavigate(params, &details)); @@ -1905,7 +1905,7 @@ TEST_F(NavigationControllerTest, InPage_Replace) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url2)); + params.page_state = PageState::CreateFromURL(url2); // This should NOT generate a new entry, nor prune the list. LoadCommittedDetails details; @@ -1952,7 +1952,7 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { params.should_update_history = true; params.gesture = NavigationGestureUnknown; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); // This should NOT generate a new entry, nor prune the list. LoadCommittedDetails details; @@ -1975,7 +1975,7 @@ TEST_F(NavigationControllerTest, ClientRedirectAfterInPageNavigation) { params.should_update_history = true; params.gesture = NavigationGestureUnknown; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); // This SHOULD generate a new entry. LoadCommittedDetails details; @@ -2093,7 +2093,7 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { browser_context()); entry->SetPageID(0); entry->SetTitle(ASCIIToUTF16("Title")); - entry->SetContentState("state"); + entry->SetPageState(PageState::CreateFromEncodedData("state")); const base::Time timestamp = base::Time::Now(); entry->SetTimestamp(timestamp); entries.push_back(entry); @@ -2139,7 +2139,7 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); LoadCommittedDetails details; our_controller.RendererDidNavigate(params, &details); @@ -2172,7 +2172,7 @@ TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { browser_context()); entry->SetPageID(0); entry->SetTitle(ASCIIToUTF16("Title")); - entry->SetContentState("state"); + entry->SetPageState(PageState::CreateFromEncodedData("state")); entries.push_back(entry); scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( WebContents::Create(WebContents::CreateParams(browser_context())))); @@ -2225,7 +2225,7 @@ TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { params.should_update_history = false; params.gesture = NavigationGestureUser; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); LoadCommittedDetails details; our_controller.RendererDidNavigate(params, &details); @@ -2594,7 +2594,7 @@ TEST_F(NavigationControllerTest, SameSubframe) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(subframe)); + params.page_state = PageState::CreateFromURL(subframe); LoadCommittedDetails details; EXPECT_FALSE(controller.RendererDidNavigate(params, &details)); @@ -2664,7 +2664,7 @@ TEST_F(NavigationControllerTest, SubframeWhilePending) { params.should_update_history = false; params.gesture = NavigationGestureAuto; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url1_sub)); + params.page_state = PageState::CreateFromURL(url1_sub); LoadCommittedDetails details; // This should return false meaning that nothing was actually updated. diff --git a/content/browser/web_contents/navigation_entry_impl.cc b/content/browser/web_contents/navigation_entry_impl.cc index b904acf..23c90e9 100644 --- a/content/browser/web_contents/navigation_entry_impl.cc +++ b/content/browser/web_contents/navigation_entry_impl.cc @@ -135,12 +135,12 @@ const string16& NavigationEntryImpl::GetTitle() const { return title_; } -void NavigationEntryImpl::SetContentState(const std::string& state) { - content_state_ = state; +void NavigationEntryImpl::SetPageState(const PageState& state) { + page_state_ = state; } -const std::string& NavigationEntryImpl::GetContentState() const { - return content_state_; +const PageState& NavigationEntryImpl::GetPageState() const { + return page_state_; } void NavigationEntryImpl::SetPageID(int page_id) { diff --git a/content/browser/web_contents/navigation_entry_impl.h b/content/browser/web_contents/navigation_entry_impl.h index c956867..96d7ac9 100644 --- a/content/browser/web_contents/navigation_entry_impl.h +++ b/content/browser/web_contents/navigation_entry_impl.h @@ -11,6 +11,7 @@ #include "content/public/browser/favicon_status.h" #include "content/public/browser/global_request_id.h" #include "content/public/browser/navigation_entry.h" +#include "content/public/common/page_state.h" #include "content/public/common/ssl_status.h" namespace content { @@ -46,8 +47,8 @@ class CONTENT_EXPORT NavigationEntryImpl virtual const GURL& GetVirtualURL() const OVERRIDE; virtual void SetTitle(const string16& title) OVERRIDE; virtual const string16& GetTitle() const OVERRIDE; - virtual void SetContentState(const std::string& state) OVERRIDE; - virtual const std::string& GetContentState() const OVERRIDE; + virtual void SetPageState(const PageState& state) OVERRIDE; + virtual const PageState& GetPageState() const OVERRIDE; virtual void SetPageID(int page_id) OVERRIDE; virtual int32 GetPageID() const OVERRIDE; virtual const string16& GetTitleForDisplay( @@ -219,7 +220,7 @@ class CONTENT_EXPORT NavigationEntryImpl bool update_virtual_url_with_url_; string16 title_; FaviconStatus favicon_; - std::string content_state_; + PageState page_state_; int32 page_id_; SSLStatus ssl_; PageTransition transition_type_; diff --git a/content/browser/web_contents/navigation_entry_impl_unittest.cc b/content/browser/web_contents/navigation_entry_impl_unittest.cc index 8bc5de1..4b18aaa 100644 --- a/content/browser/web_contents/navigation_entry_impl_unittest.cc +++ b/content/browser/web_contents/navigation_entry_impl_unittest.cc @@ -142,10 +142,10 @@ TEST_F(NavigationEntryTest, NavigationEntryAccessors) { EXPECT_EQ(ASCIIToUTF16("title2"), entry2_->GetTitle()); // State - EXPECT_EQ(std::string(), entry1_->GetContentState()); - EXPECT_EQ(std::string(), entry2_->GetContentState()); - entry2_->SetContentState("state"); - EXPECT_EQ("state", entry2_->GetContentState()); + EXPECT_FALSE(entry1_->GetPageState().IsValid()); + EXPECT_FALSE(entry2_->GetPageState().IsValid()); + entry2_->SetPageState(PageState::CreateFromEncodedData("state")); + EXPECT_EQ("state", entry2_->GetPageState().ToEncodedData()); // Page ID EXPECT_EQ(-1, entry1_->GetPageID()); diff --git a/content/browser/web_contents/render_view_host_manager_unittest.cc b/content/browser/web_contents/render_view_host_manager_unittest.cc index dc6c814..0ad1f7f 100644 --- a/content/browser/web_contents/render_view_host_manager_unittest.cc +++ b/content/browser/web_contents/render_view_host_manager_unittest.cc @@ -27,7 +27,6 @@ #include "content/test/test_content_client.h" #include "content/test/test_web_contents.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/glue_serialize.h" namespace content { namespace { @@ -726,7 +725,7 @@ TEST_F(RenderViewHostManagerTest, PageDoesBackAndReload) { params.gesture = NavigationGestureAuto; params.was_within_same_page = false; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(kUrl2)); + params.page_state = PageState::CreateFromURL(kUrl2); contents()->DidNavigate(evil_rvh, params); // That should have cancelled the pending RVH, and the evil RVH should be the diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 1645bb2..4d9f4cc 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -217,7 +217,7 @@ void MakeNavigateParams(const NavigationEntryImpl& entry, } params->referrer = entry.GetReferrer(); params->transition = entry.GetTransitionType(); - params->state = entry.GetContentState(); + params->page_state = entry.GetPageState(); params->navigation_type = GetNavigationType(controller.GetBrowserContext(), entry, reload_type); params->request_time = base::Time::Now(); @@ -1984,11 +1984,11 @@ void WebContentsImpl::ViewSource() { } void WebContentsImpl::ViewFrameSource(const GURL& url, - const std::string& content_state) { + const PageState& page_state) { if (!delegate_) return; - delegate_->ViewSourceForFrame(this, url, content_state); + delegate_->ViewSourceForFrame(this, url, page_state); } int WebContentsImpl::GetMinimumZoomPercent() const { @@ -2901,7 +2901,7 @@ void WebContentsImpl::DidNavigate( void WebContentsImpl::UpdateState(RenderViewHost* rvh, int32 page_id, - const std::string& state) { + const PageState& page_state) { // Ensure that this state update comes from either the active RVH or one of // the swapped out RVHs. We don't expect to hear from any other RVHs. DCHECK(rvh == GetRenderViewHost() || render_manager_.IsOnSwappedOutList(rvh)); @@ -2918,9 +2918,9 @@ void WebContentsImpl::UpdateState(RenderViewHost* rvh, return; NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); - if (state == entry->GetContentState()) + if (page_state == entry->GetPageState()) return; // Nothing to update. - entry->SetContentState(state); + entry->SetPageState(page_state); controller_.NotifyEntryChanged(entry, entry_index); } diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 808b855..2af13f8 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -276,7 +276,7 @@ class CONTENT_EXPORT WebContentsImpl bool* enable_decrement) const OVERRIDE; virtual void ViewSource() OVERRIDE; virtual void ViewFrameSource(const GURL& url, - const std::string& content_state) OVERRIDE; + const PageState& page_state) OVERRIDE; virtual int GetMinimumZoomPercent() const OVERRIDE; virtual int GetMaximumZoomPercent() const OVERRIDE; virtual gfx::Size GetPreferredSize() const OVERRIDE; @@ -334,7 +334,7 @@ class CONTENT_EXPORT WebContentsImpl const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; virtual void UpdateState(RenderViewHost* render_view_host, int32 page_id, - const std::string& state) OVERRIDE; + const PageState& page_state) OVERRIDE; virtual void UpdateTitle(RenderViewHost* render_view_host, int32 page_id, const string16& title, diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index 1c535ac..63ae5f5 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -30,7 +30,6 @@ #include "content/test/test_content_client.h" #include "content/test/test_web_contents.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/webkit_glue.h" namespace content { namespace { @@ -1023,7 +1022,7 @@ TEST_F(WebContentsImplTest, CrossSiteNavigationCanceled) { EXPECT_TRUE(contents()->GetPendingRenderViewHost() == NULL); } -// Test that NavigationEntries have the correct content state after going +// Test that NavigationEntries have the correct page state after going // forward and back. Prevents regression for bug 1116137. TEST_F(WebContentsImplTest, NavigationEntryContentState) { TestRenderViewHost* orig_rvh = test_rvh(); @@ -1034,30 +1033,30 @@ TEST_F(WebContentsImplTest, NavigationEntryContentState) { NavigationEntry* entry = controller().GetLastCommittedEntry(); EXPECT_TRUE(entry == NULL); - // Committed entry should have content state after DidNavigate. + // Committed entry should have page state after DidNavigate. contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); entry = controller().GetLastCommittedEntry(); - EXPECT_FALSE(entry->GetContentState().empty()); + EXPECT_TRUE(entry->GetPageState().IsValid()); // Navigate to same site. const GURL url2("http://images.google.com"); controller().LoadURL(url2, Referrer(), PAGE_TRANSITION_TYPED, std::string()); entry = controller().GetLastCommittedEntry(); - EXPECT_FALSE(entry->GetContentState().empty()); + EXPECT_TRUE(entry->GetPageState().IsValid()); - // Committed entry should have content state after DidNavigate. + // Committed entry should have page state after DidNavigate. contents()->TestDidNavigate(orig_rvh, 2, url2, PAGE_TRANSITION_TYPED); entry = controller().GetLastCommittedEntry(); - EXPECT_FALSE(entry->GetContentState().empty()); + EXPECT_TRUE(entry->GetPageState().IsValid()); - // Now go back. Committed entry should still have content state. + // Now go back. Committed entry should still have page state. controller().GoBack(); contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); entry = controller().GetLastCommittedEntry(); - EXPECT_FALSE(entry->GetContentState().empty()); + EXPECT_TRUE(entry->GetPageState().IsValid()); } -// Test that NavigationEntries have the correct content state and SiteInstance +// Test that NavigationEntries have the correct page state and SiteInstance // state after opening a new window to about:blank. Prevents regression for // bugs b/1116137 and http://crbug.com/111975. TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { @@ -1069,9 +1068,9 @@ TEST_F(WebContentsImplTest, NavigationEntryContentStateNewWindow) { contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); contents()->TestDidNavigate(orig_rvh, 1, url, PAGE_TRANSITION_TYPED); - // Should have a content state here. + // Should have a page state here. NavigationEntry* entry = controller().GetLastCommittedEntry(); - EXPECT_FALSE(entry->GetContentState().empty()); + EXPECT_TRUE(entry->GetPageState().IsValid()); // The SiteInstance should be available for other navigations to use. NavigationEntryImpl* entry_impl = diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 250fe37..e13ff18 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -22,6 +22,7 @@ #include "content/public/common/file_chooser_params.h" #include "content/public/common/frame_navigate_params.h" #include "content/public/common/javascript_message_type.h" +#include "content/public/common/page_state.h" #include "content/public/common/page_zoom.h" #include "content/public/common/referrer.h" #include "content/public/common/renderer_preferences.h" @@ -162,7 +163,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::ContextMenuParams) IPC_STRUCT_TRAITS_MEMBER(page_url) IPC_STRUCT_TRAITS_MEMBER(keyword_url) IPC_STRUCT_TRAITS_MEMBER(frame_url) - IPC_STRUCT_TRAITS_MEMBER(frame_content_state) + IPC_STRUCT_TRAITS_MEMBER(frame_page_state) IPC_STRUCT_TRAITS_MEMBER(media_flags) IPC_STRUCT_TRAITS_MEMBER(selection_text) IPC_STRUCT_TRAITS_MEMBER(misspelled_word) @@ -416,7 +417,7 @@ IPC_STRUCT_BEGIN_WITH_PARENT(ViewHostMsg_FrameNavigate_Params, IPC_STRUCT_MEMBER(bool, was_fetched_via_proxy) // Serialized history item state to store in the navigation entry. - IPC_STRUCT_MEMBER(std::string, content_state) + IPC_STRUCT_MEMBER(content::PageState, page_state) // Original request's URL. IPC_STRUCT_MEMBER(GURL, original_request_url) @@ -602,7 +603,7 @@ IPC_STRUCT_BEGIN(ViewMsg_Navigate_Params) IPC_STRUCT_MEMBER(content::PageTransition, transition) // Opaque history state (received by ViewHostMsg_UpdateState). - IPC_STRUCT_MEMBER(std::string, state) + IPC_STRUCT_MEMBER(content::PageState, page_state) // Type of navigation. IPC_STRUCT_MEMBER(ViewMsg_Navigate_Type::Value, navigation_type) @@ -1490,7 +1491,7 @@ IPC_MESSAGE_ROUTED4(ViewHostMsg_MediaNotification, // page_id: unique ID that allows us to distinguish between history entries. IPC_MESSAGE_ROUTED2(ViewHostMsg_UpdateState, int32 /* page_id */, - std::string /* state */) + content::PageState /* state */) // Notifies the browser that a document has been loaded in a frame. IPC_MESSAGE_ROUTED1(ViewHostMsg_DocumentLoadedInFrame, diff --git a/content/content_common.gypi b/content/content_common.gypi index cd3e830..af62401 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -55,6 +55,9 @@ 'public/common/main_function_params.h', 'public/common/media_stream_request.cc', 'public/common/media_stream_request.h', + 'public/common/page_state.cc', + 'public/common/page_state_ios.cc', + 'public/common/page_state.h', 'public/common/page_transition_types.cc', 'public/common/page_transition_types.h', 'public/common/page_transition_types_list.h', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 4b81cba..f86f94d 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -38,6 +38,8 @@ 'public/renderer/context_menu_client.h', 'public/renderer/document_state.cc', 'public/renderer/document_state.h', + 'public/renderer/history_item_serialization.cc', + 'public/renderer/history_item_serialization.h', 'public/renderer/navigation_state.cc', 'public/renderer/navigation_state.h', 'public/renderer/password_form_conversion_utils.h', diff --git a/content/public/browser/navigation_entry.h b/content/public/browser/navigation_entry.h index e675d2f0..05f4d73 100644 --- a/content/public/browser/navigation_entry.h +++ b/content/public/browser/navigation_entry.h @@ -19,6 +19,7 @@ class GURL; namespace content { +class PageState; struct FaviconStatus; struct SSLStatus; @@ -75,6 +76,7 @@ class NavigationEntry { virtual void SetTitle(const string16& title) = 0; virtual const string16& GetTitle() const = 0; + // XXX // Content state is an opaque blob created by WebKit that represents the // state of the page. This includes form entries and scroll position for each // frame. We store it so that we can supply it back to WebKit to restore form @@ -83,8 +85,8 @@ class NavigationEntry { // WARNING: This state is saved to the file and used to restore previous // states. If the format is modified in the future, we should still be able to // deal with older versions. - virtual void SetContentState(const std::string& state) = 0; - virtual const std::string& GetContentState() const = 0; + virtual void SetPageState(const PageState& state) = 0; + virtual const PageState& GetPageState() const = 0; // Describes the current page that the tab represents. This is the ID that the // renderer generated for the page and is how we can tell new versus diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 5a3c2d3..caaee98 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -38,6 +38,7 @@ namespace content { class BrowserContext; class InterstitialPage; +class PageState; class RenderProcessHost; class RenderViewHost; class RenderWidgetHostView; @@ -389,7 +390,7 @@ class WebContents : public PageNavigator, virtual void ViewSource() = 0; virtual void ViewFrameSource(const GURL& url, - const std::string& content_state)= 0; + const PageState& page_state)= 0; // Gets the minimum/maximum zoom percent. virtual int GetMinimumZoomPercent() const = 0; diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 1e0a62c..6150861 100644 --- a/content/public/browser/web_contents_delegate.cc +++ b/content/public/browser/web_contents_delegate.cc @@ -96,7 +96,7 @@ void WebContentsDelegate::ViewSourceForTab(WebContents* source, void WebContentsDelegate::ViewSourceForFrame(WebContents* source, const GURL& frame_url, - const std::string& content_state) { + const PageState& page_state) { // Same as ViewSourceForTab, but for given subframe. GURL url = GURL(chrome::kViewSourceScheme + std::string(":") + frame_url.spec()); diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index 96198fd..8e4f794 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -34,6 +34,7 @@ class BrowserContext; class ColorChooser; class DownloadItem; class JavaScriptDialogManager; +class PageState; class RenderViewHost; class WebContents; class WebContentsImpl; @@ -240,7 +241,7 @@ class CONTENT_EXPORT WebContentsDelegate { // Opens source view for the given subframe. virtual void ViewSourceForFrame(WebContents* source, const GURL& url, - const std::string& content_state); + const PageState& page_state); // Allows delegates to handle keyboard events before sending to the renderer. // Returns true if the |event| was handled. Otherwise, if the |event| would be diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc index de32860..f2a5c8a 100644 --- a/content/public/common/common_param_traits.cc +++ b/content/public/common/common_param_traits.cc @@ -5,6 +5,7 @@ #include "content/public/common/common_param_traits.h" #include "content/public/common/content_constants.h" +#include "content/public/common/page_state.h" #include "content/public/common/referrer.h" #include "net/base/host_port_pair.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -106,6 +107,27 @@ void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { l->append(p.ToString()); } +void ParamTraits<content::PageState>::Write( + Message* m, const param_type& p) { + WriteParam(m, p.ToEncodedData()); +} + +bool ParamTraits<content::PageState>::Read( + const Message* m, PickleIterator* iter, param_type* r) { + std::string data; + if (!ReadParam(m, iter, &data)) + return false; + *r = content::PageState::CreateFromEncodedData(data); + return true; +} + +void ParamTraits<content::PageState>::Log( + const param_type& p, std::string* l) { + l->append("("); + LogParam(p.ToEncodedData(), l); + l->append(")"); +} + void ParamTraits<content::Referrer>::Write( Message* m, const param_type& p) { WriteParam(m, p.url); diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h index 8e26b8b..b8ae736 100644 --- a/content/public/common/common_param_traits.h +++ b/content/public/common/common_param_traits.h @@ -25,6 +25,7 @@ class SkBitmap; namespace content { +class PageState; struct Referrer; } @@ -59,6 +60,14 @@ struct CONTENT_EXPORT ParamTraits<net::HostPortPair> { }; template <> +struct CONTENT_EXPORT ParamTraits<content::PageState> { + typedef content::PageState param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +template <> struct CONTENT_EXPORT ParamTraits<content::Referrer> { typedef content::Referrer param_type; static void Write(Message* m, const param_type& p); diff --git a/content/public/common/context_menu_params.h b/content/public/common/context_menu_params.h index 1d5d9c6..fd455d8 100644 --- a/content/public/common/context_menu_params.h +++ b/content/public/common/context_menu_params.h @@ -11,6 +11,7 @@ #include "base/string16.h" #include "googleurl/src/gurl.h" #include "content/common/content_export.h" +#include "content/public/common/page_state.h" #include "content/public/common/ssl_status.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" @@ -87,9 +88,8 @@ struct CONTENT_EXPORT ContextMenuParams { // This is the ID of the subframe that the context menu was invoked on. int64 frame_id; - // This is the history item state of the subframe that the context menu was - // invoked on. - std::string frame_content_state; + // This is the page state of the frame on which the context menu was invoked. + PageState frame_page_state; // These are the parameters for the media element that the context menu // was invoked on. diff --git a/content/public/common/page_state.cc b/content/public/common/page_state.cc new file mode 100644 index 0000000..7f12907 --- /dev/null +++ b/content/public/common/page_state.cc @@ -0,0 +1,87 @@ +// Copyright (c) 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 "content/public/common/page_state.h" + +#include "base/logging.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" +#include "webkit/base/file_path_string_conversions.h" +#include "webkit/glue/glue_serialize_deprecated.h" + +namespace content { + +// static +PageState PageState::CreateFromEncodedData(const std::string& data) { + return PageState(data); +} + +// static +PageState PageState::CreateFromURL(const GURL& url) { + return PageState(webkit_glue::CreateHistoryStateForURL(url)); +} + +// static +PageState PageState::CreateForTesting( + const GURL& url, + bool body_contains_password_data, + const char* optional_body_data, + const base::FilePath* optional_body_file_path) { + WebKit::WebHistoryItem history_item; + history_item.initialize(); + history_item.setURLString( + WebKit::WebString::fromUTF8(url.possibly_invalid_spec())); + if (optional_body_data || optional_body_file_path) { + WebKit::WebHTTPBody http_body; + http_body.initialize(); + http_body.setContainsPasswordData(body_contains_password_data); + if (optional_body_data) { + http_body.appendData( + WebKit::WebData(optional_body_data, strlen(optional_body_data))); + } + if (optional_body_file_path) { + http_body.appendFile( + webkit_base::FilePathToWebString(*optional_body_file_path)); + } + history_item.setHTTPBody(http_body); + } + return PageState(webkit_glue::HistoryItemToString(history_item)); +} + +PageState::PageState() { +} + +bool PageState::IsValid() const { + return !data_.empty(); +} + +bool PageState::Equals(const PageState& other) const { + return data_ == other.data_; +} + +const std::string& PageState::ToEncodedData() const { + return data_; +} + +std::vector<base::FilePath> PageState::GetReferencedFiles() const { + return webkit_glue::FilePathsFromHistoryState(data_); +} + +PageState PageState::RemovePasswordData() const { + return PageState(webkit_glue::RemovePasswordDataFromHistoryState(data_)); +} + +PageState PageState::RemoveScrollOffset() const { + return PageState(webkit_glue::RemoveScrollOffsetFromHistoryState(data_)); +} + +PageState::PageState(const std::string& data) + : data_(data) { + // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass + // bogus encoded data to CreateFromEncodedData. + //DCHECK(IsValid()); +} + +} // namespace content diff --git a/content/public/common/page_state.h b/content/public/common/page_state.h new file mode 100644 index 0000000..b4484b7 --- /dev/null +++ b/content/public/common/page_state.h @@ -0,0 +1,66 @@ +// Copyright (c) 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. + +#ifndef CONTENT_PUBLIC_COMMON_PAGE_STATE_H_ +#define CONTENT_PUBLIC_COMMON_PAGE_STATE_H_ + +#include <string> +#include <vector> + +#include "content/common/content_export.h" + +class GURL; + +namespace base { +class FilePath; +} + +namespace content { + +// The PageState class represents the information needed by the rendering +// engine to reconstruct a web page (and its tree of frames), including for +// example the URLs of the documents and the values of any form fields. This +// information is used when navigating back & forward through session history. +// +// The browser process only sees the encoded form of the data, which is +// designed as an archival format. The renderer process can decode the data +// using methods found in public/renderer/history_item_serialization.h. +class CONTENT_EXPORT PageState { + public: + static PageState CreateFromEncodedData(const std::string& data); + static PageState CreateFromURL(const GURL& url); + + static PageState CreateForTesting( + const GURL& url, + bool body_contains_password_data, + const char* optional_body_data, + const base::FilePath* optional_body_file_path); + + PageState(); + + bool IsValid() const; + bool Equals(const PageState& page_state) const; + const std::string& ToEncodedData() const; + + std::vector<base::FilePath> GetReferencedFiles() const; + PageState RemovePasswordData() const; + PageState RemoveScrollOffset() const; + + private: + PageState(const std::string& data); + + std::string data_; +}; + +// Support DCHECK_EQ(a, b), etc. +inline bool operator==(const PageState& a, const PageState& b) { + return a.Equals(b); +} +inline bool operator!=(const PageState& a, const PageState& b) { + return !(a == b); +} + +} // namespace content + +#endif // CONTENT_PUBLIC_COMMON_PAGE_STATE_H_ diff --git a/content/public/common/page_state_ios.cc b/content/public/common/page_state_ios.cc new file mode 100644 index 0000000..c52eced --- /dev/null +++ b/content/public/common/page_state_ios.cc @@ -0,0 +1,70 @@ +// Copyright (c) 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 "content/public/common/page_state.h" + +#include "base/files/file_path.h" +#include "base/logging.h" + +namespace content { + +// static +PageState PageState::CreateFromEncodedData(const std::string& data) { + return PageState(data); +} + +// static +PageState PageState::CreateFromURL(const GURL& url) { + NOTIMPLEMENTED(); + return PageState(); +} + +// static +PageState PageState::CreateForTesting( + const GURL& url, + bool body_contains_password_data, + const char* optional_body_data, + const base::FilePath* optional_body_file_path) { + NOTIMPLEMENTED(); + return PageState(); +} + +PageState::PageState() { +} + +bool PageState::IsValid() const { + return !data_.empty(); +} + +bool PageState::Equals(const PageState& other) const { + return data_ == other.data_; +} + +const std::string& PageState::ToEncodedData() const { + return data_; +} + +std::vector<base::FilePath> PageState::GetReferencedFiles() const { + NOTIMPLEMENTED(); + return std::vector<base::FilePath>(); +} + +PageState PageState::RemovePasswordData() const { + NOTIMPLEMENTED(); + return *this; +} + +PageState PageState::RemoveScrollOffset() const { + NOTIMPLEMENTED(); + return *this; +} + +PageState::PageState(const std::string& data) + : data_(data) { + // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass + // bogus encoded data to CreateFromEncodedData. + //DCHECK(IsValid()); +} + +} // namespace content diff --git a/content/public/renderer/history_item_serialization.cc b/content/public/renderer/history_item_serialization.cc new file mode 100644 index 0000000..d8fcdc9 --- /dev/null +++ b/content/public/renderer/history_item_serialization.cc @@ -0,0 +1,21 @@ +// Copyright (c) 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 "content/public/renderer/history_item_serialization.h" + +#include "content/public/common/page_state.h" +#include "webkit/glue/glue_serialize_deprecated.h" + +namespace content { + +PageState HistoryItemToPageState(const WebKit::WebHistoryItem& item) { + return PageState::CreateFromEncodedData( + webkit_glue::HistoryItemToString(item)); +} + +WebKit::WebHistoryItem PageStateToHistoryItem(const PageState& state) { + return webkit_glue::HistoryItemFromString(state.ToEncodedData()); +} + +} // namespace content diff --git a/content/public/renderer/history_item_serialization.h b/content/public/renderer/history_item_serialization.h new file mode 100644 index 0000000..44eb1e1 --- /dev/null +++ b/content/public/renderer/history_item_serialization.h @@ -0,0 +1,26 @@ +// Copyright (c) 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. + +#ifndef CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ +#define CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ + +#include <string> + +#include "content/common/content_export.h" + +namespace WebKit { +class WebHistoryItem; +} + +namespace content { +class PageState; + +CONTENT_EXPORT PageState HistoryItemToPageState( + const WebKit::WebHistoryItem& item); +CONTENT_EXPORT WebKit::WebHistoryItem PageStateToHistoryItem( + const PageState& state); + +} // namespace content + +#endif // CONTENT_RENDERER_HISTORY_ITEM_SERIALIZATION_H_ diff --git a/content/public/test/render_view_fake_resources_test.cc b/content/public/test/render_view_fake_resources_test.cc index eda8ef9..71cf1be 100644 --- a/content/public/test/render_view_fake_resources_test.cc +++ b/content/public/test/render_view_fake_resources_test.cc @@ -13,6 +13,7 @@ #include "content/common/resource_messages.h" #include "content/common/view_messages.h" #include "content/public/common/resource_response.h" +#include "content/public/renderer/history_item_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_webkitplatformsupport_impl.h" @@ -28,7 +29,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "webkit/dom_storage/dom_storage_types.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webkit_glue.h" namespace content { @@ -213,7 +213,7 @@ void RenderViewFakeResourcesTest::GoToOffset( impl->historyForwardListCount() + 1); params.url = GURL(history_item.urlString()); params.transition = PAGE_TRANSITION_FORWARD_BACK; - params.state = webkit_glue::HistoryItemToString(history_item); + params.page_state = HistoryItemToPageState(history_item); params.navigation_type = ViewMsg_Navigate_Type::NORMAL; params.request_time = base::Time::Now(); channel_->Send(new ViewMsg_Navigate(impl->routing_id(), params)); diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc index 410ee6e..6c3dd33 100644 --- a/content/public/test/render_view_test.cc +++ b/content/public/test/render_view_test.cc @@ -9,6 +9,7 @@ #include "content/common/view_messages.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/common/renderer_preferences.h" +#include "content/public/renderer/history_item_serialization.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_main_platform_delegate.h" @@ -25,7 +26,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/dom_storage/dom_storage_types.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webkit_glue.h" using WebKit::WebFrame; @@ -358,7 +358,7 @@ void RenderViewTest::GoToOffset(int offset, navigate_params.current_history_list_offset = impl->history_list_offset(); navigate_params.pending_history_list_offset = pending_offset; navigate_params.page_id = impl->GetPageId() + offset; - navigate_params.state = webkit_glue::HistoryItemToString(history_item); + navigate_params.page_state = HistoryItemToPageState(history_item); navigate_params.request_time = base::Time::Now(); ViewMsg_Navigate navigate_message(impl->GetRoutingID(), navigate_params); diff --git a/content/renderer/context_menu_params_builder.cc b/content/renderer/context_menu_params_builder.cc index 8087a33..36c46f9 100644 --- a/content/renderer/context_menu_params_builder.cc +++ b/content/renderer/context_menu_params_builder.cc @@ -7,9 +7,9 @@ #include "base/logging.h" #include "content/common/ssl_status_serialization.h" #include "content/public/common/context_menu_params.h" +#include "content/public/renderer/history_item_serialization.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" -#include "webkit/glue/glue_serialize.h" namespace content { @@ -50,10 +50,8 @@ ContextMenuParams ContextMenuParamsBuilder::Build( for (size_t i = 0; i < data.customItems.size(); ++i) params.custom_items.push_back(WebMenuItem(data.customItems[i])); - if (!data.frameHistoryItem.isNull()) { - params.frame_content_state = - webkit_glue::HistoryItemToString(data.frameHistoryItem); - } + if (!data.frameHistoryItem.isNull()) + params.frame_page_state = HistoryItemToPageState(data.frameHistoryItem); if (!params.link_url.is_empty()) { WebKit::WebNode selectedNode = data.node; diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc index 405e7e1..652b1ea 100644 --- a/content/renderer/render_view_browsertest.cc +++ b/content/renderer/render_view_browsertest.cc @@ -13,6 +13,7 @@ #include "content/public/common/bindings_policy.h" #include "content/public/common/url_utils.h" #include "content/public/renderer/document_state.h" +#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" #include "content/public/test/render_view_test.h" #include "content/renderer/render_view_impl.h" @@ -31,7 +32,6 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/range/range.h" #include "ui/gfx/codec/jpeg_codec.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/web_io_operators.h" #if defined(OS_LINUX) && !defined(USE_AURA) @@ -301,9 +301,9 @@ TEST_F(RenderViewImplTest, OnNavigationHttpPost) { EXPECT_TRUE(host_nav_params.a.is_post); // Check post data sent to browser matches - EXPECT_FALSE(host_nav_params.a.content_state.empty()); - const WebKit::WebHistoryItem item = webkit_glue::HistoryItemFromString( - host_nav_params.a.content_state); + EXPECT_TRUE(host_nav_params.a.page_state.IsValid()); + const WebKit::WebHistoryItem item = PageStateToHistoryItem( + host_nav_params.a.page_state); WebKit::WebHTTPBody body = item.httpBody(); WebKit::WebHTTPBody::Element element; bool successful = body.elementAt(0, element); @@ -487,7 +487,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; - std::string state_A; + PageState state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); render_thread_->sink().ClearMessages(); @@ -500,7 +500,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { params_A.current_history_list_offset = 1; params_A.pending_history_list_offset = 0; params_A.page_id = 1; - params_A.state = state_A; + params_A.page_state = state_A; view()->OnNavigate(params_A); ProcessPendingMessages(); @@ -519,7 +519,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { render_thread_->sink().ClearMessages(); // It is possible to get a reload request at this point, containing the - // params.state of the initial page (e.g., if the new page fails the + // params.page_state of the initial page (e.g., if the new page fails the // provisional load in the renderer process, after we unload the old page). // Ensure the old page gets reloaded, not swappedout://. ViewMsg_Navigate_Params nav_params; @@ -530,7 +530,7 @@ TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { nav_params.current_history_list_offset = 0; nav_params.pending_history_list_offset = 0; nav_params.page_id = 1; - nav_params.state = state_A; + nav_params.page_state = state_A; view()->OnNavigate(nav_params); ProcessPendingMessages(); @@ -563,7 +563,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; - std::string state_A; + PageState state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); render_thread_->sink().ClearMessages(); @@ -577,7 +577,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_B); int page_id_B; - std::string state_B; + PageState state_B; ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); EXPECT_EQ(2, page_id_B); EXPECT_NE(state_A, state_B); @@ -592,7 +592,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_C); int page_id_C; - std::string state_C; + PageState state_C; ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); EXPECT_EQ(3, page_id_C); EXPECT_NE(state_B, state_C); @@ -606,7 +606,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { params_C.current_history_list_offset = 3; params_C.pending_history_list_offset = 2; params_C.page_id = 3; - params_C.state = state_C; + params_C.page_state = state_C; view()->OnNavigate(params_C); ProcessPendingMessages(); render_thread_->sink().ClearMessages(); @@ -623,7 +623,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { params_B.current_history_list_offset = 2; params_B.pending_history_list_offset = 1; params_B.page_id = 2; - params_B.state = state_B; + params_B.page_state = state_B; view()->OnNavigate(params_B); // Back to page A (page_id 1) and commit. @@ -634,7 +634,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { params_B.current_history_list_offset = 2; params_B.pending_history_list_offset = 0; params.page_id = 1; - params.state = state_A; + params.page_state = state_A; view()->OnNavigate(params); ProcessPendingMessages(); @@ -644,7 +644,7 @@ TEST_F(RenderViewImplTest, DISABLED_LastCommittedUpdateState) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg); int page_id; - std::string state; + PageState state; ViewHostMsg_UpdateState::Read(msg, &page_id, &state); EXPECT_EQ(page_id_C, page_id); EXPECT_NE(state_A, state); @@ -674,7 +674,7 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; - std::string state_A; + PageState state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); render_thread_->sink().ClearMessages(); @@ -687,7 +687,7 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { params_A.current_history_list_offset = 1; params_A.pending_history_list_offset = 0; params_A.page_id = 1; - params_A.state = state_A; + params_A.page_state = state_A; view()->OnNavigate(params_A); ProcessPendingMessages(); @@ -705,7 +705,7 @@ TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { params_B.current_history_list_offset = 0; params_B.pending_history_list_offset = 1; params_B.page_id = 2; - params_B.state = state_A; // Doesn't matter, just has to be present. + params_B.page_state = state_A; // Doesn't matter, just has to be present. view()->OnNavigate(params_B); // State should be unchanged. @@ -739,7 +739,7 @@ TEST_F(RenderViewImplTest, DontIgnoreBackAfterNavEntryLimit) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_A); int page_id_A; - std::string state_A; + PageState state_A; ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); EXPECT_EQ(1, page_id_A); render_thread_->sink().ClearMessages(); @@ -756,7 +756,7 @@ TEST_F(RenderViewImplTest, DontIgnoreBackAfterNavEntryLimit) { ViewHostMsg_UpdateState::ID); ASSERT_TRUE(msg_B); int page_id_B; - std::string state_B; + PageState state_B; ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); EXPECT_EQ(2, page_id_B); render_thread_->sink().ClearMessages(); @@ -771,7 +771,7 @@ TEST_F(RenderViewImplTest, DontIgnoreBackAfterNavEntryLimit) { params_B.current_history_list_offset = 1; params_B.pending_history_list_offset = 0; params_B.page_id = 2; - params_B.state = state_B; + params_B.page_state = state_B; view()->OnNavigate(params_B); ProcessPendingMessages(); diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 7f2172b..27dda96 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -59,6 +59,7 @@ #include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/context_menu_client.h" #include "content/public/renderer/document_state.h" +#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/navigation_state.h" #include "content/public/renderer/password_form_conversion_utils.h" #include "content/public/renderer/render_view_observer.h" @@ -198,7 +199,6 @@ #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/base/file_path_string_conversions.h" #include "webkit/dom_storage/dom_storage_types.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/weburlresponse_extradata_impl.h" @@ -1227,10 +1227,10 @@ void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) { frame->reloadWithOverrideURL(params.url, true); else frame->reload(ignore_cache); - } else if (!params.state.empty()) { + } else if (params.page_state.IsValid()) { // We must know the page ID of the page we are navigating back to. DCHECK_NE(params.page_id, -1); - WebHistoryItem item = webkit_glue::HistoryItemFromString(params.state); + WebHistoryItem item = PageStateToHistoryItem(params.page_state); if (!item.isNull()) { // Ensure we didn't save the swapped out URL in UpdateState, since the // browser should never be telling us to navigate to swappedout://. @@ -1321,7 +1321,7 @@ bool RenderViewImpl::IsBackForwardToStaleEntry( // Make sure this isn't a back/forward to an entry we have already cropped // or replaced from our history, before the browser knew about it. If so, // a new navigation has committed in the mean time, and we can ignore this. - bool is_back_forward = !is_reload && !params.state.empty(); + bool is_back_forward = !is_reload && params.page_state.IsValid(); // Note: if the history_list_length_ is 0 for a back/forward, we must be // restoring from a previous session. We'll update our state in OnNavigate. @@ -1682,13 +1682,12 @@ void RenderViewImpl::UpdateURL(WebFrame* frame) { // Make navigation state a part of the FrameNavigate message so that commited // entry had it at all times. - const WebHistoryItem& item = frame->currentHistoryItem(); - if (!item.isNull()) { - params.content_state = webkit_glue::HistoryItemToString(item); - } else { - params.content_state = - webkit_glue::CreateHistoryStateForURL(GURL(request.url())); + WebHistoryItem item = frame->currentHistoryItem(); + if (item.isNull()) { + item.initialize(); + item.setURLString(request.url().spec().utf16()); } + params.page_state = HistoryItemToPageState(item); if (!frame->parent()) { // Top-level navigation. @@ -1853,7 +1852,7 @@ void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) { return; Send(new ViewHostMsg_UpdateState( - routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); + routing_id_, page_id_, HistoryItemToPageState(item))); } void RenderViewImpl::OpenURL(WebFrame* frame, @@ -3300,7 +3299,7 @@ void RenderViewImpl::PopulateDocumentStateFromPending( if (IsReload(params)) document_state->set_load_type(DocumentState::RELOAD); - else if (!params.state.empty()) + else if (params.page_state.IsValid()) document_state->set_load_type(DocumentState::HISTORY_LOAD); else document_state->set_load_type(DocumentState::NORMAL_LOAD); diff --git a/content/shell/common/shell_messages.h b/content/shell/common/shell_messages.h index 37d60e98..df490b3 100644 --- a/content/shell/common/shell_messages.h +++ b/content/shell/common/shell_messages.h @@ -7,6 +7,7 @@ #include <vector> #include "content/public/common/common_param_traits.h" +#include "content/public/common/page_state.h" #include "content/shell/common/shell_test_configuration.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" @@ -51,7 +52,7 @@ IPC_MESSAGE_ROUTED0(ShellViewMsg_NotifyDone) IPC_MESSAGE_ROUTED3( ShellViewMsg_SessionHistory, std::vector<int> /* routing_ids */, - std::vector<std::vector<std::string> > /* session_histories */, + std::vector<std::vector<content::PageState> > /* session_histories */, std::vector<unsigned> /* current_entry_indexes */) // Send a text dump of the WebContents to the render host. diff --git a/content/shell/renderer/webkit_test_runner.cc b/content/shell/renderer/webkit_test_runner.cc index 866b096..376f109 100644 --- a/content/shell/renderer/webkit_test_runner.cc +++ b/content/shell/renderer/webkit_test_runner.cc @@ -18,6 +18,7 @@ #include "base/strings/sys_string_conversions.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "content/public/renderer/history_item_serialization.h" #include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view_visitor.h" #include "content/public/test/layouttest_support.h" @@ -56,7 +57,6 @@ #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h" #include "ui/gfx/rect.h" #include "webkit/base/file_path_string_conversions.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" #include "webkit/mocks/test_media_stream_client.h" @@ -523,7 +523,7 @@ void WebKitTestRunner::captureHistoryForWindow( WebVector<WebHistoryItem> result(num_entries); for (size_t entry = 0; entry < num_entries; ++entry) { result[entry] = - webkit_glue::HistoryItemFromString(session_histories_[pos][entry]); + PageStateToHistoryItem(session_histories_[pos][entry]); } history->swap(result); } @@ -692,7 +692,7 @@ void WebKitTestRunner::OnSetTestConfiguration( void WebKitTestRunner::OnSessionHistory( const std::vector<int>& routing_ids, - const std::vector<std::vector<std::string> >& session_histories, + const std::vector<std::vector<PageState> >& session_histories, const std::vector<unsigned>& current_entry_indexes) { routing_ids_ = routing_ids; session_histories_ = session_histories; diff --git a/content/shell/renderer/webkit_test_runner.h b/content/shell/renderer/webkit_test_runner.h index f3ee030..216e1e8 100644 --- a/content/shell/renderer/webkit_test_runner.h +++ b/content/shell/renderer/webkit_test_runner.h @@ -9,6 +9,7 @@ #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" +#include "content/public/common/page_state.h" #include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_observer_tracker.h" #include "content/shell/common/shell_test_configuration.h" @@ -114,7 +115,7 @@ class WebKitTestRunner : public RenderViewObserver, void OnSetTestConfiguration(const ShellTestConfiguration& params); void OnSessionHistory( const std::vector<int>& routing_ids, - const std::vector<std::vector<std::string> >& session_histories, + const std::vector<std::vector<PageState> >& session_histories, const std::vector<unsigned>& current_entry_indexes); void OnReset(); void OnNotifyDone(); @@ -132,7 +133,7 @@ class WebKitTestRunner : public RenderViewObserver, ShellTestConfiguration test_config_; std::vector<int> routing_ids_; - std::vector<std::vector<std::string> > session_histories_; + std::vector<std::vector<PageState> > session_histories_; std::vector<unsigned> current_entry_indexes_; bool is_main_window_; diff --git a/content/shell/webkit_test_controller.cc b/content/shell/webkit_test_controller.cc index 7239ed1..e96e2c0 100644 --- a/content/shell/webkit_test_controller.cc +++ b/content/shell/webkit_test_controller.cc @@ -29,7 +29,6 @@ #include "content/shell/shell.h" #include "content/shell/shell_browser_context.h" #include "content/shell/shell_content_browser_client.h" -#include "webkit/glue/glue_serialize.h" #include "webkit/support/webkit_support_gfx.h" namespace content { @@ -565,7 +564,7 @@ void WebKitTestController::OnLoadURLForFrame(const GURL& url, void WebKitTestController::OnCaptureSessionHistory() { std::vector<int> routing_ids; - std::vector<std::vector<std::string> > session_histories; + std::vector<std::vector<PageState> > session_histories; std::vector<unsigned> current_entry_indexes; RenderViewHost* render_view_host = @@ -587,13 +586,13 @@ void WebKitTestController::OnCaptureSessionHistory() { routing_ids.push_back(web_contents->GetRenderViewHost()->GetRoutingID()); current_entry_indexes.push_back( web_contents->GetController().GetCurrentEntryIndex()); - std::vector<std::string> history; + std::vector<PageState> history; for (int entry = 0; entry < web_contents->GetController().GetEntryCount(); ++entry) { - std::string state = web_contents->GetController().GetEntryAtIndex(entry) - ->GetContentState(); - if (state.empty()) { - state = webkit_glue::CreateHistoryStateForURL( + PageState state = web_contents->GetController().GetEntryAtIndex(entry)-> + GetPageState(); + if (!state.IsValid()) { + state = PageState::CreateFromURL( web_contents->GetController().GetEntryAtIndex(entry)->GetURL()); } history.push_back(state); diff --git a/content/test/test_web_contents.cc b/content/test/test_web_contents.cc index e46182b..bdcc948 100644 --- a/content/test/test_web_contents.cc +++ b/content/test/test_web_contents.cc @@ -15,10 +15,10 @@ #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" +#include "content/public/common/page_state.h" #include "content/public/common/page_transition_types.h" #include "content/public/common/password_form.h" #include "content/public/test/mock_render_process_host.h" -#include "webkit/glue/glue_serialize.h" namespace content { @@ -83,7 +83,7 @@ void TestWebContents::TestDidNavigateWithReferrer( params.gesture = NavigationGestureUser; params.was_within_same_page = false; params.is_post = false; - params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); + params.page_state = PageState::CreateFromURL(url); DidNavigate(render_view_host, params); } diff --git a/webkit/glue/glue_serialize.cc b/webkit/glue/glue_serialize_deprecated.cc index 1b5edbd..9dbbcc8 100644 --- a/webkit/glue/glue_serialize.cc +++ b/webkit/glue/glue_serialize_deprecated.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/glue/glue_serialize.h" +#include "webkit/glue/glue_serialize_deprecated.h" #include <string> diff --git a/webkit/glue/glue_serialize.h b/webkit/glue/glue_serialize_deprecated.h index 348b201..348b201 100644 --- a/webkit/glue/glue_serialize.h +++ b/webkit/glue/glue_serialize_deprecated.h diff --git a/webkit/glue/glue_serialize_unittest.cc b/webkit/glue/glue_serialize_unittest.cc index 0f84436..3f0dd37 100644 --- a/webkit/glue/glue_serialize_unittest.cc +++ b/webkit/glue/glue_serialize_unittest.cc @@ -12,7 +12,7 @@ #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" #include "ui/gfx/screen.h" #include "webkit/base/file_path_string_conversions.h" -#include "webkit/glue/glue_serialize.h" +#include "webkit/glue/glue_serialize_deprecated.h" #include "webkit/glue/web_io_operators.h" using WebKit::WebData; diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index b05bf75..d49e499 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -200,8 +200,8 @@ 'fling_animator_impl_android.h', 'ftp_directory_listing_response_delegate.cc', 'ftp_directory_listing_response_delegate.h', - 'glue_serialize.cc', - 'glue_serialize.h', + 'glue_serialize_deprecated.cc', + 'glue_serialize_deprecated.h', 'image_decoder.cc', 'image_decoder.h', 'network_list_observer.h', |