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 #include "config.h"
     30 #include "IconRecord.h"
     31 
     32 #include "BitmapImage.h"
     33 #include "IconDatabase.h"
     34 #include "Logging.h"
     35 #include "SQLiteStatement.h"
     36 #include "SQLiteTransaction.h"
     37 
     38 #include <limits.h>
     39 
     40 namespace WebCore {
     41 
     42 IconRecord::IconRecord(const String& url)
     43     : m_iconURL(url)
     44     , m_stamp(0)
     45     , m_dataSet(false)
     46 {
     47 
     48 }
     49 
     50 IconRecord::~IconRecord()
     51 {
     52     LOG(IconDatabase, "Destroying IconRecord for icon url %s", m_iconURL.ascii().data());
     53 }
     54 
     55 Image* IconRecord::image(const IntSize&)
     56 {
     57     // FIXME rdar://4680377 - For size right now, we are returning our one and only image and the Bridge
     58     // is resizing it in place.  We need to actually store all the original representations here and return a native
     59     // one, or resize the best one to the requested size and cache that result.
     60 
     61     return m_image.get();
     62 }
     63 
     64 void IconRecord::setImageData(PassRefPtr<SharedBuffer> data)
     65 {
     66     // It's okay to delete the raw image here. Any existing clients using this icon will be
     67     // managing an image that was created with a copy of this raw image data.
     68     m_image = BitmapImage::create();
     69 
     70     // Copy the provided data into the buffer of the new Image object.
     71     if (!m_image->setData(data, true)) {
     72         LOG(IconDatabase, "Manual image data for iconURL '%s' FAILED - it was probably invalid image data", m_iconURL.ascii().data());
     73         m_image.clear();
     74     }
     75 
     76     m_dataSet = true;
     77 }
     78 
     79 void IconRecord::loadImageFromResource(const char* resource)
     80 {
     81     if (!resource)
     82         return;
     83 
     84     m_image = Image::loadPlatformResource(resource);
     85     m_dataSet = true;
     86 }
     87 
     88 ImageDataStatus IconRecord::imageDataStatus()
     89 {
     90     if (!m_dataSet)
     91         return ImageDataStatusUnknown;
     92     if (!m_image)
     93         return ImageDataStatusMissing;
     94     return ImageDataStatusPresent;
     95 }
     96 
     97 IconSnapshot IconRecord::snapshot(bool forDeletion) const
     98 {
     99     if (forDeletion)
    100         return IconSnapshot(m_iconURL, 0, 0);
    101 
    102     return IconSnapshot(m_iconURL, m_stamp, m_image ? m_image->data() : 0);
    103 }
    104 
    105 } // namespace WebCore
    106