WebArchiveResource.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2013 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebArchiveResource.h"
  27. #if PLATFORM(MAC)
  28. #include "WebData.h"
  29. #include <WebCore/ArchiveResource.h>
  30. #include <WebCore/KURL.h>
  31. #include <wtf/RetainPtr.h>
  32. using namespace WebCore;
  33. namespace WebKit {
  34. PassRefPtr<WebArchiveResource> WebArchiveResource::create(WebData* data, const String& URL, const String& MIMEType, const String& textEncoding)
  35. {
  36. return adoptRef(new WebArchiveResource(data, URL, MIMEType, textEncoding));
  37. }
  38. PassRefPtr<WebArchiveResource> WebArchiveResource::create(PassRefPtr<ArchiveResource> archiveResource)
  39. {
  40. return adoptRef(new WebArchiveResource(archiveResource));
  41. }
  42. WebArchiveResource::WebArchiveResource(WebData* data, const String& URL, const String& MIMEType, const String& textEncoding)
  43. : m_archiveResource(ArchiveResource::create(SharedBuffer::create(data->bytes(), data->size()), KURL(KURL(), URL), MIMEType, textEncoding, String()))
  44. {
  45. }
  46. WebArchiveResource::WebArchiveResource(PassRefPtr<ArchiveResource> archiveResource)
  47. : m_archiveResource(archiveResource)
  48. {
  49. }
  50. WebArchiveResource::~WebArchiveResource()
  51. {
  52. }
  53. static void releaseCFData(unsigned char*, const void* data)
  54. {
  55. // Balanced by CFRetain in WebArchiveResource::data().
  56. CFRelease(data);
  57. }
  58. PassRefPtr<WebData> WebArchiveResource::data()
  59. {
  60. RetainPtr<CFDataRef> cfData = adoptCF(m_archiveResource->data()->createCFData());
  61. // Balanced by CFRelease in releaseCFData.
  62. CFRetain(cfData.get());
  63. return WebData::createWithoutCopying(CFDataGetBytePtr(cfData.get()), CFDataGetLength(cfData.get()), releaseCFData, cfData.get());
  64. }
  65. String WebArchiveResource::URL()
  66. {
  67. return m_archiveResource->url().string();
  68. }
  69. String WebArchiveResource::MIMEType()
  70. {
  71. return m_archiveResource->mimeType();
  72. }
  73. String WebArchiveResource::textEncoding()
  74. {
  75. return m_archiveResource->textEncoding();
  76. }
  77. ArchiveResource* WebArchiveResource::coreArchiveResource()
  78. {
  79. return m_archiveResource.get();
  80. }
  81. } // namespace WebKit
  82. #endif // PLATFORM(MAC)