OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008, 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 inline HistoryItem::HistoryItem(const HistoryItem& item) | 61 inline HistoryItem::HistoryItem(const HistoryItem& item) |
62 : RefCounted<HistoryItem>() | 62 : RefCounted<HistoryItem>() |
63 , m_urlString(item.m_urlString) | 63 , m_urlString(item.m_urlString) |
64 , m_originalURLString(item.m_originalURLString) | 64 , m_originalURLString(item.m_originalURLString) |
65 , m_referrer(item.m_referrer) | 65 , m_referrer(item.m_referrer) |
66 , m_target(item.m_target) | 66 , m_target(item.m_target) |
67 , m_scrollPoint(item.m_scrollPoint) | 67 , m_scrollPoint(item.m_scrollPoint) |
68 , m_pageScaleFactor(item.m_pageScaleFactor) | 68 , m_pageScaleFactor(item.m_pageScaleFactor) |
| 69 , m_documentState(item.m_documentState) |
69 , m_itemSequenceNumber(item.m_itemSequenceNumber) | 70 , m_itemSequenceNumber(item.m_itemSequenceNumber) |
70 , m_documentSequenceNumber(item.m_documentSequenceNumber) | 71 , m_documentSequenceNumber(item.m_documentSequenceNumber) |
71 , m_targetFrameID(item.m_targetFrameID) | 72 , m_targetFrameID(item.m_targetFrameID) |
72 , m_stateObject(item.m_stateObject) | 73 , m_stateObject(item.m_stateObject) |
73 , m_formContentType(item.m_formContentType) | 74 , m_formContentType(item.m_formContentType) |
74 { | 75 { |
75 if (item.m_formData) | 76 if (item.m_formData) |
76 m_formData = item.m_formData->copy(); | 77 m_formData = item.m_formData->copy(); |
77 | 78 |
78 unsigned size = item.m_children.size(); | 79 unsigned size = item.m_children.size(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 m_documentState.clear(); | 202 m_documentState.clear(); |
202 } | 203 } |
203 | 204 |
204 void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object) | 205 void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object) |
205 { | 206 { |
206 m_stateObject = object; | 207 m_stateObject = object; |
207 } | 208 } |
208 | 209 |
209 void HistoryItem::addChildItem(PassRefPtr<HistoryItem> child) | 210 void HistoryItem::addChildItem(PassRefPtr<HistoryItem> child) |
210 { | 211 { |
211 ASSERT(!childItemWithTarget(child->target())); | |
212 m_children.append(child); | 212 m_children.append(child); |
213 } | 213 } |
214 | 214 |
215 void HistoryItem::setChildItem(PassRefPtr<HistoryItem> child) | |
216 { | |
217 unsigned size = m_children.size(); | |
218 for (unsigned i = 0; i < size; ++i) { | |
219 if (m_children[i]->target() == child->target()) { | |
220 m_children[i] = child; | |
221 return; | |
222 } | |
223 } | |
224 m_children.append(child); | |
225 } | |
226 | |
227 HistoryItem* HistoryItem::childItemWithTarget(const String& target) const | |
228 { | |
229 unsigned size = m_children.size(); | |
230 for (unsigned i = 0; i < size; ++i) { | |
231 if (m_children[i]->target() == target) | |
232 return m_children[i].get(); | |
233 } | |
234 return 0; | |
235 } | |
236 | |
237 HistoryItem* HistoryItem::childItemWithDocumentSequenceNumber(long long number)
const | |
238 { | |
239 unsigned size = m_children.size(); | |
240 for (unsigned i = 0; i < size; ++i) { | |
241 if (m_children[i]->documentSequenceNumber() == number) | |
242 return m_children[i].get(); | |
243 } | |
244 return 0; | |
245 } | |
246 | |
247 const HistoryItemVector& HistoryItem::children() const | 215 const HistoryItemVector& HistoryItem::children() const |
248 { | 216 { |
249 return m_children; | 217 return m_children; |
250 } | 218 } |
251 | 219 |
252 void HistoryItem::clearChildren() | 220 void HistoryItem::clearChildren() |
253 { | 221 { |
254 m_children.clear(); | 222 m_children.clear(); |
255 } | 223 } |
256 | 224 |
257 // We do same-document navigation if going to a different item and if either of
the following is true: | |
258 // - The other item corresponds to the same document (for history entries create
d via pushState or fragment changes). | |
259 // - The other item corresponds to the same set of documents, including frames (
for history entries created via regular navigation) | |
260 bool HistoryItem::shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const | |
261 { | |
262 if (this == otherItem) | |
263 return false; | |
264 | |
265 if (stateObject() || otherItem->stateObject()) | |
266 return documentSequenceNumber() == otherItem->documentSequenceNumber(); | |
267 | |
268 if ((url().hasFragmentIdentifier() || otherItem->url().hasFragmentIdentifier
()) && equalIgnoringFragmentIdentifier(url(), otherItem->url())) | |
269 return documentSequenceNumber() == otherItem->documentSequenceNumber(); | |
270 | |
271 return hasSameDocumentTree(otherItem); | |
272 } | |
273 | |
274 // Does a recursive check that this item and its descendants have the same | |
275 // document sequence numbers as the other item. | |
276 bool HistoryItem::hasSameDocumentTree(HistoryItem* otherItem) const | |
277 { | |
278 if (documentSequenceNumber() != otherItem->documentSequenceNumber()) | |
279 return false; | |
280 | |
281 if (children().size() != otherItem->children().size()) | |
282 return false; | |
283 | |
284 for (size_t i = 0; i < children().size(); i++) { | |
285 HistoryItem* child = children()[i].get(); | |
286 HistoryItem* otherChild = otherItem->childItemWithDocumentSequenceNumber
(child->documentSequenceNumber()); | |
287 if (!otherChild || !child->hasSameDocumentTree(otherChild)) | |
288 return false; | |
289 } | |
290 | |
291 return true; | |
292 } | |
293 | |
294 // Does a non-recursive check that this item and its immediate children have the | |
295 // same frames as the other item. | |
296 bool HistoryItem::hasSameFrames(HistoryItem* otherItem) const | |
297 { | |
298 if (target() != otherItem->target()) | |
299 return false; | |
300 | |
301 if (children().size() != otherItem->children().size()) | |
302 return false; | |
303 | |
304 for (size_t i = 0; i < children().size(); i++) { | |
305 if (!otherItem->childItemWithTarget(children()[i]->target())) | |
306 return false; | |
307 } | |
308 | |
309 return true; | |
310 } | |
311 | |
312 String HistoryItem::formContentType() const | 225 String HistoryItem::formContentType() const |
313 { | 226 { |
314 return m_formContentType; | 227 return m_formContentType; |
315 } | 228 } |
316 | 229 |
317 void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request) | 230 void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request) |
318 { | 231 { |
319 m_referrer = request.httpReferrer(); | 232 m_referrer = request.httpReferrer(); |
320 | 233 |
321 if (equalIgnoringCase(request.httpMethod(), "POST")) { | 234 if (equalIgnoringCase(request.httpMethod(), "POST")) { |
(...skipping 21 matching lines...) Expand all Loading... |
343 { | 256 { |
344 return m_formData.get(); | 257 return m_formData.get(); |
345 } | 258 } |
346 | 259 |
347 bool HistoryItem::isCurrentDocument(Document* doc) const | 260 bool HistoryItem::isCurrentDocument(Document* doc) const |
348 { | 261 { |
349 // FIXME: We should find a better way to check if this is the current docume
nt. | 262 // FIXME: We should find a better way to check if this is the current docume
nt. |
350 return equalIgnoringFragmentIdentifier(url(), doc->url()); | 263 return equalIgnoringFragmentIdentifier(url(), doc->url()); |
351 } | 264 } |
352 | 265 |
353 #ifndef NDEBUG | |
354 | |
355 int HistoryItem::showTree() const | |
356 { | |
357 return showTreeWithIndent(0); | |
358 } | |
359 | |
360 int HistoryItem::showTreeWithIndent(unsigned indentLevel) const | |
361 { | |
362 Vector<char> prefix; | |
363 for (unsigned i = 0; i < indentLevel; ++i) | |
364 prefix.append(" ", 2); | |
365 prefix.append("\0", 1); | |
366 | |
367 fprintf(stderr, "%s+-%s (%p)\n", prefix.data(), m_urlString.utf8().data(), t
his); | |
368 | |
369 int totalSubItems = 0; | |
370 for (unsigned i = 0; i < m_children.size(); ++i) | |
371 totalSubItems += m_children[i]->showTreeWithIndent(indentLevel + 1); | |
372 return totalSubItems + 1; | |
373 } | |
374 | |
375 #endif | |
376 | |
377 } // namespace WebCore | 266 } // namespace WebCore |
378 | 267 |
379 #ifndef NDEBUG | |
380 | |
381 int showTree(const WebCore::HistoryItem* item) | |
382 { | |
383 return item->showTree(); | |
384 } | |
385 | |
386 #endif | |
OLD | NEW |