Unreviewed, rolling out r175406, r175413, and r175423.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Nov 2014 22:27:59 +0000 (22:27 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Nov 2014 22:27:59 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138327

Multipart tests are still broken (Requested by ap on #webkit).

Reverted changesets:

"Eliminate ResourceBuffer and use SharedBuffer directly
instead"
https://bugs.webkit.org/show_bug.cgi?id=138174
http://trac.webkit.org/changeset/175406

"Unreviewed, iOS build fix since 175406."
http://trac.webkit.org/changeset/175413

"Fix assertion in CachedResource::addDataBuffer"
http://trac.webkit.org/changeset/175423

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

81 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
Source/WebCore/editing/ios/EditorIOS.mm
Source/WebCore/editing/mac/EditorMac.mm
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/MediaResourceLoader.cpp
Source/WebCore/loader/ResourceBuffer.cpp [new file with mode: 0644]
Source/WebCore/loader/ResourceBuffer.h [new file with mode: 0644]
Source/WebCore/loader/ResourceLoader.cpp
Source/WebCore/loader/ResourceLoader.h
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/TextTrackLoader.cpp
Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
Source/WebCore/loader/cache/CachedCSSStyleSheet.h
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedRawResource.cpp
Source/WebCore/loader/cache/CachedRawResource.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceClient.h
Source/WebCore/loader/cache/CachedSVGDocument.cpp
Source/WebCore/loader/cache/CachedSVGDocument.h
Source/WebCore/loader/cache/CachedScript.cpp
Source/WebCore/loader/cache/CachedScript.h
Source/WebCore/loader/cache/CachedTextTrack.cpp
Source/WebCore/loader/cache/CachedTextTrack.h
Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp
Source/WebCore/loader/cache/CachedXSLStyleSheet.h
Source/WebCore/loader/cf/SubresourceLoaderCF.cpp
Source/WebCore/loader/cocoa/DiskCacheMonitorCocoa.h
Source/WebCore/loader/cocoa/DiskCacheMonitorCocoa.mm
Source/WebCore/loader/icon/IconLoader.cpp
Source/WebCore/loader/mac/ResourceBuffer.mm [new file with mode: 0644]
Source/WebCore/loader/mac/ResourceLoaderMac.mm
Source/WebCore/platform/SharedBuffer.cpp
Source/WebCore/platform/SharedBuffer.h
Source/WebCore/platform/cf/SharedBufferCF.cpp
Source/WebCore/platform/graphics/PlatformMediaResourceLoader.h
Source/WebCore/platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp
Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm
Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/soup/SharedBufferSoup.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebDataSource.mm
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebDataSource.cpp
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/NetworkProcess/mac/NetworkDiskCacheMonitor.h
Source/WebKit2/NetworkProcess/mac/NetworkDiskCacheMonitor.mm
Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm
Source/WebKit2/Platform/IPC/DataReference.h
Source/WebKit2/Shared/WebResourceBuffer.cpp [new file with mode: 0644]
Source/WebKit2/Shared/WebResourceBuffer.h [new file with mode: 0644]
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp
Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp
Source/WebKit2/WebProcess/Network/WebResourceLoader.h
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 0a9a05d..ca1c330 100644 (file)
@@ -1816,6 +1816,7 @@ set(WebCore_SOURCES
     loader/PolicyCallback.cpp
     loader/PolicyChecker.cpp
     loader/ProgressTracker.cpp
+    loader/ResourceBuffer.cpp
     loader/ResourceLoadNotifier.cpp
     loader/ResourceLoadScheduler.cpp
     loader/ResourceLoader.cpp
index ac995e3..6862a33 100644 (file)
@@ -1,3 +1,23 @@
+2014-11-03  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r175406, r175413, and r175423.
+        https://bugs.webkit.org/show_bug.cgi?id=138327
+
+        Multipart tests are still broken (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        "Eliminate ResourceBuffer and use SharedBuffer directly
+        instead"
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+        http://trac.webkit.org/changeset/175406
+
+        "Unreviewed, iOS build fix since 175406."
+        http://trac.webkit.org/changeset/175413
+
+        "Fix assertion in CachedResource::addDataBuffer"
+        http://trac.webkit.org/changeset/175423
+
 2014-11-03  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, fix bad assertion in r175487.
index 563b963..04ed0bd 100644 (file)
@@ -341,7 +341,7 @@ __ZN7WebCore13pointerCursorEv
 __ZN7WebCore13toJSDOMWindowEN3JSC7JSValueE
 __ZN7WebCore14CachedResource12removeClientEPNS_20CachedResourceClientE
 __ZN7WebCore14CachedResource16unregisterHandleEPNS_24CachedResourceHandleBaseE
-__ZN7WebCore14CachedResource21tryReplaceEncodedDataERNS_12SharedBufferE
+__ZN7WebCore14CachedResource21tryReplaceEncodedDataEN3WTF10PassRefPtrINS_12SharedBufferEEE
 __ZN7WebCore14CachedResource9addClientEPNS_20CachedResourceClientE
 __ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELm0ENS1_15CrashOnOverflowEEE
 __ZN7WebCore14ClientRectListC1Ev
@@ -384,6 +384,13 @@ __ZN7WebCore14LoaderStrategy18createBlobRegistryEv
 __ZN7WebCore14LoaderStrategy21resourceLoadSchedulerEv
 __ZN7WebCore14LoaderStrategy25loadResourceSynchronouslyEPNS_17NetworkingContextEmRKNS_15ResourceRequestENS_17StoredCredentialsENS_22ClientCredentialPolicyERNS_13ResourceErrorERNS_16ResourceResponseERN3WTF6VectorIcLm0ENSC_15CrashOnOverflowEEE
 __ZN7WebCore14PluginDocument12pluginWidgetEv
+__ZN7WebCore14ResourceBuffer12createNSDataEv
+__ZN7WebCore14ResourceBuffer6appendEPKcj
+__ZN7WebCore14ResourceBufferC1EPKcj
+__ZN7WebCore14ResourceBufferC1Ev
+__ZN7WebCore14ResourceBufferC2Ev
+__ZN7WebCore14ResourceBufferD1Ev
+__ZN7WebCore14ResourceBufferD2Ev
 __ZN7WebCore14ResourceHandle12firstRequestEv
 __ZN7WebCore14ResourceHandle16setDefersLoadingEb
 __ZN7WebCore14ResourceHandle20forceContentSniffingEv
@@ -1724,6 +1731,9 @@ __ZNK7WebCore14FrameSelection31getClippedVisibleTextRectanglesERN3WTF6VectorINS_
 __ZNK7WebCore14FrameSelection36rootEditableElementOrDocumentElementEv
 __ZNK7WebCore14InsertionPoint8isActiveEv
 __ZNK7WebCore14RenderListItem10markerTextEv
+__ZNK7WebCore14ResourceBuffer4dataEv
+__ZNK7WebCore14ResourceBuffer4sizeEv
+__ZNK7WebCore14ResourceBuffer7isEmptyEv
 __ZNK7WebCore14ResourceHandle10connectionEv
 __ZNK7WebCore14ResourceLoader11frameLoaderEv
 __ZNK7WebCore14ResourceLoader32isAllowedToAskUserForCredentialsEv
@@ -2796,6 +2806,7 @@ __ZNK7WebCore14FrameSelection29rangeByMovingCurrentSelectionEi
 __ZNK7WebCore14FrameSelection32rangeByExtendingCurrentSelectionEi
 __ZNK7WebCore14FrameSelection35characterInRelationToCaretSelectionEi
 __ZNK7WebCore14FrameSelection36elementRangeContainingCaretSelectionEv
+__ZNK7WebCore14ResourceBuffer12sharedBufferEv
 __ZNK7WebCore14SecurityOrigin8toStringEv
 __ZNK7WebCore15GraphicsLayerCA21contentsLayerForMediaEv
 __ZNK7WebCore15VisiblePosition4leftEb
index dbc16dd..8233664 100644 (file)
     <ClCompile Include="..\loader\PolicyCallback.cpp" />
     <ClCompile Include="..\loader\PolicyChecker.cpp" />
     <ClCompile Include="..\loader\ProgressTracker.cpp" />
+    <ClCompile Include="..\loader\ResourceBuffer.cpp" />
     <ClCompile Include="..\loader\ResourceLoader.cpp" />
     <ClCompile Include="..\loader\cf\ResourceLoaderCFNet.cpp" />
     <ClCompile Include="..\loader\ResourceLoadNotifier.cpp" />
     <ClInclude Include="..\loader\PolicyChecker.h" />
     <ClInclude Include="..\loader\ProgressTracker.h" />
     <ClInclude Include="..\loader\ProgressTrackerClient.h" />
+    <ClInclude Include="..\loader\ResourceBuffer.h" />
     <ClInclude Include="..\loader\ResourceLoader.h" />
     <ClInclude Include="..\loader\ResourceLoaderOptions.h" />
     <ClInclude Include="..\loader\ResourceLoadNotifier.h" />
index c5f69be..322b70c 100644 (file)
     <ClCompile Include="..\loader\ProgressTracker.cpp">
       <Filter>loader</Filter>
     </ClCompile>
+    <ClCompile Include="..\loader\ResourceBuffer.cpp">
+      <Filter>loader</Filter>
+    </ClCompile>
     <ClCompile Include="..\loader\ResourceLoader.cpp">
       <Filter>loader</Filter>
     </ClCompile>
     <ClInclude Include="..\loader\ProgressTrackerClient.h">
       <Filter>loader</Filter>
     </ClInclude>
+    <ClInclude Include="..\loader\ResourceBuffer.h">
+      <Filter>loader</Filter>
+    </ClInclude>
     <ClInclude Include="..\loader\ResourceLoader.h">
       <Filter>loader</Filter>
     </ClInclude>
index 6231788..e7db10f 100644 (file)
                51405C89190B014400754F94 /* SelectionRectGatherer.h in Headers */ = {isa = PBXBuildFile; fileRef = 51405C87190B014400754F94 /* SelectionRectGatherer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                514B3F730C722047000530DF /* FileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 514B3F720C722047000530DF /* FileSystem.h */; settings = {ATTRIBUTES = (Private, ); }; };
                514B3F760C722055000530DF /* FileSystemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514B3F750C722055000530DF /* FileSystemMac.mm */; };
+               514BC83F161CF04A004D52F4 /* ResourceBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514BC83D161CF043004D52F4 /* ResourceBuffer.mm */; };
+               514BC842161CF05C004D52F4 /* ResourceBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514BC840161CF05C004D52F4 /* ResourceBuffer.cpp */; };
+               514BC843161CF05C004D52F4 /* ResourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 514BC841161CF05C004D52F4 /* ResourceBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                514C76370CE9225E007EF3CD /* JSSQLError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514C76350CE9225E007EF3CD /* JSSQLError.cpp */; };
                514C76380CE9225E007EF3CD /* JSSQLTransaction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514C76360CE9225E007EF3CD /* JSSQLTransaction.cpp */; };
                514C764C0CE9234E007EF3CD /* AuthenticationMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 514C76420CE9234E007EF3CD /* AuthenticationMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51405C87190B014400754F94 /* SelectionRectGatherer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectionRectGatherer.h; sourceTree = "<group>"; };
                514B3F720C722047000530DF /* FileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystem.h; sourceTree = "<group>"; };
                514B3F750C722055000530DF /* FileSystemMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSystemMac.mm; sourceTree = "<group>"; };
+               514BC83D161CF043004D52F4 /* ResourceBuffer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceBuffer.mm; sourceTree = "<group>"; };
+               514BC840161CF05C004D52F4 /* ResourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceBuffer.cpp; sourceTree = "<group>"; };
+               514BC841161CF05C004D52F4 /* ResourceBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceBuffer.h; sourceTree = "<group>"; };
                514C76350CE9225E007EF3CD /* JSSQLError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSQLError.cpp; sourceTree = "<group>"; };
                514C76360CE9225E007EF3CD /* JSSQLTransaction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSQLTransaction.cpp; sourceTree = "<group>"; };
                514C76420CE9234E007EF3CD /* AuthenticationMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthenticationMac.h; sourceTree = "<group>"; };
                                1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */,
                                656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */,
                                656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.mm */,
+                               514BC83D161CF043004D52F4 /* ResourceBuffer.mm */,
                                51AA3F6E0BD5AA9E00892971 /* ResourceLoaderMac.mm */,
                        );
                        path = mac;
                                1A2A68210B5BEDE70002A480 /* ProgressTracker.cpp */,
                                1A2A68220B5BEDE70002A480 /* ProgressTracker.h */,
                                1ACADD781880D91C00D8B71D /* ProgressTrackerClient.h */,
+                               514BC840161CF05C004D52F4 /* ResourceBuffer.cpp */,
+                               514BC841161CF05C004D52F4 /* ResourceBuffer.h */,
                                93E227DE0AF589AD00D48324 /* ResourceLoader.cpp */,
                                656D37270ADBA5DE00A4554D /* ResourceLoader.h */,
                                D0A3A7301405A39800FB8ED3 /* ResourceLoaderOptions.h */,
                                99CC0B5C18BE984A006CEBCC /* ReplaySessionSegment.h in Headers */,
                                4998AEC613F9D0EA0090B1AA /* RequestAnimationFrameCallback.h in Headers */,
                                F55B3DD01251F12D003EF269 /* ResetInputType.h in Headers */,
+                               514BC843161CF05C004D52F4 /* ResourceBuffer.h in Headers */,
                                7EE6846A12D26E3800E79415 /* ResourceError.h in Headers */,
                                934F713C0D5A6F1900018D69 /* ResourceErrorBase.h in Headers */,
                                514C76790CE923A1007EF3CD /* ResourceHandle.h in Headers */,
                                99CC0B5918BE984A006CEBCC /* ReplaySession.cpp in Sources */,
                                99CC0B5B18BE984A006CEBCC /* ReplaySessionSegment.cpp in Sources */,
                                F55B3DCF1251F12D003EF269 /* ResetInputType.cpp in Sources */,
+                               514BC842161CF05C004D52F4 /* ResourceBuffer.cpp in Sources */,
+                               514BC83F161CF04A004D52F4 /* ResourceBuffer.mm in Sources */,
                                934F713E0D5A6F2800018D69 /* ResourceErrorBase.cpp in Sources */,
                                7EE6846B12D26E3800E79415 /* ResourceErrorCF.cpp in Sources */,
                                514C76500CE9234E007EF3CD /* ResourceErrorMac.mm in Sources */,
index 201c259..b8d9330 100644 (file)
@@ -62,6 +62,7 @@
 #import "RenderObject.h"
 #import "RenderStyleConstants.h"
 #import "RenderText.h"
+#import "ResourceBuffer.h"
 #import "SharedBuffer.h"
 #import "VisiblePosition.h"
 #import "VisibleUnits.h"
@@ -463,15 +464,23 @@ using WebCore::VisiblePosition;
 
 - (NSData *)dataRepresentation:(BOOL)rawImageData
 {
-    WebCore::CachedImagecachedImage = core(self)->cachedImage();
+    WebCore::CachedImage *cachedImage = core(self)->cachedImage();
     if (!cachedImage)
         return nil;
-    WebCore::Imageimage = cachedImage->image();
+    WebCore::Image *image = cachedImage->image();
     if (!image)
         return nil;
-    WebCore::SharedBuffer* data = rawImageData ? cachedImage->resourceBuffer() : image->data();
+    WebCore::SharedBuffer *data = nil;
+    if (rawImageData) {
+        ResourceBuffer *resourceBuffer = cachedImage->resourceBuffer();
+        if (resourceBuffer)
+            data = resourceBuffer->sharedBuffer();
+    } else {
+        data = image->data();
+    }
     if (!data)
         return nil;
+
     return data->createNSData().autorelease();
 }
 
