Bug 1217571 - fix the imagelib cache to work in e10s; r=seth

nsICachingChannel isn't available in the child process; we have to use
nsICacheInfoChannel instead.
This commit is contained in:
Nathan Froyd 2015-11-12 15:09:52 -05:00
parent a064648b31
commit 70563b2178
6 changed files with 77 additions and 26 deletions

View File

@ -42,11 +42,8 @@
case 2: case 2:
is(e.data.url, "image-40px.png", "Correct url expected"); is(e.data.url, "image-40px.png", "Correct url expected");
is(e.data.url2, "image-40px.png", "Correct url expected"); is(e.data.url2, "image-40px.png", "Correct url expected");
// TODO: Uncomment this check when bug 1217571 gets fixed. is(e.data.width, 40, "Correct width expected");
// Currently because of bug 1217571, the QI in imgCacheValidator::OnStartRequest() is(e.data.width2, 40, "Correct width expected");
// to nsICachingChannel fails, which causes the check below to fail in non-e10s.
//is(e.data.width, 40, "Correct width expected");
//is(e.data.width2, 40, "Correct width expected");
iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/imagecache-maxage/unregister.html"; iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/imagecache-maxage/unregister.html";
break; break;
default: default:

View File

@ -25,7 +25,7 @@
#include "nsMimeTypes.h" #include "nsMimeTypes.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
#include "nsIHttpChannel.h" #include "nsIHttpChannel.h"
#include "nsICachingChannel.h" #include "nsICacheInfoChannel.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
@ -2346,7 +2346,7 @@ imgLoader::LoadImageWithChannel(nsIChannel* channel,
nullptr, imgIRequest::CORS_NONE)) { nullptr, imgIRequest::CORS_NONE)) {
request = entry->GetRequest(); request = entry->GetRequest();
} else { } else {
nsCOMPtr<nsICachingChannel> cacheChan(do_QueryInterface(channel)); nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
bool bUseCacheCopy; bool bUseCacheCopy;
if (cacheChan) { if (cacheChan) {
@ -2722,7 +2722,7 @@ imgCacheValidator::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
// If this request is coming from cache and has the same URI as our // If this request is coming from cache and has the same URI as our
// imgRequest, the request all our proxies are pointing at is valid, and all // imgRequest, the request all our proxies are pointing at is valid, and all
// we have to do is tell them to notify their listeners. // we have to do is tell them to notify their listeners.
nsCOMPtr<nsICachingChannel> cacheChan(do_QueryInterface(aRequest)); nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(aRequest));
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest)); nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
if (cacheChan && channel && !mRequest->CacheChanged(aRequest)) { if (cacheChan && channel && !mRequest->CacheChanged(aRequest)) {
bool isFromCache = false; bool isFromCache = false;

View File

@ -17,7 +17,7 @@
#include "RasterImage.h" #include "RasterImage.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsICachingChannel.h" #include "nsICacheInfoChannel.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIThreadRetargetableRequest.h" #include "nsIThreadRetargetableRequest.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
@ -32,8 +32,6 @@
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsICacheEntry.h"
#include "plstr.h" // PL_strcasestr(...) #include "plstr.h" // PL_strcasestr(...)
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIProtocolHandler.h" #include "nsIProtocolHandler.h"
@ -586,22 +584,15 @@ imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry, nsIRequest* aRequest)
{ {
/* get the expires info */ /* get the expires info */
if (aCacheEntry) { if (aCacheEntry) {
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aRequest)); nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(aRequest));
if (cacheChannel) { if (cacheChannel) {
nsCOMPtr<nsISupports> cacheToken; uint32_t expiration = 0;
cacheChannel->GetCacheToken(getter_AddRefs(cacheToken)); /* get the expiration time from the caching channel's token */
if (cacheToken) { if (NS_SUCCEEDED(cacheChannel->GetCacheTokenExpirationTime(&expiration))) {
nsCOMPtr<nsICacheEntry> entryDesc(do_QueryInterface(cacheToken)); // Expiration time defaults to 0. We set the expiration time on our
if (entryDesc) { // entry if it hasn't been set yet.
uint32_t expiration; if (aCacheEntry->GetExpiryTime() == 0) {
/* get the expiration time from the caching channel's token */ aCacheEntry->SetExpiryTime(expiration);
entryDesc->GetExpirationTime(&expiration);
// Expiration time defaults to 0. We set the expiration time on our
// entry if it hasn't been set yet.
if (aCacheEntry->GetExpiryTime() == 0) {
aCacheEntry->SetExpiryTime(expiration);
}
} }
} }
} }

View File

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1217571
-->
<head>
<title>iframe for Bug 1217571</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<img src="damon.jpg">
</div>
</body>
</html>

View File

@ -32,6 +32,7 @@ support-files =
bug900200-ref.png bug900200-ref.png
bug1180105.sjs bug1180105.sjs
bug1180105-waiter.sjs bug1180105-waiter.sjs
bug1217571-iframe.html
clear.gif clear.gif
clear.png clear.png
clear2.gif clear2.gif
@ -89,6 +90,7 @@ skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
[test_bug89419-2.html] [test_bug89419-2.html]
skip-if = (toolkit == 'android' && processor == 'x86') #x86 only skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
[test_bug1180105.html] [test_bug1180105.html]
[test_bug1217571.html]
[test_animation_operators.html] [test_animation_operators.html]
[test_drawDiscardedImage.html] [test_drawDiscardedImage.html]
skip-if = toolkit == "gonk" #Bug 997034 - canvas.toDataURL() often causes lost connection to device. skip-if = toolkit == "gonk" #Bug 997034 - canvas.toDataURL() often causes lost connection to device.

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1217571
-->
<head>
<title>Test for Bug 1217571</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1217571">Mozilla Bug 1217571</a>
<p id="display"></p>
<iframe src="bug1217571-iframe.html"></iframe>
<iframe src="bug1217571-iframe.html"></iframe>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 614392**/
SimpleTest.waitForExplicitFinish();
window.onload = function() {
// Each iframe loads the same image. Both images should share the same
// container from the image cache. Check that this holds true.
var iframes = document.getElementsByTagName("iframe");
var imgs = Array.from(iframes, function (f) {
return SpecialPowers.wrap(f.contentDocument.getElementsByTagName("img")[0]);
});
var containers = imgs.map(function (img) {
return img.QueryInterface(SpecialPowers.Ci.nsIImageLoadingContent)
.getRequest(SpecialPowers.Ci.nsIImageLoadingContent.CURRENT_REQUEST)
.image;
});
ok(SpecialPowers.compare(containers[0], containers[1]),
"containers for identical images in different iframes should be identical");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>