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 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 ANDROID_WEBKIT_WEBICONDATABASE_H 27 #define ANDROID_WEBKIT_WEBICONDATABASE_H 28 29 #include "IconDatabaseClient.h" 30 #include "utils/threads.h" 31 #include "wtf/Vector.h" 32 33 #include <jni.h> 34 35 namespace WebCore { 36 class Image; 37 class String; 38 } 39 40 namespace android { 41 42 class WebIconDatabaseClient { 43 public: ~WebIconDatabaseClient()44 virtual ~WebIconDatabaseClient() {} 45 virtual void didAddIconForPageUrl(const WebCore::String& pageUrl) = 0; 46 }; 47 48 class WebIconDatabase : public WebCore::IconDatabaseClient { 49 public: WebIconDatabase()50 WebIconDatabase() : mDeliveryRequested(false) {} 51 // IconDatabaseClient method 52 virtual void dispatchDidAddIconForPageURL(const WebCore::String& pageURL); 53 54 static void RegisterForIconNotification(WebIconDatabaseClient* client); 55 static void UnregisterForIconNotification(WebIconDatabaseClient* client); 56 static void DeliverNotifications(void*); 57 58 private: 59 // Deliver all the icon notifications 60 void deliverNotifications(); 61 62 // List of clients and a mutex to protect it. 63 Vector<WebIconDatabaseClient*> mClients; 64 android::Mutex mClientsMutex; 65 66 // Queue of page urls that have received an icon. 67 Vector<WebCore::String> mNotifications; 68 android::Mutex mNotificationsMutex; 69 // Flag to indicate that we have requested a delivery of notifications. 70 bool mDeliveryRequested; 71 }; 72 73 jobject webcoreImageToJavaBitmap(JNIEnv* env, WebCore::Image* icon); 74 75 }; 76 77 #endif 78