1 /* 2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef HistoryItem_h 28 #define HistoryItem_h 29 30 #include "bindings/v8/SerializedScriptValue.h" 31 #include "core/platform/graphics/IntPoint.h" 32 #include "wtf/RefCounted.h" 33 #include "wtf/text/WTFString.h" 34 35 namespace WebCore { 36 37 class Document; 38 class FormData; 39 class HistoryItem; 40 class Image; 41 class KURL; 42 class ResourceRequest; 43 44 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector; 45 46 class HistoryItem : public RefCounted<HistoryItem> { 47 public: 48 static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); } 49 static PassRefPtr<HistoryItem> create(const String& urlString) 50 { 51 return adoptRef(new HistoryItem(urlString)); 52 } 53 54 ~HistoryItem(); 55 56 PassRefPtr<HistoryItem> copy() const; 57 58 // Resets the HistoryItem to its initial state, as returned by create(). 59 void reset(); 60 61 const String& originalURLString() const; 62 const String& urlString() const; 63 const String& title() const; 64 65 double lastVisitedTime() const; 66 67 void setAlternateTitle(const String& alternateTitle); 68 const String& alternateTitle() const; 69 70 const String& parent() const; 71 KURL url() const; 72 KURL originalURL() const; 73 const String& referrer() const; 74 const String& target() const; 75 bool isTargetItem() const; 76 77 FormData* formData(); 78 String formContentType() const; 79 80 int visitCount() const; 81 82 const IntPoint& scrollPoint() const; 83 void setScrollPoint(const IntPoint&); 84 void clearScrollPoint(); 85 86 float pageScaleFactor() const; 87 void setPageScaleFactor(float); 88 89 const Vector<String>& documentState() const; 90 void setDocumentState(const Vector<String>&); 91 void clearDocumentState(); 92 93 void setURL(const KURL&); 94 void setURLString(const String&); 95 void setOriginalURLString(const String&); 96 void setReferrer(const String&); 97 void setTarget(const String&); 98 void setParent(const String&); 99 void setTitle(const String&); 100 void setIsTargetItem(bool); 101 102 void setStateObject(PassRefPtr<SerializedScriptValue> object); 103 SerializedScriptValue* stateObject() const { return m_stateObject.get(); } 104 105 void setItemSequenceNumber(long long number) { m_itemSequenceNumber = number; } 106 long long itemSequenceNumber() const { return m_itemSequenceNumber; } 107 108 void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; } 109 long long documentSequenceNumber() const { return m_documentSequenceNumber; } 110 111 void setFormInfoFromRequest(const ResourceRequest&); 112 void setFormData(PassRefPtr<FormData>); 113 void setFormContentType(const String&); 114 115 void setVisitCount(int); 116 117 void addChildItem(PassRefPtr<HistoryItem>); 118 void setChildItem(PassRefPtr<HistoryItem>); 119 HistoryItem* childItemWithTarget(const String&) const; 120 HistoryItem* childItemWithDocumentSequenceNumber(long long number) const; 121 const HistoryItemVector& children() const; 122 void clearChildren(); 123 bool isAncestorOf(const HistoryItem*) const; 124 125 bool shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const; 126 bool hasSameFrames(HistoryItem* otherItem) const; 127 128 void setLastVisitedTime(double); 129 130 bool isCurrentDocument(Document*) const; 131 132 #ifndef NDEBUG 133 int showTree() const; 134 int showTreeWithIndent(unsigned indentLevel) const; 135 #endif 136 137 private: 138 HistoryItem(); 139 explicit HistoryItem(const String& urlString); 140 141 explicit HistoryItem(const HistoryItem&); 142 143 void recordVisitAtTime(double); 144 145 bool hasSameDocumentTree(HistoryItem* otherItem) const; 146 147 String m_urlString; 148 String m_originalURLString; 149 String m_referrer; 150 String m_target; 151 String m_parent; 152 String m_title; 153 String m_displayTitle; 154 155 double m_lastVisitedTime; 156 157 IntPoint m_scrollPoint; 158 float m_pageScaleFactor; 159 Vector<String> m_documentState; 160 161 HistoryItemVector m_children; 162 163 bool m_isTargetItem; 164 int m_visitCount; 165 166 // If two HistoryItems have the same item sequence number, then they are 167 // clones of one another. Traversing history from one such HistoryItem to 168 // another is a no-op. HistoryItem clones are created for parent and 169 // sibling frames when only a subframe navigates. 170 int64_t m_itemSequenceNumber; 171 172 // If two HistoryItems have the same document sequence number, then they 173 // refer to the same instance of a document. Traversing history from one 174 // such HistoryItem to another preserves the document. 175 int64_t m_documentSequenceNumber; 176 177 // Support for HTML5 History 178 RefPtr<SerializedScriptValue> m_stateObject; 179 180 // info used to repost form data 181 RefPtr<FormData> m_formData; 182 String m_formContentType; 183 184 }; //class HistoryItem 185 186 } //namespace WebCore 187 188 #ifndef NDEBUG 189 // Outside the WebCore namespace for ease of invocation from gdb. 190 extern "C" int showTree(const WebCore::HistoryItem*); 191 #endif 192 193 #endif // HISTORYITEM_H 194