WebCore:
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2007 08:07:59 +0000 (08:07 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Mar 2007 08:07:59 +0000 (08:07 +0000)
        Fix for bugzilla bug 13050 and also radar p1 5050645.

        This patch reworks resource loading to avoid having redundant buffers in the icon database and in cached
        images in the WebCore cache.  It also avoids overcopying in top-level image documents and in the icon
        database.

        There is now only one SharedBuffer for a resource and everybody observes that buffer now instead of ever
        making their own.  Even ImageIO uses the SharedBuffer while decoding.

        The page in 13050 dropped from 145mb down to 45mb of memory use with this change for a stunning savings
        of 100mb.

        Reviewed by olliej, mjs

        * WebCore.exp:
        * loader/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::data):
        * loader/CachedCSSStyleSheet.h:
        * loader/CachedImage.cpp:
        (WebCore::CachedImage::data):
        * loader/CachedImage.h:
        * loader/CachedResource.cpp:
        (WebCore::CachedResource::CachedResource):
        (WebCore::CachedResource::~CachedResource):
        * loader/CachedResource.h:
        (WebCore::CachedResource::data):
        * loader/CachedScript.cpp:
        (WebCore::CachedScript::data):
        * loader/CachedScript.h:
        * loader/CachedXSLStyleSheet.cpp:
        (WebCore::CachedXSLStyleSheet::data):
        * loader/CachedXSLStyleSheet.h:
        * loader/DocLoader.cpp:
        (WebCore::DocLoader::checkCacheObjectStatus):
        * loader/ImageDocument.cpp:
        (WebCore::ImageTokenizer::writeRawData):
        (WebCore::ImageTokenizer::finish):
        * loader/icon/IconDataCache.cpp:
        (WebCore::IconDataCache::setImageData):
        (WebCore::IconDataCache::writeToDatabase):
        * loader/icon/IconDataCache.h:
        * loader/icon/IconDatabase.cpp:
        (WebCore::IconDatabase::imageDataForIconURL):
        (WebCore::IconDatabase::iconForPageURL):
        (WebCore::IconDatabase::setIconDataForIconURL):
        (WebCore::IconDatabase::setHaveNoIconForIconURL):
        (WebCore::IconDatabase::imageDataForIconURLQuery):
        * loader/icon/IconDatabase.h:
        * loader/icon/IconLoader.cpp:
        (WebCore::IconLoader::startLoading):
        (WebCore::IconLoader::didReceiveResponse):
        (WebCore::IconLoader::didReceiveData):
        (WebCore::IconLoader::didFail):
        (WebCore::IconLoader::finishLoading):
        (WebCore::IconLoader::clearLoadingState):
        * loader/icon/IconLoader.h:
        * loader/icon/SQLStatement.cpp:
        (WebCore::SQLStatement::getColumnBlobAsVector):
        (WebCore::SQLStatement::isExpired):
        * loader/icon/SQLStatement.h:
        * loader/loader.cpp:
        (WebCore::Loader::didFinishLoading):
        (WebCore::Loader::didReceiveData):
        * page/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge getData:andResponse:forURL:]):
        (-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
        * platform/SharedBuffer.h:
        (WebCore::SharedBuffer::isEmpty):
        * platform/graphics/BitmapImage.cpp:
        (WebCore::BitmapImage::destroyDecodedData):
        (WebCore::BitmapImage::dataChanged):
        * platform/graphics/BitmapImage.h:
        * platform/graphics/Image.cpp:
        (WebCore::Image::setData):
        * platform/graphics/Image.h:
        (WebCore::Image::dataChanged):
        (WebCore::Image::data):
        * platform/graphics/ImageSource.h:
        * platform/graphics/cg/ImageSourceCG.cpp:
        (WebCore::ImageSource::setData):
        * platform/graphics/cg/PDFDocumentImage.cpp:
        (WebCore::PDFDocumentImage::dataChanged):
        * platform/graphics/cg/PDFDocumentImage.h:
        * platform/graphics/mac/ImageMac.mm:
        (WebCore::Image::loadPlatformResource):
        * platform/graphics/svg/SVGImage.cpp:
        (WebCore::SVGImage::setData):
        * platform/mac/PasteboardMac.mm:
        (WebCore::fileWrapperForImage):

WebKit:

        Fixes to ensure that the resource loader's shared buffer can always be used.

        Reviewed by olliej, mjs

        * Misc/WebIconDatabase.mm:
        (-[WebIconDatabase _convertToWebCoreFormat]):
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::deliverArchivedResources):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@20182 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/loader/CachedCSSStyleSheet.cpp
WebCore/loader/CachedCSSStyleSheet.h
WebCore/loader/CachedImage.cpp
WebCore/loader/CachedImage.h
WebCore/loader/CachedResource.cpp
WebCore/loader/CachedResource.h
WebCore/loader/CachedScript.cpp
WebCore/loader/CachedScript.h
WebCore/loader/CachedXSLStyleSheet.cpp
WebCore/loader/CachedXSLStyleSheet.h
WebCore/loader/DocLoader.cpp
WebCore/loader/ImageDocument.cpp
WebCore/loader/icon/IconDataCache.cpp
WebCore/loader/icon/IconDataCache.h
WebCore/loader/icon/IconDatabase.cpp
WebCore/loader/icon/IconDatabase.h
WebCore/loader/icon/IconLoader.cpp
WebCore/loader/icon/IconLoader.h
WebCore/loader/icon/SQLStatement.cpp
WebCore/loader/icon/SQLStatement.h
WebCore/loader/loader.cpp
WebCore/page/mac/WebCoreFrameBridge.mm
WebCore/platform/SharedBuffer.h
WebCore/platform/graphics/BitmapImage.cpp
WebCore/platform/graphics/BitmapImage.h
WebCore/platform/graphics/Image.cpp
WebCore/platform/graphics/Image.h
WebCore/platform/graphics/ImageSource.h
WebCore/platform/graphics/cg/ImageSourceCG.cpp
WebCore/platform/graphics/cg/PDFDocumentImage.cpp
WebCore/platform/graphics/cg/PDFDocumentImage.h
WebCore/platform/graphics/mac/ImageMac.mm
WebCore/platform/graphics/svg/SVGImage.cpp
WebCore/platform/graphics/svg/SVGImage.h
WebCore/platform/mac/PasteboardMac.mm
WebKit/ChangeLog
WebKit/Misc/WebIconDatabase.mm
WebKit/WebCoreSupport/WebFrameLoaderClient.mm

index e151de4b9a3aeef277bd626bd205ac4a2053caa6..c5a749582a93e90c28a312feb82c27d8ccf8d1ca 100644 (file)
@@ -1,3 +1,95 @@
+2007-03-13  David Hyatt  <hyatt@apple.com>
+
+        Fix for bugzilla bug 13050 and also radar p1 5050645.
+
+        This patch reworks resource loading to avoid having redundant buffers in the icon database and in cached
+        images in the WebCore cache.  It also avoids overcopying in top-level image documents and in the icon
+        database.
+
+        There is now only one SharedBuffer for a resource and everybody observes that buffer now instead of ever
+        making their own.  Even ImageIO uses the SharedBuffer while decoding.
+
+        The page in 13050 dropped from 145mb down to 45mb of memory use with this change for a stunning savings
+        of 100mb.
+
+        Reviewed by olliej, mjs
+
+        * WebCore.exp:
+        * loader/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::data):
+        * loader/CachedCSSStyleSheet.h:
+        * loader/CachedImage.cpp:
+        (WebCore::CachedImage::data):
+        * loader/CachedImage.h:
+        * loader/CachedResource.cpp:
+        (WebCore::CachedResource::CachedResource):
+        (WebCore::CachedResource::~CachedResource):
+        * loader/CachedResource.h:
+        (WebCore::CachedResource::data):
+        * loader/CachedScript.cpp:
+        (WebCore::CachedScript::data):
+        * loader/CachedScript.h:
+        * loader/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::data):
+        * loader/CachedXSLStyleSheet.h:
+        * loader/DocLoader.cpp:
+        (WebCore::DocLoader::checkCacheObjectStatus):
+        * loader/ImageDocument.cpp:
+        (WebCore::ImageTokenizer::writeRawData):
+        (WebCore::ImageTokenizer::finish):
+        * loader/icon/IconDataCache.cpp:
+        (WebCore::IconDataCache::setImageData):
+        (WebCore::IconDataCache::writeToDatabase):
+        * loader/icon/IconDataCache.h:
+        * loader/icon/IconDatabase.cpp:
+        (WebCore::IconDatabase::imageDataForIconURL):
+        (WebCore::IconDatabase::iconForPageURL):
+        (WebCore::IconDatabase::setIconDataForIconURL):
+        (WebCore::IconDatabase::setHaveNoIconForIconURL):
+        (WebCore::IconDatabase::imageDataForIconURLQuery):
+        * loader/icon/IconDatabase.h:
+        * loader/icon/IconLoader.cpp:
+        (WebCore::IconLoader::startLoading):
+        (WebCore::IconLoader::didReceiveResponse):
+        (WebCore::IconLoader::didReceiveData):
+        (WebCore::IconLoader::didFail):
+        (WebCore::IconLoader::finishLoading):
+        (WebCore::IconLoader::clearLoadingState):
+        * loader/icon/IconLoader.h:
+        * loader/icon/SQLStatement.cpp:
+        (WebCore::SQLStatement::getColumnBlobAsVector):
+        (WebCore::SQLStatement::isExpired):
+        * loader/icon/SQLStatement.h:
+        * loader/loader.cpp:
+        (WebCore::Loader::didFinishLoading):
+        (WebCore::Loader::didReceiveData):
+        * page/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge getData:andResponse:forURL:]):
+        (-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
+        * platform/SharedBuffer.h:
+        (WebCore::SharedBuffer::isEmpty):
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::destroyDecodedData):
+        (WebCore::BitmapImage::dataChanged):
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::setData):
+        * platform/graphics/Image.h:
+        (WebCore::Image::dataChanged):
+        (WebCore::Image::data):
+        * platform/graphics/ImageSource.h:
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::ImageSource::setData):
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::dataChanged):
+        * platform/graphics/cg/PDFDocumentImage.h:
+        * platform/graphics/mac/ImageMac.mm:
+        (WebCore::Image::loadPlatformResource):
+        * platform/graphics/svg/SVGImage.cpp:
+        (WebCore::SVGImage::setData):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::fileWrapperForImage):
+
 2007-03-13  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by darin
index 88b6e37c495dd8f5e45bcf62fa4be95b82df6850..8c7a042fedb248f7075964991c78212139b00d1d 100644 (file)
@@ -219,7 +219,7 @@ __ZN7WebCore12IconDatabase18sharedIconDatabaseEv
 __ZN7WebCore12IconDatabase20retainIconForPageURLERKNS_6StringE
 __ZN7WebCore12IconDatabase20setIconURLForPageURLERKNS_6StringES3_
 __ZN7WebCore12IconDatabase21releaseIconForPageURLERKNS_6StringE
-__ZN7WebCore12IconDatabase21setIconDataForIconURLEPKviRKNS_6StringE
+__ZN7WebCore12IconDatabase21setIconDataForIconURLEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS_6StringE
 __ZN7WebCore12IconDatabase23defaultDatabaseFilenameEv
 __ZN7WebCore12IconDatabase23isIconExpiredForIconURLERKNS_6StringE
 __ZN7WebCore12IconDatabase23setHaveNoIconForIconURLERKNS_6StringE
index 95d5e93cc324ed882d8fd475667ed652b4c71b86..1ded18795315211d5abb1584ee7cef4292e4b234 100644 (file)
@@ -67,13 +67,17 @@ void CachedCSSStyleSheet::setEncoding(const String& chs)
     m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
 }
 
-void CachedCSSStyleSheet::data(Vector<char>& data, bool allDataReceived)
+void CachedCSSStyleSheet::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
 
-    setEncodedSize(data.size());
-    m_sheet = m_decoder->decode(data.data(), encodedSize());
+    m_data = data;
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    if (!m_data.get())
+        return;
+
+    m_sheet = m_decoder->decode(m_data->data(), encodedSize());
     m_sheet += m_decoder->flush();
     m_loading = false;
     checkNotify();
index 6f69d1f236b04d0a5037aa4e0f59110bd7abb611..184df023d11c3daea5e2bf037eabaa8f7b4f0150 100644 (file)
@@ -47,7 +47,7 @@ namespace WebCore {
         virtual void ref(CachedResourceClient*);
  
         virtual void setEncoding(const String&);
-        virtual void data(Vector<char>&, bool allDataReceived);
+        virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
         virtual void error();
 
         virtual bool schedule() const { return true; }
index f36c5d864f628761e28bcd2521d1451adaf54db0..3903bfc488e00e5387dc48112293546de3c4efc5 100644 (file)
@@ -165,43 +165,10 @@ inline void CachedImage::createImage()
     m_image = new BitmapImage(this);
 }
 
-Vector<char>& CachedImage::bufferData(const char* bytes, int addedSize, Request* request)
+void CachedImage::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
 {
-    createImage();
-
-    Vector<char>& imageBuffer = m_image->dataBuffer();
-
-    if (addedSize > 0) {
-        bool success = false;
-        unsigned oldSize = imageBuffer.size();
-        unsigned newSize = oldSize + addedSize;
-
-        // Check for overflow
-        if (newSize > oldSize) {
-            // Use temporary Vector so we can safely detect if the allocation fails
-            //
-            // The code that was here before, just called resize of the imageBuffer.  Vector<>::resize
-            // will crash if the resize of a non-empty Vector<> fails.
-            Vector<char> tempBuffer(newSize);
-
-            char* tempBufferBytes = tempBuffer.data();
-            if (tempBufferBytes) {
-                memcpy(tempBufferBytes, imageBuffer.data(), oldSize);
-                memcpy(tempBufferBytes + oldSize, bytes, addedSize);
-                tempBuffer.swap(imageBuffer);
-                success = true;
-            }
-        }
-
-        if (!success)
-            error();
-    }
+    m_data = data;
 
-    return imageBuffer;
-}
-
-void CachedImage::data(Vector<char>& data, bool allDataReceived)
-{
     createImage();
 
     bool sizeAvailable = false;
@@ -209,7 +176,7 @@ void CachedImage::data(Vector<char>& data, bool allDataReceived)
     // Have the image update its data from its internal buffer.
     // It will not do anything now, but will delay decoding until 
     // queried for info (like size or specific image frames).
-    sizeAvailable = m_image->setData(allDataReceived);
+    sizeAvailable = m_image->setData(m_data, allDataReceived);
 
     // Go ahead and tell our observers to try to draw if we have either
     // received all the data or the size is known.  Each chunk from the
@@ -226,16 +193,8 @@ void CachedImage::data(Vector<char>& data, bool allDataReceived)
         
         notifyObservers();
 
-        if (m_image) {
-            Vector<char>& imageBuffer = m_image->dataBuffer();
-#if PLATFORM(CG)
-            // ImageIO sources copy the image data.  We will go ahead and count encoded
-            // size twice until this issue is fixed.  See <rdar://problem/5050645>
-            setEncodedSize(imageBuffer.size() * 2);
-#else
-            setEncodedSize(imageBuffer.size());
-#endif
-        }
+        if (m_image)
+            setEncodedSize(m_image->data() ? m_image->data()->size() : 0);
     }
     
     if (allDataReceived) {
index 74249b7c7f7de37b3e2b6e0ea3ba121fa0319ea8..b69f42196727c7e645a008747b78bb765dfc34e2 100644 (file)
@@ -57,8 +57,7 @@ public:
     virtual void allReferencesRemoved();
     virtual void destroyDecodedData();
 
-    virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
-    virtual void data(Vector<char>&, bool allDataReceived);
+    virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
     virtual void error();
 
     virtual bool schedule() const { return true; }
@@ -83,7 +82,6 @@ private:
     void notifyObservers();
 
     Image* m_image;
-    int m_dataSize;
 
     friend class Cache;
 };
index eb0b1907ec16338a6264cb00d35cce9991ffb53a..e16e8031b97ea076f429de3abfe43131ff38521f 100644 (file)
@@ -46,7 +46,6 @@ CachedResource::CachedResource(const String& URL, Type type, CachePolicy cachePo
     m_inCache = false;
     m_cachePolicy = cachePolicy;
     m_request = 0;
-    m_allData = 0;
     m_expireDateChanged = false;
     m_accessCount = 0;
     m_nextInLRUList = 0;
@@ -66,19 +65,6 @@ CachedResource::~CachedResource()
 #ifndef NDEBUG
     m_deleted = true;
 #endif
-    setAllData(0);
-}
-
-Vector<char>& CachedResource::bufferData(const char* bytes, int addedSize, Request* request)
-{
-    // Add new bytes to the buffer in the Request object.
-    Vector<char>& buffer = request->buffer();
-
-    unsigned oldSize = buffer.size();
-    buffer.resize(oldSize + addedSize);
-    memcpy(buffer.data() + oldSize, bytes, addedSize);
-    
-    return buffer;
 }
 
 void CachedResource::finish()
index 234ee6fda0e08ca5b7fc37b90c937c814a701c6c..86f0a8d78a0c22c9f15fddb29849eaef60695dd8 100644 (file)
@@ -71,8 +71,7 @@ public:
     virtual ~CachedResource();
 
     virtual void setEncoding(const String&) { }
-    virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
-    virtual void data(Vector<char>&, bool allDataReceived) = 0;
+    virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived) = 0;
     virtual void error() = 0;
 
     const String &url() const { return m_url; }
@@ -113,8 +112,7 @@ public:
 
     void setRequest(Request*);
 
-    SharedBuffer* allData() const { return m_allData.get(); }
-    void setAllData(PassRefPtr<SharedBuffer> allData) { m_allData = allData; }
+    SharedBuffer* data() const { return m_data.get(); }
 
     void setResponse(const ResourceResponse& response) { m_response = response; }
     const ResourceResponse& response() const { return m_response; }
@@ -145,7 +143,7 @@ protected:
     Request* m_request;
 
     ResourceResponse m_response;
-    RefPtr<SharedBuffer> m_allData;
+    RefPtr<SharedBuffer> m_data;
 
     Type m_type;
     Status m_status;
index 89637fc14fd979dae87f6dde669e4834a9ae6f6f..7367a8d74d6cbf449039473bd37c389660a539a9 100644 (file)
@@ -70,13 +70,16 @@ void CachedScript::setEncoding(const String& chs)
         m_encoding = encoding;
 }
 
-void CachedScript::data(Vector<char>& data, bool allDataReceived)
+void CachedScript::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
 {
-    if (!allDataReceived)
+    if (!allDataReceived || !data.get())
         return;
 
-    setEncodedSize(data.size());
-    m_script = m_encoding.decode(data.data(), encodedSize());
+    m_data = data;
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    if (!m_data.get())
+        return;
+    m_script = m_encoding.decode(m_data->data(), encodedSize());
     m_loading = false;
     checkNotify();
 }
index f8b7f7fd85ae96b6bef981232110424b10e1e6f3..56a4a3900a8438a47e60dddf63218ff4c8c295f3 100644 (file)
@@ -45,7 +45,7 @@ namespace WebCore {
         virtual void ref(CachedResourceClient*);
 
         virtual void setEncoding(const String&);
-        virtual void data(Vector<char>&, bool allDataReceived);
+        virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
         virtual void error();
 
         virtual bool schedule() const { return false; }
index f12806b3eaf5410e1bee0e3a35916a40999f67de..90d66cea3340447eefc3f0e41f085ad173649bbf 100644 (file)
@@ -66,13 +66,16 @@ void CachedXSLStyleSheet::setEncoding(const String& chs)
     m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
 }
 
-void CachedXSLStyleSheet::data(Vector<char>& data, bool allDataReceived)
+void CachedXSLStyleSheet::data(PassRefPtr<SharedBuffer> data, bool allDataReceived)
 {
-    if (!allDataReceived)
+    if (!allDataReceived || !data.get())
         return;
 
-    setEncodedSize(data.size());
-    m_sheet = String(m_decoder->decode(data.data(), encodedSize()));
+    m_data = data;     
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    if (!m_data.get())
+        return;
+    m_sheet = String(m_decoder->decode(m_data->data(), encodedSize()));
     m_sheet += m_decoder->flush();
     m_loading = false;
     checkNotify();
index 6bfc1aeda2e56e09d474187e15057d27990c3054..d4ba168cc94f141047944a3dad75e266a48a5a17 100644 (file)
@@ -46,7 +46,7 @@ namespace WebCore {
         virtual void ref(CachedResourceClient*);
         
         virtual void setEncoding(const String&);
-        virtual void data(Vector<char>&, bool allDataReceived);
+        virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived);
         virtual void error();
         
         virtual bool schedule() const { return true; }
index 72d53e4cb6ea07bcdba461d6e15d8be780f3c58e..3a3cf859b822e13176e58f486124844b23b1b268 100644 (file)
@@ -202,7 +202,7 @@ void DocLoader::checkCacheObjectStatus(CachedResource* resource)
     
     ResourceRequest request(resource->url());
     const ResourceResponse& response = resource->response();
-    SharedBuffer* data = resource->allData();
+    SharedBuffer* data = resource->data();
     
     // FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load.
     m_frame->loader()->loadedResourceFromMemoryCache(request, response, data ? data->size() : 0);
index 3c59d1ee84f3a3ff9b0ce75de511ff633d5ffc05..4af1eac0769870757a49e619a41b4807f129abfb 100644 (file)
@@ -96,7 +96,7 @@ bool ImageTokenizer::writeRawData(const char* data, int len)
         createDocumentStructure();
 
     CachedImage* cachedImage = m_imageElement->cachedImage();
-    cachedImage->data(cachedImage->bufferData(data, len, 0), false);
+    cachedImage->data(m_doc->frame()->loader()->documentLoader()->mainResourceData(), false);
 
     return false;
 }
@@ -112,11 +112,9 @@ void ImageTokenizer::finish()
 {
     if (!m_parserStopped && m_imageElement) {
         CachedImage* cachedImage = m_imageElement->cachedImage();
-        Vector<char>& buffer = cachedImage->bufferData(0, 0, 0);
-        cachedImage->data(buffer, true);
+        cachedImage->data(m_doc->frame()->loader()->documentLoader()->mainResourceData(), true);
         cachedImage->finish();
 
-        cachedImage->setAllData(m_doc->frame()->loader()->documentLoader()->mainResourceData());
         cachedImage->setResponse(m_doc->frame()->loader()->documentLoader()->response());
         
         // FIXME: Need code to set the title for platforms other than Mac OS X.
index 715261c1998d0e60946a0d5e6096122e1c176e72..4416114e07b21fcfa4680de97fb0dbe55eeeded5 100644 (file)
@@ -60,24 +60,16 @@ Image* IconDataCache::getImage(const IntSize& size)
     return 0;
 }
 
-void IconDataCache::setImageData(unsigned char* data, int size)
+void IconDataCache::setImageData(PassRefPtr<SharedBuffer> data)
 {
-    if (!data)
-        ASSERT(!size);
-
     // It's okay to delete the raw image data here. Any existing clients using this icon will be
     // managing an image that was created with a copy of this raw image data.
     if (m_image)
         delete m_image;
     m_image = new BitmapImage();
 
-    // Copy the provided data into the buffer of the new Image object
-    Vector<char>& dataBuffer = m_image->dataBuffer();
-    dataBuffer.resize(size);
-    memcpy(dataBuffer.data(), data, size);
-    
-    // Tell the Image object that all of its data has been set
-    if (!m_image->setData(true)) {
+    // Copy the provided data into the buffer of the new Image object.
+    if (!m_image->setData(data, true)) {
         LOG(IconDatabase, "Manual image data for iconURL '%s' FAILED - it was probably invalid image data", m_iconURL.ascii().data());
         delete m_image;
         m_image = 0;
@@ -119,8 +111,8 @@ void IconDataCache::writeToDatabase(SQLDatabase& db)
     
     // If we *have* image data, bind it to this statement - Otherwise the DB will get "null" for the blob data, 
     // signifying that this icon doesn't have any data    
-    if (m_image && !m_image->dataBuffer().isEmpty())
-        if (updateAttempt.bindBlob(2, m_image->dataBuffer().data(), m_image->dataBuffer().size()) != SQLResultOk) {
+    if (m_image && !m_image->data()->isEmpty())
+        if (updateAttempt.bindBlob(2, m_image->data()->data(), m_image->data()->size()) != SQLResultOk) {
             LOG_ERROR("Failed to bind icon data to SQL statement to update icon data for url %s", m_iconURL.ascii().data());
             return;
         }
@@ -146,8 +138,8 @@ void IconDataCache::writeToDatabase(SQLDatabase& db)
         
     // Then, if we *have* data, we bind it.  Otherwise the DB will get "null" for the blob data, 
     // signifying that this icon doesn't have any data
-    if (m_image && !m_image->dataBuffer().isEmpty())
-        insertStatement.bindBlob(3, m_image->dataBuffer().data(), m_image->dataBuffer().size());
+    if (m_image && !m_image->data()->isEmpty())
+        insertStatement.bindBlob(3, m_image->data()->data(), m_image->data()->size());
     
     // Finally we step and make sure the step was successful
     if (insertStatement.step() != SQLResultDone)
index 39490a03a5b8268463589d9b1287731245cb8baa..f5801f9574bd5bf68552883e7dbcd1d9b5e82bb9 100644 (file)
@@ -32,6 +32,7 @@ namespace WebCore {
 
 class Image;
 class IntSize;
+class SharedBuffer;
 class SQLDatabase;
 
 enum ImageDataStatus {
@@ -49,7 +50,7 @@ public:
     Image* getImage(const IntSize&);    
     String getIconURL() { return m_iconURL; }
 
-    void setImageData(unsigned char* data, int size);
+    void setImageData(PassRefPtr<SharedBuffer> data);
     
     void loadImageFromResource(const char*);
     
index 1e24d0d3e858739fd32f6573e1e97b629a54a95b..7bee2b193fe1c62b9a0434cf6731238b6d20bb8a 100644 (file)
@@ -320,12 +320,12 @@ void IconDatabase::createDatabaseTables(SQLDatabase& db)
     }
 }    
 
-void IconDatabase::imageDataForIconURL(const String& iconURL, Vector<unsigned char>& result)
+void IconDatabase::imageDataForIconURL(const String& iconURL, PassRefPtr<SharedBuffer> result)
 {      
     // If private browsing is enabled, we'll check there first as the most up-to-date data for an icon will be there
     if (m_privateBrowsingEnabled) {    
         imageDataForIconURLQuery(m_privateBrowsingDB, iconURL, result);
-        if (!result.isEmpty())
+        if (!result->isEmpty())
             return;
     } 
     
@@ -370,9 +370,9 @@ Image* IconDatabase::iconForPageURL(const String& pageURL, const IntSize& size,
     // If it's a new IconDataCache object that doesn't have its imageData set yet,
     // we'll read in that image data now
     if (icon->imageDataStatus() == ImageDataStatusUnknown) {
-        Vector<unsigned char> data;
-        imageDataForIconURL(iconURL, data);
-        icon->setImageData(data.data(), data.size());
+        RefPtr<SharedBuffer> data = new SharedBuffer();
+        imageDataForIconURL(iconURL, data.get());
+        icon->setImageData(data.get());
     }
         
     return icon->getImage(size);
@@ -640,22 +640,16 @@ IconDataCache* IconDatabase::getOrCreateIconDataCache(const String& iconURL)
     return icon;
 }
 
-void IconDatabase::setIconDataForIconURL(const void* data, int size, const String& iconURL)
+void IconDatabase::setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String& iconURL)
 {
-    ASSERT(size > -1);
     if (!isOpen() || iconURL.isEmpty())
         return;
 
-    if (size)
-        ASSERT(data);
-    else
-        data = 0;
-    
     // Get the IconDataCache for this IconURL (note, IconDataCacheForIconURL will create it if necessary)
     IconDataCache* icon = getOrCreateIconDataCache(iconURL);
     
     // Set the data in the IconDataCache
-    icon->setImageData((unsigned char*)data, size);
+    icon->setImageData(data);
     
     // Update the timestamp in the IconDataCache to NOW
     icon->setTimestamp((int)currentTime());
@@ -666,7 +660,7 @@ void IconDatabase::setIconDataForIconURL(const void* data, int size, const Strin
 
 void IconDatabase::setHaveNoIconForIconURL(const String& iconURL)
 {   
-    setIconDataForIconURL(0, 0, iconURL);
+    setIconDataForIconURL(0, iconURL);
 }
 
 bool IconDatabase::setIconURLForPageURL(const String& iconURL, const String& pageURL)
@@ -955,16 +949,18 @@ bool IconDatabase::pageURLTableIsEmptyQuery(SQLDatabase& db)
     return !SQLStatement(db, "SELECT iconID FROM PageURL LIMIT 1;").returnsAtLeastOneResult();
 }
 
-void IconDatabase::imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, Vector<unsigned char>& imageData)
+void IconDatabase::imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, PassRefPtr<SharedBuffer> imageData)
 {
     readySQLStatement(m_imageDataForIconURLStatement, db, "SELECT Icon.data FROM Icon WHERE Icon.url = (?);");
     m_imageDataForIconURLStatement->bindText16(1, iconURL, false);
     
     int result = m_imageDataForIconURLStatement->step();
-    imageData.clear();
-    if (result == SQLResultRow)
-        m_imageDataForIconURLStatement->getColumnBlobAsVector(0, imageData);
-    else if (result != SQLResultDone)
+    imageData->clear();
+    if (result == SQLResultRow) {
+        Vector<char> data;
+        m_imageDataForIconURLStatement->getColumnBlobAsVector(0, data);
+        imageData->append(data.data(), data.size());
+    } else if (result != SQLResultDone)
         LOG_ERROR("imageDataForIconURLQuery failed");
 
     m_imageDataForIconURLStatement->reset();
index 4d86c0b90018b72b588b4620728fe2e34d941fbb..1855b0c8d7fa8448e8c07b3ad7a4c5b310599270 100644 (file)
@@ -38,6 +38,7 @@ namespace WebCore {
 class Image;
 class IntSize;
 class IconDataCache;
+class SharedBuffer;
 class SQLTransaction;
 
 class IconDatabase : Noncopyable {
@@ -67,7 +68,7 @@ public:
 
     bool isIconExpiredForIconURL(const String&);
     
-    void setIconDataForIconURL(const void* data, int size, const String&);
+    void setIconDataForIconURL(PassRefPtr<SharedBuffer> data, const String&);
     void setHaveNoIconForIconURL(const String&);
     
     // Returns true if the set actually took place, false if the mapping already existed
@@ -121,7 +122,7 @@ private:
     void createDatabaseTables(SQLDatabase&);
     
     // Returns the image data for the given IconURL, checking both databases if necessary
-    void imageDataForIconURL(const String& iconURL, Vector<unsigned char>&);
+    void imageDataForIconURL(const String& iconURL, PassRefPtr<SharedBuffer> result);
     
     // Retains an iconURL, bringing it back from the brink if it was pending deletion
     void retainIconURL(const String& iconURL);
@@ -161,7 +162,7 @@ private:
     SQLStatement* m_addIconForIconURLStatement;
     
     // Query - Returns the image data from the given database for the given IconURL
-    void imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, Vector<unsigned char>& result);
+    void imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, PassRefPtr<SharedBuffer> result);
     SQLStatement* m_imageDataForIconURLStatement;
 
     void deleteAllPreparedStatements(bool withSync);
index ff39588ef1f3afea33658373b70168a8eed4d77a..33bbc1c22f544406efb9f3ae9e97edc2e9f5aae0 100644 (file)
@@ -41,8 +41,6 @@ using namespace std;
 
 namespace WebCore {
 
-const size_t defaultBufferSize = 4096; // bigger than most icons
-
 IconLoader::IconLoader(Frame* frame)
     : m_frame(frame)
     , m_loadIsInProgress(false)
@@ -74,7 +72,6 @@ void IconLoader::startLoading()
     // Set flag so we can detect the case where the load completes before
     // SubresourceLoader::create returns.
     m_loadIsInProgress = true;
-    m_buffer.reserveCapacity(defaultBufferSize);
 
     RefPtr<SubresourceLoader> loader = SubresourceLoader::create(m_frame, this, m_frame->loader()->iconURL());
     if (!loader)
@@ -99,22 +96,18 @@ void IconLoader::didReceiveResponse(SubresourceLoader* resourceLoader, const Res
     int status = response.httpStatusCode();
     if (status && (status < 200 || status > 299)) {
         KURL iconURL = resourceLoader->handle()->url();
-        m_resourceLoader = 0;
         finishLoading(iconURL);
+        m_resourceLoader = 0;
     }
 }
 
 void IconLoader::didReceiveData(SubresourceLoader*, const char* data, int size)
 {
-    ASSERT(data || size == 0);
-    ASSERT(size >= 0);
-    m_buffer.append(data, size);
 }
 
 void IconLoader::didFail(SubresourceLoader* resourceLoader, const ResourceError&)
 {
     ASSERT(m_loadIsInProgress);
-    m_buffer.clear();
     finishLoading(resourceLoader->handle()->url());
 }
 
@@ -130,7 +123,7 @@ void IconLoader::didFinishLoading(SubresourceLoader* resourceLoader)
 
 void IconLoader::finishLoading(const KURL& iconURL)
 {
-    IconDatabase::sharedIconDatabase()->setIconDataForIconURL(m_buffer.data(), m_buffer.size(), iconURL.url());
+    IconDatabase::sharedIconDatabase()->setIconDataForIconURL(m_resourceLoader->resourceData(), iconURL.url());
     m_frame->loader()->commitIconURLToIconDatabase(iconURL);
     m_frame->loader()->client()->dispatchDidReceiveIcon();
     clearLoadingState();
@@ -139,7 +132,6 @@ void IconLoader::finishLoading(const KURL& iconURL)
 void IconLoader::clearLoadingState()
 {
     m_resourceLoader = 0;
-    m_buffer.clear();
     m_loadIsInProgress = false;
 }
 
index 4076469b6fa668356de0ea09b61c123db9f1d69f..d63e3ca268341f21618c4916f87e97257d030bcb 100644 (file)
@@ -30,7 +30,6 @@
 #include "SubresourceLoaderClient.h"
 #include <memory>
 #include <wtf/Noncopyable.h>
-#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -58,7 +57,6 @@ private:
     Frame* m_frame;
 
     RefPtr<SubresourceLoader> m_resourceLoader;
-    Vector<char> m_buffer;
     bool m_loadIsInProgress;
 }; // class IconLoader
 
index 1406acbfe2e366f9c3855ddddd657e2dcc381b89..c97230c8fa3dc8de1ac751c54a015c3a4c13b7be 100644 (file)
@@ -230,7 +230,7 @@ int64_t SQLStatement::getColumnInt64(int col)
     return sqlite3_column_int64(m_statement, col);
 }
     
-void SQLStatement::getColumnBlobAsVector(int col, Vector<unsigned char>& result)
+void SQLStatement::getColumnBlobAsVector(int col, Vector<char>& result)
 {
     if (!m_statement && prepareAndStep() != SQLITE_ROW) {
         result.clear();
@@ -373,9 +373,9 @@ bool SQLStatement::returnDoubleResults(int col, Vector<double>& v)
     return result;
 }
 
-bool SQLStatement::isExpired()\r
-{\r
-    return m_statement ? sqlite3_expired(m_statement) : true;\r
-}\r
+bool SQLStatement::isExpired()
+{
+    return m_statement ? sqlite3_expired(m_statement) : true;
+}
 
 } // namespace WebCore
index 3a75f61ded709f51e63150a30e7a7f0d227032d3..06cdda2d25c87e4c594cfc127845e6c2d11f0cf8 100644 (file)
@@ -79,7 +79,7 @@ public:
     int getColumnInt(int col);
     int64_t getColumnInt64(int col);
     const void* getColumnBlob(int col, int& size);
-    void getColumnBlobAsVector(int col, Vector<unsigned char>&);
+    void getColumnBlobAsVector(int col, Vector<char>&);
 
     bool returnTextResults(int col, Vector<String>&);
     bool returnTextResults16(int col, Vector<String>&);
index 80fa35258b929152f3182477730a74b9cbc2d509..7bf9adb92a5b9d15e86872cd32df021957d2003d 100644 (file)
@@ -104,8 +104,7 @@ void Loader::didFinishLoading(SubresourceLoader* loader)
     DocLoader* docLoader = req->docLoader();
 
     docLoader->setLoadInProgress(true);
-    object->data(req->buffer(), true);
-    object->setAllData(loader->resourceData());
+    object->data(loader->resourceData(), true);
     docLoader->setLoadInProgress(false);
     object->finish();
 
@@ -167,14 +166,13 @@ void Loader::didReceiveData(SubresourceLoader* loader, const char* data, int siz
         return;
 
     CachedResource* object = request->cachedResource();    
-    Vector<char>& buffer = object->bufferData(data, size, request);
 
     // Set the data.
     if (request->isMultipart())
         // The loader delivers the data in a multipart section all at once, send eof.
-        object->data(buffer, true);
+        object->data(loader->resourceData(), true);
     else if (request->isIncremental())
-        object->data(buffer, false);
+        object->data(loader->resourceData(), false);
 }
 
 int Loader::numRequests(DocLoader* dl) const
index 05cdaee38fd28979997e1bdf453e3f803a762eb3..6e76d69bd626ac06a14f489e9b8f021c52d8f2d0 100644 (file)
@@ -1408,7 +1408,7 @@ static NSCharacterSet *_getPostSmartSet(void)
     if (!resource)
         return NO;
 
-    SharedBuffer* buffer = resource->allData();
+    SharedBuffer* buffer = resource->data();
     if (buffer)
         *data = [buffer->createNSData() autorelease];
     else
@@ -1435,7 +1435,7 @@ static NSCharacterSet *_getPostSmartSet(void)
 
     HashMap<String, CachedResource*>::const_iterator end = allResources.end();
     for (HashMap<String, CachedResource*>::const_iterator it = allResources.begin(); it != end; ++it) {
-        SharedBuffer* buffer = it->second->allData();
+        SharedBuffer* buffer = it->second->data();
         NSData *data;
         
         if (buffer)
index 23e9333c018d8aee3ecd9c9d55a97f27cd80662e..50ce48e519d44b796f35da2670b3f0e1120dae38 100644 (file)
@@ -54,6 +54,8 @@ public:
     const char* data() const;
     unsigned size() const;
 
+    bool isEmpty() const { return size() == 0; }
+
     void append(const char*, int);
     void clear();
     const char* platformData() const;
index 269fdb4618fd1e6a79aebe1804c644c7258cefcd..9176da5b0ded38b7843a3f08fe4943d6666f9b7d 100644 (file)
@@ -94,7 +94,7 @@ void BitmapImage::destroyDecodedData(bool incremental)
             // Reset the image source, since Image I/O has an underlying cache that it uses
             // while animating that it seems to never clear.
             m_source.clear();
-            setData(true);
+            dataChanged(true);
         }
     }
 }
@@ -137,12 +137,12 @@ IntSize BitmapImage::size() const
     return m_size;
 }
 
-bool BitmapImage::setNativeData(NativeBytePtr data, bool allDataReceived)
+bool BitmapImage::dataChanged(bool allDataReceived)
 {
     destroyDecodedData(true);
     
     // Feed all the data we've seen so far to the image decoder.
-    m_source.setData(data, allDataReceived);
+    m_source.setData(m_data.get(), allDataReceived);
     
     // Image properties will not be available until the first frame of the file
     // reaches kCGImageStatusIncomplete.
index 45852f4b591517ef7970621680f0366fab93545e..6894336a77443d9d52ec82a623384295965026b5 100644 (file)
@@ -94,7 +94,7 @@ public:
     
     virtual IntSize size() const;
 
-    virtual bool setNativeData(NativeBytePtr, bool allDataReceived);
+    virtual bool dataChanged(bool allDataReceived);
 
     // It may look unusual that there is no start animation call as public API.  This is because
     // we start and stop animating lazily.  Animation begins whenever someone draws the image.  It will
index 9cfafdc34c85bb87bf68499c713008d9891a39a2..80fff2d6f44a007a2ec33cf7ab934698959a6bc5 100644 (file)
@@ -59,9 +59,13 @@ bool Image::isNull() const
     return size().isEmpty();
 }
 
-bool Image::setData(bool allDataReceived)
+bool Image::setData(PassRefPtr<SharedBuffer> data, bool allDataReceived)
 {
-    int length = m_data.size();
+    m_data = data;
+    if (!m_data.get())
+        return true;
+
+    int length = m_data->size();
     if (!length)
         return true;
 
@@ -75,16 +79,7 @@ bool Image::setData(bool allDataReceived)
     }
 #endif
     
-#if PLATFORM(CG)
-    // Avoid the extra copy of bytes by just handing the byte array directly to a CFDataRef.
-    CFDataRef data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(m_data.data()), length, kCFAllocatorNull);
-    bool result = setNativeData(data, allDataReceived);
-    CFRelease(data);
-#else
-    bool result = setNativeData(&m_data, allDataReceived);
-#endif
-
-    return result;
+    return dataChanged(allDataReceived);
 }
 
 IntRect Image::rect() const
index 994a585d234bcb3e898ab866cacb2ee5bc5e5028..330d55f1cfeb539753c96e508d0edd2fd7eb902d 100644 (file)
@@ -30,6 +30,9 @@
 #include "Color.h"
 #include "GraphicsTypes.h"
 #include "ImageSource.h"
+#include <wtf/RefPtr.h>
+#include <wtf/PassRefPtr.h>
+#include "SharedBuffer.h"
 
 #if PLATFORM(MAC)
 #ifdef __OBJC__
@@ -60,6 +63,7 @@ class FloatSize;
 class GraphicsContext;
 class IntRect;
 class IntSize;
+class SharedBuffer;
 class String;
 
 // This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
@@ -81,15 +85,15 @@ public:
     int width() const;
     int height() const;
 
-    virtual bool setData(bool allDataReceived);
-    virtual bool setNativeData(NativeBytePtr, bool allDataReceived) { return false; }
+    bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
+    virtual bool dataChanged(bool allDataReceived) { return false; }
     
     // FIXME: PDF/SVG will be underreporting decoded sizes and will be unable to prune because these functions are not
     // implemented yet for those image types.
     virtual void destroyDecodedData(bool incremental = false) {};
     virtual unsigned decodedSize() const { return 0; }
 
-    Vector<char>& dataBuffer() { return m_data; }
+    SharedBuffer* data() { return m_data.get(); }
 
     // It may look unusual that there is no start animation call as public API.  This is because
     // we start and stop animating lazily.  Animation begins whenever someone draws the image.  It will
@@ -145,7 +149,7 @@ private:
 #endif
     
 protected:
-    Vector<char> m_data; // The encoded raw data for the image. 
+    RefPtr<SharedBuffer> m_data; // The encoded raw data for the image. 
     ImageObserver* m_imageObserver;
 };
 
index 25edf1fc9668f7ade6a9ddf47bbbd02dd7cda3fc..de11054d323a309fcabac1d74817bacc665ead68 100644 (file)
@@ -43,20 +43,18 @@ typedef struct _cairo_surface cairo_surface_t;
 namespace WebCore {
 
 class IntSize;
+class SharedBuffer;
 
 #if PLATFORM(CG)
 typedef CGImageSourceRef NativeImageSourcePtr;
 typedef CGImageRef NativeImagePtr;
-typedef CFDataRef NativeBytePtr;
 #elif PLATFORM(QT)
 class ImageDecoderQt;
 typedef ImageDecoderQt* NativeImageSourcePtr;
-typedef const Vector<char>* NativeBytePtr;
 typedef QPixmap* NativeImagePtr;
 #else
 class ImageDecoder;
 typedef ImageDecoder* NativeImageSourcePtr;
-typedef const Vector<char>* NativeBytePtr;
 typedef cairo_surface_t* NativeImagePtr;
 #endif
 
@@ -72,7 +70,7 @@ public:
 
     bool initialized() const;
     
-    void setData(NativeBytePtr, bool allDataReceived);
+    void setData(SharedBuffer* data, bool allDataReceived);
 
     bool isSizeAvailable();
     IntSize size() const;
index 88f1ff0ac875db2c3361759e880ab9f937aaac6d..59fc8d4ef84b5de5e2a840a750a06add54d7546d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "ImageSource.h"
+#include "SharedBuffer.h"
 
 #if PLATFORM(CG)
 
@@ -71,11 +72,14 @@ bool ImageSource::initialized() const
     return m_decoder;
 }
 
-void ImageSource::setData(NativeBytePtr data, bool allDataReceived)
+void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (!m_decoder)
         m_decoder = CGImageSourceCreateIncremental(NULL);
-    CGImageSourceUpdateData(m_decoder, data, allDataReceived);
+        
+    CFDataRef cfData = (CFDataRef)data->createNSData();
+    CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
+    CFRelease(cfData);
 }
 
 bool ImageSource::isSizeAvailable()
index 7e9f89691695b20b261122f4c515998ceb7fa10e..f3c12aa80254877e3df6f31d50c9f7dee69f0721 100644 (file)
@@ -53,10 +53,12 @@ IntSize PDFDocumentImage::size() const
     return IntSize((int)m_mediaBox.size().width(), (int)m_mediaBox.size().height());
 }
 
-bool PDFDocumentImage::setNativeData(NativeBytePtr data, bool allDataReceived)
+bool PDFDocumentImage::dataChanged(bool allDataReceived)
 {
-    if (allDataReceived && !m_document && data) {
+    if (allDataReceived && !m_document) {
+        CFDataRef data = (CFDataRef)m_data->createNSData();
         CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
+        CFRelease(data);
         m_document = CGPDFDocumentCreateWithProvider(dataProvider);
         CGDataProviderRelease(dataProvider);
         setCurrentPage(0);
index 5bec1bf7a232d179a4e9f5e73be64acae96e95a4..caddc0573b16c807dd3a634912dd510f1ea7f88e 100644 (file)
@@ -41,7 +41,7 @@ namespace WebCore {
         PDFDocumentImage();
         ~PDFDocumentImage();
         
-        virtual bool setNativeData(NativeBytePtr, bool allDataReceived);
+        virtual bool dataChanged(bool allDataReceived);
 
         virtual IntSize size() const;
 
index 378c3c10fa1c3c8da37c57d9fa7c61c047993b83..eb39d356272764a31a15a0168d204f894ae98bcf 100644 (file)
@@ -64,7 +64,7 @@ Image* Image::loadPlatformResource(const char *name)
     NSData *namedImageData = [NSData dataWithContentsOfFile:imagePath];
     if (namedImageData) {
         Image* image = new BitmapImage;
-        image->setNativeData((CFDataRef)namedImageData, true);
+        image->setData(SharedBuffer::wrapNSData(namedImageData), true);
         return image;
     }
     return 0;
index 5dca2401e0fbf0e0870f01c2594592a67b7ac987..8dc404a98b038e93e7c937c37f037070ba0c3ce6 100644 (file)
@@ -118,9 +118,9 @@ NativeImagePtr SVGImage::nativeImageForCurrentFrame()
 #endif
 }
 
-bool SVGImage::setData(bool allDataReceived)
+bool SVGImage::dataChanged(bool allDataReceived)
 {
-    int length = dataBuffer().size();
+    int length = m_data->size();
     if (!length) // if this was an empty image
         return true;
     
@@ -146,7 +146,7 @@ bool SVGImage::setData(bool allDataReceived)
         m_frame->loader()->commitProvisionalLoad(0);
         m_frame->loader()->setResponseMIMEType("image/svg+xml");
         m_frame->loader()->begin("placeholder.svg"); // create the empty document
-        m_frame->loader()->write(dataBuffer().data(), dataBuffer().size());
+        m_frame->loader()->write(m_data->data(), m_data->size());
         m_frame->loader()->end();
     }
     return m_frameView;
index c3904927f7295aa8d592b7b62d6b177c0e079ec9..270bda9784aaa41eae605770db345372374c81b5 100644 (file)
@@ -47,8 +47,8 @@ namespace WebCore {
         
         virtual IntSize size() const;
         
-        virtual bool setData(bool allDataReceived);
-        
+        virtual bool dataChanged(bool allDataReceived);
+
         virtual NativeImagePtr frameAtIndex(size_t) { return 0; }
         
 private:
index ed4eda9d37e121411323dd70fe684886cd97e29d..b32de03f8536c2373708a2b06107258396be151c 100644 (file)
@@ -247,7 +247,7 @@ void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame,
 
 static NSFileWrapper* fileWrapperForImage(CachedResource* resource, NSURL *URL)
 {
-    SharedBuffer* coreData = resource->allData();
+    SharedBuffer* coreData = resource->data();
     NSData *data = [[[NSData alloc] initWithBytes:coreData->platformData() 
         length:coreData->platformDataSize()] autorelease];
     NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
index ec76a0f33ffb3e5046c60eb8f49130008a0ff9b2..d9d908362ac91f4c38f321ceb84897ebb45e342f 100644 (file)
@@ -1,3 +1,14 @@
+2007-03-14  David Hyatt  <hyatt@apple.com>
+
+        Fixes to ensure that the resource loader's shared buffer can always be used.
+
+        Reviewed by olliej, mjs
+
+        * Misc/WebIconDatabase.mm:
+        (-[WebIconDatabase _convertToWebCoreFormat]):
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::deliverArchivedResources):
+
 2007-03-13  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Brady.
index dd203b47aecc41f469fad728c26319744f58eaad..d40d5ef1f5066eddb7d5810896ed8d440cc1b455 100644 (file)
@@ -529,7 +529,7 @@ static NSData* iconDataFromPathForIconURL(NSString *databasePath, NSString *icon
     while ((url = [enumerator nextObject]) != nil) {
         iconData = iconDataFromPathForIconURL(databaseDirectory, url);
         if (iconData)
-            IconDatabase::sharedIconDatabase()->setIconDataForIconURL([iconData bytes], [iconData length], url);
+            IconDatabase::sharedIconDatabase()->setIconDataForIconURL(SharedBuffer::wrapNSData(iconData), url);
         else {
             // This really *shouldn't* happen, so it'd be good to track down why it might happen in a debug build
             // however, we do know how to handle it gracefully in release
index 12e8eabe00a8ce084621d9ea5f90f3483cc608fa..2475742f9b4545322e4115b3ba87d028001bbc4d 100644 (file)
@@ -949,6 +949,7 @@ void WebFrameLoaderClient::deliverArchivedResources(Timer<WebFrameLoaderClient>*
         WebResource *resource = it->second.get();
         NSData *data = [[resource data] retain];
         loader->didReceiveResponse([resource _response]);
+        loader->addData((const char*)[data bytes], [data length], true);
         loader->didReceiveData((const char*)[data bytes], [data length], [data length], true);
         [data release];
         loader->didFinishLoading();