Bug 1432186 part 16. Remove nsIDOMNode's ownerDocument attribute. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 29 Jan 2018 23:10:52 -0500
changeset 748725 f2734b328291e796a9d9ab398b14c906c725bc62
parent 748724 89b63bd48544d121b4d19da6e684c2aecf677a4a
child 748726 6a4d5ceffed34887ea5ac3d2d18c2fae4fe9845f
push id97228
push usersfraser@mozilla.com
push dateTue, 30 Jan 2018 10:21:04 +0000
reviewersmccr8
bugs1432186
milestone60.0a1
Bug 1432186 part 16. Remove nsIDOMNode's ownerDocument attribute. r=mccr8 MozReview-Commit-ID: JqfAFxPBz41
dom/base/nsDOMSerializer.cpp
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/interfaces/core/nsIDOMNode.idl
dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
dom/xslt/xslt/txMozillaXSLTProcessor.cpp
dom/xul/nsXULPopupListener.cpp
editor/libeditor/EditorEventListener.cpp
editor/libeditor/TextEditorDataTransfer.cpp
layout/inspector/inDOMView.cpp
parser/html/nsParserUtils.cpp
toolkit/components/satchel/nsFormFillController.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
widget/nsBaseDragService.cpp
--- a/dom/base/nsDOMSerializer.cpp
+++ b/dom/base/nsDOMSerializer.cpp
@@ -46,24 +46,22 @@ SetUpEncoder(nsIDOMNode *aRoot, const ns
   *aEncoder = nullptr;
 
   nsresult rv;
   nsCOMPtr<nsIDocumentEncoder> encoder =
     do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &rv);
   if (NS_FAILED(rv))
     return rv;
 
-  bool entireDocument = true;
-  nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aRoot));
-  if (!domDoc) {
-    entireDocument = false;
-    rv = aRoot->GetOwnerDocument(getter_AddRefs(domDoc));
-    if (NS_FAILED(rv))
-      return rv;
-  }
+  nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
+  MOZ_ASSERT(root);
+
+  nsIDocument* doc = root->OwnerDoc();
+  bool entireDocument = (doc == root);
+  nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
 
   // This method will fail if no document
   rv = encoder->Init(domDoc, NS_LITERAL_STRING("application/xhtml+xml"),
                      nsIDocumentEncoder::OutputRaw |
                      nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration);
 
   if (NS_FAILED(rv))
     return rv;
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -519,26 +519,16 @@ nsINode::GetParentNode(nsIDOMNode** aPar
 {
   *aParentNode = nullptr;
 
   nsINode *parent = GetParentNode();
 
   return parent ? CallQueryInterface(parent, aParentNode) : NS_OK;
 }
 
-nsresult
-nsINode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
-{
-  *aOwnerDocument = nullptr;
-
-  nsIDocument *ownerDoc = GetOwnerDocument();
-
-  return ownerDoc ? CallQueryInterface(ownerDoc, aOwnerDocument) : NS_OK;
-}
-
 void
 nsINode::GetNodeValueInternal(nsAString& aNodeValue)
 {
   SetDOMStringToNull(aNodeValue);
 }
 
 nsINode*
 nsINode::RemoveChild(nsINode& aOldChild, ErrorResult& aError)
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -2072,17 +2072,16 @@ protected:
   // Note: virtual so that IsInNativeAnonymousSubtree can be called accross
   // module boundaries.
   virtual void CheckNotNativeAnonymous() const;
 #endif
 
   // These are just used to implement nsIDOMNode using
   // NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER and for quickstubs.
   nsresult GetParentNode(nsIDOMNode** aParentNode);
-  nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
 
   void EnsurePreInsertionValidity1(nsINode& aNewChild, nsINode* aRefChild,
                                    mozilla::ErrorResult& aError);
   void EnsurePreInsertionValidity2(bool aReplace, nsINode& aNewChild,
                                    nsINode* aRefChild,
                                    mozilla::ErrorResult& aError);
   nsINode* ReplaceOrInsertBefore(bool aReplace, nsINode* aNewChild,
                                  nsINode* aRefChild,
@@ -2262,20 +2261,16 @@ ToCanonicalSupports(nsINode* aPointer)
 {
   return aPointer;
 }
 
 #define NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER(...) \
   NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) __VA_ARGS__ override \
   { \
     return nsINode::GetParentNode(aParentNode); \
-  } \
-  NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) __VA_ARGS__ override \
-  { \
-    return nsINode::GetOwnerDocument(aOwnerDocument); \
   }
 
 #define NS_FORWARD_NSIDOMNODE_TO_NSINODE \
   NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER(final)
 
 #define NS_FORWARD_NSIDOMNODE_TO_NSINODE_OVERRIDABLE \
   NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER()
 
