WebHistory.h 5.8 KB

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