]> git.donarmstrong.com Git - dactyl.git/blob - common/content/disable-acr.jsm
Import 1.0b7.1 supporting Firefox up to 8.*
[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 const TOPIC = "chrome-document-global-created";
18
19 function observe(window, topic, url) {
20     if (topic === TOPIC)
21         checkDocument(window.document);
22 }
23 function init(id) {
24     if (id)
25         ADDON_ID = id;
26
27     Services.obs[id ? "addObserver" : "removeObserver"](observe, TOPIC, false);
28     for (let doc in chromeDocuments())
29         checkDocument(doc, !id);
30 }
31 function cleanup() { init(null); }
32
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");
42         }
43     }
44 }
45
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);
50     }
51     else {
52         doc.addEventListener("DOMContentLoaded", function listener() {
53             doc.removeEventListener("DOMContentLoaded", listener, false);
54             checkDocument(doc, disable, true);
55         }, false);
56     }
57 }
58
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;
68         }
69     }
70 }
71
72 var EXPORTED_SYMBOLS = ["cleanup", "init"];
73
74 // vim: set fdm=marker sw=4 ts=4 et ft=javascript: