[Pkg-mozext-commits] [requestpolicy] 234/257: [ref] windows.overlay: new controller

David Prévot taffit at moszumanska.debian.org
Thu Jan 28 03:20:17 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 67b276e51c005d5dfe25f0ee553c578408a19242
Author: Martin Kimmerle <dev at 256k.de>
Date:   Mon Dec 21 09:45:35 2015 +0100

    [ref] windows.overlay: new controller
    
    Factor out code into OverlayController.
---
 src/content/controllers/windows.overlay.jsm | 79 +++++++++++++++++++++++++++++
 src/content/main/window-manager.jsm         | 68 ++-----------------------
 2 files changed, 83 insertions(+), 64 deletions(-)

diff --git a/src/content/controllers/windows.overlay.jsm b/src/content/controllers/windows.overlay.jsm
new file mode 100644
index 0000000..66fbe86
--- /dev/null
+++ b/src/content/controllers/windows.overlay.jsm
@@ -0,0 +1,79 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2014 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 OverlayController */
+this.EXPORTED_SYMBOLS = ["OverlayController"];
+
+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");
+
+//==============================================================================
+// OverlayController
+//==============================================================================
+
+var OverlayController = (function() {
+  let self = {};
+
+  function loadScriptsIntoWindow(window) {
+    function loadScript(path) {
+      let uri = "chrome://rpcontinued/content/" + path;
+      Services.scriptloader.loadSubScript(uri, window);
+    }
+    loadScript("ui/overlay.js");
+    loadScript("ui/menu.js");
+    loadScript("ui/classicmenu.js");
+  }
+
+  self.loadIntoWindow = function(window) {
+    // create a scope variable
+    window.rpcontinued = {};
+
+    // load the overlay's and menu's javascript
+    loadScriptsIntoWindow(window);
+
+    // add all XUL elements
+    XULUtils.addTreeElementsToWindow(window, "mainTree");
+
+    // init() assumes that all XUL elements are ready
+    window.rpcontinued.overlay.init();
+  };
+
+  self.unloadFromWindow = function(window) {
+    // the overlay cares itself about shutdown.
+
+    // remove all XUL elements
+    XULUtils.removeTreeElementsFromWindow(window, "mainTree");
+
+    // Remove the scope variable.
+    // This wouldn't be needed when the window is closed, but this has to be
+    // done when RP is being disabled.
+    delete window.rpcontinued;
+  };
+
+  return self;
+}());
diff --git a/src/content/main/window-manager.jsm b/src/content/main/window-manager.jsm
index 102a967..4f5a526 100644
--- a/src/content/main/window-manager.jsm
+++ b/src/content/main/window-manager.jsm
@@ -31,9 +31,8 @@ let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
 let {ScriptLoader: {importModule}} = Cu.import(
     "chrome://rpcontinued/content/lib/script-loader.jsm", {});
-let {Logger} = importModule("lib/logger");
-let {XULUtils} = importModule("lib/utils/xul");
 let {Environment, ProcessEnvironment} = importModule("lib/environment");
+let {OverlayController} = importModule("controllers/windows.overlay");
 let {ToolbarButtonController} = importModule(
     "controllers/windows.toolbarbutton");
 let {StyleSheetsController} = importModule("controllers/windows.style-sheets");
@@ -57,6 +56,7 @@ let WindowSubControllers = (function() {
   let self = {};
 
   const SUBCONTROLLERS = Object.freeze([
+    OverlayController,
     ToolbarButtonController,
     StyleSheetsController,
   ]);
@@ -94,73 +94,11 @@ var rpWindowManager = (function() {
       Math.random();
 
   function loadIntoWindow(window) {
-    // ==================================
-    // # 1 : create a scope variable for RP for this window
-    // ----------------------------------------------------
-    window.rpcontinued = {};
-
-    // ==================================
-    // # 2 : load the overlay's and menu's javascript
-    // ----------------------------------------------
-    try {
-      Services.scriptloader.loadSubScript(
-          "chrome://rpcontinued/content/ui/overlay.js",
-          window);
-      Services.scriptloader.loadSubScript(
-          "chrome://rpcontinued/content/ui/menu.js",
-          window);
-      Services.scriptloader.loadSubScript(
-          "chrome://rpcontinued/content/ui/classicmenu.js",
-          window);
-    } catch (e) {
-      Logger.warning(Logger.TYPE_ERROR,
-                     "Error loading subscripts for window: " + e, e);
-    }
-
-    // ==================================
-    // # 3 : add all XUL elements
-    // --------------------------
-    try {
-      XULUtils.addTreeElementsToWindow(window, "mainTree");
-    } catch (e) {
-      Logger.warning(Logger.TYPE_ERROR,
-                     "Couldn't add tree elements to window. " + e, e);
-    }
-
-    // ==================================
-    // # 4 : controllers
-    // -----------------
     WindowSubControllers.loadIntoWindow(window);
-
-    // ==================================
-    // # 5 : init the overlay
-    // ----------------------
-    try {
-      // init must be called last, because it assumes that
-      // everything else is ready
-      window.rpcontinued.overlay.init();
-    } catch (e) {
-      Logger.warning(Logger.TYPE_ERROR,
-          "An error occurred while initializing the overlay: " + e, e);
-    }
   }
 
   function unloadFromWindow(window) {
-    // # 5 : the overlay cares itself about shutdown.
-    //       nothing to do here.
-
-    // # 4 : controllers
-    // -----------------
     WindowSubControllers.unloadFromWindow(window);
-
-    // # 3 : remove all XUL elements
-    XULUtils.removeTreeElementsFromWindow(window, "mainTree");
-
-    // # 2 and 1 : remove the `rpcontinued` variable from the window
-    // ---------------------------------------------------------
-    // This wouldn't be needed when the window is closed, but this has to be
-    // done when RP is being disabled.
-    delete window.rpcontinued;
   }
 
   ProcessEnvironment.addStartupFunction(
@@ -168,6 +106,7 @@ var rpWindowManager = (function() {
       function(data, reason) {
         WindowSubControllers.startup();
         forEachOpenWindow(loadIntoWindow);
+
         WindowListener.setLoadFunction(loadIntoWindow);
         WindowListener.setUnloadFunction(unloadFromWindow);
         WindowListener.startListening();
@@ -198,6 +137,7 @@ var rpWindowManager = (function() {
 
         forEachOpenWindow(unloadFromWindow);
         WindowSubControllers.shutdown();
+
         WindowListener.stopListening();
       });
 

-- 
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