Bug 1533105. Re-enable compartment sharing for content windows. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 06 Mar 2019 20:39:40 +0000
changeset 521044 817410ffd7f2
parent 521043 1d82c648684d
child 521045 234eea780806
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1533105
milestone67.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 1533105. Re-enable compartment sharing for content windows. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D22364
dom/base/nsGlobalWindowOuter.cpp
dom/base/test/test_shared_compartment1.html
dom/base/test/test_shared_compartment2.html
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -1773,17 +1773,16 @@ struct MOZ_STACK_CLASS CompartmentFinder
   // Input: we look for a compartment which is same-origin with the
   // given principal.
   nsIPrincipal* principal;
 
   // Output: We set this member if we find a compartment.
   JS::Compartment* compartment;
 };
 
-#if 0 /* Temporarily disabled; will reenable in bug 1533105 */
 static JS::CompartmentIterResult FindSameOriginCompartment(
     JSContext* aCx, void* aData, JS::Compartment* aCompartment) {
   auto* data = static_cast<CompartmentFinderState*>(aData);
   MOZ_ASSERT(!data->compartment, "Why are we getting called?");
 
   // If this compartment is not safe to share across globals, don't do
   // anything with it; in particular we should not be getting a
   // CompartmentPrivate from such a compartment, because it may be in
@@ -1798,17 +1797,16 @@ static JS::CompartmentIterResult FindSam
     // Can't reuse this one, keep going.
     return JS::CompartmentIterResult::KeepGoing;
   }
 
   // We have a winner!
   data->compartment = aCompartment;
   return JS::CompartmentIterResult::Stop;
 }
-#endif
 
 static JS::RealmCreationOptions& SelectZone(
     JSContext* aCx, nsIPrincipal* aPrincipal, nsGlobalWindowInner* aNewInner,
     JS::RealmCreationOptions& aOptions) {
   // Use the shared system compartment for chrome windows.
   if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
     return aOptions.setExistingCompartment(xpc::PrivilegedJunkScope());
   }
@@ -1819,26 +1817,24 @@ static JS::RealmCreationOptions& SelectZ
       // We're a toplevel load.  Use a new zone.  This way, when we do
       // zone-based compartment sharing we won't share compartments
       // across navigations.
       return aOptions.setNewCompartmentAndZone();
     }
 
     // If we have a top-level window, use its zone.
     if (top && top->GetGlobalJSObject()) {
-#if 0 /* Temporarily disabled; will reenable in bug 1533105 */
       JS::Zone* zone = JS::GetObjectZone(top->GetGlobalJSObject());
       // Now try to find an existing compartment that's same-origin
       // with our principal.
       CompartmentFinderState data(aPrincipal);
       JS_IterateCompartmentsInZone(aCx, zone, &data, FindSameOriginCompartment);
       if (data.compartment) {
         return aOptions.setExistingCompartment(data.compartment);
       }
-#endif
       return aOptions.setNewCompartmentInExistingZone(top->GetGlobalJSObject());
     }
   }
 
   return aOptions.setNewCompartmentAndZone();
 }
 
 /**
--- a/dom/base/test/test_shared_compartment1.html
+++ b/dom/base/test/test_shared_compartment1.html
@@ -22,17 +22,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     if (testsDone === 4) {
       SimpleTest.finish();
     }
   }
 
   // Test 1: same-origin iframe.
   function testFrame1() {
     var frameWin = document.getElementById("frame1").contentWindow;
-    todo(isSameCompartment(window, frameWin),
+    ok(isSameCompartment(window, frameWin),
        "Same-origin iframe must be same-compartment");
     finishIfDone();
   }
 
   // Test 2: cross-origin iframe.
   function testFrame2() {
     var frameWin = document.getElementById("frame2").contentWindow;
     ok(!isSameCompartment(window, frameWin),
@@ -43,28 +43,28 @@ https://bugzilla.mozilla.org/show_bug.cg
   // Test 3: same-site, cross-origin iframe.
   function testFrame3() {
     var frame = document.getElementById("frame3");
     ok(!isSameCompartment(window, frame.contentWindow),
        "Same-site cross-origin iframe must be cross-compartment");
 
     // Now load a same-origin page in this iframe.
     frame.onload = function() {
-      todo(isSameCompartment(window, frame.contentWindow),
+      ok(isSameCompartment(window, frame.contentWindow),
          "Frame must be same-compartment now");
       finishIfDone();
     };
     frame.src = "file_empty.html";
   }
 
   // Test 4: dynamically created iframe.
   addLoadEvent(function() {
     var frame = document.createElement("iframe");
     document.body.appendChild(frame);
-    todo(isSameCompartment(window, frame.contentWindow),
+    ok(isSameCompartment(window, frame.contentWindow),
        "Newly created iframe must be same-compartment");
     finishIfDone();
   });
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1530608">Mozilla Bug 1530608</a>
--- a/dom/base/test/test_shared_compartment2.html
+++ b/dom/base/test/test_shared_compartment2.html
@@ -25,17 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   function go(innerWin) {
     var Cu = SpecialPowers.Cu;
     var isSameCompartment = Cu.getJSTestingFunctions().isSameCompartment;
 
     var frame = document.getElementById("frame");
     ok(!isSameCompartment(window, frame.contentWindow),
        "Cross-origin iframe must be cross-compartment");
 
-    todo(isSameCompartment(window, innerWin),
+    ok(isSameCompartment(window, innerWin),
        "Same-origin inner iframe must be same-compartment");
 
     SimpleTest.finish();
   }
 
   </script>
 </head>
 <body>