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 "platform/weborigin/SecurityPolicy.h"
33 #include "wtf/Assertions.h"
34 #include "wtf/CurrentTime.h"
35 #include "wtf/text/CString.h"
39 static long long generateSequenceNumber()
41 // Initialize to the current time to reduce the likelihood of generating
42 // identifiers that overlap with those from past/future browser sessions.
43 static long long next
= static_cast<long long>(currentTime() * 1000000.0);
47 HistoryItem::HistoryItem()
48 : m_pageScaleFactor(0)
49 , m_itemSequenceNumber(generateSequenceNumber())
50 , m_documentSequenceNumber(generateSequenceNumber())
51 , m_scrollRestorationType(ScrollRestorationAuto
)
55 HistoryItem::~HistoryItem()
59 const String
& HistoryItem::urlString() const
64 KURL
HistoryItem::url() const
66 return KURL(ParsedURLString
, m_urlString
);
69 const Referrer
& HistoryItem::referrer() const
74 const String
& HistoryItem::target() const
79 void HistoryItem::setURLString(const String
& urlString
)
81 if (m_urlString
!= urlString
)
82 m_urlString
= urlString
;
85 void HistoryItem::setURL(const KURL
& url
)
87 setURLString(url
.string());
90 void HistoryItem::setReferrer(const Referrer
& referrer
)
92 // This should be a RELEASE_ASSERT.
93 m_referrer
= SecurityPolicy::generateReferrer(referrer
.referrerPolicy
, url(), referrer
.referrer
);
96 void HistoryItem::setTarget(const String
& target
)
101 const FloatPoint
& HistoryItem::visualViewportScrollPoint() const
103 return m_visualViewportScrollPoint
;
106 void HistoryItem::setVisualViewportScrollPoint(const FloatPoint
& point
)
108 m_visualViewportScrollPoint
= point
;
111 const IntPoint
& HistoryItem::scrollPoint() const
113 return m_scrollPoint
;
116 void HistoryItem::setScrollPoint(const IntPoint
& point
)
118 m_scrollPoint
= point
;
121 float HistoryItem::pageScaleFactor() const
123 return m_pageScaleFactor
;
126 void HistoryItem::setPageScaleFactor(float scaleFactor
)
128 m_pageScaleFactor
= scaleFactor
;
131 void HistoryItem::setDocumentState(const Vector
<String
>& state
)
133 ASSERT(!m_documentState
);
134 m_documentStateVector
= state
;
137 void HistoryItem::setDocumentState(DocumentState
* state
)
139 m_documentState
= state
;
142 const Vector
<String
>& HistoryItem::documentState()
145 m_documentStateVector
= m_documentState
->toStateVector();
146 return m_documentStateVector
;
149 Vector
<String
> HistoryItem::getReferencedFilePaths()
151 return FormController::getReferencedFilePaths(documentState());
154 void HistoryItem::clearDocumentState()
156 m_documentState
.clear();
157 m_documentStateVector
.clear();
160 void HistoryItem::setStateObject(PassRefPtr
<SerializedScriptValue
> object
)
162 m_stateObject
= object
;
165 const AtomicString
& HistoryItem::formContentType() const
167 return m_formContentType
;
170 void HistoryItem::setFormInfoFromRequest(const ResourceRequest
& request
)
172 if (equalIgnoringCase(request
.httpMethod(), "POST")) {
173 // FIXME: Eventually we have to make this smart enough to handle the case where
174 // we have a stream for the body to handle the "data interspersed with files" feature.
175 m_formData
= request
.httpBody();
176 m_formContentType
= request
.httpContentType();
178 m_formData
= nullptr;
179 m_formContentType
= nullAtom
;
183 void HistoryItem::setFormData(PassRefPtr
<EncodedFormData
> formData
)
185 m_formData
= formData
;
188 void HistoryItem::setFormContentType(const AtomicString
& formContentType
)
190 m_formContentType
= formContentType
;
193 EncodedFormData
* HistoryItem::formData()
195 return m_formData
.get();
198 bool HistoryItem::isCurrentDocument(Document
* doc
) const
200 // FIXME: We should find a better way to check if this is the current document.
201 return equalIgnoringFragmentIdentifier(url(), doc
->url());
204 DEFINE_TRACE(HistoryItem
)
206 visitor
->trace(m_documentState
);