OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/page_state_serialization.h" | 5 #include "content/common/page_state_serialization.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 // 13: Adds support for URL (FileSystem URL) | 186 // 13: Adds support for URL (FileSystem URL) |
187 // 14: Adds list of referenced files, version written only for first item. | 187 // 14: Adds list of referenced files, version written only for first item. |
188 // 15: Removes a bunch of values we defined but never used. | 188 // 15: Removes a bunch of values we defined but never used. |
189 // 16: Switched from blob urls to blob uuids. | 189 // 16: Switched from blob urls to blob uuids. |
190 // 17: Add a target frame id number. | 190 // 17: Add a target frame id number. |
191 // 18: Add referrer policy. | 191 // 18: Add referrer policy. |
192 // 19: Remove target frame id, which was a bad idea, and original url string, | 192 // 19: Remove target frame id, which was a bad idea, and original url string, |
193 // which is no longer used. | 193 // which is no longer used. |
194 // 20: Add pinch viewport scroll offset, the offset of the pinched zoomed | 194 // 20: Add pinch viewport scroll offset, the offset of the pinched zoomed |
195 // viewport within the unzoomed main frame. | 195 // viewport within the unzoomed main frame. |
196 // 21: Add frame sequence number | 196 // 21: Add frame sequence number. |
| 197 // 22: Add scroll restoration type. |
197 // | 198 // |
198 // NOTE: If the version is -1, then the pickle contains only a URL string. | 199 // NOTE: If the version is -1, then the pickle contains only a URL string. |
199 // See ReadPageState. | 200 // See ReadPageState. |
200 // | 201 // |
201 const int kMinVersion = 11; | 202 const int kMinVersion = 11; |
202 const int kCurrentVersion = 21; | 203 const int kCurrentVersion = 22; |
203 | 204 |
204 // A bunch of convenience functions to read/write to SerializeObjects. The | 205 // A bunch of convenience functions to read/write to SerializeObjects. The |
205 // de-serializers assume the input data will be in the correct format and fall | 206 // de-serializers assume the input data will be in the correct format and fall |
206 // back to returning safe defaults when not. | 207 // back to returning safe defaults when not. |
207 | 208 |
208 void WriteData(const void* data, int length, SerializeObject* obj) { | 209 void WriteData(const void* data, int length, SerializeObject* obj) { |
209 obj->pickle.WriteData(static_cast<const char*>(data), length); | 210 obj->pickle.WriteData(static_cast<const char*>(data), length); |
210 } | 211 } |
211 | 212 |
212 void ReadData(SerializeObject* obj, const void** data, int* length) { | 213 void ReadData(SerializeObject* obj, const void** data, int* length) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 WriteStringVector(state.document_state, obj); | 491 WriteStringVector(state.document_state, obj); |
491 | 492 |
492 WriteReal(state.page_scale_factor, obj); | 493 WriteReal(state.page_scale_factor, obj); |
493 WriteInteger64(state.item_sequence_number, obj); | 494 WriteInteger64(state.item_sequence_number, obj); |
494 WriteInteger64(state.document_sequence_number, obj); | 495 WriteInteger64(state.document_sequence_number, obj); |
495 WriteInteger64(state.frame_sequence_number, obj); | 496 WriteInteger64(state.frame_sequence_number, obj); |
496 WriteInteger(state.referrer_policy, obj); | 497 WriteInteger(state.referrer_policy, obj); |
497 WriteReal(state.pinch_viewport_scroll_offset.x(), obj); | 498 WriteReal(state.pinch_viewport_scroll_offset.x(), obj); |
498 WriteReal(state.pinch_viewport_scroll_offset.y(), obj); | 499 WriteReal(state.pinch_viewport_scroll_offset.y(), obj); |
499 | 500 |
| 501 WriteInteger(state.scroll_restoration_type, obj); |
| 502 |
500 bool has_state_object = !state.state_object.is_null(); | 503 bool has_state_object = !state.state_object.is_null(); |
501 WriteBoolean(has_state_object, obj); | 504 WriteBoolean(has_state_object, obj); |
502 if (has_state_object) | 505 if (has_state_object) |
503 WriteString(state.state_object, obj); | 506 WriteString(state.state_object, obj); |
504 | 507 |
505 WriteHttpBody(state.http_body, obj); | 508 WriteHttpBody(state.http_body, obj); |
506 | 509 |
507 // NOTE: It is a quirk of the format that we still have to write the | 510 // NOTE: It is a quirk of the format that we still have to write the |
508 // http_content_type field when the HTTP body is null. That's why this code | 511 // http_content_type field when the HTTP body is null. That's why this code |
509 // is here instead of inside WriteHttpBody. | 512 // is here instead of inside WriteHttpBody. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 } | 564 } |
562 | 565 |
563 if (obj->version >= 20) { | 566 if (obj->version >= 20) { |
564 double x = ReadReal(obj); | 567 double x = ReadReal(obj); |
565 double y = ReadReal(obj); | 568 double y = ReadReal(obj); |
566 state->pinch_viewport_scroll_offset = gfx::PointF(x, y); | 569 state->pinch_viewport_scroll_offset = gfx::PointF(x, y); |
567 } else { | 570 } else { |
568 state->pinch_viewport_scroll_offset = gfx::PointF(-1, -1); | 571 state->pinch_viewport_scroll_offset = gfx::PointF(-1, -1); |
569 } | 572 } |
570 | 573 |
| 574 if (obj->version >= 22) { |
| 575 state->scroll_restoration_type = |
| 576 static_cast<blink::WebHistoryScrollRestorationType>(ReadInteger(obj)); |
| 577 } |
| 578 |
571 bool has_state_object = ReadBoolean(obj); | 579 bool has_state_object = ReadBoolean(obj); |
572 if (has_state_object) | 580 if (has_state_object) |
573 state->state_object = ReadString(obj); | 581 state->state_object = ReadString(obj); |
574 | 582 |
575 ReadHttpBody(obj, &state->http_body); | 583 ReadHttpBody(obj, &state->http_body); |
576 | 584 |
577 // NOTE: It is a quirk of the format that we still have to read the | 585 // NOTE: It is a quirk of the format that we still have to read the |
578 // http_content_type field when the HTTP body is null. That's why this code | 586 // http_content_type field when the HTTP body is null. That's why this code |
579 // is here instead of inside ReadHttpBody. | 587 // is here instead of inside ReadHttpBody. |
580 state->http_body.http_content_type = ReadString(obj); | 588 state->http_body.http_content_type = ReadString(obj); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 ExplodedHttpBody::ExplodedHttpBody() | 675 ExplodedHttpBody::ExplodedHttpBody() |
668 : identifier(0), | 676 : identifier(0), |
669 contains_passwords(false), | 677 contains_passwords(false), |
670 is_null(true) { | 678 is_null(true) { |
671 } | 679 } |
672 | 680 |
673 ExplodedHttpBody::~ExplodedHttpBody() { | 681 ExplodedHttpBody::~ExplodedHttpBody() { |
674 } | 682 } |
675 | 683 |
676 ExplodedFrameState::ExplodedFrameState() | 684 ExplodedFrameState::ExplodedFrameState() |
677 : item_sequence_number(0), | 685 : scroll_restoration_type(blink::WebHistoryScrollRestorationAuto), |
| 686 item_sequence_number(0), |
678 document_sequence_number(0), | 687 document_sequence_number(0), |
679 frame_sequence_number(0), | 688 frame_sequence_number(0), |
680 page_scale_factor(0.0), | 689 page_scale_factor(0.0), |
681 referrer_policy(blink::WebReferrerPolicyDefault) { | 690 referrer_policy(blink::WebReferrerPolicyDefault) { |
682 } | 691 } |
683 | 692 |
684 ExplodedFrameState::ExplodedFrameState(const ExplodedFrameState& other) { | 693 ExplodedFrameState::ExplodedFrameState(const ExplodedFrameState& other) { |
685 assign(other); | 694 assign(other); |
686 } | 695 } |
687 | 696 |
688 ExplodedFrameState::~ExplodedFrameState() { | 697 ExplodedFrameState::~ExplodedFrameState() { |
689 } | 698 } |
690 | 699 |
691 void ExplodedFrameState::operator=(const ExplodedFrameState& other) { | 700 void ExplodedFrameState::operator=(const ExplodedFrameState& other) { |
692 if (&other != this) | 701 if (&other != this) |
693 assign(other); | 702 assign(other); |
694 } | 703 } |
695 | 704 |
696 void ExplodedFrameState::assign(const ExplodedFrameState& other) { | 705 void ExplodedFrameState::assign(const ExplodedFrameState& other) { |
697 url_string = other.url_string; | 706 url_string = other.url_string; |
698 referrer = other.referrer; | 707 referrer = other.referrer; |
699 target = other.target; | 708 target = other.target; |
700 state_object = other.state_object; | 709 state_object = other.state_object; |
701 document_state = other.document_state; | 710 document_state = other.document_state; |
| 711 scroll_restoration_type = other.scroll_restoration_type; |
702 pinch_viewport_scroll_offset = other.pinch_viewport_scroll_offset; | 712 pinch_viewport_scroll_offset = other.pinch_viewport_scroll_offset; |
703 scroll_offset = other.scroll_offset; | 713 scroll_offset = other.scroll_offset; |
704 item_sequence_number = other.item_sequence_number; | 714 item_sequence_number = other.item_sequence_number; |
705 document_sequence_number = other.document_sequence_number; | 715 document_sequence_number = other.document_sequence_number; |
706 frame_sequence_number = other.frame_sequence_number; | 716 frame_sequence_number = other.frame_sequence_number; |
707 page_scale_factor = other.page_scale_factor; | 717 page_scale_factor = other.page_scale_factor; |
708 referrer_policy = other.referrer_policy; | 718 referrer_policy = other.referrer_policy; |
709 http_body = other.http_body; | 719 http_body = other.http_body; |
710 children = other.children; | 720 children = other.children; |
711 } | 721 } |
(...skipping 29 matching lines...) Expand all Loading... |
741 float device_scale_factor, | 751 float device_scale_factor, |
742 ExplodedPageState* exploded) { | 752 ExplodedPageState* exploded) { |
743 g_device_scale_factor_for_testing = device_scale_factor; | 753 g_device_scale_factor_for_testing = device_scale_factor; |
744 bool rv = DecodePageState(encoded, exploded); | 754 bool rv = DecodePageState(encoded, exploded); |
745 g_device_scale_factor_for_testing = 0.0; | 755 g_device_scale_factor_for_testing = 0.0; |
746 return rv; | 756 return rv; |
747 } | 757 } |
748 #endif | 758 #endif |
749 | 759 |
750 } // namespace content | 760 } // namespace content |
OLD | NEW |