Bug 1325080 - Synchronously decode image metadata for data URIs. r?tnikkel draft
authorKevin Hsieh <kevin.hsieh@ucla.edu>
Wed, 16 Aug 2017 19:04:20 -0700
changeset 647896 82622be20c8d2e9813a36f6037345601fa468f80
parent 617946 ec666e910442ae55686160c1bd0c93b00a08dead
child 726659 bcd85c0f07ab7475c6dadb4b7504c53d32dcabb6
push id74572
push userbmo:kevin.hsieh@ucla.edu
push dateThu, 17 Aug 2017 02:11:24 +0000
reviewerstnikkel
bugs1325080
milestone56.0a1
Bug 1325080 - Synchronously decode image metadata for data URIs. r?tnikkel MozReview-Commit-ID: IPrP3EepQ6a
image/ImageFactory.cpp
image/test/mochitest/mochitest.ini
image/test/mochitest/test_bug1325080.html
--- a/image/ImageFactory.cpp
+++ b/image/ImageFactory.cpp
@@ -70,16 +70,24 @@ ComputeImageFlags(ImageURL* uri, const n
   }
   if (doDecodeImmediately) {
     imageFlags |= Image::INIT_FLAG_DECODE_IMMEDIATELY;
   }
   if (isMultiPart) {
     imageFlags |= Image::INIT_FLAG_TRANSIENT;
   }
 
+  // Synchronously decode metadata (including size) if we have a data URI since
+  // the data is immediately available.
+  bool isDataURI = false;
+  rv = uri->SchemeIs("data", &isDataURI);
+  if (NS_SUCCEEDED(rv) && isDataURI) {
+    imageFlags |= Image::INIT_FLAG_SYNC_LOAD;
+  }
+
   return imageFlags;
 }
 
 /* static */ already_AddRefed<Image>
 ImageFactory::CreateImage(nsIRequest* aRequest,
                           ProgressTracker* aProgressTracker,
                           const nsCString& aMimeType,
                           ImageURL* aURI,
--- a/image/test/mochitest/mochitest.ini
+++ b/image/test/mochitest/mochitest.ini
@@ -120,16 +120,17 @@ skip-if = true # disabled - See bug 5791
 [test_bug767779.html]
 [test_bug865919.html]
 [test_bug89419-1.html]
 [test_bug89419-2.html]
 [test_bug1132427.html]
 skip-if = os == 'android'
 [test_bug1180105.html]
 [test_bug1217571.html]
+[test_bug1325080.html]
 [test_bullet_animation.html]
 skip-if = os == 'android'
 [test_changeOfSource.html]
 skip-if = os == 'android'
 [test_changeOfSource2.html]
 skip-if = os == 'android'
 [test_discardAnimatedImage.html]
 [test_drawDiscardedImage.html]
new file mode 100644
--- /dev/null
+++ b/image/test/mochitest/test_bug1325080.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1325080
+-->
+<head>
+  <title>Test for Bug 1325080</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=1325080">Mozilla Bug 1325080</a>
+<pre id="test">
+<script type="application/javascript">
+/** Test for Bug 1325080 **/
+
+SimpleTest.waitForExplicitFinish();
+
+function createImage() {
+  // This function's code comes from the Acid3 test #72
+  document.open();
+  document.write('<!DOCTYPE html><head><style>img { height: 10px; }</style></head><body><img src="data:image/gif;base64,R0lGODlhAQABAID%2FAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="alt-text"></body>');
+  document.close();
+}
+
+window.onload = function() {
+  createImage();
+  SimpleTest.executeSoon(() => {
+    ok(document.images[0].height == 10, "Style should set height of image.");
+    SimpleTest.finish();
+  });
+}
+
+</script>
+</pre>
+</body>
+</html>