Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // 22: Add scroll restoration type. |
| 198 // 23: Remove frame sequence number, there are easier ways. | 198 // 23: Remove frame sequence number, there are easier ways. |
| 199 // 24: Add did save scroll state. | |
| 199 // | 200 // |
| 200 // NOTE: If the version is -1, then the pickle contains only a URL string. | 201 // NOTE: If the version is -1, then the pickle contains only a URL string. |
| 201 // See ReadPageState. | 202 // See ReadPageState. |
| 202 // | 203 // |
| 203 const int kMinVersion = 11; | 204 const int kMinVersion = 11; |
| 204 const int kCurrentVersion = 23; | 205 const int kCurrentVersion = 24; |
| 205 | 206 |
| 206 // A bunch of convenience functions to read/write to SerializeObjects. The | 207 // A bunch of convenience functions to read/write to SerializeObjects. The |
| 207 // de-serializers assume the input data will be in the correct format and fall | 208 // de-serializers assume the input data will be in the correct format and fall |
| 208 // back to returning safe defaults when not. | 209 // back to returning safe defaults when not. |
| 209 | 210 |
| 210 void WriteData(const void* data, int length, SerializeObject* obj) { | 211 void WriteData(const void* data, int length, SerializeObject* obj) { |
| 211 obj->pickle.WriteData(static_cast<const char*>(data), length); | 212 obj->pickle.WriteData(static_cast<const char*>(data), length); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void ReadData(SerializeObject* obj, const void** data, int* length) { | 215 void ReadData(SerializeObject* obj, const void** data, int* length) { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { | 500 const ExplodedFrameState& state, SerializeObject* obj, bool is_top) { |
| 500 // WARNING: This data may be persisted for later use. As such, care must be | 501 // WARNING: This data may be persisted for later use. As such, care must be |
| 501 // taken when changing the serialized format. If a new field needs to be | 502 // taken when changing the serialized format. If a new field needs to be |
| 502 // written, only adding at the end will make it easier to deal with loading | 503 // written, only adding at the end will make it easier to deal with loading |
| 503 // older versions. Similarly, this should NOT save fields with sensitive | 504 // older versions. Similarly, this should NOT save fields with sensitive |
| 504 // data, such as password fields. | 505 // data, such as password fields. |
| 505 | 506 |
| 506 WriteString(state.url_string, obj); | 507 WriteString(state.url_string, obj); |
| 507 WriteString(state.target, obj); | 508 WriteString(state.target, obj); |
| 508 WriteInteger(state.scroll_offset.x(), obj); | 509 WriteInteger(state.scroll_offset.x(), obj); |
| 509 WriteInteger(state.scroll_offset.y(), obj); | 510 WriteInteger(state.scroll_offset.y(), obj); |
|
majidvp
2017/02/14 20:42:16
Is did_save_scroll_state is false, then why are we
| |
| 510 WriteString(state.referrer, obj); | 511 WriteString(state.referrer, obj); |
| 511 | 512 |
| 512 WriteStringVector(state.document_state, obj); | 513 WriteStringVector(state.document_state, obj); |
| 513 | 514 |
| 514 WriteReal(state.page_scale_factor, obj); | 515 WriteReal(state.page_scale_factor, obj); |
| 515 WriteInteger64(state.item_sequence_number, obj); | 516 WriteInteger64(state.item_sequence_number, obj); |
| 516 WriteInteger64(state.document_sequence_number, obj); | 517 WriteInteger64(state.document_sequence_number, obj); |
| 518 WriteBoolean(state.did_save_scroll_state, obj); | |
|
majidvp
2017/02/14 20:42:16
Why here? I feel if anything, it should be written
| |
| 517 WriteInteger(static_cast<int>(state.referrer_policy), obj); | 519 WriteInteger(static_cast<int>(state.referrer_policy), obj); |
| 518 WriteReal(state.visual_viewport_scroll_offset.x(), obj); | 520 WriteReal(state.visual_viewport_scroll_offset.x(), obj); |
| 519 WriteReal(state.visual_viewport_scroll_offset.y(), obj); | 521 WriteReal(state.visual_viewport_scroll_offset.y(), obj); |
| 520 | 522 |
| 521 WriteInteger(state.scroll_restoration_type, obj); | 523 WriteInteger(state.scroll_restoration_type, obj); |
| 522 | 524 |
| 523 bool has_state_object = !state.state_object.is_null(); | 525 bool has_state_object = !state.state_object.is_null(); |
| 524 WriteBoolean(has_state_object, obj); | 526 WriteBoolean(has_state_object, obj); |
| 525 if (has_state_object) | 527 if (has_state_object) |
| 526 WriteString(state.state_object, obj); | 528 WriteString(state.state_object, obj); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 | 573 |
| 572 state->page_scale_factor = ReadReal(obj); | 574 state->page_scale_factor = ReadReal(obj); |
| 573 state->item_sequence_number = ReadInteger64(obj); | 575 state->item_sequence_number = ReadInteger64(obj); |
| 574 state->document_sequence_number = ReadInteger64(obj); | 576 state->document_sequence_number = ReadInteger64(obj); |
| 575 if (obj->version >= 21 && obj->version < 23) | 577 if (obj->version >= 21 && obj->version < 23) |
| 576 ReadInteger64(obj); // Skip obsolete frame sequence number. | 578 ReadInteger64(obj); // Skip obsolete frame sequence number. |
| 577 | 579 |
| 578 if (obj->version >= 17 && obj->version < 19) | 580 if (obj->version >= 17 && obj->version < 19) |
| 579 ReadInteger64(obj); // Skip obsolete target frame id number. | 581 ReadInteger64(obj); // Skip obsolete target frame id number. |
| 580 | 582 |
| 583 if (obj->version >= 24) | |
| 584 state->did_save_scroll_state = ReadBoolean(obj); | |
| 585 | |
| 581 if (obj->version >= 18) { | 586 if (obj->version >= 18) { |
| 582 state->referrer_policy = | 587 state->referrer_policy = |
| 583 static_cast<blink::WebReferrerPolicy>(ReadInteger(obj)); | 588 static_cast<blink::WebReferrerPolicy>(ReadInteger(obj)); |
| 584 } | 589 } |
| 585 | 590 |
| 586 if (obj->version >= 20) { | 591 if (obj->version >= 20) { |
| 587 double x = ReadReal(obj); | 592 double x = ReadReal(obj); |
| 588 double y = ReadReal(obj); | 593 double y = ReadReal(obj); |
| 589 state->visual_viewport_scroll_offset = gfx::PointF(x, y); | 594 state->visual_viewport_scroll_offset = gfx::PointF(x, y); |
| 590 } else { | 595 } else { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 ExplodedHttpBody::ExplodedHttpBody() : contains_passwords(false) {} | 690 ExplodedHttpBody::ExplodedHttpBody() : contains_passwords(false) {} |
| 686 | 691 |
| 687 ExplodedHttpBody::~ExplodedHttpBody() { | 692 ExplodedHttpBody::~ExplodedHttpBody() { |
| 688 } | 693 } |
| 689 | 694 |
| 690 ExplodedFrameState::ExplodedFrameState() | 695 ExplodedFrameState::ExplodedFrameState() |
| 691 : scroll_restoration_type(blink::WebHistoryScrollRestorationAuto), | 696 : scroll_restoration_type(blink::WebHistoryScrollRestorationAuto), |
| 692 item_sequence_number(0), | 697 item_sequence_number(0), |
| 693 document_sequence_number(0), | 698 document_sequence_number(0), |
| 694 page_scale_factor(0.0), | 699 page_scale_factor(0.0), |
| 695 referrer_policy(blink::WebReferrerPolicyDefault) { | 700 did_save_scroll_state(false), |
|
majidvp
2017/02/14 21:00:57
I think this is the incorrect initial value. In pa
| |
| 696 } | 701 referrer_policy(blink::WebReferrerPolicyDefault) {} |
| 697 | 702 |
| 698 ExplodedFrameState::ExplodedFrameState(const ExplodedFrameState& other) { | 703 ExplodedFrameState::ExplodedFrameState(const ExplodedFrameState& other) { |
| 699 assign(other); | 704 assign(other); |
| 700 } | 705 } |
| 701 | 706 |
| 702 ExplodedFrameState::~ExplodedFrameState() { | 707 ExplodedFrameState::~ExplodedFrameState() { |
| 703 } | 708 } |
| 704 | 709 |
| 705 void ExplodedFrameState::operator=(const ExplodedFrameState& other) { | 710 void ExplodedFrameState::operator=(const ExplodedFrameState& other) { |
| 706 if (&other != this) | 711 if (&other != this) |
| 707 assign(other); | 712 assign(other); |
| 708 } | 713 } |
| 709 | 714 |
| 710 void ExplodedFrameState::assign(const ExplodedFrameState& other) { | 715 void ExplodedFrameState::assign(const ExplodedFrameState& other) { |
| 711 url_string = other.url_string; | 716 url_string = other.url_string; |
| 712 referrer = other.referrer; | 717 referrer = other.referrer; |
| 713 target = other.target; | 718 target = other.target; |
| 714 state_object = other.state_object; | 719 state_object = other.state_object; |
| 715 document_state = other.document_state; | 720 document_state = other.document_state; |
| 716 scroll_restoration_type = other.scroll_restoration_type; | 721 scroll_restoration_type = other.scroll_restoration_type; |
| 717 visual_viewport_scroll_offset = other.visual_viewport_scroll_offset; | 722 visual_viewport_scroll_offset = other.visual_viewport_scroll_offset; |
| 718 scroll_offset = other.scroll_offset; | 723 scroll_offset = other.scroll_offset; |
| 719 item_sequence_number = other.item_sequence_number; | 724 item_sequence_number = other.item_sequence_number; |
| 720 document_sequence_number = other.document_sequence_number; | 725 document_sequence_number = other.document_sequence_number; |
| 721 page_scale_factor = other.page_scale_factor; | 726 page_scale_factor = other.page_scale_factor; |
| 727 did_save_scroll_state = other.did_save_scroll_state; | |
| 722 referrer_policy = other.referrer_policy; | 728 referrer_policy = other.referrer_policy; |
| 723 http_body = other.http_body; | 729 http_body = other.http_body; |
| 724 children = other.children; | 730 children = other.children; |
| 725 } | 731 } |
| 726 | 732 |
| 727 ExplodedPageState::ExplodedPageState() { | 733 ExplodedPageState::ExplodedPageState() { |
| 728 } | 734 } |
| 729 | 735 |
| 730 ExplodedPageState::~ExplodedPageState() { | 736 ExplodedPageState::~ExplodedPageState() { |
| 731 } | 737 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 // because it covers additional data (e.g.|contains_sensitive_info|) which | 787 // because it covers additional data (e.g.|contains_sensitive_info|) which |
| 782 // is marshaled between native code and java. WriteResourceRequestBody() | 788 // is marshaled between native code and java. WriteResourceRequestBody() |
| 783 // serializes data which needs to be saved out to disk. | 789 // serializes data which needs to be saved out to disk. |
| 784 WriteBoolean(resource_request_body.contains_sensitive_info(), &obj); | 790 WriteBoolean(resource_request_body.contains_sensitive_info(), &obj); |
| 785 return obj.GetAsString(); | 791 return obj.GetAsString(); |
| 786 } | 792 } |
| 787 | 793 |
| 788 #endif | 794 #endif |
| 789 | 795 |
| 790 } // namespace content | 796 } // namespace content |
| OLD | NEW |