Bug 1432944 part 11. Remove nsIDOMElement::GetAttribute. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 29 Jan 2018 23:28:00 -0500
changeset 401408 76c001daf2656dd2ba7396d56f667fc0c555e7b9
parent 401407 a59431cb28a1315ae036b2be828242da97ef54cc
child 401409 e723bf17f405b99ffdd479a9541e55405c97248a
push id33343
push userrgurzau@mozilla.com
push dateTue, 30 Jan 2018 10:03:41 +0000
treeherdermozilla-central@9746e0a0a81c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1432944
milestone60.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 1432944 part 11. Remove nsIDOMElement::GetAttribute. r=mccr8 MozReview-Commit-ID: 2f1vFvRdCPG
accessible/generic/Accessible.cpp
dom/base/Element.h
dom/base/nsContentAreaDragDrop.cpp
dom/base/nsContentUtils.cpp
dom/interfaces/core/nsIDOMElement.idl
dom/security/nsCSPContext.cpp
dom/xul/nsXULCommandDispatcher.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/TextEditUtils.cpp
layout/base/PresShell.cpp
layout/base/nsDocumentViewer.cpp
layout/inspector/inDOMView.cpp
layout/xul/tree/nsTreeContentView.cpp
security/manager/ssl/nsKeygenHandler.cpp
widget/cocoa/nsMenuBarX.mm
xpfe/appshell/nsAppShellWindowEnumerator.cpp
--- a/accessible/generic/Accessible.cpp
+++ b/accessible/generic/Accessible.cpp
@@ -71,16 +71,17 @@
 #include "nsAttrName.h"
 
 #ifdef DEBUG
 #include "nsIDOMCharacterData.h"
 #endif
 
 #include "mozilla/Assertions.h"
 #include "mozilla/BasicEvents.h"
+#include "mozilla/ErrorResult.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Unused.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/CanvasRenderingContext2D.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
@@ -784,20 +785,18 @@ Accessible::XULElmName(DocAccessible* aD
   } else {
     nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl = do_QueryInterface(aElm);
     if (itemEl) {
       itemEl->GetLabel(aName);
     } else {
       nsCOMPtr<nsIDOMXULSelectControlElement> select = do_QueryInterface(aElm);
       // Use label if this is not a select control element which
       // uses label attribute to indicate which option is selected
-      if (!select) {
-        nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(aElm));
-        if (xulEl)
-          xulEl->GetAttribute(NS_LITERAL_STRING("label"), aName);
+      if (!select && aElm->IsElement()) {
+        aElm->AsElement()->GetAttribute(NS_LITERAL_STRING("label"), aName);
       }
     }
   }
 
   // CASES #2 and #3 ------ label as a child or <label control="id" ... > </label>
   if (aName.IsEmpty()) {
     Accessible* labelAcc = nullptr;
     XULLabelIterator iter(aDocument, aElm);
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1111,17 +1111,17 @@ public:
       slots->mAttributeMap = new nsDOMAttributeMap(this);
     }
 
     return slots->mAttributeMap;
   }
 
   void GetAttributeNames(nsTArray<nsString>& aResult);
 
-  void GetAttribute(const nsAString& aName, nsString& aReturn)
+  void GetAttribute(const nsAString& aName, nsAString& aReturn)
   {
     DOMString str;
     GetAttribute(aName, str);
     str.ToString(aReturn);
   }
 
   void GetAttribute(const nsAString& aName, DOMString& aReturn);
   void GetAttributeNS(const nsAString& aNamespaceURI,
@@ -2190,19 +2190,10 @@ nsresult                                
   }                                                                   \
   NS_IMETHODIMP                                                       \
   _class::Set##_method(bool aValue)                                   \
   {                                                                   \
     return SetBoolAttr(nsGkAtoms::_atom, aValue);                     \
   }
 
 #define NS_FORWARD_NSIDOMELEMENT_TO_GENERIC                                   \
