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