2 * Copyright (C) 2005, 2006, 2008, 2011 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.
27 #include "core/loader/HistoryItem.h"
29 #include "core/dom/Document.h"
30 #include "core/html/forms/FormController.h"
31 #include "platform/network/ResourceRequest.h"
32 #include "wtf/CurrentTime.h"
33 #include "wtf/text/CString.h"
37 static long long generateSequenceNumber()
39 // Initialize to the current time to reduce the likelihood of generating
40 // identifiers that overlap with those from past/future browser sessions.
41 static long long next = static_cast<long long>(currentTime() * 1000000.0);
45 HistoryItem::HistoryItem()
46 : m_pageScaleFactor(0)
47 , m_itemSequenceNumber(generateSequenceNumber())
48 , m_documentSequenceNumber(generateSequenceNumber())
49 , m_frameSequenceNumber(generateSequenceNumber())
53 HistoryItem::~HistoryItem()
57 void HistoryItem::generateNewItemSequenceNumber()
59 m_itemSequenceNumber = generateSequenceNumber();
62 void HistoryItem::generateNewDocumentSequenceNumber()
64 m_documentSequenceNumber = generateSequenceNumber();
67 const String& HistoryItem::urlString() const
72 KURL HistoryItem::url() const
74 return KURL(ParsedURLString, m_urlString);
77 const Referrer& HistoryItem::referrer() const
82 const String& HistoryItem::target() const
87 void HistoryItem::setURLString(const String& urlString)
89 if (m_urlString != urlString)
90 m_urlString = urlString;
93 void HistoryItem::setURL(const KURL& url)
95 setURLString(url.string());
98 void HistoryItem::setReferrer(const Referrer& referrer)
100 m_referrer = referrer;
103 void HistoryItem::setTarget(const String& target)
108 const FloatPoint& HistoryItem::pinchViewportScrollPoint() const
110 return m_pinchViewportScrollPoint;
113 void HistoryItem::setPinchViewportScrollPoint(const FloatPoint& point)
115 m_pinchViewportScrollPoint = point;
118 const IntPoint& HistoryItem::scrollPoint() const
120 return m_scrollPoint;
123 void HistoryItem::setScrollPoint(const IntPoint& point)
125 m_scrollPoint = point;
128 void HistoryItem::clearScrollPoint()
130 m_scrollPoint = IntPoint();
131 m_pinchViewportScrollPoint = FloatPoint();
134 float HistoryItem::pageScaleFactor() const
136 return m_pageScaleFactor;
139 void HistoryItem::setPageScaleFactor(float scaleFactor)
141 m_pageScaleFactor = scaleFactor;
144 void HistoryItem::setDocumentState(const Vector<String>& state)
146 ASSERT(!m_documentState);
147 m_documentStateVector = state;
150 void HistoryItem::setDocumentState(DocumentState* state)
152 m_documentState = state;
155 const Vector<String>& HistoryItem::documentState()
158 m_documentStateVector = m_documentState->toStateVector();
159 return m_documentStateVector;
162 Vector<String> HistoryItem::getReferencedFilePaths()
164 return FormController::getReferencedFilePaths(documentState());
167 void HistoryItem::clearDocumentState()
169 m_documentState.clear();
170 m_documentStateVector.clear();
173 void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object)
175 m_stateObject = object;
178 const AtomicString& HistoryItem::formContentType() const
180 return m_formContentType;
183 void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request)
185 if (equalIgnoringCase(request.httpMethod(), "POST")) {
186 // FIXME: Eventually we have to make this smart enough to handle the case where
187 // we have a stream for the body to handle the "data interspersed with files" feature.
188 m_formData = request.httpBody();
189 m_formContentType = request.httpContentType();
191 m_formData = nullptr;
192 m_formContentType = nullAtom;
196 void HistoryItem::setFormData(PassRefPtr<FormData> formData)
198 m_formData = formData;
201 void HistoryItem::setFormContentType(const AtomicString& formContentType)
203 m_formContentType = formContentType;
206 FormData* HistoryItem::formData()
208 return m_formData.get();
211 bool HistoryItem::isCurrentDocument(Document* doc) const
213 // FIXME: We should find a better way to check if this is the current document.
214 return equalIgnoringFragmentIdentifier(url(), doc->url());
217 void HistoryItem::trace(Visitor* visitor)
219 visitor->trace(m_documentState);