Bug 1443923 - part7: Use InspectorUtils.isCustomElementName in inspector actor;r=bgrins draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 20 Jul 2018 11:05:31 +0200
changeset 821451 6b81e2fd3dbe4f4bcb52071cd3c7a2740c1919c2
parent 821424 661eac5faa54a659404b293154b5613a21f5acbf
child 821452 7c7ec0aebcfdf5e1c7a13837ea9100c8b680d1d5
push id117098
push userjdescottes@mozilla.com
push dateMon, 23 Jul 2018 10:19:47 +0000
reviewersbgrins
bugs1443923
milestone63.0a1
Bug 1443923 - part7: Use InspectorUtils.isCustomElementName in inspector actor;r=bgrins MozReview-Commit-ID: 9aKFGcoX8TS
devtools/server/actors/inspector/custom-element-watcher.js
--- a/devtools/server/actors/inspector/custom-element-watcher.js
+++ b/devtools/server/actors/inspector/custom-element-watcher.js
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const InspectorUtils = require("InspectorUtils");
 const EventEmitter = require("devtools/shared/event-emitter");
 
 /**
  * The CustomElementWatcher can be used to be notified if a custom element definition
  * is created for a node.
  *
  * When a custom element is defined for a monitored name, an "element-defined" event is
  * fired with the Set of impacted node actors as argument.
@@ -72,22 +73,23 @@ class CustomElementWatcher extends Event
     const name = nodeActor.rawNode.localName;
     if (registryMap && registryMap.has(name)) {
       registryMap.get(name).delete(nodeActor);
     }
   }
 
   _shouldWatchDefinition(nodeActor) {
     const doc = nodeActor.rawNode.ownerDocument;
-    if (!doc) {
+    if (!doc || !doc.documentElement) {
       return false;
     }
 
+    const namespaceURI = doc.documentElement.namespaceURI;
     const name = nodeActor.rawNode.localName;
-    const isValidName = name && name.includes("-");
+    const isValidName = InspectorUtils.isCustomElementName(name, namespaceURI);
 
     const customElements = doc.defaultView.customElements;
     return isValidName && !customElements.get(name);
   }
 
   _onCustomElementDefined(name, registry) {
     if (this.destroyed) {
       return;