--- a/dom/interfaces/core/nsIDOMNode.idl
+++ b/dom/interfaces/core/nsIDOMNode.idl
@@ -28,11 +28,9 @@ interface nsIDOMNode : nsISupports
   const unsigned short      PROCESSING_INSTRUCTION_NODE = 7;
   const unsigned short      COMMENT_NODE       = 8;
   const unsigned short      DOCUMENT_NODE      = 9;
   const unsigned short      DOCUMENT_TYPE_NODE = 10;
   const unsigned short      DOCUMENT_FRAGMENT_NODE = 11;
   const unsigned short      NOTATION_NODE      = 12;
 
   readonly attribute nsIDOMNode       parentNode;
-  // Modified in DOM Level 2:
-  readonly attribute nsIDOMDocument   ownerDocument;
 };
--- a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
+++ b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebBrowserPersistLocalDocument.h"
 #include "WebBrowserPersistDocumentParent.h"
 
 #include "mozilla/dom/Attr.h"
+#include "mozilla/dom/Comment.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLAnchorElement.h"
 #include "mozilla/dom/HTMLAreaElement.h"
 #include "mozilla/dom/HTMLInputElement.h"
 #include "mozilla/dom/HTMLLinkElement.h"
 #include "mozilla/dom/HTMLObjectElement.h"
 #include "mozilla/dom/HTMLOptionElement.h"
 #include "mozilla/dom/HTMLSharedElement.h"
