1 // By Kris Maglione. Public Domain.
2 // Please feel free to copy and use at will.
8 "chrome://mozapps/content/extensions/extensions.xul"
11 let { interfaces: Ci, utils: Cu } = Components;
13 Cu.import("resource://gre/modules/Services.jsm");
14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
16 const TOPIC = "chrome-document-global-created";
18 function observe(window, topic, url) {
20 checkDocument(window.document);
26 Services.obs[id ? "addObserver" : "removeObserver"](observe, TOPIC, false);
27 for (let doc in chromeDocuments())
28 checkDocument(doc, !id);
30 function cleanup() { init(null); }
32 function checkPopup(event) {
33 let doc = event.originalTarget.ownerDocument;
34 let binding = doc.getBindingParent(event.originalTarget);
35 if (binding && binding.addon && binding.addon.guid == ADDON_ID && !binding.addon.compatible) {
36 let elem = doc.getAnonymousElementByAttribute(binding, "anonid", "stillworks");
37 if (elem && elem.nextSibling) {
38 elem.nextSibling.disabled = true;
39 elem.nextSibling.setAttribute("tooltiptext", "Developer has opted out of incompatibility reports\n"+
40 "Development versions are available with updated support");
45 function checkDocument(doc, disable, force) {
46 if (["interactive", "complete"].indexOf(doc.readyState) >= 0 || force && doc.readyState === "uninitialized") {
47 if (OVERLAY_URLS.indexOf(doc.documentURI) >= 0)
48 doc[disable ? "removeEventListener" : "addEventListener"]("popupshowing", checkPopup, false);
51 doc.addEventListener("DOMContentLoaded", function listener() {
52 doc.removeEventListener("DOMContentLoaded", listener, false);
53 checkDocument(doc, disable, true);
58 function chromeDocuments() {
59 let windows = Services.wm.getXULWindowEnumerator(null);
60 while (windows.hasMoreElements()) {
61 let window = windows.getNext().QueryInterface(Ci.nsIXULWindow);
62 for each (let type in ["typeChrome", "typeContent"]) {
63 let docShells = window.docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem[type],
64 Ci.nsIDocShell.ENUMERATE_FORWARDS);
65 while (docShells.hasMoreElements())
67 yield docShells.getNext().QueryInterface(Ci.nsIDocShell).contentViewer.DOMDocument;
74 var EXPORTED_SYMBOLS = ["cleanup", "init"];
76 // vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: