[iOS] REGRESSION(r171526): PDF documents fail to load in WebKit1 with disk image...
authorpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jul 2014 21:41:36 +0000 (21:41 +0000)
committerpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jul 2014 21:41:36 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135359
<rdar://problem/17824645>

Reviewed by Darin Adler.

r171526 broke the case where we have a memory mapped file from the DiskImageCache in the
SharedBuffer. In such a case, m_buffer is empty and createCFData() returned an
WebCoreSharedBufferData with an empty buffer.

Fix this by taking the easy route of bringing back the old code for the disk image cache
file backed case. In the long run we probably want to remove the iOS specific disk image
cache anyway.

Review also uncovered another bug in r171526 where we were balancing an Objective-C alloc
with a CFRelease which is incorrect when running under GC. Fix that by using adoptNS along
with adoptCF which is what the code did before.

No new tests because the bug only occurs on device and we can't run tests on device yet.

* platform/mac/SharedBufferMac.mm:
(-[WebCoreSharedBufferData initWithDiskImageSharedBuffer:]):
(-[WebCoreSharedBufferData length]):
(-[WebCoreSharedBufferData bytes]):
(WebCore::SharedBuffer::createCFData):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/SharedBufferMac.mm

index 0a685f5..1e39811 100644 (file)
@@ -1,3 +1,31 @@
+2014-07-29  Pratik Solanki  <psolanki@apple.com>
+
+        [iOS] REGRESSION(r171526): PDF documents fail to load in WebKit1 with disk image caching enabled
+        https://bugs.webkit.org/show_bug.cgi?id=135359
+        <rdar://problem/17824645>
+
+        Reviewed by Darin Adler.
+
+        r171526 broke the case where we have a memory mapped file from the DiskImageCache in the
+        SharedBuffer. In such a case, m_buffer is empty and createCFData() returned an
+        WebCoreSharedBufferData with an empty buffer.
+
+        Fix this by taking the easy route of bringing back the old code for the disk image cache
+        file backed case. In the long run we probably want to remove the iOS specific disk image
+        cache anyway.
+
+        Review also uncovered another bug in r171526 where we were balancing an Objective-C alloc
+        with a CFRelease which is incorrect when running under GC. Fix that by using adoptNS along
+        with adoptCF which is what the code did before.
+
+        No new tests because the bug only occurs on device and we can't run tests on device yet.
+
+        * platform/mac/SharedBufferMac.mm:
+        (-[WebCoreSharedBufferData initWithDiskImageSharedBuffer:]):
+        (-[WebCoreSharedBufferData length]):
+        (-[WebCoreSharedBufferData bytes]):
+        (WebCore::SharedBuffer::createCFData):
+
 2014-07-29  Benjamin Poulain  <bpoulain@apple.com>
 
         VisitedLinkState::determineLinkState should take a reference
index 8c501d5..f97328f 100644 (file)
@@ -36,10 +36,16 @@ using namespace WebCore;
 
 @interface WebCoreSharedBufferData : NSData
 {
-    RefPtr<SharedBuffer::DataBuffer> buffer;
+    RefPtr<SharedBuffer::DataBuffer> sharedBufferDataBuffer;
+#if ENABLE(DISK_IMAGE_CACHE)
+    RefPtr<SharedBuffer> sharedBuffer;
+#endif
 }
 
 - (id)initWithSharedBufferDataBuffer:(SharedBuffer::DataBuffer*)dataBuffer;
+#if ENABLE(DISK_IMAGE_CACHE)
+- (id)initWithMemoryMappedSharedBuffer:(SharedBuffer&)memoryMappedSharedBuffer;
+#endif
 @end
 
 @implementation WebCoreSharedBufferData
@@ -71,19 +77,41 @@ using namespace WebCore;
     self = [super init];
     
     if (self)
-        buffer = dataBuffer;
+        sharedBufferDataBuffer = dataBuffer;
+
+    return self;
+}
+
+#if ENABLE(DISK_IMAGE_CACHE)
+- (id)initWithMemoryMappedSharedBuffer:(SharedBuffer&)memoryMappedSharedBuffer
+{
+    ASSERT(memoryMappedSharedBuffer.isMemoryMapped());
+    self = [super init];
+
+    if (!self)
+        return nil;
 
+    sharedBuffer = &memoryMappedSharedBuffer;
     return self;
 }
+#endif
 
 - (NSUInteger)length
 {
-    return buffer->data.size();
+#if ENABLE(DISK_IMAGE_CACHE)
+    if (sharedBuffer)
+        return sharedBuffer->size();
+#endif
+    return sharedBufferDataBuffer->data.size();
 }
 
 - (const void *)bytes
 {
-    return reinterpret_cast<const void*>(buffer->data.data());
+#if ENABLE(DISK_IMAGE_CACHE)
+    if (sharedBuffer)
+        return sharedBuffer->data();
+#endif
+    return sharedBufferDataBuffer->data.data();
 }
 
 @end
@@ -110,14 +138,19 @@ RetainPtr<CFDataRef> SharedBuffer::createCFData()
         return m_dataArray.at(0);
 #endif
 
+#if ENABLE(DISK_IMAGE_CACHE)
+    if (isMemoryMapped())
+        return adoptCF((CFDataRef)adoptNS([[WebCoreSharedBufferData alloc] initWithMemoryMappedSharedBuffer:*this]).leakRef());
+#endif
+
     data(); // Force data into m_buffer from segments or data array.
     if (hasPurgeableBuffer()) {
         RefPtr<SharedBuffer::DataBuffer> copiedBuffer = adoptRef(new DataBuffer);
         copiedBuffer->data.append(data(), size());
-        return adoptCF(reinterpret_cast<CFDataRef>([[WebCoreSharedBufferData alloc] initWithSharedBufferDataBuffer:copiedBuffer.get()]));
+        return adoptCF((CFDataRef)adoptNS([[WebCoreSharedBufferData alloc] initWithSharedBufferDataBuffer:copiedBuffer.get()]).leakRef());
     }
 
-    return adoptCF(reinterpret_cast<CFDataRef>([[WebCoreSharedBufferData alloc] initWithSharedBufferDataBuffer:m_buffer.get()]));
+    return adoptCF((CFDataRef)adoptNS([[WebCoreSharedBufferData alloc] initWithSharedBufferDataBuffer:m_buffer.get()]).leakRef());
 }
 
 PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)