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