[Pkg-mozext-commits] [requestpolicy] 232/257: [ref] windows.toolbarbutton: convert to "controller"
David Prévot
taffit at moszumanska.debian.org
Thu Jan 28 03:20:16 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit b538cfa789eb373a5b71f50f7e82f669025f15b9
Author: Martin Kimmerle <dev at 256k.de>
Date: Mon Dec 21 08:37:45 2015 +0100
[ref] windows.toolbarbutton: convert to "controller"
Convert the WindowManager's Toolbarbutton "submodule" into a
"sub-controller".
---
src/content/controllers/windows.toolbarbutton.jsm | 180 ++++++++++++++++++++++
src/content/main/window-manager-toolbarbutton.js | 165 --------------------
src/content/main/window-manager.jsm | 64 +++++---
3 files changed, 223 insertions(+), 186 deletions(-)
diff --git a/src/content/controllers/windows.toolbarbutton.jsm b/src/content/controllers/windows.toolbarbutton.jsm
new file mode 100644
index 0000000..2f4d6ba
--- /dev/null
+++ b/src/content/controllers/windows.toolbarbutton.jsm
@@ -0,0 +1,180 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2008-2012 Justin Samuel
+ * Copyright (c) 2014-2015 Martin Kimmerle
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see {tag: "http"://www.gnu.org/licenses}.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+/* global Components */
+const {utils: Cu} = Components;
+
+/* exported ToolbarButtonController */
+this.EXPORTED_SYMBOLS = ["ToolbarButtonController"];
+
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+let {ScriptLoader: {importModule}} = Cu.import(
+ "chrome://rpcontinued/content/lib/script-loader.jsm", {});
+let {XULUtils} = importModule("lib/utils/xul");
+let {Info} = importModule("lib/utils/info");
+let {Logger} = importModule("lib/logger");
+
+let CustomizableUI = null;
+if (Info.isAustralis) {
+ // FIXME: Re-enable (W126) when JSHint issue #2775 is fixed.
+ /* jshint -W126 */
+ ({CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm",
+ {}));
+ /* jshint +W126 */
+}
+
+//==============================================================================
+// ToolbarButtonController
+//==============================================================================
+
+var ToolbarButtonController = (function() {
+ let self = {};
+
+ const toolbarButtonId = "rpcontinuedToolbarButton";
+
+ let isAustralis = Info.isAustralis;
+
+ //----------------------------------------------------------------------------
+ // Case 1: Australis (Firefox >= 29)
+ //----------------------------------------------------------------------------
+
+ (function() {
+ if (!isAustralis) {
+ return;
+ }
+
+ function removeToolbarButtonFromAustralis() {
+ const {
+ attributes: {id}
+ } = XULUtils.xulTrees.toolbarbutton[0];
+ CustomizableUI.destroyWidget(id);
+ }
+
+ function addToolbarButtonToAustralis() {
+ const {
+ attributes: {id, label, tooltiptext}
+ } = XULUtils.xulTrees.toolbarbutton[0];
+
+ CustomizableUI.createWidget({
+ id: id,
+ defaultArea: CustomizableUI.AREA_NAVBAR,
+ label: label,
+ tooltiptext: tooltiptext,
+ onCommand: function(aEvent) {
+ // Bad smell
+ let win = aEvent.target.ownerDocument.defaultView;
+ win.rpcontinued.overlay.openMenu();
+ }
+ });
+ }
+
+ self.startup = function() {
+ addToolbarButtonToAustralis();
+ };
+
+ self.shutdown = function() {
+ removeToolbarButtonFromAustralis();
+ };
+ }());
+
+ //----------------------------------------------------------------------------
+ // Case 2: non-Australis
+ // - Firefox < 29
+ // - SeaMonkey
+ // - Pale Moon
+ //----------------------------------------------------------------------------
+
+ (function() {
+ if (isAustralis) {
+ return;
+ }
+
+ function addToolbarButtonToNavBar(win) {
+ // SeaMonkey users have to use a toolbar button now. At the moment I can't
+ // justify a bunch of special cases to support the statusbar when such a
+ // tiny number of users have seamonkey and I can't even be sure that many of
+ // those users want a statusbar icon.
+ //if (!Info.isFirefox) {
+ // Logger.info(Logger.TYPE_INTERNAL,
+ // "Not performing toolbar button check: not Firefox.");
+ // return;
+ //}
+ let doc = win.document;
+
+ let isFirstRun = false;
+ if (Services.vc.compare(Info.lastAppVersion, "0.0") <= 0) {
+ Logger.info(Logger.TYPE_INTERNAL, "This is the first run.");
+ isFirstRun = true;
+ }
+
+ let id = toolbarButtonId;
+
+ // find the toolbar in which the button has been placed by the user
+ let toolbarSelector = "[currentset^='" + id + ",'],[currentset*='," + id +
+ ",'],[currentset$='," + id + "']";
+ let toolbar = doc.querySelector(toolbarSelector);
+
+ if (!toolbar) {
+ // The button is in none of the toolbar "currentset"s. Either this is
+ // the first run or the button has been removed by the user (through
+ // customizing)
+ if (isFirstRun) {
+ toolbar = doc.getElementById("nav-bar");
+ toolbar.insertItem(id);
+ toolbar.setAttribute("currentset", toolbar.currentSet);
+ doc.persist(toolbar.id, "currentset");
+ }
+ } else {
+ // find the position of the button and insert.
+ let currentset = toolbar.getAttribute("currentset").split(",");
+ let index = currentset.indexOf(id);
+
+ let before = null;
+ for (let i = index + 1, len = currentset.length; i < len; i++) {
+ before = doc.getElementById(currentset[i]);
+ if (before) {
+ toolbar.insertItem(id, before);
+ break;
+ }
+ }
+ if (!before) {
+ toolbar.insertItem(id);
+ }
+ }
+ }
+
+ self.loadIntoWindow = function(win) {
+ if (!isAustralis) {
+ XULUtils.addTreeElementsToWindow(win, "toolbarbutton");
+ addToolbarButtonToNavBar(win);
+ }
+ };
+
+ self.unloadFromWindow = function(win) {
+ XULUtils.removeTreeElementsFromWindow(win, "toolbarbutton");
+ };
+ }());
+
+ return self;
+}());
diff --git a/src/content/main/window-manager-toolbarbutton.js b/src/content/main/window-manager-toolbarbutton.js
deleted file mode 100644
index 8a13ee7..0000000
--- a/src/content/main/window-manager-toolbarbutton.js
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * ***** BEGIN LICENSE BLOCK *****
- *
- * RequestPolicy - A Firefox extension for control over cross-site requests.
- * Copyright (c) 2008-2012 Justin Samuel
- * Copyright (c) 2014-2015 Martin Kimmerle
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see {tag: "http"://www.gnu.org/licenses}.
- *
- * ***** END LICENSE BLOCK *****
- */
-
-/* global Components */
-const {utils: Cu} = Components;
-
-/* global rpWindowManager: true */
-
-let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
-
-let {ScriptLoader: {importModule}} = Cu.import(
- "chrome://rpcontinued/content/lib/script-loader.jsm", {});
-let {Environment, ProcessEnvironment} = importModule("lib/environment");
-let {XULUtils} = importModule("lib/utils/xul");
-let {Info} = importModule("lib/utils/info");
-let {Logger} = importModule("lib/logger");
-
-let CustomizableUI = null;
-if (Info.isAustralis) {
- // FIXME: Re-enable (W126) when JSHint issue #2775 is fixed.
- /* jshint -W126 */
- ({CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm",
- {}));
- /* jshint +W126 */
-}
-
-//==============================================================================
-// rpWindowManager (extension)
-//==============================================================================
-
-rpWindowManager = (function(self) {
- const toolbarButtonId = "rpcontinuedToolbarButton";
-
- let isAustralis = Info.isAustralis;
-
- //
- // Case 1: Australis (Firefox >= 29)
- //
-
- if (isAustralis) {
- ProcessEnvironment.addStartupFunction(Environment.LEVELS.UI,
- addToolbarButtonToAustralis);
- ProcessEnvironment.addShutdownFunction(Environment.LEVELS.UI,
- removeToolbarButtonFromAustralis);
- }
-
- function removeToolbarButtonFromAustralis() {
- const {
- attributes: {id}
- } = XULUtils.xulTrees.toolbarbutton[0];
- CustomizableUI.destroyWidget(id);
- }
-
- function addToolbarButtonToAustralis() {
- const {
- attributes: {id, label, tooltiptext}
- } = XULUtils.xulTrees.toolbarbutton[0];
-
- CustomizableUI.createWidget({
- id: id,
- defaultArea: CustomizableUI.AREA_NAVBAR,
- label: label,
- tooltiptext: tooltiptext,
- onCommand: function(aEvent) {
- // Bad smell
- let win = aEvent.target.ownerDocument.defaultView;
- win.rpcontinued.overlay.openMenu();
- }
- });
- }
-
- //
- // Case 2: Gecko < 29
- //
-
- // this function can be deleted if Gecko < 29 isn't supported anymore
- self.addToolbarButtonToWindow = function(win) {
- if (!isAustralis) {
- XULUtils.addTreeElementsToWindow(win, "toolbarbutton");
- addToolbarButtonToNavBar(win);
- }
- };
-
- self.removeToolbarButtonFromWindow = function(win) {
- if (!isAustralis) {
- XULUtils.removeTreeElementsFromWindow(win, "toolbarbutton");
- }
- };
-
- function addToolbarButtonToNavBar(win) {
- // SeaMonkey users have to use a toolbar button now. At the moment I can't
- // justify a bunch of special cases to support the statusbar when such a
- // tiny number of users have seamonkey and I can't even be sure that many of
- // those users want a statusbar icon.
- //if (!Info.isFirefox) {
- // Logger.info(Logger.TYPE_INTERNAL,
- // "Not performing toolbar button check: not Firefox.");
- // return;
- //}
- let doc = win.document;
-
- let isFirstRun = false;
- if (Services.vc.compare(Info.lastAppVersion, "0.0") <= 0) {
- Logger.info(Logger.TYPE_INTERNAL, "This is the first run.");
- isFirstRun = true;
- }
-
- let id = toolbarButtonId;
-
- // find the toolbar in which the button has been placed by the user
- let toolbarSelector = "[currentset^='" + id + ",'],[currentset*='," + id +
- ",'],[currentset$='," + id + "']";
- let toolbar = doc.querySelector(toolbarSelector);
-
- if (!toolbar) {
- // The button is in none of the toolbar "currentset"s. Either this is
- // the first run or the button has been removed by the user (through
- // customizing)
- if (isFirstRun) {
- toolbar = doc.getElementById("nav-bar");
- toolbar.insertItem(id);
- toolbar.setAttribute("currentset", toolbar.currentSet);
- doc.persist(toolbar.id, "currentset");
- }
- } else {
- // find the position of the button and insert.
- let currentset = toolbar.getAttribute("currentset").split(",");
- let index = currentset.indexOf(id);
-
- let before = null;
- for (let i = index + 1, len = currentset.length; i < len; i++) {
- before = doc.getElementById(currentset[i]);
- if (before) {
- toolbar.insertItem(id, before);
- break;
- }
- }
- if (!before) {
- toolbar.insertItem(id);
- }
- }
- }
-
- return self;
-}(rpWindowManager || {}));
diff --git a/src/content/main/window-manager.jsm b/src/content/main/window-manager.jsm
index 6778e52..80dd31d 100644
--- a/src/content/main/window-manager.jsm
+++ b/src/content/main/window-manager.jsm
@@ -35,6 +35,8 @@ let {Logger} = importModule("lib/logger");
let {Info} = importModule("lib/utils/info");
let {XULUtils} = importModule("lib/utils/xul");
let {Environment, ProcessEnvironment} = importModule("lib/environment");
+let {ToolbarButtonController} = importModule(
+ "controllers/windows.toolbarbutton");
//==============================================================================
// WindowListener
@@ -48,6 +50,39 @@ let WindowListener = (function() {
}());
//==============================================================================
+// WindowSubControllers
+//==============================================================================
+
+let WindowSubControllers = (function() {
+ let self = {};
+
+ const SUBCONTROLLERS = Object.freeze([
+ ToolbarButtonController,
+ ]);
+
+ const SUBCONTROLLERS_REVERSE = Object.freeze(
+ SUBCONTROLLERS.slice().reverse());
+
+ function callForEachController(fnName, reverse, ...args) {
+ let controllers = reverse ? SUBCONTROLLERS_REVERSE : SUBCONTROLLERS;
+ controllers.forEach(function(controller) {
+ if (typeof controller[fnName] === "function") {
+ controller[fnName].apply(null, args);
+ }
+ });
+ }
+
+ self.startup = callForEachController.bind(null, "startup", false);
+ self.shutdown = callForEachController.bind(null, "shutdown", true);
+ self.loadIntoWindow = callForEachController.bind(null, "loadIntoWindow",
+ false);
+ self.unloadFromWindow = callForEachController.bind(null, "unloadFromWindow",
+ true);
+
+ return self;
+}());
+
+//==============================================================================
// rpWindowManager
//==============================================================================
@@ -101,14 +136,9 @@ var rpWindowManager = (function() {
}
// ==================================
- // # 4 : toolbar button
- // --------------------
- try {
- self.addToolbarButtonToWindow(window);
- } catch (e) {
- Logger.warning(Logger.TYPE_ERROR, "Error while adding the toolbar " +
- "button to the window: " + e, e);
- }
+ // # 4 : controllers
+ // -----------------
+ WindowSubControllers.loadIntoWindow(window);
// ==================================
// # 5 : init the overlay
@@ -127,9 +157,9 @@ var rpWindowManager = (function() {
// # 5 : the overlay cares itself about shutdown.
// nothing to do here.
- // # 4 : remove the toolbarbutton
- // ------------------------------
- self.removeToolbarButtonFromWindow(window);
+ // # 4 : controllers
+ // -----------------
+ WindowSubControllers.unloadFromWindow(window);
// # 3 : remove all XUL elements
XULUtils.removeTreeElementsFromWindow(window, "mainTree");
@@ -144,6 +174,7 @@ var rpWindowManager = (function() {
ProcessEnvironment.addStartupFunction(
Environment.LEVELS.INTERFACE,
function(data, reason) {
+ WindowSubControllers.startup();
forEachOpenWindow(loadIntoWindow);
WindowListener.setLoadFunction(loadIntoWindow);
WindowListener.setUnloadFunction(unloadFromWindow);
@@ -176,6 +207,7 @@ var rpWindowManager = (function() {
globalMM.removeDelayedFrameScript(frameScriptURI);
forEachOpenWindow(unloadFromWindow);
+ WindowSubControllers.shutdown();
WindowListener.stopListening();
});
@@ -217,13 +249,3 @@ var rpWindowManager = (function() {
return self;
}());
-
-rpWindowManager = (function() {
- let scope = {
- rpWindowManager: rpWindowManager
- };
- Services.scriptloader.loadSubScript(
- "chrome://rpcontinued/content/main/window-manager-toolbarbutton.js",
- scope);
- return scope.rpWindowManager;
-}());
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list