2008-03-19 Brady Eidson <beidson@apple.com>
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Mar 2008 00:24:07 +0000 (00:24 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Mar 2008 00:24:07 +0000 (00:24 +0000)
        Reviewed by Anders

        Change SharedBuffer so the wrapping platform data aspect can be shared with all CoreFoundation platforms
        (Mac and Windows instead of just Mac)

        * WebCore.vcproj/WebCore.vcproj: Add SharedBufferCF.cpp
        * WebCore.xcodeproj/project.pbxproj: Ditto

        * platform/SharedBuffer.cpp:
        * platform/SharedBuffer.h: Change the private c'tor from NSData to CFDataRef, other PLATFORM tweaks

        * platform/cf/SharedBufferCF.cpp: Added.
        (WebCore::SharedBuffer::SharedBuffer):
        (WebCore::SharedBuffer::createCFData): Non-Mac version of createCFData
        (WebCore::SharedBuffer::hasPlatformData):
        (WebCore::SharedBuffer::platformData):
        (WebCore::SharedBuffer::platformDataSize):
        (WebCore::SharedBuffer::maybeTransferPlatformData):
        (WebCore::SharedBuffer::clearPlatformData):

        * platform/mac/SharedBufferMac.mm:
        (WebCore::SharedBuffer::wrapNSData): Use the CFDataRef constructor via toll-free bridging
        (WebCore::SharedBuffer::createCFData): Mac-specific version of createCFData

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

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/platform/SharedBuffer.cpp
WebCore/platform/SharedBuffer.h
WebCore/platform/cf/SharedBufferCF.cpp [new file with mode: 0644]
WebCore/platform/mac/SharedBufferMac.mm

index 0bcfa977c9202c2b2b0dcba2a74a0feebbcebf02..4be6c0cad0e187f0111a40d9da54e519b8fda563 100644 (file)
@@ -1,3 +1,29 @@
+2008-03-19  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Anders
+
+        Change SharedBuffer so the wrapping platform data aspect can be shared with all CoreFoundation platforms
+        (Mac and Windows instead of just Mac)
+
+        * WebCore.vcproj/WebCore.vcproj: Add SharedBufferCF.cpp
+        * WebCore.xcodeproj/project.pbxproj: Ditto
+
+        * platform/SharedBuffer.cpp:
+        * platform/SharedBuffer.h: Change the private c'tor from NSData to CFDataRef, other PLATFORM tweaks
+
+        * platform/cf/SharedBufferCF.cpp: Added.
+        (WebCore::SharedBuffer::SharedBuffer):
+        (WebCore::SharedBuffer::createCFData): Non-Mac version of createCFData
+        (WebCore::SharedBuffer::hasPlatformData):
+        (WebCore::SharedBuffer::platformData):
+        (WebCore::SharedBuffer::platformDataSize):
+        (WebCore::SharedBuffer::maybeTransferPlatformData):
+        (WebCore::SharedBuffer::clearPlatformData):
+
+        * platform/mac/SharedBufferMac.mm:
+        (WebCore::SharedBuffer::wrapNSData): Use the CFDataRef constructor via toll-free bridging
+        (WebCore::SharedBuffer::createCFData): Mac-specific version of createCFData
+
 2008-03-19  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Antti.
index 2d1d2a0d8cd0ef7ecf3801d1df0496e55775b79a..98676eba7046c568a99f9481db0b693b3ab1f5a5 100644 (file)
                                        RelativePath="..\platform\cf\RetainPtr.h"\r
                                        >\r
                                </File>\r
+                               <File\r
+                                       RelativePath="..\platform\cf\SharedBufferCF.cpp"\r
+                                       >\r
+                               </File>\r
                        </Filter>\r
                        <Filter\r
                                Name="graphics"\r
index f4c5901794309668b851a095c4c164a327f2ed75..be96e88ed59b0e24f0b7cf29576397d4861d12d3 100644 (file)
                5116D9770CF177BD00C2B84D /* DatabaseDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = 5116D9750CF177BD00C2B84D /* DatabaseDetails.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5126E6BB0A2E3B12005C29FA /* IconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */; };
                5126E6BC0A2E3B12005C29FA /* IconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5126E6BA0A2E3B12005C29FA /* IconDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               512DD8E30D91E2B4000F89EE /* SharedBufferCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */; };
                513F14530AB634C400094DDF /* IconLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513F14510AB634C400094DDF /* IconLoader.cpp */; };
                513F14540AB634C400094DDF /* IconLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 513F14520AB634C400094DDF /* IconLoader.h */; };
                514075C60D53ECFE00BC2D85 /* SecurityOriginHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 514075C50D53ECFE00BC2D85 /* SecurityOriginHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5116D9750CF177BD00C2B84D /* DatabaseDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatabaseDetails.h; sourceTree = "<group>"; };
                5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IconDatabase.cpp; sourceTree = "<group>"; };
                5126E6BA0A2E3B12005C29FA /* IconDatabase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IconDatabase.h; sourceTree = "<group>"; };
+               512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBufferCF.cpp; sourceTree = "<group>"; };
                513F14510AB634C400094DDF /* IconLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IconLoader.cpp; sourceTree = "<group>"; };
                513F14520AB634C400094DDF /* IconLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IconLoader.h; sourceTree = "<group>"; };
                514075C50D53ECFE00BC2D85 /* SecurityOriginHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityOriginHash.h; sourceTree = "<group>"; };
                1AE42F670AA4B8CB00C8612D /* cf */ = {
                        isa = PBXGroup;
                        children = (
+                               5160306B0CC4362300C8AC25 /* FileSystemCF.cpp */,
+                               1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */,
                                1CEFC9B70D78DC8C007D2579 /* SchedulePair.h */,
                                1CEFC9B80D78DC8C007D2579 /* SchedulePair.cpp */,
-                               1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */,
-                               5160306B0CC4362300C8AC25 /* FileSystemCF.cpp */,
+                               512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
                        );
                        path = cf;
                        sourceTree = "<group>";
                                A9D248060D757E7D00FDF959 /* JSMimeType.cpp in Sources */,
                                A9D248080D757E7D00FDF959 /* JSMimeTypeArray.cpp in Sources */,
                                1CE3F8B40D89CFDC00FB035F /* MainThread.cpp in Sources */,
+                               512DD8E30D91E2B4000F89EE /* SharedBufferCF.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index ed47aaf0b7fdf87f949b30a7d7886bd2fcd1ebab..e99d27d86079394ef11f38ddaca540a3a4a3b703 100644 (file)
@@ -78,7 +78,7 @@ PassRefPtr<SharedBuffer> SharedBuffer::copy() const
 }
 
 
-#if !PLATFORM(MAC)
+#if !PLATFORM(CF)
 
 inline void SharedBuffer::clearPlatformData()
 {
index 45d93e84e2fdc6a4e61d8a85d2d3f382d78ab3bc..e7dcc1d1a099cab73d21087a67b9b5b18d089944 100644 (file)
@@ -53,10 +53,12 @@ public:
     
 #if PLATFORM(MAC)
     NSData *createNSData();
-    CFDataRef createCFData();
     static PassRefPtr<SharedBuffer> wrapNSData(NSData *data);
 #endif
-        
+#if PLATFORM(CF)
+    CFDataRef createCFData();
+#endif
+
     const char* data() const;
     unsigned size() const;
     const Vector<char> &buffer() { return m_buffer; }
@@ -80,9 +82,9 @@ private:
     bool hasPlatformData() const;
     
     Vector<char> m_buffer;
-#if PLATFORM(MAC)
-    SharedBuffer(NSData *nsdata);
-    RetainPtr<NSData> m_nsData;
+#if PLATFORM(CF)
+    SharedBuffer(CFDataRef);
+    RetainPtr<CFDataRef> m_cfData;
 #endif
 };
     
diff --git a/WebCore/platform/cf/SharedBufferCF.cpp b/WebCore/platform/cf/SharedBufferCF.cpp
new file mode 100644 (file)
index 0000000..18ce7a9
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2008 Apple 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.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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(CFDataRef cfData)
+    : m_cfData(cfData)
+{
+}
+
+// Mac is a CF platform but has an even more efficient version of this method,
+// so only use this version for non-Mac
+#if !PLATFORM(MAC)
+CFDataRef SharedBuffer::createCFData()
+{
+    if (m_cfData) {
+        CFRetain(m_cfData.get());
+        return m_cfData.get();
+    }
+
+    return CFDataCreate(0, m_buffer.data(), m_buffer.size());
+}
+#endif
+
+bool SharedBuffer::hasPlatformData() const
+{
+    return m_cfData;
+}
+
+const char* SharedBuffer::platformData() const
+{
+    return (const char*)CFDataGetBytePtr(m_cfData.get());
+}
+
+unsigned SharedBuffer::platformDataSize() const
+{
+    return CFDataGetLength(m_cfData.get());
+}
+
+void SharedBuffer::maybeTransferPlatformData()
+{
+    if (!m_cfData)
+        return;
+    
+    ASSERT(m_buffer.size() == 0);
+        
+    m_buffer.append((const char*)CFDataGetBytePtr(m_cfData.get()), CFDataGetLength(m_cfData.get()));
+        
+    m_cfData = 0;
+}
+
+void SharedBuffer::clearPlatformData()
+{
+    m_cfData = 0;
+}
+
+}
index 3c93c1d86c1ffe23d5f2efab299e555be2d4d2a8..e25b8900b2f39135351e637ba232f9f5b606c485 100644 (file)
@@ -95,12 +95,7 @@ namespace WebCore {
 
 PassRefPtr<SharedBuffer> SharedBuffer::wrapNSData(NSData *nsData)
 {
-    return adoptRef(new SharedBuffer(nsData));
-}
-
-SharedBuffer::SharedBuffer(NSData *nsData)
-    : m_nsData(nsData)
-{
+    return adoptRef(new SharedBuffer((CFDataRef)nsData));
 }
 
 NSData *SharedBuffer::createNSData()
@@ -109,40 +104,13 @@ NSData *SharedBuffer::createNSData()
 }
 
 CFDataRef SharedBuffer::createCFData()
-{    
-    return (CFDataRef)HardRetainWithNSRelease([[WebCoreSharedBufferData 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;
+    if (m_cfData) {
+        CFRetain(m_cfData.get());
+        return m_cfData.get();
+    }
     
-    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;
+    return (CFDataRef)HardRetainWithNSRelease([[WebCoreSharedBufferData alloc] initWithSharedBuffer:this]);
 }
 
 PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)