Eliminate ResourceBuffer and use SharedBuffer directly instead
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Oct 2014 04:25:34 +0000 (04:25 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Oct 2014 04:25:34 +0000 (04:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138174

Reviewed by Antti Koivisto.

Source/WebCore:

Refactoring, with test coverage across many existing tests.

* CMakeLists.txt: Deleted ResourceBuffer.cpp.

* WebCore.exp.in: Removed ResourceBuffer-related symbols, and updated symbol
for one function that used to take a PassRefPtr but now takes a reference instead.

* WebCore.vcxproj/WebCore.vcxproj: Deleted ResourceBuffer.cpp/.h.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Deleted ResourceBuffer.mm/.cpp/.h.

* bindings/objc/DOMUIKitExtensions.mm:
(-[DOMHTMLImageElement dataRepresentation:]): Use SharedBuffer directly.
* editing/ios/EditorIOS.mm:
(WebCore::Editor::writeImageToPasteboard): Ditto.
* editing/mac/EditorMac.mm:
(WebCore::Editor::writeImageToPasteboard): Ditto.

* html/ImageDocument.cpp:
(WebCore::ImageDocument::updateDuringParsing): Use SharedBuffer directly, and
also pass a reference only if non-null rather than passing a pointer.
(WebCore::ImageDocument::finishedParsing): Ditto. Added a missing null check.

* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::cachedResourceContent): Use SharedBuffer directly.
(WebCore::InspectorPageAgent::mainResourceContent): Ditto.
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::didFinishLoading): Ditto.
(WebCore::InspectorResourceAgent::didFailLoading): Ditto.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::mainResourceData): Use SharedBuffer directly,
and use the copy function rather than a hand-written alternative.
(WebCore::DocumentLoader::maybeCreateArchive): Ditto.
(WebCore::DocumentLoader::mainResource): Ditto.
(WebCore::DocumentLoader::subresource): Ditto.
(WebCore::DocumentLoader::maybeFinishLoadingMultipartContent): Ditto.

* loader/DocumentLoader.h: Changed mainResourceData to return a
PassRefPtr<SharedBuffer>. Would be better if it returned a SharedBuffer&,
but it currently returns a newly created buffer when there is substitute
data and can also return null, even though many callers assume it will not!

* loader/MediaResourceLoader.cpp:
(WebCore::MediaResourceLoader::dataReceived): Removed call to unused client
function bufferReceived.
(WebCore::MediaResourceLoader::notifyFinished): Removed unused buffer
argument to client function loadFinished.

* loader/ResourceBuffer.cpp: Removed.
* loader/ResourceBuffer.h: Removed.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::addDataOrBuffer): Use SharedBuffer directly.

* loader/ResourceLoader.h:
(WebCore::ResourceLoader::resourceData): Use SharedBuffer.

* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::didReceiveResponse): Use SharedBuffer.
(WebCore::SubresourceLoader::didReceiveDataOrBuffer): Ditto.

* loader/TextTrackLoader.cpp:
(WebCore::TextTrackLoader::processNewCueData): Use SharedBuffer.
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::finishedLoadingMainResource): Ditto.
* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::create): Ditto.

* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::finishLoading): Use SharedBuffer.
* loader/cache/CachedCSSStyleSheet.h: Ditto.
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::finishLoading): Ditto.
(WebCore::CachedFont::ensureCustomFontData): Ditto.
* loader/cache/CachedFont.h: Ditto.

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::didAddClient): Use SharedBuffer.
(WebCore::CachedImage::didRemoveClient): Ditto.
(WebCore::CachedImage::addIncrementalDataBuffer): Ditto. Changed to take
a reference rather than a pointer.
(WebCore::CachedImage::addDataBuffer): Ditto. Also added call through
to base class and changed to take a reference rather than a pointer.
(WebCore::CachedImage::addData): Ditto. Also added call through to base class.
(WebCore::CachedImage::finishLoading): Ditto.
* loader/cache/CachedImage.h: Ditto. Also changed the type of some bit fields
to be unsigned instead of unsigend char.

* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::calculateIncrementalDataChunk): Use SharedBuffer.
(WebCore::CachedRawResource::addDataBuffer): Ditto. Changed to take
a reference rather than a pointer.
(WebCore::CachedRawResource::addData): Ditto.
(WebCore::CachedRawResource::finishLoading): Ditto.
(WebCore::CachedRawResource::canReuse): Ditto.
* loader/cache/CachedRawResource.h: Ditto.

* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::CachedResource): Reordered data members due to change
in header.
(WebCore::CachedResource::addDataBuffer): Changed argument type.
(WebCore::CachedResource::finishLoading): Ditto.
(WebCore::CachedResource::didAddClient): Refactored to eliminate one extra hash
table lookup by using the return value from the remove function.
(WebCore::CachedResource::addClientToSet): Use std::make_unique directly instead
of using a function named "schedule" to allocate the callback object.
(WebCore::CachedResource::Callback::Callback): Changed function and data member
name.
(WebCore::CachedResource::Callback::cancel): Ditto.
(WebCore::CachedResource::Callback::timerFired): Ditto.
(WebCore::CachedResource::tryReplaceEncodedData): Changed to take a SharedBuffer&.

* loader/cache/CachedResource.h: Changed types to use SharedBuffer. Also made most
data members and one function member private instead of protected. Also renamed the
CachedResource::CachedResourceCallback function CachedResource::Callback and moved
its definition out of the CachedResource class definition.

* loader/cache/CachedResourceClient.h: Removed unneeded include.

* loader/cache/CachedSVGDocument.cpp:
(WebCore::CachedSVGDocument::finishLoading): Use SharedBuffer.

* loader/cache/CachedSVGDocument.h: Ditto. Made data members private.

* loader/cache/CachedScript.cpp:
(WebCore::CachedScript::finishLoading): Use SharedBuffer.
* loader/cache/CachedScript.h: Ditto. Also fixed indenting and removed unneeded
forward declaration.

* loader/cache/CachedTextTrack.cpp:
(WebCore::CachedTextTrack::updateData): Added, so that finishLoading does not
call addDataBuffer.
(WebCore::CachedTextTrack::addDataBuffer): Take SharedBuffer, call updateData.
(WebCore::CachedTextTrack::finishLoading): Ditto.
* loader/cache/CachedTextTrack.h: Take out unneeded explicit override of the
destructor. Updated for above changes.

* loader/cache/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::finishLoading): Updated to use SharedBuffer.
* loader/cache/CachedXSLStyleSheet.h: Took out unneeded includes, made everything
private rather than protected. Added an explicit virtual constructor so we can
compile without knowing how to ref/deref TextResourceDecoder.

* loader/cf/SubresourceLoaderCF.cpp:
(WebCore::SubresourceLoader::didReceiveDataArray): Updated to use SharedBuffer
and to call addDataBuffer only if there is a new data buffer.

* loader/cocoa/DiskCacheMonitorCocoa.h: Use SharedBuffer& instead of PassRefPtr.
* loader/cocoa/DiskCacheMonitorCocoa.mm:
(WebCore::DiskCacheMonitor::DiskCacheMonitor): Ditto.
(WebCore::DiskCacheMonitor::resourceBecameFileBacked): Ditto.

* loader/icon/IconLoader.cpp:
(WebCore::IconLoader::notifyFinished): Use SharedBuffer* instead of
RefPtr<ResourceBuffer>.

* loader/mac/ResourceBuffer.mm: Removed.

* loader/mac/ResourceLoaderMac.mm:
(WebCore::ResourceLoader::didReceiveDataArray): Use SharedBuffer.

* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::clear): Use a modern for loop.
(WebCore::SharedBuffer::copy): Return a PassRef instead of a PassRefPtr, since
this never returns null. Use modern for loops.
(WebCore::SharedBuffer::copyBufferAndClear): Use a modern for loop.

* platform/SharedBuffer.h: Changed copy to return PassRef instead of PassRefPtr.
Changed tryReplaceContentsWithPlatformBuffer to take a reference rather than
a pointer.

* platform/cf/SharedBufferCF.cpp:
(WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer): Take a reference
instead of a pointer.

* platform/graphics/PlatformMediaResourceLoader.h: Removed unused function
bufferReceived and unneeded buffer argument from loadFinished. Also marked the
constructor explicit.

* platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp:
Removed include of ResourceBuffer.h.
* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
(WebCore::WebCoreAVFResourceLoader::fulfillRequestWithResource): Use
SharedBuffer directly.

* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(CachedResourceStreamingClient::loadFinished): Updated for change to
PlatformMediaResourceLoaderClient.

* platform/mac/PasteboardMac.mm: Removed include of ResourceBuffer.h.

* platform/soup/SharedBufferSoup.cpp: Removed unused, unneeded
tryReplaceContentsWithPlatformBuffer function.

Source/WebKit/mac:

* WebView/WebDataSource.mm:
(-[WebDataSource data]): Use SharedBuffer directly.
* WebView/WebHTMLView.mm:
(-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]): Ditto.

Source/WebKit/win:

* WebDataSource.cpp:
(WebDataSource::data): Use SharedBuffer directly.
(WebDataSource::subresourceForURL): Ditto.

Source/WebKit2:

* CMakeLists.txt: Removed WebResourceBuffer.cpp.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::sendBuffer): Use a reference instead of pointer.
* NetworkProcess/NetworkResourceLoader.h: Ditto.
* NetworkProcess/mac/NetworkDiskCacheMonitor.h: Ditto.
* NetworkProcess/mac/NetworkDiskCacheMonitor.mm:
(WebKit::NetworkDiskCacheMonitor::resourceBecameFileBacked): Ditto.
* NetworkProcess/mac/NetworkResourceLoaderMac.mm:
(WebKit::NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer): Ditto.

* Shared/WebResourceBuffer.cpp: Removed.
* Shared/WebResourceBuffer.h: Removed.

* WebKit2.xcodeproj/project.pbxproj: Removed WebResourceBuffer.cpp/h.

* WebProcess/Network/NetworkProcessConnection.cpp: Removed unneeded includes.
(WebKit::NetworkProcessConnection::didCacheResource): Use a reference instead
of a pointer.

