Bug 861729 - Remove nsPIDOMWindow::mDocument r=Ms2ger
authorDavid Zbarsky <dzbarsky@gmail.com>
Wed, 24 Apr 2013 00:22:37 -0400
changeset 140660 787e5340d7afdd8579d77d5ccebcf72a0871d944
parent 140659 95262d6936423d885c738e4481679e457f6ff9f8
child 140661 fad77e38f79e2db7a8e9406acc98bfa88ecce0ec
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs861729
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 861729 - Remove nsPIDOMWindow::mDocument r=Ms2ger
dom/base/nsGlobalWindow.cpp
dom/base/nsPIDOMWindow.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1209,17 +1209,16 @@ nsGlobalWindow::~nsGlobalWindow()
     // If our outer window's inner window is this window, null out the
     // outer window's reference to this window that's being deleted.
     nsGlobalWindow *outer = GetOuterWindowInternal();
     if (outer) {
       outer->MaybeClearInnerWindow(this);
     }
   }
 
-  mDocument = nullptr;           // Forces Release
   mDoc = nullptr;
 
   NS_ASSERTION(!mArguments, "mArguments wasn't cleaned up properly!");
 
   CleanUp(true);
 
   nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
   if (ac)
@@ -1461,27 +1460,24 @@ nsGlobalWindow::FreeInnerObjects()
     mNavigator = nullptr;
   }
 
   if (mScreen) {
     mScreen->Reset();
     mScreen = nullptr;
   }
 
-  if (mDocument) {
-    NS_ASSERTION(mDoc, "Why is mDoc null?");
-
+  if (mDoc) {
     // Remember the document's principal and URI.
     mDocumentPrincipal = mDoc->NodePrincipal();
     mDocumentURI = mDoc->GetDocumentURI();
     mDocBaseURI = mDoc->GetDocBaseURI();
   }
 
   // Remove our reference to the document and the document principal.
-  mDocument = nullptr;
   mDoc = nullptr;
   mFocusedNode = nullptr;
 
   if (mApplicationCache) {
     static_cast<nsDOMOfflineResourceList*>(mApplicationCache.get())->Disconnect();
     mApplicationCache = nullptr;
   }
 
@@ -1643,17 +1639,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 
 #ifdef MOZ_GAMEPAD
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)
 #endif
 
   // Traverse stuff from nsPIDOMWindow
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameElement)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioContexts)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
   nsGlobalWindow::CleanupCachedXBLHandlers(tmp);
 
