Bug 1463015: Part 3 - Remove no-op nsPIDOMWindow(Outer|Inner)::From calls. r?nika draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 20 May 2018 15:17:51 -0700
changeset 797547 c0b936e8ce0ecbf34244255ced8762c38f545924
parent 797546 3a780c628a2f4df31094b86e323e414d777e52d6
child 797548 f5edcee36403291354f5f4c3d0e71649e795218b
push id110512
push usermaglione.k@gmail.com
push dateSun, 20 May 2018 22:52:08 +0000
reviewersnika
bugs1463015
milestone62.0a1
Bug 1463015: Part 3 - Remove no-op nsPIDOMWindow(Outer|Inner)::From calls. r?nika MozReview-Commit-ID: 5ihZhyn1u3g
accessible/base/DocManager.cpp
accessible/base/Logging.cpp
chrome/nsChromeRegistry.cpp
docshell/base/nsDocShellTreeOwner.cpp
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/AudioChannelService.cpp
dom/base/DOMRequest.cpp
dom/base/TextInputProcessor.cpp
dom/base/ThirdPartyUtil.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsWindowMemoryReporter.cpp
dom/clients/manager/ClientOpenWindowUtils.cpp
dom/commandhandler/nsCommandManager.cpp
dom/events/EventStateManager.cpp
dom/html/nsGenericHTMLFrameElement.cpp
dom/ipc/ContentChild.cpp
dom/ipc/TabChild.cpp
dom/media/webrtc/MediaEngineTabVideoSource.cpp
dom/plugins/ipc/PluginHangUIParent.cpp
dom/power/PowerManagerService.cpp
dom/storage/LocalStorageManager.cpp
dom/storage/SessionStorageManager.cpp
dom/xbl/nsXBLWindowKeyHandler.cpp
dom/xul/nsXULCommandDispatcher.cpp
editor/composer/nsEditingSession.cpp
extensions/cookie/nsPermissionManager.cpp
js/xpconnect/src/XPCConvert.cpp
layout/printing/nsPrintJob.cpp
layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
layout/xul/nsXULPopupManager.cpp
netwerk/base/nsChannelClassifier.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
security/manager/ssl/nsSecureBrowserUIImpl.cpp
toolkit/components/alerts/nsXULAlerts.cpp
toolkit/components/printingui/ipc/nsPrintingProxy.cpp
toolkit/components/printingui/nsPrintProgress.cpp
toolkit/components/printingui/nsPrintingPromptService.cpp
toolkit/components/remote/nsGTKRemoteService.cpp
toolkit/components/sessionstore/nsSessionStoreUtils.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
toolkit/components/windowwatcher/nsWindowWatcher.cpp
toolkit/xre/ProfileReset.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
uriloader/base/nsDocLoader.cpp
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
widget/android/AndroidBridge.cpp
widget/android/fennec/ThumbnailHelper.h
widget/android/nsWindow.cpp
widget/gtk/TaskbarProgress.cpp
widget/gtk/nsApplicationChooser.cpp
widget/gtk/nsColorPicker.cpp
widget/nsBaseFilePicker.cpp
widget/nsFilePickerProxy.cpp
widget/windows/WinTaskbar.cpp
widget/windows/nsColorPicker.cpp
widget/windows/nsPrintDialogWin.cpp
xpcom/base/nsMemoryReporterManager.cpp
xpcom/io/nsLocalFileWin.cpp
xpfe/appshell/nsContentTreeOwner.cpp
xpfe/appshell/nsWebShellWindow.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/accessible/base/DocManager.cpp
+++ b/accessible/base/DocManager.cpp
@@ -241,20 +241,17 @@ DocManager::OnStateChange(nsIWebProgress
   if (nsAccessibilityService::IsShutdown() || !aWebProgress ||
       (aStateFlags & (STATE_START | STATE_STOP)) == 0)
     return NS_OK;
 
   nsCOMPtr<nsPIDOMWindowOuter> DOMWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
   NS_ENSURE_STATE(DOMWindow);
 
-  nsPIDOMWindowOuter* piWindow = nsPIDOMWindowOuter::From(DOMWindow);
-  MOZ_ASSERT(piWindow);
-
-  nsCOMPtr<nsIDocument> document = piWindow->GetDoc();
+  nsCOMPtr<nsIDocument> document = DOMWindow->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/base/Logging.cpp
+++ b/accessible/base/Logging.cpp
@@ -395,19 +395,18 @@ static const char* sDocEventTitle = "DOC
 static const char* sFocusTitle = "FOCUS";
 
 void
 logging::DocLoad(const char* aMsg, nsIWebProgress* aWebProgress,
                  nsIRequest* aRequest, uint32_t aStateFlags)
 {
   MsgBegin(sDocLoadTitle, "%s", aMsg);
 
-  nsCOMPtr<nsPIDOMWindowOuter> DOMWindow;
-  aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
-  nsPIDOMWindowOuter* window = nsPIDOMWindowOuter::From(DOMWindow);
+  nsCOMPtr<nsPIDOMWindowOuter> window;
+  aWebProgress->GetDOMWindow(getter_AddRefs(window));
   if (!window) {
     MsgEnd();
     return;
   }
 
   nsCOMPtr<nsIDocument> documentNode = window->GetDoc();
   if (!documentNode) {
     MsgEnd();
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -383,18 +383,17 @@ nsresult nsChromeRegistry::RefreshWindow
   // Deal with our subframes first.
   nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
   uint32_t length;
   frames->GetLength(&length);
   uint32_t j;
   for (j = 0; j < length; j++) {
     nsCOMPtr<nsPIDOMWindowOuter> childWin;
     frames->Item(j, getter_AddRefs(childWin));
-    nsCOMPtr<nsPIDOMWindowOuter> piWindow = nsPIDOMWindowOuter::From(childWin);
-    RefreshWindow(piWindow);
+    RefreshWindow(childWin);
   }
 
   nsresult rv;
   // Get the document.
   nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
   if (!document)
     return NS_OK;
 
--- a/docshell/base/nsDocShellTreeOwner.cpp
+++ b/docshell/base/nsDocShellTreeOwner.cpp
@@ -66,23 +66,22 @@ using namespace mozilla::dom;
 // a |EventTarget| via the window root and chrome event handler.
 static nsresult
 GetDOMEventTarget(nsWebBrowser* aInBrowser, EventTarget** aTarget)
 {
   if (!aInBrowser) {
     return NS_ERROR_INVALID_POINTER;
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> domWindow;
-  aInBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
-  if (!domWindow) {
+  nsCOMPtr<nsPIDOMWindowOuter> outerWindow;
+  aInBrowser->GetContentDOMWindow(getter_AddRefs(outerWindow));
+  if (!outerWindow) {
     return NS_ERROR_FAILURE;
   }
 
-  auto* outerWindow = nsPIDOMWindowOuter::From(domWindow);
   nsPIDOMWindowOuter* rootWindow = outerWindow->GetPrivateRoot();
   NS_ENSURE_TRUE(rootWindow, NS_ERROR_FAILURE);
   nsCOMPtr<EventTarget> target = rootWindow->GetChromeEventHandler();
   NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);
   target.forget(aTarget);
 
   return NS_OK;
 }
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -55,26 +55,24 @@ AudioChannelAgent::Shutdown()
     NotifyStoppedPlaying();
   }
 }
 
 NS_IMETHODIMP
 AudioChannelAgent::Init(nsPIDOMWindowInner* aWindow,
                         nsIAudioChannelAgentCallback *aCallback)
 {
-  return InitInternal(nsPIDOMWindowInner::From(aWindow),
-                      aCallback, /* useWeakRef = */ false);
+  return InitInternal(aWindow, aCallback, /* useWeakRef = */ false);
 }
 
 NS_IMETHODIMP
 AudioChannelAgent::InitWithWeakCallback(nsPIDOMWindowInner* aWindow,
                                         nsIAudioChannelAgentCallback *aCallback)
 {
-  return InitInternal(nsPIDOMWindowInner::From(aWindow),
-                      aCallback, /* useWeakRef = */ true);
+  return InitInternal(aWindow, aCallback, /* useWeakRef = */ true);
 }
 
 nsresult
 AudioChannelAgent::FindCorrectWindow(nsPIDOMWindowInner* aWindow)
 {
   mWindow = aWindow->GetScriptableTop();
   if (NS_WARN_IF(!mWindow)) {
     return NS_OK;
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -553,17 +553,17 @@ AudioChannelService::GetWindowData(uint6
   return nullptr;
 }
 
 bool
 AudioChannelService::IsWindowActive(nsPIDOMWindowOuter* aWindow)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  auto* window = nsPIDOMWindowOuter::From(aWindow)->GetScriptableTop();
+  auto* window = aWindow->GetScriptableTop();
   if (!window) {
     return false;
   }
 
   AudioChannelWindow* winData = GetWindowData(window->WindowID());
   if (!winData) {
     return false;
   }
--- a/dom/base/DOMRequest.cpp
+++ b/dom/base/DOMRequest.cpp
@@ -203,18 +203,17 @@ DOMRequest::Then(JSContext* aCx, AnyCall
 NS_IMPL_ISUPPORTS(DOMRequestService, nsIDOMRequestService)
 
 NS_IMETHODIMP
 DOMRequestService::CreateRequest(nsPIDOMWindowInner* aWindow,
                                  DOMRequest** aRequest)
 {
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_STATE(aWindow);
-  auto* win = nsPIDOMWindowInner::From(aWindow);
-  RefPtr<DOMRequest> req = new DOMRequest(win);
+  RefPtr<DOMRequest> req = new DOMRequest(aWindow);
   req.forget(aRequest);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DOMRequestService::FireSuccess(DOMRequest* aRequest,
                                JS::Handle<JS::Value> aResult)
--- a/dom/base/TextInputProcessor.cpp
+++ b/dom/base/TextInputProcessor.cpp
@@ -364,21 +364,17 @@ TextInputProcessor::BeginInputTransactio
                       nsITextInputProcessorCallback* aCallback,
                       bool aForTests,
                       bool& aSucceeded)
 {
   aSucceeded = false;
   if (NS_WARN_IF(!aWindow)) {
     return NS_ERROR_INVALID_ARG;
   }
-  nsCOMPtr<nsPIDOMWindowInner> pWindow = nsPIDOMWindowInner::From(aWindow);
-  if (NS_WARN_IF(!pWindow)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-  nsCOMPtr<nsIDocShell> docShell(pWindow->GetDocShell());
+  nsCOMPtr<nsIDocShell> docShell(aWindow->GetDocShell());
   if (NS_WARN_IF(!docShell)) {
     return NS_ERROR_FAILURE;
   }
   RefPtr<nsPresContext> presContext;
   nsresult rv = docShell->GetPresContext(getter_AddRefs(presContext));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
--- a/dom/base/ThirdPartyUtil.cpp
+++ b/dom/base/ThirdPartyUtil.cpp
@@ -137,17 +137,17 @@ ThirdPartyUtil::IsThirdPartyWindow(nsPID
       return rv;
 
     if (result) {
       *aResult = true;
       return NS_OK;
     }
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> current = nsPIDOMWindowOuter::From(aWindow), parent;
+  nsCOMPtr<nsPIDOMWindowOuter> current = aWindow, parent;
   nsCOMPtr<nsIURI> parentURI;
   do {
     // We use GetScriptableParent rather than GetParent because we consider
     // <iframe mozbrowser> to be a top-level frame.
     parent = current->GetScriptableParent();
     if (SameCOMIdentity(parent, current)) {
       // We're at the topmost content window. We already know the answer.
       *aResult = false;
@@ -264,17 +264,17 @@ ThirdPartyUtil::GetTopWindowForChannel(n
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
   ctx->GetAssociatedWindow(getter_AddRefs(window));
   if (!window) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> top = nsPIDOMWindowOuter::From(window)->GetTop();
+  nsCOMPtr<nsPIDOMWindowOuter> top = window->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
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7642,22 +7642,17 @@ nsContentUtils::GetInnerWindowID(nsILoad
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
   rv = loadContext->GetAssociatedWindow(getter_AddRefs(window));
   if (NS_FAILED(rv) || !window) {
     return 0;
   }
 
-  auto* pwindow = nsPIDOMWindowOuter::From(window);
-  if (!pwindow) {
-    return 0;
-  }
-
-  nsPIDOMWindowInner* inner = pwindow->GetCurrentInnerWindow();
+  nsPIDOMWindowInner* inner = window->GetCurrentInnerWindow();
   return inner ? inner->WindowID() : 0;
 }
 
 nsresult
 nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost)
 {
   aHost.Truncate();
   nsresult rv = aURI->GetHost(aHost);
@@ -10163,24 +10158,19 @@ nsContentUtils::AttemptLargeAllocationLo
     return false;
   }
 
   nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
   if (NS_WARN_IF(!loadContext)) {
     return false;
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> window;
-  rv = loadContext->GetAssociatedWindow(getter_AddRefs(window));
-  if (NS_WARN_IF(NS_FAILED(rv) || !window)) {
-    return false;
-  }
-
-  nsPIDOMWindowOuter* outer = nsPIDOMWindowOuter::From(window);
-  if (NS_WARN_IF(!outer)) {
+  nsCOMPtr<nsPIDOMWindowOuter> outer;
+  rv = loadContext->GetAssociatedWindow(getter_AddRefs(outer));
+  if (NS_WARN_IF(NS_FAILED(rv) || !outer)) {
     return false;
   }
 
   if (!XRE_IsContentProcess()) {
     outer->SetLargeAllocStatus(LargeAllocStatus::NON_E10S);
     return false;
   }
 
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -3433,20 +3433,18 @@ nsIDocument::HasFocus(ErrorResult& rv) c
 
   // Is there a focused DOMWindow?
   nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
   fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
   if (!focusedWindow) {
     return false;
   }
 
-  nsPIDOMWindowOuter* piWindow = nsPIDOMWindowOuter::From(focusedWindow);
-
   // Are we an ancestor of the focused DOMWindow?
-  for (nsIDocument* currentDoc = piWindow->GetDoc(); currentDoc;
+  for (nsIDocument* currentDoc = focusedWindow->GetDoc(); currentDoc;
        currentDoc = currentDoc->GetParentDocument()) {
     if (currentDoc == this) {
       // Yes, we are an ancestor
       return true;
     }
   }
 
   return false;
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -425,58 +425,54 @@ nsFocusManager::GetActiveWindow(nsPIDOMW
 }
 
 NS_IMETHODIMP
 nsFocusManager::SetActiveWindow(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_STATE(aWindow);
 
   // only top-level windows can be made active
-  nsCOMPtr<nsPIDOMWindowOuter> piWindow = nsPIDOMWindowOuter::From(aWindow);
-  NS_ENSURE_TRUE(piWindow == piWindow->GetPrivateRoot(), NS_ERROR_INVALID_ARG);
-
-  RaiseWindow(piWindow);
+  NS_ENSURE_TRUE(aWindow == aWindow->GetPrivateRoot(), NS_ERROR_INVALID_ARG);
+
+  RaiseWindow(aWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::GetFocusedWindow(nsPIDOMWindowOuter** aFocusedWindow)
 {
   NS_IF_ADDREF(*aFocusedWindow = mFocusedWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsFocusManager::SetFocusedWindow(nsPIDOMWindowOuter* aWindowToFocus)
 {
   LOGFOCUS(("<<SetFocusedWindow begin>>"));
 
-  nsCOMPtr<nsPIDOMWindowOuter> windowToFocus = nsPIDOMWindowOuter::From(aWindowToFocus);
-  NS_ENSURE_TRUE(windowToFocus, NS_ERROR_FAILURE);
-
-  windowToFocus = windowToFocus->GetOuterWindow();
-
-  nsCOMPtr<Element> frameElement = windowToFocus->GetFrameElementInternal();
+  NS_ENSURE_TRUE(aWindowToFocus, NS_ERROR_FAILURE);
+
+  nsCOMPtr<Element> frameElement = aWindowToFocus->GetFrameElementInternal();
   if (frameElement) {
     // pass false for aFocusChanged so that the caret does not get updated
     // and scrolling does not occur.
     SetFocusInner(frameElement, 0, false, true);
   }
   else {
     // this is a top-level window. If the window has a child frame focused,
     // clear the focus. Otherwise, focus should already be in this frame, or
     // already cleared. This ensures that focus will be in this frame and not
     // in a child.
-    nsIContent* content = windowToFocus->GetFocusedElement();
+    nsIContent* content = aWindowToFocus->GetFocusedElement();
     if (content) {
       if (nsCOMPtr<nsPIDOMWindowOuter> childWindow = GetContentWindow(content))
-        ClearFocus(windowToFocus);
+        ClearFocus(aWindowToFocus);
     }
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> rootWindow = windowToFocus->GetPrivateRoot();
+  nsCOMPtr<nsPIDOMWindowOuter> rootWindow = aWindowToFocus->GetPrivateRoot();
   if (rootWindow)
     RaiseWindow(rootWindow);
 
   LOGFOCUS(("<<SetFocusedWindow end>>"));
 
   return NS_OK;
 }
 
@@ -487,20 +483,17 @@ nsFocusManager::GetFocusedElement(Elemen
   focusedElement.forget(aFocusedElement);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::GetLastFocusMethod(nsPIDOMWindowOuter* aWindow, uint32_t* aLastFocusMethod)
 {
   // the focus method is stored on the inner window
-  nsCOMPtr<nsPIDOMWindowOuter> window;
-  if (aWindow) {
-    window = nsPIDOMWindowOuter::From(aWindow);
-  }
+  nsCOMPtr<nsPIDOMWindowOuter> window(aWindow);
   if (!window)
     window = mFocusedWindow;
 
   *aLastFocusMethod = window ? window->GetFocusMethod() : 0;
 
   NS_ASSERTION((*aLastFocusMethod & FOCUSMETHOD_MASK) == *aLastFocusMethod,
                "invalid focus method");
   return NS_OK;
@@ -557,17 +550,17 @@ nsFocusManager::MoveFocus(nsPIDOMWindowO
       (aFlags & FOCUSMETHOD_MASK) == 0) {
     aFlags |= FLAG_BYMOVEFOCUS;
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
   if (aStartElement) {
     window = GetCurrentWindow(aStartElement);
   } else {
-    window = aWindow ? nsPIDOMWindowOuter::From(aWindow) : mFocusedWindow.get();
+    window = aWindow ? aWindow : mFocusedWindow.get();
   }
 
   NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
 
   bool noParentTraversal = aFlags & FLAG_NOPARENTFRAME;
   nsCOMPtr<nsIContent> newFocus;
   nsresult rv = DetermineElementToMoveFocus(window, aStartElement, aType, noParentTraversal,
                                             getter_AddRefs(newFocus));
@@ -602,29 +595,28 @@ NS_IMETHODIMP
 nsFocusManager::ClearFocus(nsPIDOMWindowOuter* aWindow)
 {
   LOGFOCUS(("<<ClearFocus begin>>"));
 
   // if the window to clear is the focused window or an ancestor of the
   // focused window, then blur the existing focused content. Otherwise, the
   // focus is somewhere else so just update the current node.
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
-
-  if (IsSameOrAncestor(window, mFocusedWindow)) {
-    bool isAncestor = (window != mFocusedWindow);
-    if (Blur(window, nullptr, isAncestor, true)) {
+
+  if (IsSameOrAncestor(aWindow, mFocusedWindow)) {
+    bool isAncestor = (aWindow != mFocusedWindow);
+    if (Blur(aWindow, nullptr, isAncestor, true)) {
       // if we are clearing the focus on an ancestor of the focused window,
       // the ancestor will become the new focused window, so focus it
       if (isAncestor)
-        Focus(window, nullptr, 0, true, false, false, true);
+        Focus(aWindow, nullptr, 0, true, false, false, true);
     }
   }
   else {
-    window->SetFocusedElement(nullptr);
+    aWindow->SetFocusedElement(nullptr);
   }
 
   LOGFOCUS(("<<ClearFocus end>>"));
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -633,21 +625,20 @@ nsFocusManager::GetFocusedElementForWind
                                            nsPIDOMWindowOuter** aFocusedWindow,
                                            Element** aElement)
 {
   *aElement = nullptr;
   if (aFocusedWindow)
     *aFocusedWindow = nullptr;
 
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
 
   nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
   RefPtr<Element> focusedElement =
-    GetFocusedDescendant(window,
+    GetFocusedDescendant(aWindow,
                          aDeep ? nsFocusManager::eIncludeAllDescendants :
                                  nsFocusManager::eOnlyCurrentWindow,
                          getter_AddRefs(focusedWindow));
 
   focusedElement.forget(aElement);
 
   if (aFocusedWindow)
     NS_IF_ADDREF(*aFocusedWindow = focusedWindow);
@@ -669,71 +660,69 @@ nsFocusManager::MoveCaretToFocus(nsPIDOM
       bool isEditable;
       docShell->GetEditable(&isEditable);
       if (isEditable)
         return NS_OK;
 
       nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
       NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
-      nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
-      nsCOMPtr<nsIContent> content = window->GetFocusedElement();
+      nsCOMPtr<nsIContent> content = aWindow->GetFocusedElement();
       if (content)
         MoveCaretToFocus(presShell, content);
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::WindowRaised(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
 
   if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
     LOGFOCUS(("Window %p Raised [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
-    nsIDocument* doc = window->GetExtantDoc();
+    nsIDocument* doc = aWindow->GetExtantDoc();
     if (doc && doc->GetDocumentURI()) {
       LOGFOCUS(("  Raised Window: %p %s", aWindow,
                 doc->GetDocumentURI()->GetSpecOrDefault().get()));
     }
     if (mActiveWindow) {
       doc = mActiveWindow->GetExtantDoc();
       if (doc && doc->GetDocumentURI()) {
         LOGFOCUS(("  Active Window: %p %s", mActiveWindow.get(),
                   doc->GetDocumentURI()->GetSpecOrDefault().get()));
       }
     }
   }
 
-  if (mActiveWindow == window) {
+  if (mActiveWindow == aWindow) {
     // The window is already active, so there is no need to focus anything,
     // but make sure that the right widget is focused. This is a special case
     // for Windows because when restoring a minimized window, a second
     // activation will occur and the top-level widget could be focused instead
     // of the child we want. We solve this by calling SetFocus to ensure that
     // what the focus manager thinks should be the current widget is actually
     // focused.
     EnsureCurrentWidgetFocused();
     return NS_OK;
   }
 
   // lower the existing window, if any. This shouldn't happen usually.
   if (mActiveWindow)
     WindowLowered(mActiveWindow);
 
-  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem = window->GetDocShell();
+  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem = aWindow->GetDocShell();
   // If there's no docShellAsItem, this window must have been closed,
   // in that case there is no tree owner.
   NS_ENSURE_TRUE(docShellAsItem, NS_OK);
 
   // set this as the active window
-  mActiveWindow = window;
+  mActiveWindow = aWindow;
 
   // ensure that the window is enabled and visible
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
   nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(treeOwner);
   if (baseWindow) {
     bool isEnabled = true;
     if (NS_SUCCEEDED(baseWindow->GetEnabled(&isEnabled)) && !isEnabled) {
@@ -744,23 +733,23 @@ nsFocusManager::WindowRaised(nsPIDOMWind
       baseWindow->SetVisibility(true);
     }
   }
 
   // If this is a parent or single process window, send the activate event.
   // Events for child process windows will be sent when ParentActivated
   // is called.
   if (XRE_IsParentProcess()) {
-    ActivateOrDeactivate(window, true);
+    ActivateOrDeactivate(aWindow, true);
   }
 
   // retrieve the last focused element within the window that was raised
   nsCOMPtr<nsPIDOMWindowOuter> currentWindow;
   RefPtr<Element> currentFocus =
-    GetFocusedDescendant(window, eIncludeAllDescendants,
+    GetFocusedDescendant(aWindow, eIncludeAllDescendants,
                          getter_AddRefs(currentWindow));
 
   NS_ASSERTION(currentWindow, "window raised with no window current");
   if (!currentWindow)
     return NS_OK;
 
   // If there is no nsIXULWindow, then this is an embedded or child process window.
   // Pass false for aWindowRaised so that commands get updated.
@@ -769,35 +758,34 @@ nsFocusManager::WindowRaised(nsPIDOMWind
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::WindowLowered(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
 
   if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
     LOGFOCUS(("Window %p Lowered [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
-    nsIDocument* doc = window->GetExtantDoc();
+    nsIDocument* doc = aWindow->GetExtantDoc();
     if (doc && doc->GetDocumentURI()) {
       LOGFOCUS(("  Lowered Window: %s",
                 doc->GetDocumentURI()->GetSpecOrDefault().get()));
     }
     if (mActiveWindow) {
       doc = mActiveWindow->GetExtantDoc();
       if (doc && doc->GetDocumentURI()) {
         LOGFOCUS(("  Active Window: %s",
                   doc->GetDocumentURI()->GetSpecOrDefault().get()));
       }
     }
   }
 
-  if (mActiveWindow != window)
+  if (mActiveWindow != aWindow)
     return NS_OK;
 
   // clear the mouse capture as the active window has changed
   nsIPresShell::SetCapturingContent(nullptr, 0);
 
   // In addition, reset the drag state to ensure that we are no longer in
   // drag-select mode.
   if (mFocusedWindow) {
@@ -810,17 +798,17 @@ nsFocusManager::WindowLowered(nsPIDOMWin
       }
     }
   }
 
   // If this is a parent or single process window, send the deactivate event.
   // Events for child process windows will be sent when ParentActivated
   // is called.
   if (XRE_IsParentProcess()) {
-    ActivateOrDeactivate(window, false);
+    ActivateOrDeactivate(aWindow, false);
   }
 
   // keep track of the window being lowered, so that attempts to raise the
   // window can be prevented until we return. Otherwise, focus can get into
   // an unusual state.
   mWindowBeingLowered = mActiveWindow;
   mActiveWindow = nullptr;
 
@@ -892,49 +880,48 @@ nsFocusManager::ContentRemoved(nsIDocume
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::WindowShown(nsPIDOMWindowOuter* aWindow, bool aNeedsFocus)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
 
   if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
-    LOGFOCUS(("Window %p Shown [Currently: %p %p]", window.get(), mActiveWindow.get(), mFocusedWindow.get()));
-    nsIDocument* doc = window->GetExtantDoc();
+    LOGFOCUS(("Window %p Shown [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
+    nsIDocument* doc = aWindow->GetExtantDoc();
     if (doc && doc->GetDocumentURI()) {
       LOGFOCUS(("Shown Window: %s",
                 doc->GetDocumentURI()->GetSpecOrDefault().get()));
     }
 
     if (mFocusedWindow) {
       doc = mFocusedWindow->GetExtantDoc();
       if (doc && doc->GetDocumentURI()) {
         LOGFOCUS((" Focused Window: %s",
                   doc->GetDocumentURI()->GetSpecOrDefault().get()));
       }
     }
   }
 
-  if (nsIDocShell* docShell = window->GetDocShell()) {
+  if (nsIDocShell* docShell = aWindow->GetDocShell()) {
     if (nsCOMPtr<nsITabChild> child = docShell->GetTabChild()) {
       bool active = static_cast<TabChild*>(child.get())->ParentIsActive();
-      ActivateOrDeactivate(window, active);
+      ActivateOrDeactivate(aWindow, active);
     }
   }
 
-  if (mFocusedWindow != window)
+  if (mFocusedWindow != aWindow)
     return NS_OK;
 
   if (aNeedsFocus) {
     nsCOMPtr<nsPIDOMWindowOuter> currentWindow;
     RefPtr<Element> currentFocus =
-      GetFocusedDescendant(window, eIncludeAllDescendants,
+      GetFocusedDescendant(aWindow, eIncludeAllDescendants,
                            getter_AddRefs(currentWindow));
     if (currentWindow)
       Focus(currentWindow, currentFocus, 0, true, false, false, true);
   }
   else {
     // Sometimes, an element in a window can be focused before the window is
     // visible, which would mean that the widget may not be properly focused.
     // When the window becomes visible, make sure the right widget is focused.
@@ -947,22 +934,21 @@ nsFocusManager::WindowShown(nsPIDOMWindo
 NS_IMETHODIMP
 nsFocusManager::WindowHidden(nsPIDOMWindowOuter* aWindow)
 {
   // if there is no window or it is not the same or an ancestor of the
   // currently focused window, just return, as the current focus will not
   // be affected.
 
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
 
   if (MOZ_LOG_TEST(gFocusLog, LogLevel::Debug)) {
-    LOGFOCUS(("Window %p Hidden [Currently: %p %p]", window.get(), mActiveWindow.get(), mFocusedWindow.get()));
+    LOGFOCUS(("Window %p Hidden [Currently: %p %p]", aWindow, mActiveWindow.get(), mFocusedWindow.get()));
     nsAutoCString spec;
-    nsIDocument* doc = window->GetExtantDoc();
+    nsIDocument* doc = aWindow->GetExtantDoc();
     if (doc && doc->GetDocumentURI()) {
       LOGFOCUS(("  Hide Window: %s",
                 doc->GetDocumentURI()->GetSpecOrDefault().get()));
     }
 
     if (mFocusedWindow) {
       doc = mFocusedWindow->GetExtantDoc();
       if (doc && doc->GetDocumentURI()) {
@@ -975,34 +961,34 @@ nsFocusManager::WindowHidden(nsPIDOMWind
       doc = mActiveWindow->GetExtantDoc();
       if (doc && doc->GetDocumentURI()) {
         LOGFOCUS(("  Active Window: %s",
                   doc->GetDocumentURI()->GetSpecOrDefault().get()));
       }
     }
   }
 
-  if (!IsSameOrAncestor(window, mFocusedWindow))
+  if (!IsSameOrAncestor(aWindow, mFocusedWindow))
     return NS_OK;
 
   // at this point, we know that the window being hidden is either the focused
   // window, or an ancestor of the focused window. Either way, the focus is no
   // longer valid, so it needs to be updated.
 
   RefPtr<Element> oldFocusedElement = mFocusedElement.forget();
 
   nsCOMPtr<nsIDocShell> focusedDocShell = mFocusedWindow->GetDocShell();
   nsCOMPtr<nsIPresShell> presShell = focusedDocShell->GetPresShell();
 
   if (oldFocusedElement && oldFocusedElement->IsInComposedDoc()) {
     NotifyFocusStateChange(oldFocusedElement,
                            nullptr,
                            mFocusedWindow->ShouldShowFocusRing(),
                            false);
-    window->UpdateCommands(NS_LITERAL_STRING("focus"), nullptr, 0);
+    aWindow->UpdateCommands(NS_LITERAL_STRING("focus"), nullptr, 0);
 
     if (presShell) {
       SendFocusOrBlurEvent(eBlur, presShell,
                            oldFocusedElement->GetComposedDoc(),
                            oldFocusedElement, 1, false);
     }
   }
 
@@ -1015,51 +1001,51 @@ nsFocusManager::WindowHidden(nsPIDOMWind
   }
 
   // if the docshell being hidden is being destroyed, then we want to move
   // focus somewhere else. Call ClearFocus on the toplevel window, which
   // will have the effect of clearing the focus and moving the focused window
   // to the toplevel window. But if the window isn't being destroyed, we are
   // likely just loading a new document in it, so we want to maintain the
   // focused window so that the new document gets properly focused.
-  nsCOMPtr<nsIDocShell> docShellBeingHidden = window->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShellBeingHidden = aWindow->GetDocShell();
   bool beingDestroyed = !docShellBeingHidden;
   if (docShellBeingHidden) {
     docShellBeingHidden->IsBeingDestroyed(&beingDestroyed);
   }
   if (beingDestroyed) {
     // There is usually no need to do anything if a toplevel window is going
     // away, as we assume that WindowLowered will be called. However, this may
     // not happen if nsIAppStartup::eForceQuit is used to quit, and can cause
     // a leak. So if the active window is being destroyed, call WindowLowered
     // directly.
-    if (mActiveWindow == mFocusedWindow || mActiveWindow == window)
+    if (mActiveWindow == mFocusedWindow || mActiveWindow == aWindow)
       WindowLowered(mActiveWindow);
     else
       ClearFocus(mActiveWindow);
     return NS_OK;
   }
 
   // if the window being hidden is an ancestor of the focused window, adjust
   // the focused window so that it points to the one being hidden. This
   // ensures that the focused window isn't in a chain of frames that doesn't
   // exist any more.
-  if (window != mFocusedWindow) {
+  if (aWindow != mFocusedWindow) {
     nsCOMPtr<nsIDocShellTreeItem> dsti =
       mFocusedWindow ? mFocusedWindow->GetDocShell() : nullptr;
     if (dsti) {
       nsCOMPtr<nsIDocShellTreeItem> parentDsti;
       dsti->GetParent(getter_AddRefs(parentDsti));
       if (parentDsti) {
         if (nsCOMPtr<nsPIDOMWindowOuter> parentWindow = parentDsti->GetWindow())
           parentWindow->SetFocusedElement(nullptr);
       }
     }
 
-    SetFocusedWindowInternal(window);
+    SetFocusedWindowInternal(aWindow);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::FireDelayedEvents(nsIDocument* aDocument)
 {
@@ -1098,20 +1084,17 @@ nsFocusManager::FocusPlugin(Element* aPl
   NS_ENSURE_ARG(aPlugin);
   SetFocusInner(aPlugin, 0, true, false);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFocusManager::ParentActivated(nsPIDOMWindowOuter* aWindow, bool aActive)
 {
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
-  NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG);
-
-  ActivateOrDeactivate(window, aActive);
+  ActivateOrDeactivate(aWindow, aActive);
   return NS_OK;
 }
 
 /* static */
 void
 nsFocusManager::NotifyFocusStateChange(nsIContent* aContent,
                                        nsIContent* aContentToFocus,
                                        bool aWindowShouldShowFocusRing,
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -4764,23 +4764,22 @@ nsGlobalWindowOuter::FocusOuter(ErrorRes
 
   // 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 == callerOuter &&
                      RevisePopupAbuseLevel(GetPopupControlState()) < openBlocked);
 
-  nsCOMPtr<nsPIDOMWindowOuter> activeDOMWindow;
-  fm->GetActiveWindow(getter_AddRefs(activeDOMWindow));
+  nsCOMPtr<nsPIDOMWindowOuter> activeWindow;
+  fm->GetActiveWindow(getter_AddRefs(activeWindow));
 
   nsCOMPtr<nsIDocShellTreeItem> rootItem;
   mDocShell->GetRootTreeItem(getter_AddRefs(rootItem));
   nsCOMPtr<nsPIDOMWindowOuter> rootWin = rootItem ? rootItem->GetWindow() : nullptr;
-  auto* activeWindow = nsPIDOMWindowOuter::From(activeDOMWindow);
   bool isActive = (rootWin == activeWindow);
 
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = GetTreeOwnerWindow();
   if (treeOwnerAsWin && (canFocus || isActive)) {
     bool isEnabled = true;
     if (NS_SUCCEEDED(treeOwnerAsWin->GetEnabled(&isEnabled)) && !isEnabled) {
       NS_WARNING( "Should not try to set the focus on a disabled window" );
       return;
@@ -7057,19 +7056,17 @@ nsGlobalWindowOuter::OpenInternal(const 
     }
   }
 
   NS_ENSURE_SUCCESS(rv, rv);
 
   // success!
 
   NS_ENSURE_TRUE(domReturn, NS_OK);
-  nsCOMPtr<nsPIDOMWindowOuter> outerReturn =
-    nsPIDOMWindowOuter::From(domReturn);
-  outerReturn.swap(*aReturn);
+  domReturn.swap(*aReturn);
 
   if (aDoJSFixups) {
     nsCOMPtr<nsIDOMChromeWindow> chrome_win(do_QueryInterface(*aReturn));
     if (!chrome_win) {
       // A new non-chrome window was created from a call to
       // window.open() from JavaScript, make sure there's a document in
       // the new window. We do this by simply asking the new window for
       // its document, this will synchronously create an empty document
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -850,26 +850,24 @@ nsWindowMemoryReporter::CheckForGhostWin
 
   // Update mDetachedWindows and write the ghost window IDs into aOutGhostIDs,
   // if it's not null.
   uint32_t ghostTimeout = GetGhostTimeout();
   TimeStamp now = mLastCheckForGhostWindows;
   mGhostWindowCount = 0;
   for (auto iter = mDetachedWindows.Iter(); !iter.Done(); iter.Next()) {
     nsWeakPtr weakKey = do_QueryInterface(iter.Key());
-    nsCOMPtr<nsPIDOMWindowInner> iwindow = do_QueryReferent(weakKey);
-    if (!iwindow) {
+    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(weakKey);
+    if (!window) {
       // The window object has been destroyed.  Stop tracking its weak ref in
       // our hashtable.
       iter.Remove();
       continue;
     }
 
-    nsPIDOMWindowInner* window = nsPIDOMWindowInner::From(iwindow);
-
     // 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<nsPIDOMWindowOuter> top;
     if (window->GetOuterWindow()) {
       top = window->GetOuterWindow()->GetTop();
     }
 
--- a/dom/clients/manager/ClientOpenWindowUtils.cpp
+++ b/dom/clients/manager/ClientOpenWindowUtils.cpp
@@ -227,18 +227,17 @@ OpenWindow(const ClientOpenWindowArgs& a
                               // opener anyway, and we _do_ want the returned
                               // window.
                               /* aForceNoOpener = */ false,
                               /* aLoadInfp = */ nullptr,
                               getter_AddRefs(newWindow));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
-    nsCOMPtr<nsPIDOMWindowOuter> pwindow = nsPIDOMWindowOuter::From(newWindow);
-    pwindow.forget(aWindow);
+    newWindow.forget(aWindow);
     MOZ_DIAGNOSTIC_ASSERT(*aWindow);
     return NS_OK;
   }
 
   // Find the most recent browser window and open a new tab in it.
   nsCOMPtr<nsPIDOMWindowOuter> browserWindow =
     nsContentUtils::GetMostRecentNonPBWindow();
   if (!browserWindow) {
@@ -266,18 +265,17 @@ OpenWindow(const ClientOpenWindowArgs& a
                      nsIBrowserDOMWindow::OPEN_NEW,
                      principal,
                      getter_AddRefs(win));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   NS_ENSURE_STATE(win);
 
-  nsCOMPtr<nsPIDOMWindowOuter> pWin = nsPIDOMWindowOuter::From(win);
-  pWin.forget(aWindow);
+  win.forget(aWindow);
   MOZ_DIAGNOSTIC_ASSERT(*aWindow);
 
   return NS_OK;
 }
 
 void
 WaitForLoad(const ClientOpenWindowArgs& aArgs,
             nsPIDOMWindowOuter* aOuterWindow,
--- a/dom/commandhandler/nsCommandManager.cpp
+++ b/dom/commandhandler/nsCommandManager.cpp
@@ -230,32 +230,31 @@ nsCommandManager::GetControllerForComman
     }
 
     // if a target window is specified, it must be the window we expect
     if (aTargetWindow != mWindow) {
       return NS_ERROR_FAILURE;
     }
   }
 
-  if (auto* targetWindow = nsPIDOMWindowOuter::From(aTargetWindow)) {
+  if (aTargetWindow) {
     // get the controller for this particular window
     nsCOMPtr<nsIControllers> controllers;
-    rv = targetWindow->GetControllers(getter_AddRefs(controllers));
+    rv = aTargetWindow->GetControllers(getter_AddRefs(controllers));
     if (NS_FAILED(rv)) {
       return rv;
     }
     if (!controllers) {
       return NS_ERROR_FAILURE;
     }
 
     // dispatch the command
     return controllers->GetControllerForCommand(aCommand, aResult);
   }
 
-  auto* window = nsPIDOMWindowOuter::From(mWindow);
-  NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
-  nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
+  NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE);
+  nsCOMPtr<nsPIWindowRoot> root = mWindow->GetTopWindowRoot();
   NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
 
   // no target window; send command to focus controller
   return root->GetControllerForCommand(aCommand, false /* for any window */,
                                        aResult);
 }
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -3359,25 +3359,24 @@ EventStateManager::PostHandleEvent(nsPre
         // 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<nsPIDOMWindowOuter> window;
           fm->GetFocusedWindow(getter_AddRefs(window));
-          auto* currentWindow = nsPIDOMWindowOuter::From(window);
-          if (currentWindow && mDocument->GetWindow() &&
-              currentWindow != mDocument->GetWindow() &&
+          if (window && mDocument->GetWindow() &&
+              window != mDocument->GetWindow() &&
               !nsContentUtils::IsChromeDoc(mDocument)) {
             nsCOMPtr<nsPIDOMWindowOuter> currentTop;
             nsCOMPtr<nsPIDOMWindowOuter> newTop;
-            currentTop = currentWindow->GetTop();
+            currentTop = window->GetTop();
             newTop = mDocument->GetWindow()->GetTop();
-            nsCOMPtr<nsIDocument> currentDoc = currentWindow->GetExtantDoc();
+            nsCOMPtr<nsIDocument> currentDoc = window->GetExtantDoc();
             if (nsContentUtils::IsChromeDoc(currentDoc) ||
                 (currentTop && newTop && currentTop != newTop)) {
               fm->SetFocusedWindow(mDocument->GetWindow());
             }
           }
         }
       }
       SetActiveManager(this, activeContent);
--- a/dom/html/nsGenericHTMLFrameElement.cpp
+++ b/dom/html/nsGenericHTMLFrameElement.cpp
@@ -133,18 +133,17 @@ nsGenericHTMLFrameElement::EnsureFrameLo
 {
   if (!IsInComposedDoc() || mFrameLoader || mFrameLoaderCreationDisallowed) {
     // If frame loader is there, we just keep it around, cached
     return;
   }
 
   // Strangely enough, this method doesn't actually ensure that the
   // frameloader exists.  It's more of a best-effort kind of thing.
-  mFrameLoader = nsFrameLoader::Create(this,
-                                       nsPIDOMWindowOuter::From(mOpenerWindow),
+  mFrameLoader = nsFrameLoader::Create(this, mOpenerWindow,
                                        mNetworkCreated);
 }
 
 nsresult
 nsGenericHTMLFrameElement::CreateRemoteFrameLoader(nsITabParent* aTabParent)
 {
   MOZ_ASSERT(!mFrameLoader);
   EnsureFrameLoader();
@@ -167,17 +166,17 @@ nsGenericHTMLFrameElement::GetFrameLoade
   RefPtr<nsFrameLoader> loader = mFrameLoader;
   return loader.forget();
 }
 
 void
 nsGenericHTMLFrameElement::PresetOpenerWindow(nsPIDOMWindowOuter* aWindow, ErrorResult& aRv)
 {
   MOZ_ASSERT(!mFrameLoader);
-  mOpenerWindow = nsPIDOMWindowOuter::From(aWindow);
+  mOpenerWindow = aWindow;
 }
 
 void
 nsGenericHTMLFrameElement::InternalSetFrameLoader(nsFrameLoader* aNewFrameLoader)
 {
   mFrameLoader = aNewFrameLoader;
 }
 
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -765,24 +765,23 @@ ContentChild::ProvideWindow(nsPIDOMWindo
 static nsresult
 GetCreateWindowParams(nsPIDOMWindowOuter* aParent,
                       nsIDocShellLoadInfo* aLoadInfo,
                       nsACString& aBaseURIString, float* aFullZoom,
                       uint32_t* aReferrerPolicy,
                       nsIPrincipal** aTriggeringPrincipal)
 {
   *aFullZoom = 1.0f;
-  auto* opener = nsPIDOMWindowOuter::From(aParent);
-  if (!opener) {
+  if (!aParent) {
     nsCOMPtr<nsIPrincipal> nullPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
     NS_ADDREF(*aTriggeringPrincipal = nullPrincipal);
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDocument> doc = opener->GetDoc();
+  nsCOMPtr<nsIDocument> doc = aParent->GetDoc();
   NS_ADDREF(*aTriggeringPrincipal = doc->NodePrincipal());
   nsCOMPtr<nsIURI> baseURI = doc->GetDocBaseURI();
   if (!baseURI) {
     NS_ERROR("nsIDocument didn't return a base URI");
     return NS_ERROR_FAILURE;
   }
 
   baseURI->GetSpec(aBaseURIString);
@@ -793,17 +792,17 @@ GetCreateWindowParams(nsPIDOMWindowOuter
     if (!sendReferrer) {
       *aReferrerPolicy = mozilla::net::RP_No_Referrer;
     } else {
       aLoadInfo->GetReferrerPolicy(aReferrerPolicy);
     }
   }
 
   RefPtr<nsDocShell> openerDocShell =
-    static_cast<nsDocShell*>(opener->GetDocShell());
+    static_cast<nsDocShell*>(aParent->GetDocShell());
   if (!openerDocShell) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIContentViewer> cv;
   nsresult rv = openerDocShell->GetContentViewer(getter_AddRefs(cv));
   if (NS_SUCCEEDED(rv) && cv) {
     cv->GetFullZoom(aFullZoom);
@@ -946,18 +945,17 @@ ContentChild::ProvideWindowCommon(TabChi
     tabId, TabId(0), *ipcContext, aChromeFlags,
     GetID(), IsForBrowser());
 
 
   PRenderFrameChild* renderFrame = newChild->SendPRenderFrameConstructor();
 
   nsCOMPtr<nsPIDOMWindowInner> parentTopInnerWindow;
   if (aParent) {
-    nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow =
-      nsPIDOMWindowOuter::From(aParent)->GetTop();
+    nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow = aParent->GetTop();
     if (parentTopWindow) {
       parentTopInnerWindow = parentTopWindow->GetCurrentInnerWindow();
     }
   }
 
   // Set to true when we're ready to return from this function.
   bool ready = false;
 
@@ -999,38 +997,35 @@ ContentChild::ProvideWindowCommon(TabChi
       return;
     }
 
     if (!layersId.IsValid()) { // if renderFrame is invalid.
       renderFrame = nullptr;
     }
 
     ShowInfo showInfo(EmptyString(), false, false, true, false, 0, 0, 0);
-    auto* opener = nsPIDOMWindowOuter::From(aParent);
     nsIDocShell* openerShell;
-    if (opener && (openerShell = opener->GetDocShell())) {
+    if (aParent && (openerShell = aParent->GetDocShell())) {
       nsCOMPtr<nsILoadContext> context = do_QueryInterface(openerShell);
       showInfo = ShowInfo(EmptyString(), false,
                           context->UsePrivateBrowsing(), true, false,
                           aTabOpener->WebWidget()->GetDPI(),
                           aTabOpener->WebWidget()->RoundsWidgetCoordinatesTo(),
                           aTabOpener->WebWidget()->GetDefaultScale().scale);
     }
 
     newChild->SetMaxTouchPoints(maxTouchPoints);
 
     // Set the opener window for this window before we start loading the document
     // inside of it. We have to do this before loading the remote scripts, because
     // they can poke at the document and cause the nsDocument to be created before
     // the openerwindow
-    nsCOMPtr<nsPIDOMWindowOuter> windowProxy = do_GetInterface(newChild->WebNavigation());
-    if (!aForceNoOpener && windowProxy && aParent) {
-      nsPIDOMWindowOuter* outer = nsPIDOMWindowOuter::From(windowProxy);
-      nsPIDOMWindowOuter* parent = nsPIDOMWindowOuter::From(aParent);
-      outer->SetOpenerWindow(parent, *aWindowIsNew);
+    nsCOMPtr<nsPIDOMWindowOuter> outer = do_GetInterface(newChild->WebNavigation());
+    if (!aForceNoOpener && outer && aParent) {
+      outer->SetOpenerWindow(aParent, *aWindowIsNew);
     }
 
     // Unfortunately we don't get a window unless we've shown the frame.  That's
     // pretty bogus; see bug 763602.
     newChild->DoFakeShow(textureFactoryIdentifier, layersId, compositorOptions,
                         renderFrame, showInfo);
 
     newChild->RecvUpdateDimensions(dimensionInfo);
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1013,17 +1013,17 @@ TabChild::ProvideWindow(nsPIDOMWindowOut
     nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent);
     bool iframeMoz = (docshell && docshell->GetIsInMozBrowser() &&
                       !(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL |
                                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
                                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME)));
 
     if (!iframeMoz) {
       int32_t openLocation =
-        nsWindowWatcher::GetWindowOpenLocation(nsPIDOMWindowOuter::From(aParent),
+        nsWindowWatcher::GetWindowOpenLocation(aParent,
                                                aChromeFlags, aCalledFromJS,
                                                aPositionSpecified, aSizeSpecified);
 
       // If it turns out we're opening in the current browser, just hand over the
       // current browser's docshell.
       if (openLocation == nsIBrowserDOMWindow::OPEN_CURRENTWINDOW) {
         nsCOMPtr<nsIWebBrowser> browser = do_GetInterface(WebNavigation());
         *aWindowIsNew = false;
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -89,17 +89,17 @@ MediaEngineTabVideoSource::InitRunnable:
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsPIDOMWindowOuter> win;
     rv = mVideoSource->mTabSource->GetTabToStream(getter_AddRefs(win));
     NS_ENSURE_SUCCESS(rv, rv);
     if (!win)
       return NS_OK;
 
-    mVideoSource->mWindow = nsPIDOMWindowOuter::From(win);
+    mVideoSource->mWindow = win;
     MOZ_ASSERT(mVideoSource->mWindow);
   }
   mVideoSource->mTimer = NS_NewTimer();
   nsCOMPtr<nsIRunnable> start(new StartRunnable(mVideoSource));
   start->Run();
   return NS_OK;
 }
 
--- a/dom/plugins/ipc/PluginHangUIParent.cpp
+++ b/dom/plugins/ipc/PluginHangUIParent.cpp
@@ -385,25 +385,24 @@ PluginHangUIParent::GetHangUIOwnerWindow
 {
   windowHandle = nullptr;
 
   nsresult rv;
   nsCOMPtr<nsIWindowMediator> winMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID,
                                                         &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsPIDOMWindowOuter> navWin;
+  nsCOMPtr<nsPIDOMWindowOuter> win;
   rv = winMediator->GetMostRecentWindow(u"navigator:browser",
-                                        getter_AddRefs(navWin));
+                                        getter_AddRefs(win));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!navWin) {
+  if (!win) {
     return NS_ERROR_FAILURE;
   }
 
-  nsPIDOMWindowOuter* win = nsPIDOMWindowOuter::From(navWin);
   nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(win);
   if (!widget) {
     return NS_ERROR_FAILURE;
   }
 
   windowHandle = reinterpret_cast<NativeWindowHandle>(widget->GetNativeData(NS_NATIVE_WINDOW));
   if (!windowHandle) {
     return NS_ERROR_FAILURE;
--- a/dom/power/PowerManagerService.cpp
+++ b/dom/power/PowerManagerService.cpp
@@ -138,17 +138,17 @@ PowerManagerService::NewWakeLock(const n
 
 NS_IMETHODIMP
 PowerManagerService::NewWakeLock(const nsAString &aTopic,
                                  nsPIDOMWindowInner *aWindow,
                                  nsISupports **aWakeLock)
 {
   mozilla::ErrorResult rv;
   RefPtr<WakeLock> wakelock =
-    NewWakeLock(aTopic, nsPIDOMWindowInner::From(aWindow), rv);
+    NewWakeLock(aTopic, aWindow, rv);
   if (rv.Failed()) {
     return rv.StealNSResult();
   }
 
   nsCOMPtr<nsIDOMEventListener> eventListener = wakelock.get();
   eventListener.forget(aWakeLock);
   return NS_OK;
 }
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -247,20 +247,18 @@ LocalStorageManager::GetStorageInternal(
     }
 
     // There is always a single instance of a cache per scope
     // in a single instance of a DOM storage manager.
     cache = PutCache(originAttrSuffix, originKey, aPrincipal);
   }
 
   if (aRetval) {
-    nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow);
-
     nsCOMPtr<nsIDOMStorage> storage = new LocalStorage(
-      inner, this, cache, aDocumentURI, aPrincipal, aPrivate);
+      aWindow, this, cache, aDocumentURI, aPrincipal, aPrivate);
     storage.forget(aRetval);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LocalStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal,
--- a/dom/storage/SessionStorageManager.cpp
+++ b/dom/storage/SessionStorageManager.cpp
@@ -64,20 +64,18 @@ SessionStorageManager::CreateStorage(nsP
   }
 
   RefPtr<SessionStorageCache> cache;
   if (!table->Get(originKey, getter_AddRefs(cache))) {
     cache = new SessionStorageCache();
     table->Put(originKey, cache);
   }
 
-  nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow);
-
   RefPtr<SessionStorage> storage =
-    new SessionStorage(inner, aPrincipal, cache, this, aDocumentURI, aPrivate);
+    new SessionStorage(aWindow, aPrincipal, cache, this, aDocumentURI, aPrivate);
 
   storage.forget(aRetval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SessionStorageManager::GetStorage(nsPIDOMWindowInner* aWindow,
                                   nsIPrincipal* aPrincipal,
@@ -98,20 +96,18 @@ SessionStorageManager::GetStorage(nsPIDO
     return NS_OK;
   }
 
   RefPtr<SessionStorageCache> cache;
   if (!table->Get(originKey, getter_AddRefs(cache))) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow);
-
   RefPtr<SessionStorage> storage =
-    new SessionStorage(inner, aPrincipal, cache, this, EmptyString(), aPrivate);
+    new SessionStorage(aWindow, aPrincipal, cache, this, EmptyString(), aPrivate);
 
   storage.forget(aRetval);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 SessionStorageManager::CloneStorage(nsIDOMStorage* aStorage)
 {
--- a/dom/xbl/nsXBLWindowKeyHandler.cpp
+++ b/dom/xbl/nsXBLWindowKeyHandler.cpp
@@ -593,18 +593,17 @@ nsXBLWindowKeyHandler::IsHTMLEditableFie
   if (!fm)
     return false;
 
   nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
   fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
   if (!focusedWindow)
     return false;
 
-  auto* piwin = nsPIDOMWindowOuter::From(focusedWindow);
-  nsIDocShell *docShell = piwin->GetDocShell();
+  nsIDocShell *docShell = focusedWindow->GetDocShell();
   if (!docShell) {
     return false;
   }
 
   RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
   if (!htmlEditor) {
     return false;
   }
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -179,27 +179,24 @@ nsXULCommandDispatcher::SetFocusedElemen
   return fm->ClearFocus(focusedWindow);
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::SetFocusedWindow(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_TRUE(aWindow, NS_OK); // do nothing if set to null
 
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
-  NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
-
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
 
   // get the containing frame for the window, and set it as focused. This will
   // end up focusing whatever is currently focused inside the frame. Since
   // setting the command dispatcher's focused window doesn't raise the window,
   // setting it to a top-level window doesn't need to do anything.
-  RefPtr<Element> frameElement = window->GetFrameElementInternal();
+  RefPtr<Element> frameElement = aWindow->GetFrameElementInternal();
   if (frameElement) {
     return fm->SetFocus(frameElement, 0);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -112,20 +112,19 @@ nsEditingSession::MakeWindowEditable(nsP
                                      bool aDoAfterUriLoad,
                                      bool aMakeWholeDocumentEditable,
                                      bool aInteractive)
 {
   mEditorType.Truncate();
   mEditorFlags = 0;
 
   NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  auto* window = nsPIDOMWindowOuter::From(aWindow);
 
   // disable plugins
-  nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   mDocShell = do_GetWeakReference(docShell);
   mInteractive = aInteractive;
   mMakeWholeDocumentEditable = aMakeWholeDocumentEditable;
 
   nsresult rv;
   if (!mInteractive) {
@@ -141,17 +140,17 @@ nsEditingSession::MakeWindowEditable(nsP
 
   //temporary to set editor type here. we will need different classes soon.
   if (!aEditorType)
     aEditorType = DEFAULT_EDITOR_TYPE;
   mEditorType = aEditorType;
 
   // if all this does is setup listeners and I don't need listeners,
   // can't this step be ignored?? (based on aDoAfterURILoad)
-  rv = PrepareForEditing(window);
+  rv = PrepareForEditing(aWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // set the flag on the docShell to say that it's editable
   rv = docShell->MakeEditable(aDoAfterUriLoad);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Setup commands common to plaintext and html editors,
   //  including the document creation observers
@@ -183,17 +182,17 @@ nsEditingSession::MakeWindowEditable(nsP
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsEditingSession::DisableJSAndPlugins(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  nsIDocShell *docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  nsIDocShell *docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   bool tmp;
   nsresult rv = docShell->GetAllowJavascript(&tmp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mScriptsEnabled = tmp;
 
@@ -216,17 +215,17 @@ nsEditingSession::RestoreJSAndPlugins(ns
 {
   if (!mDisabledJSAndPlugins) {
     return NS_OK;
   }
 
   mDisabledJSAndPlugins = false;
 
   NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  nsIDocShell *docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  nsIDocShell *docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Disable plugins in this document:
   return docShell->SetAllowPlugins(mPluginsEnabled);
 }
@@ -245,17 +244,17 @@ nsEditingSession::GetJsAndPluginsDisable
 
   boolean windowIsEditable (in nsIDOMWindow aWindow);
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::WindowIsEditable(nsPIDOMWindowOuter* aWindow,
                                    bool *outIsEditable)
 {
   NS_ENSURE_STATE(aWindow);
-  nsCOMPtr<nsIDocShell> docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   NS_ENSURE_STATE(docShell);
 
   return docShell->GetEditable(outIsEditable);
 }
 
 
 // These are MIME types that are automatically parsed as "text/plain"
 //   and thus we can edit them as plaintext
@@ -298,28 +297,27 @@ IsSupportedTextType(const char* aMIMETyp
   nsIEditor setupEditorOnWindow (in nsIDOMWindow aWindow);
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::SetupEditorOnWindow(nsPIDOMWindowOuter* aWindow)
 {
   mDoneSetup = true;
 
   NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  auto* window = nsPIDOMWindowOuter::From(aWindow);
 
   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
   nsAutoCString mimeCType;
 
   //then lets check the mime type
-  if (nsCOMPtr<nsIDocument> doc = window->GetDoc()) {
+  if (nsCOMPtr<nsIDocument> doc = aWindow->GetDoc()) {
     nsAutoString mimeType;
     doc->GetContentType(mimeType);
     AppendUTF16toUTF8(mimeType, mimeCType);
 
     if (IsSupportedTextType(mimeCType.get())) {
       mEditorType.AssignLiteral("text");
       mimeCType = "text/plain";
     } else if (!mimeCType.EqualsLiteral("text/html") &&
@@ -375,27 +373,27 @@ nsEditingSession::SetupEditorOnWindow(ns
   }
 
   // make the UI state maintainer
   mComposerCommandsUpdater = new ComposerCommandsUpdater();
 
   // now init the state maintainer
   // This allows notification of error state
   //  even if we don't create an editor
-  rv = mComposerCommandsUpdater->Init(window);
+  rv = mComposerCommandsUpdater->Init(aWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mEditorStatus != eEditorCreationInProgress) {
     mComposerCommandsUpdater->NotifyDocumentCreated();
     return NS_ERROR_FAILURE;
   }
 
   // Create editor and do other things
   //  only if we haven't found some error above,
-  nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
   nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   if (!mInteractive) {
     // Disable animation of images in this document:
     nsPresContext* presContext = presShell->GetPresContext();
     NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
@@ -525,26 +523,25 @@ nsEditingSession::TearDownEditorOnWindow
   if (mLoadBlankDocTimer) {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nullptr;
   }
 
   mDoneSetup = false;
 
   // Check if we're turning off editing (from contentEditable or designMode).
-  auto* window = nsPIDOMWindowOuter::From(aWindow);
 
-  nsCOMPtr<nsIDocument> doc = window->GetDoc();
+  nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
   nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
   bool stopEditing = htmlDoc && htmlDoc->IsEditingOn();
   if (stopEditing) {
-    RemoveWebProgressListener(window);
+    RemoveWebProgressListener(aWindow);
   }
 
-  nsCOMPtr<nsIDocShell> docShell = window->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   NS_ENSURE_STATE(docShell);
 
   RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
   if (stopEditing) {
     htmlDoc->TearingDownEditor();
   }
 
   if (mComposerCommandsUpdater && htmlEditor) {
@@ -552,22 +549,22 @@ nsEditingSession::TearDownEditorOnWindow
     // references from pointing to a destroyed editor.
     SetEditorOnControllers(aWindow, nullptr);
   }
 
   // Null out the editor on the docShell to trigger PreDestroy which
   // needs to happen before document state listeners are removed below.
   docShell->SetEditor(nullptr);
 
-  RemoveListenersAndControllers(window, htmlEditor);
+  RemoveListenersAndControllers(aWindow, htmlEditor);
 
   if (stopEditing) {
     // Make things the way they were before we started editing.
     RestoreJSAndPlugins(aWindow);
-    RestoreAnimationMode(window);
+    RestoreAnimationMode(aWindow);
 
     if (mMakeWholeDocumentEditable) {
       doc->SetEditableFlag(false);
       nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
       if (htmlDocument) {
         htmlDocument->SetEditingState(nsIHTMLDocument::eOff);
       }
     }
@@ -655,18 +652,17 @@ nsEditingSession::OnStateChange(nsIWebPr
 
       bool progressIsForTargetDocument =
         IsProgressForTargetDocument(aWebProgress);
 
       if (progressIsForTargetDocument) {
         nsCOMPtr<nsPIDOMWindowOuter> window;
         aWebProgress->GetDOMWindow(getter_AddRefs(window));
 
-        auto* piWindow = nsPIDOMWindowOuter::From(window);
-        nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
+        nsCOMPtr<nsIDocument> doc = window->GetDoc();
         nsHTMLDocument* htmlDoc = doc && doc->IsHTMLOrXHTML()
           ? doc->AsHTMLDocument() : nullptr;
         if (htmlDoc && htmlDoc->IsWriting()) {
           nsAutoString designMode;
           htmlDoc->GetDesignMode(designMode);
 
           if (designMode.EqualsLiteral("on")) {
             // This notification is for data coming in through
@@ -768,26 +764,24 @@ NS_IMETHODIMP
 nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress,
                                    nsIRequest *aRequest, nsIURI *aURI,
                                    uint32_t aFlags)
 {
   nsCOMPtr<nsPIDOMWindowOuter> domWindow;
   nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  auto* piWindow = nsPIDOMWindowOuter::From(domWindow);
-
-  nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
+  nsCOMPtr<nsIDocument> doc = domWindow->GetDoc();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   doc->SetDocumentURI(aURI);
 
   // Notify the location-changed observer that
   //  the document URL has changed
-  nsIDocShell *docShell = piWindow->GetDocShell();
+  nsIDocShell *docShell = domWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsICommandManager> commandManager = docShell->GetCommandManager();
   nsCOMPtr<nsPICommandUpdater> commandUpdater =
                                   do_QueryInterface(commandManager);
   NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
 
   return commandUpdater->CommandStatusChanged("obs_documentLocationChanged");
@@ -910,17 +904,17 @@ nsEditingSession::EndDocumentLoad(nsIWeb
   NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
 
   // Set the error state -- we will create an editor
   // anyway and load empty doc later
   if (aIsToBeMadeEditable && aStatus == NS_ERROR_FILE_NOT_FOUND) {
     mEditorStatus = eEditorErrorFileNotFound;
   }
 
-  nsIDocShell *docShell = nsPIDOMWindowOuter::From(domWindow)->GetDocShell();
+  nsIDocShell *docShell = domWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);       // better error handling?
 
   // cancel refresh from meta tags
   // we need to make sure that all pages in editor (whether editable or not)
   // can't refresh contents being edited
   nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
   if (refreshURI) {
     refreshURI->CancelRefreshURITimers();
@@ -1034,17 +1028,17 @@ nsEditingSession::EndPageLoad(nsIWebProg
   if (aStatus == NS_ERROR_FILE_NOT_FOUND) {
     mEditorStatus = eEditorErrorFileNotFound;
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> domWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
 
   nsIDocShell *docShell =
-    domWindow ? nsPIDOMWindowOuter::From(domWindow)->GetDocShell() : nullptr;
+    domWindow ? domWindow->GetDocShell() : nullptr;
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   // cancel refresh from meta tags
   // we need to make sure that all pages in editor (whether editable or not)
   // can't refresh contents being edited
   nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
   if (refreshURI) {
     refreshURI->CancelRefreshURITimers();
@@ -1102,21 +1096,18 @@ 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);
 
-  auto* piWindow = nsPIDOMWindowOuter::From(aWindow);
-  MOZ_ASSERT(piWindow);
-
   nsCOMPtr<nsIControllers> controllers;
-  nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
+  nsresult rv = aWindow->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);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -1143,20 +1134,18 @@ nsEditingSession::SetupEditorCommandCont
   Set the editor on the controller(s) for this window
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::SetEditorOnControllers(nsPIDOMWindowOuter* aWindow,
                                          nsIEditor* aEditor)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
 
-  auto* piWindow = nsPIDOMWindowOuter::From(aWindow);
-
   nsCOMPtr<nsIControllers> controllers;
-  nsresult rv = piWindow->GetControllers(getter_AddRefs(controllers));
+  nsresult rv = aWindow->GetControllers(getter_AddRefs(controllers));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISupports> editorAsISupports = static_cast<nsISupports*>(aEditor);
   if (mBaseCommandControllerId) {
     rv = SetContextOnControllerById(controllers, editorAsISupports,
                                     mBaseCommandControllerId);
     NS_ENSURE_SUCCESS(rv, rv);
   }
@@ -1275,24 +1264,22 @@ nsEditingSession::DetachFromWindow(nsPID
                "mComposerCommandsUpdater should exist.");
 
   // Kill any existing reload timer
   if (mLoadBlankDocTimer) {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nullptr;
   }
 
-  auto* window = nsPIDOMWindowOuter::From(aWindow);
-
   // Remove controllers, webprogress listener, and otherwise
   // make things the way they were before we started editing.
-  RemoveEditorControllers(window);
-  RemoveWebProgressListener(window);
+  RemoveEditorControllers(aWindow);
+  RemoveWebProgressListener(aWindow);
   RestoreJSAndPlugins(aWindow);
-  RestoreAnimationMode(window);
+  RestoreAnimationMode(aWindow);
 
   // Kill our weak reference to our original window, in case
   // it changes on restore, or otherwise dies.
   mDocShell = nullptr;
 
   return NS_OK;
 }
 
@@ -1304,49 +1291,48 @@ nsEditingSession::ReattachToWindow(nsPID
 
   NS_ASSERTION(mComposerCommandsUpdater,
                "mComposerCommandsUpdater should exist.");
 
   // Imitate nsEditorDocShell::MakeEditable() to reattach the
   // old editor ot the window.
   nsresult rv;
 
-  auto* window = nsPIDOMWindowOuter::From(aWindow);
-  nsIDocShell *docShell = window->GetDocShell();
+  nsIDocShell *docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
   mDocShell = do_GetWeakReference(docShell);
 
   // Disable plugins.
   if (!mInteractive) {
     rv = DisableJSAndPlugins(aWindow);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Tells embedder that startup is in progress.
   mEditorStatus = eEditorCreationInProgress;
 
   // Adds back web progress listener.
-  rv = PrepareForEditing(window);
+  rv = PrepareForEditing(aWindow);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Setup the command controllers again.
   rv = SetupEditorCommandController("@mozilla.org/editor/editingcontroller;1",
                                     aWindow,
                                     static_cast<nsIEditingSession*>(this),
                                     &mBaseCommandControllerId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = SetupEditorCommandController("@mozilla.org/editor/editordocstatecontroller;1",
                                     aWindow,
                                     static_cast<nsIEditingSession*>(this),
                                     &mDocStateControllerId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mComposerCommandsUpdater) {
-    mComposerCommandsUpdater->Init(window);
+    mComposerCommandsUpdater->Init(aWindow);
   }
 
   // Get editor
   RefPtr<HTMLEditor> htmlEditor = GetHTMLEditorForWindow(aWindow);
   if (NS_WARN_IF(!htmlEditor)) {
     return NS_ERROR_FAILURE;
   }
 
@@ -1386,16 +1372,15 @@ nsEditingSession::ReattachToWindow(nsPID
 
 HTMLEditor*
 nsIEditingSession::GetHTMLEditorForWindow(nsPIDOMWindowOuter* aWindow)
 {
   if (NS_WARN_IF(!aWindow)) {
     return nullptr;
   }
 
-  nsCOMPtr<nsIDocShell> docShell =
-    nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   if (NS_WARN_IF(!docShell)) {
     return nullptr;
   }
 
   return docShell->GetHTMLEditor();
 }
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -2187,20 +2187,19 @@ nsPermissionManager::TestPermission(nsIU
 }
 
 NS_IMETHODIMP
 nsPermissionManager::TestPermissionFromWindow(nsPIDOMWindowInner* aWindow,
                                               const char* aType,
                                               uint32_t* aPermission)
 {
   NS_ENSURE_ARG(aWindow);
-  nsCOMPtr<nsPIDOMWindowInner> window = nsPIDOMWindowInner::From(aWindow);
 
   // Get the document for security check
-  nsCOMPtr<nsIDocument> document = window->GetExtantDoc();
+  nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
   NS_ENSURE_TRUE(document, NS_NOINTERFACE);
 
   nsCOMPtr<nsIPrincipal> principal = document->NodePrincipal();
   return TestPermissionFromPrincipal(principal, aType, aPermission);
 }
 
 NS_IMETHODIMP
 nsPermissionManager::TestPermissionFromPrincipal(nsIPrincipal* aPrincipal,
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1020,17 +1020,17 @@ XPCConvert::JSObject2NativeInterface(voi
             if (iface && NS_SUCCEEDED(iface->QueryInterface(*iid, dest))) {
                 return true;
             }
 
             // If that failed, and iid is for nsPIDOMWindowOuter, we actually
             // want the outer!
             if (iid->Equals(NS_GET_IID(nsPIDOMWindowOuter))) {
                 if (nsCOMPtr<nsPIDOMWindowInner> inner = do_QueryInterface(iface)) {
-                    iface = nsPIDOMWindowInner::From(inner)->GetOuterWindow();
+                    iface = inner->GetOuterWindow();
                     return NS_SUCCEEDED(iface->QueryInterface(*iid, dest));
                 }
             }
 
             return false;
         }
 
         // NOTE(nika): Remove if Promise becomes non-nsISupports
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -1052,19 +1052,17 @@ nsPrintJob::PrintPreview(nsIPrintSetting
   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;
   }
 
-  auto* window = nsPIDOMWindowOuter::From(aChildDOMWin);
-  NS_ENSURE_STATE(window);
-  nsCOMPtr<nsIDocument> doc = window->GetDoc();
+  nsCOMPtr<nsIDocument> doc = aChildDOMWin->GetDoc();
   NS_ENSURE_STATE(doc);
 
   // Document is not busy -- go ahead with the Print Preview
   return CommonPrint(true, aPrintSettings, aWebProgressListener, doc);
 }
 
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP
--- a/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
+++ b/layout/tools/layout-debug/src/nsLayoutDebuggingTools.cpp
@@ -96,18 +96,17 @@ nsLayoutDebuggingTools::Init(nsPIDOMWind
 {
     if (!Preferences::GetService()) {
         return NS_ERROR_UNEXPECTED;
     }
 
     {
         if (!aWin)
             return NS_ERROR_UNEXPECTED;
-        auto* window = nsPIDOMWindowInner::From(aWin);
-        mDocShell = window->GetDocShell();
+        mDocShell = aWin->GetDocShell();
     }
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_UNEXPECTED);
 
     mPaintFlashing =
         Preferences::GetBool("nglayout.debug.paint_flashing", mPaintFlashing);
     mPaintDumping =
         Preferences::GetBool("nglayout.debug.paint_dumping", mPaintDumping);
     mInvalidateDumping =
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -861,20 +861,17 @@ CheckCaretDrawingState()
   // document and erase its caret.
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (fm) {
     nsCOMPtr<nsPIDOMWindowOuter> window;
     fm->GetFocusedWindow(getter_AddRefs(window));
     if (!window)
       return;
 
-    auto* piWindow = nsPIDOMWindowOuter::From(window);
-    MOZ_ASSERT(piWindow);
-
-    nsCOMPtr<nsIDocument> focusedDoc = piWindow->GetDoc();
+    nsCOMPtr<nsIDocument> focusedDoc = window->GetDoc();
     if (!focusedDoc)
       return;
 
     nsIPresShell* presShell = focusedDoc->GetShell();
     if (!presShell)
       return;
 
     RefPtr<nsCaret> caret = presShell->GetCaret();
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -504,18 +504,17 @@ nsChannelClassifier::NotifyTrackingProte
     nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
         do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsPIDOMWindowOuter> win;
     rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, getter_AddRefs(win));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    auto* pwin = nsPIDOMWindowOuter::From(win);
-    nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
+    nsCOMPtr<nsIDocShell> docShell = win->GetDocShell();
     if (!docShell) {
       return NS_OK;
     }
     nsCOMPtr<nsIDocument> doc = docShell->GetDocument();
     NS_ENSURE_TRUE(doc, NS_OK);
 
     // Notify nsIWebProgressListeners of this security event.
     // Can be used to change the UI state.
@@ -830,18 +829,17 @@ nsChannelClassifier::SetBlockedContent(n
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> win;
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
     do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, NS_OK);
   rv = thirdPartyUtil->GetTopWindowForChannel(channel, getter_AddRefs(win));
   NS_ENSURE_SUCCESS(rv, NS_OK);
-  auto* pwin = nsPIDOMWindowOuter::From(win);
-  nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = win->GetDocShell();
   if (!docShell) {
     return NS_OK;
   }
   nsCOMPtr<nsIDocument> doc = docShell->GetDocument();
   NS_ENSURE_TRUE(doc, NS_OK);
 
   // This event might come after the user has navigated to another page.
   // To prevent showing the TrackingProtection UI on the wrong page, we need to
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -504,18 +504,17 @@ HttpBaseChannel::SetDocshellUserAgentOve
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> domWindow;
   loadContext->GetAssociatedWindow(getter_AddRefs(domWindow));
   if (!domWindow) {
     return NS_OK;
   }
 
-  auto* pDomWindow = nsPIDOMWindowOuter::From(domWindow);
-  nsIDocShell* docshell = pDomWindow->GetDocShell();
+  nsIDocShell* docshell = domWindow->GetDocShell();
   if (!docshell) {
     return NS_OK;
   }
 
   nsString customUserAgent;
   docshell->GetCustomUserAgent(customUserAgent);
   if (customUserAgent.IsEmpty()) {
     return NS_OK;
@@ -4324,21 +4323,17 @@ HttpBaseChannel::GetInnerDOMWindow()
     if (!loadContext) {
         return nullptr;
     }
     nsCOMPtr<nsPIDOMWindowOuter> domWindow;
     loadContext->GetAssociatedWindow(getter_AddRefs(domWindow));
     if (!domWindow) {
         return nullptr;
     }
-    auto* pDomWindow = nsPIDOMWindowOuter::From(domWindow);
-    if (!pDomWindow) {
-        return nullptr;
-    }
-    nsCOMPtr<nsPIDOMWindowInner> innerWindow = pDomWindow->GetCurrentInnerWindow();
+    nsCOMPtr<nsPIDOMWindowInner> innerWindow = domWindow->GetCurrentInnerWindow();
     if (!innerWindow) {
       return nullptr;
     }
 
     return innerWindow;
 }
 
 //-----------------------------------------------------------------------------
@@ -4437,18 +4432,17 @@ HttpBaseChannel::EnsureTopLevelOuterCont
   }
 
   nsCOMPtr<nsPIDOMWindowOuter> topWindow;
   loadContext->GetTopWindow(getter_AddRefs(topWindow));
   if (!topWindow) {
     return;
   }
 
-  mTopLevelOuterContentWindowId =
-    nsPIDOMWindowOuter::From(topWindow)->WindowID();
+  mTopLevelOuterContentWindowId = topWindow->WindowID();
 }
 
 void
 HttpBaseChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHeaders)
 {
   MOZ_RELEASE_ASSERT(!mRequestObserversCalled);
 
   mRequireCORSPreflight = true;
--- a/security/manager/ssl/nsSecureBrowserUIImpl.cpp
+++ b/security/manager/ssl/nsSecureBrowserUIImpl.cpp
@@ -114,18 +114,17 @@ nsSecureBrowserUIImpl::Init(nsPIDOMWindo
     NS_WARNING("Trying to init an nsSecureBrowserUIImpl twice");
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
   nsresult rv;
   mWindow = do_GetWeakReference(aWindow, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  auto* piwindow = nsPIDOMWindowOuter::From(aWindow);
-  nsIDocShell *docShell = piwindow->GetDocShell();
+  nsIDocShell *docShell = aWindow->GetDocShell();
 
   // The Docshell will own the SecureBrowserUI object
   if (!docShell)
     return NS_ERROR_FAILURE;
 
   docShell->SetSecurityUI(this);
 
   /* GetWebProgress(mWindow) */
--- a/toolkit/components/alerts/nsXULAlerts.cpp
+++ b/toolkit/components/alerts/nsXULAlerts.cpp
@@ -370,15 +370,14 @@ nsXULAlerts::GetManualDoNotDisturb(bool*
   *aRetVal = mDoNotDisturb;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULAlerts::CloseAlert(const nsAString& aAlertName,
                         nsIPrincipal* aPrincipal)
 {
-  nsPIDOMWindowOuter* alert = mNamedWindows.GetWeak(aAlertName);
-  if (nsCOMPtr<nsPIDOMWindowOuter> domWindow = nsPIDOMWindowOuter::From(alert)) {
-    domWindow->DispatchCustomEvent(NS_LITERAL_STRING("XULAlertClose"));
+  if (nsCOMPtr<nsPIDOMWindowOuter> alert = mNamedWindows.GetWeak(aAlertName)) {
+    alert->DispatchCustomEvent(NS_LITERAL_STRING("XULAlertClose"));
   }
   return NS_OK;
 }
 
--- a/toolkit/components/printingui/ipc/nsPrintingProxy.cpp
+++ b/toolkit/components/printingui/ipc/nsPrintingProxy.cpp
@@ -76,19 +76,17 @@ nsPrintingProxy::ShowPrintDialog(nsPIDOM
   NS_ENSURE_ARG(printSettings);
 
   // If parent is null we are just being called to retrieve the print settings
   // from the printer in the parent for print preview.
   TabChild* pBrowser = nullptr;
   if (parent) {
     // Get the TabChild for this nsIDOMWindow, which we can then pass up to
     // the parent.
-    nsCOMPtr<nsPIDOMWindowOuter> pwin = nsPIDOMWindowOuter::From(parent);
-    NS_ENSURE_STATE(pwin);
-    nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
+    nsCOMPtr<nsIDocShell> docShell = parent->GetDocShell();
     NS_ENSURE_STATE(docShell);
 
     nsCOMPtr<nsITabChild> tabchild = docShell->GetTabChild();
     NS_ENSURE_STATE(tabchild);
 
     pBrowser = static_cast<TabChild*>(tabchild.get());
   }
 
@@ -135,19 +133,17 @@ nsPrintingProxy::ShowProgress(nsPIDOMWin
 {
   NS_ENSURE_ARG(parent);
   NS_ENSURE_ARG(webProgressListener);
   NS_ENSURE_ARG(printProgressParams);
   NS_ENSURE_ARG(notifyOnOpen);
 
   // Get the TabChild for this nsIDOMWindow, which we can then pass up to
   // the parent.
-  nsCOMPtr<nsPIDOMWindowOuter> pwin = nsPIDOMWindowOuter::From(parent);
-  NS_ENSURE_STATE(pwin);
-  nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = parent->GetDocShell();
   NS_ENSURE_STATE(docShell);
   nsCOMPtr<nsITabChild> tabchild = docShell->GetTabChild();
   TabChild* pBrowser = static_cast<TabChild*>(tabchild.get());
 
   RefPtr<PrintProgressDialogChild> dialogChild =
     new PrintProgressDialogChild(openDialogObserver, printSettings);
 
   SendPPrintProgressDialogConstructor(dialogChild);
--- a/toolkit/components/printingui/nsPrintProgress.cpp
+++ b/toolkit/components/printingui/nsPrintProgress.cpp
@@ -72,37 +72,33 @@ NS_IMETHODIMP nsPrintProgress::OpenProgr
 
     array->AppendElement(ifptr);
 
     array->AppendElement(parameters);
 
     // We will set the opener of the dialog to be the nsIDOMWindow for the
     // browser XUL window itself, as opposed to the content. That way, the
     // progress window has access to the opener.
-    nsCOMPtr<nsPIDOMWindowOuter> pParentWindow = nsPIDOMWindowOuter::From(parent);
-    NS_ENSURE_STATE(pParentWindow);
-    nsCOMPtr<nsIDocShell> docShell = pParentWindow->GetDocShell();
+    nsCOMPtr<nsIDocShell> docShell = parent->GetDocShell();
     NS_ENSURE_STATE(docShell);
 
     nsCOMPtr<nsIDocShellTreeOwner> owner;
     docShell->GetTreeOwner(getter_AddRefs(owner));
 
     nsCOMPtr<nsIXULWindow> ownerXULWindow = do_GetInterface(owner);
     nsCOMPtr<nsPIDOMWindowOuter> ownerWindow = do_GetInterface(ownerXULWindow);
     NS_ENSURE_STATE(ownerWindow);
 
-    nsCOMPtr<nsPIDOMWindowOuter> piOwnerWindow = nsPIDOMWindowOuter::From(ownerWindow);
-
     // Open the dialog.
     nsCOMPtr<nsPIDOMWindowOuter> newWindow;
 
-    rv = piOwnerWindow->OpenDialog(NS_ConvertASCIItoUTF16(dialogURL),
-                                   NS_LITERAL_STRING("_blank"),
-                                   NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
-                                   array, getter_AddRefs(newWindow));
+    rv = ownerWindow->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;
--- a/toolkit/components/printingui/nsPrintingPromptService.cpp
+++ b/toolkit/components/printingui/nsPrintingPromptService.cpp
@@ -74,18 +74,17 @@ nsPrintingPromptService::ShowPrintDialog
                                          nsIPrintSettings* printSettings)
 {
   NS_ENSURE_ARG(webBrowserPrint);
   NS_ENSURE_ARG(printSettings);
 
   nsCOMPtr<nsIPrintDialogService> dlgPrint(
     do_GetService(NS_PRINTDIALOGSERVICE_CONTRACTID));
   if (dlgPrint)
-    return dlgPrint->Show(
-      nsPIDOMWindowOuter::From(parent), printSettings, webBrowserPrint);
+    return dlgPrint->Show(parent, printSettings, webBrowserPrint);
 
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsPrintingPromptService::ShowProgress(
   nsPIDOMWindowOuter* parent,
   nsIWebBrowserPrint* webBrowserPrint, // ok to be null
@@ -143,18 +142,17 @@ NS_IMETHODIMP
 nsPrintingPromptService::ShowPageSetup(nsPIDOMWindowOuter* parent,
                                        nsIPrintSettings* printSettings)
 {
   NS_ENSURE_ARG(printSettings);
 
   nsCOMPtr<nsIPrintDialogService> dlgPrint(
     do_GetService(NS_PRINTDIALOGSERVICE_CONTRACTID));
   if (dlgPrint)
-    return dlgPrint->ShowPageSetup(nsPIDOMWindowOuter::From(parent),
-                                   printSettings);
+    return dlgPrint->ShowPageSetup(parent, printSettings);
 
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsPrintingPromptService::OnStateChange(nsIWebProgress* aWebProgress,
                                        nsIRequest* aRequest,
                                        uint32_t aStateFlags,
--- a/toolkit/components/remote/nsGTKRemoteService.cpp
+++ b/toolkit/components/remote/nsGTKRemoteService.cpp
@@ -58,17 +58,17 @@ static nsIWidget* GetMainWidget(nsPIDOMW
   nsCOMPtr<nsIWidget> mainWidget;
   baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
   return mainWidget;
 }
 
 NS_IMETHODIMP
 nsGTKRemoteService::RegisterWindow(nsPIDOMWindowInner* aWindow)
 {
-  nsIWidget* mainWidget = GetMainWidget(nsPIDOMWindowInner::From(aWindow));
+  nsIWidget* mainWidget = GetMainWidget(aWindow);
   NS_ENSURE_TRUE(mainWidget, NS_ERROR_FAILURE);
 
   GtkWidget* widget =
     (GtkWidget*) mainWidget->GetNativeData(NS_NATIVE_SHELLWIDGET);
   NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIWeakReference> weak = do_GetWeakReference(aWindow);
   NS_ENSURE_TRUE(weak, NS_ERROR_FAILURE);
--- a/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
+++ b/toolkit/components/sessionstore/nsSessionStoreUtils.cpp
@@ -77,20 +77,17 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(Dynamic
 NS_IMPL_ISUPPORTS(nsSessionStoreUtils, nsISessionStoreUtils)
 
 NS_IMETHODIMP
 nsSessionStoreUtils::ForEachNonDynamicChildFrame(nsPIDOMWindowOuter* aWindow,
                                                  nsISessionStoreUtilsFrameCallback* aCallback)
 {
   NS_ENSURE_TRUE(aWindow, NS_ERROR_INVALID_ARG);
 
-  nsCOMPtr<nsPIDOMWindowOuter> outer = nsPIDOMWindowOuter::From(aWindow);
-  NS_ENSURE_TRUE(outer, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIDocShell> docShell = outer->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   int32_t length;
   nsresult rv = docShell->GetChildCount(&length);
   NS_ENSURE_SUCCESS(rv, rv);
 
   for (int32_t i = 0; i < length; ++i) {
     nsCOMPtr<nsIDocShellTreeItem> item;
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -555,19 +555,18 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
         /* If a search result is found inside an editable element, we'll focus
          * the element only if focus is in our content window, i.e.
          * |if (focusedWindow.top == ourWindow.top)| */
         bool shouldFocusEditableElement = false;
         if (fm) {
           nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
           nsresult rv = fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
           if (NS_SUCCEEDED(rv) && focusedWindow) {
-            auto* fwPI = nsPIDOMWindowOuter::From(focusedWindow);
             nsCOMPtr<nsIDocShellTreeItem> fwTreeItem
-              (do_QueryInterface(fwPI->GetDocShell(), &rv));
+              (do_QueryInterface(focusedWindow->GetDocShell(), &rv));
             if (NS_SUCCEEDED(rv)) {
               nsCOMPtr<nsIDocShellTreeItem> fwRootTreeItem;
               rv = fwTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(fwRootTreeItem));
               if (NS_SUCCEEDED(rv) && fwRootTreeItem == rootContentTreeItem)
                 shouldFocusEditableElement = true;
             }
           }
         }
--- a/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
@@ -597,18 +597,17 @@ AddTabThreatSources(ThreatHit& aHit, nsI
   nsCOMPtr<nsPIDOMWindowOuter> win;
   nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
     do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, getter_AddRefs(win));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  auto* pwin = nsPIDOMWindowOuter::From(win);
-  nsCOMPtr<nsIDocShell> docShell = pwin->GetDocShell();
+  nsCOMPtr<nsIDocShell> docShell = win->GetDocShell();
   if (!docShell) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIChannel> topChannel;
   docShell->GetCurrentDocumentChannel(getter_AddRefs(topChannel));
   if (!topChannel) {
     return NS_OK;
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -654,28 +654,25 @@ nsWindowWatcher::OpenWindowInternal(nsPI
 
   uint32_t chromeFlags;
   nsAutoString name;          // string version of aName
   nsAutoCString features;     // string version of aFeatures
   nsCOMPtr<nsIURI> uriToLoad; // from aUrl, if any
   nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner; // from the parent window, if any
   nsCOMPtr<nsIDocShellTreeItem> newDocShellItem; // from the new window
 
-  nsCOMPtr<nsPIDOMWindowOuter> parent =
-    aParent ? nsPIDOMWindowOuter::From(aParent) : nullptr;
-
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = 0;
 
   if (!nsContentUtils::IsSafeToRunScript()) {
     nsContentUtils::WarnScriptWasIgnored(nullptr);
     return NS_ERROR_FAILURE;
   }
 
-  GetWindowTreeOwner(parent, getter_AddRefs(parentTreeOwner));
+  GetWindowTreeOwner(aParent, getter_AddRefs(parentTreeOwner));
 
   // We expect TabParent to have provided us the absolute URI of the window
   // we're to open, so there's no need to call URIfromURL (or more importantly,
   // to check for a chrome URI, which cannot be opened from a remote tab).
   if (aUrl) {
     rv = URIfromURL(aUrl, aParent, getter_AddRefs(uriToLoad));
     if (NS_FAILED(rv)) {
       return rv;
@@ -701,36 +698,34 @@ nsWindowWatcher::OpenWindowInternal(nsPI
   // try to find an extant window with the given name
   nsCOMPtr<nsPIDOMWindowOuter> foundWindow =
     SafeGetWindowByName(name, aForceNoOpener, aParent);
   GetWindowTreeItem(foundWindow, getter_AddRefs(newDocShellItem));
 
   // Do sandbox checks here, instead of waiting until nsIDocShell::LoadURI.
   // The state of the window can change before this call and if we are blocked
   // because of sandboxing, we wouldn't want that to happen.
-  nsCOMPtr<nsPIDOMWindowOuter> parentWindow =
-    aParent ? nsPIDOMWindowOuter::From(aParent) : nullptr;
   nsCOMPtr<nsIDocShell> parentDocShell;
-  if (parentWindow) {
-    parentDocShell = parentWindow->GetDocShell();
+  if (aParent) {
+    parentDocShell = aParent->GetDocShell();
     if (parentDocShell) {
       nsCOMPtr<nsIDocShell> foundDocShell = do_QueryInterface(newDocShellItem);
       if (parentDocShell->IsSandboxedFrom(foundDocShell)) {
         return NS_ERROR_DOM_INVALID_ACCESS_ERR;
       }
     }
   }
 
   // no extant window? make a new one.
 
   // If no parent, consider it chrome when running in the parent process.
   bool hasChromeParent = XRE_IsContentProcess() ? false : true;
   if (aParent) {
     // Check if the parent document has chrome privileges.
-    nsIDocument* doc = parentWindow->GetDoc();
+    nsIDocument* doc = aParent->GetDoc();
     hasChromeParent = doc && nsContentUtils::IsChromeDoc(doc);
   }
 
   bool isCallerChrome = nsContentUtils::LegacyIsCallerChromeOrNativeCode();
 
   // Make sure we calculate the chromeFlags *before* we push the
   // callee context onto the context stack so that
   // the calculation sees the actual caller when doing its
@@ -788,17 +783,17 @@ nsWindowWatcher::OpenWindowInternal(nsPI
     // 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) {
-      if (nsIDocument* doc = parentWindow->GetDoc()) {
+      if (nsIDocument* doc = aParent->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;
         }
       }
     }
 
@@ -908,18 +903,18 @@ nsWindowWatcher::OpenWindowInternal(nsPI
 
     NS_ASSERTION(mWindowCreator,
                  "attempted to open a new window with no WindowCreator");
     rv = NS_ERROR_FAILURE;
     if (mWindowCreator) {
       nsCOMPtr<nsIWebBrowserChrome> newChrome;
 
       nsCOMPtr<nsPIDOMWindowInner> parentTopInnerWindow;
-      if (parentWindow) {
-        nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow = parentWindow->GetTop();
+      if (aParent) {
+        nsCOMPtr<nsPIDOMWindowOuter> parentTopWindow = aParent->GetTop();
         if (parentTopWindow) {
           parentTopInnerWindow = parentTopWindow->GetCurrentInnerWindow();
         }
       }
 
       if (parentTopInnerWindow) {
         parentTopInnerWindow->Suspend();
       }
@@ -949,17 +944,17 @@ nsWindowWatcher::OpenWindowInternal(nsPI
       }
 
       if (newChrome) {
         nsCOMPtr<nsIXULWindow> xulWin = do_GetInterface(newChrome);
         if (xulWin) {
           nsCOMPtr<nsIXULBrowserWindow> xulBrowserWin;
           xulWin->GetXULBrowserWindow(getter_AddRefs(xulBrowserWin));
           if (xulBrowserWin) {
-            nsPIDOMWindowOuter* openerWindow = aForceNoOpener ? nullptr : parentWindow.get();
+            nsPIDOMWindowOuter* openerWindow = aForceNoOpener ? nullptr : aParent;
             xulBrowserWin->ForceInitialBrowserNonRemote(openerWindow);
           }
         }
         /* It might be a chrome nsXULWindow, in which case it won't have
             an nsIDOMWindow (primary content shell). But in that case, it'll
             be able to hand over an nsIDocShellTreeItem directly. */
         nsCOMPtr<nsPIDOMWindowOuter> newWindow(do_GetInterface(newChrome));
         if (newWindow) {
@@ -980,30 +975,30 @@ nsWindowWatcher::OpenWindowInternal(nsPI
     return rv;
   }
 
   nsCOMPtr<nsIDocShell> newDocShell(do_QueryInterface(newDocShellItem));
   NS_ENSURE_TRUE(newDocShell, NS_ERROR_UNEXPECTED);
 
   // If our parent is sandboxed, set it as the one permitted sandboxed navigator
   // on the new window we're opening.
-  if (activeDocsSandboxFlags && parentWindow) {
+  if (activeDocsSandboxFlags && aParent) {
     newDocShell->SetOnePermittedSandboxedNavigator(
-      parentWindow->GetDocShell());
+      aParent->GetDocShell());
   }
 
   // Copy sandbox flags to the new window if activeDocsSandboxFlags says to do
   // so.  Note that it's only nonzero if the window is new, so clobbering
   // sandbox flags on the window makes sense in that case.
   if (activeDocsSandboxFlags &
         SANDBOX_PROPAGATES_TO_AUXILIARY_BROWSING_CONTEXTS) {
     newDocShell->SetSandboxFlags(activeDocsSandboxFlags);
   }
 
-  rv = ReadyOpenedDocShellItem(newDocShellItem, parentWindow, windowIsNew,
+  rv = ReadyOpenedDocShellItem(newDocShellItem, aParent, windowIsNew,
                                aForceNoOpener, aResult);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   if (isNewToplevelWindow) {
     nsCOMPtr<nsIDocShellTreeOwner> newTreeOwner;
     newDocShellItem->GetTreeOwner(getter_AddRefs(newTreeOwner));
@@ -1133,18 +1128,18 @@ nsWindowWatcher::OpenWindowInternal(nsPI
 
     /* use the URL from the *extant* document, if any. The usual accessor
        GetDocument will synchronously create an about:blank document if
        it has no better answer, and we only care about a real document.
        Also using GetDocument to force document creation seems to
        screw up focus in the hidden window; see bug 36016.
     */
     nsCOMPtr<nsIDocument> doc = GetEntryDocument();
-    if (!doc && parentWindow) {
-      doc = parentWindow->GetExtantDoc();
+    if (!doc && aParent) {
+      doc = aParent->GetExtantDoc();
     }
     if (doc) {
       // Set the referrer
       loadInfo->SetReferrer(doc->GetDocumentURI());
       loadInfo->SetReferrerPolicy(doc->GetReferrerPolicy());
     }
   }
 
@@ -1200,17 +1195,17 @@ nsWindowWatcher::OpenWindowInternal(nsPI
   if (!aForceNoOpener && subjectPrincipal && parentDocShell) {
     nsCOMPtr<nsIDOMStorageManager> parentStorageManager =
       do_QueryInterface(parentDocShell);
     nsCOMPtr<nsIDOMStorageManager> newStorageManager =
       do_QueryInterface(newDocShell);
 
     if (parentStorageManager && newStorageManager) {
       nsCOMPtr<nsIDOMStorage> storage;
-      nsCOMPtr<nsPIDOMWindowInner> pInnerWin = parentWindow->GetCurrentInnerWindow();
+      nsCOMPtr<nsPIDOMWindowInner> pInnerWin = aParent->GetCurrentInnerWindow();
       parentStorageManager->GetStorage(pInnerWin, subjectPrincipal,
                                        isPrivateBrowsingWindow,
                                        getter_AddRefs(storage));
       if (storage) {
         newStorageManager->CloneStorage(storage);
       }
     }
   }
@@ -1234,17 +1229,17 @@ nsWindowWatcher::OpenWindowInternal(nsPI
     // Dispatch dialog events etc, but we only want to do that if
     // we're opening a modal content window (the helper classes are
     // no-ops if given no window), for chrome dialogs we don't want to
     // do any of that (it's done elsewhere for us).
     // Make sure we maintain the state on an outer window, because
     // that's where it lives; inner windows assert if you try to
     // maintain the state on them.
     nsAutoWindowStateHelper windowStateHelper(
-      parentWindow ? parentWindow->GetOuterWindow() : nullptr);
+      aParent ? aParent->GetOuterWindow() : nullptr);
 
     if (!windowStateHelper.DefaultEnabled()) {
       // Default to cancel not opening the modal window.
       NS_RELEASE(*aResult);
 
       return NS_OK;
     }
 
@@ -1570,23 +1565,20 @@ nsWindowWatcher::GetWindowByName(const n
                                  nsPIDOMWindowOuter** aResult)
 {
   if (!aResult) {
     return NS_ERROR_INVALID_ARG;
   }
 
   *aResult = nullptr;
 
-  nsPIDOMWindowOuter* currentWindow =
-    aCurrentWindow ? nsPIDOMWindowOuter::From(aCurrentWindow) : nullptr;
-
   nsCOMPtr<nsIDocShellTreeItem> treeItem;
 
   nsCOMPtr<nsIDocShellTreeItem> startItem;
-  GetWindowTreeItem(currentWindow, getter_AddRefs(startItem));
+  GetWindowTreeItem(aCurrentWindow, getter_AddRefs(startItem));
   if (startItem) {
     // Note: original requestor is null here, per idl comments
     startItem->FindItemWithName(aTargetName, nullptr, nullptr,
                                 /* aSkipTabGroup = */ false,
                                 getter_AddRefs(treeItem));
   } else {
     // Note: original requestor is null here, per idl comments
     FindItemWithName(aTargetName, nullptr, nullptr, getter_AddRefs(treeItem));
@@ -1619,17 +1611,17 @@ nsWindowWatcher::URIfromURL(const char* 
                             nsPIDOMWindowOuter* aParent,
                             nsIURI** aURI)
 {
   // Build the URI relative to the entry global.
   nsCOMPtr<nsPIDOMWindowInner> baseWindow = do_QueryInterface(GetEntryGlobal());
 
   // failing that, build it relative to the parent window, if possible
   if (!baseWindow && aParent) {
-    baseWindow = nsPIDOMWindowOuter::From(aParent)->GetCurrentInnerWindow();
+    baseWindow = aParent->GetCurrentInnerWindow();
   }
 
   // failing that, use the given URL unmodified. It had better not be relative.
 
   nsIURI* baseURI = nullptr;
 
   // get baseWindow's document URI
   if (baseWindow) {
@@ -2207,18 +2199,17 @@ nsWindowWatcher::SizeOpenedWindow(nsIDoc
   // get various interfaces for aDocShellItem, used throughout this method
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(aTreeOwner));
   if (!treeOwnerAsWin) { // we'll need this to actually size the docshell
     return;
   }
 
   double openerZoom = aOpenerFullZoom.valueOr(1.0);
   if (aParent && aOpenerFullZoom.isNothing()) {
-    nsCOMPtr<nsPIDOMWindowOuter> piWindow = nsPIDOMWindowOuter::From(aParent);
-    if (nsIDocument* doc = piWindow->GetDoc()) {
+    if (nsIDocument* doc = aParent->GetDoc()) {
       if (nsPresContext* presContext = doc->GetPresContext()) {
         openerZoom = presContext->GetFullZoom();
       }
     }
   }
 
   double scale = 1.0;
   treeOwnerAsWin->GetUnscaledDevicePixelsPerCSSPixel(&scale);
@@ -2458,17 +2449,17 @@ nsWindowWatcher::SizeOpenedWindow(nsIDoc
 
 void
 nsWindowWatcher::GetWindowTreeItem(nsPIDOMWindowOuter* aWindow,
                                    nsIDocShellTreeItem** aResult)
 {
   *aResult = 0;
 
   if (aWindow) {
-    nsIDocShell* docshell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+    nsIDocShell* docshell = aWindow->GetDocShell();
     if (docshell) {
       CallQueryInterface(docshell, aResult);
     }
   }
 }
 
 void
 nsWindowWatcher::GetWindowTreeOwner(nsPIDOMWindowOuter* aWindow,
--- a/toolkit/xre/ProfileReset.cpp
+++ b/toolkit/xre/ProfileReset.cpp
@@ -165,17 +165,16 @@ ProfileResetCleanup(nsIToolkitProfile* a
     // Wait for the cleanup thread to complete.
     SpinEventLoopUntil([&]() { return gProfileResetCleanupCompleted; });
   } else {
     gProfileResetCleanupCompleted = true;
     NS_WARNING("Cleanup thread creation failed");
     return rv;
   }
   // Close the progress window now that the cleanup thread is done.
-  auto* piWindow = nsPIDOMWindowOuter::From(progressWindow);
-  piWindow->Close();
+  progressWindow->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/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -77,19 +77,17 @@ activateWindow( nsPIDOMWindowOuter *win 
     if ( hwnd ) {
         // 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.
-        nsCOMPtr<nsPIDOMWindowOuter> piWin = nsPIDOMWindowOuter::From(win);
-        piWin->Focus();
+        win->Focus();
     }
 }
 
 
 #ifdef DEBUG_law
 #undef MOZ_DEBUG_DDE
 #define MOZ_DEBUG_DDE 1
 #endif
@@ -1401,20 +1399,18 @@ nsNativeAppSupportWin::OpenWindow( const
   }
   return rv;
 }
 
 HWND hwndForDOMWindow(nsPIDOMWindowOuter *window ) {
     if ( !window ) {
         return 0;
     }
-    nsCOMPtr<nsPIDOMWindowOuter > pidomwindow = nsPIDOMWindowOuter::From(window);
-
     nsCOMPtr<nsIBaseWindow> ppBaseWindow =
-        do_QueryInterface( pidomwindow->GetDocShell() );
+        do_QueryInterface( window->GetDocShell() );
     if ( !ppBaseWindow ) {
         return 0;
     }
 
     nsCOMPtr<nsIWidget> ppWidget;
     ppBaseWindow->GetMainWidget( getter_AddRefs( ppWidget ) );
 
     return (HWND)( ppWidget->GetNativeData( NS_NATIVE_WIDGET ) );
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -906,35 +906,29 @@ NS_IMETHODIMP
 nsDocLoader::GetDOMWindowID(uint64_t *aResult)
 {
   *aResult = 0;
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
   nsresult rv = GetDOMWindow(getter_AddRefs(window));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsPIDOMWindowOuter> piwindow = nsPIDOMWindowOuter::From(window);
-  NS_ENSURE_STATE(piwindow);
-
-  *aResult = piwindow->WindowID();
+  *aResult = window->WindowID();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocLoader::GetInnerDOMWindowID(uint64_t *aResult)
 {
   *aResult = 0;
 
-  nsCOMPtr<nsPIDOMWindowOuter> window;
-  nsresult rv = GetDOMWindow(getter_AddRefs(window));
+  nsCOMPtr<nsPIDOMWindowOuter> outer;
+  nsresult rv = GetDOMWindow(getter_AddRefs(outer));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsPIDOMWindowOuter> outer = nsPIDOMWindowOuter::From(window);
-  NS_ENSURE_STATE(outer);
-
   nsPIDOMWindowInner* inner = outer->GetCurrentInnerWindow();
   if (!inner) {
     // If we don't have an inner window, return 0.
     return NS_OK;
   }
 
   *aResult = inner->WindowID();
   return NS_OK;
@@ -943,21 +937,18 @@ nsDocLoader::GetInnerDOMWindowID(uint64_
 NS_IMETHODIMP
 nsDocLoader::GetIsTopLevel(bool *aResult)
 {
   *aResult = false;
 
   nsCOMPtr<nsPIDOMWindowOuter> window;
   GetDOMWindow(getter_AddRefs(window));
   if (window) {
-    nsCOMPtr<nsPIDOMWindowOuter> piwindow = nsPIDOMWindowOuter::From(window);
-    NS_ENSURE_STATE(piwindow);
-
-    nsCOMPtr<nsPIDOMWindowOuter> topWindow = piwindow->GetTop();
-    *aResult = piwindow == topWindow;
+    nsCOMPtr<nsPIDOMWindowOuter> topWindow = window->GetTop();
+    *aResult = window == topWindow;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocLoader::GetIsLoadingDocument(bool *aIsLoadingDocument)
 {
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -161,21 +161,20 @@ nsOfflineCachePendingUpdate::OnStateChan
         NS_RELEASE_THIS();
         return NS_OK;
     }
 
     if (!(progressStateFlags & STATE_STOP)) {
         return NS_OK;
     }
 
-    nsCOMPtr<nsPIDOMWindowOuter> windowProxy;
-    aWebProgress->GetDOMWindow(getter_AddRefs(windowProxy));
-    if (!windowProxy) return NS_OK;
+    nsCOMPtr<nsPIDOMWindowOuter> outerWindow;
+    aWebProgress->GetDOMWindow(getter_AddRefs(outerWindow));
+    if (!outerWindow) return NS_OK;
 
-    auto* outerWindow = nsPIDOMWindowOuter::From(windowProxy);
     nsPIDOMWindowInner* innerWindow = outerWindow->GetCurrentInnerWindow();
 
     nsCOMPtr<nsIDocument> progressDoc = outerWindow->GetDoc();
     if (!progressDoc) return NS_OK;
 
     if (!SameCOMIdentity(progressDoc, updateDoc)) {
         return NS_OK;
     }
@@ -525,17 +524,17 @@ nsOfflineCacheUpdateService::Schedule(ns
 NS_IMETHODIMP
 nsOfflineCacheUpdateService::ScheduleUpdate(nsIURI *aManifestURI,
                                             nsIURI *aDocumentURI,
                                             nsIPrincipal* aLoadingPrincipal,
                                             nsPIDOMWindowInner* aWindow,
                                             nsIOfflineCacheUpdate **aUpdate)
 {
     return Schedule(aManifestURI, aDocumentURI, aLoadingPrincipal, nullptr,
-                    nsPIDOMWindowInner::From(aWindow), nullptr, aUpdate);
+                    aWindow, nullptr, aUpdate);
 }
 
 NS_IMETHODIMP
 nsOfflineCacheUpdateService::ScheduleAppUpdate(nsIURI *aManifestURI,
                                                nsIURI *aDocumentURI,
                                                nsIPrincipal* aLoadingPrincipal,
                                                nsIFile *aProfileDir,
                                                nsIOfflineCacheUpdate **aUpdate)
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -829,19 +829,18 @@ extern "C"
 jobject JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *env, jclass, jlong size);
 
 static RefPtr<nsWindow>
 GetWidget(nsPIDOMWindowOuter* aWindow)
 {
     MOZ_ASSERT(aWindow);
 
-    nsCOMPtr<nsPIDOMWindowOuter> domWindow = nsPIDOMWindowOuter::From(aWindow);
     nsCOMPtr<nsIWidget> widget =
-            widget::WidgetUtils::DOMWindowToWidget(domWindow);
+            widget::WidgetUtils::DOMWindowToWidget(aWindow);
     MOZ_ASSERT(widget);
 
     return RefPtr<nsWindow>(static_cast<nsWindow*>(widget.get()));
 }
 
 void
 AndroidBridge::ContentDocumentChanged(nsPIDOMWindowOuter* aWindow)
 {
--- a/widget/android/fennec/ThumbnailHelper.h
+++ b/widget/android/fennec/ThumbnailHelper.h
@@ -120,18 +120,17 @@ class ThumbnailHelper final
 
     // Return a non-null nsIDocShell to indicate success.
     static already_AddRefed<nsIDocShell>
     GetThumbnailAndDocShell(nsPIDOMWindowOuter* aWindow,
                             jni::ByteBuffer::Param aData,
                             int32_t aThumbWidth, int32_t aThumbHeight,
                             const CSSRect& aPageRect, float aZoomFactor)
     {
-        nsCOMPtr<nsPIDOMWindowOuter> win = nsPIDOMWindowOuter::From(aWindow);
-        nsCOMPtr<nsIDocShell> docShell = win->GetDocShell();
+        nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
         RefPtr<nsPresContext> presContext;
 
         if (!docShell || NS_FAILED(docShell->GetPresContext(
                 getter_AddRefs(presContext))) || !presContext) {
             return nullptr;
         }
 
         uint8_t* const data = static_cast<uint8_t*>(aData->Address());
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1175,29 +1175,27 @@ nsWindow::GeckoViewSupport::Open(const j
     if (aPrivateMode) {
         chromeFlags += ",private";
     }
     nsCOMPtr<nsPIDOMWindowOuter> domWindow;
     ww->OpenWindow(nullptr, url.get(), aId->ToCString().get(), chromeFlags.get(),
                    androidView, getter_AddRefs(domWindow));
     MOZ_RELEASE_ASSERT(domWindow);
 
-    nsCOMPtr<nsPIDOMWindowOuter> pdomWindow =
-            nsPIDOMWindowOuter::From(domWindow);
-    nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(pdomWindow);
+    nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(domWindow);
     MOZ_ASSERT(widget);
 
     const auto window = static_cast<nsWindow*>(widget.get());
     window->SetScreenId(aScreenId);
 
     // Attach a new GeckoView support object to the new window.
     GeckoSession::Window::LocalRef sessionWindow(aCls.Env(), aWindow);
     window->mGeckoViewSupport =
             mozilla::MakeUnique<GeckoViewSupport>(window, sessionWindow);
-    window->mGeckoViewSupport->mDOMWindow = pdomWindow;
+    window->mGeckoViewSupport->mDOMWindow = domWindow;
     window->mAndroidView = androidView;
 
     // Attach other session support objects.
     window->mGeckoViewSupport->Transfer(
             sessionWindow, aQueue, aCompositor, aDispatcher, aInitData);
 
     if (window->mWidgetListener) {
         nsCOMPtr<nsIXULWindow> xulWindow(
--- a/widget/gtk/TaskbarProgress.cpp
+++ b/widget/gtk/TaskbarProgress.cpp
@@ -82,18 +82,17 @@ TaskbarProgress::SetProgressState(nsTask
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TaskbarProgress::SetPrimaryWindow(nsPIDOMWindowOuter* aWindow)
 {
   NS_ENSURE_TRUE(aWindow != nullptr, NS_ERROR_ILLEGAL_VALUE);
 
-  auto* parent = nsPIDOMWindowOuter::From(aWindow);
-  RefPtr<nsIWidget> widget = mozilla::widget::WidgetUtils::DOMWindowToWidget(parent);
+  RefPtr<nsIWidget> widget = mozilla::widget::WidgetUtils::DOMWindowToWidget(aWindow);
 
   // Only nsWindows have a native window, HeadlessWidgets do not.  Stop here if the
   // window does not have one.
   if (!widget->GetNativeData(NS_NATIVE_WINDOW)) {
     return NS_OK;
   }
 
   mPrimaryWindow = static_cast<nsWindow*>(widget.get());
--- a/widget/gtk/nsApplicationChooser.cpp
+++ b/widget/gtk/nsApplicationChooser.cpp
@@ -28,18 +28,17 @@ nsApplicationChooser::~nsApplicationChoo
 {
 }
 
 NS_IMETHODIMP
 nsApplicationChooser::Init(nsPIDOMWindowOuter* aParent,
                            const nsACString& aTitle)
 {
   NS_ENSURE_TRUE(aParent, NS_ERROR_FAILURE);
-  auto* parent = nsPIDOMWindowOuter::From(aParent);
-  mParentWidget = widget::WidgetUtils::DOMWindowToWidget(parent);
+  mParentWidget = widget::WidgetUtils::DOMWindowToWidget(aParent);
   mWindowTitle.Assign(aTitle);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsApplicationChooser::Open(const nsACString& aContentType, nsIApplicationChooserFinishedCallback *aCallback)
 {
   MOZ_ASSERT(aCallback);
--- a/widget/gtk/nsColorPicker.cpp
+++ b/widget/gtk/nsColorPicker.cpp
@@ -57,18 +57,17 @@ GtkColorSelection* nsColorPicker::Widget
                              GTK_COLOR_SELECTION_DIALOG(widget)));
 }
 #endif
 
 NS_IMETHODIMP nsColorPicker::Init(nsPIDOMWindowOuter *aParent,
                                   const nsAString& title,
                                   const nsAString& initialColor)
 {
-  auto* parent = nsPIDOMWindowOuter::From(aParent);
-  mParentWidget = mozilla::widget::WidgetUtils::DOMWindowToWidget(parent);
+  mParentWidget = mozilla::widget::WidgetUtils::DOMWindowToWidget(aParent);
   mTitle = title;
   mInitialColor = initialColor;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsColorPicker::Open(nsIColorPickerShownCallback *aColorPickerShownCallback)
 {
--- a/widget/nsBaseFilePicker.cpp
+++ b/widget/nsBaseFilePicker.cpp
@@ -166,17 +166,17 @@ nsBaseFilePicker::~nsBaseFilePicker()
 
 NS_IMETHODIMP nsBaseFilePicker::Init(nsPIDOMWindowOuter* aParent,
                                      const nsAString& aTitle,
                                      int16_t aMode)
 {
   MOZ_ASSERT(aParent, "Null parent passed to filepicker, no file "
                   "picker for you!");
 
-  mParent = nsPIDOMWindowOuter::From(aParent);
+  mParent = aParent;
 
   nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(mParent->GetOuterWindow());
   NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
 
 
   mMode = aMode;
   InitNative(widget, aTitle);
 
--- a/widget/nsFilePickerProxy.cpp
+++ b/widget/nsFilePickerProxy.cpp
@@ -30,17 +30,17 @@ NS_IMETHODIMP
 nsFilePickerProxy::Init(nsPIDOMWindowOuter* aParent, const nsAString& aTitle,
                         int16_t aMode)
 {
   TabChild* tabChild = TabChild::GetFrom(aParent);
   if (!tabChild) {
     return NS_ERROR_FAILURE;
   }
 
-  mParent = nsPIDOMWindowOuter::From(aParent);
+  mParent = aParent;
 
   mMode = aMode;
 
   NS_ADDREF_THIS();
   tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
 
   mIPCActive = true;
   return NS_OK;
--- a/widget/windows/WinTaskbar.cpp
+++ b/widget/windows/WinTaskbar.cpp
@@ -46,23 +46,22 @@ GetHWNDFromDocShell(nsIDocShell *aShell)
 
   nsCOMPtr<nsIWidget> widget;
   baseWindow->GetMainWidget(getter_AddRefs(widget));
 
   return widget ? (HWND)widget->GetNativeData(NS_NATIVE_WINDOW) : nullptr;
 }
 
 HWND
-GetHWNDFromDOMWindow(nsPIDOMWindowInner *dw) {
+GetHWNDFromDOMWindow(nsPIDOMWindowInner *window) {
   nsCOMPtr<nsIWidget> widget;
 
-  if (!dw)
+  if (!window)
     return nullptr;
 
-  nsCOMPtr<nsPIDOMWindowInner> window = nsPIDOMWindowInner::From(dw);
   return GetHWNDFromDocShell(window->GetDocShell());
 }
 
 nsresult
 SetWindowAppUserModelProp(nsPIDOMWindowInner *aParent,
                           const nsString & aIdentifier) {
   NS_ENSURE_ARG_POINTER(aParent);
 
--- a/widget/windows/nsColorPicker.cpp
+++ b/widget/windows/nsColorPicker.cpp
@@ -193,17 +193,17 @@ NS_IMPL_ISUPPORTS(nsColorPicker, nsIColo
 
 NS_IMETHODIMP
 nsColorPicker::Init(nsPIDOMWindowOuter* parent,
                     const nsAString& title,
                     const nsAString& aInitialColor)
 {
   MOZ_ASSERT(parent,
       "Null parent passed to colorpicker, no color picker for you!");
-  mParentWidget =  WidgetUtils::DOMWindowToWidget(nsPIDOMWindowOuter::From(parent));
+  mParentWidget =  WidgetUtils::DOMWindowToWidget(parent);
   mInitialColor = ColorStringToRGB(aInitialColor);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsColorPicker::Open(nsIColorPickerShownCallback* aCallback)
 {
   NS_ENSURE_ARG(aCallback);
--- a/widget/windows/nsPrintDialogWin.cpp
+++ b/widget/windows/nsPrintDialogWin.cpp
@@ -171,20 +171,18 @@ nsPrintDialogServiceWin::GetHWNDForDOMWi
     if (site) {
       HWND w;
       site->GetSiteWindow(reinterpret_cast<void**>(&w));
       return w;
     }
   }
 
   // Now we might be the Browser so check this path
-  nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
-
   nsCOMPtr<nsIDocShellTreeItem> treeItem =
-    do_QueryInterface(window->GetDocShell());
+    do_QueryInterface(aWindow->GetDocShell());
   if (!treeItem)
     return nullptr;
 
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
   if (!treeOwner)
     return nullptr;
 
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -2655,18 +2655,17 @@ nsMemoryReporterManager::SizeOfTab(nsPID
                                    int64_t* aDomSize,
                                    int64_t* aStyleSize,
                                    int64_t* aOtherSize,
                                    int64_t* aTotalSize,
                                    double*  aJSMilliseconds,
                                    double*  aNonJSMilliseconds)
 {
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aTopWindow);
-  auto* piWindow = nsPIDOMWindowOuter::From(aTopWindow);
-  if (NS_WARN_IF(!global) || NS_WARN_IF(!piWindow)) {
+  if (NS_WARN_IF(!global) || NS_WARN_IF(!aTopWindow)) {
     return NS_ERROR_FAILURE;
   }
 
   TimeStamp t1 = TimeStamp::Now();
 
   // Measure JS memory consumption (and possibly some non-JS consumption, via
   // |jsPrivateSize|).
   size_t jsObjectsSize, jsStringsSize, jsPrivateSize, jsOtherSize;
@@ -2676,17 +2675,17 @@ nsMemoryReporterManager::SizeOfTab(nsPID
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   TimeStamp t2 = TimeStamp::Now();
 
   // Measure non-JS memory consumption.
   size_t domSize, styleSize, otherSize;
-  rv = mSizeOfTabFns.mNonJS(piWindow, &domSize, &styleSize, &otherSize);
+  rv = mSizeOfTabFns.mNonJS(aTopWindow, &domSize, &styleSize, &otherSize);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   TimeStamp t3 = TimeStamp::Now();
 
   *aTotalSize = 0;
 #define DO(aN, n) { *aN = (n); *aTotalSize += (n); }
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -81,24 +81,23 @@ GetMostRecentNavigatorHWND()
 {
   nsresult rv;
   nsCOMPtr<nsIWindowMediator> winMediator(
       do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv));
   if (NS_FAILED(rv)) {
     return nullptr;
   }
 
-  nsCOMPtr<nsPIDOMWindowOuter> navWin;
+  nsCOMPtr<nsPIDOMWindowOuter> win;
   rv = winMediator->GetMostRecentWindow(u"navigator:browser",
-                                        getter_AddRefs(navWin));
+                                        getter_AddRefs(win));
   if (NS_FAILED(rv) || !navWin) {
     return nullptr;
   }
 
-  nsPIDOMWindowOuter* win = nsPIDOMWindowOuter::From(navWin);
   nsCOMPtr<nsIWidget> widget = widget::WidgetUtils::DOMWindowToWidget(win);
   if (!widget) {
     return nullptr;
   }
 
   return reinterpret_cast<HWND>(widget->GetNativeData(NS_NATIVE_WINDOW));
 }
 
--- a/xpfe/appshell/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/nsContentTreeOwner.cpp
@@ -801,18 +801,16 @@ nsContentTreeOwner::ProvideWindow(nsPIDO
                                   const nsACString& aFeatures,
                                   bool aForceNoOpener,
                                   nsIDocShellLoadInfo* aLoadInfo,
                                   bool* aWindowIsNew,
                                   nsPIDOMWindowOuter** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aParent);
 
-  auto* parent = nsPIDOMWindowOuter::From(aParent);
-
   *aReturn = nullptr;
 
   if (!mXULWindow) {
     // Nothing to do here
     return NS_OK;
   }
 
 #ifdef DEBUG
@@ -828,17 +826,17 @@ nsContentTreeOwner::ProvideWindow(nsPIDO
   // and return its window here.
   nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent);
   if (docshell && docshell->GetIsInMozBrowser() &&
       !(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL |
                         nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
                         nsIWebBrowserChrome::CHROME_OPENAS_CHROME))) {
 
     BrowserElementParent::OpenWindowResult opened =
-      BrowserElementParent::OpenWindowInProcess(parent, aURI, aName,
+      BrowserElementParent::OpenWindowInProcess(aParent, aURI, aName,
                                                 aFeatures, aForceNoOpener, aReturn);
 
     // If OpenWindowInProcess handled the open (by opening it or blocking the
     // popup), tell our caller not to proceed trying to create a new window
     // through other means.
     if (opened != BrowserElementParent::OPEN_WINDOW_IGNORED) {
       *aWindowIsNew = opened == BrowserElementParent::OPEN_WINDOW_ADDED;
       return *aWindowIsNew ? NS_OK : NS_ERROR_ABORT;
@@ -859,17 +857,17 @@ nsContentTreeOwner::ProvideWindow(nsPIDO
           return NS_ERROR_ABORT;
         }
 
       }
     }
   }
 
   int32_t openLocation =
-    nsWindowWatcher::GetWindowOpenLocation(parent, aChromeFlags, aCalledFromJS,
+    nsWindowWatcher::GetWindowOpenLocation(aParent, aChromeFlags, aCalledFromJS,
                                            aPositionSpecified, aSizeSpecified);
 
   if (openLocation != nsIBrowserDOMWindow::OPEN_NEWTAB &&
       openLocation != nsIBrowserDOMWindow::OPEN_CURRENTWINDOW) {
     // Just open a window normally
     return NS_OK;
   }
 
--- a/xpfe/appshell/nsWebShellWindow.cpp
+++ b/xpfe/appshell/nsWebShellWindow.cpp
@@ -210,17 +210,17 @@ nsresult nsWebShellWindow::Initialize(ns
   nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
   if (webProgress) {
     webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);
   }
 
   if (aOpenerWindow) {
     nsPIDOMWindowOuter* window = mDocShell->GetWindow();
     MOZ_ASSERT(window);
-    window->SetOpenerWindow(nsPIDOMWindowOuter::From(aOpenerWindow), true);
+    window->SetOpenerWindow(aOpenerWindow, true);
   }
 
   // Eagerly create an about:blank content viewer with the right principal here,
   // rather than letting it happening in the upcoming call to
   // SetInitialPrincipalToSubject. This avoids creating the about:blank document
   // and then blowing it away with a second one, which can cause problems for the
   // top-level chrome window case. See bug 789773.
   // Note that we don't accept expanded principals here, similar to
@@ -625,20 +625,19 @@ nsWebShellWindow::OnStateChange(nsIWebPr
   }
 
   if (mChromeLoaded)
     return NS_OK;
 
   // If this document notification is for a frame then ignore it...
   nsCOMPtr<nsPIDOMWindowOuter> eventWin;
   aProgress->GetDOMWindow(getter_AddRefs(eventWin));
-  auto* eventPWin = nsPIDOMWindowOuter::From(eventWin);
-  if (eventPWin) {
-    nsPIDOMWindowOuter *rootPWin = eventPWin->GetPrivateRoot();
-    if (eventPWin != rootPWin)
+  if (eventWin) {
+    nsPIDOMWindowOuter *rootPWin = eventWin->GetPrivateRoot();
+    if (eventWin != rootPWin)
       return NS_OK;
   }
 
   mChromeLoaded = true;
   mLockedUntilChromeLoad = false;
 
 #ifdef USE_NATIVE_MENUS
   ///////////////////////////////
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1375,18 +1375,17 @@ bool nsXULWindow::LoadMiscPersistentAttr
       ErrorResult rv;
       windowElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
     }
   }
 
   if (sizeMode == nsSizeMode_Fullscreen) {
     nsCOMPtr<nsPIDOMWindowOuter> ourWindow;
     GetWindowDOMWindow(getter_AddRefs(ourWindow));
-    auto* piWindow = nsPIDOMWindowOuter::From(ourWindow);
-    piWindow->SetFullScreen(true);
+    ourWindow->SetFullScreen(true);
   } else {
     // For maximized windows, ignore the XUL size and position attributes,
     // as setting them would set the window back to normal sizemode.
     if (sizeMode == nsSizeMode_Maximized) {
       mIgnoreXULSize = true;
       mIgnoreXULPosition = true;
     }
     mWindow->SetSizeMode(sizeMode);
@@ -2130,17 +2129,17 @@ NS_IMETHODIMP nsXULWindow::CreateNewCont
   }
 
   if (aOpener) {
     nsCOMPtr<nsIDocShell> docShell;
     xulWin->GetDocShell(getter_AddRefs(docShell));
     MOZ_ASSERT(docShell);
     nsCOMPtr<nsPIDOMWindowOuter> window = docShell->GetWindow();
     MOZ_ASSERT(window);
-    window->SetOpenerForInitialContentBrowser(nsPIDOMWindowOuter::From(aOpener));
+    window->SetOpenerForInitialContentBrowser(aOpener);
   }
 
   xulWin->LockUntilChromeLoad();
 
   {
     AutoNoJSAPI nojsapi;
     SpinEventLoopUntil([&]() { return !xulWin->IsLocked(); });
   }