* WebProcess/Network/WebResourceLoadScheduler.cpp: Removed unneeded include.
* WebProcess/Network/WebResourceLoader.cpp: Ditto.
* WebProcess/Network/WebResourceLoader.h: Ditto.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: Ditto.
(WebKit::WebFrameLoaderClient::finishedLoading): Use SharedBuffer directly.
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::source): Ditto.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::runJavaScriptInMainFrame): Refactored to make the relationship
between the buffer and the DataReference clearer and to avoid having a long-lived
DataReference pointing to an underlying buffer with unclear lifetime.
(WebKit::WebPage::getContentsAsString): Ditto.
(WebKit::WebPage::getSelectionAsWebArchiveData): Ditto.
(WebKit::WebPage::getMainResourceDataOfFrame): Ditto. Also use SharedBuffer directly.
(WebKit::WebPage::getResourceDataFromFrame): Ditto.
(WebKit::WebPage::getWebArchiveOfFrame): Ditto.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::containingLinkElement): Use elementLineage.
(WebKit::WebPage::performActionOnElement): Use references and SharedBuffer.
ALso did a bit of other cleanup in here.
(WebKit::isAssistableElement): Take Element& instead of Node*, since that's what
the caller has.
(WebKit::nextAssistableElement): Changed name to match what the function does.
Added an obviously-missing check on the startNode argument. Updated for change
to isAssistableElement above. Take a Page& instead of a Page*.
(WebKit::hasAssistableElement): Changed name to match what the function does.
Updated for change to nextAssistableElement above. Took out incorrect comparison
of a C++ pointer to the Objective-C object pointer nil. Take a Page& instead of a Page*.
(WebKit::WebPage::focusNextAssistedNode): Updated for above changes.
(WebKit::WebPage::getAssistedNodeInformation): Updated for above changes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175406 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 [deleted file]
Source/WebCore/loader/ResourceBuffer.h [deleted file]
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 [deleted file]
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 [deleted file]
Source/WebKit2/Shared/WebResourceBuffer.h [deleted file]
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 af34701..1b12878 100644 (file)
@@ -1816,7 +1816,6 @@ 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 2cc5861..70d868f 100644 (file)
@@ -1,3 +1,205 @@
+2014-10-30  Darin Adler  <darin@apple.com>
+
+        Eliminate ResourceBuffer and use SharedBuffer directly instead
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+
+        Reviewed by Antti Koivisto.
+
+        Refactoring, with test coverage across many existing tests.
+
+        * CMakeLists.txt: Deleted ResourceBuffer.cpp.
+
+        * WebCore.exp.in: Removed ResourceBuffer-related symbols, and updated symbol
+        for one function that used to take a PassRefPtr but now takes a reference instead.
+
+        * WebCore.vcxproj/WebCore.vcxproj: Deleted ResourceBuffer.cpp/.h.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Deleted ResourceBuffer.mm/.cpp/.h.
+
+        * bindings/objc/DOMUIKitExtensions.mm:
+        (-[DOMHTMLImageElement dataRepresentation:]): Use SharedBuffer directly.
+        * editing/ios/EditorIOS.mm:
+        (WebCore::Editor::writeImageToPasteboard): Ditto.
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::writeImageToPasteboard): Ditto.
+
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::updateDuringParsing): Use SharedBuffer directly, and
+        also pass a reference only if non-null rather than passing a pointer.
+        (WebCore::ImageDocument::finishedParsing): Ditto. Added a missing null check.
+
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::cachedResourceContent): Use SharedBuffer directly.
+        (WebCore::InspectorPageAgent::mainResourceContent): Ditto.
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::didFinishLoading): Ditto.
+        (WebCore::InspectorResourceAgent::didFailLoading): Ditto.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::mainResourceData): Use SharedBuffer directly,
+        and use the copy function rather than a hand-written alternative.
+        (WebCore::DocumentLoader::maybeCreateArchive): Ditto.
+        (WebCore::DocumentLoader::mainResource): Ditto.
+        (WebCore::DocumentLoader::subresource): Ditto.
+        (WebCore::DocumentLoader::maybeFinishLoadingMultipartContent): Ditto.
+
+        * loader/DocumentLoader.h: Changed mainResourceData to return a
+        PassRefPtr<SharedBuffer>. Would be better if it returned a SharedBuffer&,
+        but it currently returns a newly created buffer when there is substitute
+        data and can also return null, even though many callers assume it will not!
+
+        * loader/MediaResourceLoader.cpp:
+        (WebCore::MediaResourceLoader::dataReceived): Removed call to unused client
+        function bufferReceived.
+        (WebCore::MediaResourceLoader::notifyFinished): Removed unused buffer
+        argument to client function loadFinished.
+
+        * loader/ResourceBuffer.cpp: Removed.
+        * loader/ResourceBuffer.h: Removed.
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::addDataOrBuffer): Use SharedBuffer directly.
+
+        * loader/ResourceLoader.h:
+        (WebCore::ResourceLoader::resourceData): Use SharedBuffer.
+
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::didReceiveResponse): Use SharedBuffer.
+        (WebCore::SubresourceLoader::didReceiveDataOrBuffer): Ditto.
+
+        * loader/TextTrackLoader.cpp:
+        (WebCore::TextTrackLoader::processNewCueData): Use SharedBuffer.
+        * loader/appcache/ApplicationCacheGroup.cpp:
+        (WebCore::ApplicationCacheGroup::finishedLoadingMainResource): Ditto.
+        * loader/archive/cf/LegacyWebArchive.cpp:
+        (WebCore::LegacyWebArchive::create): Ditto.
+
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::finishLoading): Use SharedBuffer.
+        * loader/cache/CachedCSSStyleSheet.h: Ditto.
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::finishLoading): Ditto.
+        (WebCore::CachedFont::ensureCustomFontData): Ditto.
+        * loader/cache/CachedFont.h: Ditto.
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::didAddClient): Use SharedBuffer.
+        (WebCore::CachedImage::didRemoveClient): Ditto.
+        (WebCore::CachedImage::addIncrementalDataBuffer): Ditto. Changed to take
+        a reference rather than a pointer.
+        (WebCore::CachedImage::addDataBuffer): Ditto. Also added call through
+        to base class and changed to take a reference rather than a pointer.
+        (WebCore::CachedImage::addData): Ditto. Also added call through to base class.
+        (WebCore::CachedImage::finishLoading): Ditto.
+        * loader/cache/CachedImage.h: Ditto. Also changed the type of some bit fields
+        to be unsigned instead of unsigend char.
+
+        * loader/cache/CachedRawResource.cpp:
+        (WebCore::CachedRawResource::calculateIncrementalDataChunk): Use SharedBuffer.
+        (WebCore::CachedRawResource::addDataBuffer): Ditto. Changed to take
+        a reference rather than a pointer.
+        (WebCore::CachedRawResource::addData): Ditto.
+        (WebCore::CachedRawResource::finishLoading): Ditto.
+        (WebCore::CachedRawResource::canReuse): Ditto.
+        * loader/cache/CachedRawResource.h: Ditto.
+
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::CachedResource): Reordered data members due to change
+        in header.
+        (WebCore::CachedResource::addDataBuffer): Changed argument type.
+        (WebCore::CachedResource::finishLoading): Ditto.
+        (WebCore::CachedResource::didAddClient): Refactored to eliminate one extra hash
+        table lookup by using the return value from the remove function.
+        (WebCore::CachedResource::addClientToSet): Use std::make_unique directly instead
+        of using a function named "schedule" to allocate the callback object.
+        (WebCore::CachedResource::Callback::Callback): Changed function and data member
+        name.
+        (WebCore::CachedResource::Callback::cancel): Ditto.
+        (WebCore::CachedResource::Callback::timerFired): Ditto.
+        (WebCore::CachedResource::tryReplaceEncodedData): Changed to take a SharedBuffer&.
+
+        * loader/cache/CachedResource.h: Changed types to use SharedBuffer. Also made most
+        data members and one function member private instead of protected. Also renamed the
+        CachedResource::CachedResourceCallback function CachedResource::Callback and moved
+        its definition out of the CachedResource class definition.
+
+        * loader/cache/CachedResourceClient.h: Removed unneeded include.
+
+        * loader/cache/CachedSVGDocument.cpp:
+        (WebCore::CachedSVGDocument::finishLoading): Use SharedBuffer.
+
+        * loader/cache/CachedSVGDocument.h: Ditto. Made data members private.
+
+        * loader/cache/CachedScript.cpp:
+        (WebCore::CachedScript::finishLoading): Use SharedBuffer.
+        * loader/cache/CachedScript.h: Ditto. Also fixed indenting and removed unneeded
+        forward declaration.
+
+        * loader/cache/CachedTextTrack.cpp:
+        (WebCore::CachedTextTrack::updateData): Added, so that finishLoading does not
+        call addDataBuffer.
+        (WebCore::CachedTextTrack::addDataBuffer): Take SharedBuffer, call updateData.
+        (WebCore::CachedTextTrack::finishLoading): Ditto.
+        * loader/cache/CachedTextTrack.h: Take out unneeded explicit override of the
+        destructor. Updated for above changes.
+
+        * loader/cache/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::finishLoading): Updated to use SharedBuffer.
+        * loader/cache/CachedXSLStyleSheet.h: Took out unneeded includes, made everything
+        private rather than protected. Added an explicit virtual constructor so we can
+        compile without knowing how to ref/deref TextResourceDecoder.
+
+        * loader/cf/SubresourceLoaderCF.cpp:
+        (WebCore::SubresourceLoader::didReceiveDataArray): Updated to use SharedBuffer
+        and to call addDataBuffer only if there is a new data buffer.
+
+        * loader/cocoa/DiskCacheMonitorCocoa.h: Use SharedBuffer& instead of PassRefPtr.
+        * loader/cocoa/DiskCacheMonitorCocoa.mm:
+        (WebCore::DiskCacheMonitor::DiskCacheMonitor): Ditto.
+        (WebCore::DiskCacheMonitor::resourceBecameFileBacked): Ditto.
+
+        * loader/icon/IconLoader.cpp:
+        (WebCore::IconLoader::notifyFinished): Use SharedBuffer* instead of
+        RefPtr<ResourceBuffer>.
+
+        * loader/mac/ResourceBuffer.mm: Removed.
+
+        * loader/mac/ResourceLoaderMac.mm:
+        (WebCore::ResourceLoader::didReceiveDataArray): Use SharedBuffer.
+
+        * platform/SharedBuffer.cpp:
+        (WebCore::SharedBuffer::clear): Use a modern for loop.
+        (WebCore::SharedBuffer::copy): Return a PassRef instead of a PassRefPtr, since
+        this never returns null. Use modern for loops.
+        (WebCore::SharedBuffer::copyBufferAndClear): Use a modern for loop.
+
+        * platform/SharedBuffer.h: Changed copy to return PassRef instead of PassRefPtr.
+        Changed tryReplaceContentsWithPlatformBuffer to take a reference rather than
+        a pointer.
+
+        * platform/cf/SharedBufferCF.cpp:
+        (WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer): Take a reference
+        instead of a pointer.
+
+        * platform/graphics/PlatformMediaResourceLoader.h: Removed unused function
+        bufferReceived and unneeded buffer argument from loadFinished. Also marked the
+        constructor explicit.
+
+        * platform/graphics/avfoundation/cf/WebCoreAVCFResourceLoader.cpp:
+        Removed include of ResourceBuffer.h.
+        * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
+        (WebCore::WebCoreAVFResourceLoader::fulfillRequestWithResource): Use
+        SharedBuffer directly.
+
+        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+        (CachedResourceStreamingClient::loadFinished): Updated for change to
+        PlatformMediaResourceLoaderClient.
+
+        * platform/mac/PasteboardMac.mm: Removed include of ResourceBuffer.h.
+
+        * platform/soup/SharedBufferSoup.cpp: Removed unused, unneeded
+        tryReplaceContentsWithPlatformBuffer function.
+
 2014-10-30  Chris Dumez  <cdumez@apple.com>
 
         Move border-image-source / -webkit-mask-box-image-source to the new StyleBuilder
index 19a065f..743e23c 100644 (file)
@@ -340,7 +340,7 @@ __ZN7WebCore13pointerCursorEv
 __ZN7WebCore13toJSDOMWindowEN3JSC7JSValueE
 __ZN7WebCore14CachedResource12removeClientEPNS_20CachedResourceClientE
 __ZN7WebCore14CachedResource16unregisterHandleEPNS_24CachedResourceHandleBaseE
-__ZN7WebCore14CachedResource21tryReplaceEncodedDataEN3WTF10PassRefPtrINS_12SharedBufferEEE
+__ZN7WebCore14CachedResource21tryReplaceEncodedDataERNS_12SharedBufferE
 __ZN7WebCore14CachedResource9addClientEPNS_20CachedResourceClientE
 __ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELm0ENS1_15CrashOnOverflowEEE
 __ZN7WebCore14ClientRectListC1Ev
@@ -383,13 +383,6 @@ __ZN7WebCore14LoaderStrategy18createBlobRegistryEv
 __ZN7WebCore14LoaderStrategy21resourceLoadSchedulerEv
 __ZN7WebCore14LoaderStrategy25loadResourceSynchronouslyEPNS_17NetworkingContextEmRKNS_15ResourceRequestENS_17StoredCredentialsENS_22ClientCredentialPolicyERNS_13ResourceErrorERNS_16ResourceResponseERN3WTF6VectorIcLm0ENSC_15CrashOnOverflowEEE
 __ZN7WebCore14PluginDocument12pluginWidgetEv
-__ZN7WebCore14ResourceBuffer12createNSDataEv
-__ZN7WebCore14ResourceBuffer6appendEPKcj
-__ZN7WebCore14ResourceBufferC1EPKcj
-__ZN7WebCore14ResourceBufferC1Ev
-__ZN7WebCore14ResourceBufferC2Ev
-__ZN7WebCore14ResourceBufferD1Ev
-__ZN7WebCore14ResourceBufferD2Ev
 __ZN7WebCore14ResourceHandle12firstRequestEv
 __ZN7WebCore14ResourceHandle16setDefersLoadingEb
 __ZN7WebCore14ResourceHandle20forceContentSniffingEv
@@ -1728,9 +1721,6 @@ __ZNK7WebCore14FrameSelection31getClippedVisibleTextRectanglesERN3WTF6VectorINS_
 __ZNK7WebCore14FrameSelection36rootEditableElementOrDocumentElementEv
 __ZNK7WebCore14InsertionPoint8isActiveEv
 __ZNK7WebCore14RenderListItem10markerTextEv
-__ZNK7WebCore14ResourceBuffer4dataEv
-__ZNK7WebCore14ResourceBuffer4sizeEv
-__ZNK7WebCore14ResourceBuffer7isEmptyEv
 __ZNK7WebCore14ResourceHandle10connectionEv
 __ZNK7WebCore14ResourceLoader11frameLoaderEv
 __ZNK7WebCore14ResourceLoader32isAllowedToAskUserForCredentialsEv
@@ -2803,7 +2793,6 @@ __ZNK7WebCore14FrameSelection29rangeByMovingCurrentSelectionEi
 __ZNK7WebCore14FrameSelection32rangeByExtendingCurrentSelectionEi
 __ZNK7WebCore14FrameSelection35characterInRelationToCaretSelectionEi
 __ZNK7WebCore14FrameSelection36elementRangeContainingCaretSelectionEv
-__ZNK7WebCore14ResourceBuffer12sharedBufferEv
 __ZNK7WebCore14SecurityOrigin8toStringEv
 __ZNK7WebCore15GraphicsLayerCA21contentsLayerForMediaEv
 __ZNK7WebCore15VisiblePosition4leftEb
index 8233664..dbc16dd 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 322b70c..c5f69be 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 e7db10f..6231788 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 b8d9330..201c259 100644 (file)
@@ -62,7 +62,6 @@
 #import "RenderObject.h"
 #import "RenderStyleConstants.h"
 #import "RenderText.h"
-#import "ResourceBuffer.h"
 #import "SharedBuffer.h"
 #import "VisiblePosition.h"
 #import "VisibleUnits.h"
@@ -464,23 +463,15 @@ using WebCore::VisiblePosition;
 
 - (NSData *)dataRepresentation:(BOOL)rawImageData
 {
-    WebCore::CachedImage *cachedImage = core(self)->cachedImage();
+    WebCore::CachedImagecachedImage = core(self)->cachedImage();
     if (!cachedImage)
         return nil;
-    WebCore::Image *image = cachedImage->image();
+    WebCore::Imageimage = cachedImage->image();
     if (!image)
         return nil;
-    WebCore::SharedBuffer *data = nil;
-    if (rawImageData) {
-        ResourceBuffer *resourceBuffer = cachedImage->resourceBuffer();
-        if (resourceBuffer)
-            data = resourceBuffer->sharedBuffer();
-    } else {
-        data = image->data();
-    }
+    WebCore::SharedBuffer* data = rawImageData ? cachedImage->resourceBuffer() : image->data();
     if (!data)
         return nil;
-
     return data->createNSData().autorelease();
 }
 
index 0192d5e..b9eb96c 100644 (file)
@@ -49,7 +49,6 @@
 #include "Pasteboard.h"
 #include "RenderBlock.h"
 #include "RenderImage.h"
-#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "SoftLinking.h"
 #include "StyleProperties.h"
@@ -385,7 +384,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()->sharedBuffer();
+    pasteboardImage.resourceData = cachedImage->resourceBuffer();
 
     pasteboard.write(pasteboardImage);
 }
index 6e4190f..29276fa 100644 (file)
@@ -52,7 +52,6 @@
 #import "Range.h"
 #import "RenderBlock.h"
 #import "RenderImage.h"
-#import "ResourceBuffer.h"
 #import "RuntimeApplicationChecks.h"
 #import "Sound.h"
 #import "StyleProperties.h"
@@ -447,7 +446,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()->sharedBuffer();
+    pasteboardImage.resourceData = cachedImage->resourceBuffer();
     pasteboardImage.resourceMIMEType = cachedImage->response().mimeType();
 
     pasteboard.write(pasteboardImage);
index 179ec10..40a7b57 100644 (file)
@@ -45,7 +45,6 @@
 #include "Page.h"
 #include "RawDataDocumentParser.h"
 #include "RenderElement.h"
-#include "ResourceBuffer.h"
 #include "Settings.h"
 
 namespace WebCore {
@@ -134,7 +133,8 @@ void ImageDocument::updateDuringParsing()
     if (!m_imageElement)
         createDocumentStructure();
 
-    m_imageElement->cachedImage()->addDataBuffer(loader()->mainResourceData().get());
+    if (RefPtr<SharedBuffer> buffer = loader()->mainResourceData())
+        m_imageElement->cachedImage()->addDataBuffer(*buffer);
 
     imageUpdated();
 }
@@ -143,11 +143,11 @@ void ImageDocument::finishedParsing()
 {
     if (!parser()->isStopped() && m_imageElement) {
         CachedImage& cachedImage = *m_imageElement->cachedImage();
-        RefPtr<ResourceBuffer> data = loader()->mainResourceData();
+        RefPtr<SharedBuffer> 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 (loader()->isLoadingMultipartContent())
+        if (data && loader()->isLoadingMultipartContent())
             data = data->copy();
 
         cachedImage.finishLoading(data.get());
index 782826d..f9b2b21 100644 (file)
@@ -62,7 +62,6 @@
 #include "MainFrame.h"
 #include "MemoryCache.h"
 #include "Page.h"
-#include "ResourceBuffer.h"
 #include "ScriptController.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -143,11 +142,9 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
 
     *base64Encoded = !hasTextContent(cachedResource);
     if (*base64Encoded) {
-        RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer()->sharedBuffer();
-
+        RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer();
         if (!buffer)
             return false;
-
         *result = base64Encode(buffer->data(), buffer->size());
         return true;
     }
@@ -166,7 +163,7 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
             *result = downcast<CachedScript>(*cachedResource).script();
             return true;
         case CachedResource::RawResource: {
-            ResourceBuffer* buffer = cachedResource->resourceBuffer();
+            auto* buffer = cachedResource->resourceBuffer();
             if (!buffer)
                 return false;
             RefPtr<TextResourceDecoder> decoder = createXHRTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName());
@@ -177,7 +174,7 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
             return true;
         }
         default:
-            ResourceBuffer* buffer = cachedResource->resourceBuffer();
+            auto* buffer = cachedResource->resourceBuffer();
             return decodeBuffer(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, cachedResource->encoding(), result);
         }
     }
@@ -186,12 +183,10 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S
 
 bool InspectorPageAgent::mainResourceContent(Frame* frame, bool withBase64Encode, String* result)
 {
-    RefPtr<ResourceBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
+    RefPtr<SharedBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
     if (!buffer)
         return false;
-    String textEncodingName = frame->document()->inputEncoding();
-
-    return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), textEncodingName, withBase64Encode, result);
+    return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), frame->document()->inputEncoding(), withBase64Encode, result);
 }
 
 // static
index 1c57a4f..481b2ba 100644 (file)
@@ -54,7 +54,6 @@
 #include "NetworkResourcesData.h"
 #include "Page.h"
 #include "ProgressTracker.h"
-#include "ResourceBuffer.h"
 #include "ResourceError.h"
 #include "ResourceLoader.h"
 #include "ResourceRequest.h"
@@ -405,8 +404,9 @@ void InspectorResourceAgent::didFinishLoading(unsigned long identifier, Document
 
     String requestId = IdentifiersFactory::requestId(identifier);
     if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::DocumentResource) {
-        RefPtr<ResourceBuffer> buffer = loader->frameLoader()->documentLoader()->mainResourceData();
-        m_resourcesData->addResourceSharedBuffer(requestId, buffer ? buffer->sharedBuffer() : nullptr, loader->frame()->document()->inputEncoding());
+        m_resourcesData->addResourceSharedBuffer(requestId,
+            loader->frameLoader()->documentLoader()->mainResourceData(),
+            loader->frame()->document()->inputEncoding());
     }
 
     m_resourcesData->maybeDecodeDataToContent(requestId);
@@ -435,8 +435,9 @@ 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()) {
-            RefPtr<ResourceBuffer> buffer = frame->loader().documentLoader()->mainResourceData();
-            m_resourcesData->addResourceSharedBuffer(requestId, buffer ? buffer->sharedBuffer() : nullptr, frame->document()->inputEncoding());
+            m_resourcesData->addResourceSharedBuffer(requestId,
+                frame->loader().documentLoader()->mainResourceData(),
+                frame->document()->inputEncoding());
         }
     }
 
index 40ae594..977ed14 100644 (file)
@@ -56,7 +56,6 @@
 #include "Page.h"
 #include "PolicyChecker.h"
 #include "ProgressTracker.h"
-#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "SchemeRegistry.h"
 #include "SecurityPolicy.h"
@@ -171,20 +170,20 @@ DocumentLoader::~DocumentLoader()
     clearMainResource();
 }
 
-PassRefPtr<ResourceBuffer> DocumentLoader::mainResourceData() const
+PassRefPtr<SharedBuffer> DocumentLoader::mainResourceData() const
 {
     if (m_substituteData.isValid())
-        return ResourceBuffer::create(m_substituteData.content()->data(), m_substituteData.content()->size());
+        return m_substituteData.content()->copy();
     if (m_mainResource)
         return m_mainResource->resourceBuffer();
-    return 0;
+    return nullptr;
 }
 
 Document* DocumentLoader::document() const
 {
     if (m_frame && m_frame->loader().documentLoader() == this)
         return m_frame->document();
-    return 0;
+    return nullptr;
 }
 
 const ResourceRequest& DocumentLoader::originalRequest() const
@@ -994,8 +993,7 @@ 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.
-    RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
-    m_archive = ArchiveFactory::create(m_response.url(), mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0, m_response.mimeType());
+    m_archive = ArchiveFactory::create(m_response.url(), mainResourceData().get(), m_response.mimeType());
     if (!m_archive)
         return false;
     
@@ -1011,6 +1009,7 @@ bool DocumentLoader::maybeCreateArchive()
 }
 
 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
+
 void DocumentLoader::setArchive(PassRefPtr<Archive> archive)
 {
     m_archive = archive;
@@ -1058,47 +1057,46 @@ 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 0;
-        
+        return nullptr;
     ArchiveResource* resource = m_archiveResourceCollection->archiveResourceForURL(url);
-
-    return resource && !resource->shouldIgnoreWhenUnarchiving() ? resource : 0;
+    if (!resource || resource->shouldIgnoreWhenUnarchiving())
+        return nullptr;
+    return resource;
 }
 
 PassRefPtr<ArchiveResource> DocumentLoader::mainResource() const
 {
-    const ResourceResponse& r = response();
-    
-    RefPtr<ResourceBuffer> mainResourceBuffer = mainResourceData();
-    RefPtr<SharedBuffer> data = mainResourceBuffer ? mainResourceBuffer->sharedBuffer() : 0;
+    RefPtr<SharedBuffer> data = mainResourceData();
     if (!data)
         data = SharedBuffer::create();
         
-    return ArchiveResource::create(data, r.url(), r.mimeType(), r.textEncodingName(), frame()->tree().uniqueName());
+    auto& response = this->response();
+    return ArchiveResource::create(data, response.url(), response.mimeType(), response.textEncodingName(), frame()->tree().uniqueName());
 }
 
 PassRefPtr<ArchiveResource> DocumentLoader::subresource(const URL& url) const
 {
     if (!isCommitted())
-        return 0;
+        return nullptr;
     
     CachedResource* resource = m_cachedResourceLoader->cachedResource(url);
     if (!resource || !resource->isLoaded())
         return archiveResourceForURL(url);
 
     if (resource->type() == CachedResource::MainResource)
-        return 0;
+        return nullptr;
 
-    ResourceBuffer* data = resource->resourceBuffer();
+    auto* data = resource->resourceBuffer();
     if (!data)
-        return 0;
+        return nullptr;
 
-    return ArchiveResource::create(data->sharedBuffer(), url, resource->response());
+    return ArchiveResource::create(data, url, resource->response());
 }
 
 Vector<RefPtr<ArchiveResource>> DocumentLoader::subresources() const
@@ -1511,7 +1509,7 @@ void DocumentLoader::maybeFinishLoadingMultipartContent()
 
     frameLoader()->setupForReplace();
     m_committed = false;
-    RefPtr<ResourceBuffer> resourceData = mainResourceData();
+    RefPtr<SharedBuffer> resourceData = mainResourceData();
     commitLoad(resourceData->data(), resourceData->size());
 }
 
index 403e195..7698ffb 100644 (file)
@@ -68,7 +68,6 @@ namespace WebCore {
     class Frame;
     class FrameLoader;
     class Page;
-    class ResourceBuffer;
     class ResourceLoader;
     class SharedBuffer;
     class SubstituteResource;
@@ -93,7 +92,7 @@ namespace WebCore {
 
         WEBCORE_EXPORT FrameLoader* frameLoader() const;
         WEBCORE_EXPORT ResourceLoader* mainResourceLoader() const;
-        WEBCORE_EXPORT PassRefPtr<ResourceBuffer> mainResourceData() const;
+        WEBCORE_EXPORT PassRefPtr<SharedBuffer> mainResourceData() const;
         
         DocumentWriter& writer() const { return m_writer; }
 
index 80756f1..87de3c6 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,13 +112,10 @@ void MediaResourceLoader::responseReceived(CachedResource* resource, const Resou
 
 void MediaResourceLoader::dataReceived(CachedResource* resource, const char* data, int dataLength)
 {
-    ASSERT(resource == m_resource);
+    ASSERT_UNUSED(resource, 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)
@@ -129,7 +126,7 @@ void MediaResourceLoader::notifyFinished(CachedResource* resource)
     if (resource->loadFailedOrCanceled())
         m_client->loadFailed(resource->resourceError());
     else
-        m_client->loadFinished(resource->resourceBuffer() ? resource->resourceBuffer()->sharedBuffer() : nullptr);
+        m_client->loadFinished();
     stop();
 }
 
diff --git a/Source/WebCore/loader/ResourceBuffer.cpp b/Source/WebCore/loader/ResourceBuffer.cpp
deleted file mode 100644 (file)
index a6ba8ce..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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
deleted file mode 100644 (file)
index e63b08a..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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 2c81fa3..43b9c3f 100644 (file)
@@ -42,7 +42,6 @@
 #include "Page.h"
 #include "PlatformStrategies.h"
 #include "ProgressTracker.h"
-#include "ResourceBuffer.h"
 #include "ResourceError.h"
 #include "ResourceHandle.h"
 #include "ResourceLoadScheduler.h"
@@ -222,12 +221,12 @@ void ResourceLoader::addDataOrBuffer(const char* data, unsigned length, SharedBu
         return;
 
     if (dataPayloadType == DataPayloadWholeResource) {
-        m_resourceData = buffer ? ResourceBuffer::adoptSharedBuffer(buffer) : ResourceBuffer::create(data, length);
+        m_resourceData = buffer ? buffer : SharedBuffer::create(data, length);
         return;
     }
         
     if (!m_resourceData)
-        m_resourceData = buffer ? ResourceBuffer::adoptSharedBuffer(buffer) : ResourceBuffer::create(data, length);
+        m_resourceData = buffer ? buffer : SharedBuffer::create(data, length);
     else {
         if (buffer)
             m_resourceData->append(buffer);
index 8d094c6..1615f6d 100644 (file)
@@ -47,7 +47,6 @@ class DocumentLoader;
 class Frame;
 class FrameLoader;
 class URL;
-class ResourceBuffer;
 
 #if USE(QUICK_LOOK)
 class QuickLookHandle;
@@ -88,7 +87,7 @@ public:
     virtual void releaseResources();
     const ResourceResponse& response() const;
 
-    ResourceBuffer* resourceData() const { return m_resourceData.get(); }
+    SharedBuffer* resourceData() const { return m_resourceData.get(); }
     void clearResourceData();
     
     virtual bool isSubresourceLoader();
@@ -204,7 +203,7 @@ private:
 
     ResourceRequest m_request;
     ResourceRequest m_originalRequest; // Before redirects.
-    RefPtr<ResourceBuffer> m_resourceData;
+    RefPtr<SharedBuffer> m_resourceData;
     
     unsigned long m_identifier;
 
index 7d40e63..26a34e2 100644 (file)
@@ -38,7 +38,6 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "PageActivityAssertionToken.h"
-#include "ResourceBuffer.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCountedLeakCounter.h>
 #include <wtf/StdLibExtras.h>
@@ -233,11 +232,10 @@ void SubresourceLoader::didReceiveResponse(const ResourceResponse& response)
         }
     }
 
-    RefPtr<ResourceBuffer> buffer = resourceData();
+    auto* 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.
-        RefPtr<ResourceBuffer> copiedData = ResourceBuffer::create(buffer->data(), buffer->size());
-        m_resource->finishLoading(copiedData.get());
+        m_resource->finishLoading(&buffer->copy().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" 
@@ -273,8 +271,8 @@ void SubresourceLoader::didReceiveDataOrBuffer(const char* data, int length, Pas
     ResourceLoader::didReceiveDataOrBuffer(data, length, buffer, encodedDataLength, dataPayloadType);
 
     if (!m_loadingMultipartContent) {
-        if (ResourceBuffer* resourceData = this->resourceData())
-            m_resource->addDataBuffer(resourceData);
+        if (auto* resourceData = this->resourceData())
+            m_resource->addDataBuffer(*resourceData);
         else
             m_resource->addData(buffer ? buffer->data() : data, buffer ? buffer->size() : length);
     }
index 353cef2..0f27b92 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;
     
-    ResourceBuffer* buffer = resource->resourceBuffer();
+    auto* buffer = resource->resourceBuffer();
     if (m_parseOffset == buffer->size())
         return;
 
index 6342194..e954a33 100644 (file)
@@ -41,7 +41,6 @@
 #include "InspectorInstrumentation.h"
 #include "ManifestParser.h"
 #include "Page.h"
-#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -254,11 +253,8 @@ void ApplicationCacheGroup::finishedLoadingMainResource(DocumentLoader* loader)
                 resource->addType(ApplicationCacheResource::Master);
                 ASSERT(!resource->storageID());
             }
-        } else {
-            RefPtr<ResourceBuffer> buffer = loader->mainResourceData();
-            m_newestCache->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, buffer ? buffer->sharedBuffer() : 0));
-        }
-
+        } else
+            m_newestCache->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, loader->mainResourceData()));
         break;
     case Failure:
         // Cache update has been a failure, so there is no reason to keep the document associated with the incomplete cache
@@ -276,10 +272,8 @@ void ApplicationCacheGroup::finishedLoadingMainResource(DocumentLoader* loader)
                 resource->addType(ApplicationCacheResource::Master);
                 ASSERT(!resource->storageID());
             }
-        } else {
-            RefPtr<ResourceBuffer> buffer = loader->mainResourceData();
-            m_cacheBeingUpdated->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, buffer ? buffer->sharedBuffer() : 0));
-        }
+        } else
+            m_cacheBeingUpdated->addResource(ApplicationCacheResource::create(url, loader->response(), ApplicationCacheResource::Master, loader->mainResourceData()));
         // The "cached" event will be posted to all associated documents once update is complete.
         break;
     }
index 24cf4be..972346a 100644 (file)
@@ -46,7 +46,6 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "Range.h"
-#include "ResourceBuffer.h"
 #include "Settings.h"
 #include "markup.h"
 #include <wtf/ListHashSet.h>
@@ -550,9 +549,7 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
 #endif
                 CachedResource* cachedResource = memoryCache()->resourceForRequest(request, frame->page()->sessionID());
                 if (cachedResource) {
-                    ResourceBuffer* data = cachedResource->resourceBuffer();
-
-                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(data ? data->sharedBuffer() : 0, subresourceURL, cachedResource->response())) {
+                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(cachedResource->resourceBuffer(), subresourceURL, cachedResource->response())) {
                         subresources.append(WTF::move(resource));
                         continue;
                     }
index a2081be..e370138 100644 (file)
@@ -33,7 +33,7 @@
 #include "HTTPHeaderNames.h"
 #include "HTTPParsers.h"
 #include "MemoryCache.h"
-#include "ResourceBuffer.h"
+#include "SharedBuffer.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(ResourceBuffer* data)
+void CachedCSSStyleSheet::finishLoading(SharedBuffer* data)
 {
     m_data = data;
-    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    setEncodedSize(data ? data->size() : 0);
     // Decode the data to find out the encoding and keep the sheet text around during checkNotify()
-    if (m_data)
-        m_decodedSheetText = m_decoder->decodeAndFlush(m_data->data(), m_data->size());
+    if (data)
+        m_decodedSheetText = m_decoder->decodeAndFlush(data->data(), data->size());
     setLoading(false);
     checkNotify();
     // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.
index 80f994c..940fd1f 100644 (file)
@@ -54,7 +54,7 @@ namespace WebCore {
 
         virtual void setEncoding(const String&) override;
         virtual String encoding() const override;
-        virtual void finishLoading(ResourceBuffer*) override;
+        virtual void finishLoading(SharedBuffer*) override;
         virtual void destroyDecodedData() override;
 
     protected:
index 13682fa..1ef622e 100644 (file)
@@ -33,7 +33,6 @@
 #include "FontCustomPlatformData.h"
 #include "FontPlatformData.h"
 #include "MemoryCache.h"
-#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include "TypedElementDescendantIterator.h"
@@ -76,7 +75,7 @@ void CachedFont::didAddClient(CachedResourceClient* c)
         static_cast<CachedFontClient*>(c)->fontLoaded(this);
 }
 
-void CachedFont::finishLoading(ResourceBuffer* data)
+void CachedFont::finishLoading(SharedBuffer* data)
 {
     m_data = data;
     setEncodedSize(m_data.get() ? m_data->size() : 0);
@@ -95,30 +94,27 @@ void CachedFont::beginLoadIfNeeded(CachedResourceLoader* dl)
 bool CachedFont::ensureCustomFontData()
 {
     if (!m_fontData && !errorOccurred() && !isLoading() && m_data) {
-        SharedBuffer* buffer = m_data.get()->sharedBuffer();
-        ASSERT(buffer);
-
+        RefPtr<SharedBuffer> buffer = m_data;
         bool fontIsWOFF = false;
+
 #if (!PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090) && (!PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED < 80000)
-        RefPtr<SharedBuffer> sfntBuffer;
-
-        fontIsWOFF = isWOFF(buffer);
-        if (fontIsWOFF) {
-            Vector<char> sfnt;
-            if (convertWOFFToSfnt(buffer, sfnt)) {
-                sfntBuffer = SharedBuffer::adoptVector(sfnt);
-                buffer = sfntBuffer.get();
-            } else
+        if (isWOFF(buffer.get())) {
+            Vector<char> convertedFont;
+            if (!convertWOFFToSfnt(buffer.get(), convertedFont))
                 buffer = nullptr;
+            else {
+                buffer = SharedBuffer::adoptVector(convertedFont);
+                fontIsWOFF = true;
+            }
         }
 #endif
 
         m_fontData = buffer ? createFontCustomPlatformData(*buffer) : nullptr;
-        if (m_fontData)
-            m_hasCreatedFontDataWrappingResource = !fontIsWOFF;
-        else
+        m_hasCreatedFontDataWrappingResource = m_fontData && !fontIsWOFF;
+        if (!m_fontData)
             setStatus(DecodeError);
     }
+
     return m_fontData.get();
 }
 
index d943730..2a267cc 100644 (file)
@@ -63,7 +63,7 @@ private:
     virtual void load(CachedResourceLoader*, const ResourceLoaderOptions&) override;
 
     virtual void didAddClient(CachedResourceClient*) override;
-    virtual void finishLoading(ResourceBuffer*) override;
+    virtual void finishLoading(SharedBuffer*) override;
 
     virtual void allClientsRemoved() override;
 
index b0fda18..db2ae97 100644 (file)
@@ -37,7 +37,6 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "RenderElement.h"
-#include "ResourceBuffer.h"
 #include "SVGImage.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -116,31 +115,31 @@ void CachedImage::load(CachedResourceLoader* cachedResourceLoader, const Resourc
         setLoading(false);
 }
 
-void CachedImage::didAddClient(CachedResourceClient* c)
+void CachedImage::didAddClient(CachedResourceClient* client)
 {
     if (m_data && !m_image && !errorOccurred()) {
         createImage();
-        m_image->setData(m_data->sharedBuffer(), true);
+        m_image->setData(m_data, true);
     }
     
-    ASSERT(c->resourceClientType() == CachedImageClient::expectedType());
+    ASSERT(client->resourceClientType() == CachedImageClient::expectedType());
     if (m_image && !m_image->isNull())
-        static_cast<CachedImageClient*>(c)->imageChanged(this);
+        static_cast<CachedImageClient*>(client)->imageChanged(this);
 
-    CachedResource::didAddClient(c);
+    CachedResource::didAddClient(client);
 }
 
-void CachedImage::didRemoveClient(CachedResourceClient* c)
+void CachedImage::didRemoveClient(CachedResourceClient* client)
 {
-    ASSERT(c);
-    ASSERT(c->resourceClientType() == CachedImageClient::expectedType());
+    ASSERT(client);
+    ASSERT(client->resourceClientType() == CachedImageClient::expectedType());
 
-    m_pendingContainerSizeRequests.remove(static_cast<CachedImageClient*>(c));
+    m_pendingContainerSizeRequests.remove(static_cast<CachedImageClient*>(client));
 
     if (m_svgImageCache)
-        m_svgImageCache->removeClientFromCache(static_cast<CachedImageClient*>(c));
+        m_svgImageCache->removeClientFromCache(static_cast<CachedImageClient*>(client));
 
-    CachedResource::didRemoveClient(c);
+    CachedResource::didRemoveClient(client);
 }
 
 void CachedImage::switchClientsToRevalidatedResource()
@@ -365,18 +364,16 @@ inline void CachedImage::clearImage()
     m_image.clear();
 }
 
-void CachedImage::addIncrementalDataBuffer(ResourceBuffer* data)
+void CachedImage::addIncrementalDataBuffer(SharedBuffer& data)
 {
-    m_data = data;
-    if (!data)
-        return;
+    m_data = &data;
 
     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(m_data->sharedBuffer(), false);
+    bool sizeAvailable = m_image->setData(&data, false);
     if (!sizeAvailable)
         return;
 
@@ -398,26 +395,28 @@ void CachedImage::addIncrementalDataBuffer(ResourceBuffer* data)
     setEncodedSize(m_image->data() ? m_image->data()->size() : 0);
 }
 
-void CachedImage::addDataBuffer(ResourceBuffer* data)
+void CachedImage::addDataBuffer(SharedBuffer& data)
 {
-    ASSERT(m_options.dataBufferingPolicy() == BufferData);
+    ASSERT(dataBufferingPolicy() == BufferData);
     addIncrementalDataBuffer(data);
+    CachedResource::addDataBuffer(data);
 }
 
 void CachedImage::addData(const char* data, unsigned length)
 {
-    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
-    addIncrementalDataBuffer(ResourceBuffer::create(data, length).get());
+    ASSERT(dataBufferingPolicy() == DoNotBufferData);
+    addIncrementalDataBuffer(*SharedBuffer::create(data, length));
+    CachedResource::addData(data, length);
 }
 
-void CachedImage::finishLoading(ResourceBuffer* data)
+void CachedImage::finishLoading(SharedBuffer* data)
 {
     m_data = data;
     if (!m_image && data)
         createImage();
 
     if (m_image)
-        m_image->setData(m_data->sharedBuffer(), true);
+        m_image->setData(data, true);
 
     if (!m_image || m_image->isNull()) {
         // Image decoding failed; the image data is malformed.
index feef452..56d2aa1 100644 (file)
@@ -71,8 +71,8 @@ public:
     bool imageHasRelativeWidth() const;
     bool imageHasRelativeHeight() const;
 
-    virtual void addDataBuffer(ResourceBuffer*) override;
-    virtual void finishLoading(ResourceBuffer*) override;
+    virtual void addDataBuffer(SharedBuffer&) override;
+    virtual void finishLoading(SharedBuffer*) 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 = 0);
+    void notifyObservers(const IntRect* changeRect = nullptr);
     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(ResourceBuffer*);
+    void addIncrementalDataBuffer(SharedBuffer&);
 
     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 char m_isManuallyCached : 1;
-    unsigned char m_shouldPaintBrokenImage : 1;
+    unsigned m_isManuallyCached : 1;
+    unsigned m_shouldPaintBrokenImage : 1;
 };
 
 } // namespace WebCore
index 5f28132..68e77fe 100644 (file)
@@ -30,7 +30,7 @@
 #include "CachedResourceClientWalker.h"
 #include "CachedResourceLoader.h"
 #include "HTTPHeaderNames.h"
