Async loading of image resources
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 19:02:35 +0000 (19:02 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 19:02:35 +0000 (19:02 +0000)
commit919e81fdcdf9b459e88f5b9ae6e93ec0418a757d
tree9445d3a3553e67c9f269f467d29cdd40833b442e
parent2f25b56df7b4fe9da42f56bbdfa8b902dd6e6c1e
Async loading of image resources
https://bugs.webkit.org/show_bug.cgi?id=134488

Reviewed by Dean Jackson.

Source/WebCore:

This patch changes image loading to be asynchronous (per spec), in order
for it to be agnostic to property setting order when it comes to src, srcset and crossorigin,
as well as to enable future hooking of the <picture>-based selection logic on top of it.

Tests: fast/dom/HTMLImageElement/image-load-post-onload.html
fast/dom/HTMLImageElement/sizes/image-sizes-js-change-reverse.html

* WebCore.xcodeproj/project.pbxproj: Change MicroTask.h to be private.
* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::handleEvent): Add a microtask checkpoint after event handling.
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute): Add a microtask checkpoint after running of a scheduled action.
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::didMoveToNewDocument): Add the old document to call of elementDidMoveToNewDocument.
* html/HTMLImageLoader.cpp:
(WebCore::HTMLImageLoader::notifyFinished): Avoid a crash when notifyFinished is called and there's no CachedImage.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::didMoveToNewDocument): Add the old document to call of elementDidMoveToNewDocument.
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::didMoveToNewDocument): Add the old document to call of elementDidMoveToNewDocument.
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::didMoveToNewDocument): Add the old document to call of elementDidMoveToNewDocument.
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::attemptToRunDeferredScriptsAndEnd): Add a microtask checkpoint.
* loader/ImageLoader.cpp: Move image resource loading to be asynchronous.
(WebCore::ImageLoader::ImageLoaderTask::create):
(WebCore::ImageLoader::ImageLoaderTask::run): Run the image loading microtask and called doUpdateFromElement.
(WebCore::ImageLoader::ImageLoaderTask::ImageLoaderTask):
(WebCore::ImageLoader::ImageLoader):
(WebCore::ImageLoader::doUpdateFromElement): This is split from the previous updateFromElement, and performs the actual resource loading.
(WebCore::ImageLoader::updateFromElement): Now only prepares the stage for the actual image resource loading.
(WebCore::ImageLoader::shouldLoadImmediately): If this returns true, the image resource is loaded immediately, without queueing a microtask.
(WebCore::ImageLoader::notifyFinished): Add asserts.
(WebCore::ImageLoader::elementDidMoveToNewDocument): Handle document load event counters decrementing and incrementing.
* loader/ImageLoader.h:
(WebCore::ImageLoader::imageComplete): Make sure that the image is complete only if there aren't any pending tasks.
(WebCore::ImageLoader::hasPendingActivity): Make sure that pending activity takes pending tasks into account.
(WebCore::ImageLoader::hasPendingTask): Getter to know if an ImageLoader has a pending task. (Used by the image loading microtask)
(WebCore::ImageLoader::createWeakPtr): Create a weakPtr to be used by the microtask, so it can called back the loader if it's still alive.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::canRequest): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag and act upon it.
(WebCore::CachedResourceLoader::requestImage): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag.
(WebCore::CachedResourceLoader::requestResource): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag.
* loader/cache/CachedResourceLoader.h:
(WebCore::CachedResourceLoader::canRequest): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag and act upon it.
(WebCore::CachedResourceLoader::requestImage): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag.
(WebCore::CachedResourceLoader::requestResource): Add a 'shouldBypassMainWorldContentSecurityPolicy' flag.
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::didMoveToNewDocument): Add the old document to call of elementDidMoveToNewDocument.
* xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::end): Add a microtask checkpoint after XML finishes parsing.

LayoutTests:

* fast/dom/HTMLImageElement/image-load-post-onload-expected.txt: Added.
* fast/dom/HTMLImageElement/image-load-post-onload.html: Added.
* fast/dom/HTMLImageElement/image-loading-gc.html: Cosmetic changes.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-change-reverse-expected.txt: Added.
* fast/dom/HTMLImageElement/sizes/image-sizes-js-change-reverse.html: Added.
* fast/dom/image-object.html: Cosmetic changes.
* http/tests/misc/image-blocked-src-change-expected.txt: Removed line numbers from console.
* http/tests/misc/image-blocked-src-no-change-expected.txt: Removed line numbers from console.
* http/tests/security/contentSecurityPolicy/report-blocked-file-uri-expected.txt: Removed line numbers from console.
* http/tests/security/frame-loading-via-document-write-expected.txt: Removed line numbers from console.
* http/tests/security/local-image-from-remote-expected.txt: Removed line numbers from console.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182247 268f45cc-cd09-0410-ab3c-d52691b4dbfc
28 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLImageElement/image-load-post-onload-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/image-load-post-onload.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/image-loading-gc.html
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-change-reverse-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-js-change-reverse.html [new file with mode: 0644]
LayoutTests/fast/dom/image-object.html
LayoutTests/http/tests/misc/image-blocked-src-change-expected.txt
LayoutTests/http/tests/misc/image-blocked-src-no-change-expected.txt
LayoutTests/http/tests/security/contentSecurityPolicy/report-blocked-file-uri-expected.txt
LayoutTests/http/tests/security/frame-loading-via-document-write-expected.txt
LayoutTests/http/tests/security/local-image-from-remote-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSEventListener.cpp
Source/WebCore/bindings/js/ScheduledAction.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageLoader.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/HTMLVideoElement.cpp
Source/WebCore/html/parser/HTMLDocumentParser.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/ImageLoader.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/svg/SVGImageElement.cpp
Source/WebCore/xml/parser/XMLDocumentParser.cpp