index b9eb96c..0192d5e 100644 (file)
@@ -49,6 +49,7 @@
 #include "Pasteboard.h"
 #include "RenderBlock.h"
 #include "RenderImage.h"
+#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "SoftLinking.h"
 #include "StyleProperties.h"
@@ -384,7 +385,7 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
     pasteboardImage.url.url = imageElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(imageElement.imageSourceURL()));
     pasteboardImage.url.title = title;
     pasteboardImage.resourceMIMEType = pasteboard.resourceMIMEType(cachedImage->response().mimeType());
-    pasteboardImage.resourceData = cachedImage->resourceBuffer();
+    pasteboardImage.resourceData = cachedImage->resourceBuffer()->sharedBuffer();
 
     pasteboard.write(pasteboardImage);
 }
index 29276fa..6e4190f 100644 (file)
@@ -52,6 +52,7 @@
 #import "Range.h"
 #import "RenderBlock.h"
 #import "RenderImage.h"
+#import "ResourceBuffer.h"
 #import "RuntimeApplicationChecks.h"
 #import "Sound.h"
 #import "StyleProperties.h"
@@ -446,7 +447,7 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
     pasteboardImage.url.url = url;
     pasteboardImage.url.title = title;
     pasteboardImage.url.userVisibleForm = client()->userVisibleString(pasteboardImage.url.url);
-    pasteboardImage.resourceData = cachedImage->resourceBuffer();
+    pasteboardImage.resourceData = cachedImage->resourceBuffer()->sharedBuffer();
     pasteboardImage.resourceMIMEType = cachedImage->response().mimeType();
 
     pasteboard.write(pasteboardImage);
index 40a7b57..179ec10 100644 (file)
@@ -45,6 +45,7 @@
 #include "Page.h"
 #include "RawDataDocumentParser.h"
 #include "RenderElement.h"
+#include "ResourceBuffer.h"
 #include "Settings.h"
 
 namespace WebCore {
@@ -133,8 +134,7 @@ void ImageDocument::updateDuringParsing()
     if (!m_imageElement)
         createDocumentStructure();
 
-    if (RefPtr<SharedBuffer> buffer = loader()->mainResourceData())
-        m_imageElement->cachedImage()->addDataBuffer(*buffer);
+    m_imageElement->cachedImage()->addDataBuffer(loader()->mainResourceData().get());
 
     imageUpdated();
 }
@@ -143,11 +143,11 @@ void ImageDocument::finishedParsing()
 {
     if (!parser()->isStopped() && m_imageElement) {
         CachedImage& cachedImage = *m_imageElement->cachedImage();
-        RefPtr<SharedBuffer> data = loader()->mainResourceData();
+        RefPtr<ResourceBuffer> data = loader()->mainResourceData();
 
         // If this is a multipart image, make a copy of the current part, since the resource data
         // will be overwritten by the next part.
-        if (data && loader()->isLoadingMultipartContent())
+        if (loader()->isLoadingMultipartContent())
             data = data->copy();
 
         cachedImage.finishLoading(data.get());
index f9b2b21..782826d 100644 (file)
@@ -62,6 +62,7 @@
 #include "MainFrame.h"
 #include "MemoryCache.h"
 #include "Page.h"
+#include "ResourceBuffer.h"
 #include "ScriptController.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -142,9 +143,11 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
 
     *base64Encoded = !hasTextContent(cachedResource);
     if (*base64Encoded) {
-        RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer();
+        RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer()->sharedBuffer();
+
         if (!buffer)
             return false;
+
         *result = base64Encode(buffer->data(), buffer->size());
         return true;
     }
@@ -163,7 +166,7 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
             *result = downcast<CachedScript>(*cachedResource).script();
             return true;
         case CachedResource::RawResource: {
-            auto* buffer = cachedResource->resourceBuffer();
+            ResourceBuffer* buffer = cachedResource->resourceBuffer();
             if (!buffer)
                 return false;
             RefPtr<TextResourceDecoder> decoder = createXHRTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName());
@@ -174,7 +177,7 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
             return true;
         }
         default:
-            auto* buffer = cachedResource->resourceBuffer();
+            ResourceBuffer* buffer = cachedResource->resourceBuffer();
             return decodeBuffer(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, cachedResource->encoding(), result);
         }
     }
@@ -183,10 +186,12 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
 
 bool InspectorPageAgent::mainResourceContent(Frame* frame, bool withBase64Encode, String* result)
 {
-    RefPtr<SharedBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
+    RefPtr<ResourceBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
     if (!buffer)
         return false;
-    return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), frame->document()->inputEncoding(), withBase64Encode, result);
+    String textEncodingName = frame->document()->inputEncoding();
+
+    return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), textEncodingName, withBase64Encode, result);
 }
 
 // static
index 481b2ba..1c57a4f 100644 (file)
@@ -54,6 +54,7 @@
 #include "NetworkResourcesData.h"
 #include "Page.h"
 #include "ProgressTracker.h"
+#include "ResourceBuffer.h"
 #include "ResourceError.h"
 #include "ResourceLoader.h"
 #include "ResourceRequest.h"
@@ -404,9 +405,8 @@ void InspectorResourceAgent::didFinishLoading(unsigned long identifier, Document
 
     String requestId = IdentifiersFactory::requestId(identifier);
     if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
-        m_resourcesData->addResourceSharedBuffer(requestId,
-            loader->frameLoader()->documentLoader()->mainResourceData(),
-            loader->frame()->document()->inputEncoding());
+        RefPtr<ResourceBuffer> buffer = loader->frameLoader()->documentLoader()->mainResourceData();
+        m_resourcesData->addResourceSharedBuffer(requestId, buffer ? buffer->sharedBuffer() : nullptr, loader->frame()->document()->inputEncoding());
     }
 
     m_resourcesData->maybeDecodeDataToContent(requestId);
@@ -435,9 +435,8 @@ void InspectorResourceAgent::didFailLoading(unsigned long identifier, DocumentLo
     if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
         Frame* frame = loader ? loader->frame() : nullptr;
         if (frame && frame->loader().documentLoader() && frame->document()) {
-            m_resourcesData->addResourceSharedBuffer(requestId,
-                frame->loader().documentLoader()->mainResourceData(),
-                frame->document()->inputEncoding());
+            RefPtr<ResourceBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
+            m_resourcesData->addResourceSharedBuffer(requestId, buffer ? buffer->sharedBuffer() : nullptr, frame->document()->inputEncoding());
         }
     }
 
index 977ed14..40ae594 100644 (file)
@@ -56,6 +56,7 @@
 #include "Page.h"
 #include "PolicyChecker.h"
 #include "ProgressTracker.h"
+#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "SchemeRegistry.h"
 #include "SecurityPolicy.h"
@@ -170,20 +171,20 @@ DocumentLoader::~DocumentLoader()
     clearMainResource();
 }
 
-PassRefPtr<SharedBuffer> DocumentLoader::mainResourceData() const
+PassRefPtr<ResourceBuffer> DocumentLoader::mainResourceData() const
 {
     if (m_substituteData.isValid())
-        return m_substituteData.content()->copy();
+        return ResourceBuffer::create(m_substituteData.content()->data(), m_substituteData.content()->size());
     if (m_mainResource)
         return m_mainResource->resourceBuffer();
-    return nullptr;
+    return 0;
 }
 
 Document* DocumentLoader::document() const
 {
     if (m_frame && m_frame->loader().documentLoader() == this)
         return m_frame->document();
-    return nullptr;
+    return 0;
 }
 
 const ResourceRequest& DocumentLoader::originalRequest() const
@@ -993,7 +994,8 @@ bool DocumentLoader::maybeCreateArchive()
 #else
     
     // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0.
-    m_archive = ArchiveFactory::create(m_response.url(), mainResourceData().get(), m_response.mimeType());
+    RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
+    m_archive = ArchiveFactory::create(m_response.url(), mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0, m_response.mimeType());
     if (!m_archive)
         return false;
     
@@ -1009,7 +1011,6 @@ bool DocumentLoader::maybeCreateArchive()
 }
 
 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
-
 void DocumentLoader::setArchive(PassRefPtr<Archive> archive)
 {
     m_archive = archive;
@@ -1057,46 +1058,47 @@ SharedBuffer* DocumentLoader::parsedArchiveData() const
 {
     return m_parsedArchiveData.get();
 }
-
 #endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
 
 ArchiveResource* DocumentLoader::archiveResourceForURL(const URL& url) const
 {
     if (!m_archiveResourceCollection)
-        return nullptr;
+        return 0;
+        
     ArchiveResource* resource = m_archiveResourceCollection->archiveResourceForURL(url);
-    if (!resource || resource->shouldIgnoreWhenUnarchiving())
-        return nullptr;
-    return resource;
+
+    return resource && !resource->shouldIgnoreWhenUnarchiving() ? resource : 0;
 }
 
 PassRefPtr<ArchiveResource> DocumentLoader::mainResource() const
 {
-    RefPtr<SharedBuffer> data = mainResourceData();
+    const ResourceResponse& r = response();
+    
+    RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
+    RefPtr<SharedBuffer> data = mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0;
     if (!data)
         data = SharedBuffer::create();
         
-    auto& response = this->response();
-    return ArchiveResource::create(data, response.url(), response.mimeType(), response.textEncodingName(), frame()->tree().uniqueName());
+    return ArchiveResource::create(data, r.url(), r.mimeType(), r.textEncodingName(), frame()->tree().uniqueName());
 }
 
 PassRefPtr<ArchiveResource> DocumentLoader::subresource(const URL& url) const
 {
     if (!isCommitted())
-        return nullptr;
+        return 0;
     
     CachedResource* resource = m_cachedResourceLoader->cachedResource(url);
     if (!resource || !resource->isLoaded())
         return archiveResourceForURL(url);
 
     if (resource->type() == CachedResource::MainResource)
-        return nullptr;
+        return 0;
 
-    auto* data = resource->resourceBuffer();
+    ResourceBuffer* data = resource->resourceBuffer();
     if (!data)
-        return nullptr;
+        return 0;
 
-    return ArchiveResource::create(data, url, resource->response());
+    return ArchiveResource::create(data->sharedBuffer(), url, resource->response());
 }
 
 Vector<RefPtr<ArchiveResource>> DocumentLoader::subresources() const
@@ -1509,7 +1511,7 @@ void DocumentLoader::maybeFinishLoadingMultipartContent()
 
     frameLoader()->setupForReplace();
     m_committed = false;
-    RefPtr<SharedBuffer> resourceData = mainResourceData();
+    RefPtr<ResourceBuffer> resourceData = mainResourceData();
     commitLoad(resourceData->data(), resourceData->size());
 }
 
