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