2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WebIconDatabase_H
27 #define WebIconDatabase_H
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>
39 typedef const struct __CFString * CFStringRef;
44 }; //namespace WebCore
45 using namespace WebCore;
48 class WebIconDatabase : public IWebIconDatabase, public WebCore::IconDatabaseClient
51 static WebIconDatabase* createInstance();
52 static WebIconDatabase* sharedWebIconDatabase();
57 void startUpIconDatabase();
58 void shutDownIconDatabase();
62 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
63 virtual ULONG STDMETHODCALLTYPE AddRef(void);
64 virtual ULONG STDMETHODCALLTYPE Release(void);
67 virtual HRESULT STDMETHODCALLTYPE sharedIconDatabase(
68 /* [retval][out] */ IWebIconDatabase **result);
70 virtual HRESULT STDMETHODCALLTYPE iconForURL(
72 /* [optional][in] */ LPSIZE size,
73 /* [optional][in] */ BOOL cache,
74 /* [retval][out] */ OLE_HANDLE *image);
76 virtual HRESULT STDMETHODCALLTYPE defaultIconWithSize(
77 /* [in] */ LPSIZE size,
78 /* [retval][out] */ OLE_HANDLE *result);
80 virtual HRESULT STDMETHODCALLTYPE retainIconForURL(
83 virtual HRESULT STDMETHODCALLTYPE releaseIconForURL(
86 virtual HRESULT STDMETHODCALLTYPE removeAllIcons( void);
88 virtual HRESULT STDMETHODCALLTYPE delayDatabaseCleanup( void);
90 virtual HRESULT STDMETHODCALLTYPE allowDatabaseCleanup( void);
92 virtual HRESULT STDMETHODCALLTYPE iconURLForURL(
94 /* [retval][out] */ BSTR *iconURL);
96 virtual HRESULT STDMETHODCALLTYPE isEnabled(
97 /* [retval][out] */ BOOL *result);
99 virtual HRESULT STDMETHODCALLTYPE setEnabled(
100 /* [in] */ BOOL /*flag*/);
102 virtual HRESULT STDMETHODCALLTYPE hasIconForURL(
104 /* [retval][out] */ BOOL* result);
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();
114 static BSTR iconDatabaseDidAddIconNotification();
115 static BSTR iconDatabaseDidRemoveAllIconsNotification();
116 static CFStringRef iconDatabaseNotificationUserInfoURLKey();
119 static WebIconDatabase* m_sharedWebIconDatabase;
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;
128 Mutex m_notificationMutex;
129 Vector<String> m_notificationQueue;
130 void scheduleNotificationDelivery();
131 bool m_deliveryRequested;
133 static void deliverNotifications(void*);