index 7698ffb..403e195 100644 (file)
@@ -68,6 +68,7 @@ namespace WebCore {
     class Frame;
     class FrameLoader;
     class Page;
+    class ResourceBuffer;
     class ResourceLoader;
     class SharedBuffer;
     class SubstituteResource;
@@ -92,7 +93,7 @@ namespace WebCore {
 
         WEBCORE_EXPORT FrameLoader* frameLoader() const;
         WEBCORE_EXPORT ResourceLoader* mainResourceLoader() const;
-        WEBCORE_EXPORT PassRefPtr<SharedBuffer> mainResourceData() const;
+        WEBCORE_EXPORT PassRefPtr<ResourceBuffer> mainResourceData() const;
         
         DocumentWriter& writer() const { return m_writer; }
 
index 87de3c6..80756f1 100644 (file)
 #include "MediaResourceLoader.h"
 
 #if ENABLE(VIDEO)
-
 #include "CachedRawResource.h"
 #include "CachedResourceLoader.h"
 #include "CachedResourceRequest.h"
 #include "CrossOriginAccessControl.h"
 #include "Document.h"
+#include "ResourceBuffer.h"
 #include "SecurityOrigin.h"
 #include <wtf/NeverDestroyed.h>
 
@@ -112,10 +112,13 @@ void MediaResourceLoader::responseReceived(CachedResource* resource, const Resou
 
 void MediaResourceLoader::dataReceived(CachedResource* resource, const char* data, int dataLength)
 {
-    ASSERT_UNUSED(resource, resource == m_resource);
+    ASSERT(resource == m_resource);
 
     RefPtr<MediaResourceLoader> protect(this);
     m_client->dataReceived(data, dataLength);
+
+    if (SharedBuffer* buffer = resource->resourceBuffer() ? resource->resourceBuffer()->sharedBuffer() : nullptr)
+        m_client->bufferReceived(buffer);
 }
 
 void MediaResourceLoader::notifyFinished(CachedResource* resource)
@@ -126,7 +129,7 @@ void MediaResourceLoader::notifyFinished(CachedResource* resource)
     if (resource->loadFailedOrCanceled())
         m_client->loadFailed(resource->resourceError());
     else
-        m_client->loadFinished();
+        m_client->loadFinished(resource->resourceBuffer() ? resource->resourceBuffer()->sharedBuffer() : nullptr);
     stop();
 }
 
diff --git a/Source/WebCore/loader/ResourceBuffer.cpp b/Source/WebCore/loader/ResourceBuffer.cpp
new file mode 100644 (file)
index 0000000..a6ba8ce
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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 "ResourceBuffer.h"
+
+#include "SharedBuffer.h"
+
+namespace WebCore {
+
+ResourceBuffer::ResourceBuffer()
+    : m_sharedBuffer(SharedBuffer::create())
+{
+}
+
+ResourceBuffer::ResourceBuffer(const char* data, unsigned size)
+    : m_sharedBuffer(SharedBuffer::create(data, size))
+{
+}
+
+ResourceBuffer::ResourceBuffer(PassRefPtr<SharedBuffer> sharedBuffer)
+    : m_sharedBuffer(sharedBuffer)
+{
+    ASSERT(m_sharedBuffer);
+}
+    
+ResourceBuffer::~ResourceBuffer()
+{
+}
+
+PassRefPtr<ResourceBuffer> ResourceBuffer::adoptSharedBuffer(PassRefPtr<SharedBuffer> shared)
+{
+    return shared ? adoptRef(new ResourceBuffer(shared)) : nullptr;
+}
+
+const char* ResourceBuffer::data() const
+{
+    return m_sharedBuffer->data();
+}
+
+unsigned ResourceBuffer::size() const
+{
+    return m_sharedBuffer->size();
+}
+
+bool ResourceBuffer::isEmpty() const
+{
+    return m_sharedBuffer->isEmpty();
+}
+
+void ResourceBuffer::append(const char* data, unsigned size)
+{
+    m_sharedBuffer->append(data, size);
+}
+
+void ResourceBuffer::append(SharedBuffer* buffer)
+{
+    m_sharedBuffer->append(buffer);
+}
+
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+void ResourceBuffer::append(CFDataRef data)
+{
+    ASSERT(m_sharedBuffer);
+    m_sharedBuffer->append(data);
+}
+#endif
+
+void ResourceBuffer::clear()
+{
+    m_sharedBuffer->clear();
+}
+
+unsigned ResourceBuffer::getSomeData(const char*& data, unsigned position) const
+{
+    return m_sharedBuffer->getSomeData(data, position);
+}
+
+SharedBuffer* ResourceBuffer::sharedBuffer() const
+{
+    // Currently all ResourceBuffers are backed by SharedBuffers.
+    // In the future we might have to create the SharedBuffer on demand here.
+    // We should also phase out as much use of this accessor as possible and have clients
+    // either use the ResourceBuffer directly or use getSomeData() when sensical.
+    return m_sharedBuffer.get();
+}
+
+PassRefPtr<ResourceBuffer> ResourceBuffer::copy() const
+{
+    return ResourceBuffer::adoptSharedBuffer(m_sharedBuffer->copy());
+}
+
+#if USE(CF)
+RetainPtr<CFDataRef> ResourceBuffer::createCFData()
+{
+    return m_sharedBuffer->createCFData();
+}
+#endif
+
+} // namespace WebCore
diff --git a/Source/WebCore/loader/ResourceBuffer.h b/Source/WebCore/loader/ResourceBuffer.h
new file mode 100644 (file)
index 0000000..e63b08a
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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.
+ */
+
+#ifndef ResourceBuffer_h
+#define ResourceBuffer_h
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/RetainPtr.h>
+
+#if USE(FOUNDATION)
+OBJC_CLASS NSData;
+#endif
+
+namespace WebCore {
+
+class SharedBuffer;
+
+class ResourceBuffer : public RefCounted<ResourceBuffer> {
+public:
+
+    static PassRefPtr<ResourceBuffer> create() { return adoptRef(new ResourceBuffer); }
+    static PassRefPtr<ResourceBuffer> create(const char* data, unsigned size) { return adoptRef(new ResourceBuffer(data, size)); }
+    static PassRefPtr<ResourceBuffer> adoptSharedBuffer(PassRefPtr<SharedBuffer>);
+
+    WEBCORE_EXPORT virtual ~ResourceBuffer();
+
+    WEBCORE_EXPORT virtual const char* data() const;
+    WEBCORE_EXPORT virtual unsigned size() const;
+    WEBCORE_EXPORT virtual bool isEmpty() const;
+
+    WEBCORE_EXPORT void append(const char*, unsigned);
+    void append(SharedBuffer*);
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+    void append(CFDataRef);
+#endif
+    void clear();
+    
+    unsigned getSomeData(const char*& data, unsigned position = 0) const;
+    
+    WEBCORE_EXPORT SharedBuffer* sharedBuffer() const;
+#if USE(FOUNDATION)
+    void tryReplaceSharedBufferContents(SharedBuffer*);
+#endif
+    PassRefPtr<ResourceBuffer> copy() const;
+
+#if USE(FOUNDATION)
+    WEBCORE_EXPORT RetainPtr<NSData> createNSData();
+#endif
+#if USE(CF)
+    RetainPtr<CFDataRef> createCFData();
+#endif
+
+protected:
+    WEBCORE_EXPORT ResourceBuffer();
+
+private:
+    WEBCORE_EXPORT ResourceBuffer(const char*, unsigned);
+    ResourceBuffer(PassRefPtr<SharedBuffer>);
+
+    RefPtr<SharedBuffer> m_sharedBuffer;
+};
+
+} // namespace WebCore
+
+#endif // ResourceBuffer_h
index 43b9c3f..2c81fa3 100644 (file)
@@ -42,6 +42,7 @@
 #include "Page.h"
 #include "PlatformStrategies.h"
 #include "ProgressTracker.h"
+#include "ResourceBuffer.h"
 #include "ResourceError.h"
 #include "ResourceHandle.h"
 #include "ResourceLoadScheduler.h"
@@ -221,12 +222,12 @@ void ResourceLoader::addDataOrBuffer(const char* data, unsigned length, SharedBu
         return;
 
     if (dataPayloadType == DataPayloadWholeResource) {
-        m_resourceData = buffer ? buffer : SharedBuffer::create(data, length);
+        m_resourceData = buffer ? ResourceBuffer::adoptSharedBuffer(buffer) : ResourceBuffer::create(data, length);
         return;
     }
         
     if (!m_resourceData)
-        m_resourceData = buffer ? buffer : SharedBuffer::create(data, length);
+        m_resourceData = buffer ? ResourceBuffer::adoptSharedBuffer(buffer) : ResourceBuffer::create(data, length);
     else {
         if (buffer)
             m_resourceData->append(buffer);
index 1615f6d..8d094c6 100644 (file)
@@ -47,6 +47,7 @@ class DocumentLoader;
 class Frame;
 class FrameLoader;
 class URL;
+class ResourceBuffer;
 
 #if USE(QUICK_LOOK)
 class QuickLookHandle;
@@ -87,7 +88,7 @@ public:
     virtual void releaseResources();
     const ResourceResponse& response() const;
 
-    SharedBuffer* resourceData() const { return m_resourceData.get(); }
+    ResourceBuffer* resourceData() const { return m_resourceData.get(); }
     void clearResourceData();
     
     virtual bool isSubresourceLoader();
@@ -203,7 +204,7 @@ private:
 
     ResourceRequest m_request;
     ResourceRequest m_originalRequest; // Before redirects.
-    RefPtr<SharedBuffer> m_resourceData;
+    RefPtr<ResourceBuffer> m_resourceData;
     
     unsigned long m_identifier;
 
index 26a34e2..7d40e63 100644 (file)
@@ -38,6 +38,7 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "PageActivityAssertionToken.h"
+#include "ResourceBuffer.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCountedLeakCounter.h>
 #include <wtf/StdLibExtras.h>
@@ -232,10 +233,11 @@ void SubresourceLoader::didReceiveResponse(const ResourceResponse& response)
         }
     }
 
-    auto* buffer = resourceData();
+    RefPtr<ResourceBuffer> buffer = resourceData();
     if (m_loadingMultipartContent && buffer && buffer->size()) {
         // The resource data will change as the next part is loaded, so we need to make a copy.
-        m_resource->finishLoading(&buffer->copy().get());
+        RefPtr<ResourceBuffer> copiedData = ResourceBuffer::create(buffer->data(), buffer->size());
+        m_resource->finishLoading(copiedData.get());
         clearResourceData();
         // Since a subresource loader does not load multipart sections progressively, data was delivered to the loader all at once.        
         // After the first multipart section is complete, signal to delegates that this load is "finished" 
@@ -271,8 +273,8 @@ void SubresourceLoader::didReceiveDataOrBuffer(const char* data, int length, Pas
     ResourceLoader::didReceiveDataOrBuffer(data, length, buffer, encodedDataLength, dataPayloadType);
 
     if (!m_loadingMultipartContent) {
-        if (auto* resourceData = this->resourceData())
-            m_resource->addDataBuffer(*resourceData);
+        if (ResourceBuffer* resourceData = this->resourceData())
+            m_resource->addDataBuffer(resourceData);
         else
             m_resource->addData(buffer ? buffer->data() : data, buffer ? buffer->size() : length);
     }
index 0f27b92..353cef2 100644 (file)
@@ -36,8 +36,8 @@
 #include "CrossOriginAccessControl.h"
 #include "Document.h"
 #include "Logging.h"
+#include "ResourceBuffer.h"
 #include "SecurityOrigin.h"
-#include "SharedBuffer.h"
 #include "VTTCue.h"
 #include "WebVTTParser.h"
 
@@ -87,7 +87,7 @@ void TextTrackLoader::processNewCueData(CachedResource* resource)
     if (m_state == Failed || !resource->resourceBuffer())
         return;
     
-    auto* buffer = resource->resourceBuffer();
+    ResourceBuffer* buffer = resource->resourceBuffer();
     if (m_parseOffset == buffer->size())
         return;
 
index e954a33..6342194 100644 (file)
@@ -41,6 +41,7 @@
 #include "InspectorInstrumentation.h"
 #include "ManifestParser.h"
 #include "Page.h"
+#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -253,8 +254,11 @@ void ApplicationCacheGroup::finishedLoadingMainResource(DocumentLoader* loader)
                 resource->addType(ApplicationCacheResource::Master);
                 ASSERT(!resource->storageID());
             }
-        } else
-            m_newestCache->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, loader->mainResourceData()));
+        } else {
+            RefPtr<ResourceBuffer> buffer = loader->mainResourceData();
+            m_newestCache->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, buffer ? buffer->sharedBuffer() : 0));
+        }
+
         break;
     case Failure:
         // Cache update has been a failure, so there is no reason to keep the document associated with the incomplete cache
@@ -272,8 +276,10 @@ void ApplicationCacheGroup::finishedLoadingMainResource(DocumentLoader* loader)
                 resource->addType(ApplicationCacheResource::Master);
                 ASSERT(!resource->storageID());
             }
-        } else
-            m_cacheBeingUpdated->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, loader->mainResourceData()));
+        } else {
+            RefPtr<ResourceBuffer> buffer = loader->mainResourceData();
+            m_cacheBeingUpdated->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, buffer ? buffer->sharedBuffer() : 0));
+        }
         // The "cached" event will be posted to all associated documents once update is complete.
         break;
     }
index 972346a..24cf4be 100644 (file)
@@ -46,6 +46,7 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "Range.h"
+#include "ResourceBuffer.h"
 #include "Settings.h"
 #include "markup.h"
 #include <wtf/ListHashSet.h>
@@ -549,7 +550,9 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
 #endif
                 CachedResource* cachedResource = memoryCache()->resourceForRequest(request, frame->page()->sessionID());
                 if (cachedResource) {
-                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(cachedResource->resourceBuffer(), subresourceURL, cachedResource->response())) {
+                    ResourceBuffer* data = cachedResource->resourceBuffer();
+
+                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(data ? data->sharedBuffer() : 0, subresourceURL, cachedResource->response())) {
                         subresources.append(WTF::move(resource));
                         continue;
                     }
index e370138..a2081be 100644 (file)
@@ -33,7 +33,7 @@
 #include "HTTPHeaderNames.h"
 #include "HTTPParsers.h"
 #include "MemoryCache.h"
-#include "SharedBuffer.h"
+#include "ResourceBuffer.h"
 #include "StyleSheetContents.h"
 #include "TextResourceDecoder.h"
 #include <wtf/CurrentTime.h>
@@ -90,13 +90,13 @@ const String CachedCSSStyleSheet::sheetText(bool enforceMIMEType, bool* hasValid
     return m_decoder->decodeAndFlush(m_data->data(), m_data->size());
 }
 
-void CachedCSSStyleSheet::finishLoading(SharedBuffer* data)
+void CachedCSSStyleSheet::finishLoading(ResourceBuffer* data)
 {
     m_data = data;
-    setEncodedSize(data ? data->size() : 0);
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
     // Decode the data to find out the encoding and keep the sheet text around during checkNotify()
-    if (data)
-        m_decodedSheetText = m_decoder->decodeAndFlush(data->data(), data->size());
+    if (m_data)
+        m_decodedSheetText = m_decoder->decodeAndFlush(m_data->data(), m_data->size());
     setLoading(false);
     checkNotify();
     // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.
index 940fd1f..80f994c 100644 (file)
@@ -54,7 +54,7 @@ namespace WebCore {
 
         virtual void setEncoding(const String&) override;
         virtual String encoding() const override;
-        virtual void finishLoading(SharedBuffer*) override;
+        virtual void finishLoading(ResourceBuffer*) override;
         virtual void destroyDecodedData() override;
 
     protected:
index 1ef622e..13682fa 100644 (file)
@@ -33,6 +33,7 @@
 #include "FontCustomPlatformData.h"
 #include "FontPlatformData.h"
 #include "MemoryCache.h"
+#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include "TypedElementDescendantIterator.h"
@@ -75,7 +76,7 @@ void CachedFont::didAddClient(CachedResourceClient* c)
         static_cast<CachedFontClient*>(c)->fontLoaded(this);
 }
 
-void CachedFont::finishLoading(SharedBuffer* data)
+void CachedFont::finishLoading(ResourceBuffer* data)
 {
     m_data = data;
     setEncodedSize(m_data.get() ? m_data->size() : 0);
@@ -94,27 +95,30 @@ void CachedFont::beginLoadIfNeeded(CachedResourceLoader* dl)
 bool CachedFont::ensureCustomFontData()
 {
     if (!m_fontData && !errorOccurred() && !isLoading() && m_data) {
-        RefPtr<SharedBuffer> buffer = m_data;
-        bool fontIsWOFF = false;
+        SharedBuffer* buffer = m_data.get()->sharedBuffer();
+        ASSERT(buffer);
 
+        bool fontIsWOFF = false;
 #if (!PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090) && (!PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED < 80000)
-        if (isWOFF(buffer.get())) {
-            Vector<char> convertedFont;
-            if (!convertWOFFToSfnt(buffer.get(), convertedFont))
+        RefPtr<SharedBuffer> sfntBuffer;
+
+        fontIsWOFF = isWOFF(buffer);
+        if (fontIsWOFF) {
+            Vector<char> sfnt;
+            if (convertWOFFToSfnt(buffer, sfnt)) {
+                sfntBuffer = SharedBuffer::adoptVector(sfnt);
+                buffer = sfntBuffer.get();
+            } else
                 buffer = nullptr;
-            else {
-                buffer = SharedBuffer::adoptVector(convertedFont);
-                fontIsWOFF = true;
-            }
         }
 #endif
 
         m_fontData = buffer ? createFontCustomPlatformData(*buffer) : nullptr;
-        m_hasCreatedFontDataWrappingResource = m_fontData && !fontIsWOFF;
-        if (!m_fontData)
+        if (m_fontData)
+            m_hasCreatedFontDataWrappingResource = !fontIsWOFF;
+        else
             setStatus(DecodeError);
     }
-
     return m_fontData.get();
 }
 
index 2a267cc..d943730 100644 (file)
@@ -63,7 +63,7 @@ private:
     virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&) override;
 
     virtual void didAddClient(CachedResourceClient*) override;
-    virtual void finishLoading(SharedBuffer*) override;
+    virtual void finishLoading(ResourceBuffer*) override;
 
     virtual void allClientsRemoved() override;
 
index db2ae97..b0fda18 100644 (file)
@@ -37,6 +37,7 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "RenderElement.h"
+#include "ResourceBuffer.h"
 #include "SVGImage.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -115,31 +116,31 @@ void CachedImage::load(CachedResourceLoader* cachedResourceLoader, const Resourc
         setLoading(false);
 }
 
-void CachedImage::didAddClient(CachedResourceClient* client)
+void CachedImage::didAddClient(CachedResourceClient* c)
 {
     if (m_data && !m_image && !errorOccurred()) {
         createImage();
-        m_image->setData(m_data, true);
+        m_image->setData(m_data->sharedBuffer(), true);
     }
     
-    ASSERT(client->resourceClientType() == CachedImageClient::expectedType());
+    ASSERT(c->resourceClientType() == CachedImageClient::expectedType());
     if (m_image && !m_image->isNull())
-        static_cast<CachedImageClient*>(client)->imageChanged(this);
+        static_cast<CachedImageClient*>(c)->imageChanged(this);
 
-    CachedResource::didAddClient(client);
+    CachedResource::didAddClient(c);
 }
 
-void CachedImage::didRemoveClient(CachedResourceClient* client)
+void CachedImage::didRemoveClient(CachedResourceClient* c)
 {
-    ASSERT(client);
-    ASSERT(client->resourceClientType() == CachedImageClient::expectedType());
+    ASSERT(c);
+    ASSERT(c->resourceClientType() == CachedImageClient::expectedType());
 
-    m_pendingContainerSizeRequests.remove(static_cast<CachedImageClient*>(client));
+    m_pendingContainerSizeRequests.remove(static_cast<CachedImageClient*>(c));
 
     if (m_svgImageCache)
-        m_svgImageCache->removeClientFromCache(static_cast<CachedImageClient*>(client));
+        m_svgImageCache->removeClientFromCache(static_cast<CachedImageClient*>(c));
 
-    CachedResource::didRemoveClient(client);
+    CachedResource::didRemoveClient(c);
 }
 
 void CachedImage::switchClientsToRevalidatedResource()
@@ -364,16 +365,18 @@ inline void CachedImage::clearImage()
     m_image.clear();
 }
 
-void CachedImage::addIncrementalDataBuffer(SharedBuffer& data)
+void CachedImage::addIncrementalDataBuffer(ResourceBuffer* data)
 {
-    m_data = &data;
+    m_data = data;
+    if (!data)
+        return;
 
     createImage();
 
     // Have the image update its data from its internal buffer.
     // It will not do anything now, but will delay decoding until
     // queried for info (like size or specific image frames).
-    bool sizeAvailable = m_image->setData(&data, false);
+    bool sizeAvailable = m_image->setData(m_data->sharedBuffer(), false);
     if (!sizeAvailable)
         return;
 
@@ -395,28 +398,26 @@ void CachedImage::addIncrementalDataBuffer(SharedBuffer& data)
     setEncodedSize(m_image->data() ? m_image->data()->size() : 0);
 }
 
-void CachedImage::addDataBuffer(SharedBuffer& data)
+void CachedImage::addDataBuffer(ResourceBuffer* data)
 {
-    ASSERT(dataBufferingPolicy() == BufferData);
+    ASSERT(m_options.dataBufferingPolicy() == BufferData);
     addIncrementalDataBuffer(data);
-    CachedResource::addDataBuffer(data);
 }
 
 void CachedImage::addData(const char* data, unsigned length)
 {
-    ASSERT(dataBufferingPolicy() == DoNotBufferData);
-    addIncrementalDataBuffer(*SharedBuffer::create(data, length));
-    CachedResource::addData(data, length);
+    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
+    addIncrementalDataBuffer(ResourceBuffer::create(data, length).get());
 }
 
-void CachedImage::finishLoading(SharedBuffer* data)
+void CachedImage::finishLoading(ResourceBuffer* data)
 {
     m_data = data;
     if (!m_image && data)
         createImage();
 
     if (m_image)
-        m_image->setData(data, true);
+        m_image->setData(m_data->sharedBuffer(), true);
 
     if (!m_image || m_image->isNull()) {
         // Image decoding failed; the image data is malformed.
index 56d2aa1..feef452 100644 (file)
@@ -71,8 +71,8 @@ public:
     bool imageHasRelativeWidth() const;
     bool imageHasRelativeHeight() const;
 
-    virtual void addDataBuffer(SharedBuffer&) override;
-    virtual void finishLoading(SharedBuffer*) override;
+    virtual void addDataBuffer(ResourceBuffer*) override;
+    virtual void finishLoading(ResourceBuffer*) override;
 
     enum SizeType {
         UsedSize,
@@ -94,7 +94,7 @@ private:
     void createImage();
     void clearImage();
     // If not null, changeRect is the changed part of the image.
-    void notifyObservers(const IntRect* changeRect = nullptr);
+    void notifyObservers(const IntRect* changeRect = 0);
     void checkShouldPaintBrokenImage();
 
     virtual void switchClientsToRevalidatedResource() override;
@@ -122,7 +122,7 @@ private:
     virtual void animationAdvanced(const Image*) override;
     virtual void changedInRect(const Image*, const IntRect&) override;
 
-    void addIncrementalDataBuffer(SharedBuffer&);
+    void addIncrementalDataBuffer(ResourceBuffer*);
 
     typedef std::pair<LayoutSize, float> SizeAndZoom;
     typedef HashMap<const CachedImageClient*, SizeAndZoom> ContainerSizeRequests;
@@ -130,8 +130,8 @@ private:
 
     RefPtr<Image> m_image;
     std::unique_ptr<SVGImageCache> m_svgImageCache;
-    unsigned m_isManuallyCached : 1;
-    unsigned m_shouldPaintBrokenImage : 1;
+    unsigned char m_isManuallyCached : 1;
+    unsigned char m_shouldPaintBrokenImage : 1;
 };
 
 } // namespace WebCore
index 833da66..5f28132 100644 (file)
@@ -30,7 +30,7 @@
 #include "CachedResourceClientWalker.h"
 #include "CachedResourceLoader.h"
 #include "HTTPHeaderNames.h"
-#include "SharedBuffer.h"
+#include "ResourceBuffer.h"
 #include "SubresourceLoader.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/text/StringView.h>
@@ -46,7 +46,7 @@ CachedRawResource::CachedRawResource(ResourceRequest& resourceRequest, Type type
     ASSERT(isMainOrRawResource());
 }
 
-const char* CachedRawResource::calculateIncrementalDataChunk(SharedBuffer* data, unsigned& incrementalDataLength)
+const char* CachedRawResource::calculateIncrementalDataChunk(ResourceBuffer* data, unsigned& incrementalDataLength)
 {
     incrementalDataLength = 0;
     if (!data)
@@ -58,37 +58,34 @@ const char* CachedRawResource::calculateIncrementalDataChunk(SharedBuffer* data,
     return data->data() + previousDataLength;
 }
 
-void CachedRawResource::addDataBuffer(SharedBuffer& data)
+void CachedRawResource::addDataBuffer(ResourceBuffer* data)
 {
     CachedResourceHandle<CachedRawResource> protect(this);
-    ASSERT(dataBufferingPolicy() == BufferData);
-    m_data = &data;
+    ASSERT(m_options.dataBufferingPolicy() == BufferData);
+    m_data = data;
 
     unsigned incrementalDataLength;
-    const char* incrementalData = calculateIncrementalDataChunk(&data, incrementalDataLength);
-    setEncodedSize(data.size());
+    const char* incrementalData = calculateIncrementalDataChunk(data, incrementalDataLength);
+    if (data)
+        setEncodedSize(data->size());
     notifyClientsDataWasReceived(incrementalData, incrementalDataLength);
-    if (dataBufferingPolicy() == DoNotBufferData) {
+    if (m_options.dataBufferingPolicy() == DoNotBufferData) {
         if (m_loader)
             m_loader->setDataBufferingPolicy(DoNotBufferData);
         clear();
-        return;
     }
-
-    CachedResource::addDataBuffer(data);
 }
 
 void CachedRawResource::addData(const char* data, unsigned length)
 {
-    ASSERT(dataBufferingPolicy() == DoNotBufferData);
+    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
     notifyClientsDataWasReceived(data, length);
-    CachedResource::addData(data, length);
 }
 
-void CachedRawResource::finishLoading(SharedBuffer* data)
+void CachedRawResource::finishLoading(ResourceBuffer* data)
 {
     CachedResourceHandle<CachedRawResource> protect(this);
-    DataBufferingPolicy dataBufferingPolicy = this->dataBufferingPolicy();
+    DataBufferingPolicy dataBufferingPolicy = m_options.dataBufferingPolicy();
     if (dataBufferingPolicy == BufferData) {
         m_data = data;
 
@@ -102,7 +99,7 @@ void CachedRawResource::finishLoading(SharedBuffer* data)
     m_allowEncodedDataReplacement = !m_loader->isQuickLookResource();
 
     CachedResource::finishLoading(data);
-    if (dataBufferingPolicy == BufferData && this->dataBufferingPolicy() == DoNotBufferData) {
+    if (dataBufferingPolicy == BufferData && m_options.dataBufferingPolicy() == DoNotBufferData) {
         if (m_loader)
             m_loader->setDataBufferingPolicy(DoNotBufferData);
         clear();
@@ -225,7 +222,7 @@ static bool shouldIgnoreHeaderForCacheReuse(HTTPHeaderName name)
 
 bool CachedRawResource::canReuse(const ResourceRequest& newRequest) const
 {
-    if (dataBufferingPolicy() == DoNotBufferData)
+    if (m_options.dataBufferingPolicy() == DoNotBufferData)
         return false;
 
     if (m_resourceRequest.httpMethod() != newRequest.httpMethod())
index 2cd455a..f3c668f 100644 (file)
@@ -48,9 +48,9 @@ public:
 
 private:
     virtual void didAddClient(CachedResourceClient*) override;
-    virtual void addDataBuffer(SharedBuffer&) override;
+    virtual void addDataBuffer(ResourceBuffer*) override;
     virtual void addData(const char* data, unsigned length) override;
-    virtual void finishLoading(SharedBuffer*) override;
+    virtual void finishLoading(ResourceBuffer*) override;
 
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const override { return true; }
     virtual void allClientsRemoved() override;
@@ -64,7 +64,7 @@ private:
 
     virtual bool canReuse(const ResourceRequest&) const override;
 
-    const char* calculateIncrementalDataChunk(SharedBuffer*, unsigned& incrementalDataLength);
+    const char* calculateIncrementalDataChunk(ResourceBuffer*, unsigned& incrementalDataLength);
     void notifyClientsDataWasReceived(const char* data, unsigned length);
 
 #if USE(SOUP)
index ceee58c..5a4e4a7 100644 (file)
@@ -40,6 +40,7 @@
 #include "Logging.h"
 #include "MemoryCache.h"
 #include "PlatformStrategies.h"
+#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "ResourceLoadScheduler.h"
 #include "SchemeRegistry.h"
@@ -107,10 +108,10 @@ DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Cac
 
 CachedResource::CachedResource(const ResourceRequest& request, Type type, SessionID sessionID)
     : m_resourceRequest(request)
-    , m_decodedDataDeletionTimer(this, &CachedResource::decodedDataDeletionTimerFired, deadDecodedDataDeletionIntervalForResourceType(type))
     , m_sessionID(sessionID)
     , m_loadPriority(defaultPriorityForResourceType(type))
     , m_responseTimestamp(currentTime())
+    , m_decodedDataDeletionTimer(this, &CachedResource::decodedDataDeletionTimerFired, deadDecodedDataDeletionIntervalForResourceType(type))
     , m_lastDecodedAccessTime(0)
     , m_loadFinishTime(0)
     , m_encodedSize(0)
@@ -285,22 +286,22 @@ void CachedResource::checkNotify()
     if (isLoading() || stillNeedsLoad())
         return;
 
-    CachedResourceClientWalker<CachedResourceClient> walker(m_clients);
-    while (CachedResourceClient* client = walker.next())
-        client->notifyFinished(this);
+    CachedResourceClientWalker<CachedResourceClient> w(m_clients);
+    while (CachedResourceClient* c = w.next())
+        c->notifyFinished(this);
 }
 
-void CachedResource::addDataBuffer(SharedBuffer&)
+void CachedResource::addDataBuffer(ResourceBuffer*)
 {
-    ASSERT(dataBufferingPolicy() == BufferData);
+    ASSERT(m_options.dataBufferingPolicy() == BufferData);
 }
 
 void CachedResource::addData(const char*, unsigned)
 {
-    ASSERT(dataBufferingPolicy() == DoNotBufferData);
+    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
 }
 
-void CachedResource::finishLoading(SharedBuffer*)
+void CachedResource::finishLoading(ResourceBuffer*)
 {
     setLoading(false);
     checkNotify();
@@ -390,15 +391,17 @@ void CachedResource::addClient(CachedResourceClient* client)
         didAddClient(client);
 }
 
-void CachedResource::didAddClient(CachedResourceClient* client)
+void CachedResource::didAddClient(CachedResourceClient* c)
 {
     if (m_decodedDataDeletionTimer.isActive())
         m_decodedDataDeletionTimer.stop();
 
-    if (m_clientsAwaitingCallback.remove(client))
-        m_clients.add(client);
+    if (m_clientsAwaitingCallback.contains(c)) {
+        m_clients.add(c);
+        m_clientsAwaitingCallback.remove(c);
+    }
     if (!isLoading() && !stillNeedsLoad())
-        client->notifyFinished(this);
+        c->notifyFinished(this);
 }
 
 bool CachedResource::addClientToSet(CachedResourceClient* client)
@@ -420,7 +423,7 @@ bool CachedResource::addClientToSet(CachedResourceClient* client)
         // Therefore, rather than immediately sending callbacks on a cache hit like other CachedResources,
         // we schedule the callbacks and ensure we never finish synchronously.
         ASSERT(!m_clientsAwaitingCallback.contains(client));
-        m_clientsAwaitingCallback.add(client, std::make_unique<Callback>(*this, *client));
+        m_clientsAwaitingCallback.add(client, CachedResourceCallback::schedule(this, client));
         return false;
     }
 
@@ -728,28 +731,27 @@ void CachedResource::setLoadPriority(ResourceLoadPriority loadPriority)
     m_loadPriority = loadPriority;
 }
 
-inline CachedResource::Callback::Callback(CachedResource& resource, CachedResourceClient& client)
+CachedResource::CachedResourceCallback::CachedResourceCallback(CachedResource* resource, CachedResourceClient* client)
     : m_resource(resource)
     , m_client(client)
-    , m_timer(this, &Callback::timerFired)
+    , m_callbackTimer(this, &CachedResourceCallback::timerFired)
 {
-    m_timer.startOneShot(0);
+    m_callbackTimer.startOneShot(0);
 }
 
-inline void CachedResource::Callback::cancel()
+void CachedResource::CachedResourceCallback::cancel()
 {
-    if (m_timer.isActive())
-        m_timer.stop();
+    if (m_callbackTimer.isActive())
+        m_callbackTimer.stop();
 }
 
-void CachedResource::Callback::timerFired(Timer<Callback>&)
+void CachedResource::CachedResourceCallback::timerFired(Timer<CachedResourceCallback>&)
 {
-    m_resource.didAddClient(&m_client);
+    m_resource->didAddClient(m_client);
 }
 
 #if USE(FOUNDATION)
-
-void CachedResource::tryReplaceEncodedData(SharedBuffer& newBuffer)
+void CachedResource::tryReplaceEncodedData(PassRefPtr<SharedBuffer> newBuffer)
 {
     if (!m_data)
         return;
@@ -760,12 +762,11 @@ void CachedResource::tryReplaceEncodedData(SharedBuffer& newBuffer)
     // We have to do the memcmp because we can't tell if the replacement file backed data is for the
     // same resource or if we made a second request with the same URL which gave us a different
     // resource. We have seen this happen for cached POST resources.
-    if (m_data->size() != newBuffer.size() || memcmp(m_data->data(), newBuffer.data(), m_data->size()))
+    if (m_data->size() != newBuffer->size() || memcmp(m_data->data(), newBuffer->data(), m_data->size()))
         return;
 
-    m_data->tryReplaceContentsWithPlatformBuffer(newBuffer);
+    m_data->tryReplaceSharedBufferContents(newBuffer.get());
 }
-
 #endif
 
 }
index bf6e997..9fb9b14 100644 (file)
@@ -47,6 +47,7 @@ class CachedResourceClient;
 class CachedResourceHandleBase;
 class CachedResourceLoader;
 class InspectorResource;
+class ResourceBuffer;
 class SecurityOrigin;
 class SharedBuffer;
 class SubresourceLoader;
@@ -95,9 +96,9 @@ public:
 
     virtual void setEncoding(const String&) { }
     virtual String encoding() const { return String(); }
-    virtual void addDataBuffer(SharedBuffer&);
+    virtual void addDataBuffer(ResourceBuffer*);
     virtual void addData(const char* data, unsigned length);
-    virtual void finishLoading(SharedBuffer*);
+    virtual void finishLoading(ResourceBuffer*);
     virtual void error(CachedResource::Status);
 
     void setResourceError(const ResourceError& error) { m_error = error; }
@@ -186,7 +187,7 @@ public:
     
     void clearLoader();
 
-    SharedBuffer* resourceBuffer() const { return m_data.get(); }
+    ResourceBuffer* resourceBuffer() const { return m_data.get(); }
 
     virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
     virtual void responseReceived(const ResourceResponse&);
@@ -244,35 +245,55 @@ public:
     virtual bool canReuse(const ResourceRequest&) const { return true; }
 
 #if USE(FOUNDATION)
-    WEBCORE_EXPORT void tryReplaceEncodedData(SharedBuffer&);
+    WEBCORE_EXPORT void tryReplaceEncodedData(PassRefPtr<SharedBuffer>);
 #endif
 
 #if USE(SOUP)
-    virtual char* getOrCreateReadBuffer(size_t /* requestedSize */, size_t& /* actualSize */) { return nullptr; }
+    virtual char* getOrCreateReadBuffer(size_t /* requestedSize */, size_t& /* actualSize */) { return 0; }
 #endif
 
 protected:
+    virtual void checkNotify();
+
     void setEncodedSize(unsigned);
     void setDecodedSize(unsigned);
     void didAccessDecodedData(double timeStamp);
 
-    // FIXME: Make the rest of these data members private and use functions in derived classes instead.
     HashCountedSet<CachedResourceClient*> m_clients;
+
+    class CachedResourceCallback {
+    public:
+        CachedResourceCallback(CachedResource*, CachedResourceClient*);
+
+        static std::unique_ptr<CachedResourceCallback> schedule(CachedResource* resource, CachedResourceClient* client) { return std::make_unique<CachedResourceCallback>(resource, client); }
+        void cancel();
+    private:
+        void timerFired(Timer<CachedResourceCallback>&);
+
+        CachedResource* m_resource;
+        CachedResourceClient* m_client;
+        Timer<CachedResourceCallback> m_callbackTimer;
+    };
+    HashMap<CachedResourceClient*, std::unique_ptr<CachedResourceCallback>> m_clientsAwaitingCallback;
+
     ResourceRequest m_resourceRequest;
+    SessionID m_sessionID;
+    String m_accept;
     RefPtr<SubresourceLoader> m_loader;
     ResourceLoaderOptions m_options;
+    ResourceLoadPriority m_loadPriority;
+
     ResourceResponse m_response;
-    RefPtr<SharedBuffer> m_data;
+    double m_responseTimestamp;
+
+    RefPtr<ResourceBuffer> m_data;
     DeferrableOneShotTimer m_decodedDataDeletionTimer;
 
 private:
-    class Callback;
-
     bool addClientToSet(CachedResourceClient*);
 
     void decodedDataDeletionTimerFired();
 
-    virtual void checkNotify();
     virtual bool mayTryReplaceEncodedData() const { return false; }
 
     double freshnessLifetime(const ResourceResponse&) const;
@@ -280,12 +301,6 @@ private:
     void addAdditionalRequestHeaders(CachedResourceLoader*);
     void failBeforeStarting();
 
-    HashMap<CachedResourceClient*, std::unique_ptr<Callback>> m_clientsAwaitingCallback;
-    SessionID m_sessionID;
-    String m_accept;
-    ResourceLoadPriority m_loadPriority;
-    double m_responseTimestamp;
-
     String m_fragmentIdentifierForRequest;
 
     ResourceError m_error;
@@ -323,7 +338,7 @@ private:
     CachedResource* m_nextInLiveResourcesList;
     CachedResource* m_prevInLiveResourcesList;
 
-    CachedResourceLoader* m_owningCachedResourceLoader; // only non-null for resources that are not in the cache
+    CachedResourceLoader* m_owningCachedResourceLoader; // only non-0 for resources that are not in the cache
     
     // If this field is non-null we are using the resource as a proxy for checking whether an existing resource is still up to date
     // using HTTP If-Modified-Since/If-None-Match headers. If the response is 304 all clients of this resource are moved
@@ -340,20 +355,6 @@ private:
     RedirectChainCacheStatus m_redirectChainCacheStatus;
 };
 
-class CachedResource::Callback {
-public:
-    Callback(CachedResource&, CachedResourceClient&);
-
-    void cancel();
-
-private:
-    void timerFired(Timer<Callback>&);
-
-    CachedResource& m_resource;
-    CachedResourceClient& m_client;
-    Timer<Callback> m_timer;
-};
-
 } // namespace WebCore
 
 #define SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(ToClassName, CachedResourceType) \
index 7595110..96933e1 100644 (file)
@@ -25,8 +25,9 @@
 #ifndef CachedResourceClient_h
 #define CachedResourceClient_h
 
-namespace WebCore {
+#include <wtf/FastMalloc.h>
 
+namespace WebCore {
 class CachedResource;
 
 class CachedResourceClient {
@@ -43,14 +44,13 @@ public:
     virtual ~CachedResourceClient() { }
     virtual void notifyFinished(CachedResource*) { }
     virtual void deprecatedDidReceiveCachedResource(CachedResource*) { }
-
+    
     static CachedResourceClientType expectedType() { return BaseResourceType; }
     virtual CachedResourceClientType resourceClientType() const { return expectedType(); }
 
 protected:
     CachedResourceClient() { }
 };
-
 }
 
 #endif
index a523020..32a61b3 100644 (file)
 #include "config.h"
 #include "CachedSVGDocument.h"
 
-#include "SharedBuffer.h"
+#include "CachedResourceClient.h"
+#include "CachedResourceHandle.h"
+#include "ResourceBuffer.h"
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -48,7 +51,7 @@ String CachedSVGDocument::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedSVGDocument::finishLoading(SharedBuffer* data)
+void CachedSVGDocument::finishLoading(ResourceBuffer* data)
 {
     if (data) {
         // We don't need to create a new frame because the new document belongs to the parent UseElement.
index a791cd8..c1c603f 100644 (file)
@@ -37,14 +37,15 @@ public:
 
     SVGDocument* document() const { return m_document.get(); }
 
+protected:
+    RefPtr<SVGDocument> m_document;
+    RefPtr<TextResourceDecoder> m_decoder;
+
 private:
     virtual bool mayTryReplaceEncodedData() const override { return true; }
     virtual void setEncoding(const String&) override;
     virtual String encoding() const override;
-    virtual void finishLoading(SharedBuffer*) override;
-
-    RefPtr<SVGDocument> m_document;
-    RefPtr<TextResourceDecoder> m_decoder;
+    virtual void finishLoading(ResourceBuffer*) override;
 };
 
 } // namespace WebCore
index f8bc33c..f71a5e8 100644 (file)
@@ -33,8 +33,8 @@
 #include "HTTPParsers.h"
 #include "MIMETypeRegistry.h"
 #include "MemoryCache.h"
+#include "ResourceBuffer.h"
 #include "RuntimeApplicationChecks.h"
-#include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Vector.h>
 
@@ -76,13 +76,14 @@ const String& CachedScript::script()
         setDecodedSize(m_script.sizeInBytes());
     }
     m_decodedDataDeletionTimer.restart();
+    
     return m_script;
 }
 
-void CachedScript::finishLoading(SharedBuffer* data)
+void CachedScript::finishLoading(ResourceBuffer* data)
 {
     m_data = data;
-    setEncodedSize(data ? data->size() : 0);
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
     CachedResource::finishLoading(data);
 }
 
index 938e918..91c986a 100644 (file)
 
 namespace WebCore {
 
-class TextResourceDecoder;
+    class CachedResourceLoader;
+    class TextResourceDecoder;
 
-class CachedScript final : public CachedResource {
-public:
-    CachedScript(const ResourceRequest&, const String& charset, SessionID);
-    virtual ~CachedScript();
+    class CachedScript final : public CachedResource {
+    public:
+        CachedScript(const ResourceRequest&, const String& charset, SessionID);
+        virtual ~CachedScript();
 
-    const String& script();
+        const String& script();
 
-    String mimeType() const;
+        String mimeType() const;
 
 #if ENABLE(NOSNIFF)
-    bool mimeTypeAllowedByNosniff() const;
+        bool mimeTypeAllowedByNosniff() const;
 #endif
 
-private:
-    virtual bool mayTryReplaceEncodedData() const override { return true; }
+    private:
+        virtual bool mayTryReplaceEncodedData() const override { return true; }
 
-    virtual bool shouldIgnoreHTTPStatusCodeErrors() const override;
+        virtual bool shouldIgnoreHTTPStatusCodeErrors() const override;
 
-    virtual void setEncoding(const String&) override;
-    virtual String encoding() const override;
-    virtual void finishLoading(SharedBuffer*) override;
+        virtual void setEncoding(const String&) override;
+        virtual String encoding() const override;
+        virtual void finishLoading(ResourceBuffer*) override;
 
-    virtual void destroyDecodedData() override;
+        virtual void destroyDecodedData() override;
 
-    String m_script;
-    RefPtr<TextResourceDecoder> m_decoder;
-};
+        String m_script;
+        RefPtr<TextResourceDecoder> m_decoder;
+    };
 
 } // namespace WebCore
 
index 7155922..709fad8 100644 (file)
@@ -32,6 +32,7 @@
 #include "CachedResourceClient.h"
 #include "CachedResourceClientWalker.h"
 #include "CachedResourceLoader.h"
+#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Vector.h>
@@ -43,26 +44,24 @@ CachedTextTrack::CachedTextTrack(const ResourceRequest& resourceRequest, Session
 {
 }
 
-void CachedTextTrack::updateData(SharedBuffer* data)
+CachedTextTrack::~CachedTextTrack()
 {
-    ASSERT(dataBufferingPolicy() == BufferData);
+}
+
+void CachedTextTrack::addDataBuffer(ResourceBuffer* data)
+{
+    ASSERT(m_options.dataBufferingPolicy() == BufferData);
     m_data = data;
-    setEncodedSize(data ? data->size() : 0);
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
 
     CachedResourceClientWalker<CachedResourceClient> walker(m_clients);
-    while (CachedResourceClientclient = walker.next())
+    while (CachedResourceClient *client = walker.next())
         client->deprecatedDidReceiveCachedResource(this);
 }
 
-void CachedTextTrack::addDataBuffer(SharedBuffer& data)
-{
-    updateData(&data);
-    CachedResource::addDataBuffer(data);
-}
-
-void CachedTextTrack::finishLoading(SharedBuffer* data)
+void CachedTextTrack::finishLoading(ResourceBuffer* data)
 {
-    updateData(data);
+    addDataBuffer(data);
     CachedResource::finishLoading(data);
 }
 
index 3c1127e..4c3f38a 100644 (file)
@@ -36,13 +36,12 @@ namespace WebCore {
 class CachedTextTrack final : public CachedResource {
 public:
     CachedTextTrack(const ResourceRequest&, SessionID);
+    virtual ~CachedTextTrack();
 
 private:
     virtual bool mayTryReplaceEncodedData() const override { return true; }
-    virtual void addDataBuffer(SharedBuffer&) override;
-    virtual void finishLoading(SharedBuffer*) override;
-
-    void updateData(SharedBuffer*);
+    virtual void addDataBuffer(ResourceBuffer*) override;
+    virtual void finishLoading(ResourceBuffer*) override;
 };
 
 } // namespace WebCore
index 77952b8..66f1ec5 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "CachedResourceClientWalker.h"
 #include "CachedStyleSheetClient.h"
-#include "SharedBuffer.h"
+#include "ResourceBuffer.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Vector.h>
 
@@ -46,10 +46,6 @@ CachedXSLStyleSheet::CachedXSLStyleSheet(const ResourceRequest& resourceRequest,
     setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
 }
 
-CachedXSLStyleSheet::~CachedXSLStyleSheet()
-{
-}
-
 void CachedXSLStyleSheet::didAddClient(CachedResourceClient* c)
 {  
     ASSERT(c->resourceClientType() == CachedStyleSheetClient::expectedType());
@@ -67,12 +63,12 @@ String CachedXSLStyleSheet::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedXSLStyleSheet::finishLoading(SharedBuffer* data)
+void CachedXSLStyleSheet::finishLoading(ResourceBuffer* data)
 {
     m_data = data;
-    setEncodedSize(data ? data->size() : 0);
-    if (data)
-        m_sheet = m_decoder->decodeAndFlush(data->data(), encodedSize());
+    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    if (m_data.get())
+        m_sheet = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
     setLoading(false);
     checkNotify();
 }
index 0e00e67..d9921c2 100644 (file)
 #if ENABLE(XSLT)
 
 #include "CachedResource.h"
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
-class TextResourceDecoder;
+    class CachedResourceLoader;
+    class TextResourceDecoder;
 
-class CachedXSLStyleSheet final : public CachedResource {
-public:
-    CachedXSLStyleSheet(const ResourceRequest&, SessionID);
-    virtual ~CachedXSLStyleSheet();
+    class CachedXSLStyleSheet final : public CachedResource {
+    public:
+        CachedXSLStyleSheet(const ResourceRequest&, SessionID);
 
-    const String& sheet() const { return m_sheet; }
+        const String& sheet() const { return m_sheet; }
 
-private:
-    virtual void checkNotify() override;
-    virtual bool mayTryReplaceEncodedData() const override { return true; }
-    virtual void didAddClient(CachedResourceClient*) override;
-    virtual void setEncoding(const String&) override;
-    virtual String encoding() const override;
-    virtual void finishLoading(SharedBuffer*) override;
+    protected:
+        virtual void checkNotify() override;
 
-    String m_sheet;
-    RefPtr<TextResourceDecoder> m_decoder;
-};
+        String m_sheet;
+        RefPtr<TextResourceDecoder> m_decoder;
+
+    private:
+        virtual bool mayTryReplaceEncodedData() const override { return true; }
+
+        virtual void didAddClient(CachedResourceClient*) override;
+
+        virtual void setEncoding(const String&) override;
+        virtual String encoding() const override;
+        virtual void finishLoading(ResourceBuffer*) override;
+    };
 
 } // namespace WebCore
 
index 69e2997..5767604 100644 (file)
@@ -51,8 +51,8 @@ void SubresourceLoader::didReceiveDataArray(CFArrayRef dataArray)
             // being cancelled. Bail out if we no longer have a cached resource.
             if (!m_resource)
                 return;
-            if (auto* resourceData = this->resourceData())
-                m_resource->addDataBuffer(*resourceData);
+            if (ResourceBuffer* resourceData = this->resourceData())
+                m_resource->addDataBuffer(resourceData);
             else {
                 CFDataRef cfData = reinterpret_cast<CFDataRef>(CFArrayGetValueAtIndex(dataArray, i));
                 const char* data = reinterpret_cast<const char *>(CFDataGetBytePtr(cfData));
index a3539b8..f12e399 100644 (file)
@@ -45,7 +45,7 @@ public:
 protected:
     WEBCORE_EXPORT DiskCacheMonitor(const ResourceRequest&, SessionID, CFCachedURLResponseRef);
 
-    virtual void resourceBecameFileBacked(SharedBuffer&);
+    virtual void resourceBecameFileBacked(PassRefPtr<SharedBuffer>);
 
     const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
     SessionID sessionID() const { return m_sessionID; }
index 1c1bd5e..ca608f7 100644 (file)
@@ -103,7 +103,7 @@ DiskCacheMonitor::DiskCacheMonitor(const ResourceRequest& request, SessionID ses
         if (!fileBackedBuffer)
             return;
 
-        monitor->resourceBecameFileBacked(*fileBackedBuffer);
+        monitor->resourceBecameFileBacked(fileBackedBuffer);
     };
 
 #if USE(WEB_THREAD)
@@ -121,7 +121,7 @@ DiskCacheMonitor::DiskCacheMonitor(const ResourceRequest& request, SessionID ses
     _CFCachedURLResponseSetBecameFileBackedCallBackBlock(cachedResponse, blockToRun, dispatch_get_main_queue());
 }
 
-void DiskCacheMonitor::resourceBecameFileBacked(SharedBuffer& fileBackedBuffer)
+void DiskCacheMonitor::resourceBecameFileBacked(PassRefPtr<SharedBuffer> fileBackedBuffer)
 {
     CachedResource* resource = memoryCache()->resourceForRequest(m_resourceRequest, m_sessionID);
     if (!resource)
index 56921cd..5402eb0 100644 (file)
@@ -37,6 +37,7 @@
 #include "IconController.h"
 #include "IconDatabase.h"
 #include "Logging.h"
+#include "ResourceBuffer.h"
 #include "ResourceRequest.h"
 #include "SharedBuffer.h"
 #include <wtf/text/CString.h>
@@ -84,16 +85,16 @@ void IconLoader::notifyFinished(CachedResource* resource)
 
     // If we got a status code indicating an invalid response, then lets
     // ignore the data and not try to decode the error page as an icon.
-    auto* data = resource->resourceBuffer();
+    RefPtr<ResourceBuffer> data = resource->resourceBuffer();
     int status = resource->response().httpStatusCode();
     if (status && (status < 200 || status > 299))
-        data = nullptr;
+        data = 0;
 
     static const char pdfMagicNumber[] = "%PDF";
     static unsigned pdfMagicNumberLength = sizeof(pdfMagicNumber) - 1;
     if (data && data->size() >= pdfMagicNumberLength && !memcmp(data->data(), pdfMagicNumber, pdfMagicNumberLength)) {
         LOG(IconDatabase, "IconLoader::finishLoading() - Ignoring icon at %s because it appears to be a PDF", resource->url().string().ascii().data());
-        data = nullptr;
+        data = 0;
     }
 
     LOG(IconDatabase, "IconLoader::finishLoading() - Committing iconURL %s to database", resource->url().string().ascii().data());
@@ -101,7 +102,7 @@ void IconLoader::notifyFinished(CachedResource* resource)
     // Setting the icon data only after committing to the database ensures that the data is
     // kept in memory (so it does not have to be read from the database asynchronously), since
     // there is a page URL referencing it.
-    iconDatabase().setIconDataForIconURL(data, resource->url().string());
+    iconDatabase().setIconDataForIconURL(data ? data->sharedBuffer() : 0, resource->url().string());
     m_frame.loader().client().dispatchDidReceiveIcon();
     stopLoading();
 }
diff --git a/Source/WebCore/loader/mac/ResourceBuffer.mm b/Source/WebCore/loader/mac/ResourceBuffer.mm
new file mode 100644 (file)
index 0000000..54cf9b7
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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 "ResourceBuffer.h"
+
+#include "SharedBuffer.h"
+
+namespace WebCore {
+
+RetainPtr<NSData> ResourceBuffer::createNSData()
+{
+    return m_sharedBuffer->createNSData();
+}
+
+void ResourceBuffer::tryReplaceSharedBufferContents(SharedBuffer* newContents)
+{
+    if (!m_sharedBuffer)
+        m_sharedBuffer = newContents;
+    else
+        m_sharedBuffer->tryReplaceContentsWithPlatformBuffer(newContents);
+}
+
+} // namespace WebCore
index 3ecd597..a015e98 100644 (file)
 
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
-#include "SharedBuffer.h"
 
 #if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
 #include "InspectorInstrumentation.h"
+#include "ResourceBuffer.h"
 #endif
 
 #if USE(CFNETWORK)
@@ -83,7 +83,7 @@ void ResourceLoader::didReceiveDataArray(CFArrayRef dataArray)
 
         if (m_options.dataBufferingPolicy() == BufferData) {
             if (!m_resourceData)
-                m_resourceData = SharedBuffer::create();
+                m_resourceData = ResourceBuffer::create();
             m_resourceData->append(data);
         }
 
index 06bdb38..a1612db 100644 (file)
@@ -33,7 +33,6 @@
 namespace WebCore {
 
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-
 static const unsigned segmentSize = 0x1000;
 static const unsigned segmentPositionMask = 0x0FFF;
 
@@ -57,7 +56,6 @@ static inline void freeSegment(char* p)
 {
     fastFree(p);
 }
-
 #endif
 
 SharedBuffer::SharedBuffer()
@@ -216,8 +214,9 @@ void SharedBuffer::clear()
     clearPlatformData();
     
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-    for (char* segment : m_segments)
-        freeSegment(segment);
+    for (unsigned i = 0; i < m_segments.size(); ++i)
+        freeSegment(m_segments[i]);
+
     m_segments.clear();
 #else
     m_dataArray.clear();
@@ -227,26 +226,24 @@ void SharedBuffer::clear()
     clearDataBuffer();
 }
 
-PassRef<SharedBuffer> SharedBuffer::copy() const
+PassRefPtr<SharedBuffer> SharedBuffer::copy() const
 {
-    PassRef<SharedBuffer> clone { adoptRef(*new SharedBuffer) };
+    RefPtr<SharedBuffer> clone(adoptRef(new SharedBuffer));
     if (hasPlatformData()) {
-        clone.get().append(data(), size());
+        clone->append(data(), size());
         return clone;
     }
 
-    clone.get().m_size = m_size;
-    clone.get().m_buffer->data.reserveCapacity(m_size);
-    clone.get().m_buffer->data.append(m_buffer->data.data(), m_buffer->data.size());
-
+    clone->m_size = m_size;
+    clone->m_buffer->data.reserveCapacity(m_size);
+    clone->m_buffer->data.append(m_buffer->data.data(), m_buffer->data.size());
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-    for (char* segment : m_segments)
-        clone.get().m_buffer->data.append(segment, segmentSize);
+    for (unsigned i = 0; i < m_segments.size(); ++i)
+        clone->m_buffer->data.append(m_segments[i], segmentSize);
 #else
-    for (auto& data : m_dataArray)
-        clone.get().append(data.get());
+    for (unsigned i = 0; i < m_dataArray.size(); ++i)
+        clone->append(m_dataArray[i].get());
 #endif
-
     return clone;
 }
 
@@ -278,19 +275,17 @@ void SharedBuffer::clearDataBuffer()
 }
 
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-
 void SharedBuffer::copyBufferAndClear(char* destination, unsigned bytesToCopy) const
 {
-    for (char* segment : m_segments) {
+    for (unsigned i = 0; i < m_segments.size(); ++i) {
         unsigned effectiveBytesToCopy = std::min(bytesToCopy, segmentSize);
-        memcpy(destination, segment, effectiveBytesToCopy);
+        memcpy(destination, m_segments[i], effectiveBytesToCopy);
         destination += effectiveBytesToCopy;
         bytesToCopy -= effectiveBytesToCopy;
-        freeSegment(segment);
+        freeSegment(m_segments[i]);
     }
     m_segments.clear();
 }
-
 #endif
 
 const Vector<char>& SharedBuffer::buffer() const
index f59129a..ccb029d 100644 (file)
@@ -102,7 +102,7 @@ public:
     void append(CFDataRef);
 #endif
 
-    PassRef<SharedBuffer> copy() const;
+    PassRefPtr<SharedBuffer> copy() const;
     
     // Return the number of consecutive bytes after "position". "data"
     // points to the first byte.
@@ -118,7 +118,7 @@ public:
     //      }
     WEBCORE_EXPORT unsigned getSomeData(const char*& data, unsigned position = 0) const;
 
-    void tryReplaceContentsWithPlatformBuffer(SharedBuffer&);
+    void tryReplaceContentsWithPlatformBuffer(SharedBuffer*);
     WEBCORE_EXPORT bool hasPlatformData() const;
 
     struct DataBuffer : public ThreadSafeRefCounted<DataBuffer> {
@@ -158,7 +158,6 @@ private:
 #else
     mutable Vector<char*> m_segments;
 #endif
-
 #if USE(CF)
     explicit SharedBuffer(CFDataRef);
     RetainPtr<CFDataRef> m_cfData;
index bbf185e..567707b 100644 (file)
@@ -92,13 +92,13 @@ void SharedBuffer::clearPlatformData()
     m_cfData = 0;
 }
 
-void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer& newContents)
+void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer* newContents)
 {
-    if (!newContents.m_cfData)
+    if (!newContents->m_cfData)
         return;
 
     clear();
-    m_cfData = newContents.m_cfData;
+    m_cfData = newContents->m_cfData;
 }
 
 bool SharedBuffer::maybeAppendPlatformData(SharedBuffer* newContents)
index 532ac84..5891d8c 100644 (file)
@@ -27,7 +27,6 @@
 #define PlatformMediaResourceLoader_h
 
 #if ENABLE(VIDEO)
-
 #include <wtf/Noncopyable.h>
 #include <wtf/RefCounted.h>
 
@@ -36,6 +35,7 @@ namespace WebCore {
 class ResourceError;
 class ResourceRequest;
 class ResourceResponse;
+class SharedBuffer;
 
 class PlatformMediaResourceLoaderClient {
 public:
@@ -43,9 +43,10 @@ public:
 
     virtual void responseReceived(const ResourceResponse&) { }
     virtual void dataReceived(const char*, int) { }
+    virtual void bufferReceived(SharedBuffer*) { }
     virtual void accessControlCheckFailed(const ResourceError&) { }
     virtual void loadFailed(const ResourceError&) { }
-    virtual void loadFinished() { }
+    virtual void loadFinished(SharedBuffer*) { }
 #if USE(SOUP)
     virtual char* getOrCreateReadBuffer(size_t /*requestedSize*/, size_t& /*actualSize*/) { return nullptr; };
 #endif
@@ -67,7 +68,7 @@ public:
     virtual bool didPassAccessControlCheck() const { return false; }
 
 protected:
-    explicit PlatformMediaResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
+    PlatformMediaResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
         : m_client(WTF::move(client))
     {
     }
index 972d613..5f4bb97 100644 (file)
@@ -33,6 +33,7 @@
 #include "CachedResourceRequest.h"
 #include "MediaPlayerPrivateAVFoundationCF.h"
 #include "NotImplemented.h"
+#include "ResourceBuffer.h"
 #include "ResourceLoaderOptions.h"
 #include "SharedBuffer.h"
 #include "SoftLinking.h"
index 3e65a51..f20e6a0 100644 (file)
@@ -32,6 +32,7 @@
 #import "CachedResourceLoader.h"
 #import "CachedResourceRequest.h"
 #import "MediaPlayerPrivateAVFoundationObjC.h"
+#import "ResourceBuffer.h"
 #import "ResourceLoaderOptions.h"
 #import "SharedBuffer.h"
 #import "SoftLinking.h"
@@ -151,7 +152,7 @@ void WebCoreAVFResourceLoader::fulfillRequestWithResource(CachedResource* resour
     if (!dataRequest)
         return;
 
-    SharedBuffer* data = resource->resourceBuffer();
+    SharedBuffer* data = resource->resourceBuffer() ? resource->resourceBuffer()->sharedBuffer() : 0;
     if (!data)
         return;
 
index 12fdeba..f9d7991 100644 (file)
@@ -74,7 +74,7 @@ class CachedResourceStreamingClient final : public PlatformMediaResourceLoaderCl
         virtual void dataReceived(const char*, int) override;
         virtual void accessControlCheckFailed(const ResourceError&) override;
         virtual void loadFailed(const ResourceError&) override;
-        virtual void loadFinished() override;
+        virtual void loadFinished(SharedBuffer*) override;
 };
 
 class ResourceHandleStreamingClient : public ResourceHandleClient, public StreamingClient {
@@ -1031,7 +1031,7 @@ void CachedResourceStreamingClient::loadFailed(const ResourceError& error)
     gst_app_src_end_of_stream(src->priv->appsrc);
 }
 
-void CachedResourceStreamingClient::loadFinished()
+void CachedResourceStreamingClient::loadFinished(SharedBuffer*)
 {
     handleNotifyFinished();
 }
index 501a38c..cea9048 100644 (file)
@@ -51,6 +51,7 @@
 #import "PasteboardStrategy.h"
 #import "PlatformStrategies.h"
 #import "RenderImage.h"
+#import "ResourceBuffer.h"
 #import "Text.h"
 #import "WebCoreNSStringExtras.h"
 #import "WebNSAttributedStringExtras.h"
index 29bcdb7..37772fe 100644 (file)
@@ -44,6 +44,11 @@ void SharedBuffer::clearPlatformData()
     m_soupBuffer.reset();
 }
 
+void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer*)
+{
+    ASSERT_NOT_REACHED();
+}
+
 void SharedBuffer::maybeTransferPlatformData()
 {
     if (!m_soupBuffer)
index 3c332bb..e61d11d 100644 (file)
@@ -1,3 +1,23 @@
+2014-11-03  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r175406, r175413, and r175423.
+        https://bugs.webkit.org/show_bug.cgi?id=138327
+
+        Multipart tests are still broken (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        "Eliminate ResourceBuffer and use SharedBuffer directly
+        instead"
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+        http://trac.webkit.org/changeset/175406
+
+        "Unreviewed, iOS build fix since 175406."
+        http://trac.webkit.org/changeset/175413
+
+        "Fix assertion in CachedResource::addDataBuffer"
+        http://trac.webkit.org/changeset/175423
+
 2014-10-31  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Use std::unique_ptr for TypeCountSet
index ddb8b62..b022c71 100644 (file)
@@ -53,6 +53,7 @@
 #import <WebCore/URL.h>
 #import <WebCore/LegacyWebArchive.h>
 #import <WebCore/MIMETypeRegistry.h>
+#import <WebCore/ResourceBuffer.h>
 #import <WebCore/ResourceRequest.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/WebCoreObjCExtras.h>
@@ -458,7 +459,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
 
 - (NSData *)data
 {
-    RefPtr<SharedBuffer> mainResourceData = toPrivate(_private)->loader->mainResourceData();
+    RefPtr<ResourceBuffer> mainResourceData = toPrivate(_private)->loader->mainResourceData();
     if (!mainResourceData)
         return nil;
     return mainResourceData->createNSData().autorelease();
index 944c5c8..0863bde 100644 (file)
 #import <WebCore/Range.h>
 #import <WebCore/RenderView.h>
 #import <WebCore/RenderWidget.h>
+#import <WebCore/ResourceBuffer.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/SimpleFontData.h>
@@ -3954,7 +3955,7 @@ static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension
     NSURL *draggingImageURL = nil;
     
     if (WebCore::CachedImage* tiffResource = [self promisedDragTIFFDataSource]) {
-        if (auto* buffer = tiffResource->resourceBuffer()) {
+        if (ResourceBuffer *buffer = static_cast<CachedResource*>(tiffResource)->resourceBuffer()) {
             NSURLResponse *response = tiffResource->response().nsURLResponse();
             draggingImageURL = [response URL];
             wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().get()] autorelease];
index 3e14775..b8c418f 100644 (file)
@@ -1,3 +1,23 @@
+2014-11-03  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r175406, r175413, and r175423.
+        https://bugs.webkit.org/show_bug.cgi?id=138327
+
+        Multipart tests are still broken (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        "Eliminate ResourceBuffer and use SharedBuffer directly
+        instead"
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+        http://trac.webkit.org/changeset/175406
+
+        "Unreviewed, iOS build fix since 175406."
+        http://trac.webkit.org/changeset/175413
+
+        "Fix assertion in CachedResource::addDataBuffer"
+        http://trac.webkit.org/changeset/175423
+
 2014-11-03  Sungmann Cho  <sungmann.cho@navercorp.com>
 
         AX: Fix some minor typos related to the word "accessibility".
index 9074519..4fbd996 100644 (file)
@@ -45,6 +45,7 @@
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/URL.h>
+#include <WebCore/ResourceBuffer.h>
 
 using namespace WebCore;
 
@@ -180,7 +181,8 @@ HRESULT STDMETHODCALLTYPE WebDataSource::data(
     if (!m_loader)
         return E_FAIL;
 
-    return MemoryStream::createInstance(m_loader->mainResourceData()).copyRefTo(stream);
+    RefPtr<ResourceBuffer> buffer = m_loader->mainResourceData();
+    return MemoryStream::createInstance(buffer ? buffer->sharedBuffer() : 0).copyRefTo(stream);
 }
 
 HRESULT WebDataSource::representation(/* [retval][out] */ IWebDocumentRepresentation** rep)
@@ -301,7 +303,8 @@ HRESULT STDMETHODCALLTYPE WebDataSource::subresourceForURL(
     if (!cachedResource)
         return E_FAIL;
 
-    *resource = WebResource::createInstance(cachedResource->resourceBuffer(), cachedResource->response());
+    ResourceBuffer* buffer = cachedResource->resourceBuffer();
+    *resource = WebResource::createInstance(buffer ? buffer->sharedBuffer() : 0, cachedResource->response());
     return S_OK;
 }
 
index 0be2882..dfdb80c 100644 (file)
@@ -235,6 +235,7 @@ set(WebKit2_SOURCES
     Shared/WebProcessCreationParameters.cpp
     Shared/WebRenderLayer.cpp
     Shared/WebRenderObject.cpp
+    Shared/WebResourceBuffer.cpp
     Shared/WebTouchEvent.cpp
     Shared/WebWheelEvent.cpp
 
index 32653f2..041da69 100644 (file)
@@ -1,3 +1,23 @@
+2014-11-03  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r175406, r175413, and r175423.
+        https://bugs.webkit.org/show_bug.cgi?id=138327
+
+        Multipart tests are still broken (Requested by ap on #webkit).
+
+        Reverted changesets:
+
+        "Eliminate ResourceBuffer and use SharedBuffer directly
+        instead"
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+        http://trac.webkit.org/changeset/175406
+
+        "Unreviewed, iOS build fix since 175406."
+        http://trac.webkit.org/changeset/175413
+
+        "Fix assertion in CachedResource::addDataBuffer"
+        http://trac.webkit.org/changeset/175423
+
 2014-11-03  Tim Horton  <timothy_horton@apple.com>
 
         _actionMenuItemsForHitTestResult is given kWKActionMenuLink but an empty array of defaultMenuItems
index 8e3e258..954bba4 100644 (file)
@@ -45,6 +45,7 @@
 #include <WebCore/BlobDataFileReference.h>
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/NotImplemented.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceHandle.h>
 #include <WebCore/SharedBuffer.h>
 #include <WebCore/SynchronousLoaderClient.h>
@@ -408,20 +409,18 @@ void NetworkResourceLoader::bufferingTimerFired(Timer<NetworkResourceLoader>&)
 
 void NetworkResourceLoader::sendBuffer(WebCore::SharedBuffer* buffer, int encodedDataLength)
 {
-    ASSERT(buffer);
     ASSERT(!isSynchronous());
 
 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
     ShareableResource::Handle shareableResourceHandle;
-    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(shareableResourceHandle, *buffer);
+    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(shareableResourceHandle, buffer);
     if (!shareableResourceHandle.isNull()) {
-        // Since we're delivering this resource by ourselves all at once and don't need any more data or callbacks from the network layer, abort the loader.
+        // Since we're delivering this resource by ourselves all at once and don't need anymore data or callbacks from the network layer, abort the loader.
         abort();
         send(Messages::WebResourceLoader::DidReceiveResource(shareableResourceHandle, currentTime()));
         return;
     }
 #endif
-
     IPC::SharedBufferDataReference dataReference(buffer);
     sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveData(dataReference, encodedDataLength));
 }
index 9cee861..273e131 100644 (file)
@@ -46,6 +46,7 @@ typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
 
 namespace WebCore {
 class BlobDataFileReference;
+class ResourceBuffer;
 class ResourceHandle;
 class ResourceRequest;
 }
@@ -91,7 +92,7 @@ public:
 
 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
     static void tryGetShareableHandleFromCFURLCachedResponse(ShareableResource::Handle&, CFCachedURLResponseRef);
-    static void tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle&, WebCore::SharedBuffer&);
+    static void tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle&, WebCore::SharedBuffer*);
 #endif
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
index 583cedb..bd8c0b0 100644 (file)
@@ -48,7 +48,7 @@ private:
     NetworkDiskCacheMonitor(CFCachedURLResponseRef, NetworkResourceLoader*);
 
     // WebCore::DiskCacheMonitor
-    virtual void resourceBecameFileBacked(WebCore::SharedBuffer&) override;
+    virtual void resourceBecameFileBacked(PassRefPtr<WebCore::SharedBuffer>) override;
 
     // IPC::MessageSender
     virtual IPC::Connection* messageSenderConnection() override;
index 551d076..a23c58b 100644 (file)
@@ -59,10 +59,10 @@ NetworkDiskCacheMonitor::NetworkDiskCacheMonitor(CFCachedURLResponseRef cachedRe
 {
 }
 
-void NetworkDiskCacheMonitor::resourceBecameFileBacked(SharedBuffer& fileBackedBuffer)
+void NetworkDiskCacheMonitor::resourceBecameFileBacked(PassRefPtr<SharedBuffer> fileBackedBuffer)
 {
     ShareableResource::Handle handle;
-    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(handle, fileBackedBuffer);
+    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(handle, fileBackedBuffer.get());
     if (handle.isNull())
         return;
 
index e1337d0..43aee0a 100644 (file)
@@ -84,7 +84,7 @@ void NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse(Shareab
     tryGetShareableHandleFromCFData(handle, data);
 }
 
-void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle& handle, SharedBuffer& buffer)
+void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle& handle, SharedBuffer* buffer)
 {
     static CFURLCacheRef cache = CFURLCacheCopySharedURLCache();
     ASSERT(isMainThread());
@@ -93,7 +93,7 @@ void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResou
     if (!cache)
         return;
 
-    CFDataRef data = buffer.existingCFData();
+    CFDataRef data = buffer->existingCFData();
     if (!data)
         return;
 
@@ -102,8 +102,7 @@ void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResou
 
     tryGetShareableHandleFromCFData(handle, data);
 }
-
-#endif // IOS || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
 size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
 {
@@ -111,7 +110,6 @@ size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
 }
 
 #if USE(CFNETWORK)
-
 void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, CFCachedURLResponseRef cfResponse)
 {
     ASSERT_UNUSED(handle, handle == m_handle);
@@ -135,7 +133,6 @@ void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCac
 
     m_handle->continueWillCacheResponse(nsResponse);
 }
-
 #endif // !USE(CFNETWORK)
 
 } // namespace WebKit
index e6806b0..4f8f48d 100644 (file)
@@ -83,27 +83,21 @@ private:
     size_t m_size;
 };
 
-class SharedBufferDataReference : public DataReference {
+class SharedBufferDataReference: public DataReference {
 public:
-    // FIXME: This class doesn't handle null, so the argument should be a reference or PassRef.
     SharedBufferDataReference(WebCore::SharedBuffer* buffer)
-        : m_buffer(buffer)
     {
+        m_buffer = buffer;
     }
 
-private:
-    // FIXME: It is a bad idea to violate the Liskov Substitution Principle as we do here.
-    // Since we are using DataReference as a polymoprhic base class in this fashion,
-    // then we need it to be a base class that does not have functions such as isEmpty,
-    // size, data, and vector, all of which will do the wrong thing if they are called.
-    // Deleting these functions here does not prevent them from being called.
-    bool isEmpty() const = delete;
-    size_t size() const = delete;
+    size_t size() const { return m_buffer->size(); }
     const uint8_t* data() const = delete;
     Vector<uint8_t> vector() const = delete;
 
-    virtual void encode(ArgumentEncoder&) const override;
+    void encode(ArgumentEncoder&) const override;
+    virtual ~SharedBufferDataReference() { m_buffer = 0; }
 
+private:
     RefPtr<WebCore::SharedBuffer> m_buffer;
 };
 
diff --git a/Source/WebKit2/Shared/WebResourceBuffer.cpp b/Source/WebKit2/Shared/WebResourceBuffer.cpp
new file mode 100644 (file)
index 0000000..54b9eb3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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 "WebResourceBuffer.h"
+
+#if ENABLE(SHAREABLE_RESOURCE)
+
+#include "Logging.h"
+#include "ShareableResource.h"
+
+namespace WebKit {
+
+WebResourceBuffer::WebResourceBuffer(PassRefPtr<ShareableResource> resource)
+    : m_resource(resource)
+{
+    ASSERT(m_resource);
+}
+
+WebResourceBuffer::~WebResourceBuffer()
+{
+}
+
+const char* WebResourceBuffer::data() const
+{
+    return reinterpret_cast<const char*>(m_resource->data());
+}
+
+unsigned WebResourceBuffer::size() const
+{
+    return m_resource->size();
+}
+
+bool WebResourceBuffer::isEmpty() const
+{
+    return !m_resource || !m_resource->size();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(SHAREABLE_RESOURCE)
diff --git a/Source/WebKit2/Shared/WebResourceBuffer.h b/Source/WebKit2/Shared/WebResourceBuffer.h
new file mode 100644 (file)
index 0000000..69b4959
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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.
+ */
+
+#ifndef WebResourceBuffer_h
+#define WebResourceBuffer_h
+
+#if ENABLE(SHAREABLE_RESOURCE)
+
+#include <WebCore/ResourceBuffer.h>
+
+namespace WebKit {
+
+class ShareableResource;
+
+class WebResourceBuffer : public WebCore::ResourceBuffer {
+public:
+    static PassRefPtr<WebResourceBuffer> create(PassRefPtr<ShareableResource> resource) { return adoptRef(new WebResourceBuffer(resource)); }
+
+    virtual ~WebResourceBuffer() override;
+
+    virtual const char* data() const override;
+    virtual unsigned size() const override;
+    virtual bool isEmpty() const override;
+
+private:
+    WebResourceBuffer(PassRefPtr<ShareableResource>);
+
+    RefPtr<ShareableResource> m_resource;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(SHAREABLE_RESOURCE)
+
+#endif // WebResourceBuffer_h
index f0c8430..ac95cfd 100644 (file)
                512127C41908239A00DAF35C /* WebPasteboardOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = 512127C21908239A00DAF35C /* WebPasteboardOverrides.h */; };
                51217460164C20E30037A5C1 /* ShareableResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5121745E164C20E30037A5C1 /* ShareableResource.cpp */; };
                51217461164C20E30037A5C1 /* ShareableResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 5121745F164C20E30037A5C1 /* ShareableResource.h */; };
+               51217464164C21370037A5C1 /* WebResourceBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51217462164C21370037A5C1 /* WebResourceBuffer.cpp */; };
+               51217465164C21370037A5C1 /* WebResourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 51217463164C21370037A5C1 /* WebResourceBuffer.h */; };
                5123CF1B133D260A0056F800 /* WKIconDatabaseCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5123CF19133D260A0056F800 /* WKIconDatabaseCG.cpp */; };
                5123CF1C133D260A0056F800 /* WKIconDatabaseCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
                51290992183ACEAF005522A6 /* WebIDBServerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51290990183ACEAF005522A6 /* WebIDBServerConnection.cpp */; };
                512127C21908239A00DAF35C /* WebPasteboardOverrides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPasteboardOverrides.h; sourceTree = "<group>"; };
                5121745E164C20E30037A5C1 /* ShareableResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShareableResource.cpp; sourceTree = "<group>"; };
                5121745F164C20E30037A5C1 /* ShareableResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareableResource.h; sourceTree = "<group>"; };
+               51217462164C21370037A5C1 /* WebResourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceBuffer.cpp; sourceTree = "<group>"; };
+               51217463164C21370037A5C1 /* WebResourceBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebResourceBuffer.h; sourceTree = "<group>"; };
                5123CF19133D260A0056F800 /* WKIconDatabaseCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WKIconDatabaseCG.cpp; path = cg/WKIconDatabaseCG.cpp; sourceTree = "<group>"; };
                5123CF1A133D260A0056F800 /* WKIconDatabaseCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKIconDatabaseCG.h; path = cg/WKIconDatabaseCG.h; sourceTree = "<group>"; };
                51290990183ACEAF005522A6 /* WebIDBServerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIDBServerConnection.cpp; sourceTree = "<group>"; };
                                37948402150C350600E52CE9 /* WebRenderLayer.h */,
                                3760881C150413E900FC82C7 /* WebRenderObject.cpp */,
                                3760881D150413E900FC82C7 /* WebRenderObject.h */,
