tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / history / HistoryItem.h
1 /*
2  * Copyright (C) 2006, 2008, 2011 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 <wtf/HashMap.h>
32 #include <wtf/OwnPtr.h>
33 #include <wtf/PassOwnPtr.h>
34 #include <wtf/RefCounted.h>
35
36 #if PLATFORM(MAC)
37 #import <wtf/RetainPtr.h>
38 typedef struct objc_object* id;
39 #endif
40
41 #if PLATFORM(QT)
42 #include <QVariant>
43 #include <QByteArray>
44 #include <QDataStream>
45 #endif
46
47 namespace WebCore {
48
49 class CachedPage;
50 class Document;
51 class FormData;
52 class HistoryItem;
53 class Image;
54 class KURL;
55 class ResourceRequest;
56 class SerializedScriptValue;
57
58 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector;
59
60 extern void (*notifyHistoryItemChanged)(HistoryItem*);
61
62 enum VisitCountBehavior {
63     IncreaseVisitCount,
64     DoNotIncreaseVisitCount
65 };
66
67 class HistoryItem : public RefCounted<HistoryItem> {
68     friend class PageCache;
69
70 public: 
71     static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); }
72     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, double lastVisited)
73     {
74         return adoptRef(new HistoryItem(urlString, title, lastVisited));
75     }
76     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, double lastVisited)
77     {
78         return adoptRef(new HistoryItem(urlString, title, alternateTitle, lastVisited));
79     }
80     static PassRefPtr<HistoryItem> create(const KURL& url, const String& target, const String& parent, const String& title)
81     {
82         return adoptRef(new HistoryItem(url, target, parent, title));
83     }
84     
85     ~HistoryItem();
86
87     PassRefPtr<HistoryItem> copy() const;
88
89     // Resets the HistoryItem to its initial state, as returned by create().
90     void reset();
91     
92     void encodeBackForwardTree(Encoder&) const;
93     static PassRefPtr<HistoryItem> decodeBackForwardTree(const String& urlString, const String& title, const String& originalURLString, Decoder&);
94
95     const String& originalURLString() const;
96     const String& urlString() const;
97     const String& title() const;
98     
99     bool isInPageCache() const { return m_cachedPage; }
100     
101     double lastVisitedTime() const;
102     
103     void setAlternateTitle(const String& alternateTitle);
104     const String& alternateTitle() const;
105     
106     const String& parent() const;
107     KURL url() const;
108     KURL originalURL() const;
109     const String& referrer() const;
110     const String& target() const;
111     bool isTargetItem() const;
112     
113     FormData* formData();
114     String formContentType() const;
115     
116     int visitCount() const;
117     bool lastVisitWasFailure() const { return m_lastVisitWasFailure; }
118     bool lastVisitWasHTTPNonGet() const { return m_lastVisitWasHTTPNonGet; }
119
120     void mergeAutoCompleteHints(HistoryItem* otherItem);
121     
122     const IntPoint& scrollPoint() const;
123     void setScrollPoint(const IntPoint&);
124     void clearScrollPoint();
125     
126     float pageScaleFactor() const;
127     void setPageScaleFactor(float);
128     
129     const Vector<String>& documentState() const;
130     void setDocumentState(const Vector<String>&);
131     void clearDocumentState();
132
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);
141     
142     void setStateObject(PassRefPtr<SerializedScriptValue> object);
143     SerializedScriptValue* stateObject() const { return m_stateObject.get(); }
144
145     void setItemSequenceNumber(long long number) { m_itemSequenceNumber = number; }
146     long long itemSequenceNumber() const { return m_itemSequenceNumber; }
147
148     void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; }
149     long long documentSequenceNumber() const { return m_documentSequenceNumber; }
150
151     void setFormInfoFromRequest(const ResourceRequest&);
152     void setFormData(PassRefPtr<FormData>);
153     void setFormContentType(const String&);
154
155     void recordInitialVisit();
156
157     void setVisitCount(int);
158     void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; }
159     void setLastVisitWasHTTPNonGet(bool wasNotGet) { m_lastVisitWasHTTPNonGet = wasNotGet; }
160
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();
169     
170     bool shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const;
171     bool hasSameFrames(HistoryItem* otherItem) const;
172
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);
177
178     void addRedirectURL(const String&);
179     Vector<String>* redirectURLs() const;
180     void setRedirectURLs(PassOwnPtr<Vector<String> >);
181
182     bool isCurrentDocument(Document*) const;
183     
184 #if PLATFORM(MAC)
185     id viewState() const;
186     void setViewState(id);
187     
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);
192 #endif
193
194 #if PLATFORM(QT)
195     QVariant userData() const { return m_userData; }
196     void setUserData(const QVariant& userData) { m_userData = userData; }
197
198     bool restoreState(QDataStream& buffer, int version);
199     QDataStream& saveState(QDataStream& out, int version) const;
200 #endif
201
202 #ifndef NDEBUG
203     int showTree() const;
204     int showTreeWithIndent(unsigned indentLevel) const;
205 #endif
206
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; }
210
211     void markForFullStyleRecalc();
212 #if PLATFORM(EFL)
213 #if ENABLE(TIZEN_PAGE_CACHE)
214     void setViewZoomFactor(float zoomLevel) { m_zoomFactor = zoomLevel; }
215     float viewZoomFactor() { return m_zoomFactor; }
216 #endif
217 #endif
218 private:
219     HistoryItem();
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);
223
224     HistoryItem(const HistoryItem&);
225
226     void padDailyCountsForNewVisit(double time);
227     void collapseDailyVisitsToWeekly();
228     void recordVisitAtTime(double, VisitCountBehavior = IncreaseVisitCount);
229     
230     bool hasSameDocumentTree(HistoryItem* otherItem) const;
231
232     HistoryItem* findTargetItem();
233
234     void encodeBackForwardTreeNode(Encoder&) const;
235
236     /* When adding new member variables to this class, please notify the Qt team.
237      * qt/HistoryItemQt.cpp contains code to serialize history items.
238      */
239
240     String m_urlString;
241     String m_originalURLString;
242     String m_referrer;
243     String m_target;
244     String m_parent;
245     String m_title;
246     String m_displayTitle;
247     
248     double m_lastVisitedTime;
249     bool m_lastVisitWasHTTPNonGet;
250
251     IntPoint m_scrollPoint;
252     float m_pageScaleFactor;
253     Vector<String> m_documentState;
254     
255     HistoryItemVector m_children;
256     
257     bool m_lastVisitWasFailure;
258     bool m_isTargetItem;
259     int m_visitCount;
260     Vector<int> m_dailyVisitCounts;
261     Vector<int> m_weeklyVisitCounts;
262
263     OwnPtr<Vector<String> > m_redirectURLs;
264
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;
270
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;
275
276     // Support for HTML5 History
277     RefPtr<SerializedScriptValue> m_stateObject;
278     
279     // info used to repost form data
280     RefPtr<FormData> m_formData;
281     String m_formContentType;
282
283     // PageCache controls these fields.
284     HistoryItem* m_next;
285     HistoryItem* m_prev;
286     RefPtr<CachedPage> m_cachedPage;
287     
288 #if PLATFORM(MAC)
289     RetainPtr<id> m_viewState;
290     OwnPtr<HashMap<String, RetainPtr<id> > > m_transientProperties;
291 #endif
292
293 #if PLATFORM(QT)
294     QVariant m_userData;
295 #endif
296 #if PLATFORM(EFL)
297 #if ENABLE(TIZEN_PAGE_CACHE)
298     float m_zoomFactor;
299 #endif
300 #endif
301 }; //class HistoryItem
302
303 } //namespace WebCore
304
305 #ifndef NDEBUG
306 // Outside the WebCore namespace for ease of invocation from gdb.
307 extern "C" int showTree(const WebCore::HistoryItem*);
308 #endif
309
310 #endif // HISTORYITEM_H