From 493dd48468ec1b38dd712c52cb1cd38a0a6c31dd Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 31 Jan 2018 14:49:27 -0500 Subject: [PATCH] Bug 1434399 part 5. Remove nsIDOMXULDocument's commandDispatcher attribute. r=mystor MozReview-Commit-ID: BjRVr3ScuK5 --- dom/base/nsGlobalWindowOuter.cpp | 11 +++++------ dom/base/nsIDocument.h | 2 ++ dom/interfaces/xul/nsIDOMXULDocument.idl | 2 -- dom/xul/XULDocument.cpp | 9 +-------- dom/xul/XULDocument.h | 6 +++++- dom/xul/nsXULContentUtils.cpp | 12 +++++------- layout/xul/nsXULPopupManager.cpp | 9 ++++----- 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index d08167aaecc0..98e1d54aa41e 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -180,8 +180,7 @@ #include "nsNetCID.h" #include "nsIArray.h" -// XXX An unfortunate dependency exists here (two XUL files). -#include "nsIDOMXULDocument.h" +#include "XULDocument.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsBindingManager.h" @@ -6385,15 +6384,15 @@ nsGlobalWindowOuter::UpdateCommands(const nsAString& anAction, return; } - nsCOMPtr xulDoc = - do_QueryInterface(rootWindow->GetExtantDoc()); + nsIDocument* doc = rootWindow->GetExtantDoc(); + XULDocument* xulDoc = doc ? doc->AsXULDocument() : nullptr; // See if we contain a XUL document. // selectionchange action is only used for mozbrowser, not for XUL. So we bypass // XUL command dispatch if anAction is "selectionchange". if (xulDoc && !anAction.EqualsLiteral("selectionchange")) { // Retrieve the command dispatcher and call updateCommands on it. - nsCOMPtr xulCommandDispatcher; - xulDoc->GetCommandDispatcher(getter_AddRefs(xulCommandDispatcher)); + nsIDOMXULCommandDispatcher* xulCommandDispatcher = + xulDoc->GetCommandDispatcher(); if (xulCommandDispatcher) { nsContentUtils::AddScriptRunner(new CommandDispatcher(xulCommandDispatcher, anAction)); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 5c78102875f8..b05ded65e308 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -173,6 +173,7 @@ class XPathEvaluator; class XPathExpression; class XPathNSResolver; class XPathResult; +class XULDocument; template class Sequence; template class CallbackObjectHolder; @@ -3042,6 +3043,7 @@ public: virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; } virtual mozilla::dom::SVGDocument* AsSVGDocument() { return nullptr; } + virtual mozilla::dom::XULDocument* AsXULDocument() { return nullptr; } /* * Given a node, get a weak reference to it and append that reference to diff --git a/dom/interfaces/xul/nsIDOMXULDocument.idl b/dom/interfaces/xul/nsIDOMXULDocument.idl index 9484e292cdea..acb78a04984d 100644 --- a/dom/interfaces/xul/nsIDOMXULDocument.idl +++ b/dom/interfaces/xul/nsIDOMXULDocument.idl @@ -13,8 +13,6 @@ interface nsIBoxObject; [uuid(7790d4c3-e8f0-4e29-9887-d683ed2b2a44)] interface nsIDOMXULDocument : nsIDOMDocument { - readonly attribute nsIDOMXULCommandDispatcher commandDispatcher; - readonly attribute long width; readonly attribute long height; diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 644746190d4b..c6401cb801a9 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -50,6 +50,7 @@ #include "nsPIWindowRoot.h" #include "nsXULCommandDispatcher.h" #include "nsXULElement.h" +#include "nsXULPrototypeCache.h" #include "mozilla/Logging.h" #include "nsIFrame.h" #include "nsXBLService.h" @@ -1427,14 +1428,6 @@ XULDocument::GetTooltipNode() return nullptr; } -NS_IMETHODIMP -XULDocument::GetCommandDispatcher(nsIDOMXULCommandDispatcher** aTracker) -{ - *aTracker = mCommandDispatcher; - NS_IF_ADDREF(*aTracker); - return NS_OK; -} - nsresult XULDocument::AddElementToDocumentPre(Element* aElement) { diff --git a/dom/xul/XULDocument.h b/dom/xul/XULDocument.h index 3f081160fd1e..22f8f5633f98 100644 --- a/dom/xul/XULDocument.h +++ b/dom/xul/XULDocument.h @@ -9,7 +9,6 @@ #include "nsAutoPtr.h" #include "nsCOMPtr.h" #include "nsXULPrototypeDocument.h" -#include "nsXULPrototypeCache.h" #include "nsTArray.h" #include "mozilla/dom/XMLDocument.h" @@ -35,6 +34,7 @@ class nsIRDFResource; class nsIRDFService; class nsPIWindowRoot; +class nsXULPrototypeElement; #if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript)) class nsIObjectInputStream; class nsIObjectOutputStream; @@ -84,6 +84,10 @@ public: virtual void EndLoad() override; + virtual XULDocument* AsXULDocument() override { + return this; + } + // nsIMutationObserver interface NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED diff --git a/dom/xul/nsXULContentUtils.cpp b/dom/xul/nsXULContentUtils.cpp index ad4d7b062be1..3ce2abe983c4 100644 --- a/dom/xul/nsXULContentUtils.cpp +++ b/dom/xul/nsXULContentUtils.cpp @@ -20,7 +20,6 @@ #include "nsIDocument.h" #include "nsIDOMElement.h" #include "nsIDOMXULCommandDispatcher.h" -#include "nsIDOMXULDocument.h" #include "nsIRDFService.h" #include "nsIServiceManager.h" #include "nsXULContentUtils.h" @@ -28,8 +27,10 @@ #include "nsRDFCID.h" #include "nsString.h" #include "nsGkAtoms.h" +#include "XULDocument.h" using namespace mozilla; +using dom::XULDocument; //------------------------------------------------------------------------ @@ -120,16 +121,13 @@ nsXULContentUtils::SetCommandUpdater(nsIDocument* aDocument, Element* aElement) nsresult rv; - nsCOMPtr xuldoc = do_QueryInterface(aDocument); + XULDocument* xuldoc = aDocument->AsXULDocument(); NS_ASSERTION(xuldoc != nullptr, "not a xul document"); if (! xuldoc) return NS_ERROR_UNEXPECTED; - nsCOMPtr dispatcher; - rv = xuldoc->GetCommandDispatcher(getter_AddRefs(dispatcher)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get dispatcher"); - if (NS_FAILED(rv)) return rv; - + nsCOMPtr dispatcher = + xuldoc->GetCommandDispatcher(); NS_ASSERTION(dispatcher != nullptr, "no dispatcher"); if (! dispatcher) return NS_ERROR_UNEXPECTED; diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index cc7e9b5dcb21..571876b2de20 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -15,8 +15,6 @@ #include "nsIDOMEvent.h" #include "nsXULElement.h" #include "nsIDOMXULMenuListElement.h" -#include "nsIXULDocument.h" -#include "nsIDOMXULDocument.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsCSSFrameConstructor.h" #include "nsGlobalWindow.h" @@ -36,6 +34,7 @@ #include "nsPIWindowRoot.h" #include "nsFrameManager.h" #include "nsIObserverService.h" +#include "XULDocument.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() #include "mozilla/dom/UIEvent.h" @@ -1978,10 +1977,10 @@ nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup) } // When a menu is opened, make sure that command updating is unlocked first. - nsCOMPtr xulDoc = do_QueryInterface(document); + XULDocument* xulDoc = document->AsXULDocument(); if (xulDoc) { - nsCOMPtr xulCommandDispatcher; - xulDoc->GetCommandDispatcher(getter_AddRefs(xulCommandDispatcher)); + nsCOMPtr xulCommandDispatcher = + xulDoc->GetCommandDispatcher(); if (xulCommandDispatcher) { xulCommandDispatcher->Unlock(); }