+                               51217462164C21370037A5C1 /* WebResourceBuffer.cpp */,
+                               51217463164C21370037A5C1 /* WebResourceBuffer.h */,
                                F634445512A885C8000612D8 /* WebSecurityOrigin.h */,
                                A72D5D7F1236CBA800A88B15 /* WebSerializedScriptValue.h */,
                                C0337DD7127A51B6008FF4F4 /* WebTouchEvent.cpp */,
                                51E351F6180F5C7500E53BE9 /* WebIDBFactoryBackend.h in Headers */,
                                2D29ECD0192F2C2E00984B78 /* RemoteLayerTreeDisplayRefreshMonitor.h in Headers */,
                                3760881F150413E900FC82C7 /* WebRenderObject.h in Headers */,
+                               51217465164C21370037A5C1 /* WebResourceBuffer.h in Headers */,
                                33367630130C9998006C9DE2 /* WebResourceCacheManager.h in Headers */,
                                1AAF089B19267EE500B6390C /* WKUserScript.h in Headers */,
                                33367656130C9ECA006C9DE2 /* WebResourceCacheManagerMessages.h in Headers */,
                                37948403150C350600E52CE9 /* WebRenderLayer.cpp in Sources */,
                                2D28F3E61885CCC1004B9EAE /* WebEditorClientIOS.mm in Sources */,
                                3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */,
+                               51217464164C21370037A5C1 /* WebResourceBuffer.cpp in Sources */,
                                3336762F130C9998006C9DE2 /* WebResourceCacheManager.cpp in Sources */,
                                E115C714190F89E400ECC516 /* DatabaseProcessIOS.mm in Sources */,
                                33F9D5B91312F1EE000D683F /* WebResourceCacheManagerCFNet.cpp in Sources */,
index 671a17e..7719645 100644 (file)
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebProcess.h"
+#include "WebResourceBuffer.h"
 #include "WebResourceLoadScheduler.h"
 #include "WebResourceLoaderMessages.h"
 #include <WebCore/CachedResource.h>
 #include <WebCore/MemoryCache.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/SessionID.h>
 #include <WebCore/SharedBuffer.h>
 
@@ -93,7 +95,7 @@ void NetworkProcessConnection::didCacheResource(const ResourceRequest& request,
         return;
     }
 
-    resource->tryReplaceEncodedData(*buffer);
+    resource->tryReplaceEncodedData(buffer.release());
 }
 #endif
 
index 88cb064..1a7f9c1 100644 (file)
@@ -46,6 +46,7 @@
 #include <WebCore/FrameLoader.h>
 #include <WebCore/NetscapePlugInStreamLoader.h>
 #include <WebCore/ReferrerPolicy.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceLoader.h>
 #include <WebCore/SessionID.h>
 #include <WebCore/Settings.h>
index c5eb423..85adfbb 100644 (file)
@@ -38,6 +38,7 @@
 #include <WebCore/ApplicationCacheHost.h>
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/DocumentLoader.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceLoader.h>
 
