| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Initialize to the current time to reduce the likelihood of generating | 43 // Initialize to the current time to reduce the likelihood of generating |
| 44 // identifiers that overlap with those from past/future browser sessions. | 44 // identifiers that overlap with those from past/future browser sessions. |
| 45 static long long next = static_cast<long long>(currentTime() * 1000000.0); | 45 static long long next = static_cast<long long>(currentTime() * 1000000.0); |
| 46 return ++next; | 46 return ++next; |
| 47 } | 47 } |
| 48 | 48 |
| 49 HistoryItem::HistoryItem() | 49 HistoryItem::HistoryItem() |
| 50 : m_pageScaleFactor(0) | 50 : m_pageScaleFactor(0) |
| 51 , m_itemSequenceNumber(generateSequenceNumber()) | 51 , m_itemSequenceNumber(generateSequenceNumber()) |
| 52 , m_documentSequenceNumber(generateSequenceNumber()) | 52 , m_documentSequenceNumber(generateSequenceNumber()) |
| 53 , m_targetFrameID(0) |
| 53 { | 54 { |
| 54 } | 55 } |
| 55 | 56 |
| 56 HistoryItem::~HistoryItem() | 57 HistoryItem::~HistoryItem() |
| 57 { | 58 { |
| 58 } | 59 } |
| 59 | 60 |
| 60 inline HistoryItem::HistoryItem(const HistoryItem& item) | 61 inline HistoryItem::HistoryItem(const HistoryItem& item) |
| 61 : RefCounted<HistoryItem>() | 62 : RefCounted<HistoryItem>() |
| 62 , m_urlString(item.m_urlString) | 63 , m_urlString(item.m_urlString) |
| 63 , m_originalURLString(item.m_originalURLString) | 64 , m_originalURLString(item.m_originalURLString) |
| 64 , m_referrer(item.m_referrer) | 65 , m_referrer(item.m_referrer) |
| 65 , m_target(item.m_target) | 66 , m_target(item.m_target) |
| 66 , m_scrollPoint(item.m_scrollPoint) | 67 , m_scrollPoint(item.m_scrollPoint) |
| 67 , m_pageScaleFactor(item.m_pageScaleFactor) | 68 , m_pageScaleFactor(item.m_pageScaleFactor) |
| 69 , m_documentState(item.m_documentState) |
| 68 , m_itemSequenceNumber(item.m_itemSequenceNumber) | 70 , m_itemSequenceNumber(item.m_itemSequenceNumber) |
| 69 , m_documentSequenceNumber(item.m_documentSequenceNumber) | 71 , m_documentSequenceNumber(item.m_documentSequenceNumber) |
| 72 , m_targetFrameID(item.m_targetFrameID) |
| 73 , m_stateObject(item.m_stateObject) |
| 70 , m_formContentType(item.m_formContentType) | 74 , m_formContentType(item.m_formContentType) |
| 71 { | 75 { |
| 72 if (item.m_formData) | 76 if (item.m_formData) |
| 73 m_formData = item.m_formData->copy(); | 77 m_formData = item.m_formData->copy(); |
| 74 | 78 |
| 75 unsigned size = item.m_children.size(); | 79 unsigned size = item.m_children.size(); |
| 76 m_children.reserveInitialCapacity(size); | 80 m_children.reserveInitialCapacity(size); |
| 77 for (unsigned i = 0; i < size; ++i) | 81 for (unsigned i = 0; i < size; ++i) |
| 78 m_children.uncheckedAppend(item.m_children[i]->copy()); | 82 m_children.uncheckedAppend(item.m_children[i]->copy()); |
| 79 } | 83 } |
| 80 | 84 |
| 81 PassRefPtr<HistoryItem> HistoryItem::copy() const | 85 PassRefPtr<HistoryItem> HistoryItem::copy() const |
| 82 { | 86 { |
| 83 return adoptRef(new HistoryItem(*this)); | 87 return adoptRef(new HistoryItem(*this)); |
| 84 } | 88 } |
| 85 | 89 |
| 86 void HistoryItem::reset() | 90 void HistoryItem::reset() |
| 87 { | 91 { |
| 88 m_urlString = String(); | 92 m_urlString = String(); |
| 89 m_originalURLString = String(); | 93 m_originalURLString = String(); |
| 90 m_referrer = String(); | 94 m_referrer = String(); |
| 91 m_target = String(); | 95 m_target = String(); |
| 92 m_itemSequenceNumber = generateSequenceNumber(); | 96 m_itemSequenceNumber = generateSequenceNumber(); |
| 93 m_stateObject = 0; | 97 m_stateObject = 0; |
| 94 m_documentSequenceNumber = generateSequenceNumber(); | 98 m_documentSequenceNumber = generateSequenceNumber(); |
| 99 m_targetFrameID = 0; |
| 95 m_formData = 0; | 100 m_formData = 0; |
| 96 m_formContentType = String(); | 101 m_formContentType = String(); |
| 97 clearChildren(); | 102 clearChildren(); |
| 98 } | 103 } |
| 99 | 104 |
| 100 const String& HistoryItem::urlString() const | 105 const String& HistoryItem::urlString() const |
| 101 { | 106 { |
| 102 return m_urlString; | 107 return m_urlString; |
| 103 } | 108 } |
| 104 | 109 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 m_documentState.clear(); | 202 m_documentState.clear(); |
| 198 } | 203 } |
| 199 | 204 |
| 200 void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object) | 205 void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object) |
| 201 { | 206 { |
| 202 m_stateObject = object; | 207 m_stateObject = object; |
| 203 } | 208 } |
| 204 | 209 |
| 205 void HistoryItem::addChildItem(PassRefPtr<HistoryItem> child) | 210 void HistoryItem::addChildItem(PassRefPtr<HistoryItem> child) |
| 206 { | 211 { |
| 207 ASSERT(!childItemWithTarget(child->target())); | |
| 208 m_children.append(child); | 212 m_children.append(child); |
| 209 } | 213 } |
| 210 | 214 |
| 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 | 215 const HistoryItemVector& HistoryItem::children() const |
| 244 { | 216 { |
| 245 return m_children; | 217 return m_children; |
| 246 } | 218 } |
| 247 | 219 |
| 248 void HistoryItem::clearChildren() | 220 void HistoryItem::clearChildren() |
| 249 { | 221 { |
| 250 m_children.clear(); | 222 m_children.clear(); |
| 251 } | 223 } |
| 252 | 224 |
| 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 | 225 String HistoryItem::formContentType() const |
| 309 { | 226 { |
| 310 return m_formContentType; | 227 return m_formContentType; |
| 311 } | 228 } |
| 312 | 229 |
| 313 void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request) | 230 void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request) |
| 314 { | 231 { |
| 315 m_referrer = request.httpReferrer(); | 232 m_referrer = request.httpReferrer(); |
| 316 | 233 |
| 317 if (equalIgnoringCase(request.httpMethod(), "POST")) { | 234 if (equalIgnoringCase(request.httpMethod(), "POST")) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 339 { | 256 { |
| 340 return m_formData.get(); | 257 return m_formData.get(); |
| 341 } | 258 } |
| 342 | 259 |
| 343 bool HistoryItem::isCurrentDocument(Document* doc) const | 260 bool HistoryItem::isCurrentDocument(Document* doc) const |
| 344 { | 261 { |
| 345 // 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. |
| 346 return equalIgnoringFragmentIdentifier(url(), doc->url()); | 263 return equalIgnoringFragmentIdentifier(url(), doc->url()); |
| 347 } | 264 } |
| 348 | 265 |
| 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 | 266 } // namespace WebCore |
| 374 | 267 |
| 375 #ifndef NDEBUG | |
| 376 | |
| 377 int showTree(const WebCore::HistoryItem* item) | |
| 378 { | |
| 379 return item->showTree(); | |
| 380 } | |
| 381 | |
| 382 #endif | |
| OLD | NEW |