2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "BackForwardController.h"
31 #include "ExceptionCode.h"
33 #include "FrameLoader.h"
34 #include "FrameLoaderClient.h"
35 #include "HistoryItem.h"
37 #include "SecurityOrigin.h"
38 #include "SerializedScriptValue.h"
39 #include <wtf/MainThread.h>
43 History::History(Frame* frame)
48 Frame* History::frame() const
53 void History::disconnectFrame()
58 unsigned History::length() const
64 return m_frame->page()->backForward()->count();
72 void History::back(ScriptExecutionContext* context)
77 void History::forward()
82 void History::forward(ScriptExecutionContext* context)
87 void History::go(int distance)
92 m_frame->navigationScheduler()->scheduleHistoryNavigation(distance);
95 void History::go(ScriptExecutionContext* context, int distance)
100 ASSERT(isMainThread());
101 Frame* activeFrame = static_cast<Document*>(context)->frame();
105 if (!activeFrame->loader()->shouldAllowNavigation(m_frame))
108 m_frame->navigationScheduler()->scheduleHistoryNavigation(distance);
111 KURL History::urlForState(const String& urlString)
113 KURL baseURL = m_frame->document()->baseURL();
114 if (urlString.isEmpty())
117 return KURL(baseURL, urlString);
120 void History::stateObjectAdded(PassRefPtr<SerializedScriptValue> data, const String& title, const String& urlString, StateObjectType stateObjectType, ExceptionCode& ec)
122 if (!m_frame || !m_frame->page())
125 KURL fullURL = urlForState(urlString);
126 if (!fullURL.isValid() || !m_frame->document()->securityOrigin()->canRequest(fullURL)) {
131 if (stateObjectType == StateObjectPush)
132 m_frame->loader()->history()->pushState(data, title, fullURL.string());
133 else if (stateObjectType == StateObjectReplace)
134 m_frame->loader()->history()->replaceState(data, title, fullURL.string());
136 if (!urlString.isEmpty())
137 m_frame->document()->updateURLForPushOrReplaceState(fullURL);
139 if (stateObjectType == StateObjectPush)
140 m_frame->loader()->client()->dispatchDidPushStateWithinPage();
141 else if (stateObjectType == StateObjectReplace)
142 m_frame->loader()->client()->dispatchDidReplaceStateWithinPage();
145 } // namespace WebCore