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