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