-typedef mozilla::dom::Element Element;                                        \
-using Element::GetAttribute;                                                  \
-NS_IMETHOD GetAttribute(const nsAString& name, nsAString& _retval) final      \
-  override                                                                    \
-{                                                                             \
-  nsString attr;                                                              \
-  GetAttribute(name, attr);                                                   \
-  _retval = attr;                                                             \
-  return NS_OK;                                                               \
-}
+typedef mozilla::dom::Element Element;
 #endif // mozilla_dom_Element_h__
--- a/dom/base/nsContentAreaDragDrop.cpp
+++ b/dom/base/nsContentAreaDragDrop.cpp
@@ -537,19 +537,21 @@ DragDataProducer::Produce(DataTransfer* 
         image->GetCurrentURI(getter_AddRefs(imageURI));
         if (imageURI) {
           nsAutoCString spec;
           rv = imageURI->GetSpec(spec);
           NS_ENSURE_SUCCESS(rv, rv);
           CopyUTF8toUTF16(spec, mUrlString);
         }
 
-        nsCOMPtr<nsIDOMElement> imageElement(do_QueryInterface(image));
+        nsCOMPtr<Element> imageElement(do_QueryInterface(image));
         // XXXbz Shouldn't we use the "title" attr for title?  Using
         // "alt" seems very wrong....
+        // XXXbz Also, what if this is an nsIImageLoadingContent
+        // that's not an <html:img>?
         if (imageElement) {
           imageElement->GetAttribute(NS_LITERAL_STRING("alt"), mTitleString);
         }
 
         if (mTitleString.IsEmpty()) {
           mTitleString = mUrlString;
         }
 
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9894,17 +9894,18 @@ nsContentUtils::GetPresentationURL(nsIDo
 
   nsCOMPtr<nsILoadContext> loadContext(do_QueryInterface(aDocShell));
   nsCOMPtr<nsIDOMElement> topFrameElement;
   loadContext->GetTopFrameElement(getter_AddRefs(topFrameElement));
   if (!topFrameElement) {
     return;
   }
 
-  topFrameElement->GetAttribute(NS_LITERAL_STRING("mozpresentation"), aPresentationUrl);
+  nsCOMPtr<Element> topFrameElt = do_QueryInterface(topFrameElement);
+  topFrameElt->GetAttribute(NS_LITERAL_STRING("mozpresentation"), aPresentationUrl);
 }
 
 /* static */ nsIDocShell*
 nsContentUtils::GetDocShellForEventTarget(EventTarget* aTarget)
 {
   nsCOMPtr<nsPIDOMWindowInner> innerWindow;
 
   if (nsCOMPtr<nsINode> node = do_QueryInterface(aTarget)) {
--- a/dom/interfaces/core/nsIDOMElement.idl
+++ b/dom/interfaces/core/nsIDOMElement.idl
@@ -22,10 +22,9 @@ interface nsIDOMMozNamedAttrMap;
  *
  * For more information on this interface please see 
  * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-element
  */
 
 [uuid(6289999b-1008-4269-b42a-413ec5a9d3f4)]
 interface nsIDOMElement : nsIDOMNode
 {
-  DOMString          getAttribute(in DOMString name);
 };
--- a/dom/security/nsCSPContext.cpp
+++ b/dom/security/nsCSPContext.cpp
@@ -46,16 +46,17 @@
 #include "mozilla/dom/CSPReportBinding.h"
 #include "mozilla/dom/CSPDictionariesBinding.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "nsINetworkInterceptController.h"
 #include "nsSandboxFlags.h"
 #include "nsIScriptElement.h"
 #include "nsIEventTarget.h"
 #include "mozilla/dom/DocGroup.h"
+#include "mozilla/dom/Element.h"
 #include "nsXULAppAPI.h"
 
 using namespace mozilla;
 
 static LogModule*
 GetCspContextLog()
 {
   static LazyLogModule gCspContextPRLog("CSPContext");
@@ -184,20 +185,20 @@ nsCSPContext::ShouldLoad(nsContentPolicy
     return NS_OK;
   }
 
   nsAutoString nonce;
   bool parserCreated = false;
   if (!isPreload) {
     if (aContentType == nsIContentPolicy::TYPE_SCRIPT ||
         aContentType == nsIContentPolicy::TYPE_STYLESHEET) {
-      nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(aRequestContext);
-      if (htmlElement) {
-        rv = htmlElement->GetAttribute(NS_LITERAL_STRING("nonce"), nonce);
-        NS_ENSURE_SUCCESS(rv, rv);
+      nsCOMPtr<Element> element = do_QueryInterface(aRequestContext);
+      if (element && element->IsHTMLElement()) {
+        // XXXbz What about SVG elements that can have nonce?
+        element->GetAttribute(NS_LITERAL_STRING("nonce"), nonce);
       }
     }
 
     nsCOMPtr<nsIScriptElement> script = do_QueryInterface(aRequestContext);
     if (script && script->GetParserCreated() != mozilla::dom::NOT_FROM_PARSER) {
       parserCreated = true;
     }
   }
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -355,22 +355,21 @@ nsXULCommandDispatcher::UpdateCommands(c
     if (!mPendingUpdates.Contains(aEventName)) {
       mPendingUpdates.AppendElement(aEventName);
     }
 
     return NS_OK;
   }
 
   nsAutoString id;
-  nsCOMPtr<nsIDOMElement> element;
-  GetFocusedElement(getter_AddRefs(element));
+  nsCOMPtr<nsIDOMElement> domElement;
+  GetFocusedElement(getter_AddRefs(domElement));
+  nsCOMPtr<Element> element = do_QueryInterface(domElement);
   if (element) {
-    nsresult rv = element->GetAttribute(NS_LITERAL_STRING("id"), id);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's id");
-    if (NS_FAILED(rv)) return rv;
+    element->GetAttribute(NS_LITERAL_STRING("id"), id);
   }
 
   nsCOMArray<nsIContent> updaters;
 
   for (Updater* updater = mUpdaters; updater != nullptr; updater = updater->mNext) {
     // Skip any nodes that don't match our 'events' or 'targets'
     // filters.
     if (! Matches(updater->mEvents, aEventName))
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1322,24 +1322,24 @@ EditorBase::GetAttributeValue(nsIDOMElem
                               nsAString& aResultValue,
                               bool* aResultIsSet)
 {
   NS_ENSURE_TRUE(aResultIsSet, NS_ERROR_NULL_POINTER);
   *aResultIsSet = false;
   if (!aElement) {
     return NS_OK;
   }
+  nsCOMPtr<Element> element = do_QueryInterface(aElement);
   nsAutoString value;
-  nsresult rv = aElement->GetAttribute(aAttribute, value);
-  NS_ENSURE_SUCCESS(rv, rv);
+  element->GetAttribute(aAttribute, value);
   if (!DOMStringIsNull(value)) {
     *aResultIsSet = true;
     aResultValue = value;
   }
-  return rv;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::RemoveAttribute(nsIDOMElement* aElement,
                             const nsAString& aAttribute)
 {
   if (NS_WARN_IF(aAttribute.IsEmpty())) {
     return NS_ERROR_FAILURE;
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -466,17 +466,17 @@ HTMLEditor::StartResizing(nsIDOMElement*
 
   // do we want to preserve ratio or not?
   bool preserveRatio = HTMLEditUtils::IsImage(mResizedObject) &&
     Preferences::GetBool("editor.resizing.preserve_ratio", true);
 
   // the way we change the position/size of the shadow depends on
   // the handle
   nsAutoString locationStr;
-  aHandle->GetAttribute(NS_LITERAL_STRING("anonlocation"), locationStr);
+  mActivatedHandle->GetAttribute(NS_LITERAL_STRING("anonlocation"), locationStr);
   if (locationStr.Equals(kTopLeft)) {
     SetResizeIncrements(1, 1, -1, -1, preserveRatio);
   } else if (locationStr.Equals(kTop)) {
     SetResizeIncrements(0, 1, 0, -1, false);
   } else if (locationStr.Equals(kTopRight)) {
     SetResizeIncrements(0, 1, 1, -1, preserveRatio);
   } else if (locationStr.Equals(kLeft)) {
     SetResizeIncrements(1, 0, -1, 0, false);
--- a/editor/libeditor/TextEditUtils.cpp
+++ b/editor/libeditor/TextEditUtils.cpp
@@ -82,23 +82,24 @@ TextEditUtils::IsMozBR(nsINode* aNode)
 /**
  * HasMozAttr() returns true if aNode has type attribute and its value is
  * |_moz|. (Used to indicate div's and br's we use in mail compose rules)
  */
 bool
 TextEditUtils::HasMozAttr(nsIDOMNode* aNode)
 {
   MOZ_ASSERT(aNode);
-  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
+  nsCOMPtr<Element> element = do_QueryInterface(aNode);
   if (!element) {
     return false;
   }
-  nsAutoString typeAttrVal;
-  nsresult rv = element->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal);
-  return NS_SUCCEEDED(rv) && typeAttrVal.LowerCaseEqualsLiteral("_moz");
+  return element->AttrValueIs(kNameSpaceID_None,
+                              nsGkAtoms::type,
+                              NS_LITERAL_STRING("_moz"),
+                              eIgnoreCase);
 }
 
 /******************************************************************************
  * AutoEditInitRulesTrigger
  ******************************************************************************/
 
 AutoEditInitRulesTrigger::AutoEditInitRulesTrigger(TextEditor* aTextEditor,
                                                    nsresult& aResult)
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -31,16 +31,17 @@
 
 #ifdef XP_WIN
 #include "winuser.h"
 #endif
 
 #include "gfxContext.h"
 #include "gfxPrefs.h"
 #include "gfxUserFontSet.h"
+#include "nsContentList.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsIContentIterator.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h" // for Event::GetEventPopupControlState()
 #include "mozilla/dom/PointerEventHandler.h"
 #include "nsIDocument.h"
 #include "nsAnimationManager.h"
@@ -3108,39 +3109,35 @@ PresShell::GoToAnchor(const nsAString& a
         }
       }
     }
   }
 
   // Search for anchor in the HTML namespace with a matching name
   if (!content && !htmlDoc)
   {
-    nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mDocument);
-    nsCOMPtr<nsIDOMNodeList> list;
     NS_NAMED_LITERAL_STRING(nameSpace, "http://www.w3.org/1999/xhtml");
     // Get the list of anchor elements
-    rv = doc->GetElementsByTagNameNS(nameSpace, NS_LITERAL_STRING("a"), getter_AddRefs(list));
-    if (NS_SUCCEEDED(rv) && list) {
-      uint32_t i;
-      // Loop through the named nodes looking for the first anchor
-      for (i = 0; true; i++) {
-        nsCOMPtr<nsIDOMNode> node;
-        rv = list->Item(i, getter_AddRefs(node));
-        if (!node) { // End of list
-          break;
-        }
-        // Compare the name attribute
-        nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
-        nsAutoString value;
-        if (element && NS_SUCCEEDED(element->GetAttribute(NS_LITERAL_STRING("name"), value))) {
-          if (value.Equals(aAnchorName)) {
-            content = do_QueryInterface(element);
-            break;
-          }
-        }
+    nsCOMPtr<nsINodeList> list =
+      mDocument->GetElementsByTagNameNS(nameSpace, NS_LITERAL_STRING("a"));
+    // Loop through the anchors looking for the first one with the given name.
+    for (uint32_t i = 0; true; i++) {
+      nsIContent* node = list->Item(i);
+      if (!node) { // End of list
+        break;
+      }
+
+      // Compare the name attribute
+      if (node->IsElement() &&
+          node->AsElement()->AttrValueIs(kNameSpaceID_None,
+                                         nsGkAtoms::name,
+                                         aAnchorName,
+                                         eCaseMatters)) {
+        content = node;
+        break;
       }
     }
   }
 
   esm->SetContentState(content, NS_EVENT_STATE_URLTARGET);
 
 #ifdef ACCESSIBILITY
   nsIContent *anchorTarget = content;
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2375,20 +2375,19 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
   nsCOMPtr<nsIDOMEventTarget> chromeHandler;
   nsCOMPtr<nsIURI> uri;
   RefPtr<StyleSheet> chromeSheet;
 
   if (ds) {
     ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
   }
   if (chromeHandler) {
-    nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
-    nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
-    if (elt && content) {
-      nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
+    nsCOMPtr<Element> elt(do_QueryInterface(chromeHandler));
+    if (elt) {
+      nsCOMPtr<nsIURI> baseURI = elt->GetBaseURI();
 
       nsAutoString sheets;
       elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
       if (!sheets.IsEmpty() && baseURI) {
         RefPtr<css::Loader> cssLoader =
           new css::Loader(backendType, aDocument->GetDocGroup());
 
         char *str = ToNewCString(sheets);
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -378,21 +378,20 @@ inDOMView::GetCellText(int32_t row, nsIT
     uint16_t nodeType = domNode->NodeType();
     nsAutoString temp;
     temp.AppendInt(int32_t(nodeType));
     _retval = temp;
   } else if (colID.EqualsLiteral("colNodeValue"))
     domNode->GetNodeValue(_retval);
   else {
     if (StringBeginsWith(colID, NS_LITERAL_STRING("col@"))) {
-      nsCOMPtr<nsIDOMElement> el = do_QueryInterface(node->node);
-      if (el) {
+      if (domNode->IsElement()) {
         nsAutoString attr;
         colID.Right(attr, colID.Length()-4); // have to use this because Substring is crashing on me!
-        el->GetAttribute(attr, _retval);
+        domNode->AsElement()->GetAttribute(attr, _retval);
       }
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/xul/tree/nsTreeContentView.cpp
+++ b/layout/xul/tree/nsTreeContentView.cpp
@@ -8,16 +8,17 @@
 #include "nsGkAtoms.h"
 #include "nsIBoxObject.h"
 #include "nsTreeUtils.h"
 #include "nsTreeContentView.h"
 #include "ChildIterator.h"
 #include "nsError.h"
 #include "nsIXULSortService.h"
 #include "nsTreeBodyFrame.h"
+#include "mozilla/ErrorResult.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TreeContentViewBinding.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIDocument.h"
 
 using namespace mozilla;
 
 // A content model view implementation for the tree.
@@ -242,20 +243,22 @@ nsTreeContentView::GetCellProperties(int
   GetCellProperties(aRow, *col, aProps, rv);
   return rv.StealNSResult();
 }
 
 void
 nsTreeContentView::GetColumnProperties(nsTreeColumn& aColumn,
                                        nsAString& aProperties)
 {
-  nsCOMPtr<nsIDOMElement> element;
-  aColumn.GetElement(getter_AddRefs(element));
+  IgnoredErrorResult rv;
+  RefPtr<Element> element = aColumn.GetElement(rv);
 
-  element->GetAttribute(NS_LITERAL_STRING("properties"), aProperties);
+  if (element) {
+    element->GetAttribute(NS_LITERAL_STRING("properties"), aProperties);
+  }
 }
 
 NS_IMETHODIMP
 nsTreeContentView::GetColumnProperties(nsITreeColumn* aCol, nsAString& aProps)
 {
   RefPtr<nsTreeColumn> col = nsTreeColumn::From(aCol);
   NS_ENSURE_ARG(col);
 
--- a/security/manager/ssl/nsKeygenHandler.cpp
+++ b/security/manager/ssl/nsKeygenHandler.cpp
@@ -6,16 +6,37 @@
 
 #include "nsKeygenHandler.h"
 
 #include "cryptohi.h"
 #include "keyhi.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Base64.h"
 #include "mozilla/Casting.h"
+
+/* Disable the "base class should be explicitly initialized in the
+   copy constructor" warning that some bindings structs trigger while
+   including Element.h.  Looks like it's an inherent part of -Wextra,
+   so we can't just disable it in a targeted way in moz.build. */
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wextra"
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wextra"
+#endif // __clang__ || __GNUC__
+
+#include "mozilla/dom/Element.h"
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#elif defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif // __clang__ || __GNUC__
+
 #include "nsDependentString.h"
 #include "nsIContent.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIGenKeypairInfoDlg.h"
 #include "nsIServiceManager.h"
 #include "nsITokenDialogs.h"
 #include "nsKeygenHandlerContent.h"
 #include "nsKeygenThread.h"
@@ -25,16 +46,18 @@
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsXULAppAPI.h"
 #include "nspr.h"
 #include "secasn1.h"
 #include "secder.h"
 #include "secdert.h"
 
+using mozilla::dom::Element;
+
 //These defines are taken from the PKCS#11 spec
 #define CKM_RSA_PKCS_KEY_PAIR_GEN     0x00000000
 #define CKM_DH_PKCS_KEY_PAIR_GEN      0x00000020
 
 DERTemplate SECAlgorithmIDTemplate[] = {
     { DER_SEQUENCE,
           0, nullptr, sizeof(SECAlgorithmID) },
     { DER_OBJECT_ID,
@@ -672,34 +695,35 @@ loser:
 
 // static
 void
 nsKeygenFormProcessor::ExtractParams(nsIDOMHTMLElement* aElement,
                                      nsAString& challengeValue,
                                      nsAString& keyTypeValue,
                                      nsAString& keyParamsValue)
 {
-    aElement->GetAttribute(NS_LITERAL_STRING("keytype"), keyTypeValue);
+    nsCOMPtr<Element> element = do_QueryInterface(aElement);
+    element->GetAttribute(NS_LITERAL_STRING("keytype"), keyTypeValue);
     if (keyTypeValue.IsEmpty()) {
         // If this field is not present, we default to rsa.
         keyTypeValue.AssignLiteral("rsa");
     }
 
-    aElement->GetAttribute(NS_LITERAL_STRING("pqg"),
-                           keyParamsValue);
+    element->GetAttribute(NS_LITERAL_STRING("pqg"),
+                          keyParamsValue);
     /* XXX We can still support the pqg attribute in the keygen
      * tag for backward compatibility while introducing a more
      * general attribute named keyparams.
      */
     if (keyParamsValue.IsEmpty()) {
-        aElement->GetAttribute(NS_LITERAL_STRING("keyparams"),
-                               keyParamsValue);
+        element->GetAttribute(NS_LITERAL_STRING("keyparams"),
+                              keyParamsValue);
     }
 
-    aElement->GetAttribute(NS_LITERAL_STRING("challenge"), challengeValue);
+    element->GetAttribute(NS_LITERAL_STRING("challenge"), challengeValue);
 }
 
 nsresult
 nsKeygenFormProcessor::ProcessValue(nsIDOMHTMLElement* aElement,
                                     const nsAString& aName,
                                     nsAString& aValue)
 {
     nsAutoString challengeValue;
--- a/widget/cocoa/nsMenuBarX.mm
+++ b/widget/cocoa/nsMenuBarX.mm
@@ -592,55 +592,47 @@ NSMenuItem* nsMenuBarX::CreateNativeAppM
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   nsCOMPtr<nsIDocument> doc = inMenu->Content()->GetUncomposedDoc();
   if (!doc) {
     return nil;
   }
 
-  nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc));
-  if (!domdoc) {
+  RefPtr<mozilla::dom::Element> menuItem =
+    doc->GetElementById(nodeID);
+  if (!menuItem) {
     return nil;
   }
 
   // Get information from the gecko menu item
   nsAutoString label;
   nsAutoString modifiers;
   nsAutoString key;
-  nsCOMPtr<nsIDOMElement> menuItem;
-  domdoc->GetElementById(nodeID, getter_AddRefs(menuItem));
-  if (menuItem) {
-    menuItem->GetAttribute(NS_LITERAL_STRING("label"), label);
-    menuItem->GetAttribute(NS_LITERAL_STRING("modifiers"), modifiers);
-    menuItem->GetAttribute(NS_LITERAL_STRING("key"), key);
-  }
-  else {
-    return nil;
-  }
+  menuItem->GetAttribute(NS_LITERAL_STRING("label"), label);
+  menuItem->GetAttribute(NS_LITERAL_STRING("modifiers"), modifiers);
+  menuItem->GetAttribute(NS_LITERAL_STRING("key"), key);
 
   // Get more information about the key equivalent. Start by
   // finding the key node we need.
   NSString* keyEquiv = nil;
   unsigned int macKeyModifiers = 0;
   if (!key.IsEmpty()) {
-    nsCOMPtr<nsIDOMElement> keyElement;
-    domdoc->GetElementById(key, getter_AddRefs(keyElement));
+    RefPtr<Element> keyElement = doc->GetElementById(key);
     if (keyElement) {
-      nsCOMPtr<Element> keyContent (do_QueryInterface(keyElement));
       // first grab the key equivalent character
       nsAutoString keyChar(NS_LITERAL_STRING(" "));
-      keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyChar);
+      keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyChar);
       if (!keyChar.EqualsLiteral(" ")) {
         keyEquiv = [[NSString stringWithCharacters:reinterpret_cast<const unichar*>(keyChar.get())
                                             length:keyChar.Length()] lowercaseString];
       }
       // now grab the key equivalent modifiers
       nsAutoString modifiersStr;
-      keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
+      keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
       uint8_t geckoModifiers = nsMenuUtilsX::GeckoModifiersForNodeAttribute(modifiersStr);
       macKeyModifiers = nsMenuUtilsX::MacModifiersForGeckoModifiers(geckoModifiers);
     }
   }
   // get the label into NSString-form
   NSString* labelString = [NSString stringWithCharacters:reinterpret_cast<const unichar*>(label.get())
                                                   length:label.Length()];
 
--- a/xpfe/appshell/nsAppShellWindowEnumerator.cpp
+++ b/xpfe/appshell/nsAppShellWindowEnumerator.cpp
@@ -10,19 +10,22 @@
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMWindow.h"
 #include "nsIFactory.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIXULWindow.h"
+#include "mozilla/dom/Element.h"
 
 #include "nsWindowMediator.h"
 
+using mozilla::dom::Element;
+
 //
 // static helper functions
 //
 
 static nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocShell(nsIDocShell *aShell);
 static void GetAttribute(nsIXULWindow *inWindow, const nsAString &inAttribute,
                          nsAString &outValue);
 static void GetWindowType(nsIXULWindow* inWindow, nsString &outType);
@@ -49,17 +52,17 @@ nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocSh
 // generic "retrieve the value of a XUL attribute" function
 void GetAttribute(nsIXULWindow *inWindow, const nsAString &inAttribute,
                   nsAString &outValue)
 {
   nsCOMPtr<nsIDocShell> shell;
   if (inWindow && NS_SUCCEEDED(inWindow->GetDocShell(getter_AddRefs(shell)))) {
     nsCOMPtr<nsIDOMNode> node(GetDOMNodeFromDocShell(shell));
     if (node) {
-      nsCOMPtr<nsIDOMElement> webshellElement(do_QueryInterface(node));
+      nsCOMPtr<Element> webshellElement(do_QueryInterface(node));
       if (webshellElement)
         webshellElement->GetAttribute(inAttribute, outValue);
     }
   }
 }
 
 // retrieve the window type, stored as the value of a particular
 // attribute in its XUL window tag