#ifndef WebHistory_H
#define WebHistory_H
#include "WebKit.h"
#include <WebCore/COMPtr.h>
#include <memory>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
namespace WebCore {
class PageGroup;
}
class WebPreferences;
class WebVisitedLinkStore;
class WebHistory final : public IWebHistory, public IWebHistoryPrivate {
public:
static WebHistory* createInstance();
private:
WebHistory();
~WebHistory();
public:
HRESULT STDMETHODCALLTYPE QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject) override;
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
HRESULT STDMETHODCALLTYPE optionalSharedHistory(_COM_Outptr_opt_ IWebHistory**) override;
HRESULT STDMETHODCALLTYPE setOptionalSharedHistory(_In_opt_ IWebHistory*) override;
HRESULT STDMETHODCALLTYPE unused1() override;
HRESULT STDMETHODCALLTYPE unused2() override;
HRESULT STDMETHODCALLTYPE addItems(int itemCount, __deref_in_ecount_opt(itemCount) IWebHistoryItem**) override;
HRESULT STDMETHODCALLTYPE removeItems(int itemCount, __deref_in_ecount_opt(itemCount) IWebHistoryItem**) override;
HRESULT STDMETHODCALLTYPE removeAllItems() override;
HRESULT STDMETHODCALLTYPE orderedLastVisitedDays(_Inout_ int* count, _In_ DATE* calendarDates) override;
HRESULT STDMETHODCALLTYPE orderedItemsLastVisitedOnDay(_Inout_ int* count, __deref_in_opt IWebHistoryItem** items, DATE calendarDate) override;
HRESULT STDMETHODCALLTYPE itemForURL(_In_ BSTR url, _COM_Outptr_opt_ IWebHistoryItem**) override;
HRESULT STDMETHODCALLTYPE setHistoryItemLimit(int) override;
HRESULT STDMETHODCALLTYPE historyItemLimit(_Out_ int*) override;
HRESULT STDMETHODCALLTYPE setHistoryAgeInDaysLimit(int) override;
HRESULT STDMETHODCALLTYPE historyAgeInDaysLimit(_Out_ int*) override;
HRESULT STDMETHODCALLTYPE allItems(_Inout_ int* count, __deref_opt_out IWebHistoryItem** items) override;
HRESULT STDMETHODCALLTYPE setVisitedLinkTrackingEnabled(BOOL) override;
HRESULT STDMETHODCALLTYPE removeAllVisitedLinks() override;
static WebHistory* sharedHistory();
void visitedURL(const URL&, const WTF::String& title, const WTF::String& httpMethod, bool wasFailure, bool increaseVisitCount);
void addVisitedLinksToVisitedLinkStore(WebVisitedLinkStore&);
COMPtr<IWebHistoryItem> itemForURLString(const WTF::String&) const;
typedef int64_t DateKey;
typedef HashMap<DateKey, Vector<COMPtr<IWebHistoryItem>>> DateToEntriesMap;
typedef HashMap<WTF::String, COMPtr<IWebHistoryItem>> URLToEntriesMap;
private:
enum NotificationType
{
kWebHistoryItemsAddedNotification = 0,
kWebHistoryItemsRemovedNotification = 1,
kWebHistoryAllItemsRemovedNotification = 2,
kWebHistoryLoadedNotification = 3,
kWebHistoryItemsDiscardedWhileLoadingNotification = 4,
kWebHistorySavedNotification = 5
};
HRESULT postNotification(NotificationType notifyType, IPropertyBag* userInfo = 0);
HRESULT removeItem(IWebHistoryItem* entry);
HRESULT addItem(IWebHistoryItem* entry, bool discardDuplicate, bool* added);
HRESULT removeItemForURLString(const WTF::String& urlString);
BSTR getNotificationString(NotificationType notifyType);
ULONG m_refCount { 0 };
URLToEntriesMap m_entriesByURL;
COMPtr<WebPreferences> m_preferences;
};
#endif