• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #ifndef HistoryItem_h
27 #define HistoryItem_h
28 
29 #include "IntPoint.h"
30 #include "PlatformString.h"
31 #include "SerializedScriptValue.h"
32 #include <wtf/OwnPtr.h>
33 #include <wtf/PassOwnPtr.h>
34 
35 #if PLATFORM(MAC)
36 #import <wtf/RetainPtr.h>
37 typedef struct objc_object* id;
38 #endif
39 
40 #if PLATFORM(QT)
41 #include <QVariant>
42 #include <QByteArray>
43 #include <QDataStream>
44 #endif
45 
46 #if PLATFORM(ANDROID)
47 #include "AndroidWebHistoryBridge.h"
48 #endif
49 
50 namespace WebCore {
51 
52 class CachedPage;
53 class Document;
54 class FormData;
55 class HistoryItem;
56 class Image;
57 class KURL;
58 class ResourceRequest;
59 
60 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector;
61 
62 extern void (*notifyHistoryItemChanged)(HistoryItem*);
63 
64 enum VisitCountBehavior {
65     IncreaseVisitCount,
66     DoNotIncreaseVisitCount
67 };
68 
69 class HistoryItem : public RefCounted<HistoryItem> {
70     friend class PageCache;
71 
72 public:
create()73     static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); }
create(const String & urlString,const String & title,double lastVisited)74     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, double lastVisited)
75     {
76         return adoptRef(new HistoryItem(urlString, title, lastVisited));
77     }
create(const String & urlString,const String & title,const String & alternateTitle,double lastVisited)78     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, double lastVisited)
79     {
80         return adoptRef(new HistoryItem(urlString, title, alternateTitle, lastVisited));
81     }
create(const KURL & url,const String & target,const String & parent,const String & title)82     static PassRefPtr<HistoryItem> create(const KURL& url, const String& target, const String& parent, const String& title)
83     {
84         return adoptRef(new HistoryItem(url, target, parent, title));
85     }
86 
87     ~HistoryItem();
88 
89     PassRefPtr<HistoryItem> copy() const;
90 
91     const String& originalURLString() const;
92     const String& urlString() const;
93     const String& title() const;
94 
isInPageCache()95     bool isInPageCache() const { return m_cachedPage; }
96 
97     double lastVisitedTime() const;
98 
99     void setAlternateTitle(const String& alternateTitle);
100     const String& alternateTitle() const;
101 
102     Image* icon() const;
103 
104     const String& parent() const;
105     KURL url() const;
106     KURL originalURL() const;
107     const String& referrer() const;
108     const String& target() const;
109     bool isTargetItem() const;
110 
111     FormData* formData();
112     String formContentType() const;
113 
114     int visitCount() const;
lastVisitWasFailure()115     bool lastVisitWasFailure() const { return m_lastVisitWasFailure; }
lastVisitWasHTTPNonGet()116     bool lastVisitWasHTTPNonGet() const { return m_lastVisitWasHTTPNonGet; }
117 
118     void mergeAutoCompleteHints(HistoryItem* otherItem);
119 
120     const IntPoint& scrollPoint() const;
121     void setScrollPoint(const IntPoint&);
122     void clearScrollPoint();
123     const Vector<String>& documentState() const;
124     void setDocumentState(const Vector<String>&);
125     void clearDocumentState();
126 
127     void setURL(const KURL&);
128     void setURLString(const String&);
129     void setOriginalURLString(const String&);
130     void setReferrer(const String&);
131     void setTarget(const String&);
132     void setParent(const String&);
133     void setTitle(const String&);
134     void setIsTargetItem(bool);
135 
136     void setStateObject(PassRefPtr<SerializedScriptValue> object);
stateObject()137     SerializedScriptValue* stateObject() const { return m_stateObject.get(); }
138 
setDocumentSequenceNumber(long long number)139     void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; }
documentSequenceNumber()140     long long documentSequenceNumber() const { return m_documentSequenceNumber; }
141 
142     void setFormInfoFromRequest(const ResourceRequest&);
143     void setFormData(PassRefPtr<FormData>);
144     void setFormContentType(const String&);
145 
146     void recordInitialVisit();
147 
148     void setVisitCount(int);
setLastVisitWasFailure(bool wasFailure)149     void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; }
setLastVisitWasHTTPNonGet(bool wasNotGet)150     void setLastVisitWasHTTPNonGet(bool wasNotGet) { m_lastVisitWasHTTPNonGet = wasNotGet; }
151 
152     void addChildItem(PassRefPtr<HistoryItem>);
153     void setChildItem(PassRefPtr<HistoryItem>);
154     HistoryItem* childItemWithTarget(const String&) const;
155     HistoryItem* targetItem();
156     const HistoryItemVector& children() const;
157     bool hasChildren() const;
158     void clearChildren();
159 
160     // This should not be called directly for HistoryItems that are already included
161     // in GlobalHistory. The WebKit api for this is to use -[WebHistory setLastVisitedTimeInterval:forItem:] instead.
162     void setLastVisitedTime(double);
163     void visited(const String& title, double time, VisitCountBehavior);
164 
165     void addRedirectURL(const String&);
166     Vector<String>* redirectURLs() const;
167     void setRedirectURLs(PassOwnPtr<Vector<String> >);
168 
169     bool isCurrentDocument(Document*) const;
170 
171 #if PLATFORM(MAC)
172     id viewState() const;
173     void setViewState(id);
174 
175     // Transient properties may be of any ObjC type.  They are intended to be used to store state per back/forward list entry.
176     // The properties will not be persisted; when the history item is removed, the properties will be lost.
177     id getTransientProperty(const String&) const;
178     void setTransientProperty(const String&, id);
179 #endif
180 
181 #if PLATFORM(QT)
userData()182     QVariant userData() const { return m_userData; }
setUserData(const QVariant & userData)183     void setUserData(const QVariant& userData) { m_userData = userData; }
184 
185     bool restoreState(QDataStream& buffer, int version);
186     QDataStream& saveState(QDataStream& out, int version) const;
187 #endif
188 
189 #if PLATFORM(ANDROID)
190     void setBridge(AndroidWebHistoryBridge* bridge);
191     AndroidWebHistoryBridge* bridge() const;
192 #endif
193 
194 #ifndef NDEBUG
195     int showTree() const;
196     int showTreeWithIndent(unsigned indentLevel) const;
197 #endif
198 
199     void adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weeklyCounts);
dailyVisitCounts()200     const Vector<int>& dailyVisitCounts() const { return m_dailyVisitCounts; }
weeklyVisitCounts()201     const Vector<int>& weeklyVisitCounts() const { return m_weeklyVisitCounts; }
202 
203 private:
204     HistoryItem();
205     HistoryItem(const String& urlString, const String& title, double lastVisited);
206     HistoryItem(const String& urlString, const String& title, const String& alternateTitle, double lastVisited);
207     HistoryItem(const KURL& url, const String& frameName, const String& parent, const String& title);
208 
209     HistoryItem(const HistoryItem&);
210 
211     void padDailyCountsForNewVisit(double time);
212     void collapseDailyVisitsToWeekly();
213     void recordVisitAtTime(double, VisitCountBehavior = IncreaseVisitCount);
214 
215     HistoryItem* findTargetItem();
216 
217     /* When adding new member variables to this class, please notify the Qt team.
218      * qt/HistoryItemQt.cpp contains code to serialize history items.
219      */
220 
221     String m_urlString;
222     String m_originalURLString;
223     String m_referrer;
224     String m_target;
225     String m_parent;
226     String m_title;
227     String m_displayTitle;
228 
229     double m_lastVisitedTime;
230     bool m_lastVisitWasHTTPNonGet;
231 
232     IntPoint m_scrollPoint;
233     Vector<String> m_documentState;
234 
235     HistoryItemVector m_children;
236 
237     bool m_lastVisitWasFailure;
238     bool m_isTargetItem;
239     int m_visitCount;
240     Vector<int> m_dailyVisitCounts;
241     Vector<int> m_weeklyVisitCounts;
242 
243     OwnPtr<Vector<String> > m_redirectURLs;
244 
245     // Support for HTML5 History
246     RefPtr<SerializedScriptValue> m_stateObject;
247     long long m_documentSequenceNumber;
248 
249     // info used to repost form data
250     RefPtr<FormData> m_formData;
251     String m_formContentType;
252 
253     // PageCache controls these fields.
254     HistoryItem* m_next;
255     HistoryItem* m_prev;
256     RefPtr<CachedPage> m_cachedPage;
257 
258 #if PLATFORM(MAC)
259     RetainPtr<id> m_viewState;
260     OwnPtr<HashMap<String, RetainPtr<id> > > m_transientProperties;
261 #endif
262 
263 #if PLATFORM(QT)
264     QVariant m_userData;
265 #endif
266 
267 #if PLATFORM(ANDROID)
268     RefPtr<AndroidWebHistoryBridge> m_bridge;
269 #endif
270 
271 }; //class HistoryItem
272 
273 } //namespace WebCore
274 
275 #ifndef NDEBUG
276 // Outside the WebCore namespace for ease of invocation from gdb.
277 extern "C" int showTree(const WebCore::HistoryItem*);
278 #endif
279 
280 #endif // HISTORYITEM_H
281