• 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 
32 #if PLATFORM(MAC)
33 #import <wtf/RetainPtr.h>
34 typedef struct objc_object* id;
35 #endif
36 
37 #ifdef ANDROID_HISTORY_CLIENT
38 #include "WebHistory.h"
39 #endif
40 
41 #if PLATFORM(QT)
42 #include <QVariant>
43 #endif
44 
45 namespace WebCore {
46 
47 class CachedPage;
48 class Document;
49 class FormData;
50 class HistoryItem;
51 class Image;
52 class KURL;
53 class ResourceRequest;
54 
55 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector;
56 
57 #ifdef ANDROID_HISTORY_CLIENT
58 extern void (*notifyHistoryItemChanged)(HistoryItem*);
59 #else
60 extern void (*notifyHistoryItemChanged)();
61 #endif
62 
63 class HistoryItem : public RefCounted<HistoryItem> {
64     friend class PageCache;
65 
66 public:
create()67     static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); }
create(const String & urlString,const String & title,double lastVisited)68     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, double lastVisited)
69     {
70         return adoptRef(new HistoryItem(urlString, title, lastVisited));
71     }
create(const String & urlString,const String & title,const String & alternateTitle,double lastVisited)72     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, double lastVisited)
73     {
74         return adoptRef(new HistoryItem(urlString, title, alternateTitle, lastVisited));
75     }
create(const KURL & url,const String & target,const String & parent,const String & title)76     static PassRefPtr<HistoryItem> create(const KURL& url, const String& target, const String& parent, const String& title)
77     {
78         return adoptRef(new HistoryItem(url, target, parent, title));
79     }
80 
81     ~HistoryItem();
82 
83     PassRefPtr<HistoryItem> copy() const;
84 
85     const String& originalURLString() const;
86     const String& urlString() const;
87     const String& title() const;
88 
setInPageCache(bool inPageCache)89     void setInPageCache(bool inPageCache) { m_isInPageCache = inPageCache; }
isInPageCache()90     bool isInPageCache() const { return m_isInPageCache; }
91 
92     double lastVisitedTime() const;
93 
94     void setAlternateTitle(const String& alternateTitle);
95     const String& alternateTitle() const;
96 
97     Image* icon() const;
98 
99     const String& parent() const;
100     KURL url() const;
101     KURL originalURL() const;
102     const String& referrer() const;
103     const String& target() const;
104     bool isTargetItem() const;
105 
106     FormData* formData();
107     String formContentType() const;
108 
109     int visitCount() const;
lastVisitWasFailure()110     bool lastVisitWasFailure() const { return m_lastVisitWasFailure; }
lastVisitWasHTTPNonGet()111     bool lastVisitWasHTTPNonGet() const { return m_lastVisitWasHTTPNonGet; }
112 
113     void mergeAutoCompleteHints(HistoryItem* otherItem);
114 
115     const IntPoint& scrollPoint() const;
116     void setScrollPoint(const IntPoint&);
117     void clearScrollPoint();
118     const Vector<String>& documentState() const;
119     void setDocumentState(const Vector<String>&);
120     void clearDocumentState();
121 
122     void setURL(const KURL&);
123     void setURLString(const String&);
124     void setOriginalURLString(const String&);
125     void setReferrer(const String&);
126     void setTarget(const String&);
127     void setParent(const String&);
128     void setTitle(const String&);
129     void setIsTargetItem(bool);
130 
131     void setFormInfoFromRequest(const ResourceRequest&);
132 
133     void recordInitialVisit();
134 
135     void setVisitCount(int);
setLastVisitWasFailure(bool wasFailure)136     void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; }
setLastVisitWasHTTPNonGet(bool wasNotGet)137     void setLastVisitWasHTTPNonGet(bool wasNotGet) { m_lastVisitWasHTTPNonGet = wasNotGet; }
138 
139     void addChildItem(PassRefPtr<HistoryItem>);
140     HistoryItem* childItemWithName(const String&) const;
141     HistoryItem* targetItem();
142     HistoryItem* recurseToFindTargetItem();
143     const HistoryItemVector& children() const;
144     bool hasChildren() const;
145 
146     // This should not be called directly for HistoryItems that are already included
147     // in GlobalHistory. The WebKit api for this is to use -[WebHistory setLastVisitedTimeInterval:forItem:] instead.
148     void setLastVisitedTime(double);
149     void visited(const String& title, double time);
150 
151     void addRedirectURL(const String&);
152     Vector<String>* redirectURLs() const;
153     void setRedirectURLs(std::auto_ptr<Vector<String> >);
154 
155     bool isCurrentDocument(Document*) const;
156 
157 #if PLATFORM(MAC)
158     id viewState() const;
159     void setViewState(id);
160 
161     // Transient properties may be of any ObjC type.  They are intended to be used to store state per back/forward list entry.
162     // The properties will not be persisted; when the history item is removed, the properties will be lost.
163     id getTransientProperty(const String&) const;
164     void setTransientProperty(const String&, id);
165 #endif
166 
167 #if PLATFORM(QT)
userData()168     QVariant userData() const { return m_userData; }
setUserData(const QVariant & userData)169     void setUserData(const QVariant& userData) { m_userData = userData; }
170 #endif
171 
172 #ifndef NDEBUG
173     int showTree() const;
174     int showTreeWithIndent(unsigned indentLevel) const;
175 #endif
176 
177 #ifdef ANDROID_HISTORY_CLIENT
setBridge(android::WebHistoryItem * bridge)178     void setBridge(android::WebHistoryItem* bridge) { m_bridge = adoptRef(bridge); }
bridge()179     android::WebHistoryItem* bridge() const { return m_bridge.get(); }
180 #endif
181 
182     void adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weeklyCounts);
dailyVisitCounts()183     const Vector<int>& dailyVisitCounts() { return m_dailyVisitCounts; }
weeklyVisitCounts()184     const Vector<int>& weeklyVisitCounts() { return m_weeklyVisitCounts; }
185 
186 private:
187     HistoryItem();
188     HistoryItem(const String& urlString, const String& title, double lastVisited);
189     HistoryItem(const String& urlString, const String& title, const String& alternateTitle, double lastVisited);
190     HistoryItem(const KURL& url, const String& target, const String& parent, const String& title);
191 
192     HistoryItem(const HistoryItem&);
193 
194     void padDailyCountsForNewVisit(double time);
195     void collapseDailyVisitsToWeekly();
196     void recordVisitAtTime(double);
197 
198     String m_urlString;
199     String m_originalURLString;
200     String m_referrer;
201     String m_target;
202     String m_parent;
203     String m_title;
204     String m_displayTitle;
205 
206     double m_lastVisitedTime;
207     bool m_lastVisitWasHTTPNonGet;
208 
209     IntPoint m_scrollPoint;
210     Vector<String> m_documentState;
211 
212     HistoryItemVector m_subItems;
213 
214     bool m_lastVisitWasFailure;
215     bool m_isInPageCache;
216     bool m_isTargetItem;
217     int m_visitCount;
218     Vector<int> m_dailyVisitCounts;
219     Vector<int> m_weeklyVisitCounts;
220 
221     OwnPtr<Vector<String> > m_redirectURLs;
222 
223     // info used to repost form data
224     RefPtr<FormData> m_formData;
225     String m_formContentType;
226 
227     // PageCache controls these fields.
228     HistoryItem* m_next;
229     HistoryItem* m_prev;
230     RefPtr<CachedPage> m_cachedPage;
231 
232 #if PLATFORM(MAC)
233     RetainPtr<id> m_viewState;
234     OwnPtr<HashMap<String, RetainPtr<id> > > m_transientProperties;
235 #endif
236 
237 #ifdef ANDROID_HISTORY_CLIENT
238     RefPtr<android::WebHistoryItem> m_bridge;
239 #endif
240 
241 #if PLATFORM(QT)
242     QVariant m_userData;
243 #endif
244 }; //class HistoryItem
245 
246 } //namespace WebCore
247 
248 #ifndef NDEBUG
249 // Outside the WebCore namespace for ease of invocation from gdb.
250 extern "C" int showTree(const WebCore::HistoryItem*);
251 #endif
252 
253 #endif // HISTORYITEM_H
254