[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 376/483: Switched to a simpler module system, removed some no longer required backwards compatibility code
David Prévot
taffit at moszumanska.debian.org
Thu Jan 22 21:41:58 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 287082193d0bd9bc67541385964bc410f1e92f08
Author: Wladimir Palant <trev at adblockplus.org>
Date: Sat Jan 21 17:29:04 2012 +0100
Switched to a simpler module system, removed some no longer required backwards compatibility code
--HG--
rename : modules/Aardvark.jsm => aardvark.js
rename : modules/AppIntegration.jsm => appIntegration.js
rename : modules/Prefs.jsm => prefs.js
---
modules/Aardvark.jsm => aardvark.js | 20 ++------
modules/AppIntegration.jsm => appIntegration.js | 33 ++++++-------
bootstrap.js | 54 +++++++++++++++++++--
chrome.manifest | 1 -
chrome/content/about.js | 62 ++++---------------------
chrome/content/about.xul | 1 +
chrome/content/common.js | 22 +++++++++
chrome/content/composer.js | 26 ++++-------
chrome/content/composer.xul | 3 +-
modules/Prefs.jsm => prefs.js | 26 +++++------
10 files changed, 123 insertions(+), 125 deletions(-)
diff --git a/modules/Aardvark.jsm b/aardvark.js
similarity index 98%
rename from modules/Aardvark.jsm
rename to aardvark.js
index 2c1b044..c42bf90 100644
--- a/modules/Aardvark.jsm
+++ b/aardvark.js
@@ -4,14 +4,11 @@
* http://mozilla.org/MPL/2.0/.
*/
-var EXPORTED_SYMBOLS = ["Aardvark"];
-
const Cc = Components.classes;
const Ci = Components.interfaces;
-const Cr = Components.results;
const Cu = Components.utils;
-Cu.import("chrome://elemhidehelper-modules/content/Prefs.jsm");
+let {Prefs} = require("prefs");
// To be replaced when selection starts
function E(id) {return null;}
@@ -20,7 +17,7 @@ function E(id) {return null;}
* General element selection code *
**********************************/
-var Aardvark =
+let Aardvark = exports.Aardvark =
{
window: null,
browser: null,
@@ -74,10 +71,7 @@ var Aardvark =
canSelect: function(browser)
{
- if (!Prefs.initialized)
- return false;
-
- if (!browser || !browser.contentWindow ||
+ if (!browser || !browser.contentWindow ||
!(browser.contentDocument instanceof Ci.nsIDOMHTMLDocument))
{
return false;
@@ -304,12 +298,6 @@ var Aardvark =
this.selectElement(newSelection);
},
- bindMethod: function(method)
- {
- let me = this;
- return function() method.apply(me, arguments);
- },
-
appendDescription: function(node, value, className)
{
var descr = this.window.document.createElement("description");
@@ -750,4 +738,4 @@ var Aardvark =
// Makes sure event handlers like Aardvark.onKeyPress always have the correct
// this pointer set.
for each (let method in ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageHide", "onMouseMove", "onAfterPaint"])
- Aardvark[method] = Aardvark.bindMethod(Aardvark[method]);
+ Aardvark[method] = Aardvark[method].bind(Aardvark);
diff --git a/modules/AppIntegration.jsm b/appIntegration.js
similarity index 95%
rename from modules/AppIntegration.jsm
rename to appIntegration.js
index e45037c..d26d8c3 100644
--- a/modules/AppIntegration.jsm
+++ b/appIntegration.js
@@ -4,31 +4,29 @@
* http://mozilla.org/MPL/2.0/.
*/
-var EXPORTED_SYMBOLS = ["AppIntegration"];
-
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");
-var AppIntegration =
+let {Aardvark} = require("aardvark");
+let {Prefs} = require("prefs");
+
+let AppIntegration = exports.AppIntegration =
{
initialized: false,
elementMarkerClass: null,
styleURI: null,
- startup: function()
+ init: function()
{
if (this.initialized)
return;
this.initialized = true;
- Cu.import("chrome://elemhidehelper-modules/content/Aardvark.jsm");
- Cu.import("chrome://elemhidehelper-modules/content/Prefs.jsm");
- Prefs.startup();
+ Prefs.init("extensions.elemhidehelper.");
// Use random marker class
let rnd = [];
@@ -69,8 +67,8 @@ var AppIntegration =
for (let child = request2.responseXML.firstChild; child; child = child.nextSibling)
if (child.nodeType == child.PROCESSING_INSTRUCTION_NODE)
WindowObserver.overlay._processing.push(child);
- WindowObserver.startup();
- InspectorObserver.startup();
+ WindowObserver.init();
+ InspectorObserver.init();
}.bind(this), false);
request2.send(null);
},
@@ -92,19 +90,16 @@ var AppIntegration =
Aardvark.quit();
WindowObserver.shutdown();
InspectorObserver.shutdown();
-
- Cu.unload("chrome://elemhidehelper-modules/content/Aardvark.jsm");
- Cu.unload("chrome://elemhidehelper-modules/content/Prefs.jsm");
}
};
-var WindowObserver =
+let WindowObserver =
{
initialized: false,
overlay: null,
- startup: function()
+ init: function()
{
if (this.initialized)
return;
@@ -211,11 +206,11 @@ var WindowObserver =
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
};
-var InspectorObserver =
+let InspectorObserver =
{
initialized: false,
- startup: function()
+ init: function()
{
if (this.initialized)
return;
@@ -287,14 +282,14 @@ function WindowWrapper(wnd)
this.E("ehh-elementmarker").firstElementChild.setAttribute("class", AppIntegration.elementMarkerClass);
- this.startup();
+ this.init();
}
WindowWrapper.prototype =
{
window: null,
browser: null,
- startup: function()
+ init: function()
{
this.window.addEventListener("popupshowing", this.popupShowingHandler, false);
this.window.addEventListener("popuphiding", this.popupHidingHandler, false);
diff --git a/bootstrap.js b/bootstrap.js
index 7e04a77..2a31e44 100644
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -9,6 +9,9 @@ const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+let addonData = null;
function install(params, reason) {}
function uninstall(params, reason) {}
@@ -18,18 +21,19 @@ function startup(params, reason)
if (Services.vc.compare(Services.appinfo.platformVersion, "10.0") < 0)
Components.manager.addBootstrappedManifestLocation(params.installPath);
+ addonData = params;
+ Services.obs.addObserver(RequireObserver, "elemhidehelper-require", true);
+
let scope = {};
Services.scriptloader.loadSubScript("chrome://elemhidehelper/content/prefLoader.js", scope);
scope.loadDefaultPrefs(params.installPath);
- Cu.import("chrome://elemhidehelper-modules/content/AppIntegration.jsm");
- AppIntegration.startup();
+ require("appIntegration").AppIntegration.init();
}
function shutdown(params, reason)
{
- AppIntegration.shutdown();
- Cu.unload("chrome://elemhidehelper-modules/content/AppIntegration.jsm");
+ require("appIntegration").AppIntegration.shutdown();
let aboutWnd = Services.wm.getMostRecentWindow("ehh:about");
if (aboutWnd)
@@ -43,6 +47,48 @@ function shutdown(params, reason)
helperWnd.close();
}
+ Services.obs.removeObserver(RequireObserver, "elemhidehelper-require");
+ addonData = null;
+ require.scopes = {__proto__: null};
+
if (Services.vc.compare(Services.appinfo.platformVersion, "10.0") < 0)
Components.manager.removeBootstrappedManifestLocation(params.installPath);
}
+
+function require(module)
+{
+ let scopes = require.scopes;
+ if (!(module in scopes))
+ {
+ if (module == "info")
+ {
+ scopes[module] = {};
+ scopes[module].exports =
+ {
+ addonID: addonData.id,
+ addonVersion: addonData.version,
+ addonRoot: addonData.resourceURI.spec,
+ };
+ }
+ else
+ {
+ scopes[module] = {require: require, exports: {}};
+ Services.scriptloader.loadSubScript(addonData.resourceURI.spec + module + ".js", scopes[module]);
+ }
+ }
+ return scopes[module].exports;
+}
+require.scopes = {__proto__: null};
+
+let RequireObserver =
+{
+ observe: function(subject, topic, data)
+ {
+ if (topic == "elemhidehelper-require")
+ {
+ subject.wrappedJSObject.exports = require(data);
+ }
+ },
+
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
+};
diff --git a/chrome.manifest b/chrome.manifest
index 8985396..6f4c446 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -1,4 +1,3 @@
content elemhidehelper chrome/content/
skin elemhidehelper classic/1.0 chrome/skin/
locale elemhidehelper {{LOCALE}} chrome/locale/{{LOCALE}}/
-content elemhidehelper-modules modules/
diff --git a/chrome/content/about.js b/chrome/content/about.js
index 84f420c..afd9c13 100644
--- a/chrome/content/about.js
+++ b/chrome/content/about.js
@@ -4,61 +4,19 @@
* http://mozilla.org/MPL/2.0/.
*/
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cr = Components.results;
-const Cu = Components.utils;
+let {addonID, addonVersion, addonRoot} = require("info");
-try
-{
- Cu.import("resource://gre/modules/AddonManager.jsm");
-}
-catch (e) {}
-
-let addonID = "elemhidehelper at adblockplus.org";
-
-function E(id) document.getElementById(id);
+Cu.import("resource://gre/modules/AddonManager.jsm");
function init()
{
- let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
- if (typeof AddonManager != "undefined")
- {
- let addon = AddonManager.getAddonByID(addonID, function(addon)
- {
- loadInstallManifest(addon.getResourceURI("install.rdf"), addon.name, addon.homepageURL);
- });
- }
- else
- {
- let extensionManager = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
- let rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
- let root = rdf.GetResource("urn:mozilla:item:" + addonID);
-
- function emResource(prop)
- {
- return rdf.GetResource("http://www.mozilla.org/2004/em-rdf#" + prop);
- }
-
- function getTarget(prop)
- {
- let target = extensionManager.datasource.GetTarget(root, emResource(prop), true);
- if (target)
- return target.QueryInterface(Ci.nsIRDFLiteral).Value;
- else
- return null;
- }
-
- let installLocation = extensionManager.getInstallLocation(addonID);
- let installManifestFile = installLocation.getItemFile(addonID, "install.rdf");
- loadInstallManifest(ioService.newFileURI(installManifestFile), getTarget("name"), getTarget("homepageURL"));
- }
+ AddonManager.getAddonByID(addonID, loadInstallManifest);
}
-function loadInstallManifest(installManifestURI, name, homepage)
+function loadInstallManifest(addon)
{
let rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
- let ds = rdf.GetDataSource(installManifestURI.spec);
+ let ds = rdf.GetDataSource(addonRoot + "install.rdf");
let root = rdf.GetResource("urn:mozilla:install-manifest");
function emResource(prop)
@@ -77,8 +35,8 @@ function loadInstallManifest(installManifestURI, name, homepage)
function dataSourceLoaded()
{
- setExtensionData(name, getTargets("version")[0],
- homepage, getTargets("creator"),
+ setExtensionData(addon.name, addonVersion,
+ addon.homepageURL, getTargets("creator"),
getTargets("contributor"), getTargets("translator"));
}
@@ -130,8 +88,7 @@ function setExtensionData(name, version, homepage, authors, contributors, transl
function loadInBrowser(url)
{
- let windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
- let enumerator = windowMediator.getZOrderDOMWindowEnumerator(null, true);
+ let enumerator = Services.wm.getZOrderDOMWindowEnumerator(null, true);
if (!enumerator.hasMoreElements())
{
// On Linux the list returned will be empty, see bug 156333. Fall back to random order.
@@ -154,7 +111,6 @@ function loadInBrowser(url)
else
{
let protocolService = Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(Ci.nsIExternalProtocolService);
- let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
- protocolService.loadURI(ioService.newURI(url, null, null), null);
+ protocolService.loadURI(Services.io.newURI(url, null, null), null);
}
}
diff --git a/chrome/content/about.xul b/chrome/content/about.xul
index 48a46db..ca1c229 100644
--- a/chrome/content/about.xul
+++ b/chrome/content/about.xul
@@ -18,6 +18,7 @@
buttons="accept">
<script type="application/x-javascript;version=1.7" src="utils.js"/>
+<script type="application/x-javascript;version=1.7" src="common.js"/>
<script type="application/x-javascript;version=1.7" src="about.js"/>
<vbox id="mainBox">
diff --git a/chrome/content/common.js b/chrome/content/common.js
new file mode 100644
index 0000000..cf56df1
--- /dev/null
+++ b/chrome/content/common.js
@@ -0,0 +1,22 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+function require(module)
+{
+ let result = {};
+ result.wrappedJSObject = result;
+ Services.obs.notifyObservers(result, "elemhidehelper-require", module);
+ return result.exports;
+}
+
+function E(id) document.getElementById(id);
diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index 833d4c7..566830f 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -4,22 +4,16 @@
* http://mozilla.org/MPL/2.0/.
*/
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cr = Components.results;
-const Cu = Components.utils;
-
-var domainData;
-var nodeData;
-var selectedNode = null;
-var advancedMode = false;
-var treeView = null;
-var stylesheetURL;
-var previewStyle = null;
-var doc;
-
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("chrome://elemhidehelper-modules/content/Prefs.jsm");
+let {Prefs} = require("prefs");
+
+let domainData;
+let nodeData;
+let selectedNode = null;
+let advancedMode = false;
+let treeView = null;
+let stylesheetURL;
+let previewStyle = null;
+let doc;
let abpURL = Cc["@adblockplus.org/abp/public;1"].getService(Ci.nsIURI);
Cu.import(abpURL.spec);
diff --git a/chrome/content/composer.xul b/chrome/content/composer.xul
index e0babdc..dff9479 100644
--- a/chrome/content/composer.xul
+++ b/chrome/content/composer.xul
@@ -26,7 +26,8 @@
buttonlabeldisclosure_on="&advanced.label;"
buttonlabeldisclosure_off="&basic.label;"
windowtype="ehh:composer">
- <script type="application/x-javascript" src="composer.js"/>
+ <script type="application/x-javascript;version=1.7" src="common.js"/>
+ <script type="application/x-javascript;version=1.7" src="composer.js"/>
<description id="groupDisabledWarning" hidden="true">&groupDisabled.warning;</description>
diff --git a/modules/Prefs.jsm b/prefs.js
similarity index 92%
rename from modules/Prefs.jsm
rename to prefs.js
index 3294a07..80acca0 100644
--- a/modules/Prefs.jsm
+++ b/prefs.js
@@ -4,29 +4,24 @@
* http://mozilla.org/MPL/2.0/.
*/
-var EXPORTED_SYMBOLS = ["Prefs"];
-
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");
-const prefRoot = "extensions.elemhidehelper.";
-
-let branch = Services.prefs.getBranch(prefRoot);
+let prefRoot = null;
+let branch = null;
-var Prefs =
+let Prefs = exports.Prefs =
{
- initialized: false,
-
- startup: function()
+ init: function(root)
{
- if (this.initialized)
+ if (prefRoot)
return;
- this.initialized = true;
+ prefRoot = root;
+ branch = Services.prefs.getBranch(prefRoot);
let defaultBranch = Services.prefs.getDefaultBranch(prefRoot);
for each (let name in defaultBranch.getChildList("", {}))
@@ -74,9 +69,9 @@ var Prefs =
shutdown: function()
{
- if (!this.initialized)
+ if (!prefRoot)
return;
- this.initialized = false;
+ prefRoot = null;
try
{
@@ -87,10 +82,11 @@ var Prefs =
{
Cu.reportError(e);
}
+ branch = null;
}
};
-var PrefsPrivate =
+let PrefsPrivate =
{
ignorePrefChanges: false,
--
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