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