2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include <CoreFoundation/CoreFoundation.h>
31 #include <WebCore/COMPtr.h>
32 #include <wtf/Forward.h>
33 #include <wtf/OwnArrayPtr.h>
34 #include <wtf/RetainPtr.h>
41 //-----------------------------------------------------------------------------
45 class WebHistory : public IWebHistory, public IWebHistoryPrivate {
47 static WebHistory* createInstance();
54 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
55 virtual ULONG STDMETHODCALLTYPE AddRef(void);
56 virtual ULONG STDMETHODCALLTYPE Release(void);
59 virtual HRESULT STDMETHODCALLTYPE optionalSharedHistory(
60 /* [retval][out] */ IWebHistory** history);
62 virtual HRESULT STDMETHODCALLTYPE setOptionalSharedHistory(
63 /* [in] */ IWebHistory* history);
65 virtual HRESULT STDMETHODCALLTYPE loadFromURL(
67 /* [out] */ IWebError** error,
68 /* [retval][out] */ BOOL* succeeded);
70 virtual HRESULT STDMETHODCALLTYPE saveToURL(
72 /* [out] */ IWebError** error,
73 /* [retval][out] */ BOOL* succeeded);
75 virtual HRESULT STDMETHODCALLTYPE addItems(
76 /* [in] */ int itemCount,
77 /* [in] */ IWebHistoryItem** items);
79 virtual HRESULT STDMETHODCALLTYPE removeItems(
80 /* [in] */ int itemCount,
81 /* [in] */ IWebHistoryItem** items);
83 virtual HRESULT STDMETHODCALLTYPE removeAllItems( void);
85 virtual HRESULT STDMETHODCALLTYPE orderedLastVisitedDays(
86 /* [out][in] */ int* count,
87 /* [in] */ DATE* calendarDates);
89 virtual HRESULT STDMETHODCALLTYPE orderedItemsLastVisitedOnDay(
90 /* [out][in] */ int* count,
91 /* [in] */ IWebHistoryItem** items,
92 /* [in] */ DATE calendarDate);
94 virtual HRESULT STDMETHODCALLTYPE itemForURL(
96 /* [retval][out] */ IWebHistoryItem** item);
98 virtual HRESULT STDMETHODCALLTYPE setHistoryItemLimit(
99 /* [in] */ int limit);
101 virtual HRESULT STDMETHODCALLTYPE historyItemLimit(
102 /* [retval][out] */ int* limit);
104 virtual HRESULT STDMETHODCALLTYPE setHistoryAgeInDaysLimit(
105 /* [in] */ int limit);
107 virtual HRESULT STDMETHODCALLTYPE historyAgeInDaysLimit(
108 /* [retval][out] */ int* limit);
110 // IWebHistoryPrivate
112 virtual HRESULT STDMETHODCALLTYPE allItems(
113 /* [out][in] */ int* count,
114 /* [retval][out] */ IWebHistoryItem** items);
116 virtual HRESULT STDMETHODCALLTYPE data(IStream**);
118 virtual HRESULT STDMETHODCALLTYPE setVisitedLinkTrackingEnabled(BOOL visitedLinkTrackingEnable);
119 virtual HRESULT STDMETHODCALLTYPE removeAllVisitedLinks();
122 static WebHistory* sharedHistory();
123 void visitedURL(const WebCore::KURL&, const WTF::String& title, const WTF::String& httpMethod, bool wasFailure, bool increaseVisitCount);
124 void addVisitedLinksToPageGroup(WebCore::PageGroup&);
126 COMPtr<IWebHistoryItem> itemForURLString(const WTF::String&) const;
128 typedef int64_t DateKey;
129 typedef HashMap<DateKey, RetainPtr<CFMutableArrayRef> > DateToEntriesMap;
133 enum NotificationType
135 kWebHistoryItemsAddedNotification = 0,
136 kWebHistoryItemsRemovedNotification = 1,
137 kWebHistoryAllItemsRemovedNotification = 2,
138 kWebHistoryLoadedNotification = 3,
139 kWebHistoryItemsDiscardedWhileLoadingNotification = 4,
140 kWebHistorySavedNotification = 5
143 HRESULT loadHistoryGutsFromURL(CFURLRef url, CFMutableArrayRef discardedItems, IWebError** error);
144 HRESULT saveHistoryGuts(CFURLRef url, IWebError** error);
145 HRESULT postNotification(NotificationType notifyType, IPropertyBag* userInfo = 0);
146 HRESULT removeItem(IWebHistoryItem* entry);
147 HRESULT addItem(IWebHistoryItem* entry, bool discardDuplicate, bool* added);
148 HRESULT removeItemForURLString(CFStringRef urlString);
149 HRESULT addItemToDateCaches(IWebHistoryItem* entry);
150 HRESULT removeItemFromDateCaches(IWebHistoryItem* entry);
151 HRESULT insertItem(IWebHistoryItem* entry, DateKey);
152 HRESULT ageLimitDate(CFAbsoluteTime* time);
153 bool findKey(DateKey*, CFAbsoluteTime forDay);
154 static CFAbsoluteTime timeToDate(CFAbsoluteTime time);
155 BSTR getNotificationString(NotificationType notifyType);
156 HRESULT itemForURLString(CFStringRef urlString, IWebHistoryItem** item) const;
157 RetainPtr<CFDataRef> data() const;
160 RetainPtr<CFMutableDictionaryRef> m_entriesByURL;
161 DateToEntriesMap m_entriesByDate;
162 OwnArrayPtr<DATE> m_orderedLastVisitedDays;
163 COMPtr<WebPreferences> m_preferences;