Reviewers: abarth, Nate Chapin,
Message:
PTAL?
Description:
REGRESSION(r157081): Fix multipart handling of ResourceFetcher
r157081 broke multipart handling in ResourceFetcher.
The breakage was harmless except Motion JPEG case - ResourceFetcher
lost the reference to Motion JPEG resource so it was no longer
able to cancel the ongoing resource fetching.
This change makes the tracking working again.
Also, the change adds a stopFetching() call to DocumentLoder::stopLoading()
that is used to be there but was lost at some point.
TEST=stop-loading.html
R=
jap...@chromium.org,
aba...@chromium.org
BUG=309641
Please review this at
https://codereview.chromium.org/242373002/
SVN Base: svn://
svn.chromium.org/blink/trunk
Affected files (+36, -7 lines):
A LayoutTests/http/tests/multipart/stop-loading.html
A + LayoutTests/http/tests/multipart/stop-loading-expected.txt
M Source/core/fetch/ResourceFetcher.cpp
M Source/core/loader/DocumentLoader.cpp
Index: LayoutTests/http/tests/multipart/stop-loading-expected.txt
diff --git
a/LayoutTests/http/tests/security/calling-versus-current-expected.txt
b/LayoutTests/http/tests/multipart/stop-loading-expected.txt
similarity index 100%
copy from
LayoutTests/http/tests/security/calling-versus-current-expected.txt
copy to LayoutTests/http/tests/multipart/stop-loading-expected.txt
Index: LayoutTests/http/tests/multipart/stop-loading.html
diff --git a/LayoutTests/http/tests/multipart/stop-loading.html
b/LayoutTests/http/tests/multipart/stop-loading.html
new file mode 100644
index
0000000000000000000000000000000000000000..c5665aab692ced021d82911b43ad40d83f0ed609
--- /dev/null
+++ b/LayoutTests/http/tests/multipart/stop-loading.html
@@ -0,0 +1,25 @@
+<html>
+<head>
+<script>
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
+function firstPartLoaded()
+{
+ window.stop();
+ window.setTimeout(function() {
+ var broken = (testingImage.width != 2 && testingImage != 76);
+ document.getElementById("results").innerHTML =
broken ? "PASS" : "FAIL";
+ if (window.testRunner)
+ testRunner.notifyDone();
+ }, 100);
+}
+</script>
+</head>
+<body>
+<img id=testingImage
src="resources/multipart.php?interval=1&loop=1&img1=2x2-green.png&img2=abe.png"
onload="firstPartLoaded()">
+<p id="results"></p>
+</body>
+</html>
Index: Source/core/fetch/ResourceFetcher.cpp
diff --git a/Source/core/fetch/ResourceFetcher.cpp
b/Source/core/fetch/ResourceFetcher.cpp
index
48ef9d71fca50d00a5308b29ee33d42409e5173d..d90fbdec68168b13bc0030d4d9e8faa4888ef188
100644
--- a/Source/core/fetch/ResourceFetcher.cpp
+++ b/Source/core/fetch/ResourceFetcher.cpp
@@ -1250,10 +1250,10 @@ void ResourceFetcher::didDownloadData(const
Resource* resource, int dataLength,
void
ResourceFetcher::subresourceLoaderFinishedLoadingOnePart(ResourceLoader*
loader)
{
- if (m_multipartLoaders)
- m_multipartLoaders->add(loader);
- if (m_loaders)
- m_loaders->remove(loader);
+ if (!m_multipartLoaders)
+ m_multipartLoaders = adoptPtr(new ResourceLoaderSet());
+ m_multipartLoaders->add(loader);
+ m_loaders->remove(loader);
if (LocalFrame* frame = this->frame())
return frame->loader().checkLoadComplete(m_documentLoader);
}
@@ -1270,9 +1270,10 @@ void
ResourceFetcher::didInitializeResourceLoader(ResourceLoader* loader)
void ResourceFetcher::willTerminateResourceLoader(ResourceLoader* loader)
{
- if (!m_loaders || !m_loaders->contains(loader))
- return;
- m_loaders->remove(loader);
+ if (m_loaders && m_loaders->contains(loader))
+ m_loaders->remove(loader);
+ if (m_multipartLoaders && m_multipartLoaders->contains(loader))
+ m_multipartLoaders->remove(loader);
if (LocalFrame* frame = this->frame())
frame->loader().checkLoadComplete(m_documentLoader);
}
Index: Source/core/loader/DocumentLoader.cpp
diff --git a/Source/core/loader/DocumentLoader.cpp
b/Source/core/loader/DocumentLoader.cpp
index
e57453a91dbb40af78a00c064845f893fed506fb..9363f43c5e4d81f6ce3a4f43e43e3d7fbe158a2c
100644
--- a/Source/core/loader/DocumentLoader.cpp
+++ b/Source/core/loader/DocumentLoader.cpp
@@ -188,8 +188,11 @@ void DocumentLoader::stopLoading()
m_frame->loader().stopLoading();
}
- if (!loading)
+ if (!loading) {
+ // This is needed to cancel multipart loading which can be
happening even after the frame is loaded.
+ m_fetcher->stopFetching();
return;
+ }
if (m_loadingMainResource) {
// Stop the main resource loader and let it send the cancelled
message.