-#include "ResourceBuffer.h"
+#include "SharedBuffer.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(ResourceBuffer* data, unsigned& incrementalDataLength)
+const char* CachedRawResource::calculateIncrementalDataChunk(SharedBuffer* data, unsigned& incrementalDataLength)
 {
     incrementalDataLength = 0;
     if (!data)
@@ -58,34 +58,36 @@ const char* CachedRawResource::calculateIncrementalDataChunk(ResourceBuffer* dat
     return data->data() + previousDataLength;
 }
 
-void CachedRawResource::addDataBuffer(ResourceBuffer* data)
+void CachedRawResource::addDataBuffer(SharedBuffer& data)
 {
     CachedResourceHandle<CachedRawResource> protect(this);
-    ASSERT(m_options.dataBufferingPolicy() == BufferData);
-    m_data = data;
+    ASSERT(dataBufferingPolicy() == BufferData);
+    m_data = &data;
 
     unsigned incrementalDataLength;
-    const char* incrementalData = calculateIncrementalDataChunk(data, incrementalDataLength);
-    if (data)
-        setEncodedSize(data->size());
+    const char* incrementalData = calculateIncrementalDataChunk(&data, incrementalDataLength);
+    setEncodedSize(data.size());
     notifyClientsDataWasReceived(incrementalData, incrementalDataLength);
-    if (m_options.dataBufferingPolicy() == DoNotBufferData) {
+    if (dataBufferingPolicy() == DoNotBufferData) {
         if (m_loader)
             m_loader->setDataBufferingPolicy(DoNotBufferData);
         clear();
     }
+
+    CachedResource::addDataBuffer(data);
 }
 
 void CachedRawResource::addData(const char* data, unsigned length)
 {
-    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
+    ASSERT(dataBufferingPolicy() == DoNotBufferData);
     notifyClientsDataWasReceived(data, length);
+    CachedResource::addData(data, length);
 }
 
-void CachedRawResource::finishLoading(ResourceBuffer* data)
+void CachedRawResource::finishLoading(SharedBuffer* data)
 {
     CachedResourceHandle<CachedRawResource> protect(this);
-    DataBufferingPolicy dataBufferingPolicy = m_options.dataBufferingPolicy();
+    DataBufferingPolicy dataBufferingPolicy = this->dataBufferingPolicy();
     if (dataBufferingPolicy == BufferData) {
         m_data = data;
 
@@ -99,7 +101,7 @@ void CachedRawResource::finishLoading(ResourceBuffer* data)
     m_allowEncodedDataReplacement = !m_loader->isQuickLookResource();
 
     CachedResource::finishLoading(data);
-    if (dataBufferingPolicy == BufferData && m_options.dataBufferingPolicy() == DoNotBufferData) {
+    if (dataBufferingPolicy == BufferData && this->dataBufferingPolicy() == DoNotBufferData) {
         if (m_loader)
             m_loader->setDataBufferingPolicy(DoNotBufferData);
         clear();
@@ -222,7 +224,7 @@ static bool shouldIgnoreHeaderForCacheReuse(HTTPHeaderName name)
 
 bool CachedRawResource::canReuse(const ResourceRequest& newRequest) const
 {
-    if (m_options.dataBufferingPolicy() == DoNotBufferData)
+    if (dataBufferingPolicy() == DoNotBufferData)
         return false;
 
     if (m_resourceRequest.httpMethod() != newRequest.httpMethod())
index f3c668f..2cd455a 100644 (file)
@@ -48,9 +48,9 @@ public:
 
 private:
     virtual void didAddClient(CachedResourceClient*) override;
-    virtual void addDataBuffer(ResourceBuffer*) override;
+    virtual void addDataBuffer(SharedBuffer&) override;
     virtual void addData(const char* data, unsigned length) override;
-    virtual void finishLoading(ResourceBuffer*) override;
+    virtual void finishLoading(SharedBuffer*) 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(ResourceBuffer*, unsigned& incrementalDataLength);
+    const char* calculateIncrementalDataChunk(SharedBuffer*, unsigned& incrementalDataLength);
     void notifyClientsDataWasReceived(const char* data, unsigned length);
 
 #if USE(SOUP)
index 5a4e4a7..ceee58c 100644 (file)
@@ -40,7 +40,6 @@
 #include "Logging.h"
 #include "MemoryCache.h"
 #include "PlatformStrategies.h"
-#include "ResourceBuffer.h"
 #include "ResourceHandle.h"
 #include "ResourceLoadScheduler.h"
 #include "SchemeRegistry.h"
@@ -108,10 +107,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)
@@ -286,22 +285,22 @@ void CachedResource::checkNotify()
     if (isLoading() || stillNeedsLoad())
         return;
 
-    CachedResourceClientWalker<CachedResourceClient> w(m_clients);
-    while (CachedResourceClient* c = w.next())
-        c->notifyFinished(this);
+    CachedResourceClientWalker<CachedResourceClient> walker(m_clients);
+    while (CachedResourceClient* client = walker.next())
+        client->notifyFinished(this);
 }
 
-void CachedResource::addDataBuffer(ResourceBuffer*)
+void CachedResource::addDataBuffer(SharedBuffer&)
 {
-    ASSERT(m_options.dataBufferingPolicy() == BufferData);
+    ASSERT(dataBufferingPolicy() == BufferData);
 }
 
 void CachedResource::addData(const char*, unsigned)
 {
-    ASSERT(m_options.dataBufferingPolicy() == DoNotBufferData);
+    ASSERT(dataBufferingPolicy() == DoNotBufferData);
 }
 
-void CachedResource::finishLoading(ResourceBuffer*)
+void CachedResource::finishLoading(SharedBuffer*)
 {
     setLoading(false);
     checkNotify();
@@ -391,17 +390,15 @@ void CachedResource::addClient(CachedResourceClient* client)
         didAddClient(client);
 }
 
-void CachedResource::didAddClient(CachedResourceClient* c)
+void CachedResource::didAddClient(CachedResourceClient* client)
 {
     if (m_decodedDataDeletionTimer.isActive())
         m_decodedDataDeletionTimer.stop();
 
-    if (m_clientsAwaitingCallback.contains(c)) {
-        m_clients.add(c);
-        m_clientsAwaitingCallback.remove(c);
-    }
+    if (m_clientsAwaitingCallback.remove(client))
+        m_clients.add(client);
     if (!isLoading() && !stillNeedsLoad())
-        c->notifyFinished(this);
+        client->notifyFinished(this);
 }
 
 bool CachedResource::addClientToSet(CachedResourceClient* client)
@@ -423,7 +420,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, CachedResourceCallback::schedule(this, client));
+        m_clientsAwaitingCallback.add(client, std::make_unique<Callback>(*this, *client));
         return false;
     }
 
@@ -731,27 +728,28 @@ void CachedResource::setLoadPriority(ResourceLoadPriority loadPriority)
     m_loadPriority = loadPriority;
 }
 
-CachedResource::CachedResourceCallback::CachedResourceCallback(CachedResource* resource, CachedResourceClient* client)
+inline CachedResource::Callback::Callback(CachedResource& resource, CachedResourceClient& client)
     : m_resource(resource)
     , m_client(client)
-    , m_callbackTimer(this, &CachedResourceCallback::timerFired)
+    , m_timer(this, &Callback::timerFired)
 {
-    m_callbackTimer.startOneShot(0);
+    m_timer.startOneShot(0);
 }
 
-void CachedResource::CachedResourceCallback::cancel()
+inline void CachedResource::Callback::cancel()
 {
-    if (m_callbackTimer.isActive())
-        m_callbackTimer.stop();
+    if (m_timer.isActive())
+        m_timer.stop();
 }
 
-void CachedResource::CachedResourceCallback::timerFired(Timer<CachedResourceCallback>&)
+void CachedResource::Callback::timerFired(Timer<Callback>&)
 {
-    m_resource->didAddClient(m_client);
+    m_resource.didAddClient(&m_client);
 }
 
 #if USE(FOUNDATION)
-void CachedResource::tryReplaceEncodedData(PassRefPtr<SharedBuffer> newBuffer)
+
+void CachedResource::tryReplaceEncodedData(SharedBuffer& newBuffer)
 {
     if (!m_data)
         return;
@@ -762,11 +760,12 @@ void CachedResource::tryReplaceEncodedData(PassRefPtr<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->tryReplaceSharedBufferContents(newBuffer.get());
+    m_data->tryReplaceContentsWithPlatformBuffer(newBuffer);
 }
+
 #endif
 
 }
index 9fb9b14..bf6e997 100644 (file)
@@ -47,7 +47,6 @@ class CachedResourceClient;
 class CachedResourceHandleBase;
 class CachedResourceLoader;
 class InspectorResource;
-class ResourceBuffer;
 class SecurityOrigin;
 class SharedBuffer;
 class SubresourceLoader;
@@ -96,9 +95,9 @@ public:
 
     virtual void setEncoding(const String&) { }
     virtual String encoding() const { return String(); }
-    virtual void addDataBuffer(ResourceBuffer*);
+    virtual void addDataBuffer(SharedBuffer&);
     virtual void addData(const char* data, unsigned length);
-    virtual void finishLoading(ResourceBuffer*);
+    virtual void finishLoading(SharedBuffer*);
     virtual void error(CachedResource::Status);
 
     void setResourceError(const ResourceError& error) { m_error = error; }
@@ -187,7 +186,7 @@ public:
     
     void clearLoader();
 
-    ResourceBuffer* resourceBuffer() const { return m_data.get(); }
+    SharedBuffer* resourceBuffer() const { return m_data.get(); }
 
     virtual void willSendRequest(ResourceRequest&, const ResourceResponse&);
     virtual void responseReceived(const ResourceResponse&);
@@ -245,55 +244,35 @@ public:
     virtual bool canReuse(const ResourceRequest&) const { return true; }
 
 #if USE(FOUNDATION)
-    WEBCORE_EXPORT void tryReplaceEncodedData(PassRefPtr<SharedBuffer>);
+    WEBCORE_EXPORT void tryReplaceEncodedData(SharedBuffer&);
 #endif
 
 #if USE(SOUP)
-    virtual char* getOrCreateReadBuffer(size_t /* requestedSize */, size_t& /* actualSize */) { return 0; }
+    virtual char* getOrCreateReadBuffer(size_t /* requestedSize */, size_t& /* actualSize */) { return nullptr; }
 #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;
-    double m_responseTimestamp;
-
-    RefPtr<ResourceBuffer> m_data;
+    RefPtr<SharedBuffer> 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;
@@ -301,6 +280,12 @@ 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;
@@ -338,7 +323,7 @@ private:
     CachedResource* m_nextInLiveResourcesList;
     CachedResource* m_prevInLiveResourcesList;
 
-    CachedResourceLoader* m_owningCachedResourceLoader; // only non-0 for resources that are not in the cache
+    CachedResourceLoader* m_owningCachedResourceLoader; // only non-null 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
@@ -355,6 +340,20 @@ 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 96933e1..7595110 100644 (file)
@@ -25,9 +25,8 @@
 #ifndef CachedResourceClient_h
 #define CachedResourceClient_h
 
-#include <wtf/FastMalloc.h>
-
 namespace WebCore {
+
 class CachedResource;
 
 class CachedResourceClient {
@@ -44,13 +43,14 @@ 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 32a61b3..a523020 100644 (file)
 #include "config.h"
 #include "CachedSVGDocument.h"
 
-#include "CachedResourceClient.h"
-#include "CachedResourceHandle.h"
-#include "ResourceBuffer.h"
-#include <wtf/text/StringBuilder.h>
+#include "SharedBuffer.h"
 
 namespace WebCore {
 
@@ -51,7 +48,7 @@ String CachedSVGDocument::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedSVGDocument::finishLoading(ResourceBuffer* data)
+void CachedSVGDocument::finishLoading(SharedBuffer* data)
 {
     if (data) {
         // We don't need to create a new frame because the new document belongs to the parent UseElement.
index c1c603f..a791cd8 100644 (file)
@@ -37,15 +37,14 @@ 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(ResourceBuffer*) override;
+    virtual void finishLoading(SharedBuffer*) override;
+
+    RefPtr<SVGDocument> m_document;
+    RefPtr<TextResourceDecoder> m_decoder;
 };
 
 } // namespace WebCore
index f71a5e8..f8bc33c 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,14 +76,13 @@ const String& CachedScript::script()
         setDecodedSize(m_script.sizeInBytes());
     }
     m_decodedDataDeletionTimer.restart();
-    
     return m_script;
 }
 
-void CachedScript::finishLoading(ResourceBuffer* data)
+void CachedScript::finishLoading(SharedBuffer* data)
 {
     m_data = data;
-    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    setEncodedSize(data ? data->size() : 0);
     CachedResource::finishLoading(data);
 }
 
index 91c986a..938e918 100644 (file)
 
 namespace WebCore {
 
-    class CachedResourceLoader;
-    class TextResourceDecoder;
+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(ResourceBuffer*) override;
+    virtual void setEncoding(const String&) override;
+    virtual String encoding() const override;
+    virtual void finishLoading(SharedBuffer*) 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 709fad8..7155922 100644 (file)
@@ -32,7 +32,6 @@
 #include "CachedResourceClient.h"
 #include "CachedResourceClientWalker.h"
 #include "CachedResourceLoader.h"
-#include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Vector.h>
@@ -44,24 +43,26 @@ CachedTextTrack::CachedTextTrack(const ResourceRequest& resourceRequest, Session
 {
 }
 
-CachedTextTrack::~CachedTextTrack()
+void CachedTextTrack::updateData(SharedBuffer* data)
 {
-}
-
-void CachedTextTrack::addDataBuffer(ResourceBuffer* data)
-{
-    ASSERT(m_options.dataBufferingPolicy() == BufferData);
+    ASSERT(dataBufferingPolicy() == BufferData);
     m_data = data;
-    setEncodedSize(m_data.get() ? m_data->size() : 0);
+    setEncodedSize(data ? data->size() : 0);
 
     CachedResourceClientWalker<CachedResourceClient> walker(m_clients);
-    while (CachedResourceClient *client = walker.next())
+    while (CachedResourceClientclient = walker.next())
         client->deprecatedDidReceiveCachedResource(this);
 }
 
-void CachedTextTrack::finishLoading(ResourceBuffer* data)
+void CachedTextTrack::addDataBuffer(SharedBuffer& data)
+{
+    updateData(&data);
+    CachedResource::addDataBuffer(data);
+}
+
+void CachedTextTrack::finishLoading(SharedBuffer* data)
 {
-    addDataBuffer(data);
+    updateData(data);
     CachedResource::finishLoading(data);
 }
 
index 4c3f38a..3c1127e 100644 (file)
@@ -36,12 +36,13 @@ 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(ResourceBuffer*) override;
-    virtual void finishLoading(ResourceBuffer*) override;
+    virtual void addDataBuffer(SharedBuffer&) override;
+    virtual void finishLoading(SharedBuffer*) override;
+
+    void updateData(SharedBuffer*);
 };
 
 } // namespace WebCore
index 66f1ec5..77952b8 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "CachedResourceClientWalker.h"
 #include "CachedStyleSheetClient.h"
-#include "ResourceBuffer.h"
+#include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
 #include <wtf/Vector.h>
 
@@ -46,6 +46,10 @@ 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());
@@ -63,12 +67,12 @@ String CachedXSLStyleSheet::encoding() const
     return m_decoder->encoding().name();
 }
 
-void CachedXSLStyleSheet::finishLoading(ResourceBuffer* data)
+void CachedXSLStyleSheet::finishLoading(SharedBuffer* data)
 {
     m_data = data;
-    setEncodedSize(m_data.get() ? m_data->size() : 0);
-    if (m_data.get())
-        m_sheet = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
+    setEncodedSize(data ? data->size() : 0);
+    if (data)
+        m_sheet = m_decoder->decodeAndFlush(data->data(), encodedSize());
     setLoading(false);
     checkNotify();
 }
index d9921c2..0e00e67 100644 (file)
 #if ENABLE(XSLT)
 
 #include "CachedResource.h"
-#include <wtf/Vector.h>
 
 namespace WebCore {
 
-    class CachedResourceLoader;
-    class TextResourceDecoder;
+class TextResourceDecoder;
 
-    class CachedXSLStyleSheet final : public CachedResource {
-    public:
-        CachedXSLStyleSheet(const ResourceRequest&, SessionID);
+class CachedXSLStyleSheet final : public CachedResource {
+public:
+    CachedXSLStyleSheet(const ResourceRequest&, SessionID);
+    virtual ~CachedXSLStyleSheet();
 
-        const String& sheet() const { return m_sheet; }
+    const String& sheet() const { return m_sheet; }
 
-    protected:
-        virtual void checkNotify() override;
+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;
 
-        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;
-    };
+    String m_sheet;
+    RefPtr<TextResourceDecoder> m_decoder;
+};
 
 } // namespace WebCore
 
index 5767604..69e2997 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 (ResourceBuffer* resourceData = this->resourceData())
-                m_resource->addDataBuffer(resourceData);
+            if (auto* 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 f12e399..a3539b8 100644 (file)
@@ -45,7 +45,7 @@ public:
 protected:
     WEBCORE_EXPORT DiskCacheMonitor(const ResourceRequest&, SessionID, CFCachedURLResponseRef);
 
-    virtual void resourceBecameFileBacked(PassRefPtr<SharedBuffer>);
+    virtual void resourceBecameFileBacked(SharedBuffer&);
 
     const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
     SessionID sessionID() const { return m_sessionID; }
index ca608f7..1c1bd5e 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(PassRefPtr<SharedBuffer> fileBackedBuffer)
+void DiskCacheMonitor::resourceBecameFileBacked(SharedBuffer& fileBackedBuffer)
 {
     CachedResource* resource = memoryCache()->resourceForRequest(m_resourceRequest, m_sessionID);
     if (!resource)
index 5402eb0..56921cd 100644 (file)
@@ -37,7 +37,6 @@
 #include "IconController.h"
 #include "IconDatabase.h"
 #include "Logging.h"
-#include "ResourceBuffer.h"
 #include "ResourceRequest.h"
 #include "SharedBuffer.h"
 #include <wtf/text/CString.h>
@@ -85,16 +84,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.
-    RefPtr<ResourceBuffer> data = resource->resourceBuffer();
+    auto* data = resource->resourceBuffer();
     int status = resource->response().httpStatusCode();
     if (status && (status < 200 || status > 299))
-        data = 0;
+        data = nullptr;
 
     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 = 0;
+        data = nullptr;
     }
 
     LOG(IconDatabase, "IconLoader::finishLoading() - Committing iconURL %s to database", resource->url().string().ascii().data());
@@ -102,7 +101,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 ? data->sharedBuffer() : 0, resource->url().string());
+    iconDatabase().setIconDataForIconURL(data, 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
deleted file mode 100644 (file)
index 54cf9b7..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 a015e98..3ecd597 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 = ResourceBuffer::create();
+                m_resourceData = SharedBuffer::create();
             m_resourceData->append(data);
         }
 
index a1612db..06bdb38 100644 (file)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+
 static const unsigned segmentSize = 0x1000;
 static const unsigned segmentPositionMask = 0x0FFF;
 
@@ -56,6 +57,7 @@ static inline void freeSegment(char* p)
 {
     fastFree(p);
 }
+
 #endif
 
 SharedBuffer::SharedBuffer()
@@ -214,9 +216,8 @@ void SharedBuffer::clear()
     clearPlatformData();
     
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-    for (unsigned i = 0; i < m_segments.size(); ++i)
-        freeSegment(m_segments[i]);
-
+    for (char* segment : m_segments)
+        freeSegment(segment);
     m_segments.clear();
 #else
     m_dataArray.clear();
@@ -226,24 +227,26 @@ void SharedBuffer::clear()
     clearDataBuffer();
 }
 
-PassRefPtr<SharedBuffer> SharedBuffer::copy() const
+PassRef<SharedBuffer> SharedBuffer::copy() const
 {
-    RefPtr<SharedBuffer> clone(adoptRef(new SharedBuffer));
+    PassRef<SharedBuffer> clone { adoptRef(*new SharedBuffer) };
     if (hasPlatformData()) {
-        clone->append(data(), size());
+        clone.get().append(data(), size());
         return clone;
     }
 
-    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());
+    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());
+
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-    for (unsigned i = 0; i < m_segments.size(); ++i)
-        clone->m_buffer->data.append(m_segments[i], segmentSize);
+    for (char* segment : m_segments)
+        clone.get().m_buffer->data.append(segment, segmentSize);
 #else
-    for (unsigned i = 0; i < m_dataArray.size(); ++i)
-        clone->append(m_dataArray[i].get());
+    for (auto& data : m_dataArray)
+        clone.get().append(data.get());
 #endif
+
     return clone;
 }
 
@@ -275,17 +278,19 @@ void SharedBuffer::clearDataBuffer()
 }
 
 #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+
 void SharedBuffer::copyBufferAndClear(char* destination, unsigned bytesToCopy) const
 {
-    for (unsigned i = 0; i < m_segments.size(); ++i) {
+    for (char* segment : m_segments) {
         unsigned effectiveBytesToCopy = std::min(bytesToCopy, segmentSize);
-        memcpy(destination, m_segments[i], effectiveBytesToCopy);
+        memcpy(destination, segment, effectiveBytesToCopy);
         destination += effectiveBytesToCopy;
         bytesToCopy -= effectiveBytesToCopy;
-        freeSegment(m_segments[i]);
+        freeSegment(segment);
     }
     m_segments.clear();
 }
+
 #endif
 
 const Vector<char>& SharedBuffer::buffer() const
index ccb029d..f59129a 100644 (file)
@@ -102,7 +102,7 @@ public:
     void append(CFDataRef);
 #endif
 
-    PassRefPtr<SharedBuffer> copy() const;
+    PassRef<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,6 +158,7 @@ private:
 #else
     mutable Vector<char*> m_segments;
 #endif
+
 #if USE(CF)
     explicit SharedBuffer(CFDataRef);
     RetainPtr<CFDataRef> m_cfData;
index 567707b..bbf185e 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 5891d8c..532ac84 100644 (file)
@@ -27,6 +27,7 @@
 #define PlatformMediaResourceLoader_h
 
 #if ENABLE(VIDEO)
+
 #include <wtf/Noncopyable.h>
 #include <wtf/RefCounted.h>
 
@@ -35,7 +36,6 @@ namespace WebCore {
 class ResourceError;
 class ResourceRequest;
 class ResourceResponse;
-class SharedBuffer;
 
 class PlatformMediaResourceLoaderClient {
 public:
@@ -43,10 +43,9 @@ 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(SharedBuffer*) { }
+    virtual void loadFinished() { }
 #if USE(SOUP)
     virtual char* getOrCreateReadBuffer(size_t /*requestedSize*/, size_t& /*actualSize*/) { return nullptr; };
 #endif
@@ -68,7 +67,7 @@ public:
     virtual bool didPassAccessControlCheck() const { return false; }
 
 protected:
-    PlatformMediaResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
+    explicit PlatformMediaResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
         : m_client(WTF::move(client))
     {
     }
index 5f4bb97..972d613 100644 (file)
@@ -33,7 +33,6 @@
 #include "CachedResourceRequest.h"
 #include "MediaPlayerPrivateAVFoundationCF.h"
 #include "NotImplemented.h"
-#include "ResourceBuffer.h"
 #include "ResourceLoaderOptions.h"
 #include "SharedBuffer.h"
 #include "SoftLinking.h"
index f20e6a0..3e65a51 100644 (file)
@@ -32,7 +32,6 @@
 #import "CachedResourceLoader.h"
 #import "CachedResourceRequest.h"
 #import "MediaPlayerPrivateAVFoundationObjC.h"
-#import "ResourceBuffer.h"
 #import "ResourceLoaderOptions.h"
 #import "SharedBuffer.h"
 #import "SoftLinking.h"
@@ -152,7 +151,7 @@ void WebCoreAVFResourceLoader::fulfillRequestWithResource(CachedResource* resour
     if (!dataRequest)
         return;
 
-    SharedBuffer* data = resource->resourceBuffer() ? resource->resourceBuffer()->sharedBuffer() : 0;
+    SharedBuffer* data = resource->resourceBuffer();
     if (!data)
         return;
 
index f9d7991..12fdeba 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(SharedBuffer*) override;
+        virtual void loadFinished() 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(SharedBuffer*)
+void CachedResourceStreamingClient::loadFinished()
 {
     handleNotifyFinished();
 }
index cea9048..501a38c 100644 (file)
@@ -51,7 +51,6 @@
 #import "PasteboardStrategy.h"
 #import "PlatformStrategies.h"
 #import "RenderImage.h"
-#import "ResourceBuffer.h"
 #import "Text.h"
 #import "WebCoreNSStringExtras.h"
 #import "WebNSAttributedStringExtras.h"
index 37772fe..29bcdb7 100644 (file)
@@ -44,11 +44,6 @@ void SharedBuffer::clearPlatformData()
     m_soupBuffer.reset();
 }
 
-void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer*)
-{
-    ASSERT_NOT_REACHED();
-}
-
 void SharedBuffer::maybeTransferPlatformData()
 {
     if (!m_soupBuffer)
index c483d7d..3515b00 100644 (file)
@@ -1,3 +1,15 @@
+2014-10-30  Darin Adler  <darin@apple.com>
+
+        Eliminate ResourceBuffer and use SharedBuffer directly instead
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+
+        Reviewed by Antti Koivisto.
+
+        * WebView/WebDataSource.mm:
+        (-[WebDataSource data]): Use SharedBuffer directly.
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView namesOfPromisedFilesDroppedAtDestination:]): Ditto.
+
 2014-10-30  Jer Noble  <jer.noble@apple.com>
 
         [EME] Add Setting for accessing storage location for MediaKeys data
index b022c71..ddb8b62 100644 (file)
@@ -53,7 +53,6 @@
 #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>
@@ -459,7 +458,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
 
 - (NSData *)data
 {
-    RefPtr<ResourceBuffer> mainResourceData = toPrivate(_private)->loader->mainResourceData();
+    RefPtr<SharedBuffer> mainResourceData = toPrivate(_private)->loader->mainResourceData();
     if (!mainResourceData)
         return nil;
     return mainResourceData->createNSData().autorelease();
index 0863bde..944c5c8 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>
@@ -3955,7 +3954,7 @@ static bool matchesExtensionOrEquivalent(NSString *filename, NSString *extension
     NSURL *draggingImageURL = nil;
     
     if (WebCore::CachedImage* tiffResource = [self promisedDragTIFFDataSource]) {
-        if (ResourceBuffer *buffer = static_cast<CachedResource*>(tiffResource)->resourceBuffer()) {
+        if (auto* buffer = tiffResource->resourceBuffer()) {
             NSURLResponse *response = tiffResource->response().nsURLResponse();
             draggingImageURL = [response URL];
             wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:buffer->createNSData().get()] autorelease];
index 3a3b201..d6c485a 100644 (file)
@@ -1,3 +1,14 @@
+2014-10-30  Darin Adler  <darin@apple.com>
+
+        Eliminate ResourceBuffer and use SharedBuffer directly instead
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+
+        Reviewed by Antti Koivisto.
+
+        * WebDataSource.cpp:
+        (WebDataSource::data): Use SharedBuffer directly.
+        (WebDataSource::subresourceForURL): Ditto.
+
 2014-10-20  peavo@outlook.com  <peavo@outlook.com>
 
         [WinCairo] Crash in ATI display driver in accelerated compositing mode.
index 4fbd996..9074519 100644 (file)
@@ -45,7 +45,6 @@
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/URL.h>
-#include <WebCore/ResourceBuffer.h>
 
 using namespace WebCore;
 
@@ -181,8 +180,7 @@ HRESULT STDMETHODCALLTYPE WebDataSource::data(
     if (!m_loader)
         return E_FAIL;
 
-    RefPtr<ResourceBuffer> buffer = m_loader->mainResourceData();
-    return MemoryStream::createInstance(buffer ? buffer->sharedBuffer() : 0).copyRefTo(stream);
+    return MemoryStream::createInstance(m_loader->mainResourceData()).copyRefTo(stream);
 }
 
 HRESULT WebDataSource::representation(/* [retval][out] */ IWebDocumentRepresentation** rep)
@@ -303,8 +301,7 @@ HRESULT STDMETHODCALLTYPE WebDataSource::subresourceForURL(
     if (!cachedResource)
         return E_FAIL;
 
-    ResourceBuffer* buffer = cachedResource->resourceBuffer();
-    *resource = WebResource::createInstance(buffer ? buffer->sharedBuffer() : 0, cachedResource->response());
+    *resource = WebResource::createInstance(cachedResource->resourceBuffer(), cachedResource->response());
     return S_OK;
 }
 
index a760842..ee84ac4 100644 (file)
@@ -235,7 +235,6 @@ set(WebKit2_SOURCES
     Shared/WebProcessCreationParameters.cpp
     Shared/WebRenderLayer.cpp
     Shared/WebRenderObject.cpp
-    Shared/WebResourceBuffer.cpp
     Shared/WebTouchEvent.cpp
     Shared/WebWheelEvent.cpp
 
index cc3cbcb..d5a6fac 100644 (file)
@@ -1,3 +1,63 @@
+2014-10-30  Darin Adler  <darin@apple.com>
+
+        Eliminate ResourceBuffer and use SharedBuffer directly instead
+        https://bugs.webkit.org/show_bug.cgi?id=138174
+
+        Reviewed by Antti Koivisto.
+
+        * CMakeLists.txt: Removed WebResourceBuffer.cpp.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::sendBuffer): Use a reference instead of pointer.
+        * NetworkProcess/NetworkResourceLoader.h: Ditto.
+        * NetworkProcess/mac/NetworkDiskCacheMonitor.h: Ditto.
+        * NetworkProcess/mac/NetworkDiskCacheMonitor.mm:
+        (WebKit::NetworkDiskCacheMonitor::resourceBecameFileBacked): Ditto.
+        * NetworkProcess/mac/NetworkResourceLoaderMac.mm:
+        (WebKit::NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer): Ditto.
+
+        * Shared/WebResourceBuffer.cpp: Removed.
+        * Shared/WebResourceBuffer.h: Removed.
+
+        * WebKit2.xcodeproj/project.pbxproj: Removed WebResourceBuffer.cpp/h.
+
+        * WebProcess/Network/NetworkProcessConnection.cpp: Removed unneeded includes.
+        (WebKit::NetworkProcessConnection::didCacheResource): Use a reference instead
+        of a pointer.
+
+        * WebProcess/Network/WebResourceLoadScheduler.cpp: Removed unneeded include.
+        * WebProcess/Network/WebResourceLoader.cpp: Ditto.
+        * WebProcess/Network/WebResourceLoader.h: Ditto.
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: Ditto.
+        (WebKit::WebFrameLoaderClient::finishedLoading): Use SharedBuffer directly.
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::source): Ditto.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::runJavaScriptInMainFrame): Refactored to make the relationship
+        between the buffer and the DataReference clearer and to avoid having a long-lived
+        DataReference pointing to an underlying buffer with unclear lifetime.
+        (WebKit::WebPage::getContentsAsString): Ditto.
+        (WebKit::WebPage::getSelectionAsWebArchiveData): Ditto.
+        (WebKit::WebPage::getMainResourceDataOfFrame): Ditto. Also use SharedBuffer directly.
+        (WebKit::WebPage::getResourceDataFromFrame): Ditto.
+        (WebKit::WebPage::getWebArchiveOfFrame): Ditto.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::containingLinkElement): Use elementLineage.
+        (WebKit::WebPage::performActionOnElement): Use references and SharedBuffer.
+        ALso did a bit of other cleanup in here.
+        (WebKit::isAssistableElement): Take Element& instead of Node*, since that's what
+        the caller has.
+        (WebKit::nextAssistableElement): Changed name to match what the function does.
+        Added an obviously-missing check on the startNode argument. Updated for change
+        to isAssistableElement above. Take a Page& instead of a Page*.
+        (WebKit::hasAssistableElement): Changed name to match what the function does.
+        Updated for change to nextAssistableElement above. Took out incorrect comparison
+        of a C++ pointer to the Objective-C object pointer nil. Take a Page& instead of a Page*.
+        (WebKit::WebPage::focusNextAssistedNode): Updated for above changes.
+        (WebKit::WebPage::getAssistedNodeInformation): Updated for above changes.
+
 2014-10-30  Jer Noble  <jer.noble@apple.com>
 
         [EME] Add Setting for accessing storage location for MediaKeys data
index 954bba4..8e3e258 100644 (file)
@@ -45,7 +45,6 @@
 #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>
@@ -409,18 +408,20 @@ 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 anymore 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 any more 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 273e131..9cee861 100644 (file)
@@ -46,7 +46,6 @@ typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
 
 namespace WebCore {
 class BlobDataFileReference;
-class ResourceBuffer;
 class ResourceHandle;
 class ResourceRequest;
 }
@@ -92,7 +91,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 bd8c0b0..583cedb 100644 (file)
@@ -48,7 +48,7 @@ private:
     NetworkDiskCacheMonitor(CFCachedURLResponseRef, NetworkResourceLoader*);
 
     // WebCore::DiskCacheMonitor
-    virtual void resourceBecameFileBacked(PassRefPtr<WebCore::SharedBuffer>) override;
+    virtual void resourceBecameFileBacked(WebCore::SharedBuffer&) override;
 
     // IPC::MessageSender
     virtual IPC::Connection* messageSenderConnection() override;
index a23c58b..551d076 100644 (file)
@@ -59,10 +59,10 @@ NetworkDiskCacheMonitor::NetworkDiskCacheMonitor(CFCachedURLResponseRef cachedRe
 {
 }
 
-void NetworkDiskCacheMonitor::resourceBecameFileBacked(PassRefPtr<SharedBuffer> fileBackedBuffer)
+void NetworkDiskCacheMonitor::resourceBecameFileBacked(SharedBuffer& fileBackedBuffer)
 {
     ShareableResource::Handle handle;
-    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(handle, fileBackedBuffer.get());
+    NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(handle, fileBackedBuffer);
     if (handle.isNull())
         return;
 
index 43aee0a..e1337d0 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,7 +102,8 @@ void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResou
 
     tryGetShareableHandleFromCFData(handle, data);
 }
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+
+#endif // IOS || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
 size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
 {
@@ -110,6 +111,7 @@ size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
 }
 
 #if USE(CFNETWORK)
+
 void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, CFCachedURLResponseRef cfResponse)
 {
     ASSERT_UNUSED(handle, handle == m_handle);
@@ -133,6 +135,7 @@ void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCac
 
     m_handle->continueWillCacheResponse(nsResponse);
 }
+
 #endif // !USE(CFNETWORK)
 
 } // namespace WebKit
index 4f8f48d..e6806b0 100644 (file)
@@ -83,21 +83,27 @@ 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;
     }
 
-    size_t size() const { return m_buffer->size(); }
+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;
     const uint8_t* data() const = delete;
     Vector<uint8_t> vector() const = delete;
 
-    void encode(ArgumentEncoder&) const override;
-    virtual ~SharedBufferDataReference() { m_buffer = 0; }
+    virtual void encode(ArgumentEncoder&) const override;
 
-private:
     RefPtr<WebCore::SharedBuffer> m_buffer;
 };
 
diff --git a/Source/WebKit2/Shared/WebResourceBuffer.cpp b/Source/WebKit2/Shared/WebResourceBuffer.cpp
deleted file mode 100644 (file)
index 54b9eb3..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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
deleted file mode 100644 (file)
index 69b4959..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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 d8a4ebc..4dbf66a 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 7719645..671a17e 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>
 
@@ -95,7 +93,7 @@ void NetworkProcessConnection::didCacheResource(const ResourceRequest& request,
         return;
     }
 
-    resource->tryReplaceEncodedData(buffer.release());
+    resource->tryReplaceEncodedData(*buffer);
 }
 #endif
 
index 1a7f9c1..88cb064 100644 (file)
@@ -46,7 +46,6 @@
 #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 85adfbb..c5eb423 100644 (file)
@@ -38,7 +38,6 @@
 #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 dc9aa0f..6b92842 100644 (file)
@@ -46,7 +46,6 @@ class DataReference;
 namespace WebCore {
 class CertificateInfo;
 class ProtectionSpace;
-class ResourceBuffer;
 class ResourceError;
 class ResourceLoader;
 class ResourceRequest;
index 91f8e8f..9ce0bef 100644 (file)
@@ -74,7 +74,6 @@
 #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>
@@ -919,7 +918,7 @@ void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
             if (!webPage)
                 return;
 
-            RefPtr<ResourceBuffer> mainResourceData = loader->mainResourceData();
+            RefPtr<SharedBuffer> 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 54e0b7d..9dcee46 100644 (file)
@@ -65,7 +65,6 @@
 #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>
@@ -305,7 +304,7 @@ String WebFrame::source() const
     DocumentLoader* documentLoader = m_coreFrame->loader().activeDocumentLoader();
     if (!documentLoader)
         return String();
-    RefPtr<ResourceBuffer> mainResourceData = documentLoader->mainResourceData();
+    RefPtr<SharedBuffer> mainResourceData = documentLoader->mainResourceData();
     if (!mainResourceData)
         return String();
     return decoder->encoding().decode(mainResourceData->data(), mainResourceData->size());
index 5fedf69..d40249a 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>
@@ -2433,17 +2432,16 @@ 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()) {
-        if ((serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(), toRef(m_mainFrame->coreFrame()->script().globalObject(mainThreadNormalWorld())->globalExec(), resultValue), 0)))
-            dataReference = serializedResultValue->data();
+        serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(),
+            toRef(m_mainFrame->coreFrame()->script().globalObject(mainThreadNormalWorld())->globalExec(), resultValue), nullptr);
     }
 
+    IPC::DataReference dataReference;
+    if (serializedResultValue)
+        dataReference = serializedResultValue->data();
     send(Messages::WebPageProxy::ScriptValueCallback(dataReference, callbackID));
 }
 
@@ -2456,15 +2454,14 @@ 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
@@ -2487,20 +2484,17 @@ 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
 
-    Frame* frame = frameWithSelection(m_page.get());
-    if (frame) {
-        archive = LegacyWebArchive::createFromSelection(frame);
-        data = archive->rawDataRepresentation();
+    IPC::DataReference dataReference;
+#if PLATFORM(COCOA)
+    if (data)
         dataReference = IPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
-    }
 #endif
-
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
@@ -2523,24 +2517,20 @@ void WebPage::getSourceForFrame(uint64_t frameID, uint64_t callbackID)
 
 void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
 {
-    IPC::DataReference dataReference;
-
-    RefPtr<ResourceBuffer> buffer;
-    RefPtr<SharedBuffer> pdfResource;
+    RefPtr<SharedBuffer> buffer;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
-        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());
-            }
+        if (PluginView* pluginView = pluginViewForFrame(frame->coreFrame()))
+            buffer = pluginView->liveResourceData();
+        if (!buffer) {
+            if (DocumentLoader* loader = frame->coreFrame()->loader().documentLoader())
+                buffer = loader->mainResourceData();
         }
     }
 
+    // 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));
 }
 
@@ -2559,38 +2549,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)) {
-        if ((data = frame->webArchiveData(0, 0)))
-            dataReference = IPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
-    }
+    if (WebFrame* frame = WebProcess::shared().webFrame(frameID))
+        data = frame->webArchiveData(nullptr, nullptr);
 #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 75571cb..a46dd40 100644 (file)
@@ -81,7 +81,6 @@
 #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,10 +1841,11 @@ void WebPage::getAutocorrectionContext(String& contextBefore, String& markedText
 
 static Element* containingLinkElement(Element* element)
 {
-    for (Element* currentElement = element; currentElement; currentElement = currentElement->parentElement())
-        if (currentElement->isLink())
-            return currentElement;
-    return 0;
+    for (auto& currentElement : elementLineage(element)) {
+        if (currentElement.isLink())
+            return &currentElement;
+    }
+    return nullptr;
 }
 
 void WebPage::getPositionInformation(const IntPoint& point, InteractionInformationAtPosition& info)
@@ -1949,73 +1949,77 @@ void WebPage::performActionOnElement(uint32_t action)
     if (!is<HTMLElement>(m_interactionNode.get()))
         return;
 
-    HTMLElement* element = downcast<HTMLElement>(m_interactionNode.get());
-    if (!element->renderer())
+    HTMLElement& element = downcast<HTMLElement>(*m_interactionNode);
+    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->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());
+                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());
         }
     } else if (static_cast<SheetAction>(action) == SheetAction::SaveImage) {
-        if (!is<RenderImage>(*element->renderer()))
+        if (!is<RenderImage>(*element.renderer()))
             return;
-        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));
-            }
-        }
+        CachedImage* cachedImage = downcast<RenderImage>(*element.renderer()).cachedImage();
+        if (!cachedImage)
+            return;
+        buffer = cachedImage->resourceBuffer();
+        if (!buffer)
+            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));
     }
 }
 
-static inline bool isAssistableNode(Node* node)
+static inline bool isAssistableElement(Element& 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& element = downcast<HTMLInputElement>(*node);
-        return !element.isReadOnlyNode() && (element.isTextField() || element.isDateField() || element.isDateTimeLocalField() || element.isMonthField() || element.isTimeField());
+    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());
     }
-
-    return node->isContentEditable();
+    return node.isContentEditable();
 }
 
-static inline Element* nextFocusableElement(Node* startNode, Page* page, bool isForward)
+static inline Element* nextAssistableElement(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 && !isAssistableNode(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 && !isAssistableElement(*nextElement));
 
     return nextElement;
 }
 
-static inline bool hasFocusableElement(Node* startNode, Page* page, bool isForward)
+static inline bool hasAssistableElement(Node* startNode, Page& page, bool isForward)
 {
-    return nextFocusableElement(startNode, page, isForward) != nil;
+    return nextAssistableElement(startNode, page, isForward);
 }
 
 void WebPage::focusNextAssistedNode(bool isForward)
 {
-    Element* nextElement = nextFocusableElement(m_assistedNode.get(), m_page.get(), isForward);
+    Element* nextElement = nextAssistableElement(m_assistedNode.get(), *m_page, isForward);
     m_userIsInteracting = true;
     if (nextElement)
         nextElement->focus();
@@ -2056,8 +2060,8 @@ void WebPage::getAssistedNodeInformation(AssistedNodeInformation& information)
     information.minimumScaleFactor = minimumPageScaleFactor();
     information.maximumScaleFactor = maximumPageScaleFactor();
     information.allowsUserScaling = m_viewportConfiguration.allowsUserScaling();
-    information.hasNextNode = hasFocusableElement(m_assistedNode.get(), m_page.get(), true);
-    information.hasPreviousNode = hasFocusableElement(m_assistedNode.get(), m_page.get(), false);
+    information.hasNextNode = hasAssistableElement(m_assistedNode.get(), *m_page, true);
+    information.hasPreviousNode = hasAssistableElement(m_assistedNode.get(), *m_page, false);
 
     if (is<HTMLSelectElement>(*m_assistedNode)) {
         HTMLSelectElement& element = downcast<HTMLSelectElement>(*m_assistedNode);