1/* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2013-2014 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 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 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 WebIconDatabase_H 27#define WebIconDatabase_H 28 29#include "WebKit.h" 30 31#include <WebCore/IconDatabaseClient.h> 32#include <WebCore/IntSize.h> 33#include <WebCore/IntSizeHash.h> 34#include <wtf/Vector.h> 35#include <wtf/Threading.h> 36 37#include <windows.h> 38 39namespace WebCore 40{ 41 class IconDatabase; 42}; //namespace WebCore 43using namespace WebCore; 44using namespace WTF; 45 46class WebIconDatabase : public IWebIconDatabase, public WebCore::IconDatabaseClient 47{ 48public: 49 static WebIconDatabase* createInstance(); 50 static WebIconDatabase* sharedWebIconDatabase(); 51private: 52 WebIconDatabase(); 53 ~WebIconDatabase(); 54 void init(); 55 void startUpIconDatabase(); 56 void shutDownIconDatabase(); 57public: 58 59 // IUnknown 60 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); 61 virtual ULONG STDMETHODCALLTYPE AddRef(void); 62 virtual ULONG STDMETHODCALLTYPE Release(void); 63 64 // IWebIconDatabase 65 virtual HRESULT STDMETHODCALLTYPE sharedIconDatabase( 66 /* [retval][out] */ IWebIconDatabase **result); 67 68 virtual HRESULT STDMETHODCALLTYPE iconForURL(BSTR url, LPSIZE, BOOL cache, HBITMAP* image); 69 70 virtual HRESULT STDMETHODCALLTYPE defaultIconWithSize(/* [in] */ LPSIZE size, /* [retval][out] */ HBITMAP* result); 71 72 virtual HRESULT STDMETHODCALLTYPE retainIconForURL( 73 /* [in] */ BSTR url); 74 75 virtual HRESULT STDMETHODCALLTYPE releaseIconForURL( 76 /* [in] */ BSTR url); 77 78 virtual HRESULT STDMETHODCALLTYPE removeAllIcons( void); 79 80 virtual HRESULT STDMETHODCALLTYPE delayDatabaseCleanup( void); 81 82 virtual HRESULT STDMETHODCALLTYPE allowDatabaseCleanup( void); 83 84 virtual HRESULT STDMETHODCALLTYPE iconURLForURL( 85 /* [in] */ BSTR url, 86 /* [retval][out] */ BSTR *iconURL); 87 88 virtual HRESULT STDMETHODCALLTYPE isEnabled( 89 /* [retval][out] */ BOOL *result); 90 91 virtual HRESULT STDMETHODCALLTYPE setEnabled( 92 /* [in] */ BOOL /*flag*/); 93 94 virtual HRESULT STDMETHODCALLTYPE hasIconForURL( 95 /* [in] */ BSTR url, 96 /* [retval][out] */ BOOL* result); 97 98 // IconDatabaseClient 99 virtual void didRemoveAllIcons(); 100 virtual void didImportIconURLForPageURL(const WTF::String&); 101 virtual void didImportIconDataForPageURL(const WTF::String&); 102 virtual void didChangeIconForPageURL(const WTF::String&); 103 virtual void didFinishURLImport(); 104 105 static BSTR iconDatabaseDidAddIconNotification(); 106 static BSTR iconDatabaseDidRemoveAllIconsNotification(); 107 static BSTR iconDatabaseNotificationUserInfoURLKey(); 108protected: 109 ULONG m_refCount; 110 static WebIconDatabase* m_sharedWebIconDatabase; 111 112 // Keep a set of HBITMAPs around for the default icon, and another 113 // to share amongst present site icons 114 HBITMAP getOrCreateSharedBitmap(const IntSize&); 115 HBITMAP getOrCreateDefaultIconBitmap(const IntSize&); 116 HashMap<IntSize, HBITMAP> m_defaultIconMap; 117 HashMap<IntSize, HBITMAP> m_sharedIconMap; 118 119 Mutex m_notificationMutex; 120 Vector<String> m_notificationQueue; 121 void scheduleNotificationDelivery(); 122 bool m_deliveryRequested; 123 124 static void deliverNotifications(void*); 125}; 126 127#endif 128