https://bugs.webkit.org/show_bug.cgi?id=121237
Reviewed by Darin Adler.
Source/WebCore:
This makes memory management cleared and fixes a leak in PDFDocumentImage::createPDFDocument.
We use a RetainPtr subclass as a stopgap measure to prevent code that does [buffer->createNSData() autorelease]
from compiling and crashing due to the NSData object being overreleased.
* loader/ResourceBuffer.h:
* loader/mac/ResourceBuffer.mm:
(WebCore::ResourceBuffer::createNSData):
* platform/SharedBuffer.h:
(WebCore::SharedBuffer::NSDataRetainPtr::NSDataRetainPtr):
* platform/graphics/mac/PDFDocumentImageMac.mm:
(WebCore::PDFDocumentImage::createPDFDocument):
* platform/mac/HTMLConverter.mm:
(-[WebHTMLConverter _addAttachmentForElement:URL:needsParagraph:usePlaceholder:]):
(fileWrapperForURL):
* platform/mac/PasteboardMac.mm:
(WebCore::fileWrapper):
(WebCore::Pasteboard::read):
(WebCore::documentFragmentWithRTF):
(WebCore::fragmentFromWebArchive):
* platform/mac/PlatformPasteboardMac.mm:
(WebCore::PlatformPasteboard::setBufferForType):
* platform/mac/SharedBufferMac.mm:
(WebCore::SharedBuffer::createNSData):
Source/WebKit/mac:
Update for WebCore changes. This also fixes a leak where we'd create an NSFileWrapper from NSData but never release the data.
* WebView/WebDataSource.mm:
(-[WebDataSource data]):
* WebView/WebHTMLRepresentation.mm:
(-[WebHTMLRepresentation documentSource]):
* WebView/WebHTMLView.mm:
(-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):
* WebView/WebResource.mm:
(-[WebResource encodeWithCoder:]):
(-[WebResource data]):
Source/WebKit2:
Update for WebCore changes.
* UIProcess/API/mac/WKView.mm:
(-[WKView writeSelectionToPasteboard:types:]):
(-[WKView _setPromisedData:WebCore::withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:WebCore::forPasteboard:]):
(-[WKView namesOfPromisedFilesDroppedAtDestination:]):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155641
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2013-09-12 Anders Carlsson <andersca@apple.com>
+
+ SharedBuffer::createNSData should return a RetainPtr<NSData>
+ https://bugs.webkit.org/show_bug.cgi?id=121237
+
+ Reviewed by Darin Adler.
+
+ This makes memory management cleared and fixes a leak in PDFDocumentImage::createPDFDocument.
+ We use a RetainPtr subclass as a stopgap measure to prevent code that does [buffer->createNSData() autorelease]
+ from compiling and crashing due to the NSData object being overreleased.
+
+ * loader/ResourceBuffer.h:
+ * loader/mac/ResourceBuffer.mm:
+ (WebCore::ResourceBuffer::createNSData):
+ * platform/SharedBuffer.h:
+ (WebCore::SharedBuffer::NSDataRetainPtr::NSDataRetainPtr):
+ * platform/graphics/mac/PDFDocumentImageMac.mm:
+ (WebCore::PDFDocumentImage::createPDFDocument):
+ * platform/mac/HTMLConverter.mm:
+ (-[WebHTMLConverter _addAttachmentForElement:URL:needsParagraph:usePlaceholder:]):
+ (fileWrapperForURL):
+ * platform/mac/PasteboardMac.mm:
+ (WebCore::fileWrapper):
+ (WebCore::Pasteboard::read):
+ (WebCore::documentFragmentWithRTF):
+ (WebCore::fragmentFromWebArchive):
+ * platform/mac/PlatformPasteboardMac.mm:
+ (WebCore::PlatformPasteboard::setBufferForType):
+ * platform/mac/SharedBufferMac.mm:
+ (WebCore::SharedBuffer::createNSData):
+
2013-09-12 Timothy Hatcher <timothy@apple.com>
Remove more Timeline stuff we don't use
PassOwnPtr<PurgeableBuffer> releasePurgeableBuffer();
#if PLATFORM(MAC)
- NSData *createNSData();
+ SharedBuffer::NSDataRetainPtrWithoutImplicitConversionOperator createNSData();
#endif
#if USE(CF)
RetainPtr<CFDataRef> createCFData();
namespace WebCore {
-NSData* ResourceBuffer::createNSData()
+SharedBuffer::NSDataRetainPtrWithoutImplicitConversionOperator ResourceBuffer::createNSData()
{
return m_sharedBuffer->createNSData();
}
~SharedBuffer();
#if PLATFORM(MAC)
- NSData *createNSData();
+ // FIXME: This class exists as a temporary workaround so that code that does:
+ // [buffer->createNSData() autorelease] will fail to compile.
+ // Once both Mac and iOS builds with this change we can change the return type to be RetainPtr<NSData>,
+ // since we're mostly worried about existing code breaking (it's unlikely that we'd use retain/release together
+ // with RetainPtr in new code.
+ class NSDataRetainPtrWithoutImplicitConversionOperator : public RetainPtr<NSData*> {
+ public:
+ template<typename T>
+ NSDataRetainPtrWithoutImplicitConversionOperator(RetainPtr<T*>&& other)
+ : RetainPtr<NSData*>(std::move(other))
+ {
+ }
+
+ explicit operator PtrType() = delete;
+ };
+
+ NSDataRetainPtrWithoutImplicitConversionOperator createNSData();
static PassRefPtr<SharedBuffer> wrapNSData(NSData *data);
#endif
#if USE(CF)
void PDFDocumentImage::createPDFDocument()
{
- m_document = adoptNS([[getPDFDocumentClass() alloc] initWithData:data()->createNSData()]);
+ m_document = adoptNS([[getPDFDocumentClass() alloc] initWithData:data()->createNSData().get()]);
}
void PDFDocumentImage::computeBoundsForCurrentPage()
if (flag && resource && mimeType == "text/html")
notFound = YES;
if (resource && !notFound) {
- fileWrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:[resource->data()->createNSData() autorelease]] autorelease];
+ fileWrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:resource->data()->createNSData().get()] autorelease];
[fileWrapper setPreferredFilename:suggestedFilenameWithMIMEType(url, mimeType)];
}
}
RefPtr<ArchiveResource> resource = dataSource->subresource(URL);
if (resource) {
- NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:[resource->data()->createNSData() autorelease]] autorelease];
+ NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:resource->data()->createNSData().get()] autorelease];
NSString *filename = resource->response().suggestedFilename();
if (!filename || ![filename length])
filename = suggestedFilenameWithMIMEType(resource->url(), resource->mimeType());
static NSFileWrapper* fileWrapper(const PasteboardImage& pasteboardImage)
{
- NSData *data = pasteboardImage.resourceData->createNSData();
- NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
- [data release];
+ NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:pasteboardImage.resourceData->createNSData().get()] autorelease];
[wrapper setPreferredFilename:suggestedFilenameWithMIMEType(pasteboardImage.url.url, pasteboardImage.resourceMIMEType)];
return wrapper;
}
if (types.contains(String(NSRTFDPboardType))) {
if (RefPtr<SharedBuffer> data = platformStrategies()->pasteboardStrategy()->bufferForType(NSRTFDPboardType, m_pasteboardName)) {
- if (auto attributedString = adoptNS([[NSAttributedString alloc] initWithRTFD:[data->createNSData() autorelease] documentAttributes:NULL])) {
+ if (auto attributedString = adoptNS([[NSAttributedString alloc] initWithRTFD:data->createNSData().get() documentAttributes:NULL])) {
text.plainText = [attributedString string];
return;
}
if (types.contains(String(NSRTFPboardType))) {
if (RefPtr<SharedBuffer> data = platformStrategies()->pasteboardStrategy()->bufferForType(NSRTFPboardType, m_pasteboardName)) {
- if (auto attributedString = adoptNS([[NSAttributedString alloc] initWithRTF:[data->createNSData() autorelease] documentAttributes:NULL])) {
+ if (auto attributedString = adoptNS([[NSAttributedString alloc] initWithRTF:data->createNSData().get() documentAttributes:NULL])) {
text.plainText = [attributedString string];
return;
}
if (pasteboardType == NSRTFDPboardType) {
RefPtr<SharedBuffer> data = platformStrategies()->pasteboardStrategy()->bufferForType(NSRTFDPboardType, pastebordName);
if (data)
- string = [[NSAttributedString alloc] initWithRTFD:[data->createNSData() autorelease] documentAttributes:NULL];
+ string = [[NSAttributedString alloc] initWithRTFD:data->createNSData().get() documentAttributes:NULL];
}
if (string == nil) {
RefPtr<SharedBuffer> data = platformStrategies()->pasteboardStrategy()->bufferForType(NSRTFPboardType, pastebordName);
if (data)
- string = [[NSAttributedString alloc] initWithRTF:[data->createNSData() autorelease] documentAttributes:NULL];
+ string = [[NSAttributedString alloc] initWithRTF:data->createNSData().get() documentAttributes:NULL];
}
if (string == nil)
return nil;
return 0;
if (frame->loader().client().canShowMIMETypeAsHTML(MIMEType)) {
- RetainPtr<NSString> markupString = adoptNS([[NSString alloc] initWithData:[mainResource->data()->createNSData() autorelease] encoding:NSUTF8StringEncoding]);
+ RetainPtr<NSString> markupString = adoptNS([[NSString alloc] initWithData:mainResource->data()->createNSData().get() encoding:NSUTF8StringEncoding]);
// FIXME: seems poor form to do this as a side effect of getting a document fragment
if (DocumentLoader* loader = frame->loader().documentLoader())
loader->addAllArchiveResources(coreArchive.get());
long PlatformPasteboard::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType)
{
- BOOL didWriteData = [m_pasteboard.get() setData:buffer ? [buffer->createNSData() autorelease] : nil forType:pasteboardType];
+ BOOL didWriteData = [m_pasteboard setData:buffer ? buffer->createNSData().get() : nil forType:pasteboardType];
if (!didWriteData)
return 0;
return changeCount();
return adoptRef(new SharedBuffer((CFDataRef)nsData));
}
-NSData *SharedBuffer::createNSData()
+SharedBuffer::NSDataRetainPtrWithoutImplicitConversionOperator SharedBuffer::createNSData()
{
- return [[WebCoreSharedBufferData alloc] initWithSharedBuffer:this];
+ return adoptNS([[WebCoreSharedBufferData alloc] initWithSharedBuffer:this]);
}
RetainPtr<CFDataRef> SharedBuffer::createCFData()
+2013-09-12 Anders Carlsson <andersca@apple.com>
+
+ SharedBuffer::createNSData should return a RetainPtr<NSData>
+ https://bugs.webkit.org/show_bug.cgi?id=121237
+
+ Reviewed by Darin Adler.
+
+ Update for WebCore changes. This also fixes a leak where we'd create an NSFileWrapper from NSData but never release the data.
+
+ * WebView/WebDataSource.mm:
+ (-[WebDataSource data]):
+ * WebView/WebHTMLRepresentation.mm:
+ (-[WebHTMLRepresentation documentSource]):
+ * WebView/WebHTMLView.mm:
+ (-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]):
+ * WebView/WebResource.mm:
+ (-[WebResource encodeWithCoder:]):
+ (-[WebResource data]):
+
2013-09-12 Mark Lam <mark.lam@apple.com>
Change debug hooks to pass sourceID and position info via the DebuggerCallFrame.
RefPtr<ResourceBuffer> mainResourceData = toPrivate(_private)->loader->mainResourceData();
if (!mainResourceData)
return nil;
- return [mainResourceData->createNSData() autorelease];
+ return [mainResourceData->createNSData().leakRef() autorelease];
}
- (id <WebDocumentRepresentation>)representation
{
if ([self _isDisplayingWebArchive]) {
SharedBuffer *parsedArchiveData = [_private->dataSource _documentLoader]->parsedArchiveData();
- NSData *nsData = parsedArchiveData ? parsedArchiveData->createNSData() : nil;
- NSString *result = [[NSString alloc] initWithData:nsData encoding:NSUTF8StringEncoding];
- [nsData release];
+ NSString *result = [[NSString alloc] initWithData:parsedArchiveData ? parsedArchiveData->createNSData().get() : nil encoding:NSUTF8StringEncoding];
return [result autorelease];
}
if (WebCore::CachedImage* tiffResource = [self promisedDragTIFFDataSource]) {
if (ResourceBuffer *buffer = static_cast<CachedResource*>(tiffResource)->resourceBuffer()) {
- NSData *data = buffer->createNSData();
NSURLResponse *response = tiffResource->response().nsURLResponse();
draggingImageURL = [response URL];
- wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease];
+ wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().get()] autorelease];
NSString* filename = [response suggestedFilename];
NSString* trueExtension(tiffResource->image()->filenameExtension());
if (!matchesExtensionOrEquivalent(filename, trueExtension))
if (resource) {
if (resource->data())
- data = [resource->data()->createNSData() autorelease];
+ data = resource->data()->createNSData().get();
url = resource->url();
mimeType = resource->mimeType();
textEncoding = resource->textEncoding();
return nil;
if (!_private->coreResource->data())
return nil;
- return [_private->coreResource->data()->createNSData() autorelease];
+ return [_private->coreResource->data()->createNSData().leakRef() autorelease];
}
- (NSURL *)URL
+2013-09-12 Anders Carlsson <andersca@apple.com>
+
+ SharedBuffer::createNSData should return a RetainPtr<NSData>
+ https://bugs.webkit.org/show_bug.cgi?id=121237
+
+ Reviewed by Darin Adler.
+
+ Update for WebCore changes.
+
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView writeSelectionToPasteboard:types:]):
+ (-[WKView _setPromisedData:WebCore::withFileName:withExtension:withTitle:withURL:withVisibleURL:withArchive:WebCore::forPasteboard:]):
+ (-[WKView namesOfPromisedFilesDroppedAtDestination:]):
+
2013-09-12 Anders Carlsson <andersca@apple.com>
SharedBuffer::createCFData should return RetainPtr<CFDataRef>
[pasteboard setString:_data->_page->stringSelectionForPasteboard() forType:NSStringPboardType];
else {
RefPtr<SharedBuffer> buffer = _data->_page->dataSelectionForPasteboard([types objectAtIndex:i]);
- [pasteboard setData:buffer ? [buffer->createNSData() autorelease] : nil forType:[types objectAtIndex:i]];
+ [pasteboard setData:buffer ? buffer->createNSData().get() : nil forType:[types objectAtIndex:i]];
}
}
return YES;
[pasteboard setPropertyList:[NSArray arrayWithObject:extension] forType:NSFilesPromisePboardType];
if (archiveBuffer)
- [pasteboard setData:[archiveBuffer->createNSData() autorelease] forType:PasteboardTypes::WebArchivePboardType];
+ [pasteboard setData:archiveBuffer->createNSData().get() forType:PasteboardTypes::WebArchivePboardType];
_data->_promisedImage = image;
_data->_promisedFilename = filename;
RetainPtr<NSData> data;
if (_data->_promisedImage) {
- data = adoptNS(_data->_promisedImage->data()->createNSData());
+ data = _data->_promisedImage->data()->createNSData();
wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:data.get()]);
- [wrapper.get() setPreferredFilename:_data->_promisedFilename];
+ [wrapper setPreferredFilename:_data->_promisedFilename];
}
if (!wrapper) {