[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 200/483: Made compatible with Adblock Plus 1.3a (versions before that won't be supported). Also handling dependency on Adblock Plus "manually" now, adding or updating Adblock Plus as necessary should be a one-click affair now.
David Prévot
taffit at moszumanska.debian.org
Thu Jan 22 21:41:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.
commit ba2624bf5f158378936f6c68e9c6e12260ea3a1c
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed May 19 15:31:47 2010 +0200
Made compatible with Adblock Plus 1.3a (versions before that won't be supported). Also handling dependency on Adblock Plus "manually" now, adding or updating Adblock Plus as necessary should be a one-click affair now.
---
chrome.manifest | 10 +-
chrome/content/composer.js | 21 +-
chrome/content/overlay.js | 23 +-
chrome/content/overlayBasic.js | 95 -------
chrome/content/overlayBasic.xul | 32 ---
chrome/locale/en-US/global.properties | 7 +
components/Initializer.js | 67 +++++
install.rdf | 13 +-
modules/ABPIntegration.jsm | 479 ++++++++++++++++++++++++++++++++++
version | 2 +-
10 files changed, 572 insertions(+), 177 deletions(-)
diff --git a/chrome.manifest b/chrome.manifest
index 25860bd..95c34ad 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -1,13 +1,5 @@
-overlay chrome://adblockplus/content/overlayGeneral.xul chrome://elemhidehelper/content/overlay.xul
overlay chrome://adblockplus/content/ui/overlayGeneral.xul chrome://elemhidehelper/content/overlay.xul
-overlay chrome://browser/content/browser.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://navigator/content/navigator.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://messenger/content/mailWindowOverlay.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://songbird/content/xul/layoutWithBrowserOverlay.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://midbrowser/content/midbrowser.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://emusic/content/startup.xul chrome://elemhidehelper/content/overlayBasic.xul
-overlay chrome://webrunner/content/webrunner.xul chrome://elemhidehelper/content/overlayBasic.xul
content elemhidehelper jar:chrome/elemhidehelper.jar!/content/
skin elemhidehelper classic/1.0 jar:chrome/elemhidehelper.jar!/skin/
locale elemhidehelper {{LOCALE}} jar:chrome/elemhidehelper.jar!/locale/{{LOCALE}}/
-
+content elemhidehelper-modules modules/
diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index 7e4d4ca..c5cc484 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -22,6 +22,11 @@
*
* ***** END LICENSE BLOCK ***** */
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const Cu = Components.utils;
+
var domainData;
var nodeData;
var selectedNode = null;
@@ -101,7 +106,7 @@ function createQIProxy(obj, orig) {
obj.QueryInterface = function(iid) {
var impl = orig.QueryInterface(iid);
if (impl != orig)
- throw Components.results.NS_ERROR_NO_INTERFACE;
+ throw Cr.NS_ERROR_NO_INTERFACE;
return obj;
};
@@ -123,8 +128,7 @@ function createPropertyProxy(obj, orig, key) {
}
}
-var atomService = Components.classes["@mozilla.org/atom-service;1"]
- .getService(Components.interfaces.nsIAtomService);
+var atomService = Cc["@mozilla.org/atom-service;1"].getService(Ci.nsIAtomService);
var selectedAtom = atomService.getAtom("selected-false");
var anchorAtom = atomService.getAtom("anchor");
@@ -551,7 +555,7 @@ function updateNodeSelection() {
selection.getRangeAt(0, min, {});
var item = tree.view
- .QueryInterface(Components.interfaces.nsITreeContentView)
+ .QueryInterface(Ci.nsITreeContentView)
.getItemAtIndex(min.value);
if (!item || !item.nodeData)
return;
@@ -559,10 +563,11 @@ function updateNodeSelection() {
fillAttributes(item.nodeData);
}
-function addExpression() {
- var abp = Components.classes["@mozilla.org/adblockplus;1"]
- .createInstance().wrappedJSObject;
- abp.addPatterns([document.getElementById("expression").value], 1);
+function addExpression()
+{
+ let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI);
+ Cu.import(abpURL.spec);
+ AdblockPlus.addPatterns([document.getElementById("expression").value]);
togglePreview(false);
}
diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js
index 950ccdb..177405c 100644
--- a/chrome/content/overlay.js
+++ b/chrome/content/overlay.js
@@ -22,9 +22,9 @@
*
* ***** END LICENSE BLOCK ***** */
-// This will be called from overlayBasic - only if Adblock Plus is installed
-// and the version is correct
-function ehhInit2() {
+window.addEventListener("load", ehhInit, false);
+
+function ehhInit() {
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var branch = prefService.getBranch("extensions.adblockplus.");
@@ -35,23 +35,6 @@ function ehhInit2() {
document.getElementById("abp-toolbar-popup").addEventListener("popupshowing", ehhFillPopup, false);
window.addEventListener("blur", ehhHideTooltips, true);
ehhGetBrowser().addEventListener("select", ehhStop, false);
-
- // Make sure we configure the shortcut key even if the default pref isn't there.
- // TODO: Remove once ABP 1.1 is minimal supported version.
- if ("abpConfigureKey" in window) {
- var defaultBranch = prefService.getDefaultBranch("extensions.adblockplus.");
- try {
- // Seems to be the only way to test whether the pref really exists in the default branch
- defaultBranch.getCharPref("ehh-selectelement_key");
- }
- catch(e) {
- var key = "Accel Shift H";
- try {
- key = branch.getCharPref("ehh-selectelement_key");
- } catch(e2) {}
- abpConfigureKey("ehh-selectelement", key);
- }
- }
}
function ehhGetBrowser() {
diff --git a/chrome/content/overlayBasic.js b/chrome/content/overlayBasic.js
deleted file mode 100644
index 75776fb..0000000
--- a/chrome/content/overlayBasic.js
+++ /dev/null
@@ -1,95 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Adblock Plus Element Hiding Helper.
- *
- * The Initial Developer of the Original Code is
- * Wladimir Palant.
- * Portions created by the Initial Developer are Copyright (C) 2006-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** */
-
-window.addEventListener("load", ehhInit, false);
-
-function ehhInit() {
- var prefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService);
- var branch = prefService.getBranch("extensions.adblockplus.");
-
- // Check whether ABP is installed and has at least the required version
- var requiredVersion = "0.7.5";
- var installedVersion = "0";
- try {
- var abp = Components.classes["@mozilla.org/adblockplus;1"]
- .createInstance().wrappedJSObject;
- installedVersion = abp.getInstalledVersion();
- } catch(e) {}
-
- var parts1 = requiredVersion.split(".");
- var parts2 = installedVersion.split(".");
- var mustUpdate = false;
- for (var i = 0; i < parts1.length; i++) {
- if (parts2.length <= i || parseInt(parts1[i]) > parseInt(parts2[i])) {
- mustUpdate = true;
- break;
- }
- if (parseInt(parts1[i]) < parseInt(parts2[i]))
- break;
- }
-
- // Show warning about required ABP update if necessary
- if (mustUpdate) {
- var noWarning = {value: false};
- try {
- noWarning.value = branch.getBoolPref("ehh.norequirementswarning");
- } catch(e) {}
-
- if (!noWarning.value) {
- // Make sure we don't show the warning twice
- var hiddenWnd = Components.classes["@mozilla.org/appshell/appShellService;1"]
- .getService(Components.interfaces.nsIAppShellService)
- .hiddenDOMWindow;
- if ("ehhNoRequirementsWarning" in hiddenWnd)
- noWarning.value = true;
- else
- hiddenWnd.ehhNoRequirementsWarning = true;
- }
-
- if (!noWarning.value) {
- setTimeout(function() {
- var stringService = Components.classes["@mozilla.org/intl/stringbundle;1"]
- .getService(Components.interfaces.nsIStringBundleService);
- var strings = stringService.createBundle("chrome://elemhidehelper/locale/global.properties");
- var promptService = Components.classes['@mozilla.org/embedcomp/prompt-service;1']
- .getService(Components.interfaces.nsIPromptService);
- promptService.alertCheck(window,
- strings.GetStringFromName("noabp_warning_title"),
- strings.formatStringFromName("noabp_warning_text", [requiredVersion], 1),
- strings.GetStringFromName("noabp_warning_disable"),
- noWarning);
-
- if (noWarning.value) {
- try {
- branch.setBoolPref("ehh.norequirementswarning", true);
- } catch(e) {}
- }
- }, 0);
- }
- return;
- }
-
- ehhInit2();
-}
\ No newline at end of file
diff --git a/chrome/content/overlayBasic.xul b/chrome/content/overlayBasic.xul
deleted file mode 100644
index 032555d..0000000
--- a/chrome/content/overlayBasic.xul
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://elemhidehelper/skin/overlay.css" type="text/css"?>
-
-<!-- ***** BEGIN LICENSE BLOCK *****
- - Version: MPL 1.1
- -
- - The contents of this file are subject to the Mozilla Public License Version
- - 1.1 (the "License"); you may not use this file except in compliance with
- - the License. You may obtain a copy of the License at
- - http://www.mozilla.org/MPL/
- -
- - Software distributed under the License is distributed on an "AS IS" basis,
- - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- - for the specific language governing rights and limitations under the
- - License.
- -
- - The Original Code is Adblock Plus Element Hiding Helper.
- -
- - The Initial Developer of the Original Code is
- - Wladimir Palant.
- - Portions created by the Initial Developer are Copyright (C) 2006-2010
- - the Initial Developer. All Rights Reserved.
- -
- - Contributor(s):
- -
- - ***** END LICENSE BLOCK ***** -->
-
-<!DOCTYPE overlay SYSTEM "chrome://elemhidehelper/locale/overlay.dtd">
-
-<overlay id="ehh-overlayBasic" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript" src="overlayBasic.js"/>
-</overlay>
diff --git a/chrome/locale/en-US/global.properties b/chrome/locale/en-US/global.properties
index a75258a..fbd667f 100644
--- a/chrome/locale/en-US/global.properties
+++ b/chrome/locale/en-US/global.properties
@@ -18,3 +18,10 @@ command.showMenu.label=show/hide help
noabp_warning_title=Element Hiding Helper
noabp_warning_text=This release of the Element Hiding Helper extension requires Adblock Plus %S or higher. The Element Hiding Helper will be disabled until Adblock Plus is either installed or updated.
noabp_warning_disable=Do not show this warning again.
+
+abpInstallationRequired=Element Hiding Helper requires Adblock Plus to work propertly, you didn't install it yet. Install now?
+abpEnableRequired=Element Hiding Helper requires Adblock Plus to work propertly, you disabled it however. Enable now?
+abpUpdateRequired=Element Hiding Helper requires a newer Adblock Plus version to work propertly. Install Adblock Plus update now?
+selfUpdateRequired=Element Hiding Helper cannot work with the installed Adblock Plus version, a newer Element Hiding Helper version might help. Install Element Hiding Helper update now?
+actionAccept=Yes
+actionDeny=Later
diff --git a/components/Initializer.js b/components/Initializer.js
new file mode 100644
index 0000000..a69e15f
--- /dev/null
+++ b/components/Initializer.js
@@ -0,0 +1,67 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Adblock Plus Element Hiding Helper.
+ *
+ * The Initial Developer of the Original Code is
+ * Wladimir Palant.
+ * Portions created by the Initial Developer are Copyright (C) 2006-2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+/**
+ * Helper component to load ABPIntegration.jsm module.
+ * @constructor
+ */
+function Initializer() {}
+Initializer.prototype =
+{
+ classDescription: "EHH helper component",
+ contractID: "@adblockplus.org/ehh/startup;1",
+ classID: Components.ID("{2d53b96c-1dd2-11b2-94ad-dedbdb99852f}"),
+ _xpcom_categories: [{ category: "app-startup", service: true }],
+
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
+
+ observe: function(subject, topic, data)
+ {
+ let observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
+ switch (topic)
+ {
+ case "app-startup":
+ observerService.addObserver(this, "final-ui-startup", true);
+ break;
+ case "final-ui-startup":
+ // Load the module
+ let chromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
+ let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+ let moduleURL = chromeRegistry.convertChromeURL(ioService.newURI("chrome://elemhidehelper-modules/content/ABPIntegration.jsm", null, null));
+ Cu.import(moduleURL.spec);
+
+ observerService.removeObserver(this, "final-ui-startup");
+ break;
+ }
+ }
+};
+
+var NSGetModule = XPCOMUtils.generateNSGetModule([Initializer]);
diff --git a/install.rdf b/install.rdf
index 8e26563..fca12d3 100644
--- a/install.rdf
+++ b/install.rdf
@@ -16,7 +16,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0.12</em:minVersion>
- <em:maxVersion>3.7a4pre</em:maxVersion>
+ <em:maxVersion>3.7a5pre</em:maxVersion>
</Description>
</em:targetApplication>
@@ -87,17 +87,6 @@
</Description>
</em:targetApplication>
- <!-- Dependency on Adblock Plus -->
- <em:requires>
- <Description>
- <em:id>{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}</em:id>
- <em:name>Adblock Plus</em:name>
- <em:homepageURL>http://adblockplus.org/</em:homepageURL>
- <em:minVersion>1.1</em:minVersion>
- <em:maxVersion>*</em:maxVersion>
- </Description>
- </em:requires>
-
<!-- Front End MetaData -->
<em:name>Adblock Plus: Element Hiding Helper</em:name>
<em:description>Helps you create element hiding rules for Adblock Plus to fight the text ads.</em:description>
diff --git a/modules/ABPIntegration.jsm b/modules/ABPIntegration.jsm
new file mode 100644
index 0000000..c4efcd9
--- /dev/null
+++ b/modules/ABPIntegration.jsm
@@ -0,0 +1,479 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Adblock Plus Element Hiding Helper.
+ *
+ * The Initial Developer of the Original Code is
+ * Wladimir Palant.
+ * Portions created by the Initial Developer are Copyright (C) 2006-2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = ["EHH"];
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+/**
+ * Add-on ID of the Adblock Plus add-on.
+ * @type String
+ */
+const abpID = "{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}";
+
+/**
+ * ID of Adblock Plus on addons.mozilla.org.
+ * @type Integer
+ */
+const abpAmoID = 1865;
+
+/**
+ * Minimal required Adblock Plus version.
+ * @type String
+ */
+const minABPVersion = "1.3a";
+
+/**
+ * Add-on ID of this add-on.
+ * @type String
+ */
+const myID = "elemhidehelper at adblockplus.org";
+
+/**
+ * Location of this file to be reported to Adblock Plus (lazily initialized).
+ * @type nsIURI
+ */
+let moduleURI = null;
+
+/**
+ * Timer used to delay checking for compatible Adblock Plus version.
+ * @type nsITimer
+ */
+let timer = null;
+
+/**
+ * Exported symbol of the module, will be triggered by Adblock Plus.
+ * @class
+ */
+var EHH =
+{
+ initialized: false,
+
+ startup: function()
+ {
+ EHH.initialized = true;
+ },
+
+ shutdown: function(/**Boolean*/ cleanup)
+ {
+ if (cleanup)
+ {
+ EHH.initialized = false;
+
+ // Close all our windows
+ let enumerator = Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getEnumerator("ehh:composer");
+ while (enumerator.hasMoreElements())
+ {
+ let wnd = enumerator.getNext();
+ if (wnd instanceof Ci.nsIDOMWindowInternal && !wnd.closed)
+ wnd.close();
+ }
+ }
+ }
+};
+
+let extensionManager = null;
+
+/**
+ * Executed when the module loads, registers its location in the ABP category
+ * and starts waiting for Adblock Plus to initialize it.
+ */
+function init()
+{
+ let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+ let uri = ioService.newFileURI(__LOCATION__);
+
+ let categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
+ categoryManager.addCategoryEntry("adblock-plus-module-location", uri.spec, uri.spec, false, true);
+
+ // Wait a minute before checking, just in case...
+ timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+ timer.initWithCallback(startABPCheck, 60000, Ci.nsITimer.TYPE_ONE_SHOT);
+}
+
+/**
+ * Starts checking whether a compatible Adblock Plus version is installed.
+ */
+function startABPCheck()
+{
+ timer = null;
+ if (!EHH.initialized)
+ {
+ // Adblock Plus didn't initialize us - what's wrong?
+ checkDependencies();
+ }
+}
+
+/**
+ * Called if no compatible Adblock Plus version is found, tries to find the cause.
+ */
+function checkDependencies()
+{
+ // Get extension manager - either new or old API
+ try
+ {
+ Cu.import("resource://gre/modules/AddonManager.jsm");
+ }
+ catch (e)
+ {
+ extensionManager = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
+ }
+
+ getAddonInfo(abpID, checkABPInfo);
+}
+
+/**
+ * Checks the information on the installed Adblock Plus add-on.
+ */
+function checkABPInfo(info)
+{
+ if (info == null)
+ {
+ // Adblock Plus isn't installed - suggest installing it
+ showMessage("abpInstallationRequired");
+ return;
+ }
+
+ if (info.hasPendingOperations)
+ {
+ // Some operation is pending already, don't bother the user
+ return;
+ }
+
+ let versionComparator = Cc["@mozilla.org/xpcom/version-comparator;1"]
+ .getService(Ci.nsIVersionComparator);
+ if (versionComparator.compare(info.version, minABPVersion) < 0)
+ {
+ // Adblock Plus is too old - suggest updating it
+ checkForUpdates(info, "abpUpdateRequired");
+ return;
+ }
+
+ if (info.userDisabled)
+ {
+ // Adblock Plus is disabled - suggest enabling
+ if (info.canEnable)
+ showMessage("abpEnableRequired", info);
+ return;
+ }
+
+ if (info.appDisabled)
+ {
+ // Adblock Plus disabled by application - outdated version? Check for updates.
+ checkForUpdates(info, "abpUpdateRequired");
+ return;
+ }
+
+ // Everything looks fine - maybe it is us who needs an update?
+ getAddonInfo(myID, function(info)
+ {
+ if (info)
+ checkForUpdates(info, "selfUpdateRequired");
+ });
+}
+
+/**
+ * Retrieves the information on an installed add-on by its ID.
+ */
+function getAddonInfo(addonID, callback)
+{
+ if (typeof AddonManager != "undefined")
+ {
+ AddonManager.getAddonByID(addonID, function(addon)
+ {
+ if (!addon)
+ {
+ callback(null);
+ return;
+ }
+
+ callback({
+ version: addon.version,
+ hasPendingOperations: addon.pendingOperations ? true : false,
+ appDisabled: addon.appDisabled,
+ userDisabled: addon.userDisabled,
+ canUpdate: (addon.permissions & AddonManager.PERM_CAN_UPGRADE) ? true : false,
+ canEnable: (addon.permissions & AddonManager.PERM_CAN_ENABLE) ? true : false,
+ _source: addon
+ });
+ });
+ }
+ else
+ {
+ let addon = extensionManager.getItemForID(addonID);
+ if (!addon)
+ {
+ callback(null);
+ return;
+ }
+
+ let rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
+ let addonResource = rdf.GetResource("urn:mozilla:item:" + addonID);
+
+ function getAddonProperty(property)
+ {
+ let link = rdf.GetResource("http://www.mozilla.org/2004/em-rdf#" + property);
+ let target = extensionManager.datasource.GetTarget(addonResource, link, true);
+ return (target instanceof Ci.nsIRDFLiteral ? target.Value : null);
+ }
+
+ callback({
+ version: addon.version,
+ hasPendingOperations: !!getAddonProperty("opType"),
+ appDisabled: !!getAddonProperty("appDisabled"),
+ userDisabled: !!getAddonProperty("userDisabled"),
+ canUpdate: extensionManager.getInstallLocation(addonID).canAccess,
+ canEnable: true,
+ _source: addon
+ });
+ }
+}
+
+/**
+ * Looks for available updates of an add-on.
+ */
+function checkForUpdates(info, message)
+{
+ if (!info.canUpdate)
+ return; // Sorry all you restricted users out there...
+
+ if (typeof AddonManager != "undefined")
+ {
+ info._source.findUpdates({
+ onUpdateAvailable: function(addon, install)
+ {
+ if (install.version != info.version)
+ {
+ info._install = install;
+ showMessage(message, info);
+ }
+ },
+ onNoUpdateAvailable: function(addon) {},
+ onCompatibilityUpdateAvailable: function(addon) {},
+ onNoCompatibilityUpdateAvailable: function(addon) {},
+ onUpdateFinished: function(addon) {}
+ }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
+ }
+ else
+ {
+ extensionManager.update([info._source], 1, 0, {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIAddonUpdateCheckListener]),
+ onAddonUpdateStarted: function(addon) {},
+ onAddonUpdateEnded: function(addon, status)
+ {
+ if (addon.version != info.version)
+ {
+ info._install = addon;
+ showMessage(message, info);
+ }
+ },
+ onUpdateStarted: function() {},
+ onUpdateEnded: function() {},
+ });
+ }
+}
+
+let knownWindowTypes = {
+ "navigator:browser": true,
+ "mail:3pane": true,
+ "mail:messageWindow": true,
+ "Songbird:Main": true,
+ "emusic:window": true
+};
+
+/**
+ * Finds a compatible application window to display messages in.
+ */
+function getAppWindow() /**nsIDOMWindow*/
+{
+ let mediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
+ let enumerator = mediator.getZOrderDOMWindowEnumerator(null, true);
+ while (enumerator.hasMoreElements())
+ {
+ let wnd = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
+ let wndType = wnd.document.documentElement.getAttribute("windowtype");
+ if (wndType in knownWindowTypes)
+ return wnd;
+ }
+
+ return null;
+}
+
+/**
+ * Displays a message to the user.
+ */
+function showMessage(action, info)
+{
+ let wnd = getAppWindow();
+ if (!wnd)
+ return null; // Nothing to show the message in
+
+ let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"]
+ .getService(Ci.nsIStringBundleService)
+ .createBundle("chrome://elemhidehelper/locale/global.properties");
+
+ let doc = wnd.document;
+ let popupset = doc.createElement("popupset");
+ let panel = doc.createElement("panel");
+ let description = doc.createElement("description");
+ let buttonBox = doc.createElement("hbox");
+ let acceptButton = doc.createElement("button");
+ let denyButton = doc.createElement("button");
+
+ description.textContent = stringBundle.GetStringFromName(action);
+ acceptButton.setAttribute("label", stringBundle.GetStringFromName("actionAccept"));
+ denyButton.setAttribute("label", stringBundle.GetStringFromName("actionDeny"));
+ buttonBox.setAttribute("pack", "center");
+ panel.style.maxWidth = "300px";
+ panel.style.marginLeft = "50px";
+ panel.style.marginTop = "50px";
+ panel.style.padding = "10px";
+
+ acceptButton.addEventListener("command", function()
+ {
+ panel.hidePopup();
+ executeAction(action, info);
+ }, false);
+ denyButton.addEventListener("command", function()
+ {
+ panel.hidePopup();
+ }, false);
+
+ buttonBox.appendChild(acceptButton);
+ buttonBox.appendChild(denyButton);
+ panel.appendChild(description);
+ panel.appendChild(buttonBox);
+ popupset.appendChild(panel);
+ doc.documentElement.appendChild(popupset);
+
+ panel.openPopup(doc.documentElement, "overlap", -1, -1, false);
+}
+
+/**
+ * Creates an install object for an add-on that isn't installed yet by its AMO ID.
+ */
+function getInstallForAddon(addonID, callback)
+{
+ // Get download URL and hash from API, download won't work without a hash
+ let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIJSXMLHttpRequest);
+ xhr.open("GET", "https://services.addons.mozilla.org/api/1.1/addon/" + addonID);
+ xhr.onload = function()
+ {
+ xhr.onload = null;
+
+ let doc = xhr.responseXML;
+ if (doc && doc.documentElement && doc.documentElement.localName == "addon")
+ {
+ let name = null;
+ let version = null;
+ let iconURL = null;
+ let downloadURL = null;
+ let downloadHash = null;
+ for (let i = 0, len = doc.documentElement.childNodes.length; i < len; i++)
+ {
+ let node = doc.documentElement.childNodes[i];
+ switch (node.localName)
+ {
+ case "name":
+ name = node.textContent;
+ break;
+ case "version":
+ version = node.textContent;
+ break;
+ case "icon":
+ iconURL = node.textContent;
+ break;
+ case "install":
+ downloadURL = node.textContent;
+ downloadHash = node.getAttribute("hash");
+ break;
+ }
+ }
+
+ if (downloadURL)
+ {
+ if (typeof AddonManager != "undefined")
+ {
+ AddonManager.getInstallForURL(downloadURL, callback, "application/x-xpinstall",
+ downloadHash, name, iconURL, version, null);
+ }
+ else
+ {
+ // HACK: Use plain HTTP as download URL - extension manager's certificate
+ // check will want the final URL to be HTTPS as well otherwise. With the
+ // hash we are on the safe side anyway.
+ downloadURL = downloadURL.replace(/^https:/, "http:");
+
+ let install = Cc["@mozilla.org/updates/item;1"].createInstance(Ci.nsIUpdateItem);
+ install.init(abpID, version, "app-profile", null, null, name, downloadURL,
+ downloadHash, iconURL, null, null, Ci.nsIUpdateItem.TYPE_EXTENSION, null);
+ callback(install);
+ }
+ }
+ }
+ };
+ xhr.send();
+}
+
+/**
+ * Executes an action if the user accepted the message.
+ */
+function executeAction(action, info)
+{
+ function doInstall(install)
+ {
+ if (typeof install.install == "function")
+ install.install();
+ else
+ extensionManager.addDownloads([install], 1, null);
+ }
+
+ switch (action)
+ {
+ case "abpInstallationRequired":
+ getInstallForAddon(abpAmoID, doInstall);
+ break;
+ case "abpEnableRequired":
+ if ("userDisabled" in info._source)
+ info._source.userDisabled = false;
+ else
+ extensionManager.enableItem(abpID);
+ return;
+ case "abpUpdateRequired":
+ case "selfUpdateRequired":
+ doInstall(info._install);
+ break;
+ default:
+ return;
+ }
+}
+
+init();
diff --git a/version b/version
index ece61c6..6d971dc 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-1.0.6
\ No newline at end of file
+1.1a
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git
More information about the Pkg-mozext-commits
mailing list