Bug 817531. Fix the referrer header for background image loads. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 06 Dec 2012 15:21:19 -0500
changeset 115255 a381a84d7af2c324fb84a8bb3c8b84e85d6de8f4
parent 115254 c6079d201336e0d70ee5f3f84161b34eb3b1b6de
child 115256 db4197606782126847ee1e0e36c6c339e47690df
push id19240
push userbzbarsky@mozilla.com
push dateFri, 07 Dec 2012 01:40:20 +0000
treeherdermozilla-inbound@db4197606782 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs817531
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 817531. Fix the referrer header for background image loads. r=khuey
content/html/content/src/nsGenericHTMLElement.cpp
layout/reftests/backgrounds/background-referrer-image.png
layout/reftests/backgrounds/background-referrer-ref.html
layout/reftests/backgrounds/background-referrer.html
layout/reftests/backgrounds/background-referrer.sjs
layout/reftests/backgrounds/reftest.list
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2077,17 +2077,18 @@ nsGenericHTMLElement::ParseBackgroundAtt
 
     nsString value(aValue);
     nsRefPtr<nsStringBuffer> buffer = nsCSSValue::BufferFromString(value);
     if (MOZ_UNLIKELY(!buffer)) {
       return false;
     }
 
     mozilla::css::URLValue *url =
-      new mozilla::css::URLValue(buffer, baseURI, uri, NodePrincipal());
+      new mozilla::css::URLValue(uri, buffer, doc->GetDocumentURI(),
+                                 NodePrincipal());
     aResult.SetTo(url, &aValue);
     return true;
   }
 
   return false;
 }
 
 bool
copy from image/test/reftest/generic/green.png
copy to layout/reftests/backgrounds/background-referrer-image.png
copy from image/test/reftest/generic/accept-image-catchall-ref.html
copy to layout/reftests/backgrounds/background-referrer-ref.html
--- a/image/test/reftest/generic/accept-image-catchall-ref.html
+++ b/layout/reftests/backgrounds/background-referrer-ref.html
@@ -1,12 +1,11 @@
 <!DOCTYPE html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=398066
+https://bugzilla.mozilla.org/show_bug.cgi?id=817531
 -->
 <html>
 <head>
-  <title>Accept: header should include image/* catchall</title>
+  <title>Referer: header should be correct</title>
 </head>
-<body>
-<img src="green.png">
+<body background="background-referrer-image.png">
 </body>
 </html>
copy from image/test/reftest/generic/accept-image-catchall.html
copy to layout/reftests/backgrounds/background-referrer.html
--- a/image/test/reftest/generic/accept-image-catchall.html
+++ b/layout/reftests/backgrounds/background-referrer.html
@@ -1,12 +1,11 @@
 <!DOCTYPE html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=398066
+https://bugzilla.mozilla.org/show_bug.cgi?id=817531
 -->
 <html>
 <head>
-  <title>Accept: header should include image/* catchall</title>
+  <title>Referer: header should be correct</title>
 </head>
-<body>
-<img src="check-header.sjs">
+<body background="background-referrer.sjs">
 </body>
 </html>
copy from image/test/reftest/generic/check-header.sjs
copy to layout/reftests/backgrounds/background-referrer.sjs
--- a/image/test/reftest/generic/check-header.sjs
+++ b/layout/reftests/backgrounds/background-referrer.sjs
@@ -1,31 +1,25 @@
 const BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", "nsIBinaryOutputStream", "setOutputStream");
 
-function isCatchall(v)
-{
-  // "image/*" item exactly or with a quality factor
-  return /^image\/\*(?:|;q=(?:1(?:\.0{0,3})?|0(?:\.\d{0,3})?))$/.test(v);
-}
-
 /*
 # Python used to generate the following byte array
 def toHex(n):
   if n < 16: return "0x" + hex(n)[2:].upper()
   return "0x" + hex(n)[2:].upper()
 
 def hexFile(name):
   f = open(name, "rb")
   try:
     while True:
       print toHex(ord(f.read(1))) + ", ",
   except:
     pass
 
-hexFile("image/test/reftest/generic/green.png")
+hexFile("layout/reftests/backgrounds/background-referrer-image.png")
 */
 
 const IMAGE_DATA =
   [
    0x89,  0x50,  0x4E,  0x47,  0x0D,  0x0A,  0x1A,  0x0A,  0x00,  0x00,  0x00,
    0x0D,  0x49,  0x48,  0x44,  0x52,  0x00,  0x00,  0x00,  0x64,  0x00,  0x00,
    0x00,  0x64,  0x08,  0x02,  0x00,  0x00,  0x00,  0xFF,  0x80,  0x02,  0x03,
    0x00,  0x00,  0x00,  0x01,  0x73,  0x52,  0x47,  0x42,  0x00,  0xAE,  0xCE,
@@ -48,21 +42,21 @@ const IMAGE_DATA =
    0x49,  0x45,  0x4E,  0x44,  0xAE,  0x42,  0x60,  0x82,
   ];
 
 function handleRequest(request, response)
 {
   response.setHeader("Content-Type", "text/plain", false);
   response.setHeader("Cache-Control", "no-cache", false);
 
-  var accept = request.hasHeader("Accept")
-             ? request.getHeader("Accept")
-             : "";
+  var referrer = request.hasHeader("Referer") ?
+                   request.getHeader("Referer") : "";
 
-  if (accept.split(",").some(isCatchall))
+  // Test url looks like http://localhost:port/timestamp/number/background-referrer.html
+  if (/^http:\/\/localhost:[0-9]+\/[0-9]+\/[0-9]+\/background-referrer.html$/.test(referrer))
   {
     response.setHeader("Content-Type", "image/png", false);
 
     var stream = new BinaryOutputStream(response.bodyOutputStream);
     stream.writeByteArray(IMAGE_DATA, IMAGE_DATA.length);
   }
   else
   {
--- a/layout/reftests/backgrounds/reftest.list
+++ b/layout/reftests/backgrounds/reftest.list
@@ -133,8 +133,10 @@ random-if(bug685516) HTTP != root-backgr
 random-if(bug685516) == really-big-background.html really-big-background-ref.html
 random-if(bug685516) == body-background.html body-background-ref.html
 random-if(bug685516) == table-background.html table-background-ref.html
 random-if(bug685516) != div-background.html div-background-ref.html
 
 random-if(bug685516) == background-repeat-1-ref.html background-repeat-1.html
 
 random-if(bug685516) == multi-background-clip-content-border.html multi-background-clip-content-border-ref.html
+
+fails-if(Android) HTTP == background-referrer.html background-referrer-ref.html