OLD | NEW |
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 Loading... |
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 Loading... |
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 ASSERT(value == "manual" || value == "auto"); |
| 83 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader() || !
RuntimeEnabledFeatures::scrollRestorationEnabled()) |
84 return; | 84 return; |
85 | 85 |
86 if (HistoryItem* historyItem = m_frame->loader().currentItem()) { | 86 HistoryScrollRestorationType scrollRestoration = value == "manual" ? ScrollR
estorationManual : ScrollRestorationAuto; |
87 options.setScrollRestoration(historyItem->scrollRestorationType() == Scr
ollRestorationManual ? "manual" : "auto"); | 87 if (scrollRestoration == scrollRestorationInternal()) |
| 88 return; |
| 89 // Equivalent to calling replace on the same entry but with new scroll resto
ration option |
| 90 m_frame->loader().setScrollRestorationType(scrollRestoration); |
| 91 } |
| 92 |
| 93 String History::scrollRestoration() |
| 94 { |
| 95 return scrollRestorationInternal() == ScrollRestorationManual ? "manual" : "
auto"; |
| 96 } |
| 97 |
| 98 HistoryScrollRestorationType History::scrollRestorationInternal() const |
| 99 { |
| 100 if (m_frame && RuntimeEnabledFeatures::scrollRestorationEnabled()) { |
| 101 if (HistoryItem* historyItem = m_frame->loader().currentItem()) |
| 102 return historyItem->scrollRestorationType(); |
88 } | 103 } |
| 104 |
| 105 return ScrollRestorationAuto; |
89 } | 106 } |
90 | 107 |
91 bool History::stateChanged() const | 108 bool History::stateChanged() const |
92 { | 109 { |
93 return m_lastStateObjectRequested != stateInternal(); | 110 return m_lastStateObjectRequested != stateInternal(); |
94 } | 111 } |
95 | 112 |
96 bool History::isSameAsCurrentState(SerializedScriptValue* state) const | 113 bool History::isSameAsCurrentState(SerializedScriptValue* state) const |
97 { | 114 { |
98 return state == stateInternal(); | 115 return state == stateInternal(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 Document* document = m_frame->document(); | 149 Document* document = m_frame->document(); |
133 | 150 |
134 if (urlString.isNull()) | 151 if (urlString.isNull()) |
135 return document->url(); | 152 return document->url(); |
136 if (urlString.isEmpty()) | 153 if (urlString.isEmpty()) |
137 return document->baseURL(); | 154 return document->baseURL(); |
138 | 155 |
139 return KURL(document->baseURL(), urlString); | 156 return KURL(document->baseURL(), urlString); |
140 } | 157 } |
141 | 158 |
142 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str
ing& /* title */, const String& urlString, const StateOptions& options, FrameLoa
dType type, ExceptionState& exceptionState) | 159 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str
ing& /* title */, const String& urlString, HistoryScrollRestorationType restorat
ionType, FrameLoadType type, ExceptionState& exceptionState) |
143 { | 160 { |
144 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) | 161 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) |
145 return; | 162 return; |
146 | 163 |
147 KURL fullURL = urlForState(urlString); | 164 KURL fullURL = urlForState(urlString); |
148 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest
(fullURL)) { | 165 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. | 166 // 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() + "'."); | 167 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; | 168 return; |
152 } | 169 } |
153 | 170 |
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); | 171 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig
ationHistoryApi, data, restorationType, type); |
159 } | 172 } |
160 | 173 |
161 } // namespace blink | 174 } // namespace blink |
OLD | NEW |