Bug 1460940 - Remove nsIDOMDocument uses in toolkit/. r?bz draft
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Fri, 11 May 2018 19:46:15 +0200
changeset 794812 2e86671438e686c3981a71925ddc040a1ecf043e
parent 794811 808311cbaa76f9ce60ce8e671280c0f397e2c9b2
child 794813 206213c3562d0a958000be9671634effb7c1982f
push id109776
push userbmo:adrian.wielgosik@gmail.com
push dateMon, 14 May 2018 13:49:41 +0000
reviewersbz
bugs1460940
milestone62.0a1
Bug 1460940 - Remove nsIDOMDocument uses in toolkit/. r?bz MozReview-Commit-ID: LJhw1bKsUkn
toolkit/components/extensions/ExtensionPolicyService.cpp
toolkit/components/extensions/mozIExtensionProcessScript.idl
toolkit/components/find/nsWebBrowserFind.cpp
toolkit/components/find/nsWebBrowserFind.h
--- a/toolkit/components/extensions/ExtensionPolicyService.cpp
+++ b/toolkit/components/extensions/ExtensionPolicyService.cpp
@@ -301,18 +301,17 @@ ExtensionPolicyService::CheckDocument(ns
     if (win->GetDocumentURI()) {
       CheckContentScripts(win.get(), false);
     }
 
     nsIPrincipal* principal = aDocument->NodePrincipal();
 
     RefPtr<WebExtensionPolicy> policy = BasePrincipal::Cast(principal)->AddonPolicy();
     if (policy) {
-      nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aDocument);
-      ProcessScript().InitExtensionDocument(policy, doc);
+      ProcessScript().InitExtensionDocument(policy, aDocument);
     }
   }
 }
 
 // Checks for loads of about:blank into new window globals, and loads any
 // matching content scripts. about:blank loads do not trigger document element
 // inserted events, so they're the only load type that are special cased this
 // way.
