Bug 775868 - add checks to DOMWindowUtils, fix tests. r=smaug,bholley a=akeybl
☠☠ backed out by c0218c868070 ☠ ☠
authorAndrew McCreight <amccreight@mozilla.com>
Mon, 10 Sep 2012 12:43:45 -0700
changeset 81999 a06b73f390127aa7f5c73a914c843c5573065a62
parent 81998 2b2a09683ad5d5d8a1b59be10f01478aa0987add
child 82000 c0218c86807051dab03e2ecb6e70c8368ee61786
push id275
push useramccreight@mozilla.com
push dateMon, 24 Sep 2012 23:49:06 +0000
reviewerssmaug, bholley, akeybl
bugs775868
milestone10.0.8esrpre
Bug 775868 - add checks to DOMWindowUtils, fix tests. r=smaug,bholley a=akeybl
dom/base/nsDOMWindowUtils.cpp
dom/tests/mochitest/bugs/test_bug534149.html
dom/tests/mochitest/bugs/test_bug61098.html
dom/tests/mochitest/general/test_domWindowUtils.html
dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
editor/libeditor/html/tests/test_root_element_replacement.html
layout/forms/test/test_bug348236.html
toolkit/components/prompts/test/test_bug625187.html
toolkit/content/tests/widgets/popup_shared.js
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -154,29 +154,37 @@ nsDOMWindowUtils::GetPresContext()
   nsRefPtr<nsPresContext> presContext;
   docShell->GetPresContext(getter_AddRefs(presContext));
   return presContext;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetImageAnimationMode(PRUint16 *aMode)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aMode);
   *aMode = 0;
   nsPresContext* presContext = GetPresContext();
   if (presContext) {
     *aMode = presContext->ImageAnimationMode();
     return NS_OK;
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::SetImageAnimationMode(PRUint16 aMode)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsPresContext* presContext = GetPresContext();
   if (presContext) {
     presContext->SetImageAnimationMode(aMode);
     return NS_OK;
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
@@ -216,16 +224,20 @@ nsDOMWindowUtils::GetDocumentMetadata(co
   
   aValue.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::Redraw(PRUint32 aCount, PRUint32 *aDurationOut)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   if (aCount == 0)
     aCount = 1;
 
   if (nsIPresShell* presShell = GetPresShell()) {
     nsIFrame *rootFrame = presShell->GetRootFrame();
 
     if (rootFrame) {
       nsRect r(nsPoint(0, 0), rootFrame->GetSize());
@@ -757,16 +769,20 @@ nsDOMWindowUtils::CycleCollect(nsICycleC
 
   nsJSContext::CycleCollectNow(aListener);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::ProcessUpdates()
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsPresContext* presContext = GetPresContext();
   if (!presContext)
     return NS_ERROR_UNEXPECTED;
 
   nsIPresShell* shell = presContext->GetPresShell();
   if (!shell)
     return NS_ERROR_UNEXPECTED;
 
@@ -844,31 +860,39 @@ nsDOMWindowUtils::SendSimpleGestureEvent
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::ElementFromPoint(float aX, float aY,
                                    bool aIgnoreRootScrollFrame,
                                    bool aFlushLayout,
                                    nsIDOMElement** aReturn)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
   NS_ENSURE_STATE(doc);
 
   return doc->ElementFromPointHelper(aX, aY, aIgnoreRootScrollFrame, aFlushLayout,
                                      aReturn);
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::NodesFromRect(float aX, float aY,
                                 float aTopSize, float aRightSize,
                                 float aBottomSize, float aLeftSize,
                                 bool aIgnoreRootScrollFrame,
                                 bool aFlushLayout,
                                 nsIDOMNodeList** aReturn)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
   NS_ENSURE_STATE(doc);
 
   return doc->NodesFromRectHelper(aX, aY, aTopSize, aRightSize, aBottomSize, aLeftSize, 
                                   aIgnoreRootScrollFrame, aFlushLayout, aReturn);
 }
 
 static already_AddRefed<gfxImageSurface>
@@ -949,27 +973,36 @@ nsDOMWindowUtils::CompareCanvases(nsIDOM
 
   *retVal = different;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetIsMozAfterPaintPending(bool *aResult)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
+  NS_ENSURE_ARG_POINTER(aResult);
   *aResult = false;
   nsPresContext* presContext = GetPresContext();
   if (!presContext)
     return NS_OK;
   *aResult = presContext->IsDOMPaintEventPending();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::ClearMozAfterPaintEvents()
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsPresContext* presContext = GetPresContext();
   if (!presContext)
     return NS_OK;
   presContext->ClearMozAfterPaintEvents();
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1006,16 +1039,20 @@ nsDOMWindowUtils::SuppressEventHandling(
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetScrollXY(bool aFlushLayout, PRInt32* aScrollX, PRInt32* aScrollY)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
   NS_ENSURE_STATE(doc);
 
   if (aFlushLayout) {
     doc->FlushPendingNotifications(Flush_Layout);
   }
 
   nsPoint scrollPos(0,0);
@@ -1031,16 +1068,20 @@ nsDOMWindowUtils::GetScrollXY(bool aFlus
   *aScrollY = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.y);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetIMEIsOpen(bool *aState)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aState);
 
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget)
     return NS_ERROR_FAILURE;
 
   // Open state should not be available when IME is not enabled.
   IMEContext context;
@@ -1050,16 +1091,20 @@ nsDOMWindowUtils::GetIMEIsOpen(bool *aSt
     return NS_ERROR_NOT_AVAILABLE;
 
   return widget->GetIMEOpenState(aState);
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetIMEStatus(PRUint32 *aState)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aState);
 
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget)
     return NS_ERROR_FAILURE;
 
   IMEContext context;
   nsresult rv = widget->GetInputMode(context);
@@ -1067,16 +1112,20 @@ nsDOMWindowUtils::GetIMEStatus(PRUint32 
 
   *aState = context.mStatus;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetFocusedInputType(char** aType)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aType);
 
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget) {
     return NS_ERROR_FAILURE;
   }
 
   IMEContext context;
@@ -1086,16 +1135,20 @@ nsDOMWindowUtils::GetFocusedInputType(ch
   *aType = ToNewCString(context.mHTMLInputType);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::FindElementWithViewId(nsViewID aID,
                                         nsIDOMElement** aResult)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   if (aID == FrameMetrics::ROOT_SCROLL_ID) {
     nsPresContext* presContext = GetPresContext();
     if (!presContext) {
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     nsIDocument* document = presContext->Document();
     mozilla::dom::Element* rootElement = document->GetRootElement();
@@ -1508,54 +1561,73 @@ nsDOMWindowUtils::GetVisitedDependentCom
   static_cast<nsComputedDOMStyle*>(decl.get())->SetExposeVisitedStyle(false);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::EnterModalState()
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   mWindow->EnterModalState();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::LeaveModalState()
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   mWindow->LeaveModalState(nsnull);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::EnterModalStateWithWindow(nsIDOMWindow **aWindow)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   *aWindow = mWindow->EnterModalState();
   NS_IF_ADDREF(*aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::LeaveModalStateWithWindow(nsIDOMWindow *aWindow)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aWindow);
   mWindow->LeaveModalState(aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::IsInModalState(bool *retval)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   *retval = mWindow->IsInModalState();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetParent()
 {
-  // This wasn't privileged in the past, but better to expose less than more.
   if (!IsUniversalXPConnectCapable()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   nsCOMPtr<nsIXPConnect> xpc = nsContentUtils::XPConnect();
 
   // get the xpconnect native call context
   nsAXPCNativeCallContext *cc = nsnull;
@@ -1604,24 +1676,32 @@ nsDOMWindowUtils::GetParent()
 
   cc->SetReturnValueWasSet(true);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetOuterWindowID(PRUint64 *aWindowID)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ASSERTION(mWindow->IsOuterWindow(), "How did that happen?");
   *aWindowID = mWindow->WindowID();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentInnerWindowID(PRUint64 *aWindowID)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ASSERTION(mWindow->IsOuterWindow(), "How did that happen?");
   nsGlobalWindow* inner = mWindow->GetCurrentInnerWindowInternal();
   if (!inner) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   *aWindowID = inner->WindowID();
   return NS_OK;
 }
@@ -1648,16 +1728,20 @@ nsDOMWindowUtils::ResumeTimeouts()
   mWindow->ResumeTimeouts();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetLayerManagerType(nsAString& aType)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget)
     return NS_ERROR_FAILURE;
 
   LayerManager *mgr = widget->GetLayerManager();
   if (!mgr)
     return NS_ERROR_FAILURE;
 
@@ -1760,16 +1844,20 @@ nsDOMWindowUtils::ComputeAnimationDistan
 }
 
 nsresult
 nsDOMWindowUtils::RenderDocument(const nsRect& aRect,
                                  PRUint32 aFlags,
                                  nscolor aBackgroundColor,
                                  gfxContext* aThebesContext)
 {
+    if (!IsUniversalXPConnectCapable()) {
+      return NS_ERROR_DOM_SECURITY_ERR;
+    }
+
     // Get DOM Document
     nsresult rv;
     nsCOMPtr<nsIDOMDocument> ddoc;
     rv = mWindow->GetDocument(getter_AddRefs(ddoc));
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Get Document
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(ddoc, &rv);
@@ -1781,16 +1869,20 @@ nsDOMWindowUtils::RenderDocument(const n
 
     // Render Document
     return presShell->RenderDocument(aRect, aFlags, aBackgroundColor, aThebesContext);
 }
 
 NS_IMETHODIMP 
 nsDOMWindowUtils::GetCursorType(PRInt16 *aCursor)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ENSURE_ARG_POINTER(aCursor);
 
   bool isSameDoc = false;
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
 
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   do {
@@ -1837,16 +1929,20 @@ nsDOMWindowUtils::GoOnline()
     return NS_OK;
   }
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetDisplayDPI(float *aDPI)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget)
     return NS_ERROR_FAILURE;
 
   *aDPI = widget->GetDPI();
 
   return NS_OK;
 }
@@ -1862,17 +1958,22 @@ nsDOMWindowUtils::GetOuterWindowWithId(P
 
   *aWindow = nsGlobalWindow::GetOuterWindowWithId(aWindowID);
   NS_IF_ADDREF(*aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
-                              nsIDOMFile **aDOMFile) {
+                              nsIDOMFile **aDOMFile)
+{
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   NS_ADDREF(*aDOMFile = new nsDOMFileFile(aFile));
   return NS_OK;
 }
 
 #ifdef DEBUG
 static bool
 CheckLeafLayers(Layer* aLayer, const nsIntPoint& aOffset, nsIntRegion* aCoveredRegion)
 {
@@ -1948,16 +2049,20 @@ nsDOMWindowUtils::GetMayHaveTouchEventLi
   nsPIDOMWindow* innerWindow = mWindow->GetCurrentInnerWindow();
   *aResult = innerWindow ? innerWindow->HasTouchEventListeners() : false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::CheckAndClearPaintedState(nsIDOMElement* aElement, bool* aResult)
 {
+  if (!IsUniversalXPConnectCapable()) {
+    return NS_ERROR_DOM_SECURITY_ERR;
+  }
+
   if (!aElement) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsresult rv;
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/dom/tests/mochitest/bugs/test_bug534149.html
+++ b/dom/tests/mochitest/bugs/test_bug534149.html
@@ -14,23 +14,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 534149 **/
 function getIDs(iframe) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var win = iframe.contentWindow;
   // Force inner creation
   win.document;
 
-  var util = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var util = SpecialPowers.getDOMWindowUtils(win);
   return [util.outerWindowID, util.currentInnerWindowID];
 }
 
 var i1 = document.createElement("iframe");
 var i2 = document.createElement("iframe");
 
 document.body.appendChild(i1);
 var [i1outer, i1inner] = getIDs(i1);
@@ -41,43 +39,39 @@ var [i2outer, i2inner] = getIDs(i2);
 is(i1inner, i1outer + 1, "For frame 1, inner should come right after outer");
 is(i2inner, i2outer + 1, "For frame 2, inner should come right after outer");
 is(i2outer, i1inner + 1, "Frame 2 comes right after frame 1");
 
 var innerWindowDestroyID;
 var outerWindowDestroyID;
 
 function outerObserver(id) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   outerWindowDestroyID =
-    id.QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
+    SpecialPowers.wrap(id).QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
 }
 function innerObserver(id) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   innerWindowDestroyID =
-   id.QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
+   SpecialPowers.wrap(id).QueryInterface(Components.interfaces.nsISupportsPRUint64).data;
 }
 
 function removeFrame(iframe) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var obsSvc = Components.classes["@mozilla.org/observer-service;1"]
+  var obsSvc = SpecialPowers.wrap(Components).classes["@mozilla.org/observer-service;1"]
                          .getService(Components.interfaces.nsIObserverService);
   obsSvc.addObserver(outerObserver, "outer-window-destroyed", false);
   obsSvc.addObserver(innerObserver, "inner-window-destroyed", false);
 
   iframe.parentNode.removeChild(iframe);
 }
 
 removeFrame(i1);
 SimpleTest.waitForExplicitFinish();
 SimpleTest.executeSoon(function() {
   is(innerWindowDestroyID, i1inner, "inner window of frame 1 should be destroyed");
   is(outerWindowDestroyID, i1outer, "outer window of frame 1 should be destroyed");
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var obsSvc = Components.classes["@mozilla.org/observer-service;1"]
+  var obsSvc = SpecialPowers.wrap(Components).classes["@mozilla.org/observer-service;1"]
                          .getService(Components.interfaces.nsIObserverService);
   obsSvc.removeObserver(outerObserver, "outer-window-destroyed");
   obsSvc.removeObserver(innerObserver, "inner-window-destroyed");
   SimpleTest.finish();
 });
   
 
 </script>
--- a/dom/tests/mochitest/bugs/test_bug61098.html
+++ b/dom/tests/mochitest/bugs/test_bug61098.html
@@ -47,19 +47,17 @@ function registerMockPromptService()
     {
       // The real prompt service puts the window into a modal state
       // immediately before showing a modal prompt, and leaves the modal state
       // when the prompt is dismissed by the user. This mock prompt doesn't
       // show anything to the user, so we only need to enter and immediately
       // leave the modal state -- this is done to trigger the necessary
       // accounting for triggering the "stop showing more prompts" code for
       // abusive pages.
-      var winUtils = this.domWindow
-                         .QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindowUtils);
+      var winUtils = SpecialPowers.getDOMWindowUtils(this.domWindow);
       var w = winUtils.enterModalStateWithWindow();
       winUtils.leaveModalStateWithWindow(w);
     },
 
     alert: function(aDialogTitle, aText)
     {
       this._toggleModalState();
       promptState = {method: "alert",
--- a/dom/tests/mochitest/general/test_domWindowUtils.html
+++ b/dom/tests/mochitest/general/test_domWindowUtils.html
@@ -20,20 +20,17 @@
 
 <body id="body">
 
 <div class="test" id="onscreen" style="top: 100px; background-color: red;"></div>
 <div class="test" id="offscreen" style="top: 100000px; background-color: green;"></div>
 
 <script type="application/javascript;version=1.8">
 
-// Enable privileges so we can use nsIDOMWindowUtils interface
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                           .getInterface(Components.interfaces.nsIDOMWindowUtils);
+var domWindowUtils = SpecialPowers.getDOMWindowUtils(window);
 
 /*
   nsIDOMElement elementFromPoint(in long aX,
                                  in long aY,
                                  in boolean aIgnoreRootScrollFrame,
                                  in boolean aFlushLayout);
 */
 function testElementFromPoint() {
--- a/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
+++ b/dom/tests/mochitest/general/test_domWindowUtils_scrollXY.html
@@ -19,22 +19,19 @@
     function doTests() {
       testScrollXY();
       testHiddenIframe();
 
       SimpleTest.finish();
     }
 
     function testScrollXY() {
-      // Enable privileges so we can use nsIDOMWindowUtils interface
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       let iframe = document.getElementById("iframe");
       let cwindow = iframe.contentWindow;
-      let domWindowUtils = cwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
+      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
 
       function checkGetScrollXYState(flush, vals, testName) {
         let scrollX = {}, scrollY = {};
         domWindowUtils.getScrollXY(flush, scrollX, scrollY);
         is(scrollX.value, vals[0], "getScrollXY x for test: " + testName);
         is(scrollY.value, vals[1], "getScrollXY y for test: " + testName);
       }
 
@@ -59,18 +56,17 @@
       cwindow.document.body.style.height = 'auto';
       checkGetScrollXYState(false, [900, 1000], "didn't flush layout for getScrollXY");
       checkGetScrollXYState(true, [0, 0], "flushed layout for getScrollXY");
     }
 
     function testHiddenIframe() {
       let iframe = document.getElementById("hidden-iframe");
       let cwindow = iframe.contentWindow;
-      let domWindowUtils = cwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
+      let domWindowUtils = SpecialPowers.getDOMWindowUtils(cwindow);
 
       // make sure getScrollXY doesn't throw
       let scrollX = {}, scrollY = {};
       domWindowUtils.getScrollXY(false, scrollX, scrollY);
 
       is(scrollX.value, 0, "scrollX is zero for display:none iframe");
       is(scrollY.value, 0, "scrollY is zero for display:none iframe");
     }
--- a/editor/libeditor/html/tests/test_root_element_replacement.html
+++ b/editor/libeditor/html/tests/test_root_element_replacement.html
@@ -88,19 +88,17 @@ function onLoadIFrame()
   var frameDoc = gIFrame.contentWindow.document;
 
   var selCon = gIFrame.contentWindow.
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsIWebNavigation).
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsISelectionDisplay).
     QueryInterface(Components.interfaces.nsISelectionController);
-  var utils = window.
-    QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-    getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var utils = SpecialPowers.getDOMWindowUtils(window);
   const nsIDOMNode = Components.interfaces.nsIDOMNode;
 
   // move focus to the HTML editor
   const kTest = kTests[gTestIndex];
   ok(true, "Running " + kTest.description);
   if (kTest.args.length == 1) {
     kTest.initializer(frameDoc, gSetFocusToIFrame, kTest.args[0]);
     ok(selCon.caretVisible, "caret isn't visible -- " + kTest.description);
--- a/layout/forms/test/test_bug348236.html
+++ b/layout/forms/test/test_bug348236.html
@@ -33,27 +33,24 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   /** Test for Bug 348236 **/
 
 SimpleTest.waitForExplicitFinish()
 addLoadEvent(function test() {
 
     var
         CI = Components.interfaces,
-        WinUtils = window
-                   .QueryInterface(CI.nsIInterfaceRequestor)
-                   .getInterface(CI.nsIDOMWindowUtils),
+        WinUtils = SpecialPowers.getDOMWindowUtils(window),
         sec = netscape.security,
         eSelect = $("eSelect"),
         IDOMNSEvent = CI.nsIDOMNSEvent,
         IDOMKeyEvent = CI.nsIDOMKeyEvent,
         timeout = 0 // Choose a larger value like 500 ms if you want to see what's happening.
 
     function keypressOnSelect(key, modifiers) {
-        sec.PrivilegeManager.enablePrivilege("UniversalXPConnect")
         WinUtils.focus(eSelect)
         WinUtils.sendKeyEvent("keyup", key, 0, modifiers, true)
         WinUtils.sendKeyEvent("keypress", key, 0, modifiers, true)
         WinUtils.sendKeyEvent("keydown", key, 0, modifiers, true)
     }
 
     function testKey(key, modifiers, keyString, functionToContinue) {
         var selectGotClick
@@ -61,28 +58,26 @@ addLoadEvent(function test() {
         eSelect.selectedIndex = 0
         eSelect.onchangeCount = 0
 
         // Drop the SELECT down.
         keypressOnSelect(key, modifiers)
         // This timeout and the following are necessary to let the sent events take effect.
         setTimeout(cont1, timeout)
         function cont1() {
-            sec.PrivilegeManager.enablePrivilege("UniversalXPConnect")
             // Move the mouse over option 3 (90 = 3 (rows) * 24 (row height) + 18).
             WinUtils.sendMouseEvent("mousemove", 355, 90, 0, 0, 0, true)
             setTimeout(cont2, timeout)
         }
         function cont2() {
             // Close the select.
             keypressOnSelect(key, modifiers)
             setTimeout(cont3, timeout)
         }
         function cont3() {
-            sec.PrivilegeManager.enablePrivilege("UniversalXPConnect")
             is(eSelect.value, "3", "Select's value should be 3 after hovering over option 3 and pressing " + keyString + ".")
             is(eSelect.onchangeCount, 1, "Onchange should have fired once.")
 
             // Simulate click on area to the left of the select.
             eSelect.addEventListener("click", clickListener, true)
             selectGotClick = false
             WinUtils.sendMouseEvent("mousedown", 320, 0, 0, 0, 0, true)
             WinUtils.sendMouseEvent("mouseup", 320, 0, 0, 0, 0, true)
--- a/toolkit/components/prompts/test/test_bug625187.html
+++ b/toolkit/components/prompts/test/test_bug625187.html
@@ -25,18 +25,17 @@
 
 <pre id="test"></pre>
 
 <script class="testbody" type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var testNum = 0;
 var dialogNum = 0;
-var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-              getInterface(Components.interfaces.nsIDOMWindowUtils);
+var utils = SpecialPowers.getDOMWindowUtils(window);
 
 function hasTabModalPrompts() {
   var prefName = "prompts.tab_modal.enabled";
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   Components.utils.import("resource://gre/modules/Services.jsm");
   return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
          Services.prefs.getBoolPref(prefName);
 }
--- a/toolkit/content/tests/widgets/popup_shared.js
+++ b/toolkit/content/tests/widgets/popup_shared.js
@@ -47,18 +47,17 @@ function startPopupTests(tests)
   document.addEventListener("command", eventOccurred, false);
   document.addEventListener("DOMMenuItemActive", eventOccurred, false);
   document.addEventListener("DOMMenuItemInactive", eventOccurred, false);
   document.addEventListener("DOMMenuInactive", eventOccurred, false);
   document.addEventListener("DOMMenuBarActive", eventOccurred, false);
   document.addEventListener("DOMMenuBarInactive", eventOccurred, false);
 
   gPopupTests = tests;
-  gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                       .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  gWindowUtils = SpecialPowers.getDOMWindowUtils(window);
 
   goNext();
 }
 
 function finish()
 {
   if (window.opener) {
     window.close();
@@ -79,25 +78,21 @@ function ok(condition, message) {
 function is(left, right, message) {
   if (window.opener)
     window.opener.SimpleTest.is(left, right, message);
   else
     SimpleTest.is(left, right, message);
 }
 
 function disableNonTestMouse(aDisable) {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   gWindowUtils.disableNonTestMouseEvents(aDisable);
 }
 
 function eventOccurred(event)
 {
-   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   if (gPopupTests.length <= gTestIndex) {
     ok(false, "Extra " + event.type + " event fired");
     return;
   }
 
   var test = gPopupTests[gTestIndex];
   if ("autohide" in test && gAutoHide) {
     if (event.type == "DOMMenuInactive") {