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