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