Cherry-pick r292801. rdar://problem/91346216
Crash under CachedResourceClientWalker<WebCore::CachedImageClient>::next()
https://bugs.webkit.org/show_bug.cgi?id=239253
<rdar://91346216>
Reviewed by Simon Fraser and Brent Fulgham.
I haven't been able to reproduce the issue or figure out why this is happening so I am doing
some hardening and adding assertions to help catch the underlying bug.
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::didUpdateCachedImage):
There is some speculation that r291141 could have caused this because of the timing of when
this patch landed and the fact that this patch modifies ImageLoader, which is a CachedImageClient.
I couldn't see anything wrong with the change. However, I did notice that we were calling
didUpdateCachedImage() twice with the same CachedImage now for lazy loading (once initially and then
another time when the image actually starts lazily). This was intentional. However, the registering
again as a client of the CachedImage (and then unregistering right away) was not. Technically, this
should be fine since CachedResource is using a HashCountedSet for m_clients locally. However, for
the sake of safety, I am now not doing this redundant registering/unregistering as a client of
the CachedImage when this image has not changed.
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::checkNotify):
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::checkNotify):
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::load):
(WebCore::CachedImage::addClientWaitingForAsyncDecoding):
(WebCore::CachedImage::notifyObservers):
(WebCore::CachedImage::canDestroyDecodedData):
(WebCore::CachedImage::imageFrameAvailable):
(WebCore::CachedImage::scheduleRenderingUpdate):
(WebCore::CachedImage::isVisibleInViewport):
(WebCore::CachedImage::isVisibleInViewport const): Deleted.
* loader/cache/CachedImage.h:
* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::notifyClientsDataWasReceived):
(WebCore::iterateRedirects):
(WebCore::CachedRawResource::redirectReceived):
The new assertions found a bug here where we were capturing the CachedRawResourceClient by value in the lambda and thus
making a copy of it (even though this is a polymorphic class). I fixed the bug and marked CachedResourceClient as non
copyable to avoid issues like these.
(WebCore::CachedRawResource::responseReceived):
(WebCore::CachedRawResource::shouldCacheResponse):
(WebCore::CachedRawResource::didSendData):
(WebCore::CachedRawResource::finishedTimingForWorkerLoad):
(WebCore::CachedRawResource::previewResponseReceived):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::checkNotify):
(WebCore::CachedResource::didAddClient):
(WebCore::CachedResource::addClientToSet):
(WebCore::CachedResource::removeClient):
* loader/cache/CachedResource.h:
* loader/cache/CachedResourceClient.h:
(WebCore::CachedResourceClient::~CachedResourceClient):
(WebCore::CachedResourceClient::addAssociatedResource):
(WebCore::CachedResourceClient::removeAssociatedResource):
Add new assertions to make sure that a CachedResourceClient is no longer associated (i.e. marked as a client of) with
any CachedResource at the time it is destroyed. Hopefully, this will catch the issue right away and give us a useful
stack trace, instead of crashing later on when iterating over the clients of a CachedResource.
* loader/cache/CachedResourceClientWalker.h:
(WebCore::CachedResourceClientWalker::CachedResourceClientWalker):
(WebCore::CachedResourceClientWalker::next):
CachedResourceClientWalker is meant to be a safe way of iterating over the clients of a CachedResource, allowing clients
to unregister themselves as we iterate. However, when clients unregister themselves, it could in theory cause the
CachedResource itself to get destroyed. In such cases, the CachedResourceClientWalker would not be safe since its
m_clientSet data member would come from a dead CachedResource. To address the issue, the walker now keeps a handle to
the cached resource, instead of the reference to the CachedResource's clients set. The handle will ensure the cached
resource stays alive.
* loader/cache/CachedScript.cpp:
* loader/cache/CachedTextTrack.cpp:
(WebCore::CachedTextTrack::doUpdateBuffer):
* loader/cache/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::checkNotify):
* rendering/RenderObject.cpp:
Canonical link: https://commits.webkit.org/249583@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292801 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Canonical link: https://commits.webkit.org/[email protected]
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-613.2.6.0-branch@292823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.
Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.
On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.
Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.
On Windows, follow the instructions on our website.
Run the following command to clone WebKit's Git SVN repository:
git clone [email protected]:WebKit/WebKit.git WebKit
or
git clone https://github.com/WebKit/WebKit.git WebKit
If you want to be able to track Subversion revision from your git checkout, you can run the following command to do so:
Tools/Scripts/git-webkit setup-git-svn
For information about this, and other aspects of using Git with WebKit, read the wiki page.
If you don‘t want to use Git, run the following command to check out WebKit’s Subversion repository:
svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit
Install Xcode and its command line tools if you haven't done so already:
xcode-select --installRun the following command to build a debug build with debugging symbols and assertions:
Tools/Scripts/build-webkit --debug
For performance testing, and other purposes, use --release instead.
You can open WebKit.xcworkspace to build and debug WebKit within Xcode.
If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild for both Products and Intermediates.
iOS, tvOS and watchOS are all considered embedded builds. The first time after you install a new Xcode, you will need to run:
sudo Tools/Scripts/configure-xcode-for-embedded-development
Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.” when building target JSCLLIntOffsetsExtractor of project JavaScriptCore.
Run the following command to build a debug build with debugging symbols and assertions for embededded simulators:
Tools/Scripts/build-webkit --debug --<platform>-simulator
or embedded devices:
Tools/Scripts/build-webkit --debug --<platform>-device
where platform is ios, tvos or watchos.
For production builds:
cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/gtk/install-dependencies Tools/Scripts/update-webkitgtk-libs Tools/Scripts/build-webkit --gtk --debug
For more information on building WebKitGTK+, see the wiki page.
For production builds:
cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/wpe/install-dependencies Tools/Scripts/update-webkitwpe-libs Tools/Scripts/build-webkit --wpe --debug
For building WebKit on Windows, see the wiki page.
Run the following command to launch Safari with your local build of WebKit:
Tools/Scripts/run-safari --debug
The run-safari script sets the DYLD_FRAMEWORK_PATH environment variable to point to your build products, and then launches /Applications/Safari.app. DYLD_FRAMEWORK_PATH tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks.
To run other applications with your local build of WebKit, run the following command:
Tools/Scripts/run-webkit-app <application-path>
Run the following command to launch iOS simulator with your local build of WebKit:
run-safari --debug --ios-simulator
In both cases, if you have built release builds instead, use --release instead of --debug.
If you have a development build, you can use the run-minibrowser script, e.g.:
run-minibrowser --debug --wpe
Pass one of --gtk, --jsc-only, or --wpe to indicate the port to use.
Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.