From b6bdac4b1f6a8334ca80dae293e4debcafd26f8b Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 1 Feb 2011 15:20:55 -0500 Subject: [PATCH] Disable sending incompatibility reports via the ACR. --- common/bootstrap.js | 23 ++++++-- pentadactyl/content/disable-acr.jsm | 84 +++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 pentadactyl/content/disable-acr.jsm diff --git a/common/bootstrap.js b/common/bootstrap.js index f149183a..cbd001a6 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -14,9 +14,15 @@ const Ci = Components.interfaces; const Cu = Components.utils; const Cr = Components.results; -Cu.import("resource://gre/modules/AddonManager.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); +function module(uri) { + let obj = {}; + Cu.import(uri, obj); + return obj; +} + +const { AddonManager } = module("resource://gre/modules/AddonManager.jsm"); +const { XPCOMUtils } = module("resource://gre/modules/XPCOMUtils.jsm"); +const { Services } = module("resource://gre/modules/Services.jsm"); const resourceProto = Services.io.getProtocolHandler("resource") .QueryInterface(Ci.nsIResProtocolHandler); @@ -95,6 +101,7 @@ function startup(data, reason) { else getURI = function getURI(path) Services.io.newURI("jar:" + Services.io.newFileURI(basePath).spec + "!/" + path, null, null); + try { init(); } @@ -163,6 +170,11 @@ function init() { } } + try { + module("resource://dactyl-local-content/disable-acr.jsm").init(); + } + catch (e) {} + if (JSMLoader && JSMLoader.bump != 3) // Temporary hack Services.scriptloader.loadSubScript("resource://dactyl" + suffix + "/bootstrap.jsm", Cu.import("resource://dactyl/bootstrap.jsm", global)); @@ -186,6 +198,11 @@ function init() { function shutdown(data, reason) { dump("dactyl: bootstrap: shutdown " + reasonToString(reason) + "\n"); if (reason != APP_SHUTDOWN) { + try { + module("resource://dactyl-local-content/disable-acr.jsm").cleanup(); + } + catch (e) {} + if ([ADDON_UPGRADE, ADDON_DOWNGRADE, ADDON_UNINSTALL].indexOf(reason) >= 0) Services.obs.notifyObservers(null, "dactyl-purge", null); diff --git a/pentadactyl/content/disable-acr.jsm b/pentadactyl/content/disable-acr.jsm new file mode 100644 index 00000000..1dccce3f --- /dev/null +++ b/pentadactyl/content/disable-acr.jsm @@ -0,0 +1,84 @@ +// By Kris Maglione. Public Domain. +// Please feel free to copy and use at will. + +const ADDON_ID = "pentadactyl@dactyl.googlecode.com"; + +const OVERLAY_URLS = [ + "about:addons", + "chrome://mozapps/content/extensions/extensions.xul" +]; + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; +const Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +function observe(subject, topic, data) { + if (topic in observers) + observers[topic](subject, data); +} +function init(disable) { + for (let observer in observers) + Services.obs[disable ? "removeObserver" : "addObserver"](observe, observer, false); + for (let doc in chromeDocuments) + checkDocument(doc, disable); +} +function cleanup() { init(true); } +var observers = { + "chrome-document-global-created": function (window, uri) { + checkDocument(window.document); + } +} + +function checkPopup(event) { + try { + let doc = event.originalTarget.ownerDocument; + let binding = doc.getBindingParent(event.originalTarget); + if (binding && binding.addon && binding.addon.guid == ADDON_ID && !binding.addon.compatible) { + let elem = doc.getAnonymousElementByAttribute(binding, "anonid", "stillworks"); + if (elem && elem.nextSibling) { + elem.nextSibling.disabled = true; + elem.nextSibling.setAttribute("tooltiptext", "Developer has opted out of incompatibility reports"); + } + } + } + catch (e) { + Cu.reportError(e); + } +} + +function checkDocument(doc, disable, force) { + if (["interactive", "complete"].indexOf(doc.readyState) >= 0 || force && doc.readyState === "uninitialized") { + if (OVERLAY_URLS.indexOf(doc.documentURI) >= 0) + doc[disable ? "removeEventListener" : "addEventListener"]("popupshowing", checkPopup, false); + } + else { + doc.addEventListener("DOMContentLoaded", function listener() { + try { + doc.removeEventListener("DOMContentLoaded", listener, false); + checkDocument(doc, disable, true); + } + catch (e) { + Cu.reportError(e); + } + }, false); + } +} + +function chromeDocuments() { + let windows = Services.ww.getXULWindowEnumerator(null); + while (windows.hasMoreElements()) { + let window = windows.getNext().QueryInterface(Ci.nsIXULWindow); + let docShells = window.docShell.getDocShellEnumerator(Ci.nsIDocShell.typeChrome, + Ci.nsIDocShell.ENUMERATE_FORWARDS); + while (docShells.hasMoreElements()) + yield docShells.getNext().containedDocShells.DOMDocument; + } +} + +var EXPORTED_SYMBOLS = ["cleanup", "init"]; + +// vim: set fdm=marker sw=4 ts=4 et: