Bug 1217571 - fix the imagelib cache to work in e10s; r=seth, a=ritu
authorNathan Froyd <froydnj@mozilla.com>
Thu, 12 Nov 2015 15:09:52 -0500
changeset 305523 40f1515c4d0530fcefc2f479da0a734f60ecea24
parent 305522 e7dfc76d2f5f3ae917dffec980eaaea3126c3aa3
child 305524 b5ca0fa6c80c45fac4bdff9ef218cad3766f8ce0
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth, ritu
bugs1217571
milestone44.0a2
Bug 1217571 - fix the imagelib cache to work in e10s; r=seth, a=ritu nsICachingChannel isn't available in the child process; we have to use nsICacheInfoChannel instead.
dom/workers/test/serviceworkers/test_imagecache_max_age.html
image/imgLoader.cpp
image/imgRequest.cpp
image/test/mochitest/bug1217571-iframe.html
image/test/mochitest/mochitest.ini
image/test/mochitest/test_bug1217571.html
--- a/dom/workers/test/serviceworkers/test_imagecache_max_age.html
+++ b/dom/workers/test/serviceworkers/test_imagecache_max_age.html
@@ -37,21 +37,18 @@
           // Wait for 100ms so that the image gets expired.
           setTimeout(function() {
             iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/imagecache-maxage/index.html?new"
           }, 100);
           break;
         case 2:
           is(e.data.url, "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.
-          // Currently because of bug 1217571, the QI in imgCacheValidator::OnStartRequest()
-          // 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");
+          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";
           break;
         default:
           ok(false, "This should never happen");
         }
       } else if (e.data.status == "unregistrationdone") {
         window.onmessage = null;
         SimpleTest.finish();
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -20,17 +20,17 @@
 #include "nsContentUtils.h"
 #include "nsCORSListenerProxy.h"
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIProtocolHandler.h"
 #include "nsMimeTypes.h"
 #include "nsStreamUtils.h"
 #include "nsIHttpChannel.h"
-#include "nsICachingChannel.h"
+#include "nsICacheInfoChannel.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIProgressEventSink.h"
 #include "nsIChannelEventSink.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIFileURL.h"
 #include "nsIFile.h"
 #include "nsCRT.h"
@@ -2360,17 +2360,17 @@ imgLoader::LoadImageWithChannel(nsIChann
       // Since aCanMakeNewChannel == false, we don't need to pass content policy
       // type/principal/etc
       if (ValidateEntry(entry, uri, nullptr, nullptr, RP_Default,
                         nullptr, aObserver, aCX, requestFlags,
                         nsIContentPolicy::TYPE_INVALID, false, nullptr,
                         nullptr, imgIRequest::CORS_NONE)) {
         request = entry->GetRequest();
       } else {
-        nsCOMPtr<nsICachingChannel> cacheChan(do_QueryInterface(channel));
+        nsCOMPtr<nsICacheInfoChannel> cacheChan(do_QueryInterface(channel));
         bool bUseCacheCopy;
 
         if (cacheChan) {
           cacheChan->IsFromCache(&bUseCacheCopy);
         } else {
           bUseCacheCopy = false;
         }
 
@@ -2736,17 +2736,17 @@ imgCacheValidator::OnStartRequest(nsIReq
     MOZ_ASSERT_UNREACHABLE("OnStartRequest delivered more than once?");
     aRequest->Cancel(NS_BINDING_ABORTED);
     return NS_ERROR_FAILURE;
   }
 
   // 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
   // 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));
   if (cacheChan && channel && !mRequest->CacheChanged(aRequest)) {
     bool isFromCache = false;
     cacheChan->IsFromCache(&isFromCache);
 
     nsCOMPtr<nsIURI> channelURI;
     channel->GetURI(getter_AddRefs(channelURI));
 
--- a/image/imgRequest.cpp
+++ b/image/imgRequest.cpp
@@ -12,33 +12,31 @@
 #include "DecodePool.h"
 #include "ProgressTracker.h"
 #include "ImageFactory.h"
 #include "Image.h"
 #include "MultipartImage.h"
 #include "RasterImage.h"
 
 #include "nsIChannel.h"
-#include "nsICachingChannel.h"
+#include "nsICacheInfoChannel.h"
 #include "nsIDocument.h"
 #include "nsIThreadRetargetableRequest.h"
 #include "nsIInputStream.h"
 #include "nsIMultiPartChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsIApplicationCache.h"
 #include "nsIApplicationCacheChannel.h"
 #include "nsMimeTypes.h"
 
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsContentUtils.h"
 
-#include "nsICacheEntry.h"
-
 #include "plstr.h" // PL_strcasestr(...)
 #include "nsNetUtil.h"
 #include "nsIProtocolHandler.h"
 #include "imgIRequest.h"
 
 using namespace mozilla;
 using namespace mozilla::image;
 
@@ -581,32 +579,25 @@ imgRequest::UpdateCacheEntrySize()
   mCacheEntry->SetDataSize(size);
 }
 
 void
 imgRequest::SetCacheValidation(imgCacheEntry* aCacheEntry, nsIRequest* aRequest)
 {
   /* get the expires info */
   if (aCacheEntry) {
-    nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aRequest));
+    nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(aRequest));
     if (cacheChannel) {
-      nsCOMPtr<nsISupports> cacheToken;
-      cacheChannel->GetCacheToken(getter_AddRefs(cacheToken));
-      if (cacheToken) {
-        nsCOMPtr<nsICacheEntry> entryDesc(do_QueryInterface(cacheToken));
-        if (entryDesc) {
-          uint32_t expiration;
-          /* get the expiration time from the caching channel's token */
-          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);
-          }
+      uint32_t expiration = 0;
+      /* get the expiration time from the caching channel's token */
+      if (NS_SUCCEEDED(cacheChannel->GetCacheTokenExpirationTime(&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);
         }
       }
     }
 
     // Determine whether the cache entry must be revalidated when we try to use
     // it. Currently, only HTTP specifies this information...
     nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
     if (httpChannel) {
new file mode 100644
--- /dev/null
+++ b/image/test/mochitest/bug1217571-iframe.html
@@ -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>
--- a/image/test/mochitest/mochitest.ini
+++ b/image/test/mochitest/mochitest.ini
@@ -27,16 +27,17 @@ support-files =
   bug733553.sjs
   bug767779.sjs
   bug89419-iframe.html
   bug89419.sjs
   bug900200.png
   bug900200-ref.png
   bug1180105.sjs
   bug1180105-waiter.sjs
+  bug1217571-iframe.html
   clear.gif
   clear.png
   clear2.gif
   clear2-results.gif
   damon.jpg
   error-early.png
   green.png
   green-background.html
@@ -84,16 +85,17 @@ skip-if = (toolkit == 'android' && proce
 [test_bug733553.html]
 [test_bug767779.html]
 [test_bug865919.html]
 [test_bug89419-1.html]
 skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
 [test_bug89419-2.html]
 skip-if = (toolkit == 'android' && processor == 'x86') #x86 only
 [test_bug1180105.html]
+[test_bug1217571.html]
 [test_animation_operators.html]
 [test_drawDiscardedImage.html]
 skip-if = toolkit == "gonk" #Bug 997034 - canvas.toDataURL() often causes lost connection to device.
 [test_error_events.html]
 [test_short_gif_header.html]
 [test_image_buffer_limit.html]
 #skip-if = toolkit != "gonk" #Image buffer limit is only set for Firefox OS currently.
 disabled = bug 1060869
new file mode 100644
--- /dev/null
+++ b/image/test/mochitest/test_bug1217571.html
@@ -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>