Bug 1216401: Eviscerate nsIDOMWindow, move still needed methods to nsPIDOMWindow. r=bz
authorKyle Huey <khuey@kylehuey.com>
Mon, 26 Oct 2015 14:37:32 -0700
changeset 269601 9c01b4d30bddd2b48ad2e43fe9d06da3558409c9
parent 269600 253416fea6438c102e6d9c5c3b2c6f04fe62896e
child 269602 833f6548966e8ad771f929d94e1c6452999b1fda
push id67142
push userkhuey@mozilla.com
push dateTue, 27 Oct 2015 03:02:41 +0000
treeherdermozilla-inbound@9c01b4d30bdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1216401
milestone44.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 1216401: Eviscerate nsIDOMWindow, move still needed methods to nsPIDOMWindow. r=bz
accessible/base/DocManager.cpp
accessible/generic/ApplicationAccessible.cpp
accessible/generic/ImageAccessible.cpp
accessible/generic/RootAccessible.cpp
accessible/windows/msaa/moz.build
accessible/windows/msaa/nsWinUtils.cpp
chrome/moz.build
chrome/nsChromeRegistry.cpp
chrome/nsChromeRegistry.h
docshell/base/nsDSURIContentListener.cpp
docshell/base/nsDocShell.cpp
docshell/base/nsDocShellEditorData.cpp
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/AudioChannelService.cpp
dom/base/Navigator.cpp
dom/base/ThirdPartyUtil.cpp
dom/base/WebSocket.cpp
dom/base/nsContentAreaDragDrop.cpp
dom/base/nsContentPolicy.cpp
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/base/nsMimeTypeArray.cpp
dom/base/nsObjectLoadingContent.cpp
dom/base/nsPIDOMWindow.h
dom/base/nsPluginArray.cpp
dom/base/nsScreen.cpp
dom/base/nsWindowMemoryReporter.cpp
dom/base/nsWindowRoot.cpp
dom/base/nsXMLHttpRequest.cpp
dom/browser-element/BrowserElementAudioChannel.cpp
dom/browser-element/BrowserElementParent.cpp
dom/events/EventStateManager.cpp
dom/geolocation/nsGeolocation.cpp
dom/html/HTMLMediaElement.cpp
dom/html/nsGenericHTMLElement.cpp
dom/interfaces/base/nsIDOMWindow.idl
dom/ipc/TabChild.cpp
dom/ipc/TabParent.cpp
dom/media/eme/MediaKeys.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/system/nsDeviceSensors.cpp
dom/xbl/nsXBLPrototypeHandler.cpp
dom/xml/nsXMLPrettyPrinter.cpp
dom/xul/nsXULCommandDispatcher.cpp
dom/xul/nsXULPopupListener.cpp
editor/composer/nsComposerCommandsUpdater.cpp
editor/composer/nsEditingSession.cpp
embedding/browser/moz.build
embedding/browser/nsContextMenuInfo.cpp
embedding/components/commandhandler/nsCommandManager.cpp
embedding/components/find/nsWebBrowserFind.cpp
embedding/components/printingui/mac/nsPrintProgress.cpp
embedding/components/printingui/unixshared/nsPrintProgress.cpp
embedding/components/printingui/win/nsPrintProgress.cpp
embedding/components/windowwatcher/nsWindowWatcher.cpp
js/xpconnect/wrappers/AccessCheck.cpp
layout/base/nsDocumentViewer.cpp
layout/generic/nsPluginFrame.cpp
layout/printing/nsPrintEngine.cpp
layout/svg/nsSVGOuterSVGFrame.cpp
layout/xul/nsXULPopupManager.cpp
layout/xul/nsXULTooltipListener.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
netwerk/base/LoadInfo.cpp
netwerk/protocol/http/nsHttpHandler.cpp
toolkit/components/perfmonitoring/nsPerformanceStats.cpp
toolkit/components/satchel/nsFormFillController.cpp
toolkit/components/satchel/nsFormFillController.h
toolkit/components/startup/nsAppStartup.cpp
toolkit/xre/ProfileReset.cpp
toolkit/xre/moz.build
toolkit/xre/nsNativeAppSupportWin.cpp
uriloader/base/nsDocLoader.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
widget/cocoa/moz.build
widget/cocoa/nsMenuItemIconX.mm
xpfe/appshell/nsContentTreeOwner.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/accessible/base/DocManager.cpp
+++ b/accessible/base/DocManager.cpp
@@ -185,21 +185,21 @@ DocManager::OnStateChange(nsIWebProgress
   if (nsAccessibilityService::IsShutdown() || !aWebProgress ||
       (aStateFlags & (STATE_START | STATE_STOP)) == 0)
     return NS_OK;
 
   nsCOMPtr<nsIDOMWindow> DOMWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
   NS_ENSURE_STATE(DOMWindow);
 
-  nsCOMPtr<nsIDOMDocument> DOMDocument;
-  DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
-  NS_ENSURE_STATE(DOMDocument);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(DOMWindow);
+  MOZ_ASSERT(piWindow);
 
-  nsCOMPtr<nsIDocument> document(do_QueryInterface(DOMDocument));
+  nsCOMPtr<nsIDocument> document = piWindow->GetDoc();
+  NS_ENSURE_STATE(document);
 
   // Document was loaded.
   if (aStateFlags & STATE_STOP) {
 #ifdef A11Y_LOG
     if (logging::IsEnabled(logging::eDocLoad))
       logging::DocLoad("document loaded", aWebProgress, aRequest, aStateFlags);
 #endif
 
--- a/accessible/generic/ApplicationAccessible.cpp
+++ b/accessible/generic/ApplicationAccessible.cpp
@@ -1,10 +1,10 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim:expandtab:shiftwidth=4:tabstop=4:
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ApplicationAccessible.h"
 
 #include "nsAccessibilityService.h"
@@ -188,22 +188,20 @@ ApplicationAccessible::CacheChildren()
   if (NS_FAILED(rv))
     return;
 
   bool hasMore = false;
   windowEnumerator->HasMoreElements(&hasMore);
   while (hasMore) {
     nsCOMPtr<nsISupports> window;
     windowEnumerator->GetNext(getter_AddRefs(window));
-    nsCOMPtr<nsIDOMWindow> DOMWindow = do_QueryInterface(window);
+    nsCOMPtr<nsPIDOMWindow> DOMWindow = do_QueryInterface(window);
     if (DOMWindow) {
-      nsCOMPtr<nsIDOMDocument> DOMDocument;
-      DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
-      if (DOMDocument) {
-        nsCOMPtr<nsIDocument> docNode(do_QueryInterface(DOMDocument));
+      nsCOMPtr<nsIDocument> docNode = DOMWindow->GetDoc();
+      if (docNode) {
         GetAccService()->GetDocAccessible(docNode); // ensure creation
       }
     }
     windowEnumerator->HasMoreElements(&hasMore);
   }
 }
 
 Accessible*
--- a/accessible/generic/ImageAccessible.cpp
+++ b/accessible/generic/ImageAccessible.cpp
@@ -128,23 +128,22 @@ ImageAccessible::DoAction(uint8_t aIndex
     return false;
 
   nsAutoCString utf8spec;
   uri->GetSpec(utf8spec);
   NS_ConvertUTF8toUTF16 spec(utf8spec);
 
   nsIDocument* document = mContent->OwnerDoc();
   nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
-  nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(piWindow);
-  if (!win)
+  if (!piWindow)
     return false;
 
-  nsCOMPtr<nsIDOMWindow> tmp;
-  return NS_SUCCEEDED(win->Open(spec, EmptyString(), EmptyString(),
-                                getter_AddRefs(tmp)));
+  nsCOMPtr<nsPIDOMWindow> tmp;
+  return NS_SUCCEEDED(piWindow->Open(spec, EmptyString(), EmptyString(),
+                                     getter_AddRefs(tmp)));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // ImageAccessible
 
 nsIntPoint
 ImageAccessible::Position(uint32_t aCoordType)
 {
--- a/accessible/generic/RootAccessible.cpp
+++ b/accessible/generic/RootAccessible.cpp
@@ -481,21 +481,19 @@ Relation
 RootAccessible::RelationByType(RelationType aType)
 {
   if (!mDocumentNode || aType != RelationType::EMBEDS)
     return DocAccessibleWrap::RelationByType(aType);
 
   nsPIDOMWindow* rootWindow = mDocumentNode->GetWindow();
   if (rootWindow) {
     nsCOMPtr<nsIDOMWindow> contentWindow = nsGlobalWindow::Cast(rootWindow)->GetContent();
-    if (contentWindow) {
-      nsCOMPtr<nsIDOMDocument> contentDOMDocument;
-      contentWindow->GetDocument(getter_AddRefs(contentDOMDocument));
-      nsCOMPtr<nsIDocument> contentDocumentNode =
-        do_QueryInterface(contentDOMDocument);
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(contentWindow);
+    if (piWindow) {
+      nsCOMPtr<nsIDocument> contentDocumentNode = piWindow->GetDoc();
       if (contentDocumentNode) {
         DocAccessible* contentDocument =
           GetAccService()->GetDocAccessible(contentDocumentNode);
         if (contentDocument)
           return Relation(contentDocument);
       }
     }
   }
--- a/accessible/windows/msaa/moz.build
+++ b/accessible/windows/msaa/moz.build
@@ -51,16 +51,17 @@ LOCAL_INCLUDES += [
     '/accessible/html',
     '/accessible/windows',
     '/accessible/windows/ia2',
     '/accessible/windows/sdn',
     '/accessible/windows/uia',
     '/accessible/xpcom',
     '/accessible/xul',
     '/dom/base',
+    '/layout/style',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['GNU_CXX']:
     CXXFLAGS += ['-Wshadow']
--- a/accessible/windows/msaa/nsWinUtils.cpp
+++ b/accessible/windows/msaa/nsWinUtils.cpp
@@ -10,23 +10,25 @@
 #include "Compatibility.h"
 #include "DocAccessible.h"
 #include "nsAccessibilityService.h"
 #include "nsCoreUtils.h"
 
 #include "mozilla/Preferences.h"
 #include "nsArrayUtils.h"
 #include "nsIArray.h"
+#include "nsICSSDeclaration.h"
 #include "nsIDocument.h"
 #include "nsIDocShellTreeItem.h"
-#include "nsIDOMElement.h"
+#include "mozilla/dom/Element.h"
 #include "nsXULAppAPI.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
+using mozilla::dom::Element;
 
 // Window property used by ipc related code in identifying accessible
 // tab windows.
 const wchar_t* kPropNameTabContent = L"AccessibleTabWindow";
 
 /**
  * WindowProc to process WM_GETOBJECT messages, used in windows emulation mode.
  */
@@ -38,25 +40,28 @@ nsRefPtrHashtable<nsPtrHashKey<void>, Do
 already_AddRefed<nsIDOMCSSStyleDeclaration>
 nsWinUtils::GetComputedStyleDeclaration(nsIContent* aContent)
 {
   nsIContent* elm = nsCoreUtils::GetDOMElementFor(aContent);
   if (!elm)
     return nullptr;
 
   // Returns number of items in style declaration
-  nsCOMPtr<nsIDOMWindow> window =
+  nsCOMPtr<nsPIDOMWindow> window =
     do_QueryInterface(elm->OwnerDoc()->GetWindow());
   if (!window)
     return nullptr;
 
-  nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
-  nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(elm));
-  window->GetComputedStyle(domElement, EmptyString(), getter_AddRefs(cssDecl));
-  return cssDecl.forget();
+  ErrorResult dummy;
+  nsCOMPtr<nsICSSDeclaration> cssDecl;
+  nsCOMPtr<Element> domElement(do_QueryInterface(elm));
+  cssDecl = window->GetComputedStyle(*domElement, EmptyString(), dummy);
+  nsCOMPtr<nsIDOMCSSStyleDeclaration> domDecl = do_QueryInterface(cssDecl);
+  dummy.SuppressException();
+  return domDecl.forget();
 }
 
 bool
 nsWinUtils::MaybeStartWindowEmulation()
 {
   // Register window class that'll be used for document accessibles associated
   // with tabs.
   if (IPCAccessibilityActive())
--- a/chrome/moz.build
+++ b/chrome/moz.build
@@ -28,15 +28,16 @@ include('/ipc/chromium/chromium-config.m
 
 FINAL_LIBRARY = 'xul'
 
 GENERATED_INCLUDES += [
     '/xpcom',
 ]
 
 LOCAL_INCLUDES += [
+    '/dom/base',
     '/netwerk/base',
     '/netwerk/protocol/res',
     '/xpcom/components'
 ]
 
 if CONFIG['MOZ_ENABLE_GTK']:
     CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -308,25 +308,20 @@ nsChromeRegistry::ConvertChromeURL(nsIUR
   return NS_NewURI(aResult, path, nullptr, baseURI);
 }
 
 ////////////////////////////////////////////////////////////////////////
 
 // theme stuff
 
 
-static void FlushSkinBindingsForWindow(nsIDOMWindow* aWindow)
+static void FlushSkinBindingsForWindow(nsPIDOMWindow* aWindow)
 {
-  // Get the DOM document.
-  nsCOMPtr<nsIDOMDocument> domDocument;
-  aWindow->GetDocument(getter_AddRefs(domDocument));
-  if (!domDocument)
-    return;
-
-  nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
+  // Get the document.
+  nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
   if (!document)
     return;
 
   // Annihilate all XBL bindings.
   document->FlushSkinBindings();
 }
 
 // XXXbsmedberg: move this to nsIWindowMediator
@@ -340,32 +335,32 @@ NS_IMETHODIMP nsChromeRegistry::RefreshS
   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
   windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
   bool more;
   windowEnumerator->HasMoreElements(&more);
   while (more) {
     nsCOMPtr<nsISupports> protoWindow;
     windowEnumerator->GetNext(getter_AddRefs(protoWindow));
     if (protoWindow) {
-      nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
+      nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(protoWindow);
       if (domWindow)
         FlushSkinBindingsForWindow(domWindow);
     }
     windowEnumerator->HasMoreElements(&more);
   }
 
   FlushSkinCaches();
 
   windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
   windowEnumerator->HasMoreElements(&more);
   while (more) {
     nsCOMPtr<nsISupports> protoWindow;
     windowEnumerator->GetNext(getter_AddRefs(protoWindow));
     if (protoWindow) {
-      nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
+      nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(protoWindow);
       if (domWindow)
         RefreshWindow(domWindow);
     }
     windowEnumerator->HasMoreElements(&more);
   }
    
   return NS_OK;
 }
@@ -377,38 +372,33 @@ nsChromeRegistry::FlushSkinCaches()
     mozilla::services::GetObserverService();
   NS_ASSERTION(obsSvc, "Couldn't get observer service.");
 
   obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
                           NS_CHROME_FLUSH_SKINS_TOPIC, nullptr);
 }
 
 // XXXbsmedberg: move this to windowmediator
-nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
+nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow)
 {
   // Deal with our subframes first.
-  nsCOMPtr<nsIDOMWindowCollection> frames;
-  aWindow->GetFrames(getter_AddRefs(frames));
+  nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
   uint32_t length;
   frames->GetLength(&length);
   uint32_t j;
   for (j = 0; j < length; j++) {
     nsCOMPtr<nsIDOMWindow> childWin;
     frames->Item(j, getter_AddRefs(childWin));
-    RefreshWindow(childWin);
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(childWin);
+    RefreshWindow(piWindow);
   }
 
   nsresult rv;
-  // Get the DOM document.
-  nsCOMPtr<nsIDOMDocument> domDocument;
-  aWindow->GetDocument(getter_AddRefs(domDocument));
-  if (!domDocument)
-    return NS_OK;
-
-  nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
+  // Get the document.
+  nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
   if (!document)
     return NS_OK;
 
   // Deal with the agent sheets first.  Have to do all the style sets by hand.
   nsCOMPtr<nsIPresShell> shell = document->GetShell();
   if (shell) {
     // Reload only the chrome URL agent style sheets.
     nsCOMArray<nsIStyleSheet> agentSheets;
@@ -516,20 +506,19 @@ nsChromeRegistry::ReloadChrome()
       // Get each dom window
       bool more;
       rv = windowEnumerator->HasMoreElements(&more);
       if (NS_FAILED(rv)) return rv;
       while (more) {
         nsCOMPtr<nsISupports> protoWindow;
         rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
         if (NS_SUCCEEDED(rv)) {
-          nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
+          nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(protoWindow);
           if (domWindow) {
-            nsCOMPtr<nsIDOMLocation> location;
-            domWindow->GetLocation(getter_AddRefs(location));
+            nsIDOMLocation* location = domWindow->GetLocation();
             if (location) {
               rv = location->Reload(false);
               if (NS_FAILED(rv)) return rv;
             }
           }
         }
         rv = windowEnumerator->HasMoreElements(&more);
         if (NS_FAILED(rv)) return rv;
--- a/chrome/nsChromeRegistry.h
+++ b/chrome/nsChromeRegistry.h
@@ -17,17 +17,17 @@
 #include "nsString.h"
 #include "nsURIHashKey.h"
 #include "nsInterfaceHashtable.h"
 #include "nsXULAppAPI.h"
 #include "nsIXPConnect.h"
 
 #include "mozilla/FileLocation.h"
 
-class nsIDOMWindow;
+class nsPIDOMWindow;
 class nsIPrefBranch;
 class nsIURL;
 
 // The chrome registry is actually split between nsChromeRegistryChrome and
 // nsChromeRegistryContent. The work/data that is common to both resides in
 // the shared nsChromeRegistry implementation, with operations that only make
 // sense for one side erroring out in the other.
 
@@ -90,17 +90,17 @@ protected:
   virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
                                         const nsCString& aProvider,
                                         const nsCString& aPath) = 0;
   virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
                                        uint32_t* aFlags) = 0;
 
   nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
 
-  static nsresult RefreshWindow(nsIDOMWindow* aWindow);
+  static nsresult RefreshWindow(nsPIDOMWindow* aWindow);
   static nsresult GetProviderAndPath(nsIURL* aChromeURL,
                                      nsACString& aProvider, nsACString& aPath);
 
   bool GetDirectionForLocale(const nsACString& aLocale);
 
 public:
   static already_AddRefed<nsChromeRegistry> GetSingleton();
 
--- a/docshell/base/nsDSURIContentListener.cpp
+++ b/docshell/base/nsDSURIContentListener.cpp
@@ -143,18 +143,18 @@ nsDSURIContentListener::DoContent(const 
 
   if (NS_FAILED(rv)) {
     // we don't know how to handle the content
     *aContentHandler = nullptr;
     return rv;
   }
 
   if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI) {
-    nsCOMPtr<nsIDOMWindow> domWindow =
-      mDocShell ? mDocShell->GetWindow() : nullptr;
+    nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(
+      mDocShell ? mDocShell->GetWindow() : nullptr);
     NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
     domWindow->Focus();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -289,26 +289,25 @@ nsDSURIContentListener::CheckOneFrameOpt
   if (!mDocShell) {
     return true;
   }
 
   // We need to check the location of this window and the location of the top
   // window, if we're not the top.  X-F-O: SAMEORIGIN requires that the
   // document must be same-origin with top window.  X-F-O: DENY requires that
   // the document must never be framed.
-  nsCOMPtr<nsIDOMWindow> thisWindow = mDocShell->GetWindow();
+  nsCOMPtr<nsPIDOMWindow> thisWindow = mDocShell->GetWindow();
   // If we don't have DOMWindow there is no risk of clickjacking
   if (!thisWindow) {
     return true;
   }
 
   // GetScriptableTop, not GetTop, because we want this to respect
   // <iframe mozbrowser> boundaries.
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  thisWindow->GetScriptableTop(getter_AddRefs(topWindow));
+  nsCOMPtr<nsPIDOMWindow> topWindow = thisWindow->GetScriptableTop();
 
   // if the document is in the top window, it's not in a frame.
   if (thisWindow == topWindow) {
     return true;
   }
 
   // Find the top docshell in our parent chain that doesn't have the system
   // principal and use it for the principal comparison.  Finding the top
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -3498,24 +3498,23 @@ nsDocShell::CanAccessItem(nsIDocShellTre
     return false;
   }
 
   if (!aConsiderOpener) {
     // All done here
     return false;
   }
 
-  nsCOMPtr<nsIDOMWindow> targetWindow = aTargetItem->GetWindow();
+  nsCOMPtr<nsPIDOMWindow> targetWindow = aTargetItem->GetWindow();
   if (!targetWindow) {
     NS_ERROR("This should not happen, really");
     return false;
   }
 
-  nsCOMPtr<nsIDOMWindow> targetOpener;
-  targetWindow->GetOpener(getter_AddRefs(targetOpener));
+  nsCOMPtr<nsIDOMWindow> targetOpener = targetWindow->GetOpener();
   nsCOMPtr<nsIWebNavigation> openerWebNav(do_GetInterface(targetOpener));
   nsCOMPtr<nsIDocShellTreeItem> openerItem(do_QueryInterface(openerWebNav));
 
   if (!openerItem) {
     return false;
   }
 
   return CanAccessItem(openerItem, aAccessingItem, false);
@@ -7485,17 +7484,17 @@ nsDocShell::EndPageLoad(nsIWebProgress* 
     if (isTopFrame == false && aStatus == NS_ERROR_TRACKING_URI) {
       // frameElement is our nsIContent to be annotated
       nsCOMPtr<nsIDOMElement> frameElement;
       nsPIDOMWindow* thisWindow = GetWindow();
       if (!thisWindow) {
         return NS_OK;
       }
 
-      thisWindow->GetFrameElement(getter_AddRefs(frameElement));
+      frameElement = thisWindow->GetFrameElement();
       if (!frameElement) {
         return NS_OK;
       }
 
       // Parent window
       nsCOMPtr<nsIDocShellTreeItem> parentItem;
       GetSameTypeParent(getter_AddRefs(parentItem));
       if (!parentItem) {
@@ -9734,18 +9733,17 @@ nsDocShell::InternalLoad(nsIURI* aURI,
         if (isNewWindow) {
           //
           // At this point, a new window has been created, but the
           // URI did not have any data associated with it...
           //
           // So, the best we can do, is to tear down the new window
           // that was just created!
           //
-          nsCOMPtr<nsIDOMWindow> domWin = targetDocShell->GetWindow();
-          if (domWin) {
+          if (nsCOMPtr<nsPIDOMWindow> domWin = targetDocShell->GetWindow()) {
             domWin->Close();
           }
         }
         //
         // NS_ERROR_NO_CONTENT should not be returned to the
         // caller... This is an internal error code indicating that
         // the URI had no data associated with it - probably a
         // helper-app style protocol (ie. mailto://)
@@ -13001,44 +12999,41 @@ nsDocShell::GetAssociatedWindow(nsIDOMWi
 {
   CallGetInterface(this, aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetTopWindow(nsIDOMWindow** aWindow)
 {
-  nsCOMPtr<nsIDOMWindow> win = GetWindow();
+  nsCOMPtr<nsPIDOMWindow> win = GetWindow();
   if (win) {
-    win->GetTop(aWindow);
-  }
+    win = win->GetTop();
+  }
+  win.forget(aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetTopFrameElement(nsIDOMElement** aElement)
 {
   *aElement = nullptr;
-  nsCOMPtr<nsIDOMWindow> win = GetWindow();
+  nsCOMPtr<nsPIDOMWindow> win = GetWindow();
   if (!win) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMWindow> top;
-  win->GetScriptableTop(getter_AddRefs(top));
+  nsCOMPtr<nsPIDOMWindow> top = win->GetScriptableTop();
   NS_ENSURE_TRUE(top, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsPIDOMWindow> piTop = do_QueryInterface(top);
-  NS_ENSURE_TRUE(piTop, NS_ERROR_FAILURE);
-
   // GetFrameElementInternal, /not/ GetScriptableFrameElement -- if |top| is
   // inside <iframe mozbrowser>, we want to return the iframe, not null.
   // And we want to cross the content/chrome boundary.
   nsCOMPtr<nsIDOMElement> elt =
-    do_QueryInterface(piTop->GetFrameElementInternal());
+    do_QueryInterface(top->GetFrameElementInternal());
   elt.forget(aElement);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetNestedFrameId(uint64_t* aId)
 {
   *aId = 0;
--- a/docshell/base/nsDocShellEditorData.cpp
+++ b/docshell/base/nsDocShellEditorData.cpp
@@ -153,19 +153,19 @@ nsDocShellEditorData::DetachFromWindow()
     mDocShell ? mDocShell->GetWindow() : nullptr;
   nsresult rv = mEditingSession->DetachFromWindow(domWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mIsDetached = true;
   mDetachedMakeEditable = mMakeEditable;
   mMakeEditable = false;
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  domWindow->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(domWindow);
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
+  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
   if (htmlDoc) {
     mDetachedEditingState = htmlDoc->GetEditingState();
   }
 
   mDocShell = nullptr;
 
   return NS_OK;
 }
@@ -178,17 +178,17 @@ nsDocShellEditorData::ReattachToWindow(n
   nsCOMPtr<nsIDOMWindow> domWindow =
     mDocShell ? mDocShell->GetWindow() : nullptr;
   nsresult rv = mEditingSession->ReattachToWindow(domWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mIsDetached = false;
   mMakeEditable = mDetachedMakeEditable;
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  domWindow->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(domWindow);
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
+  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
   if (htmlDoc) {
     htmlDoc->SetEditingState(mDetachedEditingState);
   }
 
   return NS_OK;
 }
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -107,18 +107,17 @@ AudioChannelAgent::InitInternal(nsIDOMWi
   if (NS_WARN_IF(!aWindow)) {
     return NS_OK;
   }
 
   nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
   MOZ_ASSERT(pInnerWindow->IsInnerWindow());
   mInnerWindowID = pInnerWindow->WindowID();
 
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  aWindow->GetScriptableTop(getter_AddRefs(topWindow));
+  nsCOMPtr<nsPIDOMWindow> topWindow = pInnerWindow->GetScriptableTop();
   if (NS_WARN_IF(!topWindow)) {
     return NS_OK;
   }
 
   mWindow = do_QueryInterface(topWindow);
   if (mWindow) {
     mWindow = mWindow->GetOuterWindow();
   }
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -92,28 +92,26 @@ NotifyChannelActive(uint64_t aWindowID, 
                     bool aActive)
 {
   RefPtr<nsRunnable> runnable =
     new NotifyChannelActiveRunnable(aWindowID, aAudioChannel, aActive);
   NS_DispatchToCurrentThread(runnable);
 }
 
 already_AddRefed<nsPIDOMWindow>
-GetTopWindow(nsIDOMWindow* aWindow)
+GetTopWindow(nsPIDOMWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
 
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  aWindow->GetScriptableTop(getter_AddRefs(topWindow));
+  nsCOMPtr<nsPIDOMWindow> topWindow = aWindow->GetScriptableTop();
   MOZ_ASSERT(topWindow);
 
-  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(topWindow);
-  window = window->GetOuterWindow();
+  topWindow = topWindow->GetOuterWindow();
 
-  return window.forget();
+  return topWindow.forget();
 }
 
 bool
 IsParentProcess()
 {
   return XRE_GetProcessType() == GeckoProcessType_Default;
 }
 
@@ -342,18 +340,17 @@ AudioChannelService::GetState(nsPIDOMWin
     if (winData) {
       *aVolume *= winData->mChannels[aAudioChannel].mVolume;
       *aMuted = *aMuted || winData->mChannels[aAudioChannel].mMuted;
     }
 
     *aVolume *= window->GetAudioVolume();
     *aMuted = *aMuted || window->GetAudioMuted();
 
-    nsCOMPtr<nsIDOMWindow> win;
-    window->GetScriptableParent(getter_AddRefs(win));
+    nsCOMPtr<nsPIDOMWindow> win = window->GetScriptableParent();
     if (window == win) {
       break;
     }
 
     window = do_QueryInterface(win);
 
     // If there is no parent, or we are the toplevel we don't continue.
   } while (window && window != aWindow);
@@ -535,24 +532,22 @@ AudioChannelService::Observe(nsISupports
 }
 
 void
 AudioChannelService::RefreshAgentsVolume(nsPIDOMWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsOuterWindow());
 
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  aWindow->GetScriptableTop(getter_AddRefs(topWindow));
-  nsCOMPtr<nsPIDOMWindow> pTopWindow = do_QueryInterface(topWindow);
-  if (!pTopWindow) {
+  nsCOMPtr<nsPIDOMWindow> topWindow = aWindow->GetScriptableTop();
+  if (!topWindow) {
     return;
   }
 
-  AudioChannelWindow* winData = GetWindowData(pTopWindow->WindowID());
+  AudioChannelWindow* winData = GetWindowData(topWindow->WindowID());
   if (!winData) {
     return;
   }
 
   nsTObserverArray<AudioChannelAgent*>::ForwardIterator
     iter(winData->mAgents);
   while (iter.HasMore()) {
     iter.GetNext()->WindowVolumeChanged();
@@ -561,24 +556,22 @@ AudioChannelService::RefreshAgentsVolume
 
 void
 AudioChannelService::RefreshAgentsCapture(nsPIDOMWindow* aWindow,
                                           uint64_t aInnerWindowID)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsOuterWindow());
 
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  aWindow->GetScriptableTop(getter_AddRefs(topWindow));
-  nsCOMPtr<nsPIDOMWindow> pTopWindow = do_QueryInterface(topWindow);
-  if (!pTopWindow) {
+  nsCOMPtr<nsPIDOMWindow> topWindow = aWindow->GetScriptableTop();
+  if (!topWindow) {
     return;
   }
 
-  AudioChannelWindow* winData = GetWindowData(pTopWindow->WindowID());
+  AudioChannelWindow* winData = GetWindowData(topWindow->WindowID());
 
   // This can happen, but only during shutdown, because the the outer window
   // changes ScriptableTop, so that its ID is different.
   // In this case either we are capturing, and it's too late because the window
   // has been closed anyways, or we are un-capturing, and everything has already
   // been cleaned up by the HTMLMediaElements or the AudioContexts.
   if (!winData) {
     return;
@@ -702,17 +695,18 @@ AudioChannelService::GetAudioChannelVolu
 
 NS_IMETHODIMP
 AudioChannelService::GetAudioChannelVolume(nsIDOMWindow* aWindow,
                                            unsigned short aAudioChannel,
                                            float* aVolume)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(aWindow);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(piWindow);
   MOZ_ASSERT(window->IsOuterWindow());
   *aVolume = GetAudioChannelVolume(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 
 void
 AudioChannelService::SetAudioChannelVolume(nsPIDOMWindow* aWindow,
                                            AudioChannel aAudioChannel,
@@ -729,17 +723,18 @@ AudioChannelService::SetAudioChannelVolu
 
 NS_IMETHODIMP
 AudioChannelService::SetAudioChannelVolume(nsIDOMWindow* aWindow,
                                            unsigned short aAudioChannel,
                                            float aVolume)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(aWindow);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(piWindow);
   MOZ_ASSERT(window->IsOuterWindow());
   SetAudioChannelVolume(window, (AudioChannel)aAudioChannel, aVolume);
   return NS_OK;
 }
 
 bool
 AudioChannelService::GetAudioChannelMuted(nsPIDOMWindow* aWindow,
                                           AudioChannel aAudioChannel)
@@ -754,17 +749,18 @@ AudioChannelService::GetAudioChannelMute
 
 NS_IMETHODIMP
 AudioChannelService::GetAudioChannelMuted(nsIDOMWindow* aWindow,
                                           unsigned short aAudioChannel,
                                           bool* aMuted)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(aWindow);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(piWindow);
   MOZ_ASSERT(window->IsOuterWindow());
   *aMuted = GetAudioChannelMuted(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 
 void
 AudioChannelService::SetAudioChannelMuted(nsPIDOMWindow* aWindow,
                                           AudioChannel aAudioChannel,
@@ -786,17 +782,18 @@ AudioChannelService::SetAudioChannelMute
 
 NS_IMETHODIMP
 AudioChannelService::SetAudioChannelMuted(nsIDOMWindow* aWindow,
                                           unsigned short aAudioChannel,
                                           bool aMuted)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(aWindow);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(piWindow);
   MOZ_ASSERT(window->IsOuterWindow());
   SetAudioChannelMuted(window, (AudioChannel)aAudioChannel, aMuted);
   return NS_OK;
 }
 
 bool
 AudioChannelService::IsAudioChannelActive(nsPIDOMWindow* aWindow,
                                           AudioChannel aAudioChannel)
@@ -811,17 +808,18 @@ AudioChannelService::IsAudioChannelActiv
 
 NS_IMETHODIMP
 AudioChannelService::IsAudioChannelActive(nsIDOMWindow* aWindow,
                                           unsigned short aAudioChannel,
                                           bool* aActive)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(aWindow);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTopWindow(piWindow);
   MOZ_ASSERT(window->IsOuterWindow());
   *aActive = IsAudioChannelActive(window, (AudioChannel)aAudioChannel);
   return NS_OK;
 }
 void
 AudioChannelService::SetDefaultVolumeControlChannel(int32_t aChannel,
                                                     bool aVisible)
 {
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -2640,47 +2640,42 @@ Navigator::HasPresentationSupport(JSCont
   // Grant access to browser receiving pages and their same-origin iframes. (App
   // pages should be controlled by "presentation" permission in app manifests.)
   mozilla::dom::ContentChild* cc =
     mozilla::dom::ContentChild::GetSingleton();
   if (!cc || !cc->IsForBrowser()) {
     return false;
   }
 
-  nsCOMPtr<nsIDOMWindow> top;
-  nsresult rv = win->GetTop(getter_AddRefs(top));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return false;
-  }
-
+  win = win->GetOuterWindow();
+  nsCOMPtr<nsPIDOMWindow> top = win->GetTop();
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(win);
   nsCOMPtr<nsIScriptObjectPrincipal> topSop = do_QueryInterface(top);
   if (!sop || !topSop) {
     return false;
   }
 
   nsIPrincipal* principal = sop->GetPrincipal();
   nsIPrincipal* topPrincipal = topSop->GetPrincipal();
   if (!principal || !topPrincipal || !principal->Subsumes(topPrincipal)) {
     return false;
   }
 
-  nsCOMPtr<nsPIDOMWindow> piTop = do_QueryInterface(top);
-  if (!piTop || !(piTop = piTop->GetCurrentInnerWindow())) {
+  if (!(top = top->GetCurrentInnerWindow())) {
     return false;
   }
 
   nsCOMPtr<nsIPresentationService> presentationService =
     do_GetService(PRESENTATION_SERVICE_CONTRACTID);
   if (NS_WARN_IF(!presentationService)) {
     return false;
   }
 
   nsAutoString sessionId;
-  presentationService->GetExistentSessionIdAtLaunch(piTop->WindowID(), sessionId);
+  presentationService->GetExistentSessionIdAtLaunch(top->WindowID(), sessionId);
   return !sessionId.IsEmpty();
 }
 
 /* static */
 bool
 Navigator::IsE10sEnabled(JSContext* aCx, JSObject* aGlobal)
 {
   return XRE_IsContentProcess();
--- a/dom/base/ThirdPartyUtil.cpp
+++ b/dom/base/ThirdPartyUtil.cpp
@@ -136,24 +136,22 @@ ThirdPartyUtil::IsThirdPartyWindow(nsIDO
       return rv;
 
     if (result) {
       *aResult = true;
       return NS_OK;
     }
   }
 
-  nsCOMPtr<nsIDOMWindow> current = aWindow, parent;
+  nsCOMPtr<nsPIDOMWindow> current = do_QueryInterface(aWindow), parent;
   nsCOMPtr<nsIURI> parentURI;
   do {
     // We use GetScriptableParent rather than GetParent because we consider
     // <iframe mozbrowser/mozapp> to be a top-level frame.
-    rv = current->GetScriptableParent(getter_AddRefs(parent));
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    parent = current->GetScriptableParent();
     if (SameCOMIdentity(parent, current)) {
       // We're at the topmost content window. We already know the answer.
       *aResult = false;
       return NS_OK;
     }
 
     rv = GetURIFromWindow(parent, getter_AddRefs(parentURI));
     NS_ENSURE_SUCCESS(rv, rv);
@@ -270,19 +268,22 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIC
   // If there is no window, the consumer kicking off the load didn't provide one
   // to the channel. This is limited to loads of certain types of resources. If
   // those loads require cookies, the forceAllowThirdPartyCookie property should
   // be set on the channel.
   nsCOMPtr<nsIDOMWindow> ourWin, parentWin;
   ctx->GetAssociatedWindow(getter_AddRefs(ourWin));
   if (!ourWin) return NS_ERROR_INVALID_ARG;
 
+  nsCOMPtr<nsPIDOMWindow> piOurWin = do_QueryInterface(ourWin);
+  MOZ_ASSERT(piOurWin);
+
   // We use GetScriptableParent rather than GetParent because we consider
   // <iframe mozbrowser/mozapp> to be a top-level frame.
-  ourWin->GetScriptableParent(getter_AddRefs(parentWin));
+  parentWin = piOurWin->GetScriptableParent();
   NS_ENSURE_TRUE(parentWin, NS_ERROR_INVALID_ARG);
 
   // Check whether this is the document channel for this window (representing a
   // load of a new page). In that situation we want to avoid comparing
   // channelURI to ourWin, since what's in ourWin right now will be replaced as
   // the channel loads.  This covers the case of a freshly kicked-off load
   // (e.g. the user typing something in the location bar, or clicking on a
   // bookmark), where the window's URI hasn't yet been set, and will be bogus.
@@ -310,32 +311,33 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIC
   return IsThirdPartyWindow(ourWin, channelURI, aResult);
 }
 
 NS_IMETHODIMP
 ThirdPartyUtil::GetTopWindowForChannel(nsIChannel* aChannel, nsIDOMWindow** aWin)
 {
   NS_ENSURE_ARG(aWin);
 
-  nsresult rv;
   // Find the associated window and its parent window.
   nsCOMPtr<nsILoadContext> ctx;
   NS_QueryNotificationCallbacks(aChannel, ctx);
   if (!ctx) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsCOMPtr<nsIDOMWindow> window;
-  rv = ctx->GetAssociatedWindow(getter_AddRefs(window));
-  if (!window) {
+  ctx->GetAssociatedWindow(getter_AddRefs(window));
+  nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(window);
+  if (!top) {
     return NS_ERROR_INVALID_ARG;
   }
-
-  rv = window->GetTop(aWin);
-  return rv;
+  
+  top = top->GetTop();
+  top.forget(aWin);
+  return NS_OK;
 }
 
 // Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
 // "bbc.co.uk". Only properly-formed URI's are tolerated, though a trailing
 // dot may be present. If aHostURI is an IP address, an alias such as
 // 'localhost', an eTLD such as 'co.uk', or the empty string, aBaseDomain will
 // be the exact host. The result of this function should only be used in exact
 // string comparisons, since substring comparisons will not be valid for the
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -1134,26 +1134,30 @@ protected:
     }
 
     nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
     if (!principal) {
       mRv.Throw(NS_ERROR_FAILURE);
       return true;
     }
 
+    if (aWindow->IsOuterWindow()) {
+      aWindow = aWindow->GetCurrentInnerWindow();
+    }
+
+    MOZ_ASSERT(aWindow);
+
     uint64_t windowID = 0;
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    aWindow->GetScriptableTop(getter_AddRefs(topWindow));
-    nsCOMPtr<nsPIDOMWindow> pTopWindow = do_QueryInterface(topWindow);
-    if (pTopWindow) {
-      pTopWindow = pTopWindow->GetCurrentInnerWindow();
+    nsCOMPtr<nsPIDOMWindow> topWindow = aWindow->GetScriptableTop();
+    if (topWindow) {
+      topWindow = topWindow->GetCurrentInnerWindow();
     }
 
-    if (pTopWindow) {
-      windowID = pTopWindow->WindowID();
+    if (topWindow) {
+      windowID = topWindow->WindowID();
     }
 
     mImpl->AsyncOpen(principal, windowID, mRv);
     return true;
   }
 
   virtual bool InitWindowless(WorkerPrivate* aTopLevelWorkerPrivate) override
   {
@@ -1205,16 +1209,18 @@ WebSocket::Constructor(const GlobalObjec
 
     ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
     if (!ownerWindow) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
   }
 
+  MOZ_ASSERT_IF(ownerWindow, ownerWindow->IsInnerWindow());
+
   nsTArray<nsString> protocolArray;
 
   for (uint32_t index = 0, len = aProtocols.Length(); index < len; ++index) {
 
     const nsString& protocolElement = aProtocols[index];
 
     if (protocolElement.IsEmpty()) {
       aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
@@ -1318,26 +1324,26 @@ WebSocket::Constructor(const GlobalObjec
   aRv = webSocket->mImpl->mChannel->SetNotificationCallbacks(webSocket->mImpl);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   if (NS_IsMainThread()) {
     MOZ_ASSERT(principal);
 
+    nsPIDOMWindow* outerWindow = ownerWindow->GetOuterWindow();
+
     uint64_t windowID = 0;
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    ownerWindow->GetScriptableTop(getter_AddRefs(topWindow));
-    nsCOMPtr<nsPIDOMWindow> pTopWindow = do_QueryInterface(topWindow);
-    if (pTopWindow) {
-      pTopWindow = pTopWindow->GetCurrentInnerWindow();
+    nsCOMPtr<nsPIDOMWindow> topWindow = outerWindow->GetScriptableTop();
+    if (topWindow) {
+      topWindow = topWindow->GetCurrentInnerWindow();
     }
 
-    if (pTopWindow) {
-      windowID = pTopWindow->WindowID();
+    if (topWindow) {
+      windowID = topWindow->WindowID();
     }
 
     webSocket->mImpl->AsyncOpen(principal, windowID, aRv);
   } else {
     RefPtr<AsyncOpenRunnable> runnable =
       new AsyncOpenRunnable(webSocket->mImpl, aRv);
     runnable->Dispatch(aGlobal.Context());
   }
--- a/dom/base/nsContentAreaDragDrop.cpp
+++ b/dom/base/nsContentAreaDragDrop.cpp
@@ -388,17 +388,17 @@ DragDataProducer::Produce(DataTransfer* 
     if (selcon) {
       selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
     }
 
     if (!selection)
       return NS_OK;
   }
   else {
-    mWindow->GetSelection(getter_AddRefs(selection));
+    selection = mWindow->GetSelection();
     if (!selection)
       return NS_OK;
 
     // Check if the node is inside a form control. Don't set aCanDrag to false
     //however, as we still want to allow the drag.
     nsCOMPtr<nsIContent> findFormNode = mSelectionTargetNode;
     nsIContent* findFormParent = findFormNode->GetParent();
     while (findFormParent) {
--- a/dom/base/nsContentPolicy.cpp
+++ b/dom/base/nsContentPolicy.cpp
@@ -183,19 +183,18 @@ nsContentPolicy::CheckPolicy(CPMethod   
     if (window) {
         nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
         nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
         loadContext->GetTopFrameElement(getter_AddRefs(topFrameElement));
 
         MOZ_ASSERT(window->IsOuterWindow());
 
         if (topFrameElement) {
-            nsCOMPtr<nsIDOMWindow> topWindow;
-            window->GetScriptableTop(getter_AddRefs(topWindow));
-            isTopLevel = topWindow == static_cast<nsIDOMWindow*>(window);
+            nsCOMPtr<nsPIDOMWindow> topWindow = window->GetScriptableTop();
+            isTopLevel = topWindow == window;
         } else {
             // If we don't have a top frame element, then requestingContext is
             // part of the top-level XUL document. Presumably it's the <browser>
             // element that content is being loaded into, so we call it the
             // topFrameElement.
             topFrameElement = do_QueryInterface(requestingContext);
             isTopLevel = true;
         }
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -6908,33 +6908,30 @@ nsContentUtils::GetRootDocument(nsIDocum
   while (doc->GetParentDocument()) {
     doc = doc->GetParentDocument();
   }
   return doc;
 }
 
 /* static */
 bool
-nsContentUtils::IsInPointerLockContext(nsIDOMWindow* aWin)
+nsContentUtils::IsInPointerLockContext(nsPIDOMWindow* aWin)
 {
   if (!aWin) {
     return false;
   }
 
   nsCOMPtr<nsIDocument> pointerLockedDoc =
     do_QueryReferent(EventStateManager::sPointerLockedDoc);
   if (!pointerLockedDoc || !pointerLockedDoc->GetWindow()) {
     return false;
   }
 
-  nsCOMPtr<nsIDOMWindow> lockTop;
-  pointerLockedDoc->GetWindow()->GetScriptableTop(getter_AddRefs(lockTop));
-
-  nsCOMPtr<nsIDOMWindow> top;
-  aWin->GetScriptableTop(getter_AddRefs(top));
+  nsCOMPtr<nsPIDOMWindow> lockTop = pointerLockedDoc->GetWindow()->GetScriptableTop();
+  nsCOMPtr<nsPIDOMWindow> top = aWin->GetScriptableTop();
 
   return top == lockTop;
 }
 
 // static
 int32_t
 nsContentUtils::GetAdjustedOffsetInTextControl(nsIFrame* aOffsetFrame,
                                                int32_t aOffset)
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2066,17 +2066,17 @@ public:
    * will be the chrome document.
    */
   static nsIDocument* GetRootDocument(nsIDocument* aDoc);
 
   /**
    * Returns true if aWin and the current pointer lock document
    * have common scriptable top window.
    */
-  static bool IsInPointerLockContext(nsIDOMWindow* aWin);
+  static bool IsInPointerLockContext(nsPIDOMWindow* aWin);
 
   /**
    * Returns the time limit on handling user input before
    * EventStateManager::IsHandlingUserInput() stops returning true.
    * This enables us to detect long running user-generated event handlers.
    */
   static TimeDuration HandlingUserInputTimeout();
 
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -1989,25 +1989,30 @@ nsDOMWindowUtils::GetClassName(JS::Handl
 NS_IMETHODIMP
 nsDOMWindowUtils::GetVisitedDependentComputedStyle(
                     nsIDOMElement *aElement, const nsAString& aPseudoElement,
                     const nsAString& aPropertyName, nsAString& aResult)
 {
   aResult.Truncate();
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
+  nsCOMPtr<Element> element = do_QueryInterface(aElement);
+  NS_ENSURE_STATE(window && element);
+  window = window->GetCurrentInnerWindow();
   NS_ENSURE_STATE(window);
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
-  nsresult rv =
-    window->GetComputedStyle(aElement, aPseudoElement, getter_AddRefs(decl));
-  NS_ENSURE_SUCCESS(rv, rv);
+  {
+    ErrorResult rv;
+    decl = window->GetComputedStyle(*element, aPseudoElement, rv);
+    ENSURE_SUCCESS(rv, rv.StealNSResult());
+  }
 
   static_cast<nsComputedDOMStyle*>(decl.get())->SetExposeVisitedStyle(true);
-  rv = decl->GetPropertyValue(aPropertyName, aResult);
+  nsresult rv = decl->GetPropertyValue(aPropertyName, aResult);
   static_cast<nsComputedDOMStyle*>(decl.get())->SetExposeVisitedStyle(false);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::EnterModalState()
 {
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3270,22 +3270,21 @@ nsIDocument::HasFocus(ErrorResult& rv) c
 
   // Is there a focused DOMWindow?
   nsCOMPtr<nsIDOMWindow> focusedWindow;
   fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
   if (!focusedWindow) {
     return false;
   }
 
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(focusedWindow);
+  MOZ_ASSERT(piWindow);
+
   // Are we an ancestor of the focused DOMWindow?
-  nsCOMPtr<nsIDOMDocument> domDocument;
-  focusedWindow->GetDocument(getter_AddRefs(domDocument));
-  nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
-
-  for (nsIDocument* currentDoc = document; currentDoc;
+  for (nsIDocument* currentDoc = piWindow->GetDoc(); currentDoc;
        currentDoc = currentDoc->GetParentDocument()) {
     if (currentDoc == this) {
       // Yes, we are an ancestor
       return true;
     }
   }
 
   return false;
@@ -6997,19 +6996,21 @@ already_AddRefed<nsLocation>
 nsIDocument::GetLocation() const
 {
   nsCOMPtr<nsIDOMWindow> w = do_QueryInterface(mScriptGlobalObject);
 
   if (!w) {
     return nullptr;
   }
 
-  nsCOMPtr<nsIDOMLocation> loc;
-  w->GetLocation(getter_AddRefs(loc));
-  return loc.forget().downcast<nsLocation>();
+  nsGlobalWindow* window = static_cast<nsGlobalWindow*>(w.get());
+  ErrorResult dummy;
+  RefPtr<nsLocation> loc = window->GetLocation(dummy);
+  dummy.SuppressException();
+  return loc.forget();
 }
 
 Element*
 nsIDocument::GetHtmlElement() const
 {
   Element* rootElement = GetRootElement();
   if (rootElement && rootElement->IsHTMLElement(nsGkAtoms::html))
     return rootElement;
@@ -11784,19 +11785,17 @@ ShouldApplyFullscreenDirectly(nsIDocumen
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     // If we are in the content process, we can apply the fullscreen
     // state directly only if we have been in DOM fullscreen, because
     // otherwise we always need to notify the chrome.
     return nsContentUtils::GetRootDocument(aDoc)->IsFullScreenDoc();
   } else {
     // If we are in the chrome process, and the window has not been in
     // fullscreen, we certainly need to make that fullscreen first.
-    bool fullscreen;
-    NS_WARN_IF(NS_FAILED(aRootWin->GetFullScreen(&fullscreen)));
-    if (!fullscreen) {
+    if (!aRootWin->GetFullScreen()) {
       return false;
     }
     // The iterator not being at end indicates there is still some
     // pending fullscreen request relates to this document. We have to
     // push the request to the pending queue so requests are handled
     // in the correct order.
     PendingFullscreenRequestList::Iterator
       iter(aDoc, PendingFullscreenRequestList::eDocumentsWithSameRoot);
@@ -12488,28 +12487,25 @@ nsDocument::ShouldLockPointer(Element* a
   nsCOMPtr<nsPIDOMWindow> ownerInnerWindow = ownerDoc->GetInnerWindow();
   if (!ownerInnerWindow) {
     return false;
   }
   if (ownerWindow->GetCurrentInnerWindow() != ownerInnerWindow) {
     return false;
   }
 
-  nsCOMPtr<nsIDOMWindow> top;
-  ownerWindow->GetScriptableTop(getter_AddRefs(top));
-  nsCOMPtr<nsPIDOMWindow> piTop = do_QueryInterface(top);
-  if (!piTop || !piTop->GetExtantDoc() ||
-      piTop->GetExtantDoc()->Hidden()) {
+  nsCOMPtr<nsPIDOMWindow> top = ownerWindow->GetScriptableTop();
+  if (!top || !top->GetExtantDoc() || top->GetExtantDoc()->Hidden()) {
     NS_WARNING("ShouldLockPointer(): Top document isn't visible.");
     return false;
   }
 
   if (!aNoFocusCheck) {
     mozilla::ErrorResult rv;
-    if (!piTop->GetExtantDoc()->HasFocus(rv)) {
+    if (!top->GetExtantDoc()->HasFocus(rv)) {
       NS_WARNING("ShouldLockPointer(): Top document isn't focused.");
       return false;
     }
   }
 
   return true;
 }
 
@@ -13281,20 +13277,17 @@ MarkDocumentTreeToBeInSyncOperation(nsID
 
 nsAutoSyncOperation::nsAutoSyncOperation(nsIDocument* aDoc)
 {
   mMicroTaskLevel = nsContentUtils::MicroTaskLevel();
   nsContentUtils::SetMicroTaskLevel(0);
   if (aDoc) {
     nsPIDOMWindow* win = aDoc->GetWindow();
     if (win) {
-      nsCOMPtr<nsIDOMWindow> topWindow;
-      win->GetTop(getter_AddRefs(topWindow));
-      nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(topWindow);
-      if (top) {
+      if (nsCOMPtr<nsPIDOMWindow> top = win->GetTop()) {
         nsCOMPtr<nsIDocument> doc = top->GetExtantDoc();
         MarkDocumentTreeToBeInSyncOperation(doc, &mDocuments);
       }
     }
   }
 }
 
 nsAutoSyncOperation::~nsAutoSyncOperation()
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -439,19 +439,17 @@ nsGlobalWindow::DOMMinTimeoutValue() con
 // inner doesn't already exists.
 #define FORWARD_TO_INNER_CREATE(method, args, err_rval)                       \
   PR_BEGIN_MACRO                                                              \
   if (IsOuterWindow()) {                                                      \
     if (!mInnerWindow) {                                                      \
       if (mIsClosed) {                                                        \
         return err_rval;                                                      \
       }                                                                       \
-      nsCOMPtr<nsIDOMDocument> doc;                                           \
-      nsresult fwdic_nr = GetDocument(getter_AddRefs(doc));                   \
-      NS_ENSURE_SUCCESS(fwdic_nr, err_rval);                                  \
+      nsCOMPtr<nsIDocument> doc = GetDoc();                                   \
       if (!mInnerWindow) {                                                    \
         return err_rval;                                                      \
       }                                                                       \
     }                                                                         \
     return GetCurrentInnerWindowInternal()->method args;                      \
   }                                                                           \
   PR_END_MACRO
 
@@ -2333,17 +2331,17 @@ CreateNativeGlobalForInner(JSContext* aC
 
   // DOMWindow with nsEP is not supported, we have to make sure
   // no one creates one accidentally.
   nsCOMPtr<nsIExpandedPrincipal> nsEP = do_QueryInterface(aPrincipal);
   MOZ_RELEASE_ASSERT(!nsEP, "DOMWindow with nsEP is not supported");
 
   nsGlobalWindow *top = nullptr;
   if (aNewInner->GetOuterWindow()) {
-    top = aNewInner->GetTop();
+    top = aNewInner->GetTopInternal();
   }
   JS::CompartmentOptions options;
 
   // Sometimes add-ons load their own XUL windows, either as separate top-level
   // windows or inside a browser element. In such cases we want to tag the
   // window's compartment with the add-on ID. See bug 1092156.
   if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
     options.setAddonId(MapURIToAddonID(aURI));
@@ -2847,17 +2845,17 @@ nsGlobalWindow::DispatchDOMWindowCreated
                         "content-document-global-created",
                       origin.get());
   }
 }
 
 void
 nsGlobalWindow::ClearStatus()
 {
-  SetStatus(EmptyString());
+  SetStatusOuter(EmptyString());
 }
 
 void
 nsGlobalWindow::InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument)
 {
   NS_PRECONDITION(IsInnerWindow(), "Must only be called on inner windows");
   MOZ_ASSERT(aDocument);
 
@@ -2911,21 +2909,19 @@ nsGlobalWindow::SetDocShell(nsIDocShell*
   mChromeEventHandler = do_QueryInterface(chromeEventHandler);
   if (!mChromeEventHandler) {
     // We have no chrome event handler. If we have a parent,
     // get our chrome event handler from the parent. If
     // we don't have a parent, then we need to make a new
     // window root object that will function as a chrome event
     // handler and receive all events that occur anywhere inside
     // our window.
-    nsCOMPtr<nsIDOMWindow> parentWindow;
-    GetParent(getter_AddRefs(parentWindow));
-    if (parentWindow.get() != static_cast<nsIDOMWindow*>(this)) {
-      nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(parentWindow));
-      mChromeEventHandler = piWindow->GetChromeEventHandler();
+    nsCOMPtr<nsPIDOMWindow> parentWindow = GetParent();
+    if (parentWindow.get() != static_cast<nsPIDOMWindow*>(this)) {
+      mChromeEventHandler = parentWindow->GetChromeEventHandler();
     }
     else {
       mChromeEventHandler = NS_NewWindowRoot(this);
     }
   }
 
   bool docShellActive;
   mDocShell->GetIsActive(&docShellActive);
@@ -3050,17 +3046,17 @@ nsGlobalWindow::UpdateParentTarget()
   // child global, and if it doesn't have one, just use the chrome event
   // handler itself.
 
   nsCOMPtr<Element> frameElement = GetFrameElementInternal();
   nsCOMPtr<EventTarget> eventTarget =
     TryGetTabChildGlobalAsEventTarget(frameElement);
 
   if (!eventTarget) {
-    nsGlobalWindow* topWin = GetScriptableTop();
+    nsGlobalWindow* topWin = GetScriptableTopInternal();
     if (topWin) {
       frameElement = topWin->GetFrameElementInternal();
       eventTarget = TryGetTabChildGlobalAsEventTarget(frameElement);
     }
   }
 
   if (!eventTarget) {
     eventTarget = TryGetTabChildGlobalAsEventTarget(mChromeEventHandler);
@@ -3157,17 +3153,17 @@ nsGlobalWindow::PreHandleEvent(EventChai
   return NS_OK;
 }
 
 bool
 nsGlobalWindow::ShouldPromptToBlockDialogs()
 {
   MOZ_ASSERT(IsOuterWindow());
 
-  nsGlobalWindow *topWindow = GetScriptableTop();
+  nsGlobalWindow *topWindow = GetScriptableTopInternal();
   if (!topWindow) {
     NS_ASSERTION(!mDocShell, "ShouldPromptToBlockDialogs() called without a top window?");
     return true;
   }
 
   topWindow = topWindow->GetCurrentInnerWindowInternal();
   if (!topWindow) {
     return true;
@@ -3176,17 +3172,17 @@ nsGlobalWindow::ShouldPromptToBlockDialo
   return topWindow->DialogsAreBeingAbused();
 }
 
 bool
 nsGlobalWindow::AreDialogsEnabled()
 {
   MOZ_ASSERT(IsOuterWindow());
 
-  nsGlobalWindow *topWindow = GetScriptableTop();
+  nsGlobalWindow *topWindow = GetScriptableTopInternal();
   if (!topWindow) {
     NS_ERROR("AreDialogsEnabled() called without a top window?");
     return false;
   }
 
   // TODO: Warn if no top window?
   topWindow = topWindow->GetCurrentInnerWindowInternal();
   if (!topWindow) {
@@ -3207,18 +3203,18 @@ nsGlobalWindow::AreDialogsEnabled()
 
   return topWindow->mAreDialogsEnabled;
 }
 
 bool
 nsGlobalWindow::DialogsAreBeingAbused()
 {
   MOZ_ASSERT(IsInnerWindow());
-  NS_ASSERTION(GetScriptableTop() &&
-               GetScriptableTop()->GetCurrentInnerWindowInternal() == this,
+  NS_ASSERTION(GetScriptableTopInternal() &&
+               GetScriptableTopInternal()->GetCurrentInnerWindowInternal() == this,
                "DialogsAreBeingAbused called with invalid window");
 
   if (mLastDialogQuitTime.IsNull() ||
       nsContentUtils::IsCallerChrome()) {
     return false;
   }
 
   TimeDuration dialogInterval(TimeStamp::Now() - mLastDialogQuitTime);
@@ -3268,33 +3264,33 @@ nsGlobalWindow::ConfirmDialogIfNeeded()
   }
 
   return true;
 }
 
 void
 nsGlobalWindow::DisableDialogs()
 {
-  nsGlobalWindow *topWindow = GetScriptableTop();
+  nsGlobalWindow *topWindow = GetScriptableTopInternal();
   if (!topWindow) {
     NS_ERROR("DisableDialogs() called without a top window?");
     return;
   }
 
   topWindow = topWindow->GetCurrentInnerWindowInternal();
   // TODO: Warn if no top window?
   if (topWindow) {
     topWindow->mAreDialogsEnabled = false;
   }
 }
 
 void
 nsGlobalWindow::EnableDialogs()
 {
-  nsGlobalWindow *topWindow = GetScriptableTop();
+  nsGlobalWindow *topWindow = GetScriptableTopInternal();
   if (!topWindow) {
     NS_ERROR("EnableDialogs() called without a top window?");
     return;
   }
 
   // TODO: Warn if no top window?
   topWindow = topWindow->GetCurrentInnerWindowInternal();
   if (topWindow) {
@@ -3561,80 +3557,49 @@ nsPIDOMWindow::UnmuteAudioContexts()
 
   for (uint32_t i = 0; i < mAudioContexts.Length(); ++i) {
     if (!mAudioContexts[i]->IsOffline()) {
       mAudioContexts[i]->Unmute();
     }
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetDocument(nsIDOMDocument** aDocument)
-{
-  nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(GetDocument());
-  document.forget(aDocument);
-  return NS_OK;
-}
-
 nsGlobalWindow*
 nsGlobalWindow::Window()
 {
   return this;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetWindow(nsIDOMWindow** aWindow)
-{
-  FORWARD_TO_OUTER(GetWindow, (aWindow), NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIDOMWindow> window = Window();
-  window.forget(aWindow);
-
-  return NS_OK;
-}
-
 nsGlobalWindow*
 nsGlobalWindow::Self()
 {
   return this;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetSelf(nsIDOMWindow** aWindow)
-{
-  FORWARD_TO_OUTER(GetSelf, (aWindow), NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIDOMWindow> window = Self();
-  window.forget(aWindow);
-
-  return NS_OK;
-}
-
 Navigator*
 nsGlobalWindow::GetNavigator(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mNavigator) {
     mNavigator = new Navigator(this);
   }
 
   return mNavigator;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetNavigator(nsIDOMNavigator** aNavigator)
-{
-  FORWARD_TO_INNER(GetNavigator, (aNavigator), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMNavigator> navigator = GetNavigator(rv);
-  navigator.forget(aNavigator);
-
-  return rv.StealNSResult();
+nsIDOMNavigator*
+nsGlobalWindow::GetNavigator()
+{
+  FORWARD_TO_INNER(GetNavigator, (), nullptr);
+
+  ErrorResult dummy;
+  nsIDOMNavigator* navigator = GetNavigator(dummy);
+  dummy.SuppressException();
+  return navigator;
 }
 
 nsScreen*
 nsGlobalWindow::GetScreen(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mScreen) {
@@ -3643,52 +3608,39 @@ nsGlobalWindow::GetScreen(ErrorResult& a
       aError.Throw(NS_ERROR_UNEXPECTED);
       return nullptr;
     }
   }
 
   return mScreen;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScreen(nsIDOMScreen** aScreen)
-{
-  FORWARD_TO_INNER(GetScreen, (aScreen), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  RefPtr<nsScreen> screen = GetScreen(rv);
-  screen.forget(aScreen);
-
-  return rv.StealNSResult();
+nsIDOMScreen*
+nsGlobalWindow::GetScreen()
+{
+  FORWARD_TO_INNER(GetScreen, (), nullptr);
+
+  ErrorResult dummy;
+  nsIDOMScreen* screen = GetScreen(dummy);
+  dummy.SuppressException();
+  return screen;
 }
 
 nsHistory*
 nsGlobalWindow::GetHistory(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mHistory) {
     mHistory = new nsHistory(this);
   }
 
   return mHistory;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetHistory(nsISupports** aHistory)
-{
-  FORWARD_TO_INNER(GetHistory, (aHistory), NS_ERROR_FAILURE);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> history = GetHistory(rv);
-  history.forget(aHistory);
-
-  return rv.StealNSResult();
-}
-
 nsPerformance*
 nsPIDOMWindow::GetPerformance()
 {
   MOZ_ASSERT(IsInnerWindow());
   CreatePerformanceObjectIfNeeded();
   return mPerformance;
 }
 
@@ -3707,25 +3659,23 @@ nsPIDOMWindow::CreatePerformanceObjectIf
       !NS_SUCCEEDED(timedChannel->GetTimingEnabled(&timingEnabled)) ||
       !timingEnabled) {
     timedChannel = nullptr;
   }
   if (timing) {
     // If we are dealing with an iframe, we will need the parent's performance
     // object (so we can add the iframe as a resource of that page).
     nsPerformance* parentPerformance = nullptr;
-    nsCOMPtr<nsIDOMWindow> parentWindow;
-    GetScriptableParent(getter_AddRefs(parentWindow));
-    nsCOMPtr<nsPIDOMWindow> parentPWindow = do_GetInterface(parentWindow);
-    if (GetOuterWindow() != parentPWindow) {
-      if (parentPWindow && !parentPWindow->IsInnerWindow()) {
-        parentPWindow = parentPWindow->GetCurrentInnerWindow();
+    nsCOMPtr<nsPIDOMWindow> parentWindow = GetScriptableParent();
+    if (GetOuterWindow() != parentWindow) {
+      if (parentWindow && !parentWindow->IsInnerWindow()) {
+        parentWindow = parentWindow->GetCurrentInnerWindow();
       }
-      if (parentPWindow) {
-        parentPerformance = parentPWindow->GetPerformance();
+      if (parentWindow) {
+        parentPerformance = parentWindow->GetPerformance();
       }
     }
     mPerformance =
       new nsPerformance(this, timing, timedChannel, parentPerformance);
   }
 }
 
 bool
@@ -3823,112 +3773,105 @@ nsGlobalWindow::GetSpeechSynthesis(Error
     mSpeechSynthesis = new SpeechSynthesis(this);
   }
 
   return mSpeechSynthesis;
 }
 #endif
 
 already_AddRefed<nsIDOMWindow>
-nsGlobalWindow::GetParentOuter(ErrorResult& aError)
+nsGlobalWindow::GetParentOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return nullptr;
   }
 
   nsCOMPtr<nsIDOMWindow> parent;
   if (mDocShell->GetIsBrowserOrApp()) {
     parent = this;
   } else {
-    aError = GetRealParent(getter_AddRefs(parent));
+    parent = GetParent();
   }
 
   return parent.forget();
 }
 
 already_AddRefed<nsIDOMWindow>
 nsGlobalWindow::GetParent(ErrorResult& aError)
 {
-  FORWARD_TO_OUTER_OR_THROW(GetParentOuter, (aError), aError, nullptr);
+  FORWARD_TO_OUTER_OR_THROW(GetParentOuter, (), aError, nullptr);
 }
 
 /**
  * GetScriptableParent is called when script reads window.parent.
  *
  * In contrast to GetRealParent, GetScriptableParent respects <iframe
  * mozbrowser> boundaries, so if |this| is contained by an <iframe
  * mozbrowser>, we will return |this| as its own parent.
  */
-NS_IMETHODIMP
-nsGlobalWindow::GetScriptableParent(nsIDOMWindow** aParent)
-{
-  FORWARD_TO_OUTER(GetScriptableParent, (aParent), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMWindow> parent = GetParentOuter(rv);
-  parent.forget(aParent);
-
-  return rv.StealNSResult();
+nsPIDOMWindow*
+nsGlobalWindow::GetScriptableParent()
+{
+  FORWARD_TO_OUTER(GetScriptableParent, (), nullptr);
+
+  nsCOMPtr<nsIDOMWindow> parent = GetParentOuter();
+  nsCOMPtr<nsPIDOMWindow> piParent = do_QueryInterface(parent);
+  return piParent.get();
 }
 
 /**
- * nsIDOMWindow::GetParent (when called from C++) is just a wrapper around
+ * nsPIDOMWindow::GetParent (when called from C++) is just a wrapper around
  * GetRealParent.
  */
-NS_IMETHODIMP
-nsGlobalWindow::GetRealParent(nsIDOMWindow** aParent)
-{
-  FORWARD_TO_OUTER(GetRealParent, (aParent), NS_ERROR_NOT_INITIALIZED);
-
-  *aParent = nullptr;
+already_AddRefed<nsPIDOMWindow>
+nsGlobalWindow::GetParent()
+{
+  MOZ_ASSERT(IsOuterWindow());
+
   if (!mDocShell) {
-    return NS_OK;
+    return nullptr;
   }
 
   nsCOMPtr<nsIDocShell> parent;
   mDocShell->GetSameTypeParentIgnoreBrowserAndAppBoundaries(getter_AddRefs(parent));
 
   if (parent) {
     nsCOMPtr<nsPIDOMWindow> win = parent->GetWindow();
-    win.forget(aParent);
-  }
-  else {
-    *aParent = static_cast<nsIDOMWindow*>(this);
-    NS_ADDREF(*aParent);
-  }
-  return NS_OK;
+    return win.forget();
+  }
+
+  nsCOMPtr<nsPIDOMWindow> win(this);
+  return win.forget();
 }
 
 static nsresult
-GetTopImpl(nsGlobalWindow* aWin, nsIDOMWindow** aTop, bool aScriptable)
+GetTopImpl(nsGlobalWindow* aWin, nsPIDOMWindow** aTop, bool aScriptable)
 {
   *aTop = nullptr;
 
   // Walk up the parent chain.
 
-  nsCOMPtr<nsIDOMWindow> prevParent = aWin;
-  nsCOMPtr<nsIDOMWindow> parent = aWin;
+  nsCOMPtr<nsPIDOMWindow> prevParent = aWin;
+  nsCOMPtr<nsPIDOMWindow> parent = aWin;
   do {
     if (!parent) {
       break;
     }
 
     prevParent = parent;
 
-    nsCOMPtr<nsIDOMWindow> newParent;
-    nsresult rv;
+    nsCOMPtr<nsPIDOMWindow> newParent;
     if (aScriptable) {
-      rv = parent->GetScriptableParent(getter_AddRefs(newParent));
+      newParent = parent->GetScriptableParent();
     }
     else {
-      rv = parent->GetParent(getter_AddRefs(newParent));
-    }
-    NS_ENSURE_SUCCESS(rv, rv);
+      newParent = parent->GetParent();
+    }
 
     parent = newParent;
 
   } while (parent != prevParent);
 
   if (parent) {
     parent.swap(*aTop);
   }
@@ -3938,40 +3881,32 @@ GetTopImpl(nsGlobalWindow* aWin, nsIDOMW
 
 /**
  * GetScriptableTop is called when script reads window.top.
  *
  * In contrast to GetRealTop, GetScriptableTop respects <iframe mozbrowser>
  * boundaries.  If we encounter a window owned by an <iframe mozbrowser> while
  * walking up the window hierarchy, we'll stop and return that window.
  */
-NS_IMETHODIMP
-nsGlobalWindow::GetScriptableTop(nsIDOMWindow **aTop)
-{
-  FORWARD_TO_OUTER(GetScriptableTop, (aTop), NS_ERROR_NOT_INITIALIZED);
-  return GetTopImpl(this, aTop, /* aScriptable = */ true);
-}
-
-/**
- * nsIDOMWindow::GetTop (when called from C++) is just a wrapper around
- * GetRealTop.
- */
-NS_IMETHODIMP
-nsGlobalWindow::GetRealTop(nsIDOMWindow** aTop)
-{
-  nsGlobalWindow* outer;
-  if (IsInnerWindow()) {
-    outer = GetOuterWindowInternal();
-    if (!outer) {
-      return NS_ERROR_NOT_INITIALIZED;
-    }
-  } else {
-    outer = this;
-  }
-  return GetTopImpl(outer, aTop, /* aScriptable = */ false);
+nsPIDOMWindow*
+nsGlobalWindow::GetScriptableTop()
+{
+  FORWARD_TO_OUTER(GetScriptableTop, (), nullptr);
+  nsCOMPtr<nsPIDOMWindow> window;
+  GetTopImpl(this, getter_AddRefs(window), /* aScriptable = */ true);
+  return window.get();
+}
+
+already_AddRefed<nsPIDOMWindow>
+nsGlobalWindow::GetTop()
+{
+  MOZ_ASSERT(IsOuterWindow());
+  nsCOMPtr<nsPIDOMWindow> window;
+  GetTopImpl(this, getter_AddRefs(window), /* aScriptable = */ false);
+  return window.forget();
 }
 
 void
 nsGlobalWindow::GetContentOuter(JSContext* aCx,
                                 JS::MutableHandle<JSObject*> aRetval,
                                 ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
@@ -4014,17 +3949,17 @@ nsGlobalWindow::GetContentInternal(Error
     GetChildWindow(NS_LITERAL_STRING("content"));
   if (domWindow) {
     return domWindow.forget();
   }
 
   // If we're contained in <iframe mozbrowser> or <iframe mozapp>, then
   // GetContent is the same as window.top.
   if (mDocShell && mDocShell->GetIsInBrowserOrApp()) {
-    return GetTopOuter(aError);
+    return GetTopOuter();
   }
 
   nsCOMPtr<nsIDocShellTreeItem> primaryContent;
   if (aUnprivilegedCaller) {
     // If we're called by non-chrome code, make sure we don't return
     // the primary content window if the calling tab is hidden. In
     // such a case we return the same-type root in the hidden tab,
     // which is "good enough", for now.
@@ -4081,17 +4016,17 @@ nsGlobalWindow::GetScriptableContent(JSC
   GetContent(aCx, &content, rv);
   if (!rv.Failed()) {
     aVal.setObjectOrNull(content);
   }
 
   return rv.StealNSResult();
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::GetPrompter(nsIPrompt** aPrompt)
 {
   if (IsInnerWindow()) {
     nsGlobalWindow* outer = GetOuterWindowInternal();
     if (!outer) {
       NS_WARNING("No outer window available!");
       return NS_ERROR_NOT_INITIALIZED;
     }
@@ -4115,191 +4050,115 @@ nsGlobalWindow::GetMenubar(ErrorResult& 
 
   if (!mMenubar) {
     mMenubar = new MenubarProp(this);
   }
 
   return mMenubar;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetMenubar(nsISupports** aMenubar)
-{
-  FORWARD_TO_INNER(GetMenubar, (aMenubar), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> menubar = GetMenubar(rv);
-  menubar.forget(aMenubar);
-
-  return rv.StealNSResult();
-}
-
 BarProp*
 nsGlobalWindow::GetToolbar(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mToolbar) {
     mToolbar = new ToolbarProp(this);
   }
 
   return mToolbar;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetToolbar(nsISupports** aToolbar)
-{
-  FORWARD_TO_INNER(GetToolbar, (aToolbar), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> toolbar = GetToolbar(rv);
-  toolbar.forget(aToolbar);
-
-  return rv.StealNSResult();
-}
-
 BarProp*
 nsGlobalWindow::GetLocationbar(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mLocationbar) {
     mLocationbar = new LocationbarProp(this);
   }
   return mLocationbar;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetLocationbar(nsISupports** aLocationbar)
-{
-  FORWARD_TO_INNER(GetLocationbar, (aLocationbar), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> locationbar = GetLocationbar(rv);
-  locationbar.forget(aLocationbar);
-
-  return rv.StealNSResult();
-}
-
 BarProp*
 nsGlobalWindow::GetPersonalbar(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mPersonalbar) {
     mPersonalbar = new PersonalbarProp(this);
   }
   return mPersonalbar;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetPersonalbar(nsISupports** aPersonalbar)
-{
-  FORWARD_TO_INNER(GetPersonalbar, (aPersonalbar), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> personalbar = GetPersonalbar(rv);
-  personalbar.forget(aPersonalbar);
-
-  return rv.StealNSResult();
-}
-
 BarProp*
 nsGlobalWindow::GetStatusbar(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mStatusbar) {
     mStatusbar = new StatusbarProp(this);
   }
   return mStatusbar;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetStatusbar(nsISupports** aStatusbar)
-{
-  FORWARD_TO_INNER(GetStatusbar, (aStatusbar), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> statusbar = GetStatusbar(rv);
-  statusbar.forget(aStatusbar);
-
-  return rv.StealNSResult();
-}
-
 BarProp*
 nsGlobalWindow::GetScrollbars(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mScrollbars) {
     mScrollbars = new ScrollbarsProp(this);
   }
 
   return mScrollbars;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScrollbars(nsISupports** aScrollbars)
-{
-  FORWARD_TO_INNER(GetScrollbars, (aScrollbars), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> scrollbars = GetScrollbars(rv);
-  scrollbars.forget(aScrollbars);
-
-  return rv.StealNSResult();
-}
-
 bool
 nsGlobalWindow::GetClosedOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   // If someone called close(), or if we don't have a docshell, we're closed.
   return mIsClosed || !mDocShell;
 }
 
 bool
 nsGlobalWindow::GetClosed(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetClosedOuter, (), aError, false);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetClosed(bool* aClosed)
-{
-  FORWARD_TO_INNER(GetClosed, (aClosed), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aClosed = GetClosed(rv);
-
-  return rv.StealNSResult();
+bool
+nsGlobalWindow::Closed()
+{
+  MOZ_ASSERT(IsOuterWindow());
+
+  return GetClosedOuter();
 }
 
 nsDOMWindowList*
 nsGlobalWindow::GetWindowList()
 {
   MOZ_ASSERT(IsOuterWindow());
 
   if (!mFrames && mDocShell) {
     mFrames = new nsDOMWindowList(mDocShell);
   }
 
   return mFrames;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetFrames(nsIDOMWindowCollection** aFrames)
-{
-  FORWARD_TO_OUTER(GetFrames, (aFrames), NS_ERROR_NOT_INITIALIZED);
-
-  *aFrames = GetWindowList();
-  NS_IF_ADDREF(*aFrames);
-  return NS_OK;
+already_AddRefed<nsIDOMWindowCollection>
+nsGlobalWindow::GetFrames()
+{
+  FORWARD_TO_OUTER(GetFrames, (), nullptr);
+
+  nsCOMPtr<nsIDOMWindowCollection> frames = GetWindowList();
+  return frames.forget();
 }
 
 already_AddRefed<nsIDOMWindow>
 nsGlobalWindow::IndexedGetterOuter(uint32_t aIndex)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsDOMWindowList* windows = GetWindowList();
@@ -4465,53 +4324,40 @@ nsGlobalWindow::GetApplicationCache(Erro
     applicationCache->Init();
 
     mApplicationCache = applicationCache;
   }
 
   return mApplicationCache;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetApplicationCache(nsIDOMOfflineResourceList **aApplicationCache)
-{
-  FORWARD_TO_INNER(GetApplicationCache, (aApplicationCache), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
+already_AddRefed<nsIDOMOfflineResourceList>
+nsGlobalWindow::GetApplicationCache()
+{
+  FORWARD_TO_INNER(GetApplicationCache, (), nullptr);
+
+  ErrorResult dummy;
   nsCOMPtr<nsIDOMOfflineResourceList> applicationCache =
-    GetApplicationCache(rv);
-  applicationCache.forget(aApplicationCache);
-
-  return rv.StealNSResult();
+    GetApplicationCache(dummy);
+  dummy.SuppressException();
+  return applicationCache.forget();
 }
 
 Crypto*
 nsGlobalWindow::GetCrypto(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mCrypto) {
     mCrypto = new Crypto();
     mCrypto->Init(this);
   }
   return mCrypto;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto)
-{
-  FORWARD_TO_INNER(GetCrypto, (aCrypto), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMCrypto> crypto = GetCrypto(rv);
-  crypto.forget(aCrypto);
-
-  return rv.StealNSResult();
-}
-
 nsIControllers*
 nsGlobalWindow::GetControllersOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mControllers) {
     nsresult rv;
     mControllers = do_CreateInstance(kXULControllersCID, &rv);
@@ -4542,29 +4388,29 @@ nsGlobalWindow::GetControllersOuter(Erro
 }
 
 nsIControllers*
 nsGlobalWindow::GetControllers(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetControllersOuter, (aError), aError, nullptr);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::GetControllers(nsIControllers** aResult)
 {
   FORWARD_TO_INNER(GetControllers, (aResult), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   nsCOMPtr<nsIControllers> controllers = GetControllers(rv);
   controllers.forget(aResult);
 
   return rv.StealNSResult();
 }
 
-nsIDOMWindow*
+nsPIDOMWindow*
 nsGlobalWindow::GetOpenerWindowOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsPIDOMWindow> opener = do_QueryReferent(mOpener);
   if (!opener) {
     return nullptr;
   }
@@ -4602,58 +4448,46 @@ nsGlobalWindow::GetOpenerWindowOuter()
         return opener;
       }
     }
   }
 
   return nullptr;
 }
 
-nsIDOMWindow*
+nsPIDOMWindow*
 nsGlobalWindow::GetOpenerWindow(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetOpenerWindowOuter, (), aError, nullptr);
 }
 
 void
 nsGlobalWindow::GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
                           ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
 
-  nsCOMPtr<nsIDOMWindow> opener = GetOpenerWindow(aError);
+  nsCOMPtr<nsPIDOMWindow> opener = GetOpenerWindow(aError);
   if (aError.Failed() || !opener) {
     aRetval.setNull();
     return;
   }
 
   aError = nsContentUtils::WrapNative(aCx, opener, aRetval);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScriptableOpener(JSContext* aCx,
-                                    JS::MutableHandle<JS::Value> aOpener)
-{
-  FORWARD_TO_INNER(GetScriptableOpener, (aCx, aOpener), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  GetOpener(aCx, aOpener, rv);
-
-  return rv.StealNSResult();
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::GetOpener(nsIDOMWindow** aOpener)
-{
-  FORWARD_TO_INNER(GetOpener, (aOpener), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMWindow> opener = GetOpenerWindow(rv);
-  opener.forget(aOpener);
-  return rv.StealNSResult();
+already_AddRefed<nsPIDOMWindow>
+nsGlobalWindow::GetOpener()
+{
+  FORWARD_TO_INNER(GetOpener, (), nullptr);
+
+  ErrorResult dummy;
+  nsCOMPtr<nsPIDOMWindow> opener = GetOpenerWindow(dummy);
+  dummy.SuppressException();
+  return opener.forget();
 }
 
 void
 nsGlobalWindow::SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
                           ErrorResult& aError)
 {
   // Check if we were called from a privileged chrome script.  If not, and if
   // aOpener is not null, just define aOpener on our inner window's JS object,
@@ -4695,58 +4529,30 @@ nsGlobalWindow::SetOpener(JSContext* aCx
       return;
     }
     win = win->GetOuterWindow();
   }
 
   SetOpenerWindow(win, false);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetScriptableOpener(JSContext* aCx,
-                                    JS::Handle<JS::Value> aOpener)
-{
-  ErrorResult rv;
-  SetOpener(aCx, aOpener, rv);
-
-  return rv.StealNSResult();
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::SetOpener(nsIDOMWindow* aOpener)
-{
-  SetOpenerWindow(aOpener, false);
-  return NS_OK;
-}
-
 void
 nsGlobalWindow::GetStatusOuter(nsAString& aStatus)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   aStatus = mStatus;
 }
 
 void
 nsGlobalWindow::GetStatus(nsAString& aStatus, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetStatusOuter, (aStatus), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetStatus(nsAString& aStatus)
-{
-  FORWARD_TO_INNER(GetStatus, (aStatus), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  GetStatus(aStatus, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SetStatusOuter(const nsAString& aStatus)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   mStatus = aStatus;
 
   /*
@@ -4766,81 +4572,48 @@ nsGlobalWindow::SetStatusOuter(const nsA
 }
 
 void
 nsGlobalWindow::SetStatus(const nsAString& aStatus, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(SetStatusOuter, (aStatus), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetStatus(const nsAString& aStatus)
-{
-  FORWARD_TO_INNER(SetStatus, (aStatus), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  SetStatus(aStatus, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::GetNameOuter(nsAString& aName)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (mDocShell) {
     mDocShell->GetName(aName);
   }
 }
 
 void
 nsGlobalWindow::GetName(nsAString& aName, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetNameOuter, (aName), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetName(nsAString& aName)
-{
-  FORWARD_TO_INNER(GetName, (aName), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  GetName(aName, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SetNameOuter(const nsAString& aName, mozilla::ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (mDocShell) {
     aError = mDocShell->SetName(aName);
   }
 }
 
 void
 nsGlobalWindow::SetName(const nsAString& aName, mozilla::ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(SetNameOuter, (aName, aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetName(const nsAString& aName)
-{
-  FORWARD_TO_INNER(SetName, (aName), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  SetName(aName, rv);
-
-  return rv.StealNSResult();
-}
-
 // Helper functions used by many methods below.
 int32_t
 nsGlobalWindow::DevToCSSIntPixels(int32_t px)
 {
   if (!mDocShell)
     return px; // assume 1:1
 
   RefPtr<nsPresContext> presContext;
@@ -4956,17 +4729,17 @@ void
 nsGlobalWindow::GetInnerWidth(JSContext* aCx,
                               JS::MutableHandle<JS::Value> aValue,
                               ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetInnerWidth, aValue,
                             aError);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::GetInnerWidth(int32_t* aInnerWidth)
 {
   FORWARD_TO_INNER(GetInnerWidth, (aInnerWidth), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   *aInnerWidth = GetInnerWidth(rv);
 
   return rv.StealNSResult();
@@ -5017,31 +4790,16 @@ nsGlobalWindow::SetInnerWidth(int32_t aI
 void
 nsGlobalWindow::SetInnerWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
                               ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetInnerWidth,
                             aValue, "innerWidth", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetInnerWidth(int32_t aInnerWidth)
-{
-  FORWARD_TO_OUTER(SetInnerWidth, (aInnerWidth), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetInnerWidthOuter(aInnerWidth, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::GetInnerHeightOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   CSSIntSize size;
   aError = GetInnerSize(size);
   return size.height;
@@ -5057,17 +4815,17 @@ void
 nsGlobalWindow::GetInnerHeight(JSContext* aCx,
                               JS::MutableHandle<JS::Value> aValue,
                               ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetInnerHeight, aValue,
                             aError);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::GetInnerHeight(int32_t* aInnerHeight)
 {
   FORWARD_TO_INNER(GetInnerHeight, (aInnerHeight), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   *aInnerHeight = GetInnerHeight(rv);
 
   return rv.StealNSResult();
@@ -5117,31 +4875,16 @@ nsGlobalWindow::SetInnerHeight(int32_t a
 void
 nsGlobalWindow::SetInnerHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
                                ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetInnerHeight,
                             aValue, "innerHeight", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetInnerHeight(int32_t aInnerHeight)
-{
-  FORWARD_TO_OUTER(SetInnerHeight, (aInnerHeight), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetInnerHeightOuter(aInnerHeight, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 nsIntSize
 nsGlobalWindow::GetOuterSize(ErrorResult& aError)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   if (nsContentUtils::ShouldResistFingerprinting(mDocShell)) {
     CSSIntSize size;
     aError = GetInnerSize(size);
@@ -5186,27 +4929,16 @@ void
 nsGlobalWindow::GetOuterWidth(JSContext* aCx,
                               JS::MutableHandle<JS::Value> aValue,
                               ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetOuterWidth, aValue,
                             aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetOuterWidth(int32_t* aOuterWidth)
-{
-  FORWARD_TO_INNER(GetOuterWidth, (aOuterWidth), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aOuterWidth = GetOuterWidth(rv);
-
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::GetOuterHeightOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
   return GetOuterSize(aError).height;
 }
 
 int32_t
@@ -5219,27 +4951,16 @@ void
 nsGlobalWindow::GetOuterHeight(JSContext* aCx,
                                JS::MutableHandle<JS::Value> aValue,
                                ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetOuterHeight, aValue,
                             aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetOuterHeight(int32_t* aOuterHeight)
-{
-  FORWARD_TO_INNER(GetOuterHeight, (aOuterHeight), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aOuterHeight = GetOuterHeight(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
                              ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = GetTreeOwnerWindow();
   if (!treeOwnerAsWin) {
@@ -5283,31 +5004,16 @@ nsGlobalWindow::SetOuterWidth(int32_t aO
 void
 nsGlobalWindow::SetOuterWidth(JSContext* aCx, JS::Handle<JS::Value> aValue,
                               ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetOuterWidth,
                             aValue, "outerWidth", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetOuterWidth(int32_t aOuterWidth)
-{
-  FORWARD_TO_OUTER(SetOuterWidth, (aOuterWidth), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetOuterWidthOuter(aOuterWidth, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SetOuterHeightOuter(int32_t aOuterHeight, ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   SetOuterSize(aOuterHeight, false, aError, aCallerIsChrome);
 }
 
@@ -5320,31 +5026,16 @@ nsGlobalWindow::SetOuterHeight(int32_t a
 void
 nsGlobalWindow::SetOuterHeight(JSContext* aCx, JS::Handle<JS::Value> aValue,
                                ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetOuterHeight,
                             aValue, "outerHeight", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetOuterHeight(int32_t aOuterHeight)
-{
-  FORWARD_TO_OUTER(SetOuterHeight, (aOuterHeight), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetOuterHeightOuter(aOuterHeight, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 nsIntPoint
 nsGlobalWindow::GetScreenXY(ErrorResult& aError)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   // When resisting fingerprinting, always return (0,0)
   if (nsContentUtils::ShouldResistFingerprinting(mDocShell)) {
     return nsIntPoint(0, 0);
@@ -5379,27 +5070,16 @@ void
 nsGlobalWindow::GetScreenX(JSContext* aCx,
                            JS::MutableHandle<JS::Value> aValue,
                            ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetScreenX, aValue,
                             aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScreenX(int32_t* aScreenX)
-{
-  FORWARD_TO_INNER(GetScreenX, (aScreenX), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aScreenX = GetScreenX(rv);
-
-  return rv.StealNSResult();
-}
-
 nsRect
 nsGlobalWindow::GetInnerScreenRect()
 {
   MOZ_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return nsRect();
   }
@@ -5441,27 +5121,16 @@ nsGlobalWindow::GetMozInnerScreenXOuter(
 }
 
 float
 nsGlobalWindow::GetMozInnerScreenX(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetMozInnerScreenXOuter, (), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetMozInnerScreenX(float* aScreenX)
-{
-  FORWARD_TO_INNER(GetMozInnerScreenX, (aScreenX), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aScreenX = GetMozInnerScreenX(rv);
-
-  return rv.StealNSResult();
-}
-
 float
 nsGlobalWindow::GetMozInnerScreenYOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   // Return 0 to prevent fingerprinting.
   if (nsContentUtils::ShouldResistFingerprinting(mDocShell)) {
     return 0.0;
@@ -5472,27 +5141,16 @@ nsGlobalWindow::GetMozInnerScreenYOuter(
 }
 
 float
 nsGlobalWindow::GetMozInnerScreenY(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetMozInnerScreenYOuter, (), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetMozInnerScreenY(float* aScreenY)
-{
-  FORWARD_TO_INNER(GetMozInnerScreenY, (aScreenY), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aScreenY = GetMozInnerScreenY(rv);
-
-  return rv.StealNSResult();
-}
-
 float
 nsGlobalWindow::GetDevicePixelRatioOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return 1.0;
   }
@@ -5512,17 +5170,17 @@ nsGlobalWindow::GetDevicePixelRatioOuter
 }
 
 float
 nsGlobalWindow::GetDevicePixelRatio(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatioOuter, (), aError, 0.0);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::GetDevicePixelRatio(float* aRatio)
 {
   FORWARD_TO_INNER(GetDevicePixelRatio, (aRatio), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   *aRatio = GetDevicePixelRatio(rv);
 
   return rv.StealNSResult();
@@ -5542,27 +5200,16 @@ nsGlobalWindow::GetMozPaintCountOuter()
 }
 
 uint64_t
 nsGlobalWindow::GetMozPaintCount(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetMozPaintCountOuter, (), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetMozPaintCount(uint64_t* aResult)
-{
-  FORWARD_TO_INNER(GetMozPaintCount, (aResult), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aResult = GetMozPaintCount(rv);
-
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::RequestAnimationFrame(FrameRequestCallback& aCallback,
                                       ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mDoc) {
     return 0;
@@ -5572,59 +5219,28 @@ nsGlobalWindow::RequestAnimationFrame(Fr
     js::NotifyAnimationActivity(GetWrapperPreserveColor());
   }
 
   int32_t handle;
   aError = mDoc->ScheduleFrameRequestCallback(aCallback, &handle);
   return handle;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::RequestAnimationFrame(JS::Handle<JS::Value> aCallback,
-                                      JSContext* cx,
-                                      int32_t* aHandle)
-{
-  FORWARD_TO_INNER(RequestAnimationFrame, (aCallback, cx, aHandle), NS_ERROR_UNEXPECTED);
-  if (!aCallback.isObject() || !JS::IsCallable(&aCallback.toObject())) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  JS::Rooted<JSObject*> callbackObj(cx, &aCallback.toObject());
-  RefPtr<FrameRequestCallback> callback =
-    new FrameRequestCallback(cx, callbackObj, GetIncumbentGlobal());
-
-  ErrorResult rv;
-  *aHandle = RequestAnimationFrame(*callback, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::CancelAnimationFrame(int32_t aHandle, ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mDoc) {
     return;
   }
 
   mDoc->CancelFrameRequestCallback(aHandle);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::CancelAnimationFrame(int32_t aHandle)
-{
-  FORWARD_TO_INNER(CancelAnimationFrame, (aHandle), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  CancelAnimationFrame(aHandle, rv);
-
-  return rv.StealNSResult();
-}
-
 already_AddRefed<MediaQueryList>
 nsGlobalWindow::MatchMediaOuter(const nsAString& aMediaQueryList)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDoc) {
     return nullptr;
   }
@@ -5638,29 +5254,16 @@ nsGlobalWindow::MatchMedia(const nsAStri
 {
   // FIXME: This whole forward-to-outer and then get a pres
   // shell/context off the docshell dance is sort of silly; it'd make
   // more sense to forward to the inner, but it's what everyone else
   // (GetSelection, GetScrollXY, etc.) does around here.
   FORWARD_TO_OUTER_OR_THROW(MatchMediaOuter, (aMediaQueryList), aError, nullptr);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::MatchMedia(const nsAString& aMediaQueryList,
-                           nsISupports** aResult)
-{
-  FORWARD_TO_INNER(MatchMedia, (aMediaQueryList, aResult), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  RefPtr<MediaQueryList> mediaQueryList = MatchMedia(aMediaQueryList, rv);
-  mediaQueryList.forget(aResult);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SetScreenXOuter(int32_t aScreenX, ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = GetTreeOwnerWindow();
   if (!treeOwnerAsWin) {
     aError.Throw(NS_ERROR_FAILURE);
@@ -5688,56 +5291,30 @@ nsGlobalWindow::SetScreenX(int32_t aScre
 void
 nsGlobalWindow::SetScreenX(JSContext* aCx, JS::Handle<JS::Value> aValue,
                            ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetScreenX,
                             aValue, "screenX", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetScreenX(int32_t aScreenX)
-{
-  FORWARD_TO_OUTER(SetScreenX, (aScreenX), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetScreenXOuter(aScreenX, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::GetScreenYOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   return DevToCSSIntPixels(GetScreenXY(aError).y);
 }
 
 int32_t
 nsGlobalWindow::GetScreenY(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetScreenYOuter, (aError), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScreenY(int32_t* aScreenY)
-{
-  FORWARD_TO_INNER(GetScreenY, (aScreenY), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aScreenY = GetScreenY(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::GetScreenY(JSContext* aCx,
                            JS::MutableHandle<JS::Value> aValue,
                            ErrorResult& aError)
 {
   GetReplaceableWindowCoord(aCx, &nsGlobalWindow::GetScreenY, aValue,
                             aError);
 }
@@ -5774,31 +5351,16 @@ nsGlobalWindow::SetScreenY(int32_t aScre
 void
 nsGlobalWindow::SetScreenY(JSContext* aCx, JS::Handle<JS::Value> aValue,
                            ErrorResult& aError)
 {
   SetReplaceableWindowCoord(aCx, &nsGlobalWindow::SetScreenY,
                             aValue, "screenY", aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SetScreenY(int32_t aScreenY)
-{
-  FORWARD_TO_OUTER(SetScreenY, (aScreenY), NS_ERROR_UNEXPECTED);
-
-  if (IsFrame()) {
-    return NS_OK;
-  }
-
-  ErrorResult rv;
-  SetScreenYOuter(aScreenY, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 // NOTE: Arguments to this function should have values scaled to
 // CSS pixels, not device pixels.
 void
 nsGlobalWindow::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight, bool aCallerIsChrome)
 {
   MOZ_ASSERT(IsOuterWindow());
 
 #ifdef MOZ_XUL
@@ -5878,18 +5440,17 @@ nsGlobalWindow::CheckSecurityLeftAndTop(
     nsGlobalWindow* rootWindow =
       static_cast<nsGlobalWindow*>(GetPrivateRoot());
     if (rootWindow) {
       rootWindow->FlushPendingNotifications(Flush_Layout);
     }
 
     nsCOMPtr<nsIBaseWindow> treeOwner = GetTreeOwnerWindow();
 
-    nsCOMPtr<nsIDOMScreen> screen;
-    GetScreen(getter_AddRefs(screen));
+    nsCOMPtr<nsIDOMScreen> screen = GetScreen();
 
     if (treeOwner && screen) {
       int32_t screenLeft, screenTop, screenWidth, screenHeight;
       int32_t winLeft, winTop, winWidth, winHeight;
 
       // Get the window size
       treeOwner->GetPositionAndSize(&winLeft, &winTop, &winWidth, &winHeight);
 
@@ -5934,28 +5495,16 @@ nsGlobalWindow::CheckSecurityLeftAndTop(
       if (aLeft)
         *aLeft = 0;
       if (aTop)
         *aTop = 0;
     }
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetPageXOffset(int32_t* aPageXOffset)
-{
-  return GetScrollX(aPageXOffset);
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::GetPageYOffset(int32_t* aPageYOffset)
-{
-  return GetScrollY(aPageYOffset);
-}
-
 void
 nsGlobalWindow::GetScrollMaxXYOuter(int32_t* aScrollMaxX, int32_t* aScrollMaxY)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   FlushPendingNotifications(Flush_Layout);
   nsIScrollableFrame *sf = GetScrollFrame();
   if (!sf) {
@@ -5987,50 +5536,26 @@ nsGlobalWindow::GetScrollMaxX(ErrorResul
 {
   MOZ_ASSERT(IsInnerWindow());
 
   int32_t scrollMaxX = 0;
   GetScrollMaxXY(&scrollMaxX, nullptr, aError);
   return scrollMaxX;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScrollMaxX(int32_t* aScrollMaxX)
-{
-  FORWARD_TO_INNER(GetScrollMaxX, (aScrollMaxX), NS_ERROR_UNEXPECTED);
-
-  NS_ENSURE_ARG_POINTER(aScrollMaxX);
-  ErrorResult rv;
-  *aScrollMaxX = GetScrollMaxX(rv);
-
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::GetScrollMaxY(ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
 
   int32_t scrollMaxY = 0;
   GetScrollMaxXY(nullptr, &scrollMaxY, aError);
   return scrollMaxY;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScrollMaxY(int32_t* aScrollMaxY)
-{
-  FORWARD_TO_INNER(GetScrollMaxY, (aScrollMaxY), NS_ERROR_UNEXPECTED);
-
-  NS_ENSURE_ARG_POINTER(aScrollMaxY);
-  ErrorResult rv;
-  *aScrollMaxY = GetScrollMaxY(rv);
-
-  return rv.StealNSResult();
-}
-
 CSSIntPoint
 nsGlobalWindow::GetScrollXY(bool aDoFlush)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   if (aDoFlush) {
     FlushPendingNotifications(Flush_Layout);
   } else {
@@ -6061,80 +5586,52 @@ nsGlobalWindow::GetScrollXOuter()
 }
 
 int32_t
 nsGlobalWindow::GetScrollX(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetScrollXOuter, (), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScrollX(int32_t* aScrollX)
-{
-  FORWARD_TO_INNER(GetScrollX, (aScrollX), NS_ERROR_UNEXPECTED);
-  NS_ENSURE_ARG_POINTER(aScrollX);
-  ErrorResult rv;
-  *aScrollX = GetScrollX(rv);
-  return rv.StealNSResult();
-}
-
 int32_t
 nsGlobalWindow::GetScrollYOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
   return GetScrollXY(false).y;
 }
 
 int32_t
 nsGlobalWindow::GetScrollY(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetScrollYOuter, (), aError, 0);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetScrollY(int32_t* aScrollY)
-{
-  FORWARD_TO_INNER(GetScrollY, (aScrollY), NS_ERROR_UNEXPECTED);
-  NS_ENSURE_ARG_POINTER(aScrollY);
-  ErrorResult rv;
-  *aScrollY = GetScrollY(rv);
-  return rv.StealNSResult();
-}
-
 uint32_t
 nsGlobalWindow::Length()
 {
   FORWARD_TO_OUTER(Length, (), 0);
 
   nsDOMWindowList* windows = GetWindowList();
 
   return windows ? windows->GetLength() : 0;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetLength(uint32_t* aLength)
-{
-  *aLength = Length();
-  return NS_OK;
-}
-
 already_AddRefed<nsIDOMWindow>
-nsGlobalWindow::GetTopOuter(mozilla::ErrorResult& aError)
+nsGlobalWindow::GetTopOuter()
 {
   MOZ_ASSERT(IsOuterWindow());
 
-  nsCOMPtr<nsIDOMWindow> top;
-  aError = GetScriptableTop(getter_AddRefs(top));
+  nsCOMPtr<nsPIDOMWindow> top = GetScriptableTop();
   return top.forget();
 }
 
 already_AddRefed<nsIDOMWindow>
 nsGlobalWindow::GetTop(mozilla::ErrorResult& aError)
 {
-  FORWARD_TO_OUTER_OR_THROW(GetTopOuter, (aError), aError, nullptr);
+  FORWARD_TO_OUTER_OR_THROW(GetTopOuter, (), aError, nullptr);
 }
 
 nsPIDOMWindow*
 nsGlobalWindow::GetChildWindow(const nsAString& aName)
 {
   nsCOMPtr<nsIDocShell> docShell(GetDocShell());
   NS_ENSURE_TRUE(docShell, nullptr);
 
@@ -6280,17 +5777,17 @@ nsGlobalWindow::SetFullScreenOuter(bool 
 }
 
 void
 nsGlobalWindow::SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(SetFullScreenOuter, (aFullScreen, aError), aError, /* void */);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::SetFullScreen(bool aFullScreen)
 {
   FORWARD_TO_OUTER(SetFullScreen, (aFullScreen), NS_ERROR_NOT_INITIALIZED);
 
   return SetFullscreenInternal(eForFullscreenMode, aFullScreen);
 }
 
 void
@@ -6613,17 +6110,17 @@ nsGlobalWindow::SetFullscreenInternal(Fu
   return NS_OK;
 }
 
 void
 nsGlobalWindow::SetWidgetFullscreen(FullscreenReason aReason, bool aIsFullscreen,
                                     nsIWidget* aWidget, nsIScreen* aScreen)
 {
   MOZ_ASSERT(IsOuterWindow());
-  MOZ_ASSERT(this == GetTop(), "Only topmost window should call this");
+  MOZ_ASSERT(this == GetTopInternal(), "Only topmost window should call this");
   MOZ_ASSERT(!GetFrameElementInternal(), "Content window should not call this");
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
 
   if (nsCOMPtr<nsIPresShell> presShell = mDocShell->GetPresShell()) {
     presShell->SetIsInFullscreenChange(true);
   }
   if (aReason == nsPIDOMWindow::eForFullscreenMode) {
     // If we enter fullscreen for fullscreen mode, we want
@@ -6727,25 +6224,25 @@ nsGlobalWindow::GetFullScreenOuter()
 }
 
 bool
 nsGlobalWindow::GetFullScreen(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetFullScreenOuter, (), aError, false);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetFullScreen(bool* aFullScreen)
-{
-  FORWARD_TO_INNER(GetFullScreen, (aFullScreen), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aFullScreen = GetFullScreen(rv);
-
-  return rv.StealNSResult();
+bool
+nsGlobalWindow::GetFullScreen()
+{
+  FORWARD_TO_INNER(GetFullScreen, (), false);
+
+  ErrorResult dummy;
+  bool fullscreen = GetFullScreen(dummy);
+  dummy.SuppressException();
+  return fullscreen;
 }
 
 void
 nsGlobalWindow::Dump(const nsAString& aStr)
 {
   if (!nsContentUtils::DOMWindowDumpEnabled()) {
     return;
   }
@@ -6795,47 +6292,16 @@ nsGlobalWindow::EnsureReflowFlushAndPain
   if (mDoc) {
     mDoc->FlushPendingNotifications(Flush_Layout);
   }
 
   // Unsuppress painting.
   presShell->UnsuppressPainting();
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetTextZoom(float *aZoom)
-{
-  FORWARD_TO_OUTER(GetTextZoom, (aZoom), NS_ERROR_NOT_INITIALIZED);
-
-  if (mDocShell) {
-    nsCOMPtr<nsIContentViewer> contentViewer;
-    mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
-
-    if (contentViewer) {
-      return contentViewer->GetTextZoom(aZoom);
-    }
-  }
-  return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::SetTextZoom(float aZoom)
-{
-  FORWARD_TO_OUTER(SetTextZoom, (aZoom), NS_ERROR_NOT_INITIALIZED);
-
-  if (mDocShell) {
-    nsCOMPtr<nsIContentViewer> contentViewer;
-    mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
-
-    if (contentViewer)
-      return contentViewer->SetTextZoom(aZoom);
-  }
-  return NS_ERROR_FAILURE;
-}
-
 // static
 void
 nsGlobalWindow::MakeScriptDialogTitle(nsAString &aOutTitle)
 {
   aOutTitle.Truncate();
 
   // Try to get a host from the running principal -- this will do the
   // right thing for javascript: and data: documents.
@@ -7036,52 +6502,30 @@ nsGlobalWindow::AlertOuter(const nsAStri
 }
 
 void
 nsGlobalWindow::Alert(const nsAString& aMessage, mozilla::ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(AlertOuter, (aMessage, aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Alert(const nsAString& aString)
-{
-  FORWARD_TO_INNER(Alert, (aString), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Alert(aString, rv);
-
-  return rv.StealNSResult();
-}
-
 bool
 nsGlobalWindow::ConfirmOuter(const nsAString& aMessage, ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   return AlertOrConfirm(/* aAlert = */ false, aMessage, aError);
 }
 
 bool
 nsGlobalWindow::Confirm(const nsAString& aMessage, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(ConfirmOuter, (aMessage, aError), aError, false);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Confirm(const nsAString& aString, bool* aReturn)
-{
-  FORWARD_TO_INNER(Confirm, (aString, aReturn), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aReturn = Confirm(aString, rv);
-
-  return rv.StealNSResult();
-}
-
 already_AddRefed<Promise>
 nsGlobalWindow::Fetch(const RequestOrUSVString& aInput,
                       const RequestInit& aInit, ErrorResult& aRv)
 {
   return FetchRequest(this, aInput, aInit, aRv);
 }
 
 void
@@ -7170,28 +6614,16 @@ nsGlobalWindow::PromptOuter(const nsAStr
 void
 nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial,
                        nsAString& aReturn, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(PromptOuter, (aMessage, aInitial, aReturn, aError),
                             aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial,
-                       nsAString& aReturn)
-{
-  FORWARD_TO_INNER(Prompt, (aMessage, aInitial, aReturn), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Prompt(aMessage, aInitial, aReturn, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::FocusOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (!fm) {
     return;
@@ -7206,18 +6638,17 @@ nsGlobalWindow::FocusOuter(ErrorResult& 
 
   if (!isVisible) {
     // A hidden tab is being focused, ignore this call.
     return;
   }
 
   nsCOMPtr<nsPIDOMWindow> caller = do_QueryInterface(GetEntryGlobal());
   caller = caller ? caller->GetOuterWindow() : nullptr;
-  nsCOMPtr<nsIDOMWindow> opener;
-  GetOpener(getter_AddRefs(opener));
+  nsCOMPtr<nsIDOMWindow> opener = GetOpener();
 
   // Enforce dom.disable_window_flip (for non-chrome), but still allow the
   // window which opened us to raise us at times when popups are allowed
   // (bugs 355482 and 369306).
   bool canFocus = CanSetProperty("dom.disable_window_flip") ||
                     (opener == caller &&
                      RevisePopupAbuseLevel(gPopupControlState) < openAbused);
 
@@ -7297,17 +6728,17 @@ nsGlobalWindow::FocusOuter(ErrorResult& 
 }
 
 void
 nsGlobalWindow::Focus(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(FocusOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::Focus()
 {
   FORWARD_TO_INNER(Focus, (), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   Focus(rv);
 
   return rv.StealNSResult();
@@ -7346,25 +6777,16 @@ nsGlobalWindow::BlurOuter()
 }
 
 void
 nsGlobalWindow::Blur(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(BlurOuter, (), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Blur()
-{
-  ErrorResult rv;
-  Blur(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::BackOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
   if (!webNav) {
     aError.Throw(NS_ERROR_FAILURE);
@@ -7375,27 +6797,16 @@ nsGlobalWindow::BackOuter(ErrorResult& a
 }
 
 void
 nsGlobalWindow::Back(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(BackOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Back()
-{
-  FORWARD_TO_INNER(Back, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Back(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::ForwardOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
   if (!webNav) {
     aError.Throw(NS_ERROR_FAILURE);
@@ -7406,27 +6817,16 @@ nsGlobalWindow::ForwardOuter(ErrorResult
 }
 
 void
 nsGlobalWindow::Forward(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(ForwardOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Forward()
-{
-  FORWARD_TO_INNER(Forward, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Forward(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::HomeOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return;
   }
@@ -7475,27 +6875,16 @@ nsGlobalWindow::HomeOuter(ErrorResult& a
 }
 
 void
 nsGlobalWindow::Home(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(HomeOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Home()
-{
-  FORWARD_TO_INNER(Home, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Home(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::StopOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
   if (webNav) {
     aError = webNav->Stop(nsIWebNavigation::STOP_ALL);
@@ -7503,27 +6892,16 @@ nsGlobalWindow::StopOuter(ErrorResult& a
 }
 
 void
 nsGlobalWindow::Stop(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(StopOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Stop()
-{
-  FORWARD_TO_INNER(Stop, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Stop(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::PrintOuter(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
 #ifdef NS_PRINTING
   if (Preferences::GetBool("dom.disable_window_print", false)) {
     aError.Throw(NS_ERROR_NOT_AVAILABLE);
@@ -7599,27 +6977,16 @@ nsGlobalWindow::PrintOuter(ErrorResult& 
 }
 
 void
 nsGlobalWindow::Print(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(PrintOuter, (aError), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Print()
-{
-  FORWARD_TO_INNER(Print, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Print(rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::MoveToOuter(int32_t aXPos, int32_t aYPos, ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
   /*
    * If caller is not chrome and the user has not explicitly exempted the site,
    * prevent window.moveTo() by exiting early
    */
@@ -7644,27 +7011,16 @@ nsGlobalWindow::MoveToOuter(int32_t aXPo
 }
 
 void
 nsGlobalWindow::MoveTo(int32_t aXPos, int32_t aYPos, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(MoveToOuter, (aXPos, aYPos, aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::MoveTo(int32_t aXPos, int32_t aYPos)
-{
-  FORWARD_TO_OUTER(MoveTo, (aXPos, aYPos), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  MoveToOuter(aXPos, aYPos, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::MoveByOuter(int32_t aXDif, int32_t aYDif, ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   /*
    * If caller is not chrome and the user has not explicitly exempted the site,
    * prevent window.moveBy() by exiting early
@@ -7704,17 +7060,17 @@ nsGlobalWindow::MoveByOuter(int32_t aXDi
 }
 
 void
 nsGlobalWindow::MoveBy(int32_t aXDif, int32_t aYDif, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(MoveByOuter, (aXDif, aYDif, aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::MoveBy(int32_t aXDif, int32_t aYDif)
 {
   FORWARD_TO_OUTER(MoveBy, (aXDif, aYDif), NS_ERROR_UNEXPECTED);
 
   ErrorResult rv;
   MoveByOuter(aXDif, aYDif, rv, /* aCallerIsChrome = */ true);
 
   return rv.StealNSResult();
@@ -7762,27 +7118,16 @@ nsGlobalWindow::ResizeToOuter(int32_t aW
 }
 
 void
 nsGlobalWindow::ResizeTo(int32_t aWidth, int32_t aHeight, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(ResizeToOuter, (aWidth, aHeight, aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ResizeTo(int32_t aWidth, int32_t aHeight)
-{
-  FORWARD_TO_OUTER(ResizeTo, (aWidth, aHeight), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  ResizeToOuter(aWidth, aHeight, rv, nsContentUtils::IsCallerChrome());
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif,
                               ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   /*
    * If caller is a browser-element then dispatch a resize event to
@@ -7843,27 +7188,16 @@ nsGlobalWindow::ResizeByOuter(int32_t aW
 
 void
 nsGlobalWindow::ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
                          ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(ResizeByOuter, (aWidthDif, aHeightDif, aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ResizeBy(int32_t aWidthDif, int32_t aHeightDif)
-{
-  FORWARD_TO_OUTER(ResizeBy, (aWidthDif, aHeightDif), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  ResizeByOuter(aWidthDif, aHeightDif, rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::SizeToContentOuter(ErrorResult& aError, bool aCallerIsChrome)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return;
   }
@@ -7910,34 +7244,16 @@ nsGlobalWindow::SizeToContentOuter(Error
 }
 
 void
 nsGlobalWindow::SizeToContent(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter, (aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::SizeToContent()
-{
-  FORWARD_TO_OUTER(SizeToContent, (), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  SizeToContentOuter(rv, /* aCallerIsChrome = */ true);
-
-  return rv.StealNSResult();
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::GetWindowRoot(nsIDOMEventTarget **aWindowRoot)
-{
-  nsCOMPtr<nsPIWindowRoot> root = GetTopWindowRoot();
-  return CallQueryInterface(root, aWindowRoot);
-}
-
 already_AddRefed<nsPIWindowRoot>
 nsGlobalWindow::GetTopWindowRoot()
 {
   nsPIDOMWindow* piWin = GetPrivateRoot();
   if (!piWin) {
     return nullptr;
   }
 
@@ -7983,30 +7299,16 @@ nsGlobalWindow::ScrollTo(const ScrollToO
 }
 
 void
 nsGlobalWindow::Scroll(const ScrollToOptions& aOptions)
 {
   ScrollTo(aOptions);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Scroll(int32_t aXScroll, int32_t aYScroll)
-{
-  ScrollTo(CSSIntPoint(aXScroll, aYScroll), ScrollOptions());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::ScrollTo(int32_t aXScroll, int32_t aYScroll)
-{
-  ScrollTo(CSSIntPoint(aXScroll, aYScroll), ScrollOptions());
-  return NS_OK;
-}
-
 void
 nsGlobalWindow::ScrollTo(const CSSIntPoint& aScroll,
                          const ScrollOptions& aOptions)
 {
   FlushPendingNotifications(Flush_Layout);
   nsIScrollableFrame *sf = GetScrollFrame();
 
   if (sf) {
@@ -8029,24 +7331,16 @@ nsGlobalWindow::ScrollTo(const CSSIntPoi
     bool smoothScroll = sf->GetScrollbarStyles().IsSmoothScroll(aOptions.mBehavior);
 
     sf->ScrollToCSSPixels(scroll, smoothScroll
                             ? nsIScrollableFrame::SMOOTH_MSD
                             : nsIScrollableFrame::INSTANT);
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ScrollBy(int32_t aXScrollDif, int32_t aYScrollDif)
-{
-  ScrollBy(double(aXScrollDif), double(aYScrollDif));
-
-  return NS_OK;
-}
-
 void
 nsGlobalWindow::ScrollBy(double aXScrollDif, double aYScrollDif)
 {
   FlushPendingNotifications(Flush_Layout);
   nsIScrollableFrame *sf = GetScrollFrame();
 
   if (sf) {
     // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
@@ -8073,26 +7367,16 @@ nsGlobalWindow::ScrollBy(const ScrollToO
     if (aOptions.mTop.WasPassed()) {
       scrollPos.y += mozilla::ToZeroIfNonfinite(aOptions.mTop.Value());
     }
 
     ScrollTo(scrollPos, aOptions);
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ScrollByLines(int32_t numLines)
-{
-  FORWARD_TO_INNER(ScrollByLines, (numLines), NS_ERROR_UNEXPECTED);
-
-  ScrollByLines(numLines, ScrollOptions());
-
-  return NS_OK;
-}
-
 void
 nsGlobalWindow::ScrollByLines(int32_t numLines,
                               const ScrollOptions& aOptions)
 {
   MOZ_ASSERT(IsInnerWindow());
 
   FlushPendingNotifications(Flush_Layout);
   nsIScrollableFrame *sf = GetScrollFrame();
@@ -8104,26 +7388,16 @@ nsGlobalWindow::ScrollByLines(int32_t nu
 
     sf->ScrollBy(nsIntPoint(0, numLines), nsIScrollableFrame::LINES,
                  smoothScroll
                    ? nsIScrollableFrame::SMOOTH_MSD
                    : nsIScrollableFrame::INSTANT);
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ScrollByPages(int32_t numPages)
-{
-  FORWARD_TO_INNER(ScrollByPages, (numPages), NS_ERROR_UNEXPECTED);
-
-  ScrollByPages(numPages, ScrollOptions());
-
-  return NS_OK;
-}
-
 void
 nsGlobalWindow::ScrollByPages(int32_t numPages,
                               const ScrollOptions& aOptions)
 {
   MOZ_ASSERT(IsInnerWindow());
 
   FlushPendingNotifications(Flush_Layout);
   nsIScrollableFrame *sf = GetScrollFrame();
@@ -8281,27 +7555,23 @@ nsGlobalWindow::CanSetProperty(const cha
 }
 
 bool
 nsGlobalWindow::PopupWhitelisted()
 {
   if (!IsPopupBlocked(mDoc))
     return true;
 
-  nsCOMPtr<nsIDOMWindow> parent;
-
-  if (NS_FAILED(GetParent(getter_AddRefs(parent))) ||
-      parent == static_cast<nsIDOMWindow*>(this))
+  nsCOMPtr<nsPIDOMWindow> parent = GetParent();
+  if (parent == static_cast<nsPIDOMWindow*>(this))
   {
     return false;
   }
 
-  return static_cast<nsGlobalWindow*>
-                    (static_cast<nsIDOMWindow*>
-                                (parent.get()))->PopupWhitelisted();
+  return static_cast<nsGlobalWindow*>(parent.get())->PopupWhitelisted();
 }
 
 /*
  * Examine the current document state to see if we're in a way that is
  * typically abused by web designers. The window.open code uses this
  * routine to determine whether to allow the new window.
  * Returns a value from the PopupControlState enum.
  */
@@ -8345,19 +7615,17 @@ nsGlobalWindow::RevisePopupAbuseLevel(Po
 void
 nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow,
                                 const nsAString &aPopupURL,
                                 const nsAString &aPopupWindowName,
                                 const nsAString &aPopupWindowFeatures)
 {
   // fetch the URI of the window requesting the opened window
 
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  GetTop(getter_AddRefs(topWindow));
-  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(topWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetTop();
   if (!window) {
     return;
   }
 
   nsCOMPtr<nsIDocument> topDoc = window->GetDoc();
   nsCOMPtr<nsIURI> popupURI;
 
   // build the URI of the would-have-been popup window
@@ -8400,32 +7668,37 @@ nsGlobalWindow::OpenOuter(const nsAStrin
 already_AddRefed<nsIDOMWindow>
 nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
                      const nsAString& aOptions, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(OpenOuter, (aUrl, aName, aOptions, aError), aError,
                             nullptr);
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
-                     const nsAString& aOptions, nsIDOMWindow **_retval)
+                     const nsAString& aOptions, nsPIDOMWindow **_retval)
 {
   FORWARD_TO_OUTER(Open, (aUrl, aName, aOptions, _retval),
                    NS_ERROR_NOT_INITIALIZED);
-  return OpenInternal(aUrl, aName, aOptions,
-                      false,          // aDialog
-                      false,          // aContentModal
-                      true,           // aCalledNoScript
-                      false,          // aDoJSFixups
-                      true,           // aNavigate
-                      nullptr, nullptr,  // No args
-                      GetPrincipal(),    // aCalleePrincipal
-                      nullptr,           // aJSCallerContext
-                      _retval);
+  nsCOMPtr<nsIDOMWindow> window;
+  nsresult rv = OpenInternal(aUrl, aName, aOptions,
+                             false,          // aDialog
+                             false,          // aContentModal
+                             true,           // aCalledNoScript
+                             false,          // aDoJSFixups
+                             true,           // aNavigate
+                             nullptr, nullptr,  // No args
+                             GetPrincipal(),    // aCalleePrincipal
+                             nullptr,           // aJSCallerContext
+                             getter_AddRefs(window));
+  if (NS_SUCCEEDED(rv) && window) {
+    return CallQueryInterface(window, _retval);
+  }
+  return rv;
 }
 
 nsresult
 nsGlobalWindow::OpenJS(const nsAString& aUrl, const nsAString& aName,
                        const nsAString& aOptions, nsIDOMWindow **_retval)
 {
   MOZ_ASSERT(IsOuterWindow());
   return OpenInternal(aUrl, aName, aOptions,
@@ -8437,23 +7710,22 @@ nsGlobalWindow::OpenJS(const nsAString& 
                       nullptr, nullptr,  // No args
                       GetPrincipal(),    // aCalleePrincipal
                       nsContentUtils::GetCurrentJSContext(), // aJSCallerContext
                       _retval);
 }
 
 // like Open, but attaches to the new window any extra parameters past
 // [features] as a JS property named "arguments"
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::OpenDialog(const nsAString& aUrl, const nsAString& aName,
                            const nsAString& aOptions,
                            nsISupports* aExtraArgument, nsIDOMWindow** _retval)
 {
-  FORWARD_TO_OUTER(OpenDialog, (aUrl, aName, aOptions, aExtraArgument, _retval),
-                   NS_ERROR_NOT_INITIALIZED);
+  MOZ_ASSERT(IsOuterWindow());
   return OpenInternal(aUrl, aName, aOptions,
                       true,                    // aDialog
                       false,                   // aContentModal
                       true,                    // aCalledNoScript
                       false,                   // aDoJSFixups
                       true,                    // aNavigate
                       nullptr, aExtraArgument,    // Arguments
                       GetPrincipal(),             // aCalleePrincipal
@@ -8728,32 +8000,16 @@ nsGlobalWindow::PostMessageMoz(JSContext
       aError.Throw(NS_ERROR_OUT_OF_MEMORY);
       return;
     }
   }
 
   PostMessageMoz(aCx, aMessage, aTargetOrigin, transferArray, aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::PostMessageMoz(JS::Handle<JS::Value> aMessage,
-                               const nsAString& aOrigin,
-                               JS::Handle<JS::Value> aTransfer,
-                               JSContext* aCx)
-{
-  FORWARD_TO_INNER(PostMessageMoz,
-                   (aMessage, aOrigin, aTransfer, aCx),
-                   NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  PostMessageMoz(aCx, aMessage, aOrigin, aTransfer, rv);
-
-  return rv.StealNSResult();
-}
-
 class nsCloseEvent : public nsRunnable {
 
   RefPtr<nsGlobalWindow> mWindow;
   bool mIndirect;
 
   nsCloseEvent(nsGlobalWindow *aWindow, bool aIndirect)
     : mWindow(aWindow)
     , mIndirect(aIndirect)
@@ -8887,17 +8143,17 @@ nsGlobalWindow::CloseOuter(bool aTrusted
 }
 
 void
 nsGlobalWindow::Close(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(CloseOuter, (nsContentUtils::IsCallerChrome()), aError, );
 }
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::Close()
 {
   FORWARD_TO_OUTER(Close, (), NS_ERROR_UNEXPECTED);
   CloseOuter(/* aTrustedCaller = */ true);
   return NS_OK;
 }
 
 void
@@ -9008,17 +8264,17 @@ nsGlobalWindow::ReallyCloseWindow()
 
 void
 nsGlobalWindow::EnterModalState()
 {
   MOZ_ASSERT(IsOuterWindow(), "Modal state is maintained on outer windows");
 
   // GetScriptableTop, not GetTop, so that EnterModalState works properly with
   // <iframe mozbrowser>.
-  nsGlobalWindow* topWin = GetScriptableTop();
+  nsGlobalWindow* topWin = GetScriptableTopInternal();
 
   if (!topWin) {
     NS_ERROR("Uh, EnterModalState() called w/o a reachable top window?");
     return;
   }
 
   // If there is an active ESM in this window, clear it. Otherwise, this can
   // cause a problem if a modal state is entered during a mouseup event.
@@ -9085,40 +8341,33 @@ nsGlobalWindow::RunPendingTimeoutsRecurs
   inner->RunTimeout(nullptr);
 
   // Check again if we're frozen since running pending timeouts
   // could've frozen us.
   if (inner->IsFrozen()) {
     return;
   }
 
-  nsCOMPtr<nsIDOMWindowCollection> frames;
-  aWindow->GetFrames(getter_AddRefs(frames));
-
+  nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
   if (!frames) {
     return;
   }
 
-  uint32_t i, length;
-  if (NS_FAILED(frames->GetLength(&length)) || !length) {
-    return;
-  }
-
-  for (i = 0; i < length && aTopWindow->mModalStateDepth == 0; i++) {
+  uint32_t length = 0;
+  frames->GetLength(&length);
+
+  for (uint32_t i = 0; i < length && aTopWindow->mModalStateDepth == 0; i++) {
     nsCOMPtr<nsIDOMWindow> child;
     frames->Item(i, getter_AddRefs(child));
 
     if (!child) {
       return;
     }
 
-    nsGlobalWindow *childWin =
-      static_cast<nsGlobalWindow *>
-                 (static_cast<nsIDOMWindow *>
-                             (child.get()));
+    auto* childWin = static_cast<nsGlobalWindow*>(child.get());
 
     RunPendingTimeoutsRecursive(aTopWindow, childWin);
   }
 }
 
 class nsPendingTimeoutRunner : public nsRunnable
 {
 public:
@@ -9139,17 +8388,17 @@ private:
   RefPtr<nsGlobalWindow> mWindow;
 };
 
 void
 nsGlobalWindow::LeaveModalState()
 {
   MOZ_ASSERT(IsOuterWindow(), "Modal state is maintained on outer windows");
 
-  nsGlobalWindow* topWin = GetScriptableTop();
+  nsGlobalWindow* topWin = GetScriptableTopInternal();
 
   if (!topWin) {
     NS_ERROR("Uh, LeaveModalState() called w/o a reachable top window?");
     return;
   }
 
   topWin->mModalStateDepth--;
 
@@ -9179,17 +8428,17 @@ nsGlobalWindow::LeaveModalState()
     bool dummy;
     topWin->DispatchEvent(event, &dummy);
   }
 }
 
 bool
 nsGlobalWindow::IsInModalState()
 {
-  nsGlobalWindow *topWin = GetScriptableTop();
+  nsGlobalWindow *topWin = GetScriptableTopInternal();
 
   if (!topWin) {
     // IsInModalState() getting called w/o a reachable top window is a bit
     // iffy, but valid enough not to make noise about it.  See bug 404828
     return false;
   }
 
   return topWin->mModalStateDepth != 0;
@@ -9336,39 +8585,16 @@ nsGlobalWindow::CacheXBLPrototypeHandler
   if (!mCachedXBLPrototypeHandlers) {
     mCachedXBLPrototypeHandlers = new nsJSThingHashtable<nsPtrHashKey<nsXBLPrototypeHandler>, JSObject*>();
     PreserveWrapper(ToSupports(this));
   }
 
   mCachedXBLPrototypeHandlers->Put(aKey, aHandler);
 }
 
-/**
- * GetScriptableFrameElement is called when script reads
- * nsIGlobalWindow::frameElement.
- *
- * In contrast to GetRealFrameElement, GetScriptableFrameElement says that the
- * window contained by an <iframe mozbrowser> or <iframe mozapp> has no frame
- * element (effectively treating a mozbrowser the same as a content/chrome
- * boundary).
- */
-NS_IMETHODIMP
-nsGlobalWindow::GetScriptableFrameElement(nsIDOMElement** aFrameElement)
-{
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMElement> frameElement = do_QueryInterface(GetFrameElement(rv));
-  if (rv.Failed()) {
-    return rv.StealNSResult();
-  }
-
-  frameElement.forget(aFrameElement);
-
-  return NS_OK;
-}
-
 Element*
 nsGlobalWindow::GetFrameElementOuter()
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell || mDocShell->GetIsBrowserOrApp()) {
     return nullptr;
   }
@@ -9419,27 +8645,26 @@ nsGlobalWindow::GetRealFrameElement(Erro
 {
   FORWARD_TO_OUTER_OR_THROW(GetRealFrameElementOuter, (), aError, nullptr);
 }
 
 /**
  * nsIGlobalWindow::GetFrameElement (when called from C++) is just a wrapper
  * around GetRealFrameElement.
  */
-NS_IMETHODIMP
-nsGlobalWindow::GetRealFrameElement(nsIDOMElement** aFrameElement)
-{
-  FORWARD_TO_INNER(GetRealFrameElement, (aFrameElement), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
+already_AddRefed<nsIDOMElement>
+nsGlobalWindow::GetFrameElement()
+{
+  FORWARD_TO_INNER(GetFrameElement, (), nullptr);
+
+  ErrorResult dummy;
   nsCOMPtr<nsIDOMElement> frameElement =
-    do_QueryInterface(GetRealFrameElement(rv));
-  frameElement.forget(aFrameElement);
-
-  return rv.StealNSResult();
+    do_QueryInterface(GetRealFrameElement(dummy));
+  dummy.SuppressException();
+  return frameElement.forget();
 }
 
 /* static */ bool
 nsGlobalWindow::TokenizeDialogOptions(nsAString& aToken,
                                       nsAString::const_iterator& aIter,
                                       nsAString::const_iterator aEnd)
 {
   while (aIter != aEnd && nsCRT::IsAsciiSpace(*aIter)) {
@@ -9672,39 +8897,16 @@ nsGlobalWindow::ShowModalDialog(JSContex
     aError = nsContentUtils::XPConnect()->VariantToJS(aCx,
                                                       FastGetGlobalJSObject(),
                                                       retVal, aRetval);
   } else {
     aRetval.setNull();
   }
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::ShowModalDialog(const nsAString& aURI, nsIVariant *aArgs_,
-                                const nsAString& aOptions, uint8_t aArgc,
-                                nsIVariant **aRetVal)
-{
-  FORWARD_TO_INNER(ShowModalDialog, (aURI, aArgs_, aOptions, aArgc, aRetVal),
-                   NS_ERROR_UNEXPECTED);
-
-  // Per-spec the |arguments| parameter is supposed to pass through unmodified.
-  // However, XPConnect default-initializes variants to null, rather than
-  // undefined. Fix this up here.
-  nsCOMPtr<nsIVariant> aArgs = aArgs_;
-  if (aArgc < 1) {
-    aArgs = CreateVoidVariant();
-  }
-
-  ErrorResult rv;
-  nsCOMPtr<nsIVariant> retVal = ShowModalDialog(aURI, aArgs, aOptions, rv);
-  retVal.forget(aRetVal);
-
-  return rv.StealNSResult();
-}
-
 class ChildCommandDispatcher : public nsRunnable
 {
 public:
   ChildCommandDispatcher(nsGlobalWindow* aWindow,
                          nsITabChild* aTabChild,
                          const nsAString& aAction)
   : mWindow(aWindow), mTabChild(aTabChild), mAction(aAction) {}
 
@@ -9741,17 +8943,17 @@ public:
   {
     return mDispatcher->UpdateCommands(mAction);
   }
 
   nsCOMPtr<nsIDOMXULCommandDispatcher> mDispatcher;
   nsString                             mAction;
 };
 
-NS_IMETHODIMP
+nsresult
 nsGlobalWindow::UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason)
 {
   // If this is a child process, redirect to the parent process.
   if (nsCOMPtr<nsITabChild> child = do_GetInterface(GetDocShell())) {
     nsContentUtils::AddScriptRunner(new ChildCommandDispatcher(this, child, anAction));
     return NS_OK;
   }
 
@@ -9795,26 +8997,21 @@ nsGlobalWindow::GetSelectionOuter()
 }
 
 Selection*
 nsGlobalWindow::GetSelection(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetSelectionOuter, (), aError, nullptr);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetSelection(nsISelection** aSelection)
-{
-  FORWARD_TO_INNER(GetSelection, (aSelection), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsISelection> selection = GetSelection(rv);
-  selection.forget(aSelection);
-
-  return rv.StealNSResult();
+already_AddRefed<nsISelection>
+nsGlobalWindow::GetSelection()
+{
+  nsCOMPtr<nsISelection> selection = GetSelectionOuter();
+  return selection.forget();
 }
 
 bool
 nsGlobalWindow::FindOuter(const nsAString& aString, bool aCaseSensitive,
                           bool aBackwards, bool aWrapAround, bool aWholeWord,
                           bool aSearchInFrames, bool aShowDialog,
                           ErrorResult& aError)
 {
@@ -9860,19 +9057,19 @@ nsGlobalWindow::FindOuter(const nsAStrin
 
     nsCOMPtr<nsIDOMWindow> findDialog;
 
     if (windowMediator) {
       windowMediator->GetMostRecentWindow(MOZ_UTF16("findInPage"),
                                           getter_AddRefs(findDialog));
     }
 
-    if (findDialog) {
+    if (nsCOMPtr<nsPIDOMWindow> piFindDialog = do_QueryInterface(findDialog)) {
       // The Find dialog is already open, bring it to the top.
-      aError = findDialog->Focus();
+      aError = piFindDialog->Focus();
     } else if (finder) {
       // Open a Find dialog
       nsCOMPtr<nsIDOMWindow> dialog;
       aError = OpenDialog(NS_LITERAL_STRING("chrome://global/content/finddialog.xul"),
                           NS_LITERAL_STRING("_blank"),
                           NS_LITERAL_STRING("chrome, resizable=no, dependent=yes"),
                           finder, getter_AddRefs(dialog));
     }
@@ -9893,74 +9090,32 @@ nsGlobalWindow::Find(const nsAString& aS
                      ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(FindOuter,
                             (aString, aCaseSensitive, aBackwards, aWrapAround,
                              aWholeWord, aSearchInFrames, aShowDialog, aError),
                             aError, false);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Find(const nsAString& aStr, bool aCaseSensitive,
-                     bool aBackwards, bool aWrapAround, bool aWholeWord,
-                     bool aSearchInFrames, bool aShowDialog,
-                     bool *aDidFind)
-{
-  FORWARD_TO_INNER(Find,
-                   (aStr, aCaseSensitive, aBackwards, aWrapAround, aWholeWord,
-                    aSearchInFrames, aShowDialog, aDidFind),
-                   NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  *aDidFind = Find(aStr, aCaseSensitive, aBackwards, aWrapAround, aWholeWord,
-                   aSearchInFrames, aShowDialog, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::Atob(const nsAString& aAsciiBase64String,
                      nsAString& aBinaryData, ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
   aError = nsContentUtils::Atob(aAsciiBase64String, aBinaryData);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Atob(const nsAString& aAsciiBase64String,
-                     nsAString& aBinaryData)
-{
-  FORWARD_TO_INNER(Atob, (aAsciiBase64String, aBinaryData), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Atob(aAsciiBase64String, aBinaryData, rv);
-
-  return rv.StealNSResult();
-}
-
 void
 nsGlobalWindow::Btoa(const nsAString& aBinaryData,
                      nsAString& aAsciiBase64String, ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
   aError = nsContentUtils::Btoa(aBinaryData, aAsciiBase64String);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::Btoa(const nsAString& aBinaryData,
-                     nsAString& aAsciiBase64String)
-{
-  FORWARD_TO_INNER(Btoa, (aBinaryData, aAsciiBase64String), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  Btoa(aBinaryData, aAsciiBase64String, rv);
-
-  return rv.StealNSResult();
-}
-
 //*****************************************************************************
 // nsGlobalWindow::nsIDOMEventTarget
 //*****************************************************************************
 
 NS_IMETHODIMP
 nsGlobalWindow::RemoveEventListener(const nsAString& aType,
                                     nsIDOMEventListener* aListener,
                                     bool aUseCapture)
@@ -10121,20 +9276,19 @@ nsGlobalWindow::GetContextForEventHandle
 // nsGlobalWindow::nsPIDOMWindow
 //*****************************************************************************
 
 nsPIDOMWindow*
 nsGlobalWindow::GetPrivateParent()
 {
   MOZ_ASSERT(IsOuterWindow());
 
-  nsCOMPtr<nsIDOMWindow> parent;
-  GetParent(getter_AddRefs(parent));
-
-  if (static_cast<nsIDOMWindow *>(this) == parent.get()) {
+  nsCOMPtr<nsPIDOMWindow> parent = GetParent();
+
+  if (static_cast<nsPIDOMWindow *>(this) == parent.get()) {
     nsCOMPtr<nsIContent> chromeElement(do_QueryInterface(mChromeEventHandler));
     if (!chromeElement)
       return nullptr;             // This is ok, just means a null parent.
 
     nsIDocument* doc = chromeElement->GetComposedDoc();
     if (!doc)
       return nullptr;             // This is ok, just means a null parent.
 
@@ -10156,26 +9310,25 @@ nsGlobalWindow::GetPrivateRoot()
     nsGlobalWindow* outer = GetOuterWindowInternal();
     if (!outer) {
       NS_WARNING("No outer window available!");
       return nullptr;
     }
     return outer->GetPrivateRoot();
   }
 
-  nsCOMPtr<nsIDOMWindow> top;
-  GetTop(getter_AddRefs(top));
+  nsCOMPtr<nsPIDOMWindow> top = GetTop();
 
   nsCOMPtr<nsIContent> chromeElement(do_QueryInterface(mChromeEventHandler));
   if (chromeElement) {
     nsIDocument* doc = chromeElement->GetComposedDoc();
     if (doc) {
-      nsIDOMWindow *parent = doc->GetWindow();
+      nsCOMPtr<nsPIDOMWindow> parent = doc->GetWindow();
       if (parent) {
-        parent->GetTop(getter_AddRefs(top));
+        top = parent->GetTop();
       }
     }
   }
 
   return static_cast<nsGlobalWindow*>(top.get());
 }
 
 nsLocation*
@@ -10185,26 +9338,25 @@ nsGlobalWindow::GetLocation(ErrorResult&
 
   nsIDocShell *docShell = GetDocShell();
   if (!mLocation && docShell) {
     mLocation = new nsLocation(this, docShell);
   }
   return mLocation;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetLocation(nsIDOMLocation ** aLocation)
-{
-  FORWARD_TO_INNER(GetLocation, (aLocation), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMLocation> location = GetLocation(rv);
-  location.forget(aLocation);
-
-  return rv.StealNSResult();
+nsIDOMLocation*
+nsGlobalWindow::GetLocation()
+{
+  FORWARD_TO_INNER(GetLocation, (), nullptr);
+
+  ErrorResult dummy;
+  nsIDOMLocation* location = GetLocation(dummy);
+  dummy.SuppressException();
+  return location;
 }
 
 void
 nsGlobalWindow::ActivateOrDeactivate(bool aActivate)
 {
   MOZ_ASSERT(IsOuterWindow());
 
   if (!mDoc) {
@@ -10764,43 +9916,25 @@ nsGlobalWindow::UpdateCanvasFocus(bool a
 already_AddRefed<nsICSSDeclaration>
 nsGlobalWindow::GetComputedStyle(Element& aElt, const nsAString& aPseudoElt,
                                  ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
   return GetComputedStyleHelper(aElt, aPseudoElt, false, aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetComputedStyle(nsIDOMElement* aElt,
-                                 const nsAString& aPseudoElt,
-                                 nsIDOMCSSStyleDeclaration** aReturn)
-{
-  FORWARD_TO_INNER(GetComputedStyle, (aElt, aPseudoElt, aReturn), NS_ERROR_UNEXPECTED);
-  return GetComputedStyleHelper(aElt, aPseudoElt, false, aReturn);
-}
-
 already_AddRefed<nsICSSDeclaration>
 nsGlobalWindow::GetDefaultComputedStyle(Element& aElt,
                                         const nsAString& aPseudoElt,
                                         ErrorResult& aError)
 {
   MOZ_ASSERT(IsInnerWindow());
   return GetComputedStyleHelper(aElt, aPseudoElt, true, aError);
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetDefaultComputedStyle(nsIDOMElement* aElt,
-                                        const nsAString& aPseudoElt,
-                                        nsIDOMCSSStyleDeclaration** aReturn)
-{
-  FORWARD_TO_INNER(GetDefaultComputedStyle, (aElt, aPseudoElt, aReturn), NS_ERROR_UNEXPECTED);
-  return GetComputedStyleHelper(aElt, aPseudoElt, true, aReturn);
-}
-
 nsresult
 nsGlobalWindow::GetComputedStyleHelper(nsIDOMElement* aElt,
                                        const nsAString& aPseudoElt,
                                        bool aDefaultStylesOnly,
                                        nsIDOMCSSStyleDeclaration** aReturn)
 {
   MOZ_ASSERT(IsInnerWindow());
 
@@ -10948,28 +10082,16 @@ nsGlobalWindow::GetSessionStorage(ErrorR
 
   if (MOZ_LOG_TEST(gDOMLeakPRLog, LogLevel::Debug)) {
     PR_LogPrint("nsGlobalWindow %p returns %p sessionStorage", this, mSessionStorage.get());
   }
 
   return mSessionStorage;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetSessionStorage(nsISupports** aSessionStorage)
-{
-  FORWARD_TO_INNER(GetSessionStorage, (aSessionStorage), NS_ERROR_FAILURE);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMStorage> storage = GetSessionStorage(rv);
-  storage.forget(aSessionStorage);
-
-  return rv.StealNSResult();
-}
-
 DOMStorage*
 nsGlobalWindow::GetLocalStorage(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!Preferences::GetBool(kStorageEnabled)) {
     return nullptr;
   }
@@ -11008,51 +10130,28 @@ nsGlobalWindow::GetLocalStorage(ErrorRes
 
     mLocalStorage = static_cast<DOMStorage*>(storage.get());
     MOZ_ASSERT(mLocalStorage);
   }
 
   return mLocalStorage;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetLocalStorage(nsISupports** aLocalStorage)
-{
-  NS_ENSURE_ARG(aLocalStorage);
-  FORWARD_TO_INNER(GetLocalStorage, (aLocalStorage), NS_ERROR_UNEXPECTED);
-
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMStorage> storage = GetLocalStorage(rv);
-  storage.forget(aLocalStorage);
-
-  return rv.StealNSResult();
-}
-
 IDBFactory*
 nsGlobalWindow::GetIndexedDB(ErrorResult& aError)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
   if (!mIndexedDB) {
     // This may keep mIndexedDB null without setting an error.
     aError = IDBFactory::CreateForWindow(this, getter_AddRefs(mIndexedDB));
   }
 
   return mIndexedDB;
 }
 
-NS_IMETHODIMP
-nsGlobalWindow::GetIndexedDB(nsISupports** _retval)
-{
-  ErrorResult rv;
-  nsCOMPtr<nsISupports> request(GetIndexedDB(rv));
-  request.forget(_retval);
-
-  return rv.StealNSResult();
-}
-
 //*****************************************************************************
 // nsGlobalWindow::nsIInterfaceRequestor
 //*****************************************************************************
 
 NS_IMETHODIMP
 nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink)
 {
   NS_ENSURE_ARG_POINTER(aSink);
@@ -11941,18 +11040,17 @@ nsGlobalWindow::Observe(nsISupports* aSu
 
   if (!nsCRT::strcmp(aTopic, "offline-cache-update-added")) {
     if (mApplicationCache)
       return NS_OK;
 
     // Instantiate the application object now. It observes update belonging to
     // this window's document and correctly updates the applicationCache object
     // state.
-    nsCOMPtr<nsIDOMOfflineResourceList> applicationCache;
-    GetApplicationCache(getter_AddRefs(applicationCache));
+    nsCOMPtr<nsIDOMOfflineResourceList> applicationCache = GetApplicationCache();
     nsCOMPtr<nsIObserver> observer = do_QueryInterface(applicationCache);
     if (observer)
       observer->Observe(aSubject, aTopic, aData);
 
     return NS_OK;
   }
 
 #ifdef MOZ_B2G
@@ -12113,20 +11211,19 @@ nsGlobalWindow::GetParentInternal()
     nsGlobalWindow* outer = GetOuterWindowInternal();
     if (!outer) {
       NS_WARNING("No outer window available!");
       return nullptr;
     }
     return outer->GetParentInternal();
   }
 
-  nsCOMPtr<nsIDOMWindow> parent;
-  GetParent(getter_AddRefs(parent));
-
-  if (parent && parent != static_cast<nsIDOMWindow *>(this)) {
+  nsCOMPtr<nsPIDOMWindow> parent = GetParent();
+
+  if (parent && parent != static_cast<nsPIDOMWindow*>(this)) {
     return parent;
   }
 
   return nullptr;
 }
 
 void
 nsGlobalWindow::UnblockScriptedClosing()
@@ -12320,18 +11417,18 @@ nsGlobalWindow::OpenInternal(const nsASt
       // XXXbz should this just use EnsureInnerWindow()?
 #ifdef DEBUG_jst
       {
         nsCOMPtr<nsPIDOMWindow> pidomwin(do_QueryInterface(*aReturn));
         NS_ASSERTION(pidomwin->GetExtantDoc(), "No document in new window!!!");
       }
 #endif
 
-      nsCOMPtr<nsIDOMDocument> doc;
-      (*aReturn)->GetDocument(getter_AddRefs(doc));
+      // Force document creation.
+      nsCOMPtr<nsIDocument> doc = static_cast<nsPIDOMWindow*>(*aReturn)->GetDoc();
     }
   }
 
   if (checkForPopup) {
     if (abuseLevel >= openControlled) {
       nsGlobalWindow *opened = static_cast<nsGlobalWindow *>(*aReturn);
       if (!opened->IsPopupSpamWindow()) {
         opened->SetPopupSpamWindow(true);
@@ -14528,52 +13625,24 @@ nsGlobalModalWindow::SetReturnValue(nsIV
 
 /* static */
 bool
 nsGlobalWindow::IsModalContentWindow(JSContext* aCx, JSObject* aGlobal)
 {
   return xpc::WindowOrNull(aGlobal)->IsModalContentWindow();
 }
 
-
 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
 int16_t
 nsGlobalWindow::Orientation() const
 {
   return WindowOrientationObserver::OrientationAngle();
 }
 #endif
 
-NS_IMETHODIMP
-nsGlobalWindow::GetConsole(JSContext* aCx,
-                           JS::MutableHandle<JS::Value> aConsole)
-{
-  FORWARD_TO_INNER(GetConsole, (aCx, aConsole), NS_ERROR_FAILURE);
-
-  ErrorResult rv;
-  RefPtr<Console> console = GetConsole(rv);
-  if (rv.Failed()) {
-    return rv.StealNSResult();
-  }
-
-  if (!GetOrCreateDOMReflector(aCx, console, aConsole)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsGlobalWindow::SetConsole(JSContext* aCx, JS::Handle<JS::Value> aValue)
-{
-  ErrorResult rv;
-  RedefineProperty(aCx, "console", aValue, rv);
-  return rv.StealNSResult();
-}
-
 Console*
 nsGlobalWindow::GetConsole(ErrorResult& aRv)
 {
   MOZ_RELEASE_ASSERT(IsInnerWindow());
 
   if (!mConsole) {
     mConsole = new Console(this);
   }
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -521,41 +521,31 @@ public:
   {
     // Make sure this matches the casts we do in QueryInterface().
     return (nsGlobalWindow *)(mozilla::dom::EventTarget *)supports;
   }
   static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper)
   {
     return FromSupports(wrapper->Native());
   }
-
-  /**
-   * Wrap nsIDOMWindow::GetTop so we can overload the inline GetTop()
-   * implementation below.  (nsIDOMWindow::GetTop simply calls
-   * nsIDOMWindow::GetRealTop().)
-   */
-  nsresult GetTop(nsIDOMWindow **aWindow)
+  already_AddRefed<nsPIDOMWindow> GetTop() override;
+  nsPIDOMWindow* GetScriptableTop() override;
+  inline nsGlobalWindow *GetTopInternal()
   {
-    return nsIDOMWindow::GetTop(aWindow);
-  }
-
-  inline nsGlobalWindow *GetTop()
-  {
-    nsCOMPtr<nsIDOMWindow> top;
-    GetTop(getter_AddRefs(top));
+    nsGlobalWindow* outer = IsOuterWindow() ? this : GetOuterWindowInternal();
+    nsCOMPtr<nsPIDOMWindow> top = outer ? outer->GetTop() : nullptr;
     if (top)
       return static_cast<nsGlobalWindow *>(top.get());
     return nullptr;
   }
 
-  inline nsGlobalWindow* GetScriptableTop()
+  inline nsGlobalWindow* GetScriptableTopInternal()
   {
-    nsCOMPtr<nsIDOMWindow> top;
-    GetScriptableTop(getter_AddRefs(top));
-    return static_cast<nsGlobalWindow *>(top.get());
+    nsPIDOMWindow* top = GetScriptableTop();
+    return static_cast<nsGlobalWindow*>(top);
   }
 
   nsPIDOMWindow* GetChildWindow(const nsAString& aName);
 
   // These return true if we've reached the state in this top level window
   // where we ask the user if further dialogs should be blocked.
   //
   // DialogsAreBeingAbused must be called on the scriptable top inner window.
@@ -690,23 +680,18 @@ public:
     MOZ_ASSERT(IsOuterWindow());
     return mHadOriginalOpener;
   }
 
   bool
   IsTopLevelWindow()
   {
     MOZ_ASSERT(IsOuterWindow());
-    nsCOMPtr<nsIDOMWindow> parentWindow;
-    nsresult rv = GetScriptableTop(getter_AddRefs(parentWindow));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return false;
-    }
-
-    return parentWindow == static_cast<nsIDOMWindow*>(this);
+    nsPIDOMWindow* parentWindow = GetScriptableTop();
+    return parentWindow == static_cast<nsPIDOMWindow*>(this);
   }
 
   virtual void
   FirePopupBlockedEvent(nsIDocument* aDoc,
                         nsIURI* aPopupURI,
                         const nsAString& aPopupWindowName,
                         const nsAString& aPopupWindowFeatures) override;
 
@@ -857,68 +842,82 @@ public:
   {
     return GetDoc();
   }
   void GetNameOuter(nsAString& aName);
   void GetName(nsAString& aName, mozilla::ErrorResult& aError);
   void SetNameOuter(const nsAString& aName, mozilla::ErrorResult& aError);
   void SetName(const nsAString& aName, mozilla::ErrorResult& aError);
   nsLocation* GetLocation(mozilla::ErrorResult& aError);
+  nsIDOMLocation* GetLocation() override;
   nsHistory* GetHistory(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError);
   mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError);
   void GetStatusOuter(nsAString& aStatus);
   void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError);
   void SetStatusOuter(const nsAString& aStatus);
   void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
   void CloseOuter(bool aTrustedCaller);
   void Close(mozilla::ErrorResult& aError);
+  nsresult Close() override;
   bool GetClosedOuter();
   bool GetClosed(mozilla::ErrorResult& aError);
+  bool Closed() override;
   void StopOuter(mozilla::ErrorResult& aError);
   void Stop(mozilla::ErrorResult& aError);
   void FocusOuter(mozilla::ErrorResult& aError);
   void Focus(mozilla::ErrorResult& aError);
+  nsresult Focus() override;
   void BlurOuter();
   void Blur(mozilla::ErrorResult& aError);
   already_AddRefed<nsIDOMWindow> GetFramesOuter();
+  already_AddRefed<nsIDOMWindowCollection> GetFrames() override;
   already_AddRefed<nsIDOMWindow> GetFrames(mozilla::ErrorResult& aError);
   uint32_t Length();
-  already_AddRefed<nsIDOMWindow> GetTopOuter(mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMWindow> GetTopOuter();
   already_AddRefed<nsIDOMWindow> GetTop(mozilla::ErrorResult& aError);
+
+  nsresult GetPrompter(nsIPrompt** aPrompt) override;
 protected:
   explicit nsGlobalWindow(nsGlobalWindow *aOuterWindow);
-  nsIDOMWindow* GetOpenerWindowOuter();
-  nsIDOMWindow* GetOpenerWindow(mozilla::ErrorResult& aError);
+  nsPIDOMWindow* GetOpenerWindowOuter();
+  nsPIDOMWindow* GetOpenerWindow(mozilla::ErrorResult& aError);
   // Initializes the mWasOffline member variable
   void InitWasOffline();
 public:
   void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
                  mozilla::ErrorResult& aError);
+  already_AddRefed<nsPIDOMWindow> GetOpener() override;
   void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
                  mozilla::ErrorResult& aError);
-  using nsIDOMWindow::GetParent;
-  already_AddRefed<nsIDOMWindow> GetParentOuter(mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMWindow> GetParentOuter();
   already_AddRefed<nsIDOMWindow> GetParent(mozilla::ErrorResult& aError);
+  already_AddRefed<nsPIDOMWindow> GetParent() override;
+  nsPIDOMWindow* GetScriptableParent() override;
   mozilla::dom::Element* GetFrameElementOuter();
   mozilla::dom::Element* GetFrameElement(mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMElement> GetFrameElement() override;
   already_AddRefed<nsIDOMWindow> OpenOuter(const nsAString& aUrl,
                                            const nsAString& aName,
                                            const nsAString& aOptions,
                                            mozilla::ErrorResult& aError);
   already_AddRefed<nsIDOMWindow> Open(const nsAString& aUrl,
                                       const nsAString& aName,
                                       const nsAString& aOptions,
                                       mozilla::ErrorResult& aError);
+  nsresult Open(const nsAString& aUrl, const nsAString& aName,
+                const nsAString& aOptions, nsPIDOMWindow **_retval) override;
   mozilla::dom::Navigator* GetNavigator(mozilla::ErrorResult& aError);
+  nsIDOMNavigator* GetNavigator() override;
   nsIDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
+  already_AddRefed<nsIDOMOfflineResourceList> GetApplicationCache() override;
 
 #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
   int16_t Orientation() const;
 #endif
 
   mozilla::dom::Console* GetConsole(mozilla::ErrorResult& aRv);
 
   void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult,
@@ -982,28 +981,31 @@ public:
   void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
             mozilla::ErrorResult& aError);
   void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
             mozilla::ErrorResult& aError);
   mozilla::dom::DOMStorage* GetSessionStorage(mozilla::ErrorResult& aError);
   mozilla::dom::DOMStorage* GetLocalStorage(mozilla::ErrorResult& aError);
   mozilla::dom::Selection* GetSelectionOuter();
   mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
+  already_AddRefed<nsISelection> GetSelection() override;
   mozilla::dom::indexedDB::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError);
   already_AddRefed<nsICSSDeclaration>
     GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
-                     mozilla::ErrorResult& aError);
+                     mozilla::ErrorResult& aError) override;
   already_AddRefed<mozilla::dom::MediaQueryList> MatchMediaOuter(const nsAString& aQuery);
   already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(const nsAString& aQuery,
                                                             mozilla::ErrorResult& aError);
   nsScreen* GetScreen(mozilla::ErrorResult& aError);
+  nsIDOMScreen* GetScreen() override;
   void MoveToOuter(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void MoveTo(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError);
   void MoveByOuter(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void MoveBy(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError);
+  nsresult MoveBy(int32_t aXDif, int32_t aYDif) override;
   void ResizeToOuter(int32_t aWidth, int32_t aHeight, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void ResizeTo(int32_t aWidth, int32_t aHeight,
                 mozilla::ErrorResult& aError);
   void ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
                 mozilla::ErrorResult& aError);
   void Scroll(double aXScroll, double aYScroll);
   void Scroll(const mozilla::dom::ScrollToOptions& aOptions);
@@ -1064,30 +1066,34 @@ public:
     GetDefaultComputedStyle(mozilla::dom::Element& aElt,
                             const nsAString& aPseudoElt,
                             mozilla::ErrorResult& aError);
   void SizeToContentOuter(mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void SizeToContent(mozilla::ErrorResult& aError);
   mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError);
   nsIControllers* GetControllersOuter(mozilla::ErrorResult& aError);
   nsIControllers* GetControllers(mozilla::ErrorResult& aError);
+  nsresult GetControllers(nsIControllers** aControllers) override;
   mozilla::dom::Element* GetRealFrameElementOuter();
   mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
   float GetMozInnerScreenXOuter();
   float GetMozInnerScreenX(mozilla::ErrorResult& aError);
   float GetMozInnerScreenYOuter();
   float GetMozInnerScreenY(mozilla::ErrorResult& aError);
   float GetDevicePixelRatioOuter();
   float GetDevicePixelRatio(mozilla::ErrorResult& aError);
+  nsresult GetDevicePixelRatio(float* aRatio) override;
   int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
   int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
   bool GetFullScreenOuter();
   bool GetFullScreen(mozilla::ErrorResult& aError);
+  bool GetFullScreen() override;
   void SetFullScreenOuter(bool aFullScreen, mozilla::ErrorResult& aError);
   void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError);
+  nsresult SetFullScreen(bool aFullScreen) override;
   void BackOuter(mozilla::ErrorResult& aError);
   void Back(mozilla::ErrorResult& aError);
   void ForwardOuter(mozilla::ErrorResult& aError);
   void Forward(mozilla::ErrorResult& aError);
   void HomeOuter(mozilla::ErrorResult& aError);
   void Home(mozilla::ErrorResult& aError);
   bool FindOuter(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
                  bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
@@ -1109,16 +1115,20 @@ public:
                                                  const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
                                                  mozilla::ErrorResult& aError);
   already_AddRefed<nsIDOMWindow> OpenDialog(JSContext* aCx,
                                             const nsAString& aUrl,
                                             const nsAString& aName,
                                             const nsAString& aOptions,
                                             const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
                                             mozilla::ErrorResult& aError);
+  nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName,
+                      const nsAString& aOptions,
+                      nsISupports* aExtraArgument, nsIDOMWindow** _retval) override;
+  nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) override;
 
   already_AddRefed<nsIDOMWindow>
     GetContentInternal(mozilla::ErrorResult& aError, bool aUnprivilegedCaller);
   void GetContentOuter(JSContext* aCx,
                        JS::MutableHandle<JSObject*> aRetval,
                        mozilla::ErrorResult& aError);
   void GetContent(JSContext* aCx,
                   JS::MutableHandle<JSObject*> aRetval,
@@ -1212,22 +1222,28 @@ protected:
   void GetReplaceableWindowCoord(JSContext* aCx, WindowCoordGetter aGetter,
                                  JS::MutableHandle<JS::Value> aRetval,
                                  mozilla::ErrorResult& aError);
   void SetReplaceableWindowCoord(JSContext* aCx, WindowCoordSetter aSetter,
                                  JS::Handle<JS::Value> aValue,
                                  const char* aPropName,
                                  mozilla::ErrorResult& aError);
   // And the implementations of WindowCoordGetter/WindowCoordSetter.
+public:
   int32_t GetInnerWidthOuter(mozilla::ErrorResult& aError);
+protected:
   int32_t GetInnerWidth(mozilla::ErrorResult& aError);
+  nsresult GetInnerWidth(int32_t* aWidth) override;
   void SetInnerWidthOuter(int32_t aInnerWidth, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void SetInnerWidth(int32_t aInnerWidth, mozilla::ErrorResult& aError);
+public:
   int32_t GetInnerHeightOuter(mozilla::ErrorResult& aError);
+protected:
   int32_t GetInnerHeight(mozilla::ErrorResult& aError);
+  nsresult GetInnerHeight(int32_t* aHeight) override;
   void SetInnerHeightOuter(int32_t aInnerHeight, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void SetInnerHeight(int32_t aInnerHeight, mozilla::ErrorResult& aError);
   int32_t GetScreenXOuter(mozilla::ErrorResult& aError);
   int32_t GetScreenX(mozilla::ErrorResult& aError);
   void SetScreenXOuter(int32_t aScreenX, mozilla::ErrorResult& aError, bool aCallerIsChrome);
   void SetScreenX(int32_t aScreenX, mozilla::ErrorResult& aError);
   int32_t GetScreenYOuter(mozilla::ErrorResult& aError);
   int32_t GetScreenY(mozilla::ErrorResult& aError);
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -191,18 +191,17 @@ nsMimeTypeArray::GetSupportedNames(unsig
 
 void
 nsMimeTypeArray::EnsurePluginMimeTypes()
 {
   if (!mMimeTypes.IsEmpty() || !mWindow) {
     return;
   }
 
-  nsCOMPtr<nsIDOMNavigator> navigator;
-  mWindow->GetNavigator(getter_AddRefs(navigator));
+  nsCOMPtr<nsIDOMNavigator> navigator = mWindow->GetNavigator();
 
   if (!navigator) {
     return;
   }
 
   ErrorResult rv;
   nsPluginArray *pluginArray =
     static_cast<Navigator*>(navigator.get())->GetPlugins(rv);
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -3295,27 +3295,24 @@ nsObjectLoadingContent::ShouldPlay(Fallb
 
   // Check the permission manager for permission based on the principal of
   // the toplevel content.
 
   nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIObjectLoadingContent*>(this));
   MOZ_ASSERT(thisContent);
   nsIDocument* ownerDoc = thisContent->OwnerDoc();
 
-  nsCOMPtr<nsIDOMWindow> window = ownerDoc->GetWindow();
+  nsCOMPtr<nsPIDOMWindow> window = ownerDoc->GetWindow();
   if (!window) {
     return false;
   }
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  rv = window->GetTop(getter_AddRefs(topWindow));
-  NS_ENSURE_SUCCESS(rv, false);
-  nsCOMPtr<nsIDOMDocument> topDocument;
-  rv = topWindow->GetDocument(getter_AddRefs(topDocument));
-  NS_ENSURE_SUCCESS(rv, false);
-  nsCOMPtr<nsIDocument> topDoc = do_QueryInterface(topDocument);
+  nsCOMPtr<nsPIDOMWindow> topWindow = window->GetTop();
+  NS_ENSURE_TRUE(topWindow, false);
+  nsCOMPtr<nsIDocument> topDoc = topWindow->GetDoc();
+  NS_ENSURE_TRUE(topDoc, false);
 
   nsCOMPtr<nsIPermissionManager> permissionManager = services::GetPermissionManager();
   NS_ENSURE_TRUE(permissionManager, false);
 
   // For now we always say that the system principal uses click-to-play since
   // that maintains current behavior and we have tests that expect this.
   // What we really should do is disable plugins entirely in pages that use
   // the system principal, i.e. in chrome pages. That way the click-to-play
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -17,16 +17,17 @@
 #include "js/TypeDecls.h"
 
 #define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
 #define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen"
 #define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed"
 
 class nsIArray;
 class nsIContent;
+class nsICSSDeclaration;
 class nsIDocShell;
 class nsIDocument;
 class nsIIdleObserver;
 class nsIScriptTimeoutHandler;
 class nsIURI;
 class nsPerformance;
 class nsPIWindowRoot;
 class nsXBLPrototypeHandler;
@@ -57,30 +58,47 @@ enum PopupControlState {
 enum UIStateChangeType
 {
   UIStateChangeType_NoChange,
   UIStateChangeType_Set,
   UIStateChangeType_Clear
 };
 
 #define NS_PIDOMWINDOW_IID \
-{ 0x052e675a, 0xacd3, 0x48d1, \
-  { 0x8a, 0xcd, 0xbf, 0xff, 0xbd, 0x24, 0x4c, 0xed } }
+{ 0x775dabc9, 0x8f43, 0x4277, \
+  { 0x9a, 0xdb, 0xf1, 0x99, 0x0d, 0x77, 0xcf, 0xfb } }
 
 class nsPIDOMWindow : public nsIDOMWindowInternal
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOW_IID)
 
   virtual nsPIDOMWindow* GetPrivateRoot() = 0;
 
   // Outer windows only.
   virtual void ActivateOrDeactivate(bool aActivate) = 0;
 
   // this is called GetTopWindowRoot to avoid conflicts with nsIDOMWindow::GetWindowRoot
+  /**
+   * |top| gets the root of the window hierarchy.
+   *
+   * This function does not cross chrome-content boundaries, so if this
+   * window's parent is of a different type, |top| will return this window.
+   *
+   * When script reads the top property, we run GetScriptableTop, which
+   * will not cross an <iframe mozbrowser> boundary.
+   *
+   * In contrast, C++ calls to GetTop are forwarded to GetRealTop, which
+   * ignores <iframe mozbrowser> boundaries.
+   */
+
+  virtual already_AddRefed<nsPIDOMWindow> GetTop() = 0; // Outer only
+  virtual already_AddRefed<nsPIDOMWindow> GetParent() = 0;
+  virtual nsPIDOMWindow* GetScriptableTop() = 0;
+  virtual nsPIDOMWindow* GetScriptableParent() = 0;
   virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() = 0;
 
   // Inner windows only.
   virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0;
   virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0;
 
   // Outer windows only.
   virtual void SetActive(bool aActive)
@@ -758,16 +776,48 @@ public:
     mMarkedCCGeneration = aGeneration;
   }
 
   uint32_t GetMarkedCCGeneration()
   {
     return mMarkedCCGeneration;
   }
 
+  virtual nsIDOMScreen* GetScreen() = 0;
+  virtual nsIDOMNavigator* GetNavigator() = 0;
+  virtual nsIDOMLocation* GetLocation() = 0;
+  virtual nsresult GetPrompter(nsIPrompt** aPrompt) = 0;
+  virtual nsresult GetControllers(nsIControllers** aControllers) = 0;
+  virtual already_AddRefed<nsISelection> GetSelection() = 0;
+  virtual already_AddRefed<nsPIDOMWindow> GetOpener() = 0;
+  virtual already_AddRefed<nsIDOMWindowCollection> GetFrames() = 0;
+  virtual nsresult Open(const nsAString& aUrl, const nsAString& aName,
+                        const nsAString& aOptions, nsPIDOMWindow **_retval) = 0;
+  virtual nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName,
+                              const nsAString& aOptions,
+                              nsISupports* aExtraArgument, nsIDOMWindow** _retval) = 0;
+
+  virtual nsresult GetDevicePixelRatio(float* aRatio) = 0;
+  virtual nsresult GetInnerWidth(int32_t* aWidth) = 0;
+  virtual nsresult GetInnerHeight(int32_t* aHeight) = 0;
+  virtual already_AddRefed<nsICSSDeclaration>
+    GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
+                     mozilla::ErrorResult& aError) = 0;
+  virtual already_AddRefed<nsIDOMElement> GetFrameElement() = 0;
+  virtual already_AddRefed<nsIDOMOfflineResourceList> GetApplicationCache() = 0;
+  virtual bool Closed() = 0;
+  virtual bool GetFullScreen() = 0;
+  virtual nsresult SetFullScreen(bool aFullScreen) = 0;
+
+  virtual nsresult Focus() = 0;
+  virtual nsresult Close() = 0;
+
+  virtual nsresult MoveBy(int32_t aXDif, int32_t aYDif) = 0;
+  virtual nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) = 0;
+
 protected:
   // The nsPIDOMWindow constructor. The aOuterWindow argument should
   // be null if and only if the created window itself is an outer
   // window. In all other cases aOuterWindow should be the outer
   // window for the inner window that is being created.
   explicit nsPIDOMWindow(nsPIDOMWindow *aOuterWindow);
 
   ~nsPIDOMWindow();
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -142,18 +142,17 @@ nsPluginArray::Refresh(bool aReloadDocum
     // different types).
     if (newPluginTags.Length() == mPlugins.Length()) {
       return;
     }
   }
 
   mPlugins.Clear();
 
-  nsCOMPtr<nsIDOMNavigator> navigator;
-  mWindow->GetNavigator(getter_AddRefs(navigator));
+  nsCOMPtr<nsIDOMNavigator> navigator = mWindow->GetNavigator();
 
   if (!navigator) {
     return;
   }
 
   static_cast<mozilla::dom::Navigator*>(navigator.get())->RefreshMIMEArray();
 
   nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -307,17 +307,17 @@ nsScreen::WrapObject(JSContext* aCx, JS:
   return ScreenBinding::Wrap(aCx, this, aGivenProto);
 }
 
 nsresult
 nsScreen::GetWindowInnerRect(nsRect& aRect)
 {
   aRect.x = 0;
   aRect.y = 0;
-  nsCOMPtr<nsIDOMWindow> win = GetOwner();
+  nsCOMPtr<nsPIDOMWindow> win = GetOwner();
   if (!win) {
     return NS_ERROR_FAILURE;
   }
   nsresult rv = win->GetInnerWidth(&aRect.width);
   NS_ENSURE_SUCCESS(rv, rv);
   return win->GetInnerHeight(&aRect.height);
 }
 
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -58,22 +58,20 @@ AddNonJSSizeOfWindowAndItsDescendents(ns
   nsWindowSizes innerWindowSizes(moz_malloc_size_of);
   nsGlobalWindow* inner = aWindow->IsOuterWindow() ? aWindow->GetCurrentInnerWindowInternal()
                                                    : nullptr;
   if (inner) {
     inner->AddSizeOfIncludingThis(&innerWindowSizes);
     innerWindowSizes.addToTabSizes(aSizes);
   }
 
-  nsCOMPtr<nsIDOMWindowCollection> frames;
-  nsresult rv = aWindow->GetFrames(getter_AddRefs(frames));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
 
   uint32_t length;
-  rv = frames->GetLength(&length);
+  nsresult rv = frames->GetLength(&length);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Measure this window's descendents.
   for (uint32_t i = 0; i < length; i++) {
       nsCOMPtr<nsIDOMWindow> child;
       rv = frames->Item(i, getter_AddRefs(child));
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(child);
@@ -247,18 +245,18 @@ CollectWindowReports(nsGlobalWindow *aWi
   nsAutoCString windowPath("explicit/");
 
   // Avoid calling aWindow->GetTop() if there's no outer window.  It will work
   // just fine, but will spew a lot of warnings.
   nsGlobalWindow *top = nullptr;
   nsCOMPtr<nsIURI> location;
   if (aWindow->GetOuterWindow()) {
     // Our window should have a null top iff it has a null docshell.
-    MOZ_ASSERT(!!aWindow->GetTop() == !!aWindow->GetDocShell());
-    top = aWindow->GetTop();
+    MOZ_ASSERT(!!aWindow->GetTopInternal() == !!aWindow->GetDocShell());
+    top = aWindow->GetTopInternal();
     if (top) {
       location = GetWindowURI(top);
     }
   }
   if (!location) {
     location = GetWindowURI(aWindow);
   }
 
@@ -742,19 +740,19 @@ CheckForGhostWindowsEnumerator(nsISuppor
     // The window object has been destroyed.  Stop tracking its weak ref in our
     // hashtable.
     return PL_DHASH_REMOVE;
   }
 
   // Avoid calling GetTop() if we have no outer window.  Nothing will break if
   // we do, but it will spew debug output, which can cause our test logs to
   // overflow.
-  nsCOMPtr<nsIDOMWindow> top;
+  nsCOMPtr<nsPIDOMWindow> top;
   if (window->GetOuterWindow()) {
-    window->GetTop(getter_AddRefs(top));
+    top = window->GetOuterWindow()->GetTop();
   }
 
   if (top) {
     // The window is no longer detached, so we no longer want to track it.
     return PL_DHASH_REMOVE;
   }
 
   nsCOMPtr<nsIURI> uri = GetWindowURI(window);
@@ -801,17 +799,17 @@ static PLDHashOperator
 GetNonDetachedWindowDomainsEnumerator(const uint64_t& aId, nsGlobalWindow* aWindow,
                                       void* aClosure)
 {
   GetNonDetachedWindowDomainsEnumeratorData *data =
     static_cast<GetNonDetachedWindowDomainsEnumeratorData*>(aClosure);
 
   // Null outer window implies null top, but calling GetTop() when there's no
   // outer window causes us to spew debug warnings.
-  if (!aWindow->GetOuterWindow() || !aWindow->GetTop()) {
+  if (!aWindow->GetOuterWindow() || !aWindow->GetTopInternal()) {
     // This window is detached, so we don't care about its domain.
     return PL_DHASH_NEXT;
   }
 
   nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
 
   nsAutoCString domain;
   if (uri) {
--- a/dom/base/nsWindowRoot.cpp
+++ b/dom/base/nsWindowRoot.cpp
@@ -237,17 +237,17 @@ nsWindowRoot::GetControllers(nsIControll
       do_QueryInterface(focusedContent);
     if (htmlInputElement)
       return htmlInputElement->GetControllers(aResult);
 
     if (focusedContent->IsEditable() && focusedWindow)
       return focusedWindow->GetControllers(aResult);
   }
   else {
-    nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(focusedWindow);
+    nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(focusedWindow);
     if (domWindow)
       return domWindow->GetControllers(aResult);
   }
 
   return NS_OK;
 }
 
 nsresult
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -2936,27 +2936,25 @@ nsXMLHttpRequest::Send(nsIVariant* aVari
 
   // If we're synchronous, spin an event loop here and wait
   if (!(mState & XML_HTTP_REQUEST_ASYNC)) {
     mState |= XML_HTTP_REQUEST_SYNCLOOPING;
 
     nsCOMPtr<nsIDocument> suspendedDoc;
     nsCOMPtr<nsIRunnable> resumeTimeoutRunnable;
     if (GetOwner()) {
-      nsCOMPtr<nsIDOMWindow> topWindow;
-      if (NS_SUCCEEDED(GetOwner()->GetTop(getter_AddRefs(topWindow)))) {
-        nsCOMPtr<nsPIDOMWindow> suspendedWindow(do_QueryInterface(topWindow));
-        if (suspendedWindow &&
-            (suspendedWindow = suspendedWindow->GetCurrentInnerWindow())) {
-          suspendedDoc = suspendedWindow->GetExtantDoc();
+      if (nsCOMPtr<nsPIDOMWindow> topWindow = GetOwner()->GetOuterWindow()->GetTop()) {
+        if (topWindow &&
+            (topWindow = topWindow->GetCurrentInnerWindow())) {
+          suspendedDoc = topWindow->GetExtantDoc();
           if (suspendedDoc) {
             suspendedDoc->SuppressEventHandling(nsIDocument::eEvents);
           }
-          suspendedWindow->SuspendTimeouts(1, false);
-          resumeTimeoutRunnable = new nsResumeTimeoutsEvent(suspendedWindow);
+          topWindow->SuspendTimeouts(1, false);
+          resumeTimeoutRunnable = new nsResumeTimeoutsEvent(topWindow);
         }
       }
     }
 
     ChangeState(XML_HTTP_REQUEST_SENT);
 
     {
       nsAutoSyncOperation sync(suspendedDoc);
--- a/dom/browser-element/BrowserElementAudioChannel.cpp
+++ b/dom/browser-element/BrowserElementAudioChannel.cpp
@@ -112,40 +112,34 @@ nsresult
 BrowserElementAudioChannel::Initialize()
 {
   if (!mFrameLoader) {
     nsCOMPtr<nsPIDOMWindow> window = GetOwner();
     if (!window) {
       return NS_ERROR_FAILURE;
     }
 
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    window->GetScriptableTop(getter_AddRefs(topWindow));
-
-    mFrameWindow = do_QueryInterface(topWindow);
+    mFrameWindow = window->GetScriptableTop();
     mFrameWindow = mFrameWindow->GetOuterWindow();
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocShell> docShell;
   nsresult rv = mFrameLoader->GetDocShell(getter_AddRefs(docShell));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (docShell) {
     nsCOMPtr<nsPIDOMWindow> window = docShell->GetWindow();
     if (!window) {
       return NS_ERROR_FAILURE;
     }
 
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    window->GetScriptableTop(getter_AddRefs(topWindow));
-
-    mFrameWindow = do_QueryInterface(topWindow);
+    mFrameWindow = window->GetScriptableTop();
     mFrameWindow = mFrameWindow->GetOuterWindow();
     return NS_OK;
   }
 
   rv = mFrameLoader->GetTabParent(getter_AddRefs(mTabParent));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
--- a/dom/browser-element/BrowserElementParent.cpp
+++ b/dom/browser-element/BrowserElementParent.cpp
@@ -253,20 +253,18 @@ BrowserElementParent::OpenWindowInProces
   // If we call window.open from an <iframe> inside an <iframe mozbrowser>,
   // it's as though the top-level document inside the <iframe mozbrowser>
   // called window.open.  (Indeed, in the OOP case, the inner <iframe> lives
   // out-of-process, so we couldn't touch it if we tried.)
   //
   // GetScriptableTop gets us the <iframe mozbrowser>'s window; we'll use its
   // frame element, rather than aOpenerWindow's frame element, as our "opener
   // frame element" below.
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  aOpenerWindow->GetScriptableTop(getter_AddRefs(topWindow));
-
-  nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(topWindow);
+  nsCOMPtr<nsPIDOMWindow> openerWindow = do_QueryInterface(aOpenerWindow);
+  nsCOMPtr<nsPIDOMWindow> win = openerWindow->GetScriptableTop();
 
   nsCOMPtr<Element> openerFrameElement = win->GetFrameElementInternal();
   NS_ENSURE_TRUE(openerFrameElement, BrowserElementParent::OPEN_WINDOW_IGNORED);
 
 
   RefPtr<HTMLIFrameElement> popupFrameElement =
     CreateIframe(openerFrameElement, aName, /* aRemote = */ false);
   NS_ENSURE_TRUE(popupFrameElement, BrowserElementParent::OPEN_WINDOW_IGNORED);
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -3018,27 +3018,27 @@ EventStateManager::PostHandleEvent(nsPre
         StopTrackingDragGesture();
 
         // When the event was cancelled, there is currently a chrome document
         // focused and a mousedown just occurred on a content document, ensure
         // that the window that was clicked is focused.
         EnsureDocument(mPresContext);
         nsIFocusManager* fm = nsFocusManager::GetFocusManager();
         if (mDocument && fm) {
-          nsCOMPtr<nsIDOMWindow> currentWindow;
-          fm->GetFocusedWindow(getter_AddRefs(currentWindow));
+          nsCOMPtr<nsIDOMWindow> window;
+          fm->GetFocusedWindow(getter_AddRefs(window));
+          nsCOMPtr<nsPIDOMWindow> currentWindow = do_QueryInterface(window);
           if (currentWindow && mDocument->GetWindow() &&
               currentWindow != mDocument->GetWindow() &&
               !nsContentUtils::IsChromeDoc(mDocument)) {
-            nsCOMPtr<nsIDOMWindow> currentTop;
-            nsCOMPtr<nsIDOMWindow> newTop;
-            currentWindow->GetTop(getter_AddRefs(currentTop));
-            mDocument->GetWindow()->GetTop(getter_AddRefs(newTop));
-            nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(currentWindow);
-            nsCOMPtr<nsIDocument> currentDoc = win->GetExtantDoc();
+            nsCOMPtr<nsPIDOMWindow> currentTop;
+            nsCOMPtr<nsPIDOMWindow> newTop;
+            currentTop = currentWindow->GetTop();
+            newTop = mDocument->GetWindow()->GetTop();
+            nsCOMPtr<nsIDocument> currentDoc = currentWindow->GetExtantDoc();
             if (nsContentUtils::IsChromeDoc(currentDoc) ||
                 (currentTop && newTop && currentTop != newTop)) {
               fm->SetFocusedWindow(mDocument->GetWindow());
             }
           }
         }
       }
       SetActiveManager(this, activeContent);
@@ -4107,29 +4107,30 @@ EventStateManager::NotifyMouseOver(Widge
 // it manifest as a potential one-device-pix discrepancy.
 static LayoutDeviceIntPoint
 GetWindowInnerRectCenter(nsPIDOMWindow* aWindow,
                          nsIWidget* aWidget,
                          nsPresContext* aContext)
 {
   NS_ENSURE_TRUE(aWindow && aWidget && aContext, LayoutDeviceIntPoint(0, 0));
 
-  float cssInnerX = 0.0;
-  aWindow->GetMozInnerScreenX(&cssInnerX);
+  nsGlobalWindow* window = nsGlobalWindow::Cast(aWindow);
+
+  float cssInnerX = window->GetMozInnerScreenXOuter();
   int32_t innerX = int32_t(NS_round(cssInnerX));
 
-  float cssInnerY = 0.0;
-  aWindow->GetMozInnerScreenY(&cssInnerY);
+  float cssInnerY = window->GetMozInnerScreenYOuter();
   int32_t innerY = int32_t(NS_round(cssInnerY));
- 
-  int32_t innerWidth = 0;
-  aWindow->GetInnerWidth(&innerWidth);
-
-  int32_t innerHeight = 0;
-  aWindow->GetInnerHeight(&innerHeight);
+
+  ErrorResult dummy;
+  int32_t innerWidth = window->GetInnerWidthOuter(dummy);
+  dummy.SuppressException();
+
+  int32_t innerHeight = window->GetInnerHeightOuter(dummy);
+  dummy.SuppressException();
 
   nsIntRect screen;
   aWidget->GetScreenBounds(screen);
 
   int32_t cssScreenX = aContext->DevPixelsToIntCSSPixels(screen.x);
   int32_t cssScreenY = aContext->DevPixelsToIntCSSPixels(screen.y);
 
   return LayoutDeviceIntPoint(
--- a/dom/geolocation/nsGeolocation.cpp
+++ b/dom/geolocation/nsGeolocation.cpp
@@ -1600,24 +1600,19 @@ Geolocation::WindowOwnerStillExists()
   // is being used without a window.
   if (mOwner == nullptr) {
     return true;
   }
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mOwner);
 
   if (window) {
-    bool closed = false;
-    window->GetClosed(&closed);
-    if (closed) {
-      return false;
-    }
-
     nsPIDOMWindow* outer = window->GetOuterWindow();
-    if (!outer || outer->GetCurrentInnerWindow() != window) {
+    if (!outer || outer->GetCurrentInnerWindow() != window ||
+        outer->Closed()) {
       return false;
     }
   }
 
   return true;
 }
 
 void
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4948,22 +4948,21 @@ HTMLMediaElement::IsEventAttributeName(n
          nsGenericHTMLElement::IsEventAttributeName(aName);
 }
 
 already_AddRefed<nsIPrincipal>
 HTMLMediaElement::GetTopLevelPrincipal()
 {
   RefPtr<nsIPrincipal> principal;
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(OwnerDoc()->GetParentObject());
-  nsCOMPtr<nsIDOMWindow> topWindow;
   if (!window) {
     return nullptr;
   }
-  window->GetTop(getter_AddRefs(topWindow));
-  nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(topWindow);
+  window = window->GetOuterWindow();
+  nsCOMPtr<nsPIDOMWindow> top = window->GetTop();
   if (!top) {
     return nullptr;
   }
   nsIDocument* doc = top->GetExtantDoc();
   if (!doc) {
     return nullptr;
   }
   principal = doc->NodePrincipal();
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -127,20 +127,18 @@ public:
     nsIDocument* document = mElement->OwnerDoc();
 
     nsPIDOMWindow* window = document->GetWindow();
     if (!window) {
       return NS_OK;
     }
 
     // Trying to found the top window (equivalent to window.top).
-    nsCOMPtr<nsIDOMWindow> top;
-    window->GetTop(getter_AddRefs(top));
-    if (top) {
-      window = static_cast<nsPIDOMWindow*>(top.get());
+    if (nsCOMPtr<nsPIDOMWindow> top = window->GetTop()) {
+      window = top;
     }
 
     if (window->GetFocusedNode()) {
       return NS_OK;
     }
 
     nsCOMPtr<nsIDocument> topDoc = window->GetExtantDoc();
     if (topDoc && topDoc->GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE) {
--- a/dom/interfaces/base/nsIDOMWindow.idl
+++ b/dom/interfaces/base/nsIDOMWindow.idl
@@ -9,468 +9,22 @@ interface nsIControllers;
 interface nsIDOMBlob;
 interface nsIDOMLocation;
 interface nsIDOMOfflineResourceList;
 interface nsIPrompt;
 interface nsISelection;
 interface nsIVariant;
 
 /**
- * The nsIDOMWindow interface is the primary interface for a DOM
- * window object. It represents a single window object that may
- * contain child windows if the document in the window contains a
- * HTML frameset document or if the document contains iframe elements.
- *
- * @see <http://www.whatwg.org/html/#window>
+ * Empty interface for compatibility with older versions.
+ * @deprecated Use WebIDL for script visible features,
+ *             nsPIDOMWindow for C++ callers.
  */
 
-[scriptable, uuid(ab30b7cc-f7f9-4b9b-befb-7dbf6cf86d46)]
-interface nsIDOMWindow : nsISupports
-{
-  // the current browsing context
-  readonly attribute nsIDOMWindow                       window;
-
-  /* [replaceable] self */
-  readonly attribute nsIDOMWindow                       self;
-
-  /**
-   * Accessor for the document in this window.
-   */
-  readonly attribute nsIDOMDocument                     document;
-
-  /**
-   * Set/Get the name of this window.
-   *
-   * This attribute is "replaceable" in JavaScript
-   */
-           attribute DOMString                          name;
-
-  /* The setter that takes a string argument needs to be special cased! */
-  readonly attribute nsIDOMLocation                     location;
-
-  readonly attribute nsISupports                        history;
-
-
-  /* [replaceable] locationbar */
-  /* BarProp */
-  readonly attribute nsISupports                        locationbar;
-
-  /* [replaceable] menubar */
-  /* BarProp */
-  readonly attribute nsISupports                        menubar;
-
-  /* [replaceable] personalbar */
-  /* BarProp */
-  readonly attribute nsISupports                        personalbar;
-
-  /**
-   * Accessor for the object that controls whether or not scrollbars
-   * are shown in this window.
-   *
-   * This attribute is "replaceable" in JavaScript
-   */
-  /* BarProp */
-  readonly attribute nsISupports                        scrollbars;
-
-  /* [replaceable] statusbar */
-  /* BarProp */
-  readonly attribute nsISupports                        statusbar;
-
-  /* [replaceable] toolbar */
-  /* BarProp */
-  readonly attribute nsISupports                        toolbar;
-
-  /* [replaceable] */
-           attribute DOMString                          status;
-
-  void                      close();
-  void                      stop();
-  void                      focus();
-  void                      blur();
-
-
-  // other browsing contexts
-  /* [replaceable] length */
-  readonly attribute unsigned long                      length;
-
-  /**
-   * |top| gets the root of the window hierarchy.
-   *
-   * This function does not cross chrome-content boundaries, so if this
-   * window's parent is of a different type, |top| will return this window.
-   *
-   * When script reads the top property, we run GetScriptableTop, which
-   * will not cross an <iframe mozbrowser> boundary.
-   *
-   * In contrast, C++ calls to GetTop are forwarded to GetRealTop, which
-   * ignores <iframe mozbrowser> boundaries.
-   *
-   * This property is "replaceable" in JavaScript.
-   */
-  [binaryname(ScriptableTop)]
-  readonly attribute nsIDOMWindow                       top;
-
-  /**
-   * You shouldn't need to call this function directly; call GetTop instead.
-   */
-  [noscript]
-  readonly attribute nsIDOMWindow                       realTop;
-
-  %{C++
-  nsresult GetTop(nsIDOMWindow **aWindow)
-  {
-    return GetRealTop(aWindow);
-  }
-  %}
-
-  /**
-   * |parent| gets this window's parent window.  If this window has no parent,
-   * we return the window itself.
-   *
-   * This property does not cross chrome-content boundaries, so if this
-   * window's parent is of a different type, we return the window itself as its
-   * parent.
-   *
-   * When script reads the property (or when C++ calls ScriptableTop), this
-   * property does not cross <iframe mozbrowser> boundaries.  In contrast, when
-   * C++ calls GetParent, we ignore the mozbrowser attribute.
-   */
-  [binaryname(ScriptableParent)]
-  readonly attribute nsIDOMWindow                       parent;
-
-  /**
-   * You shouldn't need to read this property directly; call GetParent instead.
-   */
-  [noscript]
-  readonly attribute nsIDOMWindow                       realParent;
-
-  %{C++
-  inline nsresult GetParent(nsIDOMWindow **aWindow)
-  {
-    return GetRealParent(aWindow);
-  }
-  %}
-
-  [implicit_jscontext, binaryname(ScriptableOpener)]
-           attribute jsval                              opener;
-
-  [noscript, binaryname(Opener)]
-           attribute nsIDOMWindow                       openerWindow;
-
-  /**
-   * |frameElement| gets this window's <iframe> or <frame> element, if it has
-   * one.
-   *
-   * When script reads this property (or when C++ calls
-   * ScriptableFrameElement), we return |null| if the window is inside an
-   * <iframe mozbrowser>.  In contrast, when C++ calls GetFrameElement, we
-   * ignore the mozbrowser attribute.
-   */
-  [binaryname(ScriptableFrameElement)]
-  readonly attribute nsIDOMElement                      frameElement;
-
-  /**
-   * You shouldn't need to read this property directly; call GetFrameElement
-   * instead.
-   */
-  [noscript]
-  readonly attribute nsIDOMElement                      realFrameElement;
-
-  %{C++
-  inline nsresult GetFrameElement(nsIDOMElement **aElement)
-  {
-    return GetRealFrameElement(aElement);
-  }
-  %}
-
-
-  // the user agent
-  readonly attribute nsIDOMNavigator                    navigator;
-
-  /**
-   * Get the application cache object for this window.
-   */
-  readonly attribute nsIDOMOfflineResourceList          applicationCache;
-
-
-  // user prompts
-  void                      alert([optional, Null(Stringify)] in DOMString text);
-  boolean                   confirm([optional] in DOMString text);
-
-  // prompt() should return a null string if cancel is pressed
-  DOMString                 prompt([optional] in DOMString aMessage,
-                                   [optional] in DOMString aInitial);
-
-  void                      print();
-
-  [optional_argc]
-  nsIVariant                showModalDialog(in DOMString aURI,
-                                            [optional] in nsIVariant aArgs,
-                                            [optional] in DOMString aOptions);
-
-
-  // cross-document messaging
-  /**
-   * Implements a safe message-passing system which can cross same-origin
-   * boundaries.
-   *
-   * This method, when called, causes a MessageEvent to be asynchronously
-   * dispatched at the primary document for the window upon which this method is
-   * called.  (Note that the postMessage property on windows is allAccess and
-   * thus is readable cross-origin.)  The dispatched event will have message as
-   * its data, the calling context's window as its source, and an origin
-   * determined by the calling context's main document URI.  The targetOrigin
-   * argument specifies a URI and is used to restrict the message to be sent
-   * only when the target window has the same origin as targetOrigin (since,
-   * when the sender and the target have different origins, neither can read the
-   * location of the other).
-   * 
-   * @see <http://www.whatwg.org/html/#dom-window-postmessage>
-   */
-  [implicit_jscontext, binaryname(PostMessageMoz)]
-    void postMessage(in jsval message, in DOMString targetOrigin,
-                     [optional] in jsval transfer);
-
-
-  // WindowBase64
-  // Ascii base64 data to binary data and vice versa...
-  DOMString                 atob(in DOMString aAsciiString);
-  DOMString                 btoa(in DOMString aBase64Data);
-
-
-  // WindowSessionStorage
-  /**
-   * Session storage for the current browsing context.
-   * This attribute is a DOMStorage
-   */
-  readonly attribute nsISupports sessionStorage;
-
-
-  // WindowLocalStorage
-  /**
-   * Local storage for the current browsing context.
-   * This attribute is a DOMStorage
-   */
-  readonly attribute nsISupports localStorage;
-
-
-  // IndexedDB
-  // https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#requests
-  // IDBEnvironment
-  readonly attribute nsISupports indexedDB;
-
-
-  // DOM Range
-  /**
-   * Method for accessing this window's selection object.
-   */
-  nsISelection              getSelection();
-
-
-  // CSSOM-View
-  // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface
-  nsISupports      matchMedia(in DOMString media_query_list);
-
-  readonly attribute nsIDOMScreen                       screen;
-
-  // viewport
-           attribute long                               innerWidth;
-           attribute long                               innerHeight;
-
-
-  // viewport scrolling
-  /**
-   * Accessor for the current x scroll position in this window in
-   * pixels.
-   *
-   * This attribute is "replaceable" in JavaScript
-   */
-  readonly attribute long                               scrollX;
-
-  /* The offset in pixels by which the window is scrolled */
-  readonly attribute long                               pageXOffset;
-
-  /**
-   * Accessor for the current y scroll position in this window in
-   * pixels.
-   *
-   * This attribute is "replaceable" in JavaScript
-   */
-  readonly attribute long                               scrollY;
-
-  /* The offset in pixels by which the window is scrolled */
-  readonly attribute long                               pageYOffset;
-
-  void                      scroll(in long xScroll, in long yScroll);
-
-  /**
-   * Method for scrolling this window to an absolute pixel offset.
-   */
-  void                      scrollTo(in long xScroll, in long yScroll);
-
-  /**
-   * Method for scrolling this window to a pixel offset relative to
-   * the current scroll position.
-   */
-  void                      scrollBy(in long xScrollDif, in long yScrollDif);
-
-
-  // client
-           attribute long                        screenX;
-           attribute long                        screenY;
-           attribute long                        outerWidth;
-           attribute long                        outerHeight;
-
-
-  // CSSOM
-  /**
-   * @see <http://dev.w3.org/csswg/cssom/#dom-window-getcomputedstyle>
-   */
-  nsIDOMCSSStyleDeclaration getComputedStyle(in nsIDOMElement elt, 
-                                             [optional] in DOMString pseudoElt);
-  nsIDOMCSSStyleDeclaration getDefaultComputedStyle(in nsIDOMElement elt,
-                                                    [optional] in DOMString pseudoElt);
-
-
-  // Mozilla extensions
-  /**
-   * Get the window root for this window. This is useful for hooking
-   * up event listeners to this window and every other window nested
-   * in the window root.
-   */
-  [noscript] readonly attribute nsIDOMEventTarget windowRoot;
-
-  /**
-   * Accessor for the child windows in this window.
-   */
-  [noscript] readonly attribute nsIDOMWindowCollection  frames;
-
-  /**
-   * Set/Get the document scale factor as a multiplier on the default
-   * size. When setting this attribute, a NS_ERROR_NOT_IMPLEMENTED
-   * error may be returned by implementations not supporting
-   * zoom. Implementations not supporting zoom should return 1.0 all
-   * the time for the Get operation. 1.0 is equals normal size,
-   * i.e. no zoom.
-   */
-  [noscript] attribute float                            textZoom;
-
-  /**
-   * Method for scrolling this window by a number of lines.
-   */
-  void                      scrollByLines(in long numLines);
-
-  /**
-   * Method for scrolling this window by a number of pages.
-   */
-  void                      scrollByPages(in long numPages);
-
-  /**
-   * Method for sizing this window to the content in the window.
-   */
-  void                      sizeToContent();
-
-  /* [replaceable] prompter */
-  [noscript] readonly attribute nsIPrompt               prompter;
-
-  readonly attribute boolean                            closed;
-
-  readonly attribute nsIDOMCrypto                       crypto;
-
-  // Note: this is [ChromeOnly] scriptable via WebIDL.
-  [noscript] readonly attribute nsIControllers          controllers;
-
-  readonly attribute float                              mozInnerScreenX;
-  readonly attribute float                              mozInnerScreenY;
-  readonly attribute float                              devicePixelRatio;
-
-  /* The maximum offset that the window can be scrolled to
-     (i.e., the document width/height minus the scrollport width/height) */
-  readonly attribute long                               scrollMaxX;
-  readonly attribute long                               scrollMaxY;
-
-           attribute boolean                            fullScreen;
-
-  void                      back();
-  void                      forward();
-  void                      home();
-
-  void                      moveTo(in long xPos, in long yPos);
-  void                      moveBy(in long xDif, in long yDif);
-  void                      resizeTo(in long width, in long height);
-  void                      resizeBy(in long widthDif, in long heightDif);
-
-  /**
-   * Open a new window with this one as the parent.  This method will
-   * NOT examine the JS stack for purposes of determining a caller.
-   * This window will be used for security checks during the search by
-   * name and the default character set on the newly opened window
-   * will just be the default character set of this window.
-   */
-  [noscript] nsIDOMWindow   open(in DOMString url, in DOMString name,
-                                 in DOMString options);
-
-  /**
-   * This method works like open except that aExtraArgument gets
-   * converted into the array window.arguments in JS, if
-   * aExtraArgument is a nsISupportsArray then the individual items in
-   * the array are inserted into window.arguments, and primitive
-   * nsISupports (nsISupportsPrimitives) types are converted to native
-   * JS types when possible.
-   */
-  [noscript] nsIDOMWindow   openDialog(in DOMString url, in DOMString name,
-                                       in DOMString options,
-                                       in nsISupports aExtraArgument);
-
-  // XXX Should this be in nsIDOMChromeWindow?
-  void                      updateCommands(in DOMString action,
-                                           [optional] in nsISelection sel,
-                                           [optional] in short reason);
-
-  /* Find in page.
-   * @param str: the search pattern
-   * @param caseSensitive: is the search caseSensitive
-   * @param backwards: should we search backwards
-   * @param wrapAround: should we wrap the search
-   * @param wholeWord: should we search only for whole words
-   * @param searchInFrames: should we search through all frames
-   * @param showDialog: should we show the Find dialog
-   */
-  boolean                   find([optional] in DOMString str,
-                                 [optional] in boolean caseSensitive,
-                                 [optional] in boolean backwards,
-                                 [optional] in boolean wrapAround,
-                                 [optional] in boolean wholeWord,
-                                 [optional] in boolean searchInFrames,
-                                 [optional] in boolean showDialog);
-
-  /**
-   * Returns the number of times this document for this window has
-   * been painted to the screen.
-   */
-  readonly attribute unsigned long long mozPaintCount;
-
-  /**
-   * Request a refresh of this browser window.
-   *
-   * @see <http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/RequestAnimationFrame/Overview.html>
-   */
-  // jsval because we want a WebIDL callback here
-  [implicit_jscontext]
-  long requestAnimationFrame(in jsval aCallback);
-
-  /**
-   * Cancel a refresh callback.
-   */
-  void cancelAnimationFrame(in long aHandle);
-
-  /**
-   * Console API
-   */
-  [implicit_jscontext] attribute jsval console;
-};
+[scriptable, uuid(b8343993-0383-4add-9930-ad176b189240)]
+interface nsIDOMWindow : nsISupports {};
 
 /**
  * Empty interface for compatibility with older versions.
  * @deprecated Use nsIDOMWindow instead
  */
-[scriptable, uuid(2ec49e81-b2ba-4633-991a-f48f1e1d8800)]
+[scriptable, uuid(8c589e65-3237-4cd1-8bad-c5c47135e79b)]
 interface nsIDOMWindowInternal : nsIDOMWindow {};
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1186,30 +1186,18 @@ TabChild::ProvideWindowCommon(nsIDOMWind
   nsTArray<FrameScriptInfo> frameScripts;
   nsCString urlToLoad;
 
   if (aIframeMoz) {
     newChild->SendBrowserFrameOpenWindow(this, url, name,
                                          NS_ConvertUTF8toUTF16(features),
                                          aWindowIsNew);
   } else {
-    nsCOMPtr<nsIDOMDocument> domDoc;
-    aOpener->GetDocument(getter_AddRefs(domDoc));
-    if (!domDoc) {
-      NS_ERROR("Could retrieve document from nsIBaseWindow");
-      return NS_ERROR_FAILURE;
-    }
-
-    nsCOMPtr<nsIDocument> doc;
-    doc = do_QueryInterface(domDoc);
-    if (!doc) {
-      NS_ERROR("Document from nsIBaseWindow didn't QI to nsIDocument");
-      return NS_ERROR_FAILURE;
-    }
-
+    nsCOMPtr<nsPIDOMWindow> opener = do_QueryInterface(aOpener);
+    nsCOMPtr<nsIDocument> doc = opener->GetDoc();
     nsCOMPtr<nsIURI> baseURI = doc->GetDocBaseURI();
     if (!baseURI) {
       NS_ERROR("nsIDocument didn't return a base URI");
       return NS_ERROR_FAILURE;
     }
 
     nsAutoCString baseURIString;
     baseURI->GetSpec(baseURIString);
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -750,36 +750,35 @@ public:
   }
 
 private:
   TabParent* mNewTab;
   bool* mWindowIsNew;
   nsCString* mURLToLoad;
 };
 
-static already_AddRefed<nsIDOMWindow>
+static already_AddRefed<nsPIDOMWindow>
 FindMostRecentOpenWindow()
 {
   nsCOMPtr<nsIWindowMediator> windowMediator =
     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
   windowMediator->GetEnumerator(MOZ_UTF16("navigator:browser"),
                                 getter_AddRefs(windowEnumerator));
 
-  nsCOMPtr<nsIDOMWindow> latest;
+  nsCOMPtr<nsPIDOMWindow> latest;
 
   bool hasMore = false;
   MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->HasMoreElements(&hasMore)));
   while (hasMore) {
     nsCOMPtr<nsISupports> item;
     MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->GetNext(getter_AddRefs(item))));
-    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(item);
-
-    bool isClosed;
-    if (window && NS_SUCCEEDED(window->GetClosed(&isClosed)) && !isClosed) {
+    nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(item);
+
+    if (window && !window->Closed()) {
       latest = window;
     }
 
     MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->HasMoreElements(&hasMore)));
   }
 
   return latest.forget();
 }
@@ -822,27 +821,24 @@ TabParent::RecvCreateWindow(PBrowserPare
   MOZ_ASSERT(newTab);
 
   // Content has requested that we open this new content window, so
   // we must have an opener.
   newTab->SetHasContentOpener(true);
 
   nsCOMPtr<nsIContent> frame(do_QueryInterface(mFrameElement));
 
-  nsCOMPtr<nsIDOMWindow> parent;
+  nsCOMPtr<nsPIDOMWindow> parent;
   if (frame) {
-    parent = do_QueryInterface(frame->OwnerDoc()->GetWindow());
+    parent = frame->OwnerDoc()->GetWindow();
 
     // If our chrome window is in the process of closing, don't try to open a
     // new tab in it.
-    if (parent) {
-      bool isClosed;
-      if (NS_SUCCEEDED(parent->GetClosed(&isClosed)) && isClosed) {
-        parent = nullptr;
-      }
+    if (parent && parent->Closed()) {
+      parent = nullptr;
     }
   }
 
   nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin = mBrowserDOMWindow;
 
   // If we haven't found a chrome window to open in, just use the most recently
   // opened one.
   if (!parent) {
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -307,19 +307,18 @@ MediaKeys::Init(ErrorResult& aRv)
   // Determine principal of the "top-level" window; the principal of the
   // page that will display in the URL bar.
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetParentObject());
   if (!window) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
                          NS_LITERAL_CSTRING("Couldn't get top-level window in MediaKeys::Init"));
     return promise.forget();
   }
-  nsCOMPtr<nsIDOMWindow> topWindow;
-  window->GetTop(getter_AddRefs(topWindow));
-  nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(topWindow);
+  window = window->GetOuterWindow();
+  nsCOMPtr<nsPIDOMWindow> top = window->GetTop();
   if (!top || !top->GetExtantDoc()) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
                          NS_LITERAL_CSTRING("Couldn't get document in MediaKeys::Init"));
     return promise.forget();
   }
 
   mTopLevelPrincipal = top->GetExtantDoc()->NodePrincipal();
 
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -3025,21 +3025,18 @@ NS_IMETHODIMP nsPluginInstanceOwner::Cre
     nsIDocument *doc = nullptr;
     nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
     if (content) {
       doc = content->OwnerDoc();
       parentWidget = nsContentUtils::WidgetForDocument(doc);
 #ifndef XP_MACOSX
       // If we're running in the content process, we need a remote widget created in chrome.
       if (XRE_IsContentProcess()) {
-        nsCOMPtr<nsIDOMWindow> window = doc->GetWindow();
-        if (window) {
-          nsCOMPtr<nsIDOMWindow> topWindow;
-          window->GetTop(getter_AddRefs(topWindow));
-          if (topWindow) {
+        if (nsCOMPtr<nsPIDOMWindow> window = doc->GetWindow()) {
+          if (nsCOMPtr<nsPIDOMWindow> topWindow = window->GetTop()) {
             dom::TabChild* tc = dom::TabChild::GetFrom(topWindow);
             if (tc) {
               // This returns a PluginWidgetProxy which remotes a number of calls.
               rv = tc->CreatePluginWidget(parentWidget.get(), getter_AddRefs(mWidget));
               if (NS_FAILED(rv)) {
                 return rv;
               }
             }
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -212,25 +212,22 @@ nsDeviceSensors::Notify(const mozilla::h
   for (uint32_t i = windowListeners.Count(); i > 0 ; ) {
     --i;
 
     nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(windowListeners[i]);
     if (WindowCannotReceiveSensorEvent(pwindow)) {
         continue;
     }
 
-    nsCOMPtr<nsIDOMDocument> domdoc;
-    windowListeners[i]->GetDocument(getter_AddRefs(domdoc));
-
-    if (domdoc) {
+    if (nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(pwindow->GetDoc())) {
       nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(windowListeners[i]);
       if (type == nsIDeviceSensorData::TYPE_ACCELERATION ||
         type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION ||
         type == nsIDeviceSensorData::TYPE_GYROSCOPE)
-        FireDOMMotionEvent(domdoc, target, type, x, y, z);
+        FireDOMMotionEvent(domDoc, target, type, x, y, z);
       else if (type == nsIDeviceSensorData::TYPE_ORIENTATION)
         FireDOMOrientationEvent(target, x, y, z);
       else if (type == nsIDeviceSensorData::TYPE_PROXIMITY)
         FireDOMProximityEvent(target, x, y, z);
       else if (type == nsIDeviceSensorData::TYPE_LIGHT)
         FireDOMLightEvent(target, x);
 
     }
--- a/dom/xbl/nsXBLPrototypeHandler.cpp
+++ b/dom/xbl/nsXBLPrototypeHandler.cpp
@@ -567,19 +567,20 @@ nsXBLPrototypeHandler::GetController(Eve
 
   if (!controllers) {
     nsCOMPtr<nsIDOMHTMLInputElement> htmlInputElement(do_QueryInterface(aTarget));
     if (htmlInputElement)
       htmlInputElement->GetControllers(getter_AddRefs(controllers));
   }
 
   if (!controllers) {
-    nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(aTarget));
-    if (domWindow)
+    nsCOMPtr<nsPIDOMWindow> domWindow(do_QueryInterface(aTarget));
+    if (domWindow) {
       domWindow->GetControllers(getter_AddRefs(controllers));
+    }
   }
 
   // Return the first controller.
   // XXX This code should be checking the command name and using supportscommand and
   // iscommandenabled.
   nsCOMPtr<nsIController> controller;
   if (controllers) {
     controllers->GetControllerAt(0, getter_AddRefs(controller));
--- a/dom/xml/nsXMLPrettyPrinter.cpp
+++ b/dom/xml/nsXMLPrettyPrinter.cpp
@@ -1,23 +1,22 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
 #include "nsXMLPrettyPrinter.h"
 #include "nsContentUtils.h"
-#include "nsIDOMCSSStyleDeclaration.h"
+#include "nsICSSDeclaration.h"
 #include "nsIDOMDocumentXBL.h"
 #include "nsIObserver.h"
 #include "nsIXSLTProcessor.h"
 #include "nsSyncLoadService.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMElement.h"
-#include "nsIDOMDocument.h"
 #include "nsIServiceManager.h"
 #include "nsNetUtil.h"
 #include "mozilla/dom/Element.h"
 #include "nsIDOMDocumentFragment.h"
 #include "nsBindingManager.h"
 #include "nsXBLService.h"
 #include "nsIScriptSecurityManager.h"
 #include "mozilla/Preferences.h"
@@ -50,32 +49,34 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocum
 
     // Check for iframe with display:none. Such iframes don't have presshells
     if (!aDocument->GetShell()) {
         return NS_OK;
     }
 
     // check if we're in an invisible iframe
     nsPIDOMWindow *internalWin = aDocument->GetWindow();
-    nsCOMPtr<nsIDOMElement> frameElem;
+    nsCOMPtr<Element> frameElem;
     if (internalWin) {
-        internalWin->GetFrameElement(getter_AddRefs(frameElem));
+        frameElem = internalWin->GetFrameElementInternal();
     }
 
     if (frameElem) {
-        nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle;
-        nsCOMPtr<nsIDOMDocument> frameOwnerDoc;
-        frameElem->GetOwnerDocument(getter_AddRefs(frameOwnerDoc));
-        if (frameOwnerDoc) {
-            nsCOMPtr<nsIDOMWindow> window;
-            frameOwnerDoc->GetDefaultView(getter_AddRefs(window));
-            if (window) {
-                window->GetComputedStyle(frameElem,
-                                         EmptyString(),
-                                         getter_AddRefs(computedStyle));
+        nsCOMPtr<nsICSSDeclaration> computedStyle;
+        if (nsIDocument* frameOwnerDoc = frameElem->OwnerDoc()) {
+            nsCOMPtr<nsIDOMWindow> window = frameOwnerDoc->GetDefaultView();
+            nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
+            if (piWindow) {
+                piWindow = piWindow->GetCurrentInnerWindow();
+
+                ErrorResult dummy;
+                computedStyle = piWindow->GetComputedStyle(*frameElem,
+                                                           EmptyString(),
+                                                           dummy);
+                dummy.SuppressException();
             }
         }
 
         if (computedStyle) {
             nsAutoString visibility;
             computedStyle->GetPropertyValue(NS_LITERAL_STRING("visibility"),
                                             visibility);
             if (!visibility.EqualsLiteral("visible")) {
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -155,23 +155,21 @@ nsXULCommandDispatcher::GetFocusedWindow
 
   nsCOMPtr<nsPIDOMWindow> window;
   GetRootFocusedContentAndWindow(getter_AddRefs(window));
   if (!window)
     return NS_OK;
 
   // Make sure the caller can access this window. The caller can access this
   // window iff it can access the document.
-  nsCOMPtr<nsIDOMDocument> domdoc;
-  nsresult rv = window->GetDocument(getter_AddRefs(domdoc));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
 
   // Note: If there is no document, then this window has been cleared and
   // there's nothing left to protect, so let the window pass through.
-  if (domdoc && !nsContentUtils::CanCallerAccess(domdoc))
+  if (doc && !nsContentUtils::CanCallerAccess(doc))
     return NS_ERROR_DOM_SECURITY_ERR;
 
   window.forget(aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
--- a/dom/xul/nsXULPopupListener.cpp
+++ b/dom/xul/nsXULPopupListener.cpp
@@ -115,25 +115,23 @@ nsXULPopupListener::HandleEvent(nsIDOMEv
   }
 
   // Get the node that was clicked on.
   EventTarget* target = mouseEvent->InternalDOMEvent()->GetTarget();
   nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(target);
 
   if (!targetNode && mIsContext) {
     // Not a DOM node, see if it's the DOM window (bug 380818).
-    nsCOMPtr<nsIDOMWindow> domWin = do_QueryInterface(target);
+    nsCOMPtr<nsPIDOMWindow> domWin = do_QueryInterface(target);
     if (!domWin) {
       return NS_ERROR_DOM_WRONG_TYPE_ERR;
     }
     // Try to use the root node as target node.
-    nsCOMPtr<nsIDOMDocument> domDoc;
-    domWin->GetDocument(getter_AddRefs(domDoc));
+    nsCOMPtr<nsIDocument> doc = domWin->GetDoc();
 
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
     if (doc)
       targetNode = do_QueryInterface(doc->GetRootElement());
     if (!targetNode) {
       return NS_ERROR_FAILURE;
     }
   }
 
   nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
--- a/editor/composer/nsComposerCommandsUpdater.cpp
+++ b/editor/composer/nsComposerCommandsUpdater.cpp
@@ -334,21 +334,23 @@ nsComposerCommandsUpdater::UpdateOneComm
   commandUpdater->CommandStatusChanged(aCommand);
 
   return NS_OK;
 }
 
 bool
 nsComposerCommandsUpdater::SelectionIsCollapsed()
 {
-  nsCOMPtr<nsIDOMWindow> domWindow = do_QueryReferent(mDOMWindow);
+  nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryReferent(mDOMWindow);
   NS_ENSURE_TRUE(domWindow, true);
 
-  nsCOMPtr<nsISelection> domSelection;
-  if (NS_SUCCEEDED(domWindow->GetSelection(getter_AddRefs(domSelection))) && domSelection)
+  domWindow = domWindow->GetOuterWindow();
+  NS_ENSURE_TRUE(domWindow, true);
+
+  if (nsCOMPtr<nsISelection> domSelection = domWindow->GetSelection())
   {
     bool selectionCollapsed = false;
     domSelection->GetIsCollapsed(&selectionCollapsed);
     return selectionCollapsed;
   }
 
   NS_WARNING("nsComposerCommandsUpdater::SelectionIsCollapsed - no domSelection");
 
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -297,21 +297,22 @@ nsEditingSession::SetupEditorOnWindow(ns
   mDoneSetup = true;
 
   nsresult rv;
 
   //MIME CHECKING
   //must get the content type
   // Note: the doc gets this from the network channel during StartPageLoad,
   //    so we don't have to get it from there ourselves
-  nsCOMPtr<nsIDOMDocument> doc;
   nsAutoCString mimeCType;
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
+  MOZ_ASSERT(window);
 
   //then lets check the mime type
-  if (NS_SUCCEEDED(aWindow->GetDocument(getter_AddRefs(doc))) && doc)
+  if (nsCOMPtr<nsIDocument> doc = window->GetDoc())
   {
     nsAutoString mimeType;
     if (NS_SUCCEEDED(doc->GetContentType(mimeType)))
       AppendUTF16toUTF8(mimeType, mimeCType);
 
     if (IsSupportedTextType(mimeCType.get()))
     {
       mEditorType.AssignLiteral("text");
@@ -529,19 +530,21 @@ nsEditingSession::TearDownEditorOnWindow
   {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nullptr;
   }
 
   mDoneSetup = false;
 
   // Check if we're turning off editing (from contentEditable or designMode).
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aWindow->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
+  MOZ_ASSERT(window);
+
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
+  nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
   bool stopEditing = htmlDoc && htmlDoc->IsEditingOn();
   if (stopEditing)
     RemoveWebProgressListener(aWindow);
 
   nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow);
   NS_ENSURE_STATE(docShell);
 
   nsCOMPtr<nsIEditor> editor;
@@ -567,19 +570,16 @@ nsEditingSession::TearDownEditorOnWindow
   if (stopEditing)
   {
     // Make things the way they were before we started editing.
     RestoreJSAndPlugins(aWindow);
     RestoreAnimationMode(aWindow);
 
     if (mMakeWholeDocumentEditable)
     {
-      nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
-
       doc->SetEditableFlag(false);
       nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
       if (htmlDocument) {
         htmlDocument->SetEditingState(nsIHTMLDocument::eOff);
       }
     }
   }
 
@@ -668,18 +668,18 @@ nsEditingSession::OnStateChange(nsIWebPr
       bool progressIsForTargetDocument =
         IsProgressForTargetDocument(aWebProgress);
 
       if (progressIsForTargetDocument)
       {
         nsCOMPtr<nsIDOMWindow> window;
         aWebProgress->GetDOMWindow(getter_AddRefs(window));
 
-        nsCOMPtr<nsIDOMDocument> doc;
-        window->GetDocument(getter_AddRefs(doc));
+        nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
+        nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
 
         nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
 
         if (htmlDoc && htmlDoc->IsWriting())
         {
           nsCOMPtr<nsIDOMHTMLDocument> htmlDomDoc = do_QueryInterface(doc);
           nsAutoString designMode;
           htmlDomDoc->GetDesignMode(designMode);
@@ -795,21 +795,20 @@ NS_IMETHODIMP
 nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress,
                                    nsIRequest *aRequest, nsIURI *aURI,
                                    uint32_t aFlags)
 {
   nsCOMPtr<nsIDOMWindow> domWindow;
   nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  rv = domWindow->GetDocument(getter_AddRefs(domDoc));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(domWindow);
+  MOZ_ASSERT(piWindow);
 
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   doc->SetDocumentURI(aURI);
 
   // Notify the location-changed observer that
   //  the document URL has changed
   nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
@@ -1157,18 +1156,21 @@ nsEditingSession::SetupEditorCommandCont
                                   nsISupports *aContext,
                                   uint32_t *aControllerId)
 {
   NS_ENSURE_ARG_POINTER(aControllerClassName);
   NS_ENSURE_ARG_POINTER(aWindow);
   NS_ENSURE_ARG_POINTER(aContext);
   NS_ENSURE_ARG_POINTER(aControllerId);
 
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  MOZ_ASSERT(piWindow);
+
   nsCOMPtr<nsIControllers> controllers;
-  nsresult rv = aWindow->GetControllers(getter_AddRefs(controllers));
+  nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We only have to create each singleton controller once
   // We know this has happened once we have a controllerId value
   if (!*aControllerId)
   {
     nsCOMPtr<nsIController> controller;
     controller = do_CreateInstance(aControllerClassName, &rv);
@@ -1196,18 +1198,21 @@ nsEditingSession::SetupEditorCommandCont
   Set the editor on the controller(s) for this window
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow,
                                          nsIEditor* aEditor)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
 
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  MOZ_ASSERT(piWindow);
+
   nsCOMPtr<nsIControllers> controllers;
-  nsresult rv = aWindow->GetControllers(getter_AddRefs(controllers));
+  nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISupports> editorAsISupports = do_QueryInterface(aEditor);
   if (mBaseCommandControllerId)
   {
     rv = SetContextOnControllerById(controllers, editorAsISupports,
                                     mBaseCommandControllerId);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -1248,18 +1253,19 @@ nsEditingSession::SetContextOnController
 
 void
 nsEditingSession::RemoveEditorControllers(nsIDOMWindow *aWindow)
 {
   // Remove editor controllers from the aWindow, call when we're
   // tearing down/detaching editor.
 
   nsCOMPtr<nsIControllers> controllers;
-  if (aWindow)
-    aWindow->GetControllers(getter_AddRefs(controllers));
+  if (nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow)) {
+    piWindow->GetControllers(getter_AddRefs(controllers));
+  }
 
   if (controllers)
   {
     nsCOMPtr<nsIController> controller;
     if (mBaseCommandControllerId)
     {
       controllers->GetControllerById(mBaseCommandControllerId,
                                      getter_AddRefs(controller));
--- a/embedding/browser/moz.build
+++ b/embedding/browser/moz.build
@@ -45,9 +45,10 @@ UNIFIED_SOURCES += [
     'nsWebBrowser.cpp',
     'nsWebBrowserContentPolicy.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 LOCAL_INCLUDES += [
     '/dom/base',
     '/dom/svg',
+    '/layout/style',
 ]
--- a/embedding/browser/nsContextMenuInfo.cpp
+++ b/embedding/browser/nsContextMenuInfo.cpp
@@ -12,28 +12,31 @@
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMHTMLHtmlElement.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsIDOMHTMLImageElement.h"
 #include "nsIDOMHTMLAreaElement.h"
 #include "nsIDOMHTMLLinkElement.h"
 #include "nsIDOMWindow.h"
-#include "nsIDOMCSSStyleDeclaration.h"
+#include "nsICSSDeclaration.h"
 #include "nsIDOMCSSValue.h"
 #include "nsIDOMCSSPrimitiveValue.h"
 #include "nsNetUtil.h"
 #include "nsUnicharUtils.h"
 #include "nsIDocument.h"
 #include "nsIPrincipal.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIContentPolicy.h"
 #include "nsAutoPtr.h"
 #include "imgRequestProxy.h"
 
+using mozilla::dom::Element;
+using mozilla::ErrorResult;
+
 NS_IMPL_ISUPPORTS(nsContextMenuInfo, nsIContextMenuInfo)
 
 nsContextMenuInfo::nsContextMenuInfo()
 {
 }
 
 nsContextMenuInfo::~nsContextMenuInfo()
 {
@@ -255,32 +258,38 @@ nsContextMenuInfo::GetBackgroundImageReq
   nsCOMPtr<nsIDOMDocument> document;
   domNode->GetOwnerDocument(getter_AddRefs(document));
   NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMWindow> window;
   document->GetDefaultView(getter_AddRefs(window));
   NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
 
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
+  MOZ_ASSERT(piWindow);
+  piWindow = piWindow->GetCurrentInnerWindow();
+  MOZ_ASSERT(piWindow);
+
   nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue;
   nsAutoString bgStringValue;
 
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(document));
   nsCOMPtr<nsIPrincipal> principal = doc ? doc->NodePrincipal() : nullptr;
 
   while (true) {
-    nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(domNode));
+    nsCOMPtr<Element> domElement(do_QueryInterface(domNode));
     // bail for the parent node of the root element or null argument
     if (!domElement) {
       break;
     }
 
-    nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle;
-    window->GetComputedStyle(domElement, EmptyString(),
-                             getter_AddRefs(computedStyle));
+    ErrorResult dummy;
+    nsCOMPtr<nsICSSDeclaration> computedStyle =
+      piWindow->GetComputedStyle(*domElement, EmptyString(), dummy);
+    dummy.SuppressException();
     if (computedStyle) {
       nsCOMPtr<nsIDOMCSSValue> cssValue;
       computedStyle->GetPropertyCSSValue(NS_LITERAL_STRING("background-image"),
                                          getter_AddRefs(cssValue));
       primitiveValue = do_QueryInterface(cssValue);
       if (primitiveValue) {
         primitiveValue->GetStringValue(bgStringValue);
         if (!bgStringValue.EqualsLiteral("none")) {
--- a/embedding/components/commandhandler/nsCommandManager.cpp
+++ b/embedding/components/commandhandler/nsCommandManager.cpp
@@ -243,20 +243,20 @@ nsCommandManager::GetControllerForComman
     }
 
     // if a target window is specified, it must be the window we expect
     if (aTargetWindow != mWindow) {
       return NS_ERROR_FAILURE;
     }
   }
 
-  if (aTargetWindow) {
+  if (nsCOMPtr<nsPIDOMWindow> targetWindow = do_QueryInterface(aTargetWindow)) {
     // get the controller for this particular window
     nsCOMPtr<nsIControllers> controllers;
-    rv = aTargetWindow->GetControllers(getter_AddRefs(controllers));
+    rv = targetWindow->GetControllers(getter_AddRefs(controllers));
     if (NS_FAILED(rv)) {
       return rv;
     }
     if (!controllers) {
       return NS_ERROR_FAILURE;
     }
 
     // dispatch the command
--- a/embedding/components/find/nsWebBrowserFind.cpp
+++ b/embedding/components/find/nsWebBrowserFind.cpp
@@ -349,23 +349,22 @@ IsInNativeAnonymousSubtree(nsIContent* a
 
   return false;
 }
 
 void
 nsWebBrowserFind::SetSelectionAndScroll(nsIDOMWindow* aWindow,
                                         nsIDOMRange* aRange)
 {
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aWindow->GetDocument(getter_AddRefs(domDoc));
-  if (!domDoc) {
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
+  if (!doc) {
     return;
   }
 
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
   nsIPresShell* presShell = doc->GetShell();
   if (!presShell) {
     return;
   }
 
   nsCOMPtr<nsIDOMNode> node;
   aRange->GetStartContainer(getter_AddRefs(node));
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
@@ -696,36 +695,32 @@ nsresult
 nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow, bool aWrapping,
                                 bool* aDidFind)
 {
   NS_ENSURE_ARG(aWindow);
   NS_ENSURE_ARG_POINTER(aDidFind);
 
   *aDidFind = false;
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  nsresult rv = aWindow->GetDocument(getter_AddRefs(domDoc));
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (!domDoc) {
-    return NS_ERROR_FAILURE;
-  }
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
 
   // Do security check, to ensure that the frame we're searching is
   // acccessible from the frame where the Find is being run.
 
   // get a uri for the window
-  nsCOMPtr<nsIDocument> theDoc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsIDocument> theDoc = piWindow->GetDoc();
   if (!theDoc) {
     return NS_ERROR_FAILURE;
   }
 
   if (!nsContentUtils::SubjectPrincipal()->Subsumes(theDoc->NodePrincipal())) {
     return NS_ERROR_DOM_PROP_ACCESS_DENIED;
   }
 
+  nsresult rv;
   nsCOMPtr<nsIFind> find = do_CreateInstance(NS_FIND_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   (void)find->SetCaseSensitive(mMatchCase);
   (void)find->SetFindBackwards(mFindBackwards);
 
   // XXX Make and set a line breaker here, once that's implemented.
   (void)find->SetWordBreaker(nullptr);
@@ -742,16 +737,19 @@ nsWebBrowserFind::SearchInFrame(nsIDOMWi
   NS_ENSURE_ARG_POINTER(searchRange);
   nsCOMPtr<nsIDOMRange> startPt = nsFind::CreateRange(theDoc);
   NS_ENSURE_ARG_POINTER(startPt);
   nsCOMPtr<nsIDOMRange> endPt = nsFind::CreateRange(theDoc);
   NS_ENSURE_ARG_POINTER(endPt);
 
   nsCOMPtr<nsIDOMRange> foundRange;
 
+  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(theDoc);
+  MOZ_ASSERT(domDoc);
+
   // If !aWrapping, search from selection to end
   if (!aWrapping)
     rv = GetSearchLimits(searchRange, startPt, endPt, domDoc, sel, false);
 
   // If aWrapping, search the part of the starting frame
   // up to the point where we left off.
   else
     rv = GetSearchLimits(searchRange, startPt, endPt, domDoc, sel, true);
@@ -789,23 +787,22 @@ nsWebBrowserFind::OnEndSearchFrame(nsIDO
   return NS_OK;
 }
 
 void
 nsWebBrowserFind::GetFrameSelection(nsIDOMWindow* aWindow, nsISelection** aSel)
 {
   *aSel = nullptr;
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aWindow->GetDocument(getter_AddRefs(domDoc));
-  if (!domDoc) {
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aWindow);
+  nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
+  if (!doc) {
     return;
   }
 
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
   nsIPresShell* presShell = doc->GetShell();
   if (!presShell) {
     return;
   }
 
   // text input controls have their independent selection controllers that we
   // must use when they have focus.
   nsPresContext* presContext = presShell->GetPresContext();
--- a/embedding/components/printingui/mac/nsPrintProgress.cpp
+++ b/embedding/components/printingui/mac/nsPrintProgress.cpp
@@ -5,16 +5,17 @@
 
 #include "nsPrintProgress.h"
 
 #include "nsIBaseWindow.h"
 #include "nsISupportsArray.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIComponentManager.h"
+#include "nsPIDOMWindow.h"
 
 NS_IMPL_ADDREF(nsPrintProgress)
 NS_IMPL_RELEASE(nsPrintProgress)
 
 NS_INTERFACE_MAP_BEGIN(nsPrintProgress)
    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintStatusFeedback)
    NS_INTERFACE_MAP_ENTRY(nsIPrintProgress)
    NS_INTERFACE_MAP_ENTRY(nsIPrintStatusFeedback)
@@ -57,18 +58,21 @@ NS_IMETHODIMP nsPrintProgress::CloseProg
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nullptr;
 
-  if (! m_closeProgress && m_dialog)
-    return m_dialog->GetPrompter(_retval);
+  if (! m_closeProgress && m_dialog) {
+    nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(m_dialog);
+    MOZ_ASSERT(window);
+    return window->GetPrompter(_retval);
+  }
     
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(bool *aProcessCanceledByUser)
 {
   NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
   *aProcessCanceledByUser = m_processCanceled;
--- a/embedding/components/printingui/unixshared/nsPrintProgress.cpp
+++ b/embedding/components/printingui/unixshared/nsPrintProgress.cpp
@@ -87,23 +87,26 @@ NS_IMETHODIMP nsPrintProgress::OpenProgr
 
     nsCOMPtr<nsIDocShellTreeOwner> owner;
     docShell->GetTreeOwner(getter_AddRefs(owner));
 
     nsCOMPtr<nsIXULWindow> ownerXULWindow = do_GetInterface(owner);
     nsCOMPtr<nsIDOMWindow> ownerWindow = do_GetInterface(ownerXULWindow);
     NS_ENSURE_STATE(ownerWindow);
 
+    nsCOMPtr<nsPIDOMWindow> piOwnerWindow = do_QueryInterface(ownerWindow);
+    MOZ_ASSERT(piOwnerWindow);
+
     // Open the dialog.
     nsCOMPtr<nsIDOMWindow> newWindow;
 
-    rv = ownerWindow->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
-                                 NS_LITERAL_STRING("_blank"),
-                                 NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
-                                 array, getter_AddRefs(newWindow));
+    rv = piOwnerWindow->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
+                                   NS_LITERAL_STRING("_blank"),
+                                   NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
+                                   array, getter_AddRefs(newWindow));
   }
 
   return rv;
 }
 
 NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(bool forceClose)
 {
   m_closeProgress = true;
@@ -112,18 +115,21 @@ NS_IMETHODIMP nsPrintProgress::CloseProg
                        (nsresult)forceClose);
 }
 
 NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nullptr;
 
-  if (! m_closeProgress && m_dialog)
-    return m_dialog->GetPrompter(_retval);
+  if (! m_closeProgress && m_dialog) {
+    nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(m_dialog);
+    MOZ_ASSERT(window);
+    return window->GetPrompter(_retval);
+  }
     
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(bool *aProcessCanceledByUser)
 {
   NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
   *aProcessCanceledByUser = m_processCanceled;
--- a/embedding/components/printingui/win/nsPrintProgress.cpp
+++ b/embedding/components/printingui/win/nsPrintProgress.cpp
@@ -115,22 +115,25 @@ NS_IMETHODIMP nsPrintProgress::OpenProgr
 
     nsCOMPtr<nsIDocShellTreeOwner> owner;
     docShell->GetTreeOwner(getter_AddRefs(owner));
 
     nsCOMPtr<nsIXULWindow> ownerXULWindow = do_GetInterface(owner);
     nsCOMPtr<nsIDOMWindow> ownerWindow = do_GetInterface(ownerXULWindow);
     NS_ENSURE_STATE(ownerWindow);
 
+    nsCOMPtr<nsPIDOMWindow> piOwnerWindow = do_QueryInterface(ownerWindow);
+    MOZ_ASSERT(piOwnerWindow);
+
     // Open the dialog.
     nsCOMPtr<nsIDOMWindow> newWindow;
-    rv = ownerWindow->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
-                                 NS_LITERAL_STRING("_blank"),
-                                 NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
-                                 array, getter_AddRefs(newWindow));
+    rv = piOwnerWindow->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
+                                   NS_LITERAL_STRING("_blank"),
+                                   NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
+                                   array, getter_AddRefs(newWindow));
   }
 
   return rv;
 }
 
 NS_IMETHODIMP nsPrintProgress::CloseProgressDialog(bool forceClose)
 {
   m_closeProgress = true;
@@ -139,18 +142,21 @@ NS_IMETHODIMP nsPrintProgress::CloseProg
                        static_cast<nsresult>(forceClose));
 }
 
 NS_IMETHODIMP nsPrintProgress::GetPrompter(nsIPrompt **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
   *_retval = nullptr;
 
-  if (! m_closeProgress && m_dialog)
-    return m_dialog->GetPrompter(_retval);
+  if (! m_closeProgress && m_dialog) {
+    nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(m_dialog);
+    MOZ_ASSERT(window);
+    return window->GetPrompter(_retval);
+  }
     
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP nsPrintProgress::GetProcessCanceledByUser(bool *aProcessCanceledByUser)
 {
   NS_ENSURE_ARG_POINTER(aProcessCanceledByUser);
   *aProcessCanceledByUser = m_processCanceled;
--- a/embedding/components/windowwatcher/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/nsWindowWatcher.cpp
@@ -544,19 +544,17 @@ nsWindowWatcher::OpenWindowInternal(nsID
   }
 
   // no extant window? make a new one.
 
   // If no parent, consider it chrome.
   bool hasChromeParent = true;
   if (aParent) {
     // Check if the parent document has chrome privileges.
-    nsCOMPtr<nsIDOMDocument> domdoc;
-    aParent->GetDocument(getter_AddRefs(domdoc));
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
+    nsIDocument* doc = parentWindow->GetDoc();
     hasChromeParent =
       doc && nsContentUtils::IsChromeDoc(doc) && !openedFromRemoteTab;
   }
 
   // Make sure we call CalculateChromeFlags() *before* we push the
   // callee context onto the context stack so that
   // CalculateChromeFlags() sees the actual caller when doing its
   // security checks.
@@ -625,21 +623,17 @@ nsWindowWatcher::OpenWindowInternal(nsID
     // We're going to either open up a new window ourselves or ask a
     // nsIWindowProvider for one.  In either case, we'll want to set the right
     // name on it.
     windowNeedsName = true;
 
     // If the parent trying to open a new window is sandboxed
     // without 'allow-popups', this is not allowed and we fail here.
     if (aParent) {
-      nsCOMPtr<nsIDOMDocument> domdoc;
-      aParent->GetDocument(getter_AddRefs(domdoc));
-      nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
-
-      if (doc) {
+      if (nsIDocument* doc = parentWindow->GetDoc()) {
         // Save sandbox flags for copying to new browsing context (docShell).
         activeDocsSandboxFlags = doc->GetSandboxFlags();
         if (activeDocsSandboxFlags & SANDBOXED_AUXILIARY_NAVIGATION) {
           return NS_ERROR_DOM_INVALID_ACCESS_ERR;
         }
       }
     }
 
@@ -1432,37 +1426,31 @@ nsWindowWatcher::RemoveEnumerator(nsWatc
 }
 
 nsresult
 nsWindowWatcher::URIfromURL(const char* aURL,
                             nsIDOMWindow* aParent,
                             nsIURI** aURI)
 {
   // Build the URI relative to the entry global.
-  nsCOMPtr<nsIDOMWindow> baseWindow = do_QueryInterface(GetEntryGlobal());
+  nsCOMPtr<nsPIDOMWindow> baseWindow = do_QueryInterface(GetEntryGlobal());
 
   // failing that, build it relative to the parent window, if possible
   if (!baseWindow) {
-    baseWindow = aParent;
+    baseWindow = do_QueryInterface(aParent);
   }
 
   // failing that, use the given URL unmodified. It had better not be relative.
 
   nsIURI* baseURI = nullptr;
 
   // get baseWindow's document URI
   if (baseWindow) {
-    nsCOMPtr<nsIDOMDocument> domDoc;
-    baseWindow->GetDocument(getter_AddRefs(domDoc));
-    if (domDoc) {
-      nsCOMPtr<nsIDocument> doc;
-      doc = do_QueryInterface(domDoc);
-      if (doc) {
-        baseURI = doc->GetDocBaseURI();
-      }
+    if (nsIDocument* doc = baseWindow->GetDoc()) {
+      baseURI = doc->GetDocBaseURI();
     }
   }
 
   // build and return the absolute URI
   return NS_NewURI(aURI, aURL, baseURI);
 }
 
 #define NS_CALCULATE_CHROME_FLAG_FOR(feature, flag)                            \
@@ -1642,20 +1630,16 @@ nsWindowWatcher::CalculateChromeFlags(ns
   /* On mobile we want to ignore the dialog window feature, since the mobile UI
      does not provide any affordance for dialog windows. This does not interfere
      with dialog windows created through openDialog. */
   bool disableDialogFeature = false;
   nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
   branch->GetBoolPref("dom.disable_window_open_dialog_feature",
                       &disableDialogFeature);
 
-  bool isFullScreen = false;
-  if (aParent) {
-    aParent->GetFullScreen(&isFullScreen);
-  }
   if (openedFromContentScript) {
     // If the caller context is content, we do not support the
     // dialog feature. See bug 1095236.
     disableDialogFeature = true;
   }
 
   if (!disableDialogFeature) {
     chromeFlags |= WinHasOption(aFeatures, "dialog", 0, nullptr) ?
@@ -2009,24 +1993,21 @@ nsWindowWatcher::SizeOpenedDocShellItem(
   aDocShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(treeOwner));
   if (!treeOwnerAsWin) { // we'll need this to actually size the docshell
     return;
   }
 
   double openerZoom = 1.0;
   if (aParent) {
-    nsCOMPtr<nsIDOMDocument> openerDoc;
-    aParent->GetDocument(getter_AddRefs(openerDoc));
-    if (openerDoc) {
-      nsCOMPtr<nsIDocument> doc = do_QueryInterface(openerDoc);
-      nsIPresShell* shell = doc->GetShell();
-      if (shell) {
-        nsPresContext* presContext = shell->GetPresContext();
-        if (presContext) {
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(aParent);
+    MOZ_ASSERT(piWindow);
+    if (nsIDocument* doc = piWindow->GetDoc()) {
+      if (nsIPresShell* shell = doc->GetShell()) {
+        if (nsPresContext* presContext = shell->GetPresContext()) {
           openerZoom = presContext->GetFullZoom();
         }
       }
     }
   }
 
   double scale;
   treeOwnerAsWin->GetUnscaledDevicePixelsPerCSSPixel(&scale);
@@ -2222,18 +2203,18 @@ nsWindowWatcher::GetWindowTreeOwner(nsID
 int32_t
 nsWindowWatcher::GetWindowOpenLocation(nsIDOMWindow* aParent,
                                        uint32_t aChromeFlags,
                                        bool aCalledFromJS,
                                        bool aPositionSpecified,
                                        bool aSizeSpecified)
 {
   bool isFullScreen = false;
-  if (aParent) {
-    aParent->GetFullScreen(&isFullScreen);
+  if (nsCOMPtr<nsPIDOMWindow> piParent = do_QueryInterface(aParent)) {
+    isFullScreen = piParent->GetFullScreen();
   }
 
   // Where should we open this?
   int32_t containerPref;
   if (NS_FAILED(Preferences::GetInt("browser.link.open_newwindow",
                                     &containerPref))) {
     // We couldn't read the user preference, so fall back on the default.
     return nsIBrowserDOMWindow::OPEN_NEWTAB;
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -115,18 +115,17 @@ IsFrameId(JSContext* cx, JSObject* obj, 
     MOZ_ASSERT(!js::IsWrapper(obj));
     RootedId id(cx, idArg);
 
     nsGlobalWindow* win = WindowOrNull(obj);
     if (!win) {
         return false;
     }
 
-    nsCOMPtr<nsIDOMWindowCollection> col;
-    win->GetFrames(getter_AddRefs(col));
+    nsCOMPtr<nsIDOMWindowCollection> col = win->GetFrames();
     if (!col) {
         return false;
     }
 
     nsCOMPtr<nsIDOMWindow> domwin;
     if (JSID_IS_INT(id)) {
         col->Item(JSID_TO_INT(id), getter_AddRefs(domwin));
     } else if (JSID_IS_STRING(id)) {
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3772,19 +3772,19 @@ nsDocumentViewer::PrintPreview(nsIPrintS
   }
 
   nsCOMPtr<nsIDocShell> docShell(mContainer);
   if (!docShell || !mDeviceContext) {
     PR_PL(("Can't Print Preview without device context and docshell"));
     return NS_ERROR_FAILURE;
   }
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aChildDOMWin->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aChildDOMWin);
+  MOZ_ASSERT(window);
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
   NS_ENSURE_STATE(doc);
 
   nsAutoPtr<nsPrintEventDispatcher> beforeAndAfterPrint(
     new nsPrintEventDispatcher(doc));
   NS_ENSURE_STATE(!GetIsPrinting());
   if (!mPrintEngine) {
     mPrintEngine = new nsPrintEngine();
 
@@ -4344,19 +4344,19 @@ nsDocumentViewer::OnDonePrinting()
       mPrintEngine = nullptr;
       pe->Destroy();
     }
 
     // We are done printing, now cleanup 
     if (mDeferredWindowClose) {
       mDeferredWindowClose = false;
       if (mContainer) {
-        nsCOMPtr<nsIDOMWindow> win = mContainer->GetWindow();
-        if (win)
+        if (nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mContainer->GetWindow())) {
           win->Close();
+        }
       }
     } else if (mClosingWhilePrinting) {
       if (mDocument) {
         mDocument->SetScriptGlobalObject(nullptr);
         mDocument->Destroy();
         mDocument = nullptr;
       }
       mClosingWhilePrinting = false;
--- a/layout/generic/nsPluginFrame.cpp
+++ b/layout/generic/nsPluginFrame.cpp
@@ -783,20 +783,19 @@ nsPluginFrame::SetScrollVisibility(bool 
   }
 }
 
 mozilla::LayoutDeviceIntPoint
 nsPluginFrame::GetRemoteTabChromeOffset()
 {
   LayoutDeviceIntPoint offset;
   if (XRE_IsContentProcess()) {
-    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetContent()->OwnerDoc()->GetWindow());
+    nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetContent()->OwnerDoc()->GetWindow());
     if (window) {
-      nsCOMPtr<nsIDOMWindow> topWindow;
-      window->GetTop(getter_AddRefs(topWindow));
+      nsCOMPtr<nsPIDOMWindow> topWindow = window->GetTop();
       if (topWindow) {
         dom::TabChild* tc = dom::TabChild::GetFrom(topWindow);
         if (tc) {
           offset += tc->GetChromeDisplacement();
         }
       }
     }
   }
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -785,23 +785,25 @@ nsPrintEngine::PrintPreview(nsIPrintSett
   uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
   if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
       busyFlags != nsIDocShell::BUSY_FLAGS_NONE) {
     CloseProgressDialog(aWebProgressListener);
     FirePrintingErrorEvent(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY);
     return NS_ERROR_FAILURE;
   }
 
-  NS_ENSURE_STATE(aChildDOMWin);
-  nsCOMPtr<nsIDOMDocument> doc;
-  aChildDOMWin->GetDocument(getter_AddRefs(doc));
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aChildDOMWin);
+  NS_ENSURE_STATE(window);
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
   NS_ENSURE_STATE(doc);
+  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
+  MOZ_ASSERT(domDoc);
 
   // Document is not busy -- go ahead with the Print Preview
-  return CommonPrint(true, aPrintSettings, aWebProgressListener, doc);
+  return CommonPrint(true, aPrintSettings, aWebProgressListener, domDoc);
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
 nsPrintEngine::GetIsFramesetDocument(bool *aIsFramesetDocument)
 {
   nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer));
   *aIsFramesetDocument = IsParentAFrameSet(webContainer);
@@ -3106,19 +3108,19 @@ nsPrintEngine::FindPrintObjectByDOMWin(n
   NS_ASSERTION(aPO, "Pointer is null!");
 
   // Often the CurFocused DOMWindow is passed in
   // andit is valid for it to be null, so short circut
   if (!aDOMWin) {
     return nullptr;
   }
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aDOMWin->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aDOMWin);
+
+  nsCOMPtr<nsIDocument> doc = window->GetDoc();
   if (aPO->mDocument && aPO->mDocument->GetOriginalDocument() == doc) {
     return aPO;
   }
 
   int32_t cnt = aPO->mKids.Length();
   for (int32_t i = 0; i < cnt; ++i) {
     nsPrintObject* po = FindPrintObjectByDOMWin(aPO->mKids[i], aDOMWin);
     if (po) {
--- a/layout/svg/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/nsSVGOuterSVGFrame.cpp
@@ -884,24 +884,23 @@ nsSVGOuterSVGFrame::GetCanvasTM()
 // Implementation helpers
 
 bool
 nsSVGOuterSVGFrame::IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame)
 {
   if (!mContent->GetParent()) {
     // Our content is the document element
     nsCOMPtr<nsIDocShell> docShell = PresContext()->GetDocShell();
-    nsCOMPtr<nsIDOMWindow> window;
+    nsCOMPtr<nsPIDOMWindow> window;
     if (docShell) {
       window = docShell->GetWindow();
     }
 
     if (window) {
-      nsCOMPtr<nsIDOMElement> frameElement;
-      window->GetFrameElement(getter_AddRefs(frameElement));
+      nsCOMPtr<nsIDOMElement> frameElement = window->GetFrameElement();
       nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(frameElement);
       if (olc) {
         // Our document is inside an HTML 'object', 'embed' or 'applet' element
         if (aEmbeddingFrame) {
           nsCOMPtr<nsIContent> element = do_QueryInterface(frameElement);
           *aEmbeddingFrame = element->GetPrimaryFrame();
           NS_ASSERTION(*aEmbeddingFrame, "Yikes, no embedding frame!");
         }
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -825,20 +825,20 @@ CheckCaretDrawingState()
   // document and erase its caret.
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (fm) {
     nsCOMPtr<nsIDOMWindow> window;
     fm->GetFocusedWindow(getter_AddRefs(window));
     if (!window)
       return;
 
-    nsCOMPtr<nsIDOMDocument> domDoc;
-    nsCOMPtr<nsIDocument> focusedDoc;
-    window->GetDocument(getter_AddRefs(domDoc));
-    focusedDoc = do_QueryInterface(domDoc);
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
+    MOZ_ASSERT(piWindow);
+
+    nsCOMPtr<nsIDocument> focusedDoc = piWindow->GetDoc();
     if (!focusedDoc)
       return;
 
     nsIPresShell* presShell = focusedDoc->GetShell();
     if (!presShell)
       return;
 
     RefPtr<nsCaret> caret = presShell->GetCaret();
--- a/layout/xul/nsXULTooltipListener.cpp
+++ b/layout/xul/nsXULTooltipListener.cpp
@@ -564,20 +564,17 @@ nsXULTooltipListener::FindTooltip(nsICon
     NS_WARNING("Unable to retrieve the tooltip node document.");
     return NS_ERROR_FAILURE;
   }
   nsPIDOMWindow *window = document->GetWindow();
   if (!window) {
     return NS_OK;
   }
 
-  bool closed;
-  window->GetClosed(&closed);
-
-  if (closed) {
+  if (window->Closed()) {
     return NS_OK;
   }
 
   nsAutoString tooltipText;
   aTarget->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, tooltipText);
   if (!tooltipText.IsEmpty()) {
     // specifying tooltiptext means we will always use the default tooltip
     nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShell());
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -681,23 +681,20 @@ PeerConnectionImpl::Initialize(PeerConne
 #endif // MOZILLA_INTERNAL_API
 
   PRTime timestamp = PR_Now();
   // Ok if we truncate this.
   char temp[128];
 
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   nsAutoCString locationCStr;
-  nsIDOMLocation* location;
-  res = mWindow->GetLocation(&location);
-
-  if (location && NS_SUCCEEDED(res)) {
+
+  if (nsCOMPtr<nsIDOMLocation> location = mWindow->GetLocation()) {
     nsAutoString locationAStr;
     location->ToString(locationAStr);
-    location->Release();
 
     CopyUTF16toUTF8(locationAStr, locationCStr);
 #define HELLO_CLICKER_URL_START "https://hello.firefox.com/"
 #define HELLO_INITIATOR_URL_START "about:loop"
     mIsLoop = (strncmp(HELLO_CLICKER_URL_START, locationCStr.get(),
                        strlen(HELLO_CLICKER_URL_START)) == 0) ||
               (strncmp(HELLO_INITIATOR_URL_START, locationCStr.get(),
                        strlen(HELLO_INITIATOR_URL_START)) == 0);
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -69,20 +69,18 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadin
       outerWindow = aLoadingContext->OwnerDoc()->GetWindow();
     }
 
     if (outerWindow) {
       nsCOMPtr<nsPIDOMWindow> inner = outerWindow->GetCurrentInnerWindow();
       mInnerWindowID = inner ? inner->WindowID() : 0;
       mOuterWindowID = outerWindow->WindowID();
 
-      nsCOMPtr<nsIDOMWindow> parent;
-      outerWindow->GetParent(getter_AddRefs(parent));
-      nsCOMPtr<nsPIDOMWindow> piParent = do_QueryInterface(parent);
-      mParentOuterWindowID = piParent->WindowID();
+      nsCOMPtr<nsPIDOMWindow> parent = outerWindow->GetParent();
+      mParentOuterWindowID = parent->WindowID();
     }
 
     mUpgradeInsecureRequests = aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests();
   }
 
   mOriginAttributes = BasePrincipal::Cast(mLoadingPrincipal)->OriginAttributesRef();
 }
 
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2222,23 +2222,22 @@ void
 nsHttpHandler::TickleWifi(nsIInterfaceRequestor *cb)
 {
     if (!cb || !mWifiTickler)
         return;
 
     // If B2G requires a similar mechanism nsINetworkManager, currently only avail
     // on B2G, contains the necessary information on wifi and gateway
 
-    nsCOMPtr<nsIDOMWindow> domWindow;
-    cb->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
-    if (!domWindow)
+    nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(cb);
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(domWindow);
+    if (!piWindow)
         return;
 
-    nsCOMPtr<nsIDOMNavigator> domNavigator;
-    domWindow->GetNavigator(getter_AddRefs(domNavigator));
+    nsCOMPtr<nsIDOMNavigator> domNavigator = piWindow->GetNavigator();
     nsCOMPtr<nsIMozNavigatorNetwork> networkNavigator =
         do_QueryInterface(domNavigator);
     if (!networkNavigator)
         return;
 
     nsCOMPtr<nsINetworkProperties> networkProperties;
     networkNavigator->GetProperties(getter_AddRefs(networkProperties));
     if (!networkProperties)
--- a/toolkit/components/perfmonitoring/nsPerformanceStats.cpp
+++ b/toolkit/components/perfmonitoring/nsPerformanceStats.cpp
@@ -63,27 +63,27 @@ namespace {
  */
 already_AddRefed<nsPIDOMWindow>
 GetPrivateWindow(JSContext* cx) {
   nsCOMPtr<nsPIDOMWindow> win = xpc::CurrentWindowOrNull(cx);
   if (!win) {
     return nullptr;
   }
 
-  nsCOMPtr<nsIDOMWindow> top;
-  nsresult rv = win->GetTop(getter_AddRefs(top));
-  if (!top || NS_FAILED(rv)) {
+  win = win->GetOuterWindow();
+  if (!win) {
     return nullptr;
   }
 
-  nsCOMPtr<nsPIDOMWindow> ptop = do_QueryInterface(top);
-  if (!ptop) {
+  nsCOMPtr<nsPIDOMWindow> top = win->GetTop();
+  if (!top) {
     return nullptr;
   }
-  return ptop.forget();
+
+  return top.forget();
 }
 
 bool
 URLForGlobal(JSContext* cx, JS::Handle<JSObject*> global, nsAString& url) {
   nsCOMPtr<nsIPrincipal> principal = nsContentUtils::ObjectPrincipal(global);
   if (!principal) {
     return false;
   }
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -96,18 +96,18 @@ nsFormFillController::~nsFormFillControl
     mFocusedInput = nullptr;
   }
   PwmgrInputsEnumData ed(this, nullptr);
   mPwmgrInputs.Enumerate(RemoveForDocumentEnumerator, &ed);
 
   // Remove ourselves as a focus listener from all cached docShells
   uint32_t count = mDocShells.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    nsCOMPtr<nsIDOMWindow> domWindow = GetWindowForDocShell(mDocShells[i]);
-    RemoveWindowListeners(domWindow);
+    nsCOMPtr<nsPIDOMWindow> window = GetWindowForDocShell(mDocShells[i]);
+    RemoveWindowListeners(window);
   }
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsIMutationObserver
 //
 
 void
@@ -236,32 +236,32 @@ NS_IMETHODIMP
 nsFormFillController::AttachToBrowser(nsIDocShell *aDocShell, nsIAutoCompletePopup *aPopup)
 {
   NS_ENSURE_TRUE(aDocShell && aPopup, NS_ERROR_ILLEGAL_VALUE);
 
   mDocShells.AppendElement(aDocShell);
   mPopups.AppendElement(aPopup);
 
   // Listen for focus events on the domWindow of the docShell
-  nsCOMPtr<nsIDOMWindow> domWindow = GetWindowForDocShell(aDocShell);
-  AddWindowListeners(domWindow);
+  nsCOMPtr<nsPIDOMWindow> window = GetWindowForDocShell(aDocShell);
+  AddWindowListeners(window);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::DetachFromBrowser(nsIDocShell *aDocShell)
 {
   int32_t index = GetIndexOfDocShell(aDocShell);
   NS_ENSURE_TRUE(index >= 0, NS_ERROR_FAILURE);
 
   // Stop listening for focus events on the domWindow of the docShell
-  nsCOMPtr<nsIDOMWindow> domWindow =
+  nsCOMPtr<nsPIDOMWindow> window =
     GetWindowForDocShell(mDocShells.SafeElementAt(index));
-  RemoveWindowListeners(domWindow);
+  RemoveWindowListeners(window);
 
   mDocShells.RemoveElementAt(index);
   mPopups.RemoveElementAt(index);
 
   return NS_OK;
 }
 
 
@@ -1075,25 +1075,22 @@ nsFormFillController::MouseDown(nsIDOMEv
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////
 //// nsFormFillController
 
 void
-nsFormFillController::AddWindowListeners(nsIDOMWindow *aWindow)
+nsFormFillController::AddWindowListeners(nsPIDOMWindow *aWindow)
 {
   if (!aWindow)
     return;
 
-  nsCOMPtr<nsPIDOMWindow> privateDOMWindow(do_QueryInterface(aWindow));
-  EventTarget* target = nullptr;
-  if (privateDOMWindow)
-    target = privateDOMWindow->GetChromeEventHandler();
+  EventTarget* target = aWindow->GetChromeEventHandler();
 
   if (!target)
     return;
 
   target->AddEventListener(NS_LITERAL_STRING("focus"), this,
                            true, false);
   target->AddEventListener(NS_LITERAL_STRING("blur"), this,
                            true, false);
@@ -1111,33 +1108,28 @@ nsFormFillController::AddWindowListeners
   target->AddEventListener(NS_LITERAL_STRING("contextmenu"), this,
                            true, false);
 
   // Note that any additional listeners added should ensure that they ignore
   // untrusted events, which might be sent by content that's up to no good.
 }
 
 void
-nsFormFillController::RemoveWindowListeners(nsIDOMWindow *aWindow)
+nsFormFillController::RemoveWindowListeners(nsPIDOMWindow *aWindow)
 {
   if (!aWindow)
     return;
 
   StopControllingInput();
 
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  aWindow->GetDocument(getter_AddRefs(domDoc));
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
+  nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   PwmgrInputsEnumData ed(this, doc);
   mPwmgrInputs.Enumerate(RemoveForDocumentEnumerator, &ed);
 
-  nsCOMPtr<nsPIDOMWindow> privateDOMWindow(do_QueryInterface(aWindow));
-  EventTarget* target = nullptr;
-  if (privateDOMWindow)
-    target = privateDOMWindow->GetChromeEventHandler();
+  EventTarget* target = aWindow->GetChromeEventHandler();
 
   if (!target)
     return;
 
   target->RemoveEventListener(NS_LITERAL_STRING("focus"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("blur"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("pagehide"), this, true);
   target->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
@@ -1222,17 +1214,17 @@ nsFormFillController::GetDocShellForInpu
   NS_ENSURE_TRUE(node, nullptr);
 
   nsCOMPtr<nsPIDOMWindow> win = node->OwnerDoc()->GetWindow();
   NS_ENSURE_TRUE(win, nullptr);
 
   return win->GetDocShell();
 }
 
-nsIDOMWindow *
+nsPIDOMWindow *
 nsFormFillController::GetWindowForDocShell(nsIDocShell *aDocShell)
 {
   nsCOMPtr<nsIContentViewer> contentViewer;
   aDocShell->GetContentViewer(getter_AddRefs(contentViewer));
   NS_ENSURE_TRUE(contentViewer, nullptr);
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
--- a/toolkit/components/satchel/nsFormFillController.h
+++ b/toolkit/components/satchel/nsFormFillController.h
@@ -11,30 +11,30 @@
 #include "nsIAutoCompleteSearch.h"
 #include "nsIAutoCompleteController.h"
 #include "nsIAutoCompletePopup.h"
 #include "nsIFormAutoComplete.h"
 #include "nsIDOMEventListener.h"
 #include "nsCOMPtr.h"
 #include "nsDataHashtable.h"
 #include "nsIDocShell.h"
-#include "nsIDOMWindow.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsILoginManager.h"
 #include "nsIMutationObserver.h"
 #include "nsTArray.h"
 #include "nsCycleCollectionParticipant.h"
 
 // X.h defines KeyPress
 #ifdef KeyPress
 #undef KeyPress
 #endif
 
 class nsFormHistory;
 class nsINode;
+class nsPIDOMWindow;
 
 class nsFormFillController final : public nsIFormFillController,
                                    public nsIAutoCompleteInput,
                                    public nsIAutoCompleteSearch,
                                    public nsIDOMEventListener,
                                    public nsIFormAutoCompleteObserver,
                                    public nsIMutationObserver
 {
@@ -53,18 +53,18 @@ public:
   nsresult KeyPress(nsIDOMEvent* aKeyEvent);
   nsresult MouseDown(nsIDOMEvent* aMouseEvent);
 
   nsFormFillController();
 
 protected:
   virtual ~nsFormFillController();
 
-  void AddWindowListeners(nsIDOMWindow *aWindow);
-  void RemoveWindowListeners(nsIDOMWindow *aWindow);
+  void AddWindowListeners(nsPIDOMWindow *aWindow);
+  void RemoveWindowListeners(nsPIDOMWindow *aWindow);
 
   void AddKeyListener(nsINode* aInput);
   void RemoveKeyListener();
 
   void StartControllingInput(nsIDOMHTMLInputElement *aInput);
   void StopControllingInput();
   /**
    * Checks that aElement is a type of element we want to fill, then calls
@@ -74,17 +74,17 @@ protected:
 
   nsresult PerformInputListAutoComplete(const nsAString& aSearch,
                                         nsIAutoCompleteResult** aResult);
 
   void RevalidateDataList();
   bool RowMatch(nsFormHistory *aHistory, uint32_t aIndex, const nsAString &aInputName, const nsAString &aInputValue);
 
   inline nsIDocShell *GetDocShellForInput(nsIDOMHTMLInputElement *aInput);
-  inline nsIDOMWindow *GetWindowForDocShell(nsIDocShell *aDocShell);
+  inline nsPIDOMWindow *GetWindowForDocShell(nsIDocShell *aDocShell);
   inline int32_t GetIndexOfDocShell(nsIDocShell *aDocShell);
 
   void MaybeRemoveMutationObserver(nsINode* aNode);
 
   static PLDHashOperator RemoveForDocumentEnumerator(const nsINode* aKey,
                                                      bool& aEntry,
                                                      void* aUserData);
   bool IsEventTrusted(nsIDOMEvent *aEvent);
--- a/toolkit/components/startup/nsAppStartup.cpp
+++ b/toolkit/components/startup/nsAppStartup.cpp
@@ -428,21 +428,19 @@ nsAppStartup::Quit(uint32_t aMode)
         if (windowEnumerator) {
           bool more;
           while (windowEnumerator->HasMoreElements(&more), more) {
             /* we can't quit immediately. we'll try again as the last window
                finally closes. */
             ferocity = eAttemptQuit;
             nsCOMPtr<nsISupports> window;
             windowEnumerator->GetNext(getter_AddRefs(window));
-            nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(window);
+            nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(window);
             if (domWindow) {
-              bool closed = false;
-              domWindow->GetClosed(&closed);
-              if (!closed) {
+              if (!domWindow->Closed()) {
                 rv = NS_ERROR_FAILURE;
                 break;
               }
             }
           }
         }
       }
     }
--- a/toolkit/xre/ProfileReset.cpp
+++ b/toolkit/xre/ProfileReset.cpp
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIAppStartup.h"
-#include "nsIDOMWindow.h"
 #include "nsIFile.h"
 #include "nsIStringBundle.h"
 #include "nsIToolkitProfile.h"
 #include "nsIWindowWatcher.h"
 
 #include "ProfileReset.h"
 
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
+#include "nsPIDOMWindow.h"
 #include "nsPrintfCString.h"
 #include "nsToolkitCompsCID.h"
 #include "nsXPCOMCIDInternal.h"
 #include "nsXREAppData.h"
 
 #include "mozilla/Services.h"
 #include "prtime.h"
 
@@ -159,16 +159,17 @@ ProfileResetCleanup(nsIToolkitProfile* a
       NS_ProcessNextEvent(thread);
     }
   } else {
     gProfileResetCleanupCompleted = true;
     NS_WARNING("Cleanup thread creation failed");
     return rv;
   }
   // Close the progress window now that the cleanup thread is done.
-  progressWindow->Close();
+  nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(progressWindow);
+  piWindow->Close();
 
   // Delete the old profile from profiles.ini. The folder was already deleted by the thread above.
   rv = aOldProfile->Remove(false);
   if (NS_FAILED(rv)) NS_WARNING("Could not remove the profile");
 
   return rv;
 }
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -77,24 +77,25 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
     ]
 
 UNIFIED_SOURCES += [
     'CreateAppData.cpp',
     'nsConsoleWriter.cpp',
     'nsNativeAppSupportBase.cpp',
     'nsSigHandlers.cpp',
     'nsXREDirProvider.cpp',
-    'ProfileReset.cpp',
 ]
 
-# nsAppRunner.cpp cannot be built in unified mode because it pulls in OS X system headers.
+# nsAppRunner.cpp and ProfileReset.cpp cannot be built in unified mode because
+# they pull in OS X system headers.
 # nsEmbedFunctions.cpp cannot be built in unified mode because it pulls in X11 headers.
 SOURCES += [
     'nsAppRunner.cpp',
     'nsEmbedFunctions.cpp',
+    'ProfileReset.cpp',
 ]
 
 if CONFIG['MOZ_GL_DEFAULT_PROVIDER'] == 'GLX':
     UNIFIED_SOURCES += [
         'glxtest.cpp',
     ]
 
 if CONFIG['MOZ_INSTRUMENT_EVENT_LOOP']:
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -77,17 +77,18 @@ activateWindow( nsIDOMWindow *win ) {
         // Restore the window if it is minimized.
         if ( ::IsIconic( hwnd ) ) {
             ::ShowWindow( hwnd, SW_RESTORE );
         }
         // Use the OS call, if possible.
         ::SetForegroundWindow( hwnd );
     } else {
         // Use internal method.
-        win->Focus();
+        nsCOMPtr<nsPIDOMWindow> piWin = do_QueryInterface(win);
+        piWin->Focus();
     }
 }
 
 
 #ifdef DEBUG_law
 #undef MOZ_DEBUG_DDE
 #define MOZ_DEBUG_DDE 1
 #endif
@@ -1016,18 +1017,17 @@ nsNativeAppSupportWin::HandleDDENotifica
 
                         // Get content window.
                         nsCOMPtr<nsIDOMWindow> internalContent_ = nsGlobalWindow::Cast(piNavWin)->GetContent();
                         nsCOMPtr<nsPIDOMWindow> internalContent = do_QueryInterface(internalContent_);
                         if ( !internalContent ) {
                             break;
                         }
                         // Get location.
-                        nsCOMPtr<nsIDOMLocation> location;
-                        internalContent->GetLocation( getter_AddRefs( location ) );
+                        nsCOMPtr<nsIDOMLocation> location = internalContent->GetLocation();
                         if ( !location ) {
                             break;
                         }
                         // Get href for URL.
                         nsAutoString url;
                         if ( NS_FAILED( location->GetHref( url ) ) ) {
                             break;
                         }
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -900,20 +900,17 @@ nsDocLoader::GetIsTopLevel(bool *aResult
   *aResult = false;
 
   nsCOMPtr<nsIDOMWindow> window;
   GetDOMWindow(getter_AddRefs(window));
   if (window) {
     nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);
     NS_ENSURE_STATE(piwindow);
 
-    nsCOMPtr<nsIDOMWindow> topWindow;
-    nsresult rv = piwindow->GetTop(getter_AddRefs(topWindow));
-    NS_ENSURE_SUCCESS(rv, rv);
-
+    nsCOMPtr<nsPIDOMWindow> topWindow = piwindow->GetTop();
     *aResult = piwindow == topWindow;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocLoader::GetIsLoadingDocument(bool *aIsLoadingDocument)
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -2547,27 +2547,25 @@ bool nsExternalAppHandler::GetNeverAskFl
   prefCString.BeginReading(start);
   prefCString.EndReading(end);
   return !CaseInsensitiveFindInReadable(nsDependentCString(aContentType),
                                         start, end);
 }
 
 nsresult nsExternalAppHandler::MaybeCloseWindow()
 {
-  nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mContentContext);
+  nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mContentContext);
   NS_ENSURE_STATE(window);
 
   if (mShouldCloseWindow) {
     // Reset the window context to the opener window so that the dependent
     // dialogs have a parent
-    nsCOMPtr<nsIDOMWindow> opener;
-    window->GetOpener(getter_AddRefs(opener));
-
-    bool isClosed;
-    if (opener && NS_SUCCEEDED(opener->GetClosed(&isClosed)) && !isClosed) {
+    nsCOMPtr<nsPIDOMWindow> opener = window->GetOpener();
+
+    if (opener && !opener->Closed()) {
       mContentContext = do_GetInterface(opener);
 
       // Now close the old window.  Do it on a timer so that we don't run
       // into issues trying to close the window before it has fully opened.
       NS_ASSERTION(!mTimer, "mTimer was already initialized once!");
       mTimer = do_CreateInstance("@mozilla.org/timer;1");
       if (!mTimer) {
         return NS_ERROR_FAILURE;
@@ -2581,17 +2579,18 @@ nsresult nsExternalAppHandler::MaybeClos
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsExternalAppHandler::Notify(nsITimer* timer)
 {
   NS_ASSERTION(mWindowToClose, "No window to close after timer fired");
 
-  mWindowToClose->Close();
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mWindowToClose);
+  window->Close();
   mWindowToClose = nullptr;
   mTimer = nullptr;
 
   return NS_OK;
 }
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // The following section contains our nsIMIMEService implementation and related methods.
 //
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -196,18 +196,20 @@ nsOfflineCachePendingUpdate::OnStateChan
     if (!(progressStateFlags & STATE_STOP)) {
         return NS_OK;
     }
 
     nsCOMPtr<nsIDOMWindow> window;
     aWebProgress->GetDOMWindow(getter_AddRefs(window));
     if (!window) return NS_OK;
 
-    nsCOMPtr<nsIDOMDocument> progressDoc;
-    window->GetDocument(getter_AddRefs(progressDoc));
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(window);
+    MOZ_ASSERT(piWindow);
+
+    nsCOMPtr<nsIDocument> progressDoc = piWindow->GetDoc();
     if (!progressDoc) return NS_OK;
 
     if (!SameCOMIdentity(progressDoc, updateDoc)) {
         return NS_OK;
     }
 
     LOG(("nsOfflineCachePendingUpdate::OnStateChange [%p, doc=%p]",
          this, progressDoc.get()));
@@ -536,22 +538,22 @@ nsOfflineCacheUpdateService::Schedule(ns
         update = new OfflineCacheUpdateChild(aWindow);
     }
     else {
         update = new OfflineCacheUpdateGlue();
     }
 
     nsresult rv;
 
-    if (aWindow) {
+    if (nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow)) {
       // Ensure there is window.applicationCache object that is
       // responsible for association of the new applicationCache
       // with the corresponding document.  Just ignore the result.
-      nsCOMPtr<nsIDOMOfflineResourceList> appCacheWindowObject;
-      aWindow->GetApplicationCache(getter_AddRefs(appCacheWindowObject));
+      nsCOMPtr<nsIDOMOfflineResourceList> appCacheWindowObject =
+          window->GetApplicationCache();
     }
 
     rv = update->Init(aManifestURI, aDocumentURI, aLoadingPrincipal, aDocument,
                       aCustomProfileDir, aAppID, aInBrowser);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = update->Schedule();
     NS_ENSURE_SUCCESS(rv, rv);
--- a/widget/cocoa/moz.build
+++ b/widget/cocoa/moz.build
@@ -82,16 +82,17 @@ if CONFIG['GNU_CXX']:
 
 # XXX: We should fix these warnings.
 ALLOW_COMPILER_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'
 LOCAL_INCLUDES += [
     '/layout/forms',
     '/layout/generic',
+    '/layout/style',
     '/layout/xul',
     '/widget',
 ]
 
 RESOURCE_FILES.cursors += [
     'cursors/arrowN.png',
     'cursors/arrowN@2x.png',
     'cursors/arrowS.png',
--- a/widget/cocoa/nsMenuItemIconX.mm
+++ b/widget/cocoa/nsMenuItemIconX.mm
@@ -21,32 +21,33 @@
 
 #include "nsMenuItemIconX.h"
 #include "nsObjCExceptions.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsNameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMElement.h"
-#include "nsIDOMCSSStyleDeclaration.h"
+#include "nsICSSDeclaration.h"
 #include "nsIDOMCSSValue.h"
 #include "nsIDOMCSSPrimitiveValue.h"
 #include "nsIDOMRect.h"
 #include "nsThreadUtils.h"
 #include "nsToolkit.h"
 #include "nsNetUtil.h"
 #include "imgLoader.h"
 #include "imgRequestProxy.h"
 #include "nsMenuItemX.h"
 #include "gfxPlatform.h"
 #include "imgIContainer.h"
 #include "nsCocoaUtils.h"
 #include "nsContentUtils.h"
 #include "nsIContentPolicy.h"
 
+using mozilla::dom::Element;
 using mozilla::gfx::SourceSurface;
 
 static const uint32_t kIconWidth = 16;
 static const uint32_t kIconHeight = 16;
 
 typedef NS_STDCALL_FUNCPROTO(nsresult, GetRectSideMethod, nsIDOMRect,
                              GetBottom, (nsIDOMCSSPrimitiveValue**));
 
@@ -162,38 +163,43 @@ nsMenuItemIconX::GetIconURI(nsIURI** aIc
   // First, look at the content node's "image" attribute.
   nsAutoString imageURIString;
   bool hasImageAttr = mContent->GetAttr(kNameSpaceID_None,
                                         nsGkAtoms::image,
                                         imageURIString);
 
   nsresult rv;
   nsCOMPtr<nsIDOMCSSValue> cssValue;
-  nsCOMPtr<nsIDOMCSSStyleDeclaration> cssStyleDecl;
+  nsCOMPtr<nsICSSDeclaration> cssStyleDecl;
   nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue;
   uint16_t primitiveType;
   if (!hasImageAttr) {
     // If the content node has no "image" attribute, get the
     // "list-style-image" property from CSS.
     nsCOMPtr<nsIDocument> document = mContent->GetComposedDoc();
     if (!document)
       return NS_ERROR_FAILURE;
 
     nsCOMPtr<nsPIDOMWindow> window = document->GetWindow();
     if (!window)
       return NS_ERROR_FAILURE;
 
-    nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mContent);
+    window = window->GetCurrentInnerWindow();
+    if (!window)
+      return NS_ERROR_FAILURE;
+
+    nsCOMPtr<Element> domElement = do_QueryInterface(mContent);
     if (!domElement)
       return NS_ERROR_FAILURE;
 
-    rv = window->GetComputedStyle(domElement, EmptyString(),
-                                  getter_AddRefs(cssStyleDecl));
-    if (NS_FAILED(rv))
-      return rv;
+    ErrorResult dummy;
+    cssStyleDecl = window->GetComputedStyle(*domElement, EmptyString(), dummy);
+    dummy.SuppressException();
+    if (!cssStyleDecl)
+      return NS_ERROR_FAILURE;
 
     NS_NAMED_LITERAL_STRING(listStyleImage, "list-style-image");
     rv = cssStyleDecl->GetPropertyCSSValue(listStyleImage,
                                            getter_AddRefs(cssValue));
     if (NS_FAILED(rv)) return rv;
 
     primitiveValue = do_QueryInterface(cssValue);
     if (!primitiveValue) return NS_ERROR_FAILURE;
--- a/xpfe/appshell/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/nsContentTreeOwner.cpp
@@ -1131,17 +1131,17 @@ nsSiteWindow::Blur(void)
   // change focus to the window we just found
   if (xulWindow) {
     nsCOMPtr<nsIDocShell> docshell;
     xulWindow->GetDocShell(getter_AddRefs(docshell));
     if (!docshell) {
       return NS_OK;
     }
 
-    nsCOMPtr<nsIDOMWindow> domWindow(docshell->GetWindow());
+    nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(docshell->GetWindow());
     if (domWindow)
       domWindow->Focus();
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSiteWindow::GetVisibility(bool *aVisibility)
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1177,19 +1177,18 @@ bool nsXULWindow::LoadSizeFromXUL()
     specHeight = std::max(temp, 100);
     gotSize = true;
   }
 
   if (gotSize) {
     // constrain to screen size
     nsCOMPtr<nsIDOMWindow> domWindow;
     GetWindowDOMWindow(getter_AddRefs(domWindow));
-    if (domWindow) {
-      nsCOMPtr<nsIDOMScreen> screen;
-      domWindow->GetScreen(getter_AddRefs(screen));
+    if (nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(domWindow)) {
+      nsCOMPtr<nsIDOMScreen> screen = window->GetScreen();
       if (screen) {
         int32_t screenWidth;
         int32_t screenHeight;
         screen->GetAvailWidth(&screenWidth);
         screen->GetAvailHeight(&screenHeight);
         if (specWidth > screenWidth)
           specWidth = screenWidth;
         if (specHeight > screenHeight)
@@ -1263,17 +1262,18 @@ bool nsXULWindow::LoadMiscPersistentAttr
       ErrorResult rv;
       windowElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
     }
   }
 
   if (sizeMode == nsSizeMode_Fullscreen) {
     nsCOMPtr<nsIDOMWindow> ourWindow;
     GetWindowDOMWindow(getter_AddRefs(ourWindow));
-    ourWindow->SetFullScreen(true);
+    nsCOMPtr<nsPIDOMWindow> piWindow = do_QueryInterface(ourWindow);
+    piWindow->SetFullScreen(true);
   } else {
     mWindow->SetSizeMode(sizeMode);
   }
   gotState = true;
 
   // zlevel
   windowElement->GetAttribute(ZLEVEL_ATTRIBUTE, stateString);
   if (!stateString.IsEmpty()) {
@@ -1478,17 +1478,17 @@ NS_IMETHODIMP nsXULWindow::SavePersisten
   docShellElement->GetAttribute(PERSIST_ATTRIBUTE, persistString);
   if (persistString.IsEmpty()) { // quick check which sometimes helps
     mPersistentAttributesDirty = 0;
     return NS_OK;
   }
 
   bool isFullscreen = false;
   if (nsPIDOMWindow* domWindow = mDocShell->GetWindow()) {
-    domWindow->GetFullScreen(&isFullscreen);
+    isFullscreen = domWindow->GetFullScreen();
   }
 
   // get our size, position and mode to persist
   nsIntRect rect;
   bool gotRestoredBounds = NS_SUCCEEDED(mWindow->GetRestoredBounds(rect));
 
   CSSToLayoutDeviceScale scale = mWindow->GetDefaultScale();