diff --git a/dom/xul/nsXULCommandDispatcher.cpp b/dom/xul/nsXULCommandDispatcher.cpp index 5046bef7f8b9..58cf788531c9 100644 --- a/dom/xul/nsXULCommandDispatcher.cpp +++ b/dom/xul/nsXULCommandDispatcher.cpp @@ -99,7 +99,7 @@ nsXULCommandDispatcher::GetWindowRoot() return nullptr; } -nsIContent* +Element* nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow) { *aWindow = nullptr; @@ -126,22 +126,20 @@ nsXULCommandDispatcher::GetFocusedElement(Element** aElement) *aElement = nullptr; nsCOMPtr focusedWindow; - nsIContent* focusedContent = + RefPtr 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; } diff --git a/dom/xul/nsXULCommandDispatcher.h b/dom/xul/nsXULCommandDispatcher.h index 234ae70d89bc..d808dc6ef7b2 100644 --- a/dom/xul/nsXULCommandDispatcher.h +++ b/dom/xul/nsXULCommandDispatcher.h @@ -23,6 +23,12 @@ class nsIDOMElement; class nsPIWindowRoot; +namespace mozilla { +namespace dom { +class Element; +} // namespace dom +} // namespace mozilla + class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher, public nsSupportsWeakReference { @@ -43,7 +49,8 @@ protected: already_AddRefed GetWindowRoot(); - nsIContent* GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow); + mozilla::dom::Element* + GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow); nsCOMPtr mDocument;