| Index: content/public/renderer/history_item_serialization.cc
|
| diff --git a/content/public/renderer/history_item_serialization.cc b/content/public/renderer/history_item_serialization.cc
|
| index d8fcdc9eff80b0d7d736922fe3f2195808024414..57237f571757dfa8965fabb4e37ec9519245ca9f 100644
|
| --- a/content/public/renderer/history_item_serialization.cc
|
| +++ b/content/public/renderer/history_item_serialization.cc
|
| @@ -4,18 +4,222 @@
|
|
|
| #include "content/public/renderer/history_item_serialization.h"
|
|
|
| +#include "content/common/page_state_serialization.h"
|
| #include "content/public/common/page_state.h"
|
| -#include "webkit/glue/glue_serialize_deprecated.h"
|
| +#include "third_party/WebKit/public/platform/WebHTTPBody.h"
|
| +#include "third_party/WebKit/public/platform/WebPoint.h"
|
| +#include "third_party/WebKit/public/platform/WebString.h"
|
| +#include "third_party/WebKit/public/platform/WebVector.h"
|
| +#include "third_party/WebKit/public/web/WebHistoryItem.h"
|
| +#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
|
| +#include "webkit/base/file_path_string_conversions.h"
|
| +
|
| +using WebKit::WebHTTPBody;
|
| +using WebKit::WebHistoryItem;
|
| +using WebKit::WebSerializedScriptValue;
|
| +using WebKit::WebString;
|
| +using WebKit::WebVector;
|
|
|
| namespace content {
|
| +namespace {
|
| +
|
| +void ToFilePathVector(const WebVector<WebString>& input,
|
| + std::vector<base::FilePath>* output) {
|
| + output->reserve(input.size());
|
| + for (size_t i = 0; i < input.size(); ++i)
|
| + output->push_back(webkit_base::WebStringToFilePath(input[i]));
|
| +}
|
| +
|
| +void ToNullableString16Vector(const WebVector<WebString>& input,
|
| + std::vector<NullableString16>* output) {
|
| + output->reserve(input.size());
|
| + for (size_t i = 0; i < input.size(); ++i)
|
| + output->push_back(input[i]);
|
| +}
|
| +
|
| +void ToExplodedHttpBodyElement(const WebHTTPBody::Element& input,
|
| + ExplodedHttpBodyElement* output) {
|
| + switch (input.type) {
|
| + case WebHTTPBody::Element::TypeData:
|
| + output->data.assign(input.data.data(), input.data.size());
|
| + break;
|
| + case WebHTTPBody::Element::TypeFile:
|
| + output->file_path = webkit_base::WebStringToFilePath(input.filePath);
|
| + output->file_start = input.fileStart;
|
| + output->file_length = input.fileLength;
|
| + output->file_modification_time = input.modificationTime;
|
| + break;
|
| + case WebHTTPBody::Element::TypeURL:
|
| + output->url = input.url;
|
| + output->file_start = input.fileStart;
|
| + output->file_length = input.fileLength;
|
| + output->file_modification_time = input.modificationTime;
|
| + break;
|
| + case WebHTTPBody::Element::TypeBlob:
|
| + output->url = input.url;
|
| + break;
|
| + }
|
| +}
|
| +
|
| +void AppendHTTPBodyElement(const ExplodedHttpBodyElement& element,
|
| + WebHTTPBody* http_body) {
|
| + switch (element.type) {
|
| + case WebHTTPBody::Element::TypeData:
|
| + http_body->appendData(element.data);
|
| + break;
|
| + case WebHTTPBody::Element::TypeFile:
|
| + http_body->appendFileRange(
|
| + webkit_base::FilePathToWebString(element.file_path),
|
| + element.file_start,
|
| + element.file_length,
|
| + element.file_modification_time);
|
| + break;
|
| + case WebHTTPBody::Element::TypeURL:
|
| + http_body->appendURLRange(
|
| + element.url,
|
| + element.file_start,
|
| + element.file_length,
|
| + element.file_modification_time);
|
| + break;
|
| + case WebHTTPBody::Element::TypeBlob:
|
| + http_body->appendBlob(element.url);
|
| + break;
|
| + }
|
| +}
|
| +
|
| +bool RecursivelyGenerateFrameState(const WebHistoryItem& item,
|
| + ExplodedFrameState* exploded_frame_state) {
|
| + exploded_frame_state->url_string = item.urlString();
|
| + exploded_frame_state->original_url_string = item.originalURLString();
|
| + exploded_frame_state->referrer = item.referrer();
|
| + exploded_frame_state->target = item.target();
|
| + exploded_frame_state->parent = item.parent();
|
| + exploded_frame_state->title = item.title();
|
| + exploded_frame_state->alternate_title = item.alternateTitle();
|
| + if (!item.stateObject().isNull())
|
| + exploded_frame_state->state_object = item.stateObject().toString();
|
| + exploded_frame_state->scroll_offset = item.scrollOffset();
|
| + exploded_frame_state->item_sequence_number = item.itemSequenceNumber();
|
| + exploded_frame_state->document_sequence_number =
|
| + item.documentSequenceNumber();
|
| + exploded_frame_state->visit_count = item.visitCount();
|
| + exploded_frame_state->visited_time = item.lastVisitedTime();
|
| + exploded_frame_state->page_scale_factor = item.pageScaleFactor();
|
| + exploded_frame_state->is_target_item = item.isTargetItem();
|
| + ToNullableString16Vector(item.documentState(),
|
| + &exploded_frame_state->document_state);
|
| +
|
| + exploded_frame_state->http_body.http_content_type = item.httpContentType();
|
| + const WebHTTPBody& http_body = item.httpBody();
|
| + if (!(exploded_frame_state->http_body.is_null = http_body.isNull())) {
|
| + exploded_frame_state->http_body.identifier = http_body.identifier();
|
| + exploded_frame_state->http_body.elements.resize(http_body.elementCount());
|
| + for (size_t i = 0; i < http_body.elementCount(); ++i) {
|
| + WebHTTPBody::Element element;
|
| + http_body.elementAt(i, element);
|
| + ToExplodedHttpBodyElement(element,
|
| + &exploded_frame_state->http_body.elements[i]);
|
| + }
|
| + exploded_frame_state->http_body.contains_passwords =
|
| + http_body.containsPasswordData();
|
| + }
|
| +
|
| + const WebVector<WebHistoryItem>& children = item.children();
|
| + exploded_frame_state->children.resize(children.size());
|
| + for (size_t i = 0; i < children.size(); ++i) {
|
| + if (!RecursivelyGenerateFrameState(children[i],
|
| + &exploded_frame_state->children[i]))
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool RecursivelyGenerateHistoryItem(
|
| + const ExplodedFrameState& exploded_frame_state,
|
| + WebHistoryItem* item) {
|
| + item->setURLString(exploded_frame_state.url_string);
|
| + item->setOriginalURLString(exploded_frame_state.original_url_string);
|
| + item->setReferrer(exploded_frame_state.referrer);
|
| + item->setTarget(exploded_frame_state.target);
|
| + item->setParent(exploded_frame_state.parent);
|
| + item->setTitle(exploded_frame_state.title);
|
| + item->setAlternateTitle(exploded_frame_state.alternate_title);
|
| + if (!exploded_frame_state.state_object.is_null()) {
|
| + item->setStateObject(
|
| + WebSerializedScriptValue::fromString(
|
| + exploded_frame_state.state_object));
|
| + }
|
| + item->setDocumentState(exploded_frame_state.document_state);
|
| + item->setScrollOffset(exploded_frame_state.scroll_offset);
|
| + item->setVisitCount(exploded_frame_state.visit_count);
|
| + item->setLastVisitedTime(exploded_frame_state.visited_time);
|
| + item->setPageScaleFactor(exploded_frame_state.page_scale_factor);
|
| + item->setIsTargetItem(exploded_frame_state.is_target_item);
|
| +
|
| + // These values are generated at WebHistoryItem construction time, and we
|
| + // only want to override those new values with old values if the old values
|
| + // are defined. A value of 0 means undefined in this context.
|
| + if (exploded_frame_state.item_sequence_number)
|
| + item->setItemSequenceNumber(exploded_frame_state.item_sequence_number);
|
| + if (exploded_frame_state.document_sequence_number) {
|
| + item->setDocumentSequenceNumber(
|
| + exploded_frame_state.document_sequence_number);
|
| + }
|
| +
|
| + item->setHTTPContentType(exploded_frame_state.http_body.http_content_type);
|
| + if (!exploded_frame_state.http_body.is_null) {
|
| + WebHTTPBody http_body;
|
| + http_body.initialize();
|
| + http_body.setIdentifier(exploded_frame_state.http_body.identifier);
|
| + for (size_t i = 0; i < exploded_frame_state.http_body.elements.size();
|
| + ++i) {
|
| + AppendHTTPBodyElement(exploded_frame_state.http_body.elements[i],
|
| + &http_body);
|
| + }
|
| + item->setHTTPBody(http_body);
|
| + }
|
|
|
| -PageState HistoryItemToPageState(const WebKit::WebHistoryItem& item) {
|
| - return PageState::CreateFromEncodedData(
|
| - webkit_glue::HistoryItemToString(item));
|
| + for (size_t i = 0; i < exploded_frame_state.children.size(); ++i) {
|
| + WebHistoryItem child_item;
|
| + child_item.initialize();
|
| + if (!RecursivelyGenerateHistoryItem(exploded_frame_state.children[i],
|
| + &child_item))
|
| + return false;
|
| + item->appendToChildren(child_item);
|
| + }
|
| +
|
| + return true;
|
| }
|
|
|
| -WebKit::WebHistoryItem PageStateToHistoryItem(const PageState& state) {
|
| - return webkit_glue::HistoryItemFromString(state.ToEncodedData());
|
| +} // namespace
|
| +
|
| +PageState HistoryItemToPageState(const WebHistoryItem& item) {
|
| + ExplodedPageState exploded_page_state;
|
| + ToFilePathVector(item.getReferencedFilePaths(),
|
| + &exploded_page_state.referenced_files);
|
| +
|
| + if (!RecursivelyGenerateFrameState(item, &exploded_page_state.top))
|
| + return PageState();
|
| +
|
| + std::string encoded_data;
|
| + if (!EncodePageState(exploded_page_state, &encoded_data))
|
| + return PageState();
|
| +
|
| + return PageState::CreateFromEncodedData(encoded_data);
|
| +}
|
| +
|
| +WebHistoryItem PageStateToHistoryItem(const PageState& page_state) {
|
| + ExplodedPageState exploded_page_state;
|
| + if (!DecodePageState(page_state.ToEncodedData(), &exploded_page_state))
|
| + return WebHistoryItem();
|
| +
|
| + WebHistoryItem item;
|
| + item.initialize();
|
| + if (!RecursivelyGenerateHistoryItem(exploded_page_state.top, &item))
|
| + return WebHistoryItem();
|
| +
|
| + return item;
|
| }
|
|
|
| } // namespace content
|
|
|