OLD | NEW |
| (Empty) |
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 "WebString.h" | |
41 #include "WebVector.h" | |
42 | |
43 using namespace WebCore; | |
44 | |
45 namespace WebKit { | |
46 | |
47 class WebHistoryItemPrivate : public HistoryItem { | |
48 }; | |
49 | |
50 void WebHistoryItem::initialize() | |
51 { | |
52 assign(static_cast<WebHistoryItemPrivate*>(HistoryItem::create().releaseRef())); | |
53 } | |
54 | |
55 void WebHistoryItem::reset() | |
56 { | |
57 assign(0); | |
58 } | |
59 | |
60 void WebHistoryItem::assign(const WebHistoryItem& other) | |
61 { | |
62 WebHistoryItemPrivate* p = const_cast<WebHistoryItemPrivate*>(other.m_private); | |
63 if (p) | |
64 p->ref(); | |
65 assign(p); | |
66 } | |
67 | |
68 WebString WebHistoryItem::urlString() const | |
69 { | |
70 ASSERT(!isNull()); | |
71 return m_private->urlString(); | |
72 } | |
73 | |
74 void WebHistoryItem::setURLString(const WebString& url) | |
75 { | |
76 ensureMutable(); | |
77 m_private->setURLString(KURL(ParsedURLString, url).string()); | |
78 } | |
79 | |
80 WebString WebHistoryItem::originalURLString() const | |
81 { | |
82 ASSERT(!isNull()); | |
83 return m_private->originalURLString(); | |
84 } | |
85 | |
86 void WebHistoryItem::setOriginalURLString(const WebString& originalURLString) | |
87 { | |
88 ensureMutable(); | |
89 m_private->setOriginalURLString(originalURLString); | |
90 } | |
91 | |
92 WebString WebHistoryItem::referrer() const | |
93 { | |
94 ASSERT(!isNull()); | |
95 return m_private->referrer(); | |
96 } | |
97 | |
98 void WebHistoryItem::setReferrer(const WebString& referrer) | |
99 { | |
100 ensureMutable(); | |
101 m_private->setReferrer(referrer); | |
102 } | |
103 | |
104 WebString WebHistoryItem::target() const | |
105 { | |
106 ASSERT(!isNull()); | |
107 return m_private->target(); | |
108 } | |
109 | |
110 void WebHistoryItem::setTarget(const WebString& target) | |
111 { | |
112 ensureMutable(); | |
113 m_private->setTarget(target); | |
114 } | |
115 | |
116 WebString WebHistoryItem::parent() const | |
117 { | |
118 ASSERT(!isNull()); | |
119 return m_private->parent(); | |
120 } | |
121 | |
122 void WebHistoryItem::setParent(const WebString& parent) | |
123 { | |
124 ensureMutable(); | |
125 m_private->setParent(parent); | |
126 } | |
127 | |
128 WebString WebHistoryItem::title() const | |
129 { | |
130 ASSERT(!isNull()); | |
131 return m_private->title(); | |
132 } | |
133 | |
134 void WebHistoryItem::setTitle(const WebString& title) | |
135 { | |
136 ensureMutable(); | |
137 m_private->setTitle(title); | |
138 } | |
139 | |
140 WebString WebHistoryItem::alternateTitle() const | |
141 { | |
142 ASSERT(!isNull()); | |
143 return m_private->alternateTitle(); | |
144 } | |
145 | |
146 void WebHistoryItem::setAlternateTitle(const WebString& alternateTitle) | |
147 { | |
148 ensureMutable(); | |
149 m_private->setAlternateTitle(alternateTitle); | |
150 } | |
151 | |
152 double WebHistoryItem::lastVisitedTime() const | |
153 { | |
154 ASSERT(!isNull()); | |
155 return m_private->lastVisitedTime(); | |
156 } | |
157 | |
158 void WebHistoryItem::setLastVisitedTime(double lastVisitedTime) | |
159 { | |
160 ensureMutable(); | |
161 // FIXME: setLastVisitedTime increments the visit count, so we have to | |
162 // correct for that. Instead, we should have a back-door to just mutate | |
163 // the last visited time directly. | |
164 int count = m_private->visitCount(); | |
165 m_private->setLastVisitedTime(lastVisitedTime); | |
166 m_private->setVisitCount(count); | |
167 } | |
168 | |
169 WebPoint WebHistoryItem::scrollOffset() const | |
170 { | |
171 ASSERT(!isNull()); | |
172 return m_private->scrollPoint(); | |
173 } | |
174 | |
175 void WebHistoryItem::setScrollOffset(const WebPoint& scrollOffset) | |
176 { | |
177 ensureMutable(); | |
178 m_private->setScrollPoint(scrollOffset); | |
179 } | |
180 | |
181 bool WebHistoryItem::isTargetItem() const | |
182 { | |
183 ASSERT(!isNull()); | |
184 return m_private->isTargetItem(); | |
185 } | |
186 | |
187 void WebHistoryItem::setIsTargetItem(bool isTargetItem) | |
188 { | |
189 ensureMutable(); | |
190 m_private->setIsTargetItem(isTargetItem); | |
191 } | |
192 | |
193 int WebHistoryItem::visitCount() const | |
194 { | |
195 ASSERT(!isNull()); | |
196 return m_private->visitCount(); | |
197 } | |
198 | |
199 void WebHistoryItem::setVisitCount(int count) | |
200 { | |
201 ensureMutable(); | |
202 m_private->setVisitCount(count); | |
203 } | |
204 | |
205 WebVector<WebString> WebHistoryItem::documentState() const | |
206 { | |
207 ASSERT(!isNull()); | |
208 return m_private->documentState(); | |
209 } | |
210 | |
211 void WebHistoryItem::setDocumentState(const WebVector<WebString>& state) | |
212 { | |
213 ensureMutable(); | |
214 // FIXME: would be nice to avoid the intermediate copy | |
215 Vector<String> ds; | |
216 for (size_t i = 0; i < state.size(); ++i) | |
217 ds.append(state[i]); | |
218 m_private->setDocumentState(ds); | |
219 } | |
220 | |
221 WebString WebHistoryItem::httpContentType() const | |
222 { | |
223 ASSERT(!isNull()); | |
224 return m_private->formContentType(); | |
225 } | |
226 | |
227 void WebHistoryItem::setHTTPContentType(const WebString& httpContentType) | |
228 { | |
229 ensureMutable(); | |
230 m_private->setFormContentType(httpContentType); | |
231 } | |
232 | |
233 WebHTTPBody WebHistoryItem::httpBody() const | |
234 { | |
235 ASSERT(!isNull()); | |
236 return WebHTTPBody(m_private->formData()); | |
237 } | |
238 | |
239 void WebHistoryItem::setHTTPBody(const WebHTTPBody& httpBody) | |
240 { | |
241 ensureMutable(); | |
242 m_private->setFormData(httpBody); | |
243 } | |
244 | |
245 WebVector<WebHistoryItem> WebHistoryItem::children() const | |
246 { | |
247 ASSERT(!isNull()); | |
248 return m_private->children(); | |
249 } | |
250 | |
251 void WebHistoryItem::setChildren(const WebVector<WebHistoryItem>& items) | |
252 { | |
253 ensureMutable(); | |
254 m_private->clearChildren(); | |
255 for (size_t i = 0; i < items.size(); ++i) | |
256 m_private->addChildItem(items[i]); | |
257 } | |
258 | |
259 void WebHistoryItem::appendToChildren(const WebHistoryItem& item) | |
260 { | |
261 ensureMutable(); | |
262 m_private->addChildItem(item); | |
263 } | |
264 | |
265 WebHistoryItem::WebHistoryItem(const PassRefPtr<HistoryItem>& item) | |
266 : m_private(static_cast<WebHistoryItemPrivate*>(item.releaseRef())) | |
267 { | |
268 } | |
269 | |
270 WebHistoryItem& WebHistoryItem::operator=(const PassRefPtr<HistoryItem>& item) | |
271 { | |
272 assign(static_cast<WebHistoryItemPrivate*>(item.releaseRef())); | |
273 return *this; | |
274 } | |
275 | |
276 WebHistoryItem::operator PassRefPtr<HistoryItem>() const | |
277 { | |
278 return m_private; | |
279 } | |
280 | |
281 void WebHistoryItem::assign(WebHistoryItemPrivate* p) | |
282 { | |
283 // p is already ref'd for us by the caller | |
284 if (m_private) | |
285 m_private->deref(); | |
286 m_private = p; | |
287 } | |
288 | |
289 void WebHistoryItem::ensureMutable() | |
290 { | |
291 ASSERT(!isNull()); | |
292 if (!m_private->hasOneRef()) | |
293 assign(static_cast<WebHistoryItemPrivate*>(m_private->copy().releaseRef())); | |
294 } | |
295 | |
296 } // namespace WebKit | |
OLD | NEW |