From 254da12e1289aeb5170ed6e2effa10969d8f0640 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 23 Jul 2016 16:21:43 -0400 Subject: [PATCH] Hide unsigned add-on warning in Standalone There's no need for Zotero Standalone add-ons to be signed by Mozilla. Currently only hides when the Extensions pane is first loaded, so if the user switches to Appearance or Plugins and switches back, the warning reappears --- .../content/zotero/standalone/standalone.js | 50 +++++++++++++++++-- .../content/zotero/standalone/standalone.xul | 2 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index 0b1c6b5e6b..05eb51b455 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -106,18 +106,62 @@ const ZoteroStandalone = new function() { } /** - * Opens a URL in the basic viewer + * Opens a URL in the basic viewer, and optionally run a callback on load + * + * @param {String} uri + * @param {Function} [onLoad] - Function to run once URI is loaded; passed the loaded document */ - this.openInViewer = function(uri) { + this.openInViewer = function(uri, onLoad) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var win = wm.getMostRecentWindow("zotero:basicViewer"); if(win) { win.loadURI(uri); } else { - window.openDialog("chrome://zotero/content/standalone/basicViewer.xul", + win = window.openDialog("chrome://zotero/content/standalone/basicViewer.xul", "basicViewer", "chrome,resizable,centerscreen,menubar,scrollbars", uri); } + if (onLoad) { + let browser + let func = function () { + win.removeEventListener("load", func); + browser = win.document.documentElement.getElementsByTagName('browser')[0]; + browser.addEventListener("pageshow", innerFunc); + }; + let innerFunc = function () { + browser.removeEventListener("pageshow", innerFunc); + onLoad(browser.contentDocument); + }; + win.addEventListener("load", func); + + } + } + + this.updateAddonsPane = function (doc) { + // Hide unsigned add-on verification warnings + // + // This only works for the initial load of the window. If the user switches to Appearance + // or Plugins and then back to Extensions, the warnings will appear again. A better way to + // disable this might be discoverable by studying + // https://dxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/content/extensions.js + var addonList = doc.getElementById('addon-list'); + setTimeout(function () { + for (let i = 0; i < addonList.itemCount; i++) { + let richListItem = addonList.getItemAtIndex(i); + let container = doc.getAnonymousElementByAttribute( + richListItem, 'anonid', 'warning-container' + ); + if (container) { + let link = doc.getAnonymousElementByAttribute( + richListItem, 'anonid', 'warning-link' + ); + if (link && link.href.indexOf('unsigned-addons') != -1) { + richListItem.removeAttribute('notification'); + container.hidden = true; + } + } + } + }); } /** diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul index 15c7db22b9..7d17a281df 100644 --- a/chrome/content/zotero/standalone/standalone.xul +++ b/chrome/content/zotero/standalone/standalone.xul @@ -168,7 +168,7 @@ command="cmd_zotero_rtfScan"/> + oncommand="ZoteroStandalone.openInViewer('chrome://mozapps/content/extensions/extensions.xul', ZoteroStandalone.updateAddonsPane)"/>