• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 
31 #include "config.h"
32 #include "WebHistoryItem.h"
33 
34 #include "FormData.h"
35 #include "HistoryItem.h"
36 #include "KURL.h"
37 
38 #include "WebHTTPBody.h"
39 #include "WebPoint.h"
40 #include "WebSerializedScriptValue.h"
41 #include "WebString.h"
42 #include "WebVector.h"
43 
44 using namespace WebCore;
45 
46 namespace WebKit {
47 
initialize()48 void WebHistoryItem::initialize()
49 {
50     m_private = HistoryItem::create();
51 }
52 
reset()53 void WebHistoryItem::reset()
54 {
55     m_private.reset();
56 }
57 
assign(const WebHistoryItem & other)58 void WebHistoryItem::assign(const WebHistoryItem& other)
59 {
60     m_private = other.m_private;
61 }
62 
urlString() const63 WebString WebHistoryItem::urlString() const
64 {
65     return m_private->urlString();
66 }
67 
setURLString(const WebString & url)68 void WebHistoryItem::setURLString(const WebString& url)
69 {
70     ensureMutable();
71     m_private->setURLString(KURL(ParsedURLString, url).string());
72 }
73 
originalURLString() const74 WebString WebHistoryItem::originalURLString() const
75 {
76     return m_private->originalURLString();
77 }
78 
setOriginalURLString(const WebString & originalURLString)79 void WebHistoryItem::setOriginalURLString(const WebString& originalURLString)
80 {
81     ensureMutable();
82     m_private->setOriginalURLString(originalURLString);
83 }
84 
referrer() const85 WebString WebHistoryItem::referrer() const
86 {
87     return m_private->referrer();
88 }
89 
setReferrer(const WebString & referrer)90 void WebHistoryItem::setReferrer(const WebString& referrer)
91 {
92     ensureMutable();
93     m_private->setReferrer(referrer);
94 }
95 
target() const96 WebString WebHistoryItem::target() const
97 {
98     return m_private->target();
99 }
100 
setTarget(const WebString & target)101 void WebHistoryItem::setTarget(const WebString& target)
102 {
103     ensureMutable();
104     m_private->setTarget(target);
105 }
106 
parent() const107 WebString WebHistoryItem::parent() const
108 {
109     return m_private->parent();
110 }
111 
setParent(const WebString & parent)112 void WebHistoryItem::setParent(const WebString& parent)
113 {
114     ensureMutable();
115     m_private->setParent(parent);
116 }
117 
title() const118 WebString WebHistoryItem::title() const
119 {
120     return m_private->title();
121 }
122 
setTitle(const WebString & title)123 void WebHistoryItem::setTitle(const WebString& title)
124 {
125     ensureMutable();
126     m_private->setTitle(title);
127 }
128 
alternateTitle() const129 WebString WebHistoryItem::alternateTitle() const
130 {
131     return m_private->alternateTitle();
132 }
133 
setAlternateTitle(const WebString & alternateTitle)134 void WebHistoryItem::setAlternateTitle(const WebString& alternateTitle)
135 {
136     ensureMutable();
137     m_private->setAlternateTitle(alternateTitle);
138 }
139 
lastVisitedTime() const140 double WebHistoryItem::lastVisitedTime() const
141 {
142     return m_private->lastVisitedTime();
143 }
144 
setLastVisitedTime(double lastVisitedTime)145 void WebHistoryItem::setLastVisitedTime(double lastVisitedTime)
146 {
147     ensureMutable();
148     // FIXME: setLastVisitedTime increments the visit count, so we have to
149     // correct for that.  Instead, we should have a back-door to just mutate
150     // the last visited time directly.
151     int count = m_private->visitCount();
152     m_private->setLastVisitedTime(lastVisitedTime);
153     m_private->setVisitCount(count);
154 }
155 
scrollOffset() const156 WebPoint WebHistoryItem::scrollOffset() const
157 {
158     return m_private->scrollPoint();
159 }
160 
setScrollOffset(const WebPoint & scrollOffset)161 void WebHistoryItem::setScrollOffset(const WebPoint& scrollOffset)
162 {
163     ensureMutable();
164     m_private->setScrollPoint(scrollOffset);
165 }
166 
isTargetItem() const167 bool WebHistoryItem::isTargetItem() const
168 {
169     return m_private->isTargetItem();
170 }
171 
setIsTargetItem(bool isTargetItem)172 void WebHistoryItem::setIsTargetItem(bool isTargetItem)
173 {
174     ensureMutable();
175     m_private->setIsTargetItem(isTargetItem);
176 }
177 
visitCount() const178 int WebHistoryItem::visitCount() const
179 {
180     return m_private->visitCount();
181 }
182 
setVisitCount(int count)183 void WebHistoryItem::setVisitCount(int count)
184 {
185     ensureMutable();
186     m_private->setVisitCount(count);
187 }
188 
documentState() const189 WebVector<WebString> WebHistoryItem::documentState() const
190 {
191     return m_private->documentState();
192 }
193 
setDocumentState(const WebVector<WebString> & state)194 void WebHistoryItem::setDocumentState(const WebVector<WebString>& state)
195 {
196     ensureMutable();
197     // FIXME: would be nice to avoid the intermediate copy
198     Vector<String> ds;
199     for (size_t i = 0; i < state.size(); ++i)
200         ds.append(state[i]);
201     m_private->setDocumentState(ds);
202 }
203 
itemSequenceNumber() const204 long long WebHistoryItem::itemSequenceNumber() const
205 {
206     return m_private->itemSequenceNumber();
207 }
208 
setItemSequenceNumber(long long itemSequenceNumber)209 void WebHistoryItem::setItemSequenceNumber(long long itemSequenceNumber)
210 {
211     ensureMutable();
212     m_private->setItemSequenceNumber(itemSequenceNumber);
213 }
214 
documentSequenceNumber() const215 long long WebHistoryItem::documentSequenceNumber() const
216 {
217     return m_private->documentSequenceNumber();
218 }
219 
setDocumentSequenceNumber(long long documentSequenceNumber)220 void WebHistoryItem::setDocumentSequenceNumber(long long documentSequenceNumber)
221 {
222     ensureMutable();
223     m_private->setDocumentSequenceNumber(documentSequenceNumber);
224 }
225 
stateObject() const226 WebSerializedScriptValue WebHistoryItem::stateObject() const
227 {
228     return WebSerializedScriptValue(m_private->stateObject());
229 }
230 
setStateObject(const WebSerializedScriptValue & object)231 void WebHistoryItem::setStateObject(const WebSerializedScriptValue& object)
232 {
233     ensureMutable();
234     m_private->setStateObject(object);
235 }
236 
httpContentType() const237 WebString WebHistoryItem::httpContentType() const
238 {
239     return m_private->formContentType();
240 }
241 
setHTTPContentType(const WebString & httpContentType)242 void WebHistoryItem::setHTTPContentType(const WebString& httpContentType)
243 {
244     ensureMutable();
245     m_private->setFormContentType(httpContentType);
246 }
247 
httpBody() const248 WebHTTPBody WebHistoryItem::httpBody() const
249 {
250     return WebHTTPBody(m_private->formData());
251 }
252 
setHTTPBody(const WebHTTPBody & httpBody)253 void WebHistoryItem::setHTTPBody(const WebHTTPBody& httpBody)
254 {
255     ensureMutable();
256     m_private->setFormData(httpBody);
257 }
258 
children() const259 WebVector<WebHistoryItem> WebHistoryItem::children() const
260 {
261     return m_private->children();
262 }
263 
setChildren(const WebVector<WebHistoryItem> & items)264 void WebHistoryItem::setChildren(const WebVector<WebHistoryItem>& items)
265 {
266     ensureMutable();
267     m_private->clearChildren();
268     for (size_t i = 0; i < items.size(); ++i)
269         m_private->addChildItem(items[i]);
270 }
271 
appendToChildren(const WebHistoryItem & item)272 void WebHistoryItem::appendToChildren(const WebHistoryItem& item)
273 {
274     ensureMutable();
275     m_private->addChildItem(item);
276 }
277 
WebHistoryItem(const PassRefPtr<HistoryItem> & item)278 WebHistoryItem::WebHistoryItem(const PassRefPtr<HistoryItem>& item)
279     : m_private(item)
280 {
281 }
282 
operator =(const PassRefPtr<HistoryItem> & item)283 WebHistoryItem& WebHistoryItem::operator=(const PassRefPtr<HistoryItem>& item)
284 {
285     m_private = item;
286     return *this;
287 }
288 
operator PassRefPtr<HistoryItem>() const289 WebHistoryItem::operator PassRefPtr<HistoryItem>() const
290 {
291     return m_private.get();
292 }
293 
ensureMutable()294 void WebHistoryItem::ensureMutable()
295 {
296     if (!m_private->hasOneRef())
297         m_private = m_private->copy();
298 }
299 
300 } // namespace WebKit
301