2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
32 #include "PageURLRecord.h"
33 #include <wtf/RefCounted.h>
34 #include "SharedBuffer.h"
36 #include "PlatformString.h"
37 #include <wtf/HashSet.h>
38 #include <wtf/OwnPtr.h>
39 #include <wtf/text/StringHash.h>
42 #include <sys/types.h> // For time_t structure.
47 class IconDataSnapshot;
52 enum ImageDataStatus {
53 ImageDataStatusPresent, ImageDataStatusMissing, ImageDataStatusUnknown
58 IconSnapshot() : m_timestamp(0) { }
60 IconSnapshot(const String& iconURL, int timestamp, SharedBuffer* data)
62 , m_timestamp(timestamp)
66 const String& iconURL() const { return m_iconURL; }
67 int timestamp() const { return m_timestamp; }
68 SharedBuffer* data() const { return m_data.get(); }
73 RefPtr<SharedBuffer> m_data;
76 class IconRecord : public RefCounted<IconRecord> {
77 friend class PageURLRecord;
79 static PassRefPtr<IconRecord> create(const String& url)
81 return adoptRef(new IconRecord(url));
85 time_t getTimestamp() { return m_stamp; }
86 void setTimestamp(time_t stamp) { m_stamp = stamp; }
88 void setImageData(PassRefPtr<SharedBuffer> data);
89 Image* image(const IntSize&);
91 String iconURL() { return m_iconURL; }
93 void loadImageFromResource(const char*);
95 ImageDataStatus imageDataStatus();
97 const HashSet<String>& retainingPageURLs() { return m_retainingPageURLs; }
99 IconSnapshot snapshot(bool forDeletion = false) const;
102 IconRecord(const String& url);
106 RefPtr<Image> m_image;
108 HashSet<String> m_retainingPageURLs;
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
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;
124 } //namespace WebCore