--- a/toolkit/components/extensions/mozIExtensionProcessScript.idl
+++ b/toolkit/components/extensions/mozIExtensionProcessScript.idl
@@ -1,18 +1,18 @@
 /* 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 "nsISupports.idl"
 
 interface mozIDOMWindowProxy;
-interface nsIDOMDocument;
+webidl Document;
 
 [scriptable,uuid(6b09dc51-6caa-4ca7-9d6d-30c87258a630)]
 interface mozIExtensionProcessScript : nsISupports
 {
   void preloadContentScript(in nsISupports contentScript);
 
   void loadContentScript(in nsISupports contentScript, in mozIDOMWindowProxy window);
 
-  void initExtensionDocument(in nsISupports extension, in nsIDOMDocument doc);
+  void initExtensionDocument(in nsISupports extension, in Document doc);
 };
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -15,17 +15,16 @@
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsIURI.h"
 #include "nsIDocShell.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
-#include "nsIDOMDocument.h"
 #include "nsISelectionController.h"
 #include "nsIFrame.h"
 #include "nsITextControlFrame.h"
 #include "nsReadableUtils.h"
 #include "nsIContent.h"
 #include "nsContentCID.h"
 #include "nsIServiceManager.h"
 #include "nsIObserverService.h"
@@ -419,43 +418,41 @@ nsWebBrowserFind::SetSelectionAndScroll(
       nsISelectionController::SELECTION_WHOLE_SELECTION,
       nsISelectionController::SCROLL_CENTER_VERTICALLY |
         nsISelectionController::SCROLL_SYNCHRONOUS);
   }
 }
 
 // Adapted from TextServicesDocument::GetDocumentContentRootNode
 nsresult
-nsWebBrowserFind::GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode)
+nsWebBrowserFind::GetRootNode(nsIDocument* aDoc, nsIDOMNode** aNode)
 {
+  NS_ENSURE_ARG_POINTER(aDoc);
   NS_ENSURE_ARG_POINTER(aNode);
   *aNode = 0;
 
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDomDoc);
-  NS_ENSURE_ARG_POINTER(doc);
-
-  if (doc->IsHTMLOrXHTML()) {
-    Element* body = doc->GetBody();
+  if (aDoc->IsHTMLOrXHTML()) {
+    Element* body = aDoc->GetBody();
     NS_ENSURE_ARG_POINTER(body);
     NS_ADDREF(*aNode = body->AsDOMNode());
     return NS_OK;
   }
 
   // For non-HTML documents, the content root node will be the doc element.
-  Element* root = doc->GetDocumentElement();
+  Element* root = aDoc->GetDocumentElement();
   NS_ENSURE_ARG_POINTER(root);
   NS_ADDREF(*aNode = root->AsDOMNode());
   return NS_OK;
 }
 
 nsresult
 nsWebBrowserFind::SetRangeAroundDocument(nsRange* aSearchRange,
                                          nsRange* aStartPt,
                                          nsRange* aEndPt,
-                                         nsIDOMDocument* aDoc)
+                                         nsIDocument* aDoc)
 {
   nsCOMPtr<nsIDOMNode> bodyNode;
   nsresult rv = GetRootNode(aDoc, getter_AddRefs(bodyNode));
   nsCOMPtr<nsIContent> bodyContent(do_QueryInterface(bodyNode));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_ARG_POINTER(bodyContent);
 
   uint32_t childCount = bodyContent->GetChildCount();
@@ -479,17 +476,17 @@ nsWebBrowserFind::SetRangeAroundDocument
 }
 
 // Set the range to go from the end of the current selection to the end of the
 // document (forward), or beginning to beginning (reverse). or around the whole
 // document if there's no selection.
 nsresult
 nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange,
                                   nsRange* aStartPt, nsRange* aEndPt,
-                                  nsIDOMDocument* aDoc, Selection* aSel,
+                                  nsIDocument* aDoc, Selection* aSel,
                                   bool aWrap)
 {
   NS_ENSURE_ARG_POINTER(aSel);
 
   // There is a selection.
   uint32_t count = aSel->RangeCount();
   if (count < 1) {
     return SetRangeAroundDocument(aSearchRange, aStartPt, aEndPt, aDoc);
@@ -722,27 +719,24 @@ nsWebBrowserFind::SearchInFrame(nsPIDOMW
 
   RefPtr<nsRange> searchRange = new nsRange(theDoc);
   RefPtr<nsRange> startPt = new nsRange(theDoc);
   RefPtr<nsRange> endPt = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(endPt);
 
   nsCOMPtr<nsIDOMRange> foundRange;
 
-  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(theDoc);
-  MOZ_ASSERT(domDoc);
-
   // If !aWrapping, search from selection to end
   if (!aWrapping)
-    rv = GetSearchLimits(searchRange, startPt, endPt, domDoc, sel, false);
+    rv = GetSearchLimits(searchRange, startPt, endPt, theDoc, sel, false);
 
   // If aWrapping, search the part of the starting frame
   // up to the point where we left off.
   else
-    rv = GetSearchLimits(searchRange, startPt, endPt, domDoc, sel, true);
+    rv = GetSearchLimits(searchRange, startPt, endPt, theDoc, sel, true);
 
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = find->Find(mSearchString.get(), searchRange, startPt, endPt,
                   getter_AddRefs(foundRange));
 
   if (NS_SUCCEEDED(rv) && foundRange) {
     *aDidFind = true;
--- a/toolkit/components/find/nsWebBrowserFind.h
+++ b/toolkit/components/find/nsWebBrowserFind.h
@@ -19,16 +19,17 @@
 #define NS_WEB_BROWSER_FIND_CONTRACTID "@mozilla.org/embedcomp/find;1"
 
 #define NS_WEB_BROWSER_FIND_CID \
   {0x57cf9383, 0x3405, 0x11d5, {0xbe, 0x5b, 0xaa, 0x20, 0xfa, 0x2c, 0xf3, 0x7c}}
 
 class nsIDOMWindow;
 
 class nsIDocShell;
+class nsIDocument;
 class nsRange;
 
 namespace mozilla {
 namespace dom {
 class Selection;
 } // namespace dom
 } // namespace mozilla
 
@@ -66,25 +67,25 @@ protected:
   already_AddRefed<mozilla::dom::Selection>
     GetFrameSelection(nsPIDOMWindowOuter* aWindow);
   nsresult ClearFrameSelection(nsPIDOMWindowOuter* aWindow);
 
   nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
 
   void SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow, nsRange* aRange);
 
-  nsresult GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode);
+  nsresult GetRootNode(nsIDocument* aDomDoc, nsIDOMNode** aNode);
   nsresult GetSearchLimits(nsRange* aRange,
                            nsRange* aStartPt, nsRange* aEndPt,
-                           nsIDOMDocument* aDoc, mozilla::dom::Selection* aSel,
+                           nsIDocument* aDoc, mozilla::dom::Selection* aSel,
                            bool aWrap);
   nsresult SetRangeAroundDocument(nsRange* aSearchRange,
                                   nsRange* aStartPoint,
                                   nsRange* aEndPoint,
-                                  nsIDOMDocument* aDoc);
+                                  nsIDocument* aDoc);
 
 protected:
   nsString mSearchString;
 
   bool mFindBackwards;
   bool mWrapFind;
   bool mEntireWord;
   bool mMatchCase;