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