index 6b92842..dc9aa0f 100644 (file)
@@ -46,6 +46,7 @@ class DataReference;
 namespace WebCore {
 class CertificateInfo;
 class ProtectionSpace;
+class ResourceBuffer;
 class ResourceError;
 class ResourceLoader;
 class ResourceRequest;
index 9ce0bef..91f8e8f 100644 (file)
@@ -74,6 +74,7 @@
 #include <WebCore/PluginData.h>
 #include <WebCore/PluginDocument.h>
 #include <WebCore/ProgressTracker.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ScriptController.h>
 #include <WebCore/Settings.h>
@@ -918,7 +919,7 @@ void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
             if (!webPage)
                 return;
 
-            RefPtr<SharedBuffer> mainResourceData = loader->mainResourceData();
+            RefPtr<ResourceBuffer> mainResourceData = loader->mainResourceData();
             IPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(mainResourceData ? mainResourceData->data() : 0), mainResourceData ? mainResourceData->size() : 0);
             webPage->send(Messages::WebPageProxy::DidFinishLoadingDataForCustomContentProvider(loader->response().suggestedFilename(), dataReference));
         }
index 9dcee46..54e0b7d 100644 (file)
@@ -65,6 +65,7 @@
 #include <WebCore/Page.h>
 #include <WebCore/PluginDocument.h>
 #include <WebCore/RenderTreeAsText.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceLoader.h>
 #include <WebCore/ScriptController.h>
 #include <WebCore/SecurityOrigin.h>
@@ -304,7 +305,7 @@ String WebFrame::source() const
     DocumentLoader* documentLoader = m_coreFrame->loader().activeDocumentLoader();
     if (!documentLoader)
         return String();
-    RefPtr<SharedBuffer> mainResourceData = documentLoader->mainResourceData();
+    RefPtr<ResourceBuffer> mainResourceData = documentLoader->mainResourceData();
     if (!mainResourceData)
         return String();
     return decoder->encoding().decode(mainResourceData->data(), mainResourceData->size());
index cf00e18..bb7ab10 100644 (file)
 #include <WebCore/RenderLayer.h>
 #include <WebCore/RenderTreeAsText.h>
 #include <WebCore/RenderView.h>
+#include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
 #include <WebCore/RuntimeEnabledFeatures.h>
@@ -2434,16 +2435,17 @@ void WebPage::runJavaScriptInMainFrame(const String& script, uint64_t callbackID
     // NOTE: We need to be careful when running scripts that the objects we depend on don't
     // disappear during script execution.
 
+    // Retain the SerializedScriptValue at this level so it (and the internal data) lives
+    // long enough for the DataReference to be encoded by the sent message.
     RefPtr<SerializedScriptValue> serializedResultValue;
+    IPC::DataReference dataReference;
+
     JSLockHolder lock(JSDOMWindow::commonVM());
     if (JSValue resultValue = m_mainFrame->coreFrame()->script().executeScript(script, true).jsValue()) {
-        serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(),
-            toRef(m_mainFrame->coreFrame()->script().globalObject(mainThreadNormalWorld())->globalExec(), resultValue), nullptr);
+        if ((serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(), toRef(m_mainFrame->coreFrame()->script().globalObject(mainThreadNormalWorld())->globalExec(), resultValue), 0)))
+            dataReference = serializedResultValue->data();
     }
 
-    IPC::DataReference dataReference;
-    if (serializedResultValue)
-        dataReference = serializedResultValue->data();
     send(Messages::WebPageProxy::ScriptValueCallback(dataReference, callbackID));
 }
 
@@ -2456,14 +2458,15 @@ void WebPage::getContentsAsString(uint64_t callbackID)
 #if ENABLE(MHTML)
 void WebPage::getContentsAsMHTMLData(uint64_t callbackID, bool useBinaryEncoding)
 {
+    IPC::DataReference dataReference;
+
     RefPtr<SharedBuffer> buffer = useBinaryEncoding
         ? MHTMLArchive::generateMHTMLDataUsingBinaryEncoding(m_page.get())
         : MHTMLArchive::generateMHTMLData(m_page.get());
 
-    // FIXME: Use SharedBufferDataReference.
-    IPC::DataReference dataReference;
     if (buffer)
         dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
+
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 #endif
@@ -2486,17 +2489,20 @@ static Frame* frameWithSelection(Page* page)
 
 void WebPage::getSelectionAsWebArchiveData(uint64_t callbackID)
 {
+    IPC::DataReference dataReference;
+
 #if PLATFORM(COCOA)
+    RefPtr<LegacyWebArchive> archive;
     RetainPtr<CFDataRef> data;
-    if (Frame* frame = frameWithSelection(m_page.get()))
-        data = LegacyWebArchive::createFromSelection(frame)->rawDataRepresentation();
-#endif
 
-    IPC::DataReference dataReference;
-#if PLATFORM(COCOA)
-    if (data)
+    Frame* frame = frameWithSelection(m_page.get());
+    if (frame) {
+        archive = LegacyWebArchive::createFromSelection(frame);
+        data = archive->rawDataRepresentation();
         dataReference = IPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
+    }
 #endif
+
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
@@ -2519,20 +2525,24 @@ void WebPage::getSourceForFrame(uint64_t frameID, uint64_t callbackID)
 
 void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
 {
-    RefPtr<SharedBuffer> buffer;
+    IPC::DataReference dataReference;
+
+    RefPtr<ResourceBuffer> buffer;
+    RefPtr<SharedBuffer> pdfResource;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
-        if (PluginView* pluginView = pluginViewForFrame(frame->coreFrame()))
-            buffer = pluginView->liveResourceData();
-        if (!buffer) {
-            if (DocumentLoader* loader = frame->coreFrame()->loader().documentLoader())
-                buffer = loader->mainResourceData();
+        if (PluginView* pluginView = pluginViewForFrame(frame->coreFrame())) {
+            if ((pdfResource = pluginView->liveResourceData()))
+                dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(pdfResource->data()), pdfResource->size());
+        }
+
+        if (dataReference.isEmpty()) {
+            if (DocumentLoader* loader = frame->coreFrame()->loader().documentLoader()) {
+                if ((buffer = loader->mainResourceData()))
+                    dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
+            }
         }
     }
 
-    // FIXME: Use SharedBufferDataReference.
-    IPC::DataReference dataReference;
-    if (buffer)
-        dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
@@ -2551,38 +2561,38 @@ static PassRefPtr<SharedBuffer> resourceDataForFrame(Frame* frame, const URL& re
 
 void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURLString, uint64_t callbackID)
 {
+    IPC::DataReference dataReference;
+    URL resourceURL(URL(), resourceURLString);
+
     RefPtr<SharedBuffer> buffer;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
-        URL resourceURL(URL(), resourceURLString);
         buffer = resourceDataForFrame(frame->coreFrame(), resourceURL);
         if (!buffer) {
             // Try to get the resource data from the cache.
             buffer = cachedResponseDataForURL(resourceURL);
         }
+
+        if (buffer)
+            dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
     }
 
-    // FIXME: Use SharedBufferDataReference.
-    IPC::DataReference dataReference;
-    if (buffer)
-        dataReference = IPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
 void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
 {
+    IPC::DataReference dataReference;
+
 #if PLATFORM(COCOA)
     RetainPtr<CFDataRef> data;
-    if (WebFrame* frame = WebProcess::shared().webFrame(frameID))
-        data = frame->webArchiveData(nullptr, nullptr);
+    if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
+        if ((data = frame->webArchiveData(0, 0)))
+            dataReference = IPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
+    }
 #else
     UNUSED_PARAM(frameID);
 #endif
 
-    IPC::DataReference dataReference;
-#if PLATFORM(COCOA)
-    if (data)
-        dataReference = IPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
-#endif
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
index cd82305..75571cb 100644 (file)
@@ -51,7 +51,6 @@
 #import <WebCore/Chrome.h>
 #import <WebCore/DNS.h>
 #import <WebCore/Element.h>
-#import <WebCore/ElementAncestorIterator.h>
 #import <WebCore/EventHandler.h>
 #import <WebCore/FloatQuad.h>
 #import <WebCore/FocusController.h>
@@ -82,6 +81,7 @@
 #import <WebCore/RenderImage.h>
 #import <WebCore/RenderThemeIOS.h>
 #import <WebCore/RenderView.h>
+#import <WebCore/ResourceBuffer.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/TextIterator.h>
 #import <WebCore/VisibleUnits.h>
@@ -1842,11 +1842,10 @@ void WebPage::getAutocorrectionContext(String& contextBefore, String& markedText
 
 static Element* containingLinkElement(Element* element)
 {
-    for (auto& currentElement : elementLineage(element)) {
-        if (currentElement.isLink())
-            return &currentElement;
-    }
-    return nullptr;
+    for (Element* currentElement = element; currentElement; currentElement = currentElement->parentElement())
+        if (currentElement->isLink())
+            return currentElement;
+    return 0;
 }
 
 void WebPage::getPositionInformation(const IntPoint& point, InteractionInformationAtPosition& info)
@@ -1950,77 +1949,73 @@ void WebPage::performActionOnElement(uint32_t action)
     if (!is<HTMLElement>(m_interactionNode.get()))
         return;
 
-    HTMLElement& element = downcast<HTMLElement>(*m_interactionNode);
-    if (!element.renderer())
+    HTMLElement* element = downcast<HTMLElement>(m_interactionNode.get());
+    if (!element->renderer())
         return;
 
     if (static_cast<SheetAction>(action) == SheetAction::Copy) {
-        if (is<RenderImage>(*element.renderer())) {
-            Element* linkElement = containingLinkElement(&element);
+        if (is<RenderImage>(*element->renderer())) {
+            Element* linkElement = containingLinkElement(element);
+        
             if (!linkElement)
-                m_interactionNode->document().frame()->editor().writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), element, downcast<RenderImage>(*element.renderer()).cachedImage()->url(), String());
+                m_interactionNode->document().frame()->editor().writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), *element, downcast<RenderImage>(*element->renderer()).cachedImage()->url(), String());
             else
-                m_interactionNode->document().frame()->editor().copyURL(linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->fastGetAttribute(HTMLNames::hrefAttr))), linkElement->textContent());
-        } else if (element.isLink()) {
-            m_interactionNode->document().frame()->editor().copyURL(element.document().completeURL(stripLeadingAndTrailingHTMLSpaces(element.fastGetAttribute(HTMLNames::hrefAttr))), element.textContent());
+                m_interactionNode->document().frame()->editor().copyURL(linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr))), linkElement->textContent());
+        } else if (element->isLink()) {
+            m_interactionNode->document().frame()->editor().copyURL(element->document().completeURL(stripLeadingAndTrailingHTMLSpaces(element->getAttribute(HTMLNames::hrefAttr))), element->textContent());
         }
     } else if (static_cast<SheetAction>(action) == SheetAction::SaveImage) {
-        if (!is<RenderImage>(*element.renderer()))
-            return;
-        CachedImage* cachedImage = downcast<RenderImage>(*element.renderer()).cachedImage();
-        if (!cachedImage)
-            return;
-        SharedBuffer* buffer = cachedImage->resourceBuffer();
-        if (!buffer)
+        if (!is<RenderImage>(*element->renderer()))
             return;
-        uint64_t bufferSize = buffer->size();
-        RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(bufferSize);
-        memcpy(sharedMemoryBuffer->data(), buffer->data(), bufferSize);
-        SharedMemory::Handle handle;
-        sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
-        send(Messages::WebPageProxy::SaveImageToLibrary(handle, bufferSize));
+        if (CachedImage* cachedImage = downcast<RenderImage>(*element->renderer()).cachedImage()) {
+            SharedMemory::Handle handle;
+            RefPtr<SharedBuffer> buffer = cachedImage->resourceBuffer()->sharedBuffer();
+            if (buffer) {
+                uint64_t bufferSize = buffer->size();
+                RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(bufferSize);
+                memcpy(sharedMemoryBuffer->data(), buffer->data(), bufferSize);
+                sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly);
+                send(Messages::WebPageProxy::SaveImageToLibrary(handle, bufferSize));
+            }
+        }
     }
 }
 
-static inline bool isAssistableElement(Element& node)
+static inline bool isAssistableNode(Node* node)
 {
-    if (is<HTMLSelectElement>(node))
+    if (is<HTMLSelectElement>(*node))
         return true;
-    if (is<HTMLTextAreaElement>(node))
-        return !downcast<HTMLTextAreaElement>(node).isReadOnlyNode();
-    if (is<HTMLInputElement>(node)) {
-        HTMLInputElement& inputElement = downcast<HTMLInputElement>(node);
-        // FIXME: This laundry list of types is not a good way to factor this. Need a suitable function on HTMLInputElement itself.
-        return !inputElement.isReadOnlyNode() && (inputElement.isTextField() || inputElement.isDateField() || inputElement.isDateTimeLocalField() || inputElement.isMonthField() || inputElement.isTimeField());
+    if (is<HTMLTextAreaElement>(*node))
+        return !downcast<HTMLTextAreaElement>(*node).isReadOnlyNode();
+    if (is<HTMLInputElement>(*node)) {
+        HTMLInputElement& element = downcast<HTMLInputElement>(*node);
+        return !element.isReadOnlyNode() && (element.isTextField() || element.isDateField() || element.isDateTimeLocalField() || element.isMonthField() || element.isTimeField());
     }
-    return node.isContentEditable();
+
+    return node->isContentEditable();
 }
 
-static inline Element* nextAssistableElement(Node* startNode, Page& page, bool isForward)
+static inline Element* nextFocusableElement(Node* startNode, Page* page, bool isForward)
 {
-    if (!is<Element>(startNode))
-        return nullptr;
-
     RefPtr<KeyboardEvent> key = KeyboardEvent::create();
 
     Element* nextElement = downcast<Element>(startNode);
     do {
-        nextElement = isForward
-            ? page.focusController().nextFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get())
-            : page.focusController().previousFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get());
-    } while (nextElement && !isAssistableElement(*nextElement));
+        nextElement = isForward ? page->focusController().nextFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get())
+            : page->focusController().previousFocusableElement(FocusNavigationScope::focusNavigationScopeOf(&nextElement->document()), nextElement, key.get());
+    } while (nextElement && !isAssistableNode(nextElement));
 
     return nextElement;
 }
 
-static inline bool hasAssistableElement(Node* startNode, Page& page, bool isForward)
+static inline bool hasFocusableElement(Node* startNode, Page* page, bool isForward)
 {
-    return nextAssistableElement(startNode, page, isForward);
+    return nextFocusableElement(startNode, page, isForward) != nil;
 }
 
 void WebPage::focusNextAssistedNode(bool isForward)
 {
-    Element* nextElement = nextAssistableElement(m_assistedNode.get(), *m_page, isForward);
+    Element* nextElement = nextFocusableElement(m_assistedNode.get(), m_page.get(), isForward);
     m_userIsInteracting = true;
     if (nextElement)
         nextElement->focus();
@@ -2061,8 +2056,8 @@ void WebPage::getAssistedNodeInformation(AssistedNodeInformation& information)
     information.minimumScaleFactor = minimumPageScaleFactor();
     information.maximumScaleFactor = maximumPageScaleFactor();
     information.allowsUserScaling = m_viewportConfiguration.allowsUserScaling();
-    information.hasNextNode = hasAssistableElement(m_assistedNode.get(), *m_page, true);
-    information.hasPreviousNode = hasAssistableElement(m_assistedNode.get(), *m_page, false);
+    information.hasNextNode = hasFocusableElement(m_assistedNode.get(), m_page.get(), true);
+    information.hasPreviousNode = hasFocusableElement(m_assistedNode.get(), m_page.get(), false);
 
     if (is<HTMLSelectElement>(*m_assistedNode)) {
         HTMLSelectElement& element = downcast<HTMLSelectElement>(*m_assistedNode);