1/* 2 * Copyright (C) 2006, 2007, 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 WebHistory_H 27#define WebHistory_H 28 29#include "WebKit.h" 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> 35 36namespace WebCore { 37 class KURL; 38 class PageGroup; 39} 40 41//----------------------------------------------------------------------------- 42 43class WebPreferences; 44 45class WebHistory : public IWebHistory, public IWebHistoryPrivate { 46public: 47 static WebHistory* createInstance(); 48private: 49 WebHistory(); 50 ~WebHistory(); 51 52public: 53 // IUnknown 54 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); 55 virtual ULONG STDMETHODCALLTYPE AddRef(void); 56 virtual ULONG STDMETHODCALLTYPE Release(void); 57 58 // IWebHistory 59 virtual HRESULT STDMETHODCALLTYPE optionalSharedHistory( 60 /* [retval][out] */ IWebHistory** history); 61 62 virtual HRESULT STDMETHODCALLTYPE setOptionalSharedHistory( 63 /* [in] */ IWebHistory* history); 64 65 virtual HRESULT STDMETHODCALLTYPE unused1() OVERRIDE; 66 virtual HRESULT STDMETHODCALLTYPE unused2() OVERRIDE; 67 68 virtual HRESULT STDMETHODCALLTYPE addItems( 69 /* [in] */ int itemCount, 70 /* [in] */ IWebHistoryItem** items); 71 72 virtual HRESULT STDMETHODCALLTYPE removeItems( 73 /* [in] */ int itemCount, 74 /* [in] */ IWebHistoryItem** items); 75 76 virtual HRESULT STDMETHODCALLTYPE removeAllItems( void); 77 78 virtual HRESULT STDMETHODCALLTYPE orderedLastVisitedDays( 79 /* [out][in] */ int* count, 80 /* [in] */ DATE* calendarDates); 81 82 virtual HRESULT STDMETHODCALLTYPE orderedItemsLastVisitedOnDay( 83 /* [out][in] */ int* count, 84 /* [in] */ IWebHistoryItem** items, 85 /* [in] */ DATE calendarDate); 86 87 virtual HRESULT STDMETHODCALLTYPE itemForURL( 88 /* [in] */ BSTR url, 89 /* [retval][out] */ IWebHistoryItem** item); 90 91 virtual HRESULT STDMETHODCALLTYPE setHistoryItemLimit( 92 /* [in] */ int limit); 93 94 virtual HRESULT STDMETHODCALLTYPE historyItemLimit( 95 /* [retval][out] */ int* limit); 96 97 virtual HRESULT STDMETHODCALLTYPE setHistoryAgeInDaysLimit( 98 /* [in] */ int limit); 99 100 virtual HRESULT STDMETHODCALLTYPE historyAgeInDaysLimit( 101 /* [retval][out] */ int* limit); 102 103 // IWebHistoryPrivate 104 105 virtual HRESULT STDMETHODCALLTYPE allItems( 106 /* [out][in] */ int* count, 107 /* [retval][out] */ IWebHistoryItem** items); 108 109 virtual HRESULT STDMETHODCALLTYPE setVisitedLinkTrackingEnabled(BOOL visitedLinkTrackingEnable); 110 virtual HRESULT STDMETHODCALLTYPE removeAllVisitedLinks(); 111 112 // WebHistory 113 static WebHistory* sharedHistory(); 114 void visitedURL(const WebCore::KURL&, const WTF::String& title, const WTF::String& httpMethod, bool wasFailure, bool increaseVisitCount); 115 void addVisitedLinksToPageGroup(WebCore::PageGroup&); 116 117 COMPtr<IWebHistoryItem> itemForURLString(const WTF::String&) const; 118 119 typedef int64_t DateKey; 120 typedef HashMap<DateKey, RetainPtr<CFMutableArrayRef> > DateToEntriesMap; 121 122private: 123 124 enum NotificationType 125 { 126 kWebHistoryItemsAddedNotification = 0, 127 kWebHistoryItemsRemovedNotification = 1, 128 kWebHistoryAllItemsRemovedNotification = 2, 129 kWebHistoryLoadedNotification = 3, 130 kWebHistoryItemsDiscardedWhileLoadingNotification = 4, 131 kWebHistorySavedNotification = 5 132 }; 133 134 HRESULT postNotification(NotificationType notifyType, IPropertyBag* userInfo = 0); 135 HRESULT removeItem(IWebHistoryItem* entry); 136 HRESULT addItem(IWebHistoryItem* entry, bool discardDuplicate, bool* added); 137 HRESULT removeItemForURLString(CFStringRef urlString); 138 HRESULT addItemToDateCaches(IWebHistoryItem* entry); 139 HRESULT removeItemFromDateCaches(IWebHistoryItem* entry); 140 HRESULT insertItem(IWebHistoryItem* entry, DateKey); 141 HRESULT ageLimitDate(CFAbsoluteTime* time); 142 bool findKey(DateKey*, CFAbsoluteTime forDay); 143 static CFAbsoluteTime timeToDate(CFAbsoluteTime time); 144 BSTR getNotificationString(NotificationType notifyType); 145 HRESULT itemForURLString(CFStringRef urlString, IWebHistoryItem** item) const; 146 147 ULONG m_refCount; 148 RetainPtr<CFMutableDictionaryRef> m_entriesByURL; 149 DateToEntriesMap m_entriesByDate; 150 OwnArrayPtr<DATE> m_orderedLastVisitedDays; 151 COMPtr<WebPreferences> m_preferences; 152}; 153 154#endif 155