Bug 887928 - document.referrer should be based on the incument script settings object. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 03 Jan 2014 14:37:17 -0800
changeset 162109 5370ef3abcdceb9805c342d64ec76f5c17a4da38
parent 162108 1d193264de9d2d992144245353db8a0fe68c08bf
child 162110 42ac1de2e3f78f7dd864af478a07f516398495bd
push id38088
push userbobbyholley@gmail.com
push dateFri, 03 Jan 2014 22:37:27 +0000
treeherdermozilla-inbound@5370ef3abcdc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs887928
milestone29.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 887928 - document.referrer should be based on the incument script settings object. r=bz
dom/base/nsLocation.cpp
dom/tests/mochitest/bugs/test_bug593174.html
dom/tests/mochitest/bugs/test_bug809290.html
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -25,16 +25,17 @@
 #include "nsError.h"
 #include "nsDOMClassInfoID.h"
 #include "nsReadableUtils.h"
 #include "nsITextToSubURI.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
 #include "mozilla/Likely.h"
 #include "nsCycleCollectionParticipant.h"
+#include "ScriptSettings.h"
 
 static nsresult
 GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
 {
   aCharset.Truncate();
 
   JSContext *cx = nsContentUtils::GetCurrentJSContext();
   if (cx) {
@@ -118,20 +119,20 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDo
     // push/replaceState, if possible.  First, get the document corresponding to
     // fp.  If the document's original URI (i.e. its URI before
     // push/replaceState) matches the principal's URI, use the document's
     // current URI as the referrer.  If they don't match, use the principal's
     // URI.
 
     nsCOMPtr<nsIDocument> doc;
     nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI;
-    nsCOMPtr<nsPIDOMWindow> entryPoint =
-      do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
-    if (entryPoint) {
-      doc = entryPoint->GetDoc();
+    nsCOMPtr<nsPIDOMWindow> incumbent =
+      do_QueryInterface(mozilla::dom::GetIncumbentGlobal());
+    if (incumbent) {
+      doc = incumbent->GetDoc();
     }
     if (doc) {
       docOriginalURI = doc->GetOriginalURI();
       docCurrentURI = doc->GetDocumentURI();
       rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI));
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
--- a/dom/tests/mochitest/bugs/test_bug593174.html
+++ b/dom/tests/mochitest/bugs/test_bug593174.html
@@ -51,25 +51,18 @@ function iframeLoaded(identifier) {
 
     // We'll get a call to iframeLoaded when this finishes.
     iframeCw.navigateInnerIframe();
   }
   else if (loadCount == 3) {
     is(iframeCw.getInnerIframeReferrer(), iframeCw.location, 'inner iframe referrer');
 
     // Now do the test again, this time with a popup.
-    //
-    // NB: in this situation, we're actually getting called in an event handler from
-    // the iframe, meaning that it serves as the script entry point. But that's a detail,
-    // and we want to pretend like this window is doing the call. So let's use setTimeout
-    // to forget about the iframe.
-    window.setTimeout(function() {
-      popup = window.open('file_bug593174_1.html');
-      popup.onload = iframeLoaded('popup/outer');
-    }, 0);
+    popup = window.open('file_bug593174_1.html');
+    popup.onload = iframeLoaded('popup/outer');
   }
   else if (loadCount == 4) {
     history.replaceState('', '', Math.random());
 
     popup.onload = null;
     popup.location = 'file_bug593174_2.html';
   }
   else if (loadCount == 5) {
--- a/dom/tests/mochitest/bugs/test_bug809290.html
+++ b/dom/tests/mochitest/bugs/test_bug809290.html
@@ -13,29 +13,35 @@ https://bugzilla.mozilla.org/show_bug.cg
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=809290">Mozilla Bug 809290</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
-/** Test for Bug 809290 **/
+/*
+ * Test for Bug 809290.
+ *
+ * This test used to check that the referrer was the entry settings object.
+ * Due to spec changes, we now need to check that the referrer is the incumbent
+ * settings object.
+ */
 SimpleTest.waitForExplicitFinish();
 
 var gNotifyCount = 0;
+var base = window.location.href.replace(/test_bug.*/, '');
 function notifyReferrer(referrer) {
   ++gNotifyCount;
   if (gNotifyCount == 1) {
-    is(referrer, window.location.href, "Referrer should be the script entry point (this script)");
+    is(referrer, base + 'file_bug809290_b1.html', "Referrer should come from the incumbent script settings object (1)");
     document.getElementById('ifr').setAttribute('src', 'file_bug809290_b2.html');
   } else {
-    is(gNotifyCount, 2);
-    is(referrer, window.location.href.replace(/test_bug.*/, 'file_bug809290_b2.html'),
-       "Referrer should be the script entry point (iframe)");
+    is(gNotifyCount, 2, "notify count");
+    is(referrer, base + 'file_bug809290_b2.html', "Referrer should come from the the incumbent script settings object (2)");
     SimpleTest.finish();
   }
 }
 
 function go() {
   var ifr = document.getElementById('ifr');
   ifr.onload = null;
   ifr.contentWindow.innerLoad();