WIP

GetAnonymousElementByAttributeNS

とりあえず、こんな感じに書けるかな……

diff -r a0b731e5e5ad content/base/src/nsDocument.cpp
--- a/content/base/src/nsDocument.cpp	Thu Apr 16 18:40:46 2009 -0700
+++ b/content/base/src/nsDocument.cpp	Fri Apr 17 13:02:50 2009 +0900
@@ -4598,77 +4598,92 @@ nsDocument::GetBindingParent(nsIDOMNode*
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content->GetBindingParent()));
   NS_IF_ADDREF(*aResult = elt);
   return NS_OK;
 }
 
 static nsresult
-GetElementByAttribute(nsIContent* aContent, nsIAtom* aAttrName,
-                      const nsAString& aAttrValue, PRBool aUniversalMatch,
-                      nsIDOMElement** aResult)
-{
-  if (aUniversalMatch ? aContent->HasAttr(kNameSpaceID_None, aAttrName) :
-                        aContent->AttrValueIs(kNameSpaceID_None, aAttrName,
+GetElementByAttributeNS(nsIContent* aContent, PRInt32 aNamespaceID,
+                        nsIAtom* aAttrName, const nsAString& aAttrValue,
+                        PRBool aUniversalMatch, nsIDOMElement** aResult)
+{
+  if (aUniversalMatch ? aContent->HasAttr(aNamespaceID, aAttrName) :
+                        aContent->AttrValueIs(aNamespaceID, aAttrName,
                                               aAttrValue, eCaseMatters)) {
     return CallQueryInterface(aContent, aResult);
   }
 
   PRUint32 childCount = aContent->GetChildCount();
 
   for (PRUint32 i = 0; i < childCount; ++i) {
     nsIContent *current = aContent->GetChildAt(i);
 
-    GetElementByAttribute(current, aAttrName, aAttrValue, aUniversalMatch,
-                          aResult);
+    GetElementByAttributeNS(current, aNamespaceID, aAttrName, aAttrValue,
+                            aUniversalMatch, aResult);
 
     if (*aResult)
       return NS_OK;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::GetAnonymousElementByAttribute(nsIDOMElement* aElement,
                                            const nsAString& aAttrName,
                                            const nsAString& aAttrValue,
                                            nsIDOMElement** aResult)
 {
+  return GetAnonymousElementByAttributeNS(aElement, NS_LITERAL_STRING(""),
+                                          aAttrName, aAttrValue, aResult);
+}
+
+NS_IMETHODIMP
+nsDocument::GetAnonymousElementByAttributeNS(nsIDOMElement* aElement,
+                                             const nsAString& aNamespaceURI,
+                                             const nsAString& aAttrName,
+                                             const nsAString& aAttrValue,
+                                             nsIDOMElement** aResult)
+{
   *aResult = nsnull;
 
   nsCOMPtr<nsIDOMNodeList> nodeList;
   GetAnonymousNodes(aElement, getter_AddRefs(nodeList));
 
   if (!nodeList)
     return NS_OK;
 
+  PRInt32 namespaceID;
+  nsresult rv = 
+      nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
+                                                            namespaceID);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   nsCOMPtr<nsIAtom> attribute = do_GetAtom(aAttrName);
 
   PRUint32 length;
   nodeList->GetLength(&length);
 
   PRBool universalMatch = aAttrValue.EqualsLiteral("*");
 
   for (PRUint32 i = 0; i < length; ++i) {
     nsCOMPtr<nsIDOMNode> current;
     nodeList->Item(i, getter_AddRefs(current));
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(current));
 
-    GetElementByAttribute(content, attribute, aAttrValue, universalMatch,
-                          aResult);
+    GetElementByAttributeNS(content, namespaceID, attribute, aAttrValue,
+                            universalMatch, aResult);
     if (*aResult)
       return NS_OK;
   }
-
-  return NS_OK;
-}
-
+  return NS_OK;
+}
 
 NS_IMETHODIMP
 nsDocument::GetAnonymousNodes(nsIDOMElement* aElement,
                               nsIDOMNodeList** aResult)
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
diff -r a0b731e5e5ad dom/interfaces/xbl/nsIDOMDocumentXBL.idl
--- a/dom/interfaces/xbl/nsIDOMDocumentXBL.idl	Thu Apr 16 18:40:46 2009 -0700
+++ b/dom/interfaces/xbl/nsIDOMDocumentXBL.idl	Fri Apr 17 13:02:50 2009 +0900
@@ -41,16 +41,20 @@
 
 [scriptable, uuid(1a38762b-4da5-4f61-80fb-9317e198cb92)]
 interface nsIDOMDocumentXBL : nsISupports
 {
   nsIDOMNodeList        getAnonymousNodes(in nsIDOMElement elt);
   nsIDOMElement         getAnonymousElementByAttribute(in nsIDOMElement elt,
                                                        in DOMString attrName,
                                                        in DOMString attrValue);
+  nsIDOMElement         getAnonymousElementByAttributeNS(in nsIDOMElement elt,
+                                                         in DOMString namespaceURI,
+                                                         in DOMString attrName,
+                                                         in DOMString attrValue);
 
   void                  addBinding(in nsIDOMElement elt,
                                    in DOMString bindingURL);
   void                  removeBinding(in nsIDOMElement elt,
                                       in DOMString bindingURL);
 
   nsIDOMElement         getBindingParent(in nsIDOMNode node);
   void                  loadBindingDocument(in DOMString documentURL);