Reviewed by Maciej.
Add a shared buffer class which is backed by either a vector or an NSData object. This object can also
be held in a custom NSData subclass. Use this in the loader wherever NSData was used.
* WebCore.exp:
* WebCore.xcodeproj/project.pbxproj:
* loader/CachedResource.h:
(WebCore::CachedResource::allData):
* loader/DocumentLoader.h:
* loader/FrameLoader.h:
* loader/ResourceLoader.h:
* loader/SubresourceLoaderClient.h:
(WebCore::SubresourceLoaderClient::didFail):
* loader/loader.cpp:
(WebCore::Loader::didFinishLoading):
* loader/loader.h:
* loader/mac/DocumentLoaderMac.mm:
(WebCore::DocumentLoader::setMainResourceData):
(WebCore::DocumentLoader::mainResourceData):
(WebCore::DocumentLoader::setupForReplaceByMIMEType):
* loader/mac/FrameLoaderMac.mm:
(WebCore::FrameLoader::mainResourceData):
* loader/mac/ImageDocumentMac.mm:
(WebCore::finishImageLoad):
* loader/mac/LoaderFunctionsMac.mm:
(WebCore::CheckCacheObjectStatus):
(WebCore::CachedResource::setAllData):
* loader/mac/NetscapePlugInStreamLoaderMac.mm:
(WebCore::NetscapePlugInStreamLoader::didFinishLoading):
* loader/mac/ResourceLoaderMac.mm:
(WebCore::ResourceLoader::addData):
(WebCore::ResourceLoader::resourceData):
(WebCore::ResourceLoader::clearResourceData):
(WebCore::ResourceLoader::didReceiveData):
(WebCore::ResourceLoader::willStopBufferingData):
* loader/mac/SubresourceLoaderMac.mm:
(WebCore::SubresourceLoader::didReceiveResponse):
(WebCore::SubresourceLoader::didFinishLoading):
* page/mac/WebCoreFrameBridge.mm:
(-[WebCoreFrameBridge getData:andResponse:forURL:]):
(-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
* platform/KURL.h:
* platform/SharedBuffer.cpp: Added.
(WebCore::SharedBuffer::SharedBuffer):
(WebCore::SharedBuffer::size):
(WebCore::SharedBuffer::data):
(WebCore::SharedBuffer::append):
(WebCore::SharedBuffer::clear):
(WebCore::SharedBuffer::clearPlatformData):
(WebCore::SharedBuffer::maybeTransferPlatformData):
(WebCore::SharedBuffer::hasPlatformData):
(WebCore::SharedBuffer::platformData):
* platform/SharedBuffer.h: Added.
* platform/mac/SharedBufferMac.mm: Added.
(-[SharedBufferData dealloc]):
(-[SharedBufferData finalize]):
(-[SharedBufferData initWithSharedBuffer:WebCore::]):
(-[SharedBufferData length]):
(-[SharedBufferData bytes]):
(WebCore::SharedBuffer::wrapNSData):
(WebCore::SharedBuffer::SharedBuffer):
(WebCore::SharedBuffer::createNSData):
(WebCore::SharedBuffer::hasPlatformData):
(WebCore::SharedBuffer::platformData):
(WebCore::SharedBuffer::platformDataSize):
(WebCore::SharedBuffer::maybeTransferPlatformData):
(WebCore::SharedBuffer::clearPlatformData):
* platform/network/ResourceHandle.h:
* platform/network/ResourceHandleClient.h:
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::bufferedData):
WebKit:
Reviewed by Maciej.
The data returned is now a SharedBuffer so wrap it in an NSData object.
* WebView/WebDataSource.mm:
(-[WebDataSource data]):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18621
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-01-05 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Maciej.
+
+ Add a shared buffer class which is backed by either a vector or an NSData object. This object can also
+ be held in a custom NSData subclass. Use this in the loader wherever NSData was used.
+
+ * WebCore.exp:
+ * WebCore.xcodeproj/project.pbxproj:
+ * loader/CachedResource.h:
+ (WebCore::CachedResource::allData):
+ * loader/DocumentLoader.h:
+ * loader/FrameLoader.h:
+ * loader/ResourceLoader.h:
+ * loader/SubresourceLoaderClient.h:
+ (WebCore::SubresourceLoaderClient::didFail):
+ * loader/loader.cpp:
+ (WebCore::Loader::didFinishLoading):
+ * loader/loader.h:
+ * loader/mac/DocumentLoaderMac.mm:
+ (WebCore::DocumentLoader::setMainResourceData):
+ (WebCore::DocumentLoader::mainResourceData):
+ (WebCore::DocumentLoader::setupForReplaceByMIMEType):
+ * loader/mac/FrameLoaderMac.mm:
+ (WebCore::FrameLoader::mainResourceData):
+ * loader/mac/ImageDocumentMac.mm:
+ (WebCore::finishImageLoad):
+ * loader/mac/LoaderFunctionsMac.mm:
+ (WebCore::CheckCacheObjectStatus):
+ (WebCore::CachedResource::setAllData):
+ * loader/mac/NetscapePlugInStreamLoaderMac.mm:
+ (WebCore::NetscapePlugInStreamLoader::didFinishLoading):
+ * loader/mac/ResourceLoaderMac.mm:
+ (WebCore::ResourceLoader::addData):
+ (WebCore::ResourceLoader::resourceData):
+ (WebCore::ResourceLoader::clearResourceData):
+ (WebCore::ResourceLoader::didReceiveData):
+ (WebCore::ResourceLoader::willStopBufferingData):
+ * loader/mac/SubresourceLoaderMac.mm:
+ (WebCore::SubresourceLoader::didReceiveResponse):
+ (WebCore::SubresourceLoader::didFinishLoading):
+ * page/mac/WebCoreFrameBridge.mm:
+ (-[WebCoreFrameBridge getData:andResponse:forURL:]):
+ (-[WebCoreFrameBridge getAllResourceDatas:andResponses:]):
+ * platform/KURL.h:
+ * platform/SharedBuffer.cpp: Added.
+ (WebCore::SharedBuffer::SharedBuffer):
+ (WebCore::SharedBuffer::size):
+ (WebCore::SharedBuffer::data):
+ (WebCore::SharedBuffer::append):
+ (WebCore::SharedBuffer::clear):
+ (WebCore::SharedBuffer::clearPlatformData):
+ (WebCore::SharedBuffer::maybeTransferPlatformData):
+ (WebCore::SharedBuffer::hasPlatformData):
+ (WebCore::SharedBuffer::platformData):
+ * platform/SharedBuffer.h: Added.
+ * platform/mac/SharedBufferMac.mm: Added.
+ (-[SharedBufferData dealloc]):
+ (-[SharedBufferData finalize]):
+ (-[SharedBufferData initWithSharedBuffer:WebCore::]):
+ (-[SharedBufferData length]):
+ (-[SharedBufferData bytes]):
+ (WebCore::SharedBuffer::wrapNSData):
+ (WebCore::SharedBuffer::SharedBuffer):
+ (WebCore::SharedBuffer::createNSData):
+ (WebCore::SharedBuffer::hasPlatformData):
+ (WebCore::SharedBuffer::platformData):
+ (WebCore::SharedBuffer::platformDataSize):
+ (WebCore::SharedBuffer::maybeTransferPlatformData):
+ (WebCore::SharedBuffer::clearPlatformData):
+ * platform/network/ResourceHandle.h:
+ * platform/network/ResourceHandleClient.h:
+ * platform/network/mac/ResourceHandleMac.mm:
+ (WebCore::ResourceHandle::bufferedData):
+
2007-01-05 Anders Carlsson <acarlsson@apple.com>
Reviewed by Adam.
__ZN7WebCore12IconDatabase4openERKNS_6StringE
__ZN7WebCore12IconDatabase5closeEv
__ZN7WebCore12IconDatabase7isEmptyEv
+__ZN7WebCore12SharedBuffer12createNSDataEv
__ZN7WebCore13HitTestResultC1ERKS0_
__ZN7WebCore13HitTestResultD1Ev
__ZN7WebCore13KeyboardEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowERKNS_6StringEjbbbbb
1A4A2DF00A1B852A00C807F8 /* JSHTMLAnchorElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A2DEC0A1B852A00C807F8 /* JSHTMLAnchorElement.h */; };
1A4A2DF10A1B852A00C807F8 /* JSHTMLAppletElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A2DED0A1B852A00C807F8 /* JSHTMLAppletElement.cpp */; };
1A4A2DF20A1B852A00C807F8 /* JSHTMLAppletElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A2DEE0A1B852A00C807F8 /* JSHTMLAppletElement.h */; };
+ 1A4A954D0B4EDCCB002D8C3C /* SharedBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A954B0B4EDCCB002D8C3C /* SharedBuffer.cpp */; };
+ 1A4A954E0B4EDCCB002D8C3C /* SharedBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A4A954C0B4EDCCB002D8C3C /* SharedBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */; };
1A6938010A11100A00C127FE /* TextDocument.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A6937FF0A11100A00C127FE /* TextDocument.cpp */; };
1A6938020A11100A00C127FE /* TextDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6938000A11100A00C127FE /* TextDocument.h */; };
1A750D5C0A90DEE1000FF215 /* JSTreeWalker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A750D5A0A90DEE1000FF215 /* JSTreeWalker.cpp */; };
1A4A2DEC0A1B852A00C807F8 /* JSHTMLAnchorElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLAnchorElement.h; sourceTree = "<group>"; };
1A4A2DED0A1B852A00C807F8 /* JSHTMLAppletElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLAppletElement.cpp; sourceTree = "<group>"; };
1A4A2DEE0A1B852A00C807F8 /* JSHTMLAppletElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLAppletElement.h; sourceTree = "<group>"; };
+ 1A4A954B0B4EDCCB002D8C3C /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
+ 1A4A954C0B4EDCCB002D8C3C /* SharedBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SharedBuffer.h; sourceTree = "<group>"; };
+ 1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedBufferMac.mm; sourceTree = "<group>"; };
1A6937FF0A11100A00C127FE /* TextDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TextDocument.cpp; sourceTree = "<group>"; };
1A6938000A11100A00C127FE /* TextDocument.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TextDocument.h; sourceTree = "<group>"; };
1A750D3C0A90DE35000FF215 /* TreeWalker.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TreeWalker.idl; sourceTree = "<group>"; };
BCAA90C20A7EBA60008B1229 /* ScrollBar.cpp */,
9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */,
AB71709F0B31193B0017123E /* SearchPopupMenuMac.mm */,
+ 1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */,
93309E9F099EB78C0056E581 /* SharedTimerMac.cpp */,
4B3043C80AE0371D00A82647 /* SoundMac.mm */,
84B2B24F056BF15F00D2B771 /* SSLKeyGeneratorMac.mm */,
BCFB2F3F097A24B500BA703D /* SegmentedString.cpp */,
BCFB2F40097A24B500BA703D /* SegmentedString.h */,
BCFB2E830979FD4F00BA703D /* Shared.h */,
+ 1A4A954B0B4EDCCB002D8C3C /* SharedBuffer.cpp */,
+ 1A4A954C0B4EDCCB002D8C3C /* SharedBuffer.h */,
93309EA0099EB78C0056E581 /* SharedTimer.h */,
4B3043C60AE0370300A82647 /* Sound.h */,
F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */,
B25AE5600B49D6630074C726 /* RadialGradientAttributes.h in Headers */,
A82422700B4A16C50084722B /* SVGAnimateMotionElement.h in Headers */,
062287840B4DB322000C34DF /* FocusDirection.h in Headers */,
+ 1A4A954E0B4EDCCB002D8C3C /* SharedBuffer.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
A88DD4890B4629B000C02990 /* PathTraversalState.cpp in Sources */,
A8241D8C0B48D31E0084722B /* SVGTimer.cpp in Sources */,
A82422710B4A16C50084722B /* SVGAnimateMotionElement.cpp in Sources */,
+ 1A4A954D0B4EDCCB002D8C3C /* SharedBuffer.cpp in Sources */,
+ 1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
#include "CachePolicy.h"
#include "PlatformString.h"
-#include "ResourceHandleClient.h" // defines PlatformData
#include "ResourceResponse.h"
+#include "SharedBuffer.h"
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
#include <time.h>
void setRequest(Request*);
- PlatformData allData() const { return m_allData; }
- void setAllData(PlatformData);
+ SharedBuffer* allData() const { return m_allData.get(); }
+ void setAllData(PassRefPtr<SharedBuffer>);
void setResponse(const ResourceResponse& response) { m_response = response; }
const ResourceResponse& response() const { return m_response; }
#endif
ResourceResponse m_response;
- PlatformData m_allData;
+ RefPtr<SharedBuffer> m_allData;
Type m_type;
Status m_status;
class HistoryItem;
class KURL;
class PageCache;
+ class SharedBuffer;
typedef Vector<ResourceResponse> ResponseVector;
FrameLoader* frameLoader() const;
#if PLATFORM(MAC)
- NSData *mainResourceData() const;
+ PassRefPtr<SharedBuffer> mainResourceData() const;
#endif
const ResourceRequest& originalRequest() const;
private:
#if PLATFORM(MAC)
- void setMainResourceData(NSData *);
+ void setMainResourceData(PassRefPtr<SharedBuffer>);
#endif
void setupForReplace();
void commitIfReady();
Frame* m_frame;
#if PLATFORM(MAC)
- RetainPtr<NSData> m_mainResourceData;
+ RefPtr<SharedBuffer> m_mainResourceData;
#endif
// A reference to actual request used to create the data source.
#ifdef __OBJC__
-@class NSData;
@class NSURLAuthenticationChallenge;
#else
-class NSData;
class NSURLAuthenticationChallenge;
#endif // __OBJC__
class ResourceLoader;
class ResourceRequest;
class ResourceResponse;
+ class SharedBuffer;
class SubresourceLoader;
class TextResourceDecoder;
class Widget;
void addSubresourceLoader(ResourceLoader*);
void removeSubresourceLoader(ResourceLoader*);
#if PLATFORM(MAC)
- NSData *mainResourceData() const;
+ PassRefPtr<SharedBuffer> mainResourceData() const;
#endif
void releaseMainResourceLoader();
#include "Shared.h"
#include "KURL.h"
-#include <wtf/RefPtr.h>
+#include <wtf/Forward.h>
#if PLATFORM(MAC)
@class NSURLAuthenticationChallenge;
#else
class NSCachedURLResponse;
-class NSData;
class NSMutableData;
class NSURLAuthenticationChallenge;
class NSURLCredential;
class Frame;
class FrameLoader;
class ResourceHandle;
+ class SharedBuffer;
class ResourceLoader : public Shared<ResourceLoader>, protected ResourceHandleClient {
public:
const ResourceResponse& response() const;
virtual void addData(const char*, int, bool allAtOnce);
- virtual NSData *resourceData();
+ virtual PassRefPtr<SharedBuffer> resourceData();
void clearResourceData();
virtual void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse);
NSURLAuthenticationChallenge *m_currentConnectionChallenge;
RetainPtr<NSURLAuthenticationChallenge> m_currentWebChallenge;
KURL m_originalURL;
- RetainPtr<NSMutableData> m_resourceData;
+ RefPtr<SharedBuffer> m_resourceData;
#endif
bool m_defersLoading;
};
#ifndef SubresourceLoaderClient_h
#define SubresourceLoaderClient_h
-// FIXME: This is just to define PlatformData, it should go away
-#include "ResourceHandleClient.h"
-
namespace WebCore {
+class ResourceError;
class ResourceRequest;
class ResourceResponse;
class SubresourceLoader;
virtual void didReceiveData(SubresourceLoader*, const char*, int) { }
virtual void didFinishLoading(SubresourceLoader*) { }
virtual void didFail(SubresourceLoader*, const ResourceError&) { }
-
- // FIXME: Get rid of this function
- virtual void receivedAllData(SubresourceLoader*, PlatformData) { }
};
}
m_requestsLoading.add(loader.release(), req);
}
-void Loader::receivedAllData(SubresourceLoader* loader, PlatformData allData)
+void Loader::didFinishLoading(SubresourceLoader* loader)
{
RequestMap::iterator i = m_requestsLoading.find(loader);
if (i == m_requestsLoading.end())
docLoader->setLoadInProgress(true);
object->data(req->buffer(), true);
- object->setAllData(allData);
+ object->setAllData(loader->resourceData());
docLoader->setLoadInProgress(false);
object->finish();
private:
virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
virtual void didReceiveData(SubresourceLoader*, const char*, int);
- virtual void receivedAllData(SubresourceLoader*, PlatformData);
+ virtual void didFinishLoading(SubresourceLoader*);
virtual void didFail(SubresourceLoader*, const ResourceError&);
void servePendingRequests();
#import "HistoryItem.h"
#import "PageCache.h"
#import "PlatformString.h"
+#import "SharedBuffer.h"
#import "WebCoreSystemInterface.h"
#import "WebDataProtocol.h"
#import "XMLTokenizer.h"
ASSERT(!m_frame || frameLoader()->activeDocumentLoader() != this || !frameLoader()->isLoading());
}
-void DocumentLoader::setMainResourceData(NSData *data)
+void DocumentLoader::setMainResourceData(PassRefPtr<SharedBuffer> data)
{
m_mainResourceData = data;
}
-NSData *DocumentLoader::mainResourceData() const
+PassRefPtr<SharedBuffer> DocumentLoader::mainResourceData() const
{
return m_mainResourceData ? m_mainResourceData.get() : frameLoader()->mainResourceData();
}
if (!doesProgressiveLoad(oldMIMEType)) {
frameLoader()->revertToProvisional(this);
setupForReplace();
- commitLoad((const char*)[mainResourceData() bytes], [mainResourceData() length]);
+ RefPtr<SharedBuffer> resourceData = mainResourceData();
+ commitLoad(resourceData->data(), resourceData->size());
}
frameLoader()->finishedLoadingDocument(this);
#import "ResourceHandle.h"
#import "ResourceRequest.h"
#import "ResourceResponse.h"
+#import "SharedBuffer.h"
#import "Settings.h"
#import "SubresourceLoader.h"
#import "SystemTime.h"
return String();
}
-NSData *FrameLoader::mainResourceData() const
+PassRefPtr<SharedBuffer> FrameLoader::mainResourceData() const
{
if (!m_mainResourceLoader)
- return nil;
+ return 0;
return m_mainResourceLoader->resourceData();
}
// FIXME: This is terrible! Makes an extra copy of the image data!
// Can't we get the NSData from NSURLConnection?
// Why is this different from image subresources?
- NSData* nsData = [[NSData alloc] initWithBytes:imageData length:imageDataSize];
- image->setAllData(nsData);
- [nsData release];
+ RefPtr<SharedBuffer> buffer = new SharedBuffer(reinterpret_cast<const char*>(imageData), imageDataSize);
Frame* frame = document->frame();
const ResourceResponse& response = frame->loader()->documentLoader()->response();
NSURLRequest *request = cachedResource->getNSURLRequest();
const ResourceResponse& response = cachedResource->response();
- NSData *data = cachedResource->allData();
+ RefPtr<SharedBuffer> data = cachedResource->allData();
// FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load.
- frame->loader()->loadedResourceFromMemoryCache(request, response, [data length]);
+ frame->loader()->loadedResourceFromMemoryCache(request, response, data->size());
frame->loader()->didTellBridgeAboutLoad(cachedResource->url());
}
-void CachedResource::setAllData(PlatformData allData)
+void CachedResource::setAllData(PassRefPtr<SharedBuffer> allData)
{
- HardRetain(allData);
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- HardRelease(m_allData);
- END_BLOCK_OBJC_EXCEPTIONS;
-
m_allData = allData;
}
#import "FrameLoader.h"
#import "ResourceError.h"
#import "ResourceResponse.h"
+#import "SharedBuffer.h"
#import <wtf/PassRefPtr.h>
namespace WebCore {
RefPtr<NetscapePlugInStreamLoader> protect(this);
frameLoader()->removePlugInStreamLoader(this);
- [m_stream.get() finishedLoadingWithData:resourceData()];
+ NSData *data = resourceData()->createNSData();
+ [m_stream.get() finishedLoadingWithData:data];
+ [data release];
ResourceLoader::didFinishLoading();
}
#import "ResourceHandle.h"
#import "ResourceRequest.h"
#import "ResourceResponse.h"
+#import "SharedBuffer.h"
#import "WebCoreSystemInterface.h"
#import "WebDataProtocol.h"
#import <Foundation/NSURLAuthenticationChallenge.h>
void ResourceLoader::addData(const char* data, int length, bool allAtOnce)
{
if (allAtOnce) {
- m_resourceData.adopt([[NSMutableData alloc] initWithBytes:data length:length]);
+ m_resourceData = new SharedBuffer(data, length);
return;
}
if (ResourceHandle::supportsBufferedData()) {
// Buffer data only if the connection has handed us the data because is has stopped buffering it.
if (m_resourceData)
- [m_resourceData.get() appendBytes:data length:length];
+ m_resourceData->append(data, length);
} else {
- if (!m_resourceData)
- m_resourceData.adopt([[NSMutableData alloc] init]);
-
- [m_resourceData.get() appendBytes:data length:length];
+ if (!m_resourceData)
+ m_resourceData = new SharedBuffer(data, length);
+ else
+ m_resourceData->append(data, length);
}
}
-NSData *ResourceLoader::resourceData()
+PassRefPtr<SharedBuffer> ResourceLoader::resourceData()
{
if (m_resourceData)
- // Retain and autorelease resourceData since releaseResources (which releases resourceData) may be called
- // before the caller of this method has an opportunity to retain the returned data (4070729).
- return [[m_resourceData.get() retain] autorelease];
+ return m_resourceData;
if (ResourceHandle::supportsBufferedData() && m_handle)
return m_handle->bufferedData();
void ResourceLoader::clearResourceData()
{
- [m_resourceData.get() setLength:0];
+ m_resourceData->clear();
}
void ResourceLoader::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
void ResourceLoader::didReceiveData(const char* data, int length, long long lengthReceived, bool allAtOnce)
{
// The following assertions are not quite valid here, since a subclass
- // might override didReceiveData: in a way that invalidates them. This
+ // might override didReceiveData in a way that invalidates them. This
// happens with the steps listed in 3266216
// ASSERT(con == connection);
// ASSERT(!m_reachedTerminalState);
void ResourceLoader::willStopBufferingData(const char* data, int length)
{
ASSERT(!m_resourceData);
- m_resourceData.adopt([[NSMutableData alloc] initWithBytes:data length:length]);
+ m_resourceData = new SharedBuffer(data, length);
}
void ResourceLoader::didFinishLoading()
#import "ResourceHandle.h"
#import "ResourceRequest.h"
#import "ResourceResponse.h"
+#import "SharedBuffer.h"
#import "SubresourceLoaderClient.h"
#import "WebCoreSystemInterface.h"
#import <wtf/Assertions.h>
return;
ResourceLoader::didReceiveResponse(r);
- if (m_loadingMultipartContent && [resourceData() length]) {
+ RefPtr<SharedBuffer> buffer = resourceData();
+ if (m_loadingMultipartContent && buffer && buffer->size()) {
// Since a subresource loader does not load multipart sections progressively,
// deliver the previously received data to the loader all at once now.
// Then clear the data to make way for the next multipart section.
if (m_client)
- m_client->didReceiveData(this, (const char*)[resourceData() bytes], [resourceData() length]);
+ m_client->didReceiveData(this, buffer->data(), buffer->size());
clearResourceData();
// After the first multipart section is complete, signal to delegates that this load is "finished"
// Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
RefPtr<SubresourceLoader> protect(this);
- if (m_client) {
- m_client->receivedAllData(this, resourceData());
+ if (m_client)
m_client->didFinishLoading(this);
- }
m_handle = 0;
if (!resource)
return NO;
- *data = resource->allData();
+ SharedBuffer* buffer = resource->allData();
+ if (buffer)
+ *data = [buffer->createNSData() autorelease];
+ else
+ *data = nil;
+
*response = resource->response().nsURLResponse();
return YES;
}
HashMap<String, CachedResource*>::const_iterator end = allResources.end();
for (HashMap<String, CachedResource*>::const_iterator it = allResources.begin(); it != end; ++it) {
- [d addObject:it->second->allData()];
+ SharedBuffer* buffer = it->second->allData();
+ NSData *data;
+
+ if (buffer)
+ data = buffer->createNSData();
+ else
+ data = nil;
+
+ [d addObject:data];
+ [data release];
[r addObject:it->second->response().nsURLResponse()];
}
#if PLATFORM(MAC)
#ifdef __OBJC__
-@class NSData;
@class NSURL;
#else
-class NSData;
class NSURL;
#endif
#endif
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SharedBuffer.h"
+
+namespace WebCore {
+
+SharedBuffer::SharedBuffer(const char* data, int size)
+{
+ m_buffer.append(data, size);
+}
+
+unsigned SharedBuffer::size() const
+{
+ if (hasPlatformData())
+ return platformDataSize();
+
+ return m_buffer.size();
+}
+
+const char* SharedBuffer::data() const
+{
+ if (hasPlatformData())
+ return platformData();
+
+ return m_buffer.data();
+}
+
+void SharedBuffer::append(const char* data, int len)
+{
+ maybeTransferPlatformData();
+
+ m_buffer.append(data, len);
+}
+
+void SharedBuffer::clear()
+{
+ clearPlatformData();
+
+ m_buffer.resize(0);
+}
+
+#if !PLATFORM(MAC)
+inline void SharedBuffer::clearPlatformData()
+{
+}
+
+inline void SharedBuffer::maybeTransferPlatformData()
+{
+}
+
+inline bool SharedBuffer::hasPlatformData() const
+{
+ return false;
+}
+
+inline const char* SharedBuffer::platformData() const
+{
+ ASSERT_NOT_REACHED();
+
+ return 0;
+}
+
+inline unsigned SharedBuffer::platformDataSize() const;
+{
+ ASSERT_NOT_REACHED();
+
+ return 0;
+}
+#endif
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SharedBuffer_h
+#define SharedBuffer_h
+
+#include "Shared.h"
+#include <wtf/Forward.h>
+#include <wtf/Vector.h>
+
+#if PLATFORM(MAC)
+#include "RetainPtr.h"
+
+#ifdef __OBJC__
+@class NSData;
+#else
+class NSData;
+#endif
+
+#endif
+
+namespace WebCore {
+
+class SharedBuffer : public Shared<SharedBuffer> {
+public:
+ SharedBuffer(const char*, int);
+#if PLATFORM(MAC)
+ NSData *createNSData();
+ static PassRefPtr<SharedBuffer> wrapNSData(NSData *data);
+#endif
+
+ const char* data() const;
+ unsigned size() const;
+
+ void append(const char*, int);
+ void clear();
+
+private:
+ void clearPlatformData();
+ void maybeTransferPlatformData();
+ bool hasPlatformData() const;
+ const char* platformData() const;
+ unsigned platformDataSize() const;
+
+ Vector<char> m_buffer;
+#if PLATFORM(MAC)
+ SharedBuffer(NSData *nsdata);
+ RetainPtr<NSData> m_nsData;
+#endif
+};
+
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SharedBuffer.h"
+#include <string.h>
+#include <wtf/PassRefPtr.h>
+
+using namespace WebCore;
+
+@interface SharedBufferData : NSData
+{
+ SharedBuffer* sharedBuffer;
+}
+
+- (id)initWithSharedBuffer:(SharedBuffer*)buffer;
+@end
+
+@implementation SharedBufferData
+
+- (void)dealloc
+{
+ sharedBuffer->deref();
+
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ sharedBuffer->deref();
+
+ [super finalize];
+}
+
+- (id)initWithSharedBuffer:(SharedBuffer*)buffer
+{
+ self = [super init];
+
+ if (self) {
+ sharedBuffer = buffer;
+ sharedBuffer->ref();
+ }
+
+ return self;
+}
+
+- (unsigned)length
+{
+ return sharedBuffer->size();
+}
+
+- (const void *)bytes
+{
+ return reinterpret_cast<const void*>(sharedBuffer->data());
+}
+
+@end
+
+namespace WebCore {
+
+PassRefPtr<SharedBuffer> SharedBuffer::wrapNSData(NSData *nsData)
+{
+ return new SharedBuffer(nsData);
+}
+
+SharedBuffer::SharedBuffer(NSData *nsData)
+ : m_nsData(nsData)
+{
+}
+
+NSData *SharedBuffer::createNSData()
+{
+ return [[SharedBufferData alloc] initWithSharedBuffer:this];
+}
+
+bool SharedBuffer::hasPlatformData() const
+{
+ return m_nsData;
+}
+
+const char* SharedBuffer::platformData() const
+{
+ return (const char*)[m_nsData.get() bytes];
+}
+
+unsigned SharedBuffer::platformDataSize() const
+{
+ return [m_nsData.get() length];
+}
+
+void SharedBuffer::maybeTransferPlatformData()
+{
+ if (!m_nsData)
+ return;
+
+ ASSERT(m_buffer.size() == 0);
+
+ m_buffer.append(reinterpret_cast<const char*>([m_nsData.get() bytes]), [m_nsData.get() length]);
+
+ m_nsData = nil;
+}
+
+void SharedBuffer::clearPlatformData()
+{
+ m_nsData = 0;
+}
+
+}
class ResourceHandleInternal;
class ResourceRequest;
class ResourceResponse;
+class SharedBuffer;
class SubresourceLoader;
class SubresourceLoaderClient;
NSURLConnection *connection() const;
WebCoreResourceHandleAsDelegate *delegate();
void releaseDelegate();
- NSData* bufferedData();
+ PassRefPtr<SharedBuffer> bufferedData();
static bool supportsBufferedData();
namespace WebCore {
-#if USE(CFNETWORK)
- typedef void* PlatformData; // unused for now
-#elif PLATFORM(MAC)
- typedef NSData* PlatformData;
-#elif PLATFORM(QT)
+#if PLATFORM(QT)
class PlatformResponseQt : public Shared<PlatformResponseQt> {
public:
QString data;
QString url;
};
- typedef void* PlatformData;
typedef RefPtr<PlatformResponseQt> PlatformResponse;
-#else
- // Not sure what the strategy for this will be on other platforms.
- typedef struct PlatformDataStruct* PlatformData;
#endif
class KURL;
#import "FrameMac.h"
#import "ResourceError.h"
#import "ResourceResponse.h"
+#import "SharedBuffer.h"
#import "SubresourceLoader.h"
#import "WebCoreSystemInterface.h"
return NSURLConnectionSupportsBufferedData;
}
-NSData* ResourceHandle::bufferedData()
+PassRefPtr<SharedBuffer> ResourceHandle::bufferedData()
{
if (ResourceHandle::supportsBufferedData())
- return [d->m_connection.get() _bufferedData];
+ return SharedBuffer::wrapNSData([d->m_connection.get() _bufferedData]);
- return nil;
+ return 0;
}
id ResourceHandle::releaseProxy()
+2007-01-05 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Maciej.
+
+ The data returned is now a SharedBuffer so wrap it in an NSData object.
+
+ * WebView/WebDataSource.mm:
+ (-[WebDataSource data]):
+
2007-01-04 Adam Roben <aroben@apple.com>
Reviewed by Geoff, cheered by others.
#import <JavaScriptCore/Assertions.h>
#import <WebCore/FrameLoader.h>
#import <WebCore/KURL.h>
-#import <WebKit/DOMHTML.h>
+#import <WebCore/MimeTypeRegistry.h>
#import <WebCore/ResourceRequest.h>
+#import <WebCore/SharedBuffer.h>
+#import <WebKit/DOMHTML.h>
#import <WebKit/DOMPrivate.h>
#import <WebKitSystemInterface.h>
-#import <WebCore/MimeTypeRegistry.h>
using namespace WebCore;
- (NSData *)data
{
- return _private->loader->mainResourceData();
+ return [_private->loader->mainResourceData()->createNSData() autorelease];
}
- (id <WebDocumentRepresentation>)representation