@@ -913,38 +914,31 @@ PersistNodeFixup::FixupNode(nsINode* aNo
     nsCOMPtr<nsIContent> content = do_QueryInterface(aNodeIn);
     if (!content) {
         return NS_OK;
     }
 
     // BASE elements are replaced by a comment so relative links are not hosed.
     if (!IsFlagSet(IWBP::PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS) &&
         content->IsHTMLElement(nsGkAtoms::base)) {
-        nsCOMPtr<nsIDOMDocument> ownerDocument;
         // Base uses HTMLSharedElement, which would be awkward to implement
         // FromContent on, since it represents multiple elements. Since we've
         // already checked IsHTMLElement here, just cast as we were doing.
         auto* base = static_cast<dom::HTMLSharedElement*>(content.get());
-        base->GetOwnerDocument(getter_AddRefs(ownerDocument));
-        if (ownerDocument) {
-            nsAutoString href;
-            base->GetHref(href); // Doesn't matter if this fails
-            nsCOMPtr<nsIDOMComment> comment;
-            nsAutoString commentText;
-            commentText.AssignLiteral(" base ");
-            if (!href.IsEmpty()) {
-                commentText += NS_LITERAL_STRING("href=\"") + href
-                    + NS_LITERAL_STRING("\" ");
-            }
-            ownerDocument->CreateComment(commentText,
-                                         getter_AddRefs(comment));
-            if (comment) {
-                return CallQueryInterface(comment, aNodeOut);
-            }
+        nsIDocument* ownerDoc = base->OwnerDoc();
+
+        nsAutoString href;
+        base->GetHref(href); // Doesn't matter if this fails
+        nsAutoString commentText;
+        commentText.AssignLiteral(" base ");
+        if (!href.IsEmpty()) {
+            commentText += NS_LITERAL_STRING("href=\"") + href
+                + NS_LITERAL_STRING("\" ");
         }
+        *aNodeOut = ownerDoc->CreateComment(commentText).take();
         return NS_OK;
     }
 
     // Fix up href and file links in the elements
     RefPtr<dom::HTMLAnchorElement> nodeAsAnchor = dom::HTMLAnchorElement::FromContent(content);
     if (nodeAsAnchor) {
         nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -186,22 +186,20 @@ txToFragmentHandlerFactory::createHandle
                                               txAXMLEventHandler** aHandler)
 {
     *aHandler = nullptr;
     switch (aFormat->mMethod) {
         case eMethodNotSet:
         {
             txOutputFormat format;
             format.merge(*aFormat);
-            nsCOMPtr<nsIDOMDocument> domdoc;
-            mFragment->GetOwnerDocument(getter_AddRefs(domdoc));
-            NS_ASSERTION(domdoc, "unable to get ownerdocument");
-            nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
+            nsCOMPtr<nsINode> node = do_QueryInterface(mFragment);
+            nsCOMPtr<nsIDocument> doc = node->OwnerDoc();
 
-            if (doc && doc->IsHTMLDocument()) {
+            if (doc->IsHTMLDocument()) {
                 format.mMethod = eHTMLOutput;
             } else {
                 format.mMethod = eXMLOutput;
             }
 
             *aHandler = new txMozillaXMLOutput(&format, mFragment, false);
             break;
         }
--- a/dom/xul/nsXULPopupListener.cpp
+++ b/dom/xul/nsXULPopupListener.cpp
@@ -220,77 +220,72 @@ nsXULPopupListener::HandleEvent(nsIDOMEv
 
   return NS_OK;
 }
 
 #ifndef NS_CONTEXT_MENU_IS_MOUSEUP
 nsresult
 nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode, bool aIsTouch)
 {
-  nsresult rv;
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  rv = aTargetNode->GetOwnerDocument(getter_AddRefs(domDoc));
-  if(NS_SUCCEEDED(rv) && domDoc)
-  {
-    nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-
-    // Get nsIDOMElement for targetNode
-    nsIPresShell *shell = doc->GetShell();
-    if (!shell)
-      return NS_ERROR_FAILURE;
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aTargetNode);
+  nsCOMPtr<nsIDocument> doc = content->OwnerDoc();
 
-    // strong reference to keep this from going away between events
-    // XXXbz between what events?  We don't use this local at all!
-    RefPtr<nsPresContext> context = shell->GetPresContext();
+  // Get nsIDOMElement for targetNode
+  nsIPresShell *shell = doc->GetShell();
+  if (!shell)
+    return NS_ERROR_FAILURE;
 
-    nsCOMPtr<nsIContent> content = do_QueryInterface(aTargetNode);
-    nsIFrame* targetFrame = content->GetPrimaryFrame();
-    if (!targetFrame) return NS_ERROR_FAILURE;
+  // strong reference to keep this from going away between events
+  // XXXbz between what events?  We don't use this local at all!
+  RefPtr<nsPresContext> context = shell->GetPresContext();
 
-    const nsStyleUserInterface* ui = targetFrame->StyleUserInterface();
-    bool suppressBlur = (ui->mUserFocus == StyleUserFocus::Ignore);
-
-    nsCOMPtr<nsIDOMElement> element;
-    nsCOMPtr<nsIContent> newFocus = do_QueryInterface(content);
+  nsIFrame* targetFrame = content->GetPrimaryFrame();
+  if (!targetFrame) return NS_ERROR_FAILURE;
 
-    nsIFrame* currFrame = targetFrame;
-    // Look for the nearest enclosing focusable frame.
-    while (currFrame) {
-        int32_t tabIndexUnused;
-        if (currFrame->IsFocusable(&tabIndexUnused, true)) {
-          newFocus = currFrame->GetContent();
-          nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
-          if (domElement) {
-            element = domElement;
-            break;
-          }
-        }
-        currFrame = currFrame->GetParent();
-    }
+  const nsStyleUserInterface* ui = targetFrame->StyleUserInterface();
+  bool suppressBlur = (ui->mUserFocus == StyleUserFocus::Ignore);
+
+  nsCOMPtr<nsIDOMElement> element;
+  nsCOMPtr<nsIContent> newFocus = content;
 
-    nsIFocusManager* fm = nsFocusManager::GetFocusManager();
-    if (fm) {
-      if (element) {
-        uint32_t focusFlags = nsIFocusManager::FLAG_BYMOUSE |
-                              nsIFocusManager::FLAG_NOSCROLL;
-        if (aIsTouch) {
-          focusFlags |= nsIFocusManager::FLAG_BYTOUCH;
-        }
-        fm->SetFocus(element, focusFlags);
-      } else if (!suppressBlur) {
-        nsPIDOMWindowOuter *window = doc->GetWindow();
-        fm->ClearFocus(window);
+  nsIFrame* currFrame = targetFrame;
+  // Look for the nearest enclosing focusable frame.
+  while (currFrame) {
+    int32_t tabIndexUnused;
+    if (currFrame->IsFocusable(&tabIndexUnused, true)) {
+      newFocus = currFrame->GetContent();
+      nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
+      if (domElement) {
+        element = domElement;
+        break;
       }
     }
+    currFrame = currFrame->GetParent();
+  }
 
-    EventStateManager* esm = context->EventStateManager();
-    nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);
-    esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);
+  nsIFocusManager* fm = nsFocusManager::GetFocusManager();
+  if (fm) {
+    if (element) {
+      uint32_t focusFlags = nsIFocusManager::FLAG_BYMOUSE |
+                            nsIFocusManager::FLAG_NOSCROLL;
+      if (aIsTouch) {
+        focusFlags |= nsIFocusManager::FLAG_BYTOUCH;
+      }
+      fm->SetFocus(element, focusFlags);
+    } else if (!suppressBlur) {
+      nsPIDOMWindowOuter *window = doc->GetWindow();
+      fm->ClearFocus(window);
+    }
   }
-  return rv;
+
+  EventStateManager* esm = context->EventStateManager();
+  nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);
+  esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);
+
+  return NS_OK;
 }
 #endif
 
 // ClosePopup
 //
 // Do everything needed to shut down the popup.
 //
 // NOTE: This routine is safe to call even if the popup is already closed.
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -970,31 +970,28 @@ EditorEventListener::CanDrop(nsIDOMDragE
        (!types.Contains(NS_LITERAL_STRING(kHTMLMime)) &&
         !types.Contains(NS_LITERAL_STRING(kFileMime))))) {
     return false;
   }
 
   // If there is no source node, this is probably an external drag and the
   // drop is allowed. The later checks rely on checking if the drag target
   // is the same as the drag source.
-  nsCOMPtr<nsIDOMNode> sourceNode;
-  dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
+  nsCOMPtr<nsINode> sourceNode = dataTransfer->GetMozSourceNode();
   if (!sourceNode) {
     return true;
   }
 
   // There is a source node, so compare the source documents and this document.
   // Disallow drops on the same document.
 
-  nsCOMPtr<nsIDOMDocument> domdoc = editorBase->GetDOMDocument();
+  nsCOMPtr<nsIDocument> domdoc = editorBase->GetDocument();
   NS_ENSURE_TRUE(domdoc, false);
 
-  nsCOMPtr<nsIDOMDocument> sourceDoc;
-  nsresult rv = sourceNode->GetOwnerDocument(getter_AddRefs(sourceDoc));
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsIDocument> sourceDoc = sourceNode->OwnerDoc();
 
   // If the source and the dest are not same document, allow to drop it always.
   if (domdoc != sourceDoc) {
     return true;
   }
 
   // If the source node is a remote browser, treat this as coming from a
   // different document and allow the drop.
@@ -1010,17 +1007,17 @@ EditorEventListener::CanDrop(nsIDOMDragE
   }
 
   // If selection is collapsed, allow to drop it always.
   if (selection->Collapsed()) {
     return true;
   }
 
   nsCOMPtr<nsIDOMNode> parent;
-  rv = aEvent->GetRangeParent(getter_AddRefs(parent));
+  nsresult rv = aEvent->GetRangeParent(getter_AddRefs(parent));
   if (NS_FAILED(rv) || !parent) {
     return false;
   }
 
   int32_t offset = 0;
   rv = aEvent->GetRangeOffset(&offset);
   NS_ENSURE_SUCCESS(rv, false);
 
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -171,23 +171,21 @@ TextEditor::InsertFromDrop(nsIDOMEvent* 
   nsCOMPtr<nsIDOMDataTransfer> domDataTransfer;
   dragEvent->GetDataTransfer(getter_AddRefs(domDataTransfer));
   nsCOMPtr<DataTransfer> dataTransfer = do_QueryInterface(domDataTransfer);
   NS_ENSURE_TRUE(dataTransfer, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
   NS_ASSERTION(dragSession, "No drag session");
 
-  nsCOMPtr<nsIDOMNode> sourceNode;
-  dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
+  nsCOMPtr<nsINode> sourceNode = dataTransfer->GetMozSourceNode();
 
   nsCOMPtr<nsIDOMDocument> srcdomdoc;
   if (sourceNode) {
-    sourceNode->GetOwnerDocument(getter_AddRefs(srcdomdoc));
-    NS_ENSURE_TRUE(sourceNode, NS_ERROR_FAILURE);
+    srcdomdoc = do_QueryInterface(sourceNode->OwnerDoc());
   }
 
   if (nsContentUtils::CheckForSubFrameDrop(dragSession,
         aDropEvent->WidgetEventPtr()->AsDragEvent())) {
     // Don't allow drags from subframe documents with different origins than
     // the drop destination.
     if (srcdomdoc && !IsSafeToInsertData(srcdomdoc)) {
       return NS_OK;
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -135,25 +135,22 @@ inDOMView::SetRootNode(nsIDOMNode* aNode
       AppendNode(CreateNode(aNode, nullptr));
     } else {
       // place only the children of the root node in the buffer
       ExpandNode(-1);
     }
 
     // store an owning reference to document so that it isn't
     // destroyed before we are
-    mRootDocument = do_QueryInterface(aNode);
-    if (!mRootDocument) {
-      aNode->GetOwnerDocument(getter_AddRefs(mRootDocument));
-    }
+    nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+    nsIDocument* doc = node->OwnerDoc();
+    mRootDocument = do_QueryInterface(doc);
 
     // add document observer
-    nsCOMPtr<nsINode> doc(do_QueryInterface(mRootDocument));
-    if (doc)
-      doc->AddMutationObserver(this);
+    doc->AddMutationObserver(this);
   } else {
     mRootDocument = nullptr;
   }
 
   if (mTree)
     mTree->EndUpdateBatch();
 
   return NS_OK;
--- a/parser/html/nsParserUtils.cpp
+++ b/parser/html/nsParserUtils.cpp
@@ -133,22 +133,19 @@ nsParserUtils::ParseFragment(const nsASt
                              nsIURI* aBaseURI,
                              nsIDOMElement* aContextElement,
                              nsIDOMDocumentFragment** aReturn)
 {
   NS_ENSURE_ARG(aContextElement);
   *aReturn = nullptr;
 
   nsCOMPtr<nsIDocument> document;
-  nsCOMPtr<nsIDOMDocument> domDocument;
-  nsCOMPtr<nsIDOMNode> contextNode;
+  nsCOMPtr<nsINode> contextNode;
   contextNode = do_QueryInterface(aContextElement);
-  contextNode->GetOwnerDocument(getter_AddRefs(domDocument));
-  document = do_QueryInterface(domDocument);
-  NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
+  document = contextNode->OwnerDoc();
 
   nsAutoScriptBlockerSuppressNodeRemoved autoBlocker;
 
   // stop scripts
   RefPtr<ScriptLoader> loader;
   bool scripts_enabled = false;
   if (document) {
     loader = document->ScriptLoader();
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -691,22 +691,19 @@ nsFormFillController::OnSearchComplete()
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::OnTextEntered(nsIDOMEvent* aEvent,
                                     bool* aPrevent)
 {
   NS_ENSURE_ARG(aPrevent);
-  NS_ENSURE_TRUE(mFocusedInput, NS_OK);
+  NS_ENSURE_TRUE(mFocusedInputNode, NS_OK);
   // Fire off a DOMAutoComplete event
-  nsCOMPtr<nsIDOMDocument> domDoc;
-  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
-  element->GetOwnerDocument(getter_AddRefs(domDoc));
-  NS_ENSURE_STATE(domDoc);
+  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mFocusedInputNode->OwnerDoc());
 
   nsCOMPtr<nsIDOMEvent> event;
   domDoc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
   NS_ENSURE_STATE(event);
 
   event->InitEvent(NS_LITERAL_STRING("DOMAutoComplete"), true, true);
 
   // XXXjst: We mark this event as a trusted event, it's up to the
@@ -733,25 +730,22 @@ nsFormFillController::GetConsumeRollupEv
 {
   *aConsumeRollupEvent = false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetInPrivateContext(bool *aInPrivateContext)
 {
-  if (!mFocusedInput) {
+  if (!mFocusedInputNode) {
     *aInPrivateContext = false;
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMDocument> inputDoc;
-  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mFocusedInput);
-  element->GetOwnerDocument(getter_AddRefs(inputDoc));
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(inputDoc);
+  nsCOMPtr<nsIDocument> doc = mFocusedInputNode->OwnerDoc();
   nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
   *aInPrivateContext = loadContext && loadContext->UsePrivateBrowsing();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormFillController::GetNoRollupOnCaretMove(bool *aNoRollupOnCaretMove)
 {
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -1176,33 +1176,30 @@ nsTypeAheadFind::GetFoundRange(nsIDOMRan
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTypeAheadFind::IsRangeVisible(nsIDOMRange *aRange,
                                 bool aMustBeInViewPort,
                                 bool *aResult)
 {
-  // Jump through hoops to extract the docShell from the range.
-  nsCOMPtr<nsIDOMNode> node;
-  aRange->GetStartContainer(getter_AddRefs(node));
-  nsCOMPtr<nsIDOMDocument> document;
-  node->GetOwnerDocument(getter_AddRefs(document));
-  nsCOMPtr<mozIDOMWindowProxy> window;
-  document->GetDefaultView(getter_AddRefs(window));
-  nsCOMPtr<nsIWebNavigation> navNav (do_GetInterface(window));
-  nsCOMPtr<nsIDocShell> docShell (do_GetInterface(navNav));
+  nsCOMPtr<nsIDOMNode> domNode;
+  aRange->GetStartContainer(getter_AddRefs(domNode));
+  nsCOMPtr<nsINode> node = do_QueryInterface(domNode);
 
-  // Set up the arguments needed to check if a range is visible.
-  nsCOMPtr<nsIPresShell> presShell (docShell->GetPresShell());
+  nsIDocument* doc = node->OwnerDoc();
+  nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
+  if (!presShell) {
+    return NS_ERROR_UNEXPECTED;
+  }
   RefPtr<nsPresContext> presContext = presShell->GetPresContext();
-  nsCOMPtr<nsIDOMRange> startPointRange = new nsRange(presShell->GetDocument());
+  nsCOMPtr<nsIDOMRange> ignored;
   *aResult = IsRangeVisible(presShell, presContext, aRange,
                             aMustBeInViewPort, false,
-                            getter_AddRefs(startPointRange),
+                            getter_AddRefs(ignored),
                             nullptr);
   return NS_OK;
 }
 
 bool
 nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
                                 nsPresContext *aPresContext,
                                 nsIDOMRange *aRange, bool aMustBeInViewPort,
@@ -1336,28 +1333,25 @@ nsTypeAheadFind::IsRangeVisible(nsIPresS
 
   return false;
 }
 
 NS_IMETHODIMP
 nsTypeAheadFind::IsRangeRendered(nsIDOMRange *aRange,
                                 bool *aResult)
 {
-  // Jump through hoops to extract the docShell from the range.
-  nsCOMPtr<nsIDOMNode> node;
-  aRange->GetStartContainer(getter_AddRefs(node));
-  nsCOMPtr<nsIDOMDocument> document;
-  node->GetOwnerDocument(getter_AddRefs(document));
-  nsCOMPtr<mozIDOMWindowProxy> window;
-  document->GetDefaultView(getter_AddRefs(window));
-  nsCOMPtr<nsIWebNavigation> navNav (do_GetInterface(window));
-  nsCOMPtr<nsIDocShell> docShell (do_GetInterface(navNav));
+  nsCOMPtr<nsIDOMNode> domNode;
+  aRange->GetStartContainer(getter_AddRefs(domNode));
+  nsCOMPtr<nsINode> node = do_QueryInterface(domNode);
 
-  // Set up the arguments needed to check if a range is visible.
-  nsCOMPtr<nsIPresShell> presShell (docShell->GetPresShell());
+  nsIDocument* doc = node->OwnerDoc();
+  nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
+  if (!presShell) {
+    return NS_ERROR_UNEXPECTED;
+  }
   RefPtr<nsPresContext> presContext = presShell->GetPresContext();
   *aResult = IsRangeRendered(presShell, presContext, aRange);
   return NS_OK;
 }
 
 bool
 nsTypeAheadFind::IsRangeRendered(nsIPresShell *aPresShell,
                                  nsPresContext *aPresContext,
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -212,17 +212,18 @@ nsBaseDragService::InvokeDragSession(nsI
                                        nsIContentPolicy::TYPE_OTHER)
 {
   AUTO_PROFILER_LABEL("nsBaseDragService::InvokeDragSession", OTHER);
 
   NS_ENSURE_TRUE(aDOMNode, NS_ERROR_INVALID_ARG);
   NS_ENSURE_TRUE(mSuppressLevel == 0, NS_ERROR_FAILURE);
 
   // stash the document of the dom node
-  aDOMNode->GetOwnerDocument(getter_AddRefs(mSourceDocument));
+  nsCOMPtr<nsINode> node = do_QueryInterface(aDOMNode);
+  mSourceDocument = do_QueryInterface(node->OwnerDoc());
   mSourceNode = aDOMNode;
   mContentPolicyType = aContentPolicyType;
   mEndDragPoint = LayoutDeviceIntPoint(0, 0);
 
   // When the mouse goes down, the selection code starts a mouse
   // capture. However, this gets in the way of determining drag
   // feedback for things like trees because the event coordinates
   // are in the wrong coord system, so turn off mouse capture.