[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.24
[framework/web/webkit-efl.git] / Source / WebCore / history / HistoryItem.h
1 /*
2  * Copyright (C) 2006, 2008, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #ifndef HistoryItem_h
28 #define HistoryItem_h
29
30 #include "IntPoint.h"
31 #include "PlatformString.h"
32 #include <wtf/HashMap.h>
33 #include <wtf/OwnPtr.h>
34 #include <wtf/PassOwnPtr.h>
35 #include <wtf/RefCounted.h>
36
37 #if PLATFORM(MAC)
38 #import <wtf/RetainPtr.h>
39 typedef struct objc_object* id;
40 #endif
41
42 #if PLATFORM(QT)
43 #include <QVariant>
44 #include <QByteArray>
45 #include <QDataStream>
46 #endif
47
48 #if PLATFORM(BLACKBERRY)
49 #include "HistoryItemViewState.h"
50 #endif
51
52 namespace WebCore {
53
54 class CachedPage;
55 class Document;
56 class FormData;
57 class HistoryItem;
58 class Image;
59 class KURL;
60 class ResourceRequest;
61 class SerializedScriptValue;
62
63 typedef Vector<RefPtr<HistoryItem> > HistoryItemVector;
64
65 extern void (*notifyHistoryItemChanged)(HistoryItem*);
66
67 enum VisitCountBehavior {
68     IncreaseVisitCount,
69     DoNotIncreaseVisitCount
70 };
71
72 class HistoryItem : public RefCounted<HistoryItem> {
73     friend class PageCache;
74
75 public: 
76     static PassRefPtr<HistoryItem> create() { return adoptRef(new HistoryItem); }
77     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, double lastVisited)
78     {
79         return adoptRef(new HistoryItem(urlString, title, lastVisited));
80     }
81     static PassRefPtr<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, double lastVisited)
82     {
83         return adoptRef(new HistoryItem(urlString, title, alternateTitle, lastVisited));
84     }
85     static PassRefPtr<HistoryItem> create(const KURL& url, const String& target, const String& parent, const String& title)
86     {
87         return adoptRef(new HistoryItem(url, target, parent, title));
88     }
89     
90     ~HistoryItem();
91
92     PassRefPtr<HistoryItem> copy() const;
93
94     // Resets the HistoryItem to its initial state, as returned by create().
95     void reset();
96     
97     void encodeBackForwardTree(Encoder&) const;
98     static PassRefPtr<HistoryItem> decodeBackForwardTree(const String& urlString, const String& title, const String& originalURLString, Decoder&);
99
100     const String& originalURLString() const;
101     const String& urlString() const;
102     const String& title() const;
103     
104     bool isInPageCache() const { return m_cachedPage; }
105     
106     double lastVisitedTime() const;
107     
108     void setAlternateTitle(const String& alternateTitle);
109     const String& alternateTitle() const;
110     
111     const String& parent() const;
112     KURL url() const;
113     KURL originalURL() const;
114     const String& referrer() const;
115     const String& target() const;
116     bool isTargetItem() const;
117     
118     FormData* formData();
119     String formContentType() const;
120     
121     int visitCount() const;
122     bool lastVisitWasFailure() const { return m_lastVisitWasFailure; }
123     bool lastVisitWasHTTPNonGet() const { return m_lastVisitWasHTTPNonGet; }
124
125     void mergeAutoCompleteHints(HistoryItem* otherItem);
126     
127     const IntPoint& scrollPoint() const;
128     void setScrollPoint(const IntPoint&);
129     void clearScrollPoint();
130     
131     float pageScaleFactor() const;
132     void setPageScaleFactor(float);
133     
134     const Vector<String>& documentState() const;
135     void setDocumentState(const Vector<String>&);
136     void clearDocumentState();
137
138     void setURL(const KURL&);
139     void setURLString(const String&);
140     void setOriginalURLString(const String&);
141     void setReferrer(const String&);
142     void setTarget(const String&);
143     void setParent(const String&);
144     void setTitle(const String&);
145     void setIsTargetItem(bool);
146     
147     void setStateObject(PassRefPtr<SerializedScriptValue> object);
148     SerializedScriptValue* stateObject() const { return m_stateObject.get(); }
149
150     void setItemSequenceNumber(long long number) { m_itemSequenceNumber = number; }
151     long long itemSequenceNumber() const { return m_itemSequenceNumber; }
152
153     void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; }
154     long long documentSequenceNumber() const { return m_documentSequenceNumber; }
155
156     void setFormInfoFromRequest(const ResourceRequest&);
157     void setFormData(PassRefPtr<FormData>);
158     void setFormContentType(const String&);
159
160     void recordInitialVisit();
161
162     void setVisitCount(int);
163     void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; }
164     void setLastVisitWasHTTPNonGet(bool wasNotGet) { m_lastVisitWasHTTPNonGet = wasNotGet; }
165
166     void addChildItem(PassRefPtr<HistoryItem>);
167     void setChildItem(PassRefPtr<HistoryItem>);
168     HistoryItem* childItemWithTarget(const String&) const;
169     HistoryItem* childItemWithDocumentSequenceNumber(long long number) const;
170     HistoryItem* targetItem();
171     const HistoryItemVector& children() const;
172     bool hasChildren() const;
173     void clearChildren();
174     
175     bool shouldDoSameDocumentNavigationTo(HistoryItem* otherItem) const;
176     bool hasSameFrames(HistoryItem* otherItem) const;
177
178     // This should not be called directly for HistoryItems that are already included
179     // in GlobalHistory. The WebKit api for this is to use -[WebHistory setLastVisitedTimeInterval:forItem:] instead.
180     void setLastVisitedTime(double);
181     void visited(const String& title, double time, VisitCountBehavior);
182
183     void addRedirectURL(const String&);
184     Vector<String>* redirectURLs() const;
185     void setRedirectURLs(PassOwnPtr<Vector<String> >);
186
187     bool isCurrentDocument(Document*) const;
188     
189 #if PLATFORM(MAC)
190     id viewState() const;
191     void setViewState(id);
192     
193     // Transient properties may be of any ObjC type.  They are intended to be used to store state per back/forward list entry.
194     // The properties will not be persisted; when the history item is removed, the properties will be lost.
195     id getTransientProperty(const String&) const;
196     void setTransientProperty(const String&, id);
197 #endif
198
199 #if PLATFORM(QT)
200     QVariant userData() const { return m_userData; }
201     void setUserData(const QVariant& userData) { m_userData = userData; }
202
203     bool restoreState(QDataStream& buffer, int version);
204     QDataStream& saveState(QDataStream& out, int version) const;
205 #endif
206
207 #if PLATFORM(BLACKBERRY)
208     HistoryItemViewState& viewState() { return m_viewState; }
209 #endif
210
211 #ifndef NDEBUG
212     int showTree() const;
213     int showTreeWithIndent(unsigned indentLevel) const;
214 #endif
215
216     void adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weeklyCounts);
217     const Vector<int>& dailyVisitCounts() const { return m_dailyVisitCounts; }
218     const Vector<int>& weeklyVisitCounts() const { return m_weeklyVisitCounts; }
219
220 #if PLATFORM(EFL)
221 #if ENABLE(TIZEN_PAGE_CACHE)
222     void setViewZoomFactor(float zoomLevel) { m_zoomFactor = zoomLevel; }
223     float viewZoomFactor() { return m_zoomFactor; }
224 #endif
225 #endif
226
227 private:
228     HistoryItem();
229     HistoryItem(const String& urlString, const String& title, double lastVisited);
230     HistoryItem(const String& urlString, const String& title, const String& alternateTitle, double lastVisited);
231     HistoryItem(const KURL& url, const String& frameName, const String& parent, const String& title);
232
233     HistoryItem(const HistoryItem&);
234
235     void padDailyCountsForNewVisit(double time);
236     void collapseDailyVisitsToWeekly();
237     void recordVisitAtTime(double, VisitCountBehavior = IncreaseVisitCount);
238     
239     bool hasSameDocumentTree(HistoryItem* otherItem) const;
240
241     HistoryItem* findTargetItem();
242
243     void encodeBackForwardTreeNode(Encoder&) const;
244
245     /* When adding new member variables to this class, please notify the Qt team.
246      * qt/HistoryItemQt.cpp contains code to serialize history items.
247      */
248
249     String m_urlString;
250     String m_originalURLString;
251     String m_referrer;
252     String m_target;
253     String m_parent;
254     String m_title;
255     String m_displayTitle;
256     
257     double m_lastVisitedTime;
258     bool m_lastVisitWasHTTPNonGet;
259
260     IntPoint m_scrollPoint;
261     float m_pageScaleFactor;
262     Vector<String> m_documentState;
263     
264     HistoryItemVector m_children;
265     
266     bool m_lastVisitWasFailure;
267     bool m_isTargetItem;
268     int m_visitCount;
269     Vector<int> m_dailyVisitCounts;
270     Vector<int> m_weeklyVisitCounts;
271
272     OwnPtr<Vector<String> > m_redirectURLs;
273
274     // If two HistoryItems have the same item sequence number, then they are
275     // clones of one another.  Traversing history from one such HistoryItem to
276     // another is a no-op.  HistoryItem clones are created for parent and
277     // sibling frames when only a subframe navigates.
278     int64_t m_itemSequenceNumber;
279
280     // If two HistoryItems have the same document sequence number, then they
281     // refer to the same instance of a document.  Traversing history from one
282     // such HistoryItem to another preserves the document.
283     int64_t m_documentSequenceNumber;
284
285     // Support for HTML5 History
286     RefPtr<SerializedScriptValue> m_stateObject;
287     
288     // info used to repost form data
289     RefPtr<FormData> m_formData;
290     String m_formContentType;
291
292     // PageCache controls these fields.
293     HistoryItem* m_next;
294     HistoryItem* m_prev;
295     RefPtr<CachedPage> m_cachedPage;
296     
297 #if PLATFORM(MAC)
298     RetainPtr<id> m_viewState;
299     OwnPtr<HashMap<String, RetainPtr<id> > > m_transientProperties;
300 #endif
301
302 #if PLATFORM(QT)
303     QVariant m_userData;
304 #endif
305 #if PLATFORM(EFL)
306 #if ENABLE(TIZEN_PAGE_CACHE)
307     float m_zoomFactor;
308 #endif
309 #endif
310
311 #if PLATFORM(BLACKBERRY)
312     HistoryItemViewState m_viewState;
313 #endif
314 }; //class HistoryItem
315
316 } //namespace WebCore
317
318 #ifndef NDEBUG
319 // Outside the WebCore namespace for ease of invocation from gdb.
320 extern "C" int showTree(const WebCore::HistoryItem*);
321 #endif
322
323 #endif // HISTORYITEM_H