2 * Copyright (C) 2009 Google 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 are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "public/web/WebHistoryItem.h"
34 #include "bindings/core/v8/SerializedScriptValue.h"
35 #include "core/loader/HistoryItem.h"
36 #include "platform/network/EncodedFormData.h"
37 #include "platform/weborigin/KURL.h"
38 #include "public/platform/WebFloatPoint.h"
39 #include "public/platform/WebHTTPBody.h"
40 #include "public/platform/WebPoint.h"
41 #include "public/platform/WebString.h"
42 #include "public/platform/WebVector.h"
43 #include "public/web/WebSerializedScriptValue.h"
44 #include "wtf/text/StringHash.h"
48 void WebHistoryItem::initialize()
50 m_private
= HistoryItem::create();
53 void WebHistoryItem::reset()
58 void WebHistoryItem::assign(const WebHistoryItem
& other
)
60 m_private
= other
.m_private
;
63 WebString
WebHistoryItem::urlString() const
65 return m_private
->urlString();
68 void WebHistoryItem::setURLString(const WebString
& url
)
70 m_private
->setURLString(KURL(ParsedURLString
, url
).string());
73 WebString
WebHistoryItem::referrer() const
75 return m_private
->referrer().referrer
;
78 WebReferrerPolicy
WebHistoryItem::referrerPolicy() const
80 return static_cast<WebReferrerPolicy
>(m_private
->referrer().referrerPolicy
);
83 void WebHistoryItem::setReferrer(const WebString
& referrer
, WebReferrerPolicy referrerPolicy
)
85 m_private
->setReferrer(Referrer(referrer
, static_cast<ReferrerPolicy
>(referrerPolicy
)));
88 WebString
WebHistoryItem::target() const
90 return m_private
->target();
93 void WebHistoryItem::setTarget(const WebString
& target
)
95 m_private
->setTarget(target
);
98 WebFloatPoint
WebHistoryItem::visualViewportScrollOffset() const
100 return m_private
->visualViewportScrollPoint();
103 void WebHistoryItem::setVisualViewportScrollOffset(const WebFloatPoint
& scrollOffset
)
105 m_private
->setVisualViewportScrollPoint(scrollOffset
);
108 WebFloatPoint
WebHistoryItem::pinchViewportScrollOffset() const
110 return visualViewportScrollOffset();
113 void WebHistoryItem::setPinchViewportScrollOffset(const WebFloatPoint
& scrollOffset
)
115 setVisualViewportScrollOffset(scrollOffset
);
118 WebPoint
WebHistoryItem::scrollOffset() const
120 return m_private
->scrollPoint();
123 void WebHistoryItem::setScrollOffset(const WebPoint
& scrollOffset
)
125 m_private
->setScrollPoint(scrollOffset
);
128 float WebHistoryItem::pageScaleFactor() const
130 return m_private
->pageScaleFactor();
133 void WebHistoryItem::setPageScaleFactor(float scale
)
135 m_private
->setPageScaleFactor(scale
);
138 WebVector
<WebString
> WebHistoryItem::documentState() const
140 return m_private
->documentState();
143 void WebHistoryItem::setDocumentState(const WebVector
<WebString
>& state
)
145 // FIXME: would be nice to avoid the intermediate copy
147 for (size_t i
= 0; i
< state
.size(); ++i
)
149 m_private
->setDocumentState(ds
);
152 long long WebHistoryItem::itemSequenceNumber() const
154 return m_private
->itemSequenceNumber();
157 void WebHistoryItem::setItemSequenceNumber(long long itemSequenceNumber
)
159 m_private
->setItemSequenceNumber(itemSequenceNumber
);
162 long long WebHistoryItem::documentSequenceNumber() const
164 return m_private
->documentSequenceNumber();
167 void WebHistoryItem::setDocumentSequenceNumber(long long documentSequenceNumber
)
169 m_private
->setDocumentSequenceNumber(documentSequenceNumber
);
172 WebHistoryScrollRestorationType
WebHistoryItem::scrollRestorationType() const
174 return static_cast<WebHistoryScrollRestorationType
>(m_private
->scrollRestorationType());
177 void WebHistoryItem::setScrollRestorationType(WebHistoryScrollRestorationType type
)
179 m_private
->setScrollRestorationType(static_cast<HistoryScrollRestorationType
>(type
));
182 WebSerializedScriptValue
WebHistoryItem::stateObject() const
184 return WebSerializedScriptValue(m_private
->stateObject());
187 void WebHistoryItem::setStateObject(const WebSerializedScriptValue
& object
)
189 m_private
->setStateObject(object
);
192 WebString
WebHistoryItem::httpContentType() const
194 return m_private
->formContentType();
197 void WebHistoryItem::setHTTPContentType(const WebString
& httpContentType
)
199 m_private
->setFormContentType(httpContentType
);
202 WebHTTPBody
WebHistoryItem::httpBody() const
204 return WebHTTPBody(m_private
->formData());
207 void WebHistoryItem::setHTTPBody(const WebHTTPBody
& httpBody
)
209 m_private
->setFormData(httpBody
);
212 WebVector
<WebString
> WebHistoryItem::getReferencedFilePaths() const
214 HashSet
<String
> filePaths
;
215 const EncodedFormData
* formData
= m_private
->formData();
217 for (size_t i
= 0; i
< formData
->elements().size(); ++i
) {
218 const FormDataElement
& element
= formData
->elements()[i
];
219 if (element
.m_type
== FormDataElement::encodedFile
)
220 filePaths
.add(element
.m_filename
);
224 const Vector
<String
>& referencedFilePaths
= m_private
->getReferencedFilePaths();
225 for (size_t i
= 0; i
< referencedFilePaths
.size(); ++i
)
226 filePaths
.add(referencedFilePaths
[i
]);
228 Vector
<String
> results
;
229 copyToVector(filePaths
, results
);
233 WebHistoryItem::WebHistoryItem(const PassRefPtrWillBeRawPtr
<HistoryItem
>& item
)
238 WebHistoryItem
& WebHistoryItem::operator=(const PassRefPtrWillBeRawPtr
<HistoryItem
>& item
)
244 WebHistoryItem::operator PassRefPtrWillBeRawPtr
<HistoryItem
>() const
246 return m_private
.get();