Bug 1456588 part 6. Change nsXULCommandDispatcher::GetRootFocusedContentAndWindow to return Element. r=enndeakin
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 26 Apr 2018 10:37:47 -0400
changeset 471874 f240cf49fff8832d31b77334aff826113dd31d59
parent 471873 b64df38f5117a598d9036cbdf367acdb212ea23e
child 471875 3f3d8231bf747cba05b0f844afe0fa1694791dcf
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs1456588
milestone61.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 1456588 part 6. Change nsXULCommandDispatcher::GetRootFocusedContentAndWindow to return Element. r=enndeakin
dom/xul/nsXULCommandDispatcher.cpp
dom/xul/nsXULCommandDispatcher.h
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -94,17 +94,17 @@ nsXULCommandDispatcher::GetWindowRoot()
     if (nsCOMPtr<nsPIDOMWindowOuter> window = mDocument->GetWindow()) {
       return window->GetTopWindowRoot();
     }
   }
 
   return nullptr;
 }
 
-nsIContent*
+Element*
 nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow)
 {
   *aWindow = nullptr;
 
   if (!mDocument) {
     return nullptr;
   }
 
@@ -121,32 +121,30 @@ nsXULCommandDispatcher::GetRootFocusedCo
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::GetFocusedElement(Element** aElement)
 {
   *aElement = nullptr;
 
   nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
-  nsIContent* focusedContent =
+  RefPtr<Element> focusedContent =
     GetRootFocusedContentAndWindow(getter_AddRefs(focusedWindow));
   if (focusedContent) {
-    CallQueryInterface(focusedContent, aElement);
-
     // Make sure the caller can access the focused element.
-    nsINode* node = *aElement;
-    if (!node || !nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(node->NodePrincipal())) {
+    if (!nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->
+          Subsumes(focusedContent->NodePrincipal())) {
       // XXX This might want to return null, but we use that return value
       // to mean "there is no focused element," so to be clear, throw an
       // exception.
-      NS_RELEASE(*aElement);
       return NS_ERROR_DOM_SECURITY_ERR;
     }
   }
 
+  focusedContent.forget(aElement);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::GetFocusedWindow(mozIDOMWindowProxy** aWindow)
 {
   *aWindow = nullptr;
 
--- a/dom/xul/nsXULCommandDispatcher.h
+++ b/dom/xul/nsXULCommandDispatcher.h
@@ -18,16 +18,22 @@
 #include "nsWeakReference.h"
 #include "nsIDOMNode.h"
 #include "nsString.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsIDOMElement;
 class nsPIWindowRoot;
 
+namespace mozilla {
+namespace dom {
+class Element;
+} // namespace dom
+} // namespace mozilla
+
 class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
                                public nsSupportsWeakReference
 {
 public:
     explicit nsXULCommandDispatcher(nsIDocument* aDocument);
 
     // nsISupports
     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -38,17 +44,18 @@ public:
     NS_DECL_NSIDOMXULCOMMANDDISPATCHER
 
     void Disconnect();
 protected:
     virtual ~nsXULCommandDispatcher();
 
     already_AddRefed<nsPIWindowRoot> GetWindowRoot();
 
-    nsIContent* GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow);
+    mozilla::dom::Element*
+      GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow);
 
     nsCOMPtr<nsIDocument> mDocument;
 
     class Updater {
     public:
       Updater(nsIDOMElement* aElement,
               const nsAString& aEvents,
               const nsAString& aTargets)