Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2028)

Unified Diff: content/common/page_state_serialization.cc

Issue 2628683003: Add DidSaveScrollOrScaleState flag to prevent restoreScrollPositionAndViewState restore from default (Closed)
Patch Set: add dump file Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/page_state_serialization.h ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/page_state_serialization.cc
diff --git a/content/common/page_state_serialization.cc b/content/common/page_state_serialization.cc
index 894ff2be722b9503cd63916528807cbe05eab224..52ed1a192a408d36f2957cebc2dd699d0c6ff3d6 100644
--- a/content/common/page_state_serialization.cc
+++ b/content/common/page_state_serialization.cc
@@ -196,12 +196,13 @@ struct SerializeObject {
// 21: Add frame sequence number.
// 22: Add scroll restoration type.
// 23: Remove frame sequence number, there are easier ways.
+// 24: Add did save scroll or scale state.
//
// NOTE: If the version is -1, then the pickle contains only a URL string.
// See ReadPageState.
//
const int kMinVersion = 11;
-const int kCurrentVersion = 23;
+const int kCurrentVersion = 24;
// A bunch of convenience functions to read/write to SerializeObjects. The
// de-serializers assume the input data will be in the correct format and fall
@@ -505,18 +506,28 @@ void WriteFrameState(
WriteString(state.url_string, obj);
WriteString(state.target, obj);
- WriteInteger(state.scroll_offset.x(), obj);
- WriteInteger(state.scroll_offset.y(), obj);
+ WriteBoolean(state.did_save_scroll_or_scale_state, obj);
+
+ if (state.did_save_scroll_or_scale_state) {
+ WriteInteger(state.scroll_offset.x(), obj);
+ WriteInteger(state.scroll_offset.y(), obj);
+ }
+
WriteString(state.referrer, obj);
WriteStringVector(state.document_state, obj);
- WriteReal(state.page_scale_factor, obj);
+ if (state.did_save_scroll_or_scale_state)
+ WriteReal(state.page_scale_factor, obj);
+
WriteInteger64(state.item_sequence_number, obj);
WriteInteger64(state.document_sequence_number, obj);
WriteInteger(static_cast<int>(state.referrer_policy), obj);
- WriteReal(state.visual_viewport_scroll_offset.x(), obj);
- WriteReal(state.visual_viewport_scroll_offset.y(), obj);
+
+ if (state.did_save_scroll_or_scale_state) {
+ WriteReal(state.visual_viewport_scroll_offset.x(), obj);
+ WriteReal(state.visual_viewport_scroll_offset.y(), obj);
+ }
WriteInteger(state.scroll_restoration_type, obj);
@@ -557,9 +568,17 @@ void ReadFrameState(SerializeObject* obj, bool is_top,
ReadReal(obj); // Skip obsolete visited time field.
}
- int x = ReadInteger(obj);
- int y = ReadInteger(obj);
- state->scroll_offset = gfx::Point(x, y);
+ if (obj->version >= 24) {
+ state->did_save_scroll_or_scale_state = ReadBoolean(obj);
+ } else {
+ state->did_save_scroll_or_scale_state = true;
+ }
+
+ if (state->did_save_scroll_or_scale_state) {
+ int x = ReadInteger(obj);
+ int y = ReadInteger(obj);
+ state->scroll_offset = gfx::Point(x, y);
+ }
if (obj->version < 15) {
ReadBoolean(obj); // Skip obsolete target item flag.
@@ -569,7 +588,9 @@ void ReadFrameState(SerializeObject* obj, bool is_top,
ReadStringVector(obj, &state->document_state);
- state->page_scale_factor = ReadReal(obj);
+ if (state->did_save_scroll_or_scale_state)
+ state->page_scale_factor = ReadReal(obj);
+
state->item_sequence_number = ReadInteger64(obj);
state->document_sequence_number = ReadInteger64(obj);
if (obj->version >= 21 && obj->version < 23)
@@ -583,7 +604,7 @@ void ReadFrameState(SerializeObject* obj, bool is_top,
static_cast<blink::WebReferrerPolicy>(ReadInteger(obj));
}
- if (obj->version >= 20) {
+ if (obj->version >= 20 && state->did_save_scroll_or_scale_state) {
double x = ReadReal(obj);
double y = ReadReal(obj);
state->visual_viewport_scroll_offset = gfx::PointF(x, y);
@@ -689,11 +710,11 @@ ExplodedHttpBody::~ExplodedHttpBody() {
ExplodedFrameState::ExplodedFrameState()
: scroll_restoration_type(blink::WebHistoryScrollRestorationAuto),
+ did_save_scroll_or_scale_state(true),
item_sequence_number(0),
document_sequence_number(0),
page_scale_factor(0.0),
- referrer_policy(blink::WebReferrerPolicyDefault) {
-}
+ referrer_policy(blink::WebReferrerPolicyDefault) {}
ExplodedFrameState::ExplodedFrameState(const ExplodedFrameState& other) {
assign(other);
@@ -714,6 +735,7 @@ void ExplodedFrameState::assign(const ExplodedFrameState& other) {
state_object = other.state_object;
document_state = other.document_state;
scroll_restoration_type = other.scroll_restoration_type;
+ did_save_scroll_or_scale_state = other.did_save_scroll_or_scale_state;
visual_viewport_scroll_offset = other.visual_viewport_scroll_offset;
scroll_offset = other.scroll_offset;
item_sequence_number = other.item_sequence_number;
« no previous file with comments | « content/common/page_state_serialization.h ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698