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

Side by Side Diff: Source/core/frame/History.cpp

Issue 1239463005: Replace history.options with history.scrollRestoration attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: minor cleanup Created 5 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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 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 12 matching lines...) Expand all
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/frame/History.h" 27 #include "core/frame/History.h"
28 28
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
33 #include "core/frame/StateOptions.h"
34 #include "core/loader/DocumentLoader.h" 33 #include "core/loader/DocumentLoader.h"
35 #include "core/loader/FrameLoader.h" 34 #include "core/loader/FrameLoader.h"
36 #include "core/loader/FrameLoaderClient.h" 35 #include "core/loader/FrameLoaderClient.h"
37 #include "core/loader/HistoryItem.h" 36 #include "core/loader/HistoryItem.h"
38 #include "core/page/Page.h" 37 #include "core/page/Page.h"
39 #include "platform/RuntimeEnabledFeatures.h" 38 #include "platform/RuntimeEnabledFeatures.h"
40 #include "platform/weborigin/KURL.h" 39 #include "platform/weborigin/KURL.h"
41 #include "platform/weborigin/SecurityOrigin.h" 40 #include "platform/weborigin/SecurityOrigin.h"
42 #include "wtf/MainThread.h" 41 #include "wtf/MainThread.h"
43 42
(...skipping 27 matching lines...) Expand all
71 { 70 {
72 if (!m_frame) 71 if (!m_frame)
73 return 0; 72 return 0;
74 73
75 if (HistoryItem* historyItem = m_frame->loader().currentItem()) 74 if (HistoryItem* historyItem = m_frame->loader().currentItem())
76 return historyItem->stateObject(); 75 return historyItem->stateObject();
77 76
78 return 0; 77 return 0;
79 } 78 }
80 79
81 void History::options(StateOptions& options) 80 void History::setScrollRestoration(const String& value)
82 { 81 {
83 if (!m_frame) 82 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader() || ! RuntimeEnabledFeatures::scrollRestorationEnabled())
84 return; 83 return;
85 84
86 if (HistoryItem* historyItem = m_frame->loader().currentItem()) { 85 HistoryScrollRestorationType scrollRestoration = value == "manual" ? ScrollR estorationManual : ScrollRestorationAuto;
Nate Chapin 2015/07/16 21:34:01 My knowledge of the v8 bindings is outdated. Are w
majidvp 2015/07/16 22:11:49 Yes V8 bindings validates that only valid values a
87 options.setScrollRestoration(historyItem->scrollRestorationType() == Scr ollRestorationManual ? "manual" : "auto"); 86 if (scrollRestoration == scrollRestorationInternal())
87 return;
88 // Equivalent to calling replace on the same entry but with new scroll resto ration option
89 m_frame->loader().updateForSameDocumentNavigation(m_frame->loader().currentI tem()->url(), SameDocumentNavigationHistoryApi, stateInternal(), scrollRestorati on, FrameLoadTypeReplaceCurrentItem);
Nate Chapin 2015/07/16 21:34:01 Why is this modeled as a navigation?
majidvp 2015/07/16 22:11:49 Hmm, perhaps it can be made simpler. I think all i
Nate Chapin 2015/07/16 22:19:32 It may not even need to notify FrameLoaderClient.
90 }
91
92 String History::scrollRestoration()
93 {
94 return scrollRestorationInternal() == ScrollRestorationManual ? "manual" : " auto";
95 }
96
97 HistoryScrollRestorationType History::scrollRestorationInternal() const
98 {
99 if (m_frame && RuntimeEnabledFeatures::scrollRestorationEnabled()) {
100 if (HistoryItem* historyItem = m_frame->loader().currentItem())
101 return historyItem->scrollRestorationType();
88 } 102 }
103
104 return ScrollRestorationAuto;
89 } 105 }
90 106
91 bool History::stateChanged() const 107 bool History::stateChanged() const
92 { 108 {
93 return m_lastStateObjectRequested != stateInternal(); 109 return m_lastStateObjectRequested != stateInternal();
94 } 110 }
95 111
96 bool History::isSameAsCurrentState(SerializedScriptValue* state) const 112 bool History::isSameAsCurrentState(SerializedScriptValue* state) const
97 { 113 {
98 return state == stateInternal(); 114 return state == stateInternal();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 Document* document = m_frame->document(); 148 Document* document = m_frame->document();
133 149
134 if (urlString.isNull()) 150 if (urlString.isNull())
135 return document->url(); 151 return document->url();
136 if (urlString.isEmpty()) 152 if (urlString.isEmpty())
137 return document->baseURL(); 153 return document->baseURL();
138 154
139 return KURL(document->baseURL(), urlString); 155 return KURL(document->baseURL(), urlString);
140 } 156 }
141 157
142 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, const StateOptions& options, FrameLoa dType type, ExceptionState& exceptionState) 158 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat ionType, FrameLoadType type, ExceptionState& exceptionState)
143 { 159 {
144 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) 160 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader())
145 return; 161 return;
146 162
147 KURL fullURL = urlForState(urlString); 163 KURL fullURL = urlForState(urlString);
148 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest (fullURL)) { 164 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest (fullURL)) {
149 // We can safely expose the URL to JavaScript, as a) no redirection take s place: JavaScript already had this URL, b) JavaScript can only access a same-o rigin History object. 165 // We can safely expose the URL to JavaScript, as a) no redirection take s place: JavaScript already had this URL, b) JavaScript can only access a same-o rigin History object.
150 exceptionState.throwSecurityError("A history state object with URL '" + fullURL.elidedString() + "' cannot be created in a document with origin '" + m_f rame->document()->securityOrigin()->toString() + "'."); 166 exceptionState.throwSecurityError("A history state object with URL '" + fullURL.elidedString() + "' cannot be created in a document with origin '" + m_f rame->document()->securityOrigin()->toString() + "'.");
151 return; 167 return;
152 } 168 }
153 169
154 HistoryScrollRestorationType restorationType = ScrollRestorationAuto;
155 if (RuntimeEnabledFeatures::scrollRestorationEnabled() && options.scrollRest oration() == "manual")
156 restorationType = ScrollRestorationManual;
157
158 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, data, restorationType, type); 170 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig ationHistoryApi, data, restorationType, type);
159 } 171 }
160 172
161 } // namespace blink 173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698