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

Side by Side Diff: third_party/WebKit/Source/core/loader/HistoryItem.cpp

Issue 2949073002: Changing scroll and view state in onpopstate shouldn't overwrite back/forward state restore (Closed)
Patch Set: Reset ViewState when trying to copy from a nullptr Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 24 matching lines...) Expand all
35 namespace blink { 35 namespace blink {
36 36
37 static long long GenerateSequenceNumber() { 37 static long long GenerateSequenceNumber() {
38 // Initialize to the current time to reduce the likelihood of generating 38 // Initialize to the current time to reduce the likelihood of generating
39 // identifiers that overlap with those from past/future browser sessions. 39 // identifiers that overlap with those from past/future browser sessions.
40 static long long next = static_cast<long long>(CurrentTime() * 1000000.0); 40 static long long next = static_cast<long long>(CurrentTime() * 1000000.0);
41 return ++next; 41 return ++next;
42 } 42 }
43 43
44 HistoryItem::HistoryItem() 44 HistoryItem::HistoryItem()
45 : did_save_scroll_or_scale_state_(false), 45 : item_sequence_number_(GenerateSequenceNumber()),
46 page_scale_factor_(0),
47 item_sequence_number_(GenerateSequenceNumber()),
48 document_sequence_number_(GenerateSequenceNumber()), 46 document_sequence_number_(GenerateSequenceNumber()),
49 scroll_restoration_type_(kScrollRestorationAuto) {} 47 scroll_restoration_type_(kScrollRestorationAuto) {}
50 48
51 HistoryItem::~HistoryItem() {} 49 HistoryItem::~HistoryItem() {}
52 50
53 const String& HistoryItem::UrlString() const { 51 const String& HistoryItem::UrlString() const {
54 return url_string_; 52 return url_string_;
55 } 53 }
56 54
57 KURL HistoryItem::Url() const { 55 KURL HistoryItem::Url() const {
(...skipping 12 matching lines...) Expand all
70 void HistoryItem::SetURL(const KURL& url) { 68 void HistoryItem::SetURL(const KURL& url) {
71 SetURLString(url.GetString()); 69 SetURLString(url.GetString());
72 } 70 }
73 71
74 void HistoryItem::SetReferrer(const Referrer& referrer) { 72 void HistoryItem::SetReferrer(const Referrer& referrer) {
75 // This should be a CHECK. 73 // This should be a CHECK.
76 referrer_ = SecurityPolicy::GenerateReferrer(referrer.referrer_policy, Url(), 74 referrer_ = SecurityPolicy::GenerateReferrer(referrer.referrer_policy, Url(),
77 referrer.referrer); 75 referrer.referrer);
78 } 76 }
79 77
80 const ScrollOffset& HistoryItem::VisualViewportScrollOffset() const {
81 return visual_viewport_scroll_offset_;
82 }
83
84 void HistoryItem::SetVisualViewportScrollOffset(const ScrollOffset& offset) { 78 void HistoryItem::SetVisualViewportScrollOffset(const ScrollOffset& offset) {
85 visual_viewport_scroll_offset_ = offset; 79 if (!view_state_)
86 SetDidSaveScrollOrScaleState(true); 80 view_state_ = WTF::MakeUnique<ViewState>();
87 } 81 view_state_->visual_viewport_scroll_offset_ = offset;
88
89 const ScrollOffset& HistoryItem::GetScrollOffset() const {
90 return scroll_offset_;
91 } 82 }
92 83
93 void HistoryItem::SetScrollOffset(const ScrollOffset& offset) { 84 void HistoryItem::SetScrollOffset(const ScrollOffset& offset) {
94 scroll_offset_ = offset; 85 if (!view_state_)
95 SetDidSaveScrollOrScaleState(true); 86 view_state_ = WTF::MakeUnique<ViewState>();
96 } 87 view_state_->scroll_offset_ = offset;
97
98 float HistoryItem::PageScaleFactor() const {
99 return page_scale_factor_;
100 } 88 }
101 89
102 void HistoryItem::SetPageScaleFactor(float scale_factor) { 90 void HistoryItem::SetPageScaleFactor(float scale_factor) {
103 page_scale_factor_ = scale_factor; 91 if (!view_state_)
104 SetDidSaveScrollOrScaleState(true); 92 view_state_ = WTF::MakeUnique<ViewState>();
93 view_state_->page_scale_factor_ = scale_factor;
105 } 94 }
106 95
107 void HistoryItem::SetDocumentState(const Vector<String>& state) { 96 void HistoryItem::SetDocumentState(const Vector<String>& state) {
108 DCHECK(!document_state_); 97 DCHECK(!document_state_);
109 document_state_vector_ = state; 98 document_state_vector_ = state;
110 } 99 }
111 100
112 void HistoryItem::SetDocumentState(DocumentState* state) { 101 void HistoryItem::SetDocumentState(DocumentState* state) {
113 document_state_ = state; 102 document_state_ = state;
114 } 103 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 request.AddHTTPOriginIfNeeded(referrer_.referrer); 162 request.AddHTTPOriginIfNeeded(referrer_.referrer);
174 } 163 }
175 return request; 164 return request;
176 } 165 }
177 166
178 DEFINE_TRACE(HistoryItem) { 167 DEFINE_TRACE(HistoryItem) {
179 visitor->Trace(document_state_); 168 visitor->Trace(document_state_);
180 } 169 }
181 170
182 } // namespace blink 171 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/HistoryItem.h ('k') | third_party/WebKit/Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698