Bug 1443923 - part4: Expose isCustomElementName to DevTools via InspectorUtils;r=emilio draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 19 Jul 2018 13:59:05 +0200
changeset 822570 4441720ced7a9a9579e699d4722157d7e5a4bc03
parent 822569 89f1267834633b0ef9da875cf16d8597b7ed6f4f
child 822571 a1ea7c9a777550a731466c8eb203f11b16dda981
push id117402
push userjdescottes@mozilla.com
push dateWed, 25 Jul 2018 13:32:04 +0000
reviewersemilio
bugs1443923
milestone63.0a1
Bug 1443923 - part4: Expose isCustomElementName to DevTools via InspectorUtils;r=emilio MozReview-Commit-ID: GaHP1gOCwoB
dom/chrome-webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.cpp
layout/inspector/InspectorUtils.h
--- a/dom/chrome-webidl/InspectorUtils.webidl
+++ b/dom/chrome-webidl/InspectorUtils.webidl
@@ -72,16 +72,18 @@ namespace InspectorUtils {
   void addPseudoClassLock(Element element,
                           DOMString pseudoClass,
                           optional boolean enabled = true);
   void removePseudoClassLock(Element element, DOMString pseudoClass);
   boolean hasPseudoClassLock(Element element, DOMString pseudoClass);
   void clearPseudoClassLocks(Element element);
   [Throws] void parseStyleSheet(CSSStyleSheet sheet, DOMString input);
   void scrollElementIntoView(Element element);
+  boolean isCustomElementName([TreatNullAs=EmptyString] DOMString name,
+                              DOMString? namespaceURI);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
   boolean includeShorthands = true;
   boolean includeExperimentals = false;
 };
 
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -735,10 +735,31 @@ InspectorUtils::ScrollElementIntoView(Gl
   }
 
   presShell->ScrollContentIntoView(&aElement,
                                    nsIPresShell::ScrollAxis(),
                                    nsIPresShell::ScrollAxis(),
                                    nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
 }
 
+
+bool
+InspectorUtils::IsCustomElementName(GlobalObject&,
+                                    const nsAString& aName,
+                                    const nsAString& aNamespaceURI)
+{
+  if (aName.IsEmpty()) {
+    return false;
+  }
+
+  int32_t namespaceID;
+  nsContentUtils::NameSpaceManager()->RegisterNameSpace(
+    aNamespaceURI,
+    namespaceID);
+
+  RefPtr<nsAtom> nameElt = NS_Atomize(aName);
+  return nsContentUtils::IsCustomElementName(
+    nameElt,
+    namespaceID);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -269,16 +269,23 @@ public:
                               ErrorResult& aRv);
 
   /**
    * Scroll an element completely into view, if possible.
    * This is similar to ensureElementIsVisible but for all ancestors.
    */
   static void ScrollElementIntoView(GlobalObject& aGlobal, Element& aElement);
 
+  /**
+   * Check if the provided name can be custom element name.
+   */
+  static bool IsCustomElementName(GlobalObject&,
+                                  const nsAString& aName,
+                                  const nsAString& aNamespaceURI);
+
 private:
   static already_AddRefed<ComputedStyle>
     GetCleanComputedStyleForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla