2 * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "PlatformString.h"
31 #include <wtf/HashMap.h>
32 #include <wtf/OwnPtr.h>
33 #include <wtf/PassOwnPtr.h>
34 #include <wtf/RefCounted.h>
37 #import <wtf/RetainPtr.h>
38 typedef struct objc_object* id;
44 #include <QDataStream>
55 class ResourceRequest;
56 class SerializedScriptValue;
58 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector;
60 extern void (*notifyHistoryItemChanged)(HistoryItem*);
62 enum VisitCountBehavior {
64 DoNotIncreaseVisitCount
67 class HistoryItem : public RefCounted<HistoryItem> {
68 friend class PageCache;
71 static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); }
72 static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, double lastVisited)
74 return adoptRef(new HistoryItem(urlString, title, lastVisited));
76 static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, double lastVisited)
78 return adoptRef(new HistoryItem(urlString, title, alternateTitle, lastVisited));
80 static PassRefPtr<HistoryItem> create(const KURL& url, const String& target, const String& parent, const String& title)
82 return adoptRef(new HistoryItem(url, target, parent, title));
87 PassRefPtr<HistoryItem> copy() const;
89 // Resets the HistoryItem to its initial state, as returned by create().
92 void encodeBackForwardTree(Encoder&) const;
93 static PassRefPtr<HistoryItem> decodeBackForwardTree(const String& urlString, const String& title, const String& originalURLString, Decoder&);
95 const String& originalURLString() const;
96 const String& urlString() const;
97 const String& title() const;
99 bool isInPageCache() const { return m_cachedPage; }
101 double lastVisitedTime() const;
103 void setAlternateTitle(const String& alternateTitle);
104 const String& alternateTitle() const;
106 const String& parent() const;
108 KURL originalURL() const;
109 const String& referrer() const;
110 const String& target() const;
111 bool isTargetItem() const;
113 FormData* formData();
114 String formContentType() const;
116 int visitCount() const;
117 bool lastVisitWasFailure() const { return m_lastVisitWasFailure; }
118 bool lastVisitWasHTTPNonGet() const { return m_lastVisitWasHTTPNonGet; }
120 void mergeAutoCompleteHints(HistoryItem* otherItem);
122 const IntPoint& scrollPoint() const;
123 void setScrollPoint(const IntPoint&);
124 void clearScrollPoint();
126 float pageScaleFactor() const;
127 void setPageScaleFactor(float);
129 const Vector<String>& documentState() const;
130 void setDocumentState(const Vector<String>&);
131 void clearDocumentState();
133 void setURL(const KURL&);
134 void setURLString(const String&);
135 void setOriginalURLString(const String&);
136 void setReferrer(const String&);
137 void setTarget(const String&);
138 void setParent(const String&);
139 void setTitle(const String&);
140 void setIsTargetItem(bool);
142 void setStateObject(PassRefPtr<SerializedScriptValue> object);
143 SerializedScriptValue* stateObject() const { return m_stateObject.get(); }
145 void setItemSequenceNumber(long long number) { m_itemSequenceNumber = number; }
146 long long itemSequenceNumber() const { return m_itemSequenceNumber; }
148 void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; }
149 long long documentSequenceNumber() const { return m_documentSequenceNumber; }
151 void setFormInfoFromRequest(const ResourceRequest&);
152 void setFormData(PassRefPtr<FormData>);
153 void setFormContentType(const String&);
155 void recordInitialVisit();
157 void setVisitCount(int);
158 void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; }
159 void setLastVisitWasHTTPNonGet(bool wasNotGet) { m_lastVisitWasHTTPNonGet = wasNotGet; }
161 void addChildItem(PassRefPtr<HistoryItem>);
162 void setChildItem(PassRefPtr<HistoryItem>);
163 HistoryItem* childItemWithTarget(const String&) const;
164 HistoryItem* childItemWithDocumentSequenceNumber(long long number) const;
165 HistoryItem* targetItem();
166 const HistoryItemVector& children() const;
167 bool hasChildren() const;
168 void clearChildren();
170 bool shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const;
171 bool hasSameFrames(HistoryItem* otherItem) const;
173 // This should not be called directly for HistoryItems that are already included
174 // in GlobalHistory. The WebKit api for this is to use -[WebHistory setLastVisitedTimeInterval:forItem:] instead.
175 void setLastVisitedTime(double);
176 void visited(const String& title, double time, VisitCountBehavior);
178 void addRedirectURL(const String&);
179 Vector<String>* redirectURLs() const;
180 void setRedirectURLs(PassOwnPtr<Vector<String> >);
182 bool isCurrentDocument(Document*) const;
185 id viewState() const;
186 void setViewState(id);
188 // Transient properties may be of any ObjC type. They are intended to be used to store state per back/forward list entry.
189 // The properties will not be persisted; when the history item is removed, the properties will be lost.
190 id getTransientProperty(const String&) const;
191 void setTransientProperty(const String&, id);
195 QVariant userData() const { return m_userData; }
196 void setUserData(const QVariant& userData) { m_userData = userData; }
198 bool restoreState(QDataStream& buffer, int version);
199 QDataStream& saveState(QDataStream& out, int version) const;
203 int showTree() const;
204 int showTreeWithIndent(unsigned indentLevel) const;
207 void adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weeklyCounts);
208 const Vector<int>& dailyVisitCounts() const { return m_dailyVisitCounts; }
209 const Vector<int>& weeklyVisitCounts() const { return m_weeklyVisitCounts; }
211 void markForFullStyleRecalc();
213 #if ENABLE(TIZEN_PAGE_CACHE)
214 void setViewZoomFactor(float zoomLevel) { m_zoomFactor = zoomLevel; }
215 float viewZoomFactor() { return m_zoomFactor; }
220 HistoryItem(const String& urlString, const String& title, double lastVisited);
221 HistoryItem(const String& urlString, const String& title, const String& alternateTitle, double lastVisited);
222 HistoryItem(const KURL& url, const String& frameName, const String& parent, const String& title);
224 HistoryItem(const HistoryItem&);
226 void padDailyCountsForNewVisit(double time);
227 void collapseDailyVisitsToWeekly();
228 void recordVisitAtTime(double, VisitCountBehavior = IncreaseVisitCount);
230 bool hasSameDocumentTree(HistoryItem* otherItem) const;
232 HistoryItem* findTargetItem();
234 void encodeBackForwardTreeNode(Encoder&) const;
236 /* When adding new member variables to this class, please notify the Qt team.
237 * qt/HistoryItemQt.cpp contains code to serialize history items.
241 String m_originalURLString;
246 String m_displayTitle;
248 double m_lastVisitedTime;
249 bool m_lastVisitWasHTTPNonGet;
251 IntPoint m_scrollPoint;
252 float m_pageScaleFactor;
253 Vector<String> m_documentState;
255 HistoryItemVector m_children;
257 bool m_lastVisitWasFailure;
260 Vector<int> m_dailyVisitCounts;
261 Vector<int> m_weeklyVisitCounts;
263 OwnPtr<Vector<String> > m_redirectURLs;
265 // If two HistoryItems have the same item sequence number, then they are
266 // clones of one another. Traversing history from one such HistoryItem to
267 // another is a no-op. HistoryItem clones are created for parent and
268 // sibling frames when only a subframe navigates.
269 int64_t m_itemSequenceNumber;
271 // If two HistoryItems have the same document sequence number, then they
272 // refer to the same instance of a document. Traversing history from one
273 // such HistoryItem to another preserves the document.
274 int64_t m_documentSequenceNumber;
276 // Support for HTML5 History
277 RefPtr<SerializedScriptValue> m_stateObject;
279 // info used to repost form data
280 RefPtr<FormData> m_formData;
281 String m_formContentType;
283 // PageCache controls these fields.
286 RefPtr<CachedPage> m_cachedPage;
289 RetainPtr<id> m_viewState;
290 OwnPtr<HashMap<String, RetainPtr<id> > > m_transientProperties;
297 #if ENABLE(TIZEN_PAGE_CACHE)
301 }; //class HistoryItem
303 } //namespace WebCore
306 // Outside the WebCore namespace for ease of invocation from gdb.
307 extern "C" int showTree(const WebCore::HistoryItem*);
310 #endif // HISTORYITEM_H