Commit 22f1098a authored by beidson@apple.com's avatar beidson@apple.com

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



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31166 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2a66f46e
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.
......@@ -4147,6 +4147,10 @@
RelativePath="..\platform\cf\RetainPtr.h"
>
</File>
<File
RelativePath="..\platform\cf\SharedBufferCF.cpp"
>
</File>
</Filter>
<Filter
Name="graphics"
......
......@@ -413,6 +413,7 @@
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, ); }; };
......@@ -4761,6 +4762,7 @@
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>"; };
......@@ -8338,10 +8340,11 @@
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>";
......@@ -16194,6 +16197,7 @@
A9D248060D757E7D00FDF959 /* JSMimeType.cpp in Sources */,
A9D248080D757E7D00FDF959 /* JSMimeTypeArray.cpp in Sources */,
1CE3F8B40D89CFDC00FB035F /* MainThread.cpp in Sources */,
512DD8E30D91E2B4000F89EE /* SharedBufferCF.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -78,7 +78,7 @@ PassRefPtr<SharedBuffer> SharedBuffer::copy() const
}
#if !PLATFORM(MAC)
#if !PLATFORM(CF)
inline void SharedBuffer::clearPlatformData()
{
......
......@@ -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
};
......
/*
* 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;
}
}
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment