| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/history_serialization.h" | 5 #include "content/renderer/history_serialization.h" |
| 6 | 6 |
| 7 #include "content/common/page_state_serialization.h" | 7 #include "content/common/page_state_serialization.h" |
| 8 #include "content/common/site_isolation_policy.h" |
| 8 #include "content/public/common/page_state.h" | 9 #include "content/public/common/page_state.h" |
| 9 #include "content/renderer/history_entry.h" | 10 #include "content/renderer/history_entry.h" |
| 10 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 11 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 12 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 12 #include "third_party/WebKit/public/platform/WebPoint.h" | 13 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
| 15 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 16 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 16 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | 17 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
| 17 | 18 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 166 } |
| 166 node->set_item(item); | 167 node->set_item(item); |
| 167 | 168 |
| 168 for (size_t i = 0; i < state.children.size(); ++i) | 169 for (size_t i = 0; i < state.children.size(); ++i) |
| 169 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); | 170 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); |
| 170 } | 171 } |
| 171 | 172 |
| 172 } // namespace | 173 } // namespace |
| 173 | 174 |
| 174 PageState HistoryEntryToPageState(HistoryEntry* entry) { | 175 PageState HistoryEntryToPageState(HistoryEntry* entry) { |
| 176 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 177 |
| 175 ExplodedPageState state; | 178 ExplodedPageState state; |
| 176 RecursivelyGenerateFrameState(entry->root_history_node(), &state.top, | 179 RecursivelyGenerateFrameState(entry->root_history_node(), &state.top, |
| 177 &state.referenced_files); | 180 &state.referenced_files); |
| 178 | 181 |
| 179 std::string encoded_data; | 182 std::string encoded_data; |
| 180 if (!EncodePageState(state, &encoded_data)) | 183 if (!EncodePageState(state, &encoded_data)) |
| 181 return PageState(); | 184 return PageState(); |
| 182 | 185 |
| 183 return PageState::CreateFromEncodedData(encoded_data); | 186 return PageState::CreateFromEncodedData(encoded_data); |
| 184 } | 187 } |
| 185 | 188 |
| 186 PageState SingleHistoryItemToPageState(const WebHistoryItem& item) { | 189 PageState SingleHistoryItemToPageState(const WebHistoryItem& item) { |
| 190 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 191 |
| 187 ExplodedPageState state; | 192 ExplodedPageState state; |
| 188 ToNullableString16Vector(item.getReferencedFilePaths(), | 193 ToNullableString16Vector(item.getReferencedFilePaths(), |
| 189 &state.referenced_files); | 194 &state.referenced_files); |
| 190 GenerateFrameStateFromItem(item, &state.top); | 195 GenerateFrameStateFromItem(item, &state.top); |
| 191 | 196 |
| 192 std::string encoded_data; | 197 std::string encoded_data; |
| 193 if (!EncodePageState(state, &encoded_data)) | 198 if (!EncodePageState(state, &encoded_data)) |
| 194 return PageState(); | 199 return PageState(); |
| 195 | 200 |
| 196 return PageState::CreateFromEncodedData(encoded_data); | 201 return PageState::CreateFromEncodedData(encoded_data); |
| 197 } | 202 } |
| 198 | 203 |
| 199 scoped_ptr<HistoryEntry> PageStateToHistoryEntry(const PageState& page_state) { | 204 scoped_ptr<HistoryEntry> PageStateToHistoryEntry(const PageState& page_state) { |
| 205 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 206 |
| 200 ExplodedPageState state; | 207 ExplodedPageState state; |
| 201 if (!DecodePageState(page_state.ToEncodedData(), &state)) | 208 if (!DecodePageState(page_state.ToEncodedData(), &state)) |
| 202 return scoped_ptr<HistoryEntry>(); | 209 return scoped_ptr<HistoryEntry>(); |
| 203 | 210 |
| 204 scoped_ptr<HistoryEntry> entry(new HistoryEntry()); | 211 scoped_ptr<HistoryEntry> entry(new HistoryEntry()); |
| 205 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); | 212 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); |
| 206 | 213 |
| 207 return entry.Pass(); | 214 return entry.Pass(); |
| 208 } | 215 } |
| 209 | 216 |
| 217 ExplodedFrameState HistoryItemToFrameState(const WebHistoryItem& item) { |
| 218 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 219 |
| 220 // TODO(creis): We're missing the list of referenced_files. |
| 221 ExplodedFrameState state; |
| 222 GenerateFrameStateFromItem(item, &state); |
| 223 return state; |
| 224 } |
| 225 |
| 226 WebHistoryItem FrameStateToHistoryItem(const ExplodedFrameState& state) { |
| 227 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 228 |
| 229 scoped_ptr<HistoryEntry> entry(new HistoryEntry()); |
| 230 RecursivelyGenerateHistoryItem(state, entry->root_history_node()); |
| 231 return entry->root_history_node()->item(); |
| 232 } |
| 233 |
| 210 } // namespace content | 234 } // namespace content |
| OLD | NEW |