Bug 1481882 - Load customElements.js in chrome XHTML documents;r=mossop
authorBrian Grinstead <bgrinstead@mozilla.com>
Thu, 16 Aug 2018 16:26:16 +0000
changeset 487013 5a85654da581748b68bdf88aebcebf8bf4a47117
parent 487012 3567e433384608b2df9c8b0124afa595edd2c3dc
child 487014 74feab038c3375df282b291682e0b1244c202f00
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1481882
milestone63.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 1481882 - Load customElements.js in chrome XHTML documents;r=mossop This provides support for using XUL elements in chrome XHTML documents, including the experimental xhtml browser window (browser.xhtml). Differential Revision: https://phabricator.services.mozilla.com/D3432
toolkit/components/processsingleton/MainProcessSingleton.js
toolkit/content/tests/chrome/chrome.ini
toolkit/content/tests/chrome/file_empty.xhtml
toolkit/content/tests/chrome/test_custom_element_base.xul
--- a/toolkit/components/processsingleton/MainProcessSingleton.js
+++ b/toolkit/components/processsingleton/MainProcessSingleton.js
@@ -68,23 +68,25 @@ MainProcessSingleton.prototype = {
       Services.mm.loadFrameScript("chrome://global/content/browser-content.js", true, true);
       Services.ppmm.loadProcessScript("chrome://global/content/process-content.js", true, true);
       Services.mm.addMessageListener("Search:AddEngine", this.addSearchEngine);
       Services.ppmm.loadProcessScript("resource:///modules/ContentObservers.js", true);
       break;
     }
 
     case "document-element-inserted":
-      // Set up Custom Elements for XUL windows before anything else happens
-      // in the document. Anything loaded here should be considered part of
-      // core XUL functionality. Any window-specific elements can be registered
-      // via <script> tags at the top of individual documents.
+      // Set up Custom Elements for XUL and XHTML documents before anything else
+      // happens. Anything loaded here should be considered part of core XUL functionality.
+      // Any window-specific elements can be registered via <script> tags at the
+      // top of individual documents.
       const doc = subject;
-      if (doc.nodePrincipal.isSystemPrincipal &&
-          doc.contentType == "application/vnd.mozilla.xul+xml") {
+      if (doc.nodePrincipal.isSystemPrincipal && (
+            doc.contentType == "application/vnd.mozilla.xul+xml" ||
+            doc.contentType == "application/xhtml+xml"
+        )) {
         Services.scriptloader.loadSubScript(
           "chrome://global/content/customElements.js", doc.ownerGlobal);
       }
       break;
 
     case "xpcom-shutdown":
       Services.mm.removeMessageListener("Search:AddEngine", this.addSearchEngine);
       Services.obs.removeObserver(this, "document-element-inserted");
--- a/toolkit/content/tests/chrome/chrome.ini
+++ b/toolkit/content/tests/chrome/chrome.ini
@@ -9,16 +9,17 @@ support-files =
   bug331215_window.xul
   bug360437_window.xul
   bug366992_window.xul
   bug409624_window.xul
   bug429723_window.xul
   bug624329_window.xul
   dialog_dialogfocus.xul
   dialog_dialogfocus2.xul
+  file_empty.xhtml
   file_about_networking_wsh.py
   file_autocomplete_with_composition.js
   file_editor_with_autocomplete.js
   findbar_entireword_window.xul
   findbar_events_window.xul
   findbar_window.xul
   frame_popup_anchor.xul
   frame_popupremoving_frame.xul
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/chrome/file_empty.xhtml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns='http://www.w3.org/1999/xhtml'>
+</html>
\ No newline at end of file
--- a/toolkit/content/tests/chrome/test_custom_element_base.xul
+++ b/toolkit/content/tests/chrome/test_custom_element_base.xul
@@ -14,20 +14,29 @@
 
   <simpleelement id="simple"/>
 
   <!-- test code goes here -->
   <script type="application/javascript"><![CDATA[
 
   SimpleTest.waitForExplicitFinish();
 
-  function runTests() {
+  async function runTests() {
     ok(MozXULElement, "MozXULElement defined on the window");
     testParseXULToFragment();
     testCustomInterface();
+
+    let htmlWin = await new Promise(resolve => {
+      let htmlIframe = document.createElement("iframe");
+      htmlIframe.src = "file_empty.xhtml";
+      htmlIframe.onload = () => resolve(htmlIframe.contentWindow);
+      document.documentElement.appendChild(htmlIframe);
+    });
+
+    ok(htmlWin.MozXULElement, "MozXULElement defined on a chrome HTML window");
     SimpleTest.finish();
   }
 
   function testParseXULToFragment() {
     ok(MozXULElement.parseXULToFragment, "parseXULToFragment helper exists");
 
     let frag = MozXULElement.parseXULToFragment(`<deck id='foo' />`);
     ok(frag instanceof DocumentFragment);