1 /* 2 * Copyright (C) 2007 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 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef IconRecord_h 30 #define IconRecord_h 31 32 #include "PageURLRecord.h" 33 #include <wtf/RefCounted.h> 34 #include "SharedBuffer.h" 35 36 #include "PlatformString.h" 37 #include <wtf/HashSet.h> 38 #include <wtf/OwnPtr.h> 39 #include <wtf/text/StringHash.h> 40 41 #if OS(SOLARIS) 42 #include <sys/types.h> // For time_t structure. 43 #endif 44 45 namespace WebCore { 46 47 class IconDataSnapshot; 48 class Image; 49 class IntSize; 50 class SQLDatabase; 51 52 enum ImageDataStatus { 53 ImageDataStatusPresent, ImageDataStatusMissing, ImageDataStatusUnknown 54 }; 55 56 class IconSnapshot { 57 public: IconSnapshot()58 IconSnapshot() : m_timestamp(0) { } 59 IconSnapshot(const String & iconURL,int timestamp,SharedBuffer * data)60 IconSnapshot(const String& iconURL, int timestamp, SharedBuffer* data) 61 : m_iconURL(iconURL) 62 , m_timestamp(timestamp) 63 , m_data(data) 64 { } 65 iconURL()66 const String& iconURL() const { return m_iconURL; } timestamp()67 int timestamp() const { return m_timestamp; } data()68 SharedBuffer* data() const { return m_data.get(); } 69 70 private: 71 String m_iconURL; 72 int m_timestamp; 73 RefPtr<SharedBuffer> m_data; 74 }; 75 76 class IconRecord : public RefCounted<IconRecord> { 77 friend class PageURLRecord; 78 public: create(const String & url)79 static PassRefPtr<IconRecord> create(const String& url) 80 { 81 return adoptRef(new IconRecord(url)); 82 } 83 ~IconRecord(); 84 getTimestamp()85 time_t getTimestamp() { return m_stamp; } setTimestamp(time_t stamp)86 void setTimestamp(time_t stamp) { m_stamp = stamp; } 87 88 void setImageData(PassRefPtr<SharedBuffer> data); 89 Image* image(const IntSize&); 90 iconURL()91 String iconURL() { return m_iconURL; } 92 93 void loadImageFromResource(const char*); 94 95 ImageDataStatus imageDataStatus(); 96 retainingPageURLs()97 const HashSet<String>& retainingPageURLs() { return m_retainingPageURLs; } 98 99 IconSnapshot snapshot(bool forDeletion = false) const; 100 101 private: 102 IconRecord(const String& url); 103 104 String m_iconURL; 105 time_t m_stamp; 106 RefPtr<Image> m_image; 107 108 HashSet<String> m_retainingPageURLs; 109 110 // This allows us to cache whether or not a SiteIcon has had its data set yet 111 // This helps the IconDatabase know if it has to set the data on a new object or not, 112 // and also to determine if the icon is missing data or if it just hasn't been brought 113 // in from the DB yet 114 bool m_dataSet; 115 116 // FIXME - Right now WebCore::Image doesn't have a very good API for accessing multiple representations 117 // Even the NSImage way of doing things that we do in WebKit isn't very clean... once we come up with a 118 // better way of handling that, we'll likely have a map of size-to-images similar to below 119 // typedef HashMap<IntSize, Image*> SizeImageMap; 120 // SizeImageMap m_images; 121 }; 122 123 124 } //namespace WebCore 125 126 #endif 127