| 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 16 matching lines...) Expand all Loading... |
| 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/loader/DocumentLoader.h" | 33 #include "core/loader/DocumentLoader.h" |
| 34 #include "core/loader/FrameLoader.h" | 34 #include "core/loader/FrameLoader.h" |
| 35 #include "core/loader/FrameLoaderClient.h" | 35 #include "core/loader/FrameLoaderClient.h" |
| 36 #include "core/loader/HistoryItem.h" | 36 #include "core/loader/HistoryItem.h" |
| 37 #include "core/page/BackForwardClient.h" | |
| 38 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
| 39 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 40 #include "platform/weborigin/SecurityOrigin.h" | 39 #include "platform/weborigin/SecurityOrigin.h" |
| 41 #include "wtf/MainThread.h" | 40 #include "wtf/MainThread.h" |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 History::History(LocalFrame* frame) | 44 History::History(LocalFrame* frame) |
| 46 : DOMWindowProperty(frame) | 45 : DOMWindowProperty(frame) |
| 47 , m_lastStateObjectRequested(nullptr) | 46 , m_lastStateObjectRequested(nullptr) |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void History::trace(Visitor* visitor) | 50 void History::trace(Visitor* visitor) |
| 52 { | 51 { |
| 53 DOMWindowProperty::trace(visitor); | 52 DOMWindowProperty::trace(visitor); |
| 54 } | 53 } |
| 55 | 54 |
| 56 unsigned History::length() const | 55 unsigned History::length() const |
| 57 { | 56 { |
| 58 if (!m_frame) | 57 if (!m_frame || !m_frame->loader().client()) |
| 59 return 0; | 58 return 0; |
| 60 if (!m_frame->page()) | 59 return m_frame->loader().client()->backForwardLength(); |
| 61 return 0; | |
| 62 return m_frame->page()->backForward().backForwardListCount(); | |
| 63 } | 60 } |
| 64 | 61 |
| 65 SerializedScriptValue* History::state() | 62 SerializedScriptValue* History::state() |
| 66 { | 63 { |
| 67 m_lastStateObjectRequested = stateInternal(); | 64 m_lastStateObjectRequested = stateInternal(); |
| 68 return m_lastStateObjectRequested.get(); | 65 return m_lastStateObjectRequested.get(); |
| 69 } | 66 } |
| 70 | 67 |
| 71 SerializedScriptValue* History::stateInternal() const | 68 SerializedScriptValue* History::stateInternal() const |
| 72 { | 69 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 94 go(context, -1); | 91 go(context, -1); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void History::forward(ExecutionContext* context) | 94 void History::forward(ExecutionContext* context) |
| 98 { | 95 { |
| 99 go(context, 1); | 96 go(context, 1); |
| 100 } | 97 } |
| 101 | 98 |
| 102 void History::go(ExecutionContext* context, int distance) | 99 void History::go(ExecutionContext* context, int distance) |
| 103 { | 100 { |
| 104 if (!m_frame) | 101 if (!m_frame || !m_frame->loader().client()) |
| 105 return; | 102 return; |
| 106 | 103 |
| 107 ASSERT(isMainThread()); | 104 ASSERT(isMainThread()); |
| 108 Document* activeDocument = toDocument(context); | 105 Document* activeDocument = toDocument(context); |
| 109 if (!activeDocument) | 106 if (!activeDocument) |
| 110 return; | 107 return; |
| 111 | 108 |
| 112 if (!activeDocument->canNavigate(*m_frame)) | 109 if (!activeDocument->canNavigate(*m_frame)) |
| 113 return; | 110 return; |
| 114 | 111 |
| 115 m_frame->navigationScheduler().scheduleHistoryNavigation(distance); | 112 if (distance) |
| 113 m_frame->loader().client()->navigateBackForward(distance); |
| 114 else |
| 115 m_frame->navigationScheduler().scheduleReload(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 KURL History::urlForState(const String& urlString) | 118 KURL History::urlForState(const String& urlString) |
| 119 { | 119 { |
| 120 Document* document = m_frame->document(); | 120 Document* document = m_frame->document(); |
| 121 | 121 |
| 122 if (urlString.isNull()) | 122 if (urlString.isNull()) |
| 123 return document->url(); | 123 return document->url(); |
| 124 if (urlString.isEmpty()) | 124 if (urlString.isEmpty()) |
| 125 return document->baseURL(); | 125 return document->baseURL(); |
| 126 | 126 |
| 127 return KURL(document->baseURL(), urlString); | 127 return KURL(document->baseURL(), urlString); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str
ing& /* title */, const String& urlString, FrameLoadType type, ExceptionState& e
xceptionState) | 130 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const Str
ing& /* title */, const String& urlString, FrameLoadType type, ExceptionState& e
xceptionState) |
| 131 { | 131 { |
| 132 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) | 132 if (!m_frame || !m_frame->page() || !m_frame->loader().documentLoader()) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 KURL fullURL = urlForState(urlString); | 135 KURL fullURL = urlForState(urlString); |
| 136 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest
(fullURL)) { | 136 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest
(fullURL)) { |
| 137 // 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. | 137 // 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. |
| 138 exceptionState.throwSecurityError("A history state object with URL '" +
fullURL.elidedString() + "' cannot be created in a document with origin '" + m_f
rame->document()->securityOrigin()->toString() + "'."); | 138 exceptionState.throwSecurityError("A history state object with URL '" +
fullURL.elidedString() + "' cannot be created in a document with origin '" + m_f
rame->document()->securityOrigin()->toString() + "'."); |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig
ationHistoryApi, data, type); | 141 m_frame->loader().updateForSameDocumentNavigation(fullURL, SameDocumentNavig
ationHistoryApi, data, type); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace blink | 144 } // namespace blink |
| OLD | NEW |