diff --git a/browser/extensions/formautofill/bootstrap.js b/browser/extensions/formautofill/bootstrap.js index c8380de96118..8a6ff02d0c32 100644 --- a/browser/extensions/formautofill/bootstrap.js +++ b/browser/extensions/formautofill/bootstrap.js @@ -7,6 +7,8 @@ /* exported startup, shutdown, install, uninstall */ const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components; +const STYLESHEET_URI = "chrome://formautofill/content/formautofill.css"; +const CACHED_STYLESHEETS = []; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); @@ -14,6 +16,25 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent", "resource://formautofill/FormAutofillParent.jsm"); +function insertStyleSheet(domWindow, url) { + let doc = domWindow.document; + let styleSheetAttr = `href="${url}" type="text/css"`; + let styleSheet = doc.createProcessingInstruction("xml-stylesheet", styleSheetAttr); + + doc.insertBefore(styleSheet, doc.documentElement); + CACHED_STYLESHEETS.push(styleSheet); +} + +let windowListener = { + onOpenWindow(aWindow) { + let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); + + domWindow.addEventListener("load", function onWindowLoaded() { + insertStyleSheet(domWindow, STYLESHEET_URI); + }, {once: true}); + }, +}; + function startup() { // Besides this pref, we'll need dom.forms.autocomplete.experimental enabled // as well to make sure form autocomplete works correctly. @@ -22,10 +43,28 @@ function startup() { } let parent = new FormAutofillParent(); + let enumerator = Services.wm.getEnumerator("navigator:browser"); + // Load stylesheet to already opened windows + while (enumerator.hasMoreElements()) { + let win = enumerator.getNext(); + let domWindow = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); + + insertStyleSheet(domWindow, STYLESHEET_URI); + } + + Services.wm.addListener(windowListener); + parent.init(); Services.mm.loadFrameScript("chrome://formautofill/content/FormAutofillFrameScript.js", true); } -function shutdown() {} +function shutdown() { + Services.wm.removeListener(windowListener); + + while (CACHED_STYLESHEETS.length !== 0) { + CACHED_STYLESHEETS.pop().remove(); + } +} + function install() {} function uninstall() {} diff --git a/browser/extensions/formautofill/content/formautofill.css b/browser/extensions/formautofill/content/formautofill.css new file mode 100644 index 000000000000..7bc3e8113ad7 --- /dev/null +++ b/browser/extensions/formautofill/content/formautofill.css @@ -0,0 +1,7 @@ +/* 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/. */ + +.autocomplete-richlistitem[originaltype="autofill-profile"] { + -moz-binding: url("chrome://formautofill/content/formautofill.xml#autocomplete-profile-listitem"); +} diff --git a/browser/extensions/formautofill/content/formautofill.xml b/browser/extensions/formautofill/content/formautofill.xml new file mode 100644 index 000000000000..bcada5fa0f44 --- /dev/null +++ b/browser/extensions/formautofill/content/formautofill.xml @@ -0,0 +1,79 @@ + + + + + + + +
+
+ +
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +