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