@@ -1690,17 +1685,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
 
 #ifdef MOZ_GAMEPAD
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
 #endif
 
   // Unlink stuff from nsPIDOMWindow
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameElement)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioContexts)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 struct TraceData
 {
   TraceData(TraceCallback& aCallback, void* aClosure) :
@@ -2140,44 +2134,44 @@ nsGlobalWindow::SetNewDocument(nsIDocume
     // This outer is now getting its first inner, thaw the outer now
     // that it's ready and is getting an inner window.
 
     Thaw();
   }
 
   NS_ASSERTION(!GetCurrentInnerWindow() ||
                GetCurrentInnerWindow()->GetExtantDoc() == mDoc,
-               "Uh, mDocument doesn't match the current inner window "
+               "Uh, mDoc doesn't match the current inner window "
                "document!");
 
   bool wouldReuseInnerWindow = WouldReuseInnerWindow(aDocument);
   if (aForceReuseInnerWindow &&
       !wouldReuseInnerWindow &&
       mDoc &&
       mDoc->NodePrincipal() != aDocument->NodePrincipal()) {
     NS_ERROR("Attempted forced inner window reuse while changing principal");
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsCOMPtr<nsIDocument> oldDoc(do_QueryInterface(mDocument));
+  nsCOMPtr<nsIDocument> oldDoc = mDoc;
 
   nsIScriptContext *scx = GetContextInternal();
   NS_ENSURE_TRUE(scx, NS_ERROR_NOT_INITIALIZED);
 
   JSContext *cx = scx->GetNativeContext();
 
 #ifndef MOZ_DISABLE_CRYPTOLEGACY
   // clear smartcard events, our document has gone away.
   if (mCrypto) {
     nsresult rv = mCrypto->SetEnableSmartCardEvents(false);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 #endif
 
-  if (!mDocument) {
+  if (!mDoc) {
     // First document load.
 
     // Get our private root. If it is equal to us, then we need to
     // attach our global key bindings that handles browser scrolling
     // and other browser commands.
     nsIDOMWindow* privateRoot = nsGlobalWindow::GetPrivateRoot();
 
     if (privateRoot == static_cast<nsIDOMWindow*>(this)) {
@@ -2194,20 +2188,19 @@ nsGlobalWindow::SetNewDocument(nsIDocume
 
   // Sometimes, WouldReuseInnerWindow() returns true even if there's no inner
   // window (see bug 776497). Be safe.
   bool reUseInnerWindow = (aForceReuseInnerWindow || wouldReuseInnerWindow) &&
                           GetCurrentInnerWindowInternal();
 
   nsresult rv = NS_OK;
 
-  // Set mDocument even if this is an outer window to avoid
+  // Set mDoc even if this is an outer window to avoid
   // having to *always* reach into the inner window to find the
   // document.
-  mDocument = do_QueryInterface(aDocument);
   mDoc = aDocument;
 
 #ifdef DEBUG
   mLastOpenedURI = aDocument->GetDocumentURI();
 #endif
 
   mContext->WillInitializeContext();
 
@@ -2467,17 +2460,16 @@ nsGlobalWindow::SetNewDocument(nsIDocume
     nsWindowSH::InstallGlobalScopePolluter(cx, newInnerWindow->mJSObject);
   }
 
   aDocument->SetScriptGlobalObject(newInnerWindow);
 
   if (!aState) {
     if (reUseInnerWindow) {
       if (newInnerWindow->mDoc != aDocument) {
-        newInnerWindow->mDocument = do_QueryInterface(aDocument);
         newInnerWindow->mDoc = aDocument;
 
         // We're reusing the inner window for a new document. In this
         // case we don't clear the inner window's scope, but we must
         // make sure the cached document property gets updated.
 
         // XXXmarkh - tell other languages about this?
         ::JS_DeleteProperty(cx, currentInner->mJSObject, "document");
@@ -2555,22 +2547,22 @@ nsGlobalWindow::PreloadLocalStorage()
   }
 
   storageManager->PrecacheStorage(principal);
 }
 
 void
 nsGlobalWindow::DispatchDOMWindowCreated()
 {
-  if (!mDoc || !mDocument) {
+  if (!mDoc) {
     return;
   }
 
   // Fire DOMWindowCreated at chrome event listeners
-  nsContentUtils::DispatchChromeEvent(mDoc, mDocument, NS_LITERAL_STRING("DOMWindowCreated"),
+  nsContentUtils::DispatchChromeEvent(mDoc, mDoc, NS_LITERAL_STRING("DOMWindowCreated"),
                                       true /* bubbles */,
                                       false /* not cancellable */);
 
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (observerService) {
     nsAutoString origin;
     nsIPrincipal* principal = mDoc->NodePrincipal();
@@ -2601,17 +2593,16 @@ nsGlobalWindow::InnerSetNewDocument(nsID
     nsIURI *uri = aDocument->GetDocumentURI();
     nsAutoCString spec;
     if (uri)
       uri->GetSpec(spec);
     PR_LogPrint("DOMWINDOW %p SetNewDocument %s", this, spec.get());
   }
 #endif
 
-  mDocument = do_QueryInterface(aDocument);
   mDoc = aDocument;
   mFocusedNode = nullptr;
   mLocalStorage = nullptr;
   mSessionStorage = nullptr;
 
 #ifdef DEBUG
   mLastOpenedURI = aDocument->GetDocumentURI();
 #endif
@@ -2697,24 +2688,23 @@ nsGlobalWindow::DetachFromDocShell()
   NotifyDOMWindowDestroyed(this);
 
   NotifyWindowIDDestroyed("outer-window-destroyed");
 
   nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
 
   if (currentInner) {
     NS_ASSERTION(mDoc, "Must have doc!");
-    
+
     // Remember the document's principal and URI.
     mDocumentPrincipal = mDoc->NodePrincipal();
     mDocumentURI = mDoc->GetDocumentURI();
     mDocBaseURI = mDoc->GetDocBaseURI();
 
     // Release our document reference
-    mDocument = nullptr;
     mDoc = nullptr;
     mFocusedNode = nullptr;
   }
 
   ClearControllers();
 
   mChromeEventHandler = nullptr; // force release now
 
@@ -3039,18 +3029,17 @@ nsGlobalWindow::PostHandleEvent(nsEventC
   nsCOMPtr<nsIScriptContext> kungFuDeathGrip2(GetContextInternal());
 
   if (aVisitor.mEvent->message == NS_RESIZE_EVENT) {
     mIsHandlingResizeEvent = false;
   } else if (aVisitor.mEvent->message == NS_PAGE_UNLOAD &&
              aVisitor.mEvent->mFlags.mIsTrusted) {
     // Execute bindingdetached handlers before we tear ourselves
     // down.
-    if (mDocument) {
-      NS_ASSERTION(mDoc, "Must have doc");
+    if (mDoc) {
       mDoc->BindingManager()->ExecuteDetachedHandlers();
     }
     mIsDocumentLoaded = false;
   } else if (aVisitor.mEvent->message == NS_LOAD &&
              aVisitor.mEvent->mFlags.mIsTrusted) {
     // This is page load event since load events don't propagate to |window|.
     // @see nsDocument::PreHandleEvent.
     mIsDocumentLoaded = true;
@@ -3225,17 +3214,17 @@ nsPIDOMWindow::GetDocBaseURI() const
   return mDoc ? mDoc->GetDocBaseURI() : mDocBaseURI.get();
 }
 
 void
 nsPIDOMWindow::MaybeCreateDoc()
 {
   MOZ_ASSERT(!mDoc);
   if (nsIDocShell* docShell = GetDocShell()) {
-    // Note that |document| here is the same thing as our mDocument, but we
+    // Note that |document| here is the same thing as our mDoc, but we
     // don't have to explicitly set the member variable because the docshell
     // has already called SetNewDocument().
     nsCOMPtr<nsIDocument> document = do_GetInterface(docShell);
   }
 }
 
 void
 nsPIDOMWindow::AddAudioContext(AudioContext* aAudioContext)
@@ -3741,19 +3730,18 @@ nsGlobalWindow::GetApplicationCache(nsID
     if (!webNav) {
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsIURI> uri;
     nsresult rv = webNav->GetCurrentURI(getter_AddRefs(uri));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
     nsCOMPtr<nsIURI> manifestURI;
-    nsContentUtils::GetOfflineAppManifest(doc, getter_AddRefs(manifestURI));
+    nsContentUtils::GetOfflineAppManifest(mDoc, getter_AddRefs(manifestURI));
 
     nsRefPtr<nsDOMOfflineResourceList> applicationCache =
       new nsDOMOfflineResourceList(manifestURI, uri, this);
     NS_ENSURE_TRUE(applicationCache, NS_ERROR_OUT_OF_MEMORY);
 
     applicationCache->Init();
 
     mApplicationCache = applicationCache;
@@ -4516,18 +4504,17 @@ nsGlobalWindow::SetScreenY(int32_t aScre
 // NOTE: Arguments to this function should have values scaled to
 // CSS pixels, not device pixels.
 nsresult
 nsGlobalWindow::CheckSecurityWidthAndHeight(int32_t* aWidth, int32_t* aHeight)
 {
 #ifdef MOZ_XUL
   if (!nsContentUtils::IsCallerChrome()) {
     // if attempting to resize the window, hide any open popups
-    nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-    nsContentUtils::HidePopupsInDocument(doc);
+    nsContentUtils::HidePopupsInDocument(mDoc);
   }
 #endif
 
   // This one is easy. Just ensure the variable is greater than 100;
   if ((aWidth && *aWidth < 100) || (aHeight && *aHeight < 100)) {
     // Check security state for use in determing window dimensions
 
     if (!nsContentUtils::IsCallerChrome()) {
@@ -4582,18 +4569,17 @@ nsGlobalWindow::CheckSecurityLeftAndTop(
 {
   // This one is harder. We have to get the screen size and window dimensions.
 
   // Check security state for use in determing window dimensions
 
   if (!nsContentUtils::IsCallerChrome()) {
 #ifdef MOZ_XUL
     // if attempting to move the window, hide any open popups
-    nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-    nsContentUtils::HidePopupsInDocument(doc);
+    nsContentUtils::HidePopupsInDocument(mDoc);
 #endif
 
     nsGlobalWindow* rootWindow =
       static_cast<nsGlobalWindow*>(GetPrivateRoot());
     if (rootWindow) {
       rootWindow->FlushPendingNotifications(Flush_Layout);
     }
 
@@ -4794,18 +4780,17 @@ nsGlobalWindow::GetChildWindow(jsid aNam
   nsCOMPtr<nsIDOMWindow> child_win(do_GetInterface(child));
   return child_win.forget();
 }
 
 bool
 nsGlobalWindow::DispatchCustomEvent(const char *aEventName)
 {
   bool defaultActionEnabled = true;
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-  nsContentUtils::DispatchTrustedEvent(doc,
+  nsContentUtils::DispatchTrustedEvent(mDoc,
                                        GetOuterWindow(),
                                        NS_ConvertASCIItoUTF16(aEventName),
                                        true, true, &defaultActionEnabled);
 
   return defaultActionEnabled;
 }
 
 void
@@ -4957,18 +4942,17 @@ nsGlobalWindow::SetFullScreenInternal(bo
       widget->MakeFullScreen(aFullScreen);
   }
 
   if (!mFullScreen) {
     // Force exit from DOM full-screen mode. This is so that if we're in
     // DOM full-screen mode and the user exits full-screen mode with
     // the browser full-screen mode toggle keyboard-shortcut, we'll detect
     // that and leave DOM API full-screen mode too.
-    nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-    nsIDocument::ExitFullscreen(doc, /* async */ false);
+    nsIDocument::ExitFullscreen(mDoc, /* async */ false);
   }
 
   if (!mWakeLock && mFullScreen) {
     nsCOMPtr<nsIPowerManagerService> pmService =
       do_GetService(POWERMANAGERSERVICE_CONTRACTID);
     NS_ENSURE_TRUE(pmService, NS_OK);
 
     pmService->NewWakeLock(NS_LITERAL_STRING("DOM_Fullscreen"), this, getter_AddRefs(mWakeLock));
@@ -5512,20 +5496,18 @@ nsGlobalWindow::Focus()
   // Don't look for a presshell if we're a root chrome window that's got
   // about:blank loaded.  We don't want to focus our widget in that case.
   // XXXbz should we really be checking for IsInitialDocument() instead?
   bool lookForPresShell = true;
   int32_t itemType = nsIDocShellTreeItem::typeContent;
   mDocShell->GetItemType(&itemType);
   if (itemType == nsIDocShellTreeItem::typeChrome &&
       GetPrivateRoot() == static_cast<nsIDOMWindow*>(this) &&
-      mDocument) {
-    nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-    NS_ASSERTION(doc, "Bogus doc?");
-    nsIURI* ourURI = doc->GetDocumentURI();
+      mDoc) {
+    nsIURI* ourURI = mDoc->GetDocumentURI();
     if (ourURI) {
       lookForPresShell = !NS_IsAboutBlank(ourURI);
     }
   }
 
   if (lookForPresShell) {
     mDocShell->GetEldestPresShell(getter_AddRefs(presShell));
   }
@@ -5538,18 +5520,17 @@ nsGlobalWindow::Focus()
   if (parent) {
     nsCOMPtr<nsIDOMDocument> parentdomdoc;
     parent->GetDocument(getter_AddRefs(parentdomdoc));
 
     nsCOMPtr<nsIDocument> parentdoc = do_QueryInterface(parentdomdoc);
     if (!parentdoc)
       return NS_OK;
 
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
-    nsIContent* frame = parentdoc->FindContentForSubDocument(doc);
+    nsIContent* frame = parentdoc->FindContentForSubDocument(mDoc);
     nsCOMPtr<nsIDOMElement> frameElement = do_QueryInterface(frame);
     if (frameElement) {
       uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
       if (canFocus)
         flags |= nsIFocusManager::FLAG_RAISE;
       return fm->SetFocus(frameElement, flags);
     }
   }
@@ -5581,22 +5562,21 @@ nsGlobalWindow::Blur()
   GetTreeOwner(getter_AddRefs(treeOwner));
   nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_GetInterface(treeOwner));
   if (siteWindow) {
     // This method call may cause mDocShell to become nullptr.
     rv = siteWindow->Blur();
 
     // if the root is focused, clear the focus
     nsIFocusManager* fm = nsFocusManager::GetFocusManager();
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
-    if (fm && mDocument) {
+    if (fm && mDoc) {
       nsCOMPtr<nsIDOMElement> element;
       fm->GetFocusedElementForWindow(this, false, nullptr, getter_AddRefs(element));
       nsCOMPtr<nsIContent> content = do_QueryInterface(element);
-      if (content == doc->GetRootElement())
+      if (content == mDoc->GetRootElement())
         fm->ClearFocus(this);
     }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
@@ -6136,51 +6116,49 @@ nsGlobalWindow::EnableExternalCapture()
 
 NS_IMETHODIMP
 nsGlobalWindow::DisableExternalCapture()
 {
   return NS_ERROR_FAILURE;
 }
 
 static
-bool IsPopupBlocked(nsIDOMDocument* aDoc)
+bool IsPopupBlocked(nsIDocument* aDoc)
 {
   nsCOMPtr<nsIPopupWindowManager> pm =
     do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID);
 
   if (!pm) {
     return false;
   }
 
-  bool blocked = true;
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDoc));
-
-  if (doc) {
-    uint32_t permission = nsIPopupWindowManager::ALLOW_POPUP;
-    pm->TestPermission(doc->NodePrincipal(), &permission);
-    blocked = (permission == nsIPopupWindowManager::DENY_POPUP);
-  }
-  return blocked;
+  if (!aDoc) {
+    return true;
+  }
+
+  uint32_t permission = nsIPopupWindowManager::ALLOW_POPUP;
+  pm->TestPermission(aDoc->NodePrincipal(), &permission);
+  return permission == nsIPopupWindowManager::DENY_POPUP;
 }
 
 /* static */
 void
 nsGlobalWindow::FirePopupBlockedEvent(nsIDocument* aDoc,
                                       nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI,
                                       const nsAString &aPopupWindowName,
                                       const nsAString &aPopupWindowFeatures)
 {
   if (aDoc) {
     // Fire a "DOMPopupBlocked" event so that the UI can hear about
     // blocked popups.
-    ErrorResult rv;
-    nsRefPtr<nsDOMEvent> event =
-      aDoc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), rv);
+    nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aDoc);
+    nsCOMPtr<nsIDOMEvent> event;
+    doc->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), getter_AddRefs(event));
     if (event) {
-      nsCOMPtr<nsIDOMPopupBlockedEvent> pbev(do_QueryObject(event));
+      nsCOMPtr<nsIDOMPopupBlockedEvent> pbev(do_QueryInterface(event));
       pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"),
                                   true, true, aRequestingWindow,
                                   aPopupURI, aPopupWindowName,
                                   aPopupWindowFeatures);
       event->SetTrusted(true);
 
       bool defaultActionEnabled;
       aDoc->DispatchEvent(event, &defaultActionEnabled);
@@ -6209,17 +6187,17 @@ nsGlobalWindow::CanSetProperty(const cha
   // If the pref is set to true, we can not set the property
   // and vice versa.
   return !Preferences::GetBool(aPrefName, true);
 }
 
 bool
 nsGlobalWindow::PopupWhitelisted()
 {
-  if (!IsPopupBlocked(mDocument))
+  if (!IsPopupBlocked(mDoc))
     return true;
 
   nsCOMPtr<nsIDOMWindow> parent;
 
   if (NS_FAILED(GetParent(getter_AddRefs(parent))) ||
       parent == static_cast<nsIDOMWindow*>(this))
   {
     return false;
@@ -6753,22 +6731,23 @@ PostMessageEvent::Run()
     StructuredCloneInfo scInfo;
     scInfo.event = this;
 
     if (!buffer.read(cx, &messageData, &kPostMessageCallbacks, &scInfo))
       return NS_ERROR_DOM_DATA_CLONE_ERR;
   }
 
   // Create the event
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(targetWindow->mDocument);
-  if (!domDoc)
-    return NS_OK;
+  nsIDocument* doc = targetWindow->mDoc;
+  if (!doc)
+    return NS_OK;
+
+  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
   nsCOMPtr<nsIDOMEvent> event;
-  domDoc->CreateEvent(NS_LITERAL_STRING("MessageEvent"),
-                      getter_AddRefs(event));
+  domDoc->CreateEvent(NS_LITERAL_STRING("MessageEvent"), getter_AddRefs(event));
   if (!event)
     return NS_OK;
 
   nsCOMPtr<nsIDOMMessageEvent> message = do_QueryInterface(event);
   nsresult rv = message->InitMessageEvent(NS_LITERAL_STRING("message"),
                                           false /* non-bubbling */,
                                           true /* cancelable */,
                                           messageData,
@@ -8690,21 +8669,20 @@ nsGlobalWindow::UpdateCanvasFocus(bool a
     return;
 
   bool editable;
   docShell->GetEditable(&editable);
   if (editable)
     return;
 
   nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
-  if (!presShell || !mDocument)
+  if (!presShell || !mDoc)
     return;
 
-  nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
-  Element *rootElement = doc->GetRootElement();
+  Element *rootElement = mDoc->GetRootElement();
   if (rootElement) {
       if ((mHasFocus || aFocusChanged) &&
           (mFocusedNode == rootElement || aNewContent == rootElement)) {
           nsIFrame* frame = rootElement->GetPrimaryFrame();
           if (frame) {
               frame = frame->GetParent();
               nsCanvasFrame* canvasFrame = do_QueryFrame(frame);
               if (canvasFrame) {
@@ -8832,18 +8810,18 @@ nsGlobalWindow::GetSessionStorage(nsIDOM
       }
     }
   }
 
   if (!mSessionStorage) {
     *aSessionStorage = nullptr;
 
     nsString documentURI;
-    if (mDocument) {
-      mDocument->GetDocumentURI(documentURI);
+    if (mDoc) {
+      mDoc->GetDocumentURI(documentURI);
     }
 
     // If the document has the sandboxed origin flag set
     // don't allow access to sessionStorage.
     if (!mDoc) {
       return NS_ERROR_FAILURE;
     }
 
@@ -8917,18 +8895,18 @@ nsGlobalWindow::GetLocalStorage(nsIDOMSt
 
     // If the document has the sandboxed origin flag set
     // don't allow access to localStorage.
     if (mDoc && (mDoc->GetSandboxFlags() & SANDBOXED_ORIGIN)) {
       return NS_ERROR_DOM_SECURITY_ERR;
     }
 
     nsString documentURI;
-    if (mDocument) {
-      mDocument->GetDocumentURI(documentURI);
+    if (mDoc) {
+      mDoc->GetDocumentURI(documentURI);
     }
 
     nsIDocShell* docShell = GetDocShell();
     nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
 
     rv = storageManager->CreateStorage(principal,
                                        documentURI,
                                        loadContext && loadContext->UsePrivateBrowsing(),
@@ -9091,19 +9069,18 @@ nsGlobalWindow::FireOfflineStatusEvent()
   if (htmlDoc) {
     nsCOMPtr<nsIDOMHTMLElement> body;
     htmlDoc->GetBody(getter_AddRefs(body));
     if (body) {
       eventTarget = body;
     }
   }
   else {
-    nsCOMPtr<nsIDOMElement> documentElement;
-    mDocument->GetDocumentElement(getter_AddRefs(documentElement));
-    if(documentElement) {        
+    Element* documentElement = mDoc->GetDocumentElement();
+    if(documentElement) {
       eventTarget = documentElement;
     }
   }
   nsContentUtils::DispatchTrustedEvent(mDoc, eventTarget, name, true, false);
 }
 
 class NotifyIdleObserverRunnable : public nsRunnable
 {
@@ -9991,17 +9968,17 @@ nsGlobalWindow::SetTimeoutOrInterval(nsI
                                      int32_t interval,
                                      bool aIsInterval, int32_t *aReturn)
 {
   FORWARD_TO_INNER(SetTimeoutOrInterval, (aHandler, interval, aIsInterval, aReturn),
                    NS_ERROR_NOT_INITIALIZED);
 
   // If we don't have a document (we could have been unloaded since
   // the call to setTimeout was made), do nothing.
-  if (!mDocument) {
+  if (!mDoc) {
     return NS_OK;
   }
 
   // Disallow negative intervals.  If aIsInterval also disallow 0,
   // because we use that as a "don't repeat" flag.
   interval = std::max(aIsInterval ? 1 : 0, interval);
 
   // Make sure we don't proceed with an interval larger than our timer
@@ -10814,18 +10791,18 @@ nsGlobalWindow::BuildURIfromBase(const c
 
   *aBuiltURI = nullptr;
   *aFreeSecurityPass = false;
   if (aCXused)
     *aCXused = nullptr;
 
   // get JSContext
   NS_ASSERTION(scx, "opening window missing its context");
-  NS_ASSERTION(mDocument, "opening window missing its document");
-  if (!scx || !mDocument)
+  NS_ASSERTION(mDoc, "opening window missing its document");
+  if (!scx || !mDoc)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMChromeWindow> chrome_win = do_QueryObject(this);
 
   if (nsContentUtils::IsCallerChrome() && !chrome_win) {
     // If open() is called from chrome on a non-chrome window, we'll
     // use the context from the window on which open() is being called
     // to prevent giving chrome priveleges to new windows opened in
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -665,18 +665,17 @@ protected:
 
   // Helper for creating performance objects.
   void CreatePerformanceObjectIfNeeded();
 
   // These two variables are special in that they're set to the same
   // value on both the outer window and the current inner window. Make
   // sure you keep them in sync!
   nsCOMPtr<mozilla::dom::EventTarget> mChromeEventHandler; // strong
-  nsCOMPtr<nsIDOMDocument> mDocument; // strong
-  nsCOMPtr<nsIDocument> mDoc; // strong, for fast access
+  nsCOMPtr<nsIDocument> mDoc; // strong
   // Cache the URI when mDoc is cleared.
   nsCOMPtr<nsIURI> mDocumentURI; // strong
   nsCOMPtr<nsIURI> mDocBaseURI; // strong
 
   nsCOMPtr<mozilla::dom::EventTarget> mParentTarget; // strong
 
   // These members are only used on outer windows.
   nsCOMPtr<nsIDOMElement> mFrameElement;