1 /* 2 * Copyright 2006, The Android Open Source Project 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 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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 "IconDatabaseClient.h" 30 #include "PlatformString.h" 31 #include "SkBitmap.h" 32 #include "utils/threads.h" 33 #include <jni.h> 34 #include <wtf/Vector.h> 35 36 namespace WebCore { 37 class Image; 38 } 39 40 namespace android { 41 42 class WebIconDatabaseClient { 43 public: ~WebIconDatabaseClient()44 virtual ~WebIconDatabaseClient() {} 45 virtual void didAddIconForPageUrl(const WTF::String& pageUrl) = 0; 46 }; 47 48 class WebIconDatabase : public WebCore::IconDatabaseClient { 49 public: WebIconDatabase()50 WebIconDatabase() : mDeliveryRequested(false) {} 51 // IconDatabaseClient methods 52 virtual bool performImport(); 53 virtual void didRemoveAllIcons(); 54 virtual void didImportIconURLForPageURL(const WTF::String&); 55 virtual void didImportIconDataForPageURL(const WTF::String&); 56 virtual void didChangeIconForPageURL(const WTF::String&); 57 virtual void didFinishURLImport(); 58 59 static void RegisterForIconNotification(WebIconDatabaseClient* client); 60 static void UnregisterForIconNotification(WebIconDatabaseClient* client); 61 static void DeliverNotifications(void*); 62 63 private: 64 // Deliver all the icon notifications 65 void deliverNotifications(); 66 67 // List of clients. 68 Vector<WebIconDatabaseClient*> mClients; 69 70 // Queue of page urls that have received an icon. 71 Vector<WTF::String> mNotifications; 72 android::Mutex mNotificationsMutex; 73 // Flag to indicate that we have requested a delivery of notifications. 74 bool mDeliveryRequested; 75 }; 76 77 SkBitmap* webcoreImageToSkBitmap(WebCore::Image* icon); 78 jobject webcoreImageToJavaBitmap(JNIEnv* env, WebCore::Image* icon); 79 80 }; 81 82 #endif 83