ResourceLoader::resourceData() should not return a PassRefPtr
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jun 2013 16:36:59 +0000 (16:36 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jun 2013 16:36:59 +0000 (16:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=117288

Reviewed by Darin Adler.

Change ResourceLoader::resourceData() to return a raw pointer
instead of a PassRefPtr since we don't want to transfer the
ownership of the resource data. Also pass a raw pointer to
CachedResource::data() so that the cached resource can decide
whether to take a reference of the data or not, for example,
CachedRawResource only takes a reference when buffering policy is
BufferData.

* html/ImageDocument.cpp:
(WebCore::ImageDocumentParser::appendBytes):
(WebCore::ImageDocumentParser::finish):
* loader/ResourceLoader.cpp:
* loader/ResourceLoader.h:
(WebCore::ResourceLoader::resourceData):
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::sendDataToResource):
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::data):
* loader/cache/CachedCSSStyleSheet.h:
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::data):
* loader/cache/CachedFont.h:
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::data):
* loader/cache/CachedImage.h:
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::data):
* loader/cache/CachedRawResource.h:
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::data):
* loader/cache/CachedResource.h:
* loader/cache/CachedSVGDocument.cpp:
(WebCore::CachedSVGDocument::data):
* loader/cache/CachedSVGDocument.h:
* loader/cache/CachedScript.cpp:
(WebCore::CachedScript::data):
* loader/cache/CachedScript.h:
* loader/cache/CachedShader.cpp:
(WebCore::CachedShader::data):
* loader/cache/CachedShader.h:
* loader/cache/CachedTextTrack.cpp:
(WebCore::CachedTextTrack::data):
* loader/cache/CachedTextTrack.h:
* loader/cache/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::data):
* loader/cache/CachedXSLStyleSheet.h:

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

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/loader/ResourceLoader.cpp
Source/WebCore/loader/ResourceLoader.h
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.h
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedRawResource.cpp
Source/WebCore/loader/cache/CachedRawResource.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedSVGDocument.cpp
Source/WebCore/loader/cache/CachedSVGDocument.h
Source/WebCore/loader/cache/CachedScript.cpp
Source/WebCore/loader/cache/CachedScript.h
Source/WebCore/loader/cache/CachedShader.cpp
Source/WebCore/loader/cache/CachedShader.h
Source/WebCore/loader/cache/CachedTextTrack.cpp
Source/WebCore/loader/cache/CachedTextTrack.h
Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp
Source/WebCore/loader/cache/CachedXSLStyleSheet.h

index 953dec5..79c0887 100644 (file)
@@ -1,3 +1,57 @@
+2013-06-06  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        ResourceLoader::resourceData() should not return a PassRefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=117288
+
+        Reviewed by Darin Adler.
+
+        Change ResourceLoader::resourceData() to return a raw pointer
+        instead of a PassRefPtr since we don't want to transfer the
+        ownership of the resource data. Also pass a raw pointer to
+        CachedResource::data() so that the cached resource can decide
+        whether to take a reference of the data or not, for example,
+        CachedRawResource only takes a reference when buffering policy is
+        BufferData.
+
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocumentParser::appendBytes):
+        (WebCore::ImageDocumentParser::finish):
+        * loader/ResourceLoader.cpp:
+        * loader/ResourceLoader.h:
+        (WebCore::ResourceLoader::resourceData):
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::sendDataToResource):
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::data):
+        * loader/cache/CachedCSSStyleSheet.h:
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::data):
+        * loader/cache/CachedFont.h:
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::data):
+        * loader/cache/CachedImage.h:
+        * loader/cache/CachedRawResource.cpp:
+        (WebCore::CachedRawResource::data):
+        * loader/cache/CachedRawResource.h:
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::data):
+        * loader/cache/CachedResource.h:
+        * loader/cache/CachedSVGDocument.cpp:
+        (WebCore::CachedSVGDocument::data):
+        * loader/cache/CachedSVGDocument.h:
+        * loader/cache/CachedScript.cpp:
+        (WebCore::CachedScript::data):
+        * loader/cache/CachedScript.h:
+        * loader/cache/CachedShader.cpp:
+        (WebCore::CachedShader::data):
+        * loader/cache/CachedShader.h:
+        * loader/cache/CachedTextTrack.cpp:
+        (WebCore::CachedTextTrack::data):
+        * loader/cache/CachedTextTrack.h:
+        * loader/cache/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::data):
+        * loader/cache/CachedXSLStyleSheet.h:
+
 2013-06-06  Chris Fleizach  <cfleizach@apple.com>
 
         AX: iOS ignores ARIA progressbar elements
index 8d70caf..2b592bc 100644 (file)
@@ -135,7 +135,8 @@ void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, size_t)
         return;
 
     CachedImage* cachedImage = document()->cachedImage();
-    cachedImage->data(frame->loader()->documentLoader()->mainResourceData(), false);
+    RefPtr<ResourceBuffer> resourceData = frame->loader()->documentLoader()->mainResourceData();
+    cachedImage->data(resourceData.get(), false);
 
     document()->imageUpdated();
 }
@@ -151,7 +152,7 @@ void ImageDocumentParser::finish()
         if (document()->frame()->loader()->documentLoader()->isLoadingMultipartContent())
             data = data->copy();
 
-        cachedImage->data(data.release(), true);
+        cachedImage->data(data.get(), true);
         cachedImage->finish();
 
         cachedImage->setResponse(document()->frame()->loader()->documentLoader()->response());
index 45b3a30..8fc4a84 100644 (file)
 
 namespace WebCore {
 
-PassRefPtr<ResourceBuffer> ResourceLoader::resourceData()
-{
-    return m_resourceData;
-}
-
 ResourceLoader::ResourceLoader(Frame* frame, ResourceLoaderOptions options)
     : m_frame(frame)
     , m_documentLoader(frame->loader()->activeDocumentLoader())
index f530d08..0a5499b 100644 (file)
@@ -73,7 +73,7 @@ public:
     virtual void releaseResources();
     const ResourceResponse& response() const;
 
-    PassRefPtr<ResourceBuffer> resourceData();
+    ResourceBuffer* resourceData() const { return m_resourceData.get(); }
     void clearResourceData();
     
     virtual bool isSubresourceLoader();
index 9e841bc..9c1f0a2 100644 (file)
@@ -266,7 +266,7 @@ void SubresourceLoader::sendDataToResource(const char* data, int length)
     //     that all data has been received yet. 
     if (m_loadingMultipartContent || !resourceData()) { 
         RefPtr<ResourceBuffer> copiedData = ResourceBuffer::create(data, length); 
-        m_resource->data(copiedData.release(), m_loadingMultipartContent);
+        m_resource->data(copiedData.get(), m_loadingMultipartContent);
     } else 
         m_resource->data(resourceData(), false);
 }
index 184e904..c1bc438 100644 (file)
@@ -93,7 +93,7 @@ const String CachedCSSStyleSheet::sheetText(bool enforceMIMEType, bool* hasValid
     return sheetText;
 }
 
-void CachedCSSStyleSheet::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedCSSStyleSheet::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index e4bb97e..ca5170d 100644 (file)
@@ -47,7 +47,7 @@ namespace WebCore {
         
         virtual void setEncoding(const String&);
         virtual String encoding() const;
-        virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+        virtual void data(ResourceBuffer*, bool allDataReceived);
         virtual void destroyDecodedData() OVERRIDE;
 
         PassRefPtr<StyleSheetContents> restoreParsedStyleSheet(const CSSParserContext&);
index cca02f2..f6e47b4 100644 (file)
@@ -75,7 +75,7 @@ void CachedFont::didAddClient(CachedResourceClient* c)
         static_cast<CachedFontClient*>(c)->fontLoaded(this);
 }
 
-void CachedFont::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedFont::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index d29521b..c5be369 100644 (file)
@@ -48,7 +48,7 @@ public:
     virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&);
 
     virtual void didAddClient(CachedResourceClient*);
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
 
     virtual void allClientsRemoved();
     void beginLoadIfNeeded(CachedResourceLoader* dl);
index 2577b27..63829f3 100644 (file)
@@ -352,7 +352,7 @@ size_t CachedImage::maximumDecodedImageSize()
     return settings ? settings->maximumDecodedImageSize() : 0;
 }
 
-void CachedImage::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedImage::data(ResourceBuffer* data, bool allDataReceived)
 {
     m_data = data;
 
index 00f9067..7d51019 100644 (file)
@@ -76,7 +76,7 @@ public:
     virtual void allClientsRemoved();
     virtual void destroyDecodedData();
 
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
     virtual void error(CachedResource::Status);
     virtual void responseReceived(const ResourceResponse&);
     
index 0016de2..f8086c1 100644 (file)
@@ -41,7 +41,7 @@ CachedRawResource::CachedRawResource(ResourceRequest& resourceRequest, Type type
 {
 }
 
-void CachedRawResource::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedRawResource::data(ResourceBuffer* data, bool allDataReceived)
 {
     CachedResourceHandle<CachedRawResource> protect(this);
     const char* incrementalData = 0;
@@ -68,7 +68,7 @@ void CachedRawResource::data(PassRefPtr<ResourceBuffer> data, bool allDataReceiv
         while (CachedRawResourceClient* c = w.next())
             c->dataReceived(this, incrementalData, incrementalDataLength);
     }
-    CachedResource::data(m_data, allDataReceived);
+    CachedResource::data(data, allDataReceived);
 
     if (dataBufferingPolicy == BufferData && m_options.dataBufferingPolicy == DoNotBufferData) {
         if (m_loader)
index 60139aa..5bf0017 100644 (file)
@@ -50,7 +50,7 @@ public:
 
 private:
     virtual void didAddClient(CachedResourceClient*);
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
 
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
     virtual void allClientsRemoved();
index ed38da8..2ef2bc1 100644 (file)
@@ -362,7 +362,7 @@ void CachedResource::checkNotify()
         c->notifyFinished(this);
 }
 
-void CachedResource::data(PassRefPtr<ResourceBuffer>, bool allDataReceived)
+void CachedResource::data(ResourceBuffer*, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index 32a588e..9e9e655 100644 (file)
@@ -101,7 +101,7 @@ public:
 
     virtual void setEncoding(const String&) { }
     virtual String encoding() const { return String(); }
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
     virtual void error(CachedResource::Status);
 
     void setResourceError(const ResourceError& error) { m_error = error; }
index f2b8e5a..6720b98 100644 (file)
@@ -53,7 +53,7 @@ String CachedSVGDocument::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedSVGDocument::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedSVGDocument::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index 99fb8ca..ab700c7 100644 (file)
@@ -40,7 +40,7 @@ public:
 
     virtual void setEncoding(const String&);
     virtual String encoding() const;
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
 
 protected:
     RefPtr<SVGDocument> m_document;
index 198dd65..42e1228 100644 (file)
@@ -82,7 +82,7 @@ const String& CachedScript::script()
     return m_script;
 }
 
-void CachedScript::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedScript::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index 5d8b27e..d2f77ce 100644 (file)
@@ -42,7 +42,7 @@ namespace WebCore {
 
         virtual void setEncoding(const String&);
         virtual String encoding() const;
-        virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+        virtual void data(ResourceBuffer*, bool allDataReceived);
         String mimeType() const;
 
         virtual void destroyDecodedData();
index 2222c60..8ce37f2 100644 (file)
@@ -60,7 +60,7 @@ const String& CachedShader::shaderString()
     return m_shaderString;
 }
 
-void CachedShader::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedShader::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (allDataReceived)
         m_data = data;
index 11b9180..bca5ffa 100644 (file)
@@ -44,7 +44,7 @@ public:
     virtual ~CachedShader();
     
     const String& shaderString();
-    void data(PassRefPtr<ResourceBuffer>, bool allDataReceived);
+    void data(ResourceBuffer*, bool allDataReceived);
 
 private:
     virtual bool mayTryReplaceEncodedData() const OVERRIDE { return true; }
index f6143dc..8634156 100644 (file)
@@ -48,7 +48,7 @@ CachedTextTrack::~CachedTextTrack()
 {
 }
 
-void CachedTextTrack::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedTextTrack::data(ResourceBuffer* data, bool allDataReceived)
 {
     m_data = data;
     setEncodedSize(m_data.get() ? m_data->size() : 0);
index 78c6c92..5c02ef7 100644 (file)
@@ -38,7 +38,7 @@ public:
     CachedTextTrack(const ResourceRequest&);
     virtual ~CachedTextTrack();
 
-    virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+    virtual void data(ResourceBuffer*, bool allDataReceived);
 
 private:
     virtual bool mayTryReplaceEncodedData() const OVERRIDE { return true; }
index 008cd56..e5ae41a 100644 (file)
@@ -63,7 +63,7 @@ String CachedXSLStyleSheet::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedXSLStyleSheet::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived)
+void CachedXSLStyleSheet::data(ResourceBuffer* data, bool allDataReceived)
 {
     if (!allDataReceived)
         return;
index df6d90f..f6c355c 100644 (file)
@@ -45,7 +45,7 @@ namespace WebCore {
         
         virtual void setEncoding(const String&);
         virtual String encoding() const;
-        virtual void data(PassRefPtr<ResourceBuffer> data, bool allDataReceived);
+        virtual void data(ResourceBuffer*, bool allDataReceived);
 
     protected:
         virtual void checkNotify();