Home | History | Annotate | Download | only in icon
      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 <wtf/HashSet.h>
     37 #include <wtf/OwnPtr.h>
     38 #include "PlatformString.h"
     39 #include "StringHash.h"
     40 
     41 namespace WebCore {
     42 
     43 class IconDataSnapshot;
     44 class Image;
     45 class IntSize;
     46 class SQLDatabase;
     47 
     48 enum ImageDataStatus {
     49     ImageDataStatusPresent, ImageDataStatusMissing, ImageDataStatusUnknown
     50 };
     51 
     52 class IconSnapshot {
     53 public:
     54     IconSnapshot() : timestamp(0) { }
     55 
     56     IconSnapshot(const String& url, int stamp, SharedBuffer* theData)
     57         : iconURL(url)
     58         , timestamp(stamp)
     59         , data(theData)
     60     { }
     61 
     62     String iconURL;
     63     int timestamp;
     64     RefPtr<SharedBuffer> data;
     65 };
     66 
     67 class IconRecord : public RefCounted<IconRecord> {
     68     friend class PageURLRecord;
     69 public:
     70     static PassRefPtr<IconRecord> create(const String& url)
     71     {
     72         return adoptRef(new IconRecord(url));
     73     }
     74     ~IconRecord();
     75 
     76     time_t getTimestamp() { return m_stamp; }
     77     void setTimestamp(time_t stamp) { m_stamp = stamp; }
     78 
     79     void setImageData(PassRefPtr<SharedBuffer> data);
     80     Image* image(const IntSize&);
     81 
     82     String iconURL() { return m_iconURL; }
     83 
     84     void loadImageFromResource(const char*);
     85 
     86     ImageDataStatus imageDataStatus();
     87 
     88     const HashSet<String>& retainingPageURLs() { return m_retainingPageURLs; }
     89 
     90     IconSnapshot snapshot(bool forDeletion = false) const;
     91 
     92 private:
     93     IconRecord(const String& url);
     94 
     95     String m_iconURL;
     96     time_t m_stamp;
     97     RefPtr<Image> m_image;
     98 
     99     HashSet<String> m_retainingPageURLs;
    100 
    101     // This allows us to cache whether or not a SiteIcon has had its data set yet
    102     // This helps the IconDatabase know if it has to set the data on a new object or not,
    103     // and also to determine if the icon is missing data or if it just hasn't been brought
    104     // in from the DB yet
    105     bool m_dataSet;
    106 
    107     // FIXME - Right now WebCore::Image doesn't have a very good API for accessing multiple representations
    108     // Even the NSImage way of doing things that we do in WebKit isn't very clean...  once we come up with a
    109     // better way of handling that, we'll likely have a map of size-to-images similar to below
    110     // typedef HashMap<IntSize, Image*> SizeImageMap;
    111     // SizeImageMap m_images;
    112 };
    113 
    114 
    115 } //namespace WebCore
    116 
    117 #endif
    118