Chromium Code Reviews| Index: content/public/common/page_state.cc |
| diff --git a/content/public/common/page_state.cc b/content/public/common/page_state.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7f12907c81f438229e199408b8f1ffaa180493ab |
| --- /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( |
|
Tom Sepez
2013/05/24 17:46:49
Can this move to the _unittest file? Maybe as a te
|
| + 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 |