[Pkg-mozext-commits] [requestpolicy] 117/280: [refact] create WindowUtils

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 20db75964f2a6630be706f537cb4aa8b0fc3bb33
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Jan 6 11:24:33 2015 +0100

    [refact] create WindowUtils
    
    window utils in utils.jsm is now in utils/windows.jsm
---
 src/content/lib/http-response.jsm       |  4 +-
 src/content/lib/request.jsm             |  5 +-
 src/content/lib/utils.jsm               | 48 -------------------
 src/content/lib/utils/windows.jsm       | 85 +++++++++++++++++++++++++++++++++
 src/content/ui/request-log.filtering.js |  4 +-
 src/content/ui/request-log.js           |  4 +-
 6 files changed, 94 insertions(+), 56 deletions(-)

diff --git a/src/content/lib/http-response.jsm b/src/content/lib/http-response.jsm
index decb3f5..15878ac 100644
--- a/src/content/lib/http-response.jsm
+++ b/src/content/lib/http-response.jsm
@@ -36,7 +36,7 @@ Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
 ScriptLoader.importModules([
   "lib/logger",
   "lib/utils/domains",
-  "lib/utils"
+  "lib/utils/windows"
 ], this);
 
 
@@ -152,7 +152,7 @@ function getBrowser() {
     } else {
       // we hope the associated window is available. in multiprocessor
       // firefox it's not available.
-      return Utils.getBrowserForWindow(loadContext.topWindow);
+      return WindowUtils.getBrowserForWindow(loadContext.topWindow);
     }
   } catch (e) {
     Logger.warning(Logger.TYPE_HEADER_REDIRECT, "The redirection's " +
diff --git a/src/content/lib/request.jsm b/src/content/lib/request.jsm
index 3c1549a..5b8bb54 100644
--- a/src/content/lib/request.jsm
+++ b/src/content/lib/request.jsm
@@ -39,6 +39,7 @@ Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
 ScriptLoader.importModules([
   "lib/logger",
   "lib/utils/domains",
+  "lib/utils/windows",
   "lib/utils"
 ], this);
 
@@ -237,7 +238,7 @@ NormalRequest.prototype.getContentWindow = function() {
 NormalRequest.prototype.getChromeWindow = function() {
   let contentWindow = this.getContentWindow();
   if (!!contentWindow) {
-    return Utils.getChromeWindow(contentWindow);
+    return WindowUtils.getChromeWindow(contentWindow);
   } else {
     return null;
   }
@@ -251,7 +252,7 @@ NormalRequest.prototype.getBrowser = function() {
   if (context instanceof Ci.nsIDOMXULElement && context.tagName === "browser") {
     return context;
   } else {
-    return Utils.getBrowserForWindow(this.getContentWindow());
+    return WindowUtils.getBrowserForWindow(this.getContentWindow());
   }
 };
 
diff --git a/src/content/lib/utils.jsm b/src/content/lib/utils.jsm
index 22b8e1e..9a44c01 100644
--- a/src/content/lib/utils.jsm
+++ b/src/content/lib/utils.jsm
@@ -105,54 +105,6 @@ let Utils = (function() {
   self.info.isAustralis = self.info.isFirefox &&
       Services.vc.compare(Services.appinfo.platformVersion, '29') >= 0;
 
-  self.getChromeWindow = function(aContentWindow) {
-    return aContentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
-                             .getInterface(Ci.nsIWebNavigation)
-                             .QueryInterface(Ci.nsIDocShellTreeItem)
-                             .rootTreeItem
-                             .QueryInterface(Ci.nsIInterfaceRequestor)
-                             .getInterface(Ci.nsIDOMWindow);
-  };
-
-  self.getBrowserForWindow = function(aContentWindow) {
-    let win = self.getChromeWindow(aContentWindow);
-    let tab = win.gBrowser._getTabForContentWindow(aContentWindow.top);
-    return tab.linkedBrowser;
-  }
-
-  self.getChromeWindowForDocShell = function(aDocShell) {
-    return aDocShell.QueryInterface(Ci.nsIDocShellTreeItem)
-                    .rootTreeItem
-                    .QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIDOMWindow);
-  };
-
-
-  //
-  // DOM utilities
-  //
-
-  /**
-   * Wait for a window to be loaded and then add a list of Elements „by ID“ to
-   * a scope. The scope is optional, but in any case will be returned.
-   *
-   * @returns {Object} the scope of the elements
-   */
-  self.getElementsByIdOnLoad = function(aWindow, aElementIDs, aScope,
-                                        aCallback) {
-    let scope = aScope || {};
-    let document = aWindow.document;
-    aWindow.addEventListener("load", function() {
-      for (let elementName in aElementIDs) {
-        scope[elementName] = document.getElementById(aElementIDs[elementName]);
-      }
-      if (aCallback) {
-        aCallback();
-      }
-    });
-    return scope;
-  };
-
 
 
   /**
diff --git a/src/content/lib/utils/windows.jsm b/src/content/lib/utils/windows.jsm
new file mode 100644
index 0000000..52197a1
--- /dev/null
+++ b/src/content/lib/utils/windows.jsm
@@ -0,0 +1,85 @@
+/*
+ * ***** 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 *****
+ */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cu = Components.utils;
+
+let EXPORTED_SYMBOLS = ["WindowUtils"];
+
+
+
+
+let WindowUtils = (function() {
+  let self = {};
+
+  self.getChromeWindow = function(aContentWindow) {
+    return aContentWindow.top.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIWebNavigation)
+                             .QueryInterface(Ci.nsIDocShellTreeItem)
+                             .rootTreeItem
+                             .QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindow);
+  };
+
+  self.getBrowserForWindow = function(aContentWindow) {
+    let win = self.getChromeWindow(aContentWindow);
+    let tab = win.gBrowser._getTabForContentWindow(aContentWindow.top);
+    return tab.linkedBrowser;
+  }
+
+  self.getChromeWindowForDocShell = function(aDocShell) {
+    return aDocShell.QueryInterface(Ci.nsIDocShellTreeItem)
+                    .rootTreeItem
+                    .QueryInterface(Ci.nsIInterfaceRequestor)
+                    .getInterface(Ci.nsIDOMWindow);
+  };
+
+
+  //
+  // Window & DOM utilities
+  //
+
+  /**
+   * Wait for a window to be loaded and then add a list of Elements „by ID“ to
+   * a scope. The scope is optional, but in any case will be returned.
+   *
+   * @returns {Object} the scope of the elements
+   */
+  self.getElementsByIdOnLoad = function(aWindow, aElementIDs, aScope,
+                                        aCallback) {
+    let scope = aScope || {};
+    let document = aWindow.document;
+    aWindow.addEventListener("load", function() {
+      for (let elementName in aElementIDs) {
+        scope[elementName] = document.getElementById(aElementIDs[elementName]);
+      }
+      if (aCallback) {
+        aCallback();
+      }
+    });
+    return scope;
+  };
+
+  return self;
+}());
diff --git a/src/content/ui/request-log.filtering.js b/src/content/ui/request-log.filtering.js
index a665bbf..4ed3ba8 100644
--- a/src/content/ui/request-log.filtering.js
+++ b/src/content/ui/request-log.filtering.js
@@ -36,11 +36,11 @@ window.requestpolicy.requestLog = (function (self) {
     ScriptLoader = mod.ScriptLoader;
     Services = mod.Services;
   }
-  let {Utils} = ScriptLoader.importModule("lib/utils");
+  let {WindowUtils} = ScriptLoader.importModule("lib/utils/windows");
 
   let filterText = null;
 
-  let elements = Utils.getElementsByIdOnLoad(window, {
+  let elements = WindowUtils.getElementsByIdOnLoad(window, {
         filterTextbox: "requestpolicy-requestLog-requestFilter",
         clearFilterButton: "requestpolicy-requestLog-clearFilter"
       });
diff --git a/src/content/ui/request-log.js b/src/content/ui/request-log.js
index 2ef4643..b04e38b 100644
--- a/src/content/ui/request-log.js
+++ b/src/content/ui/request-log.js
@@ -36,7 +36,7 @@ window.requestpolicy.requestLog = (function (self) {
     ScriptLoader = mod.ScriptLoader;
   }
   let {StringUtils} = ScriptLoader.importModule("lib/utils/strings");
-  let {Utils} = ScriptLoader.importModule("lib/utils");
+  let {WindowUtils} = ScriptLoader.importModule("lib/utils/windows");
 
 
   self.isEmptyMessageDisplayed = true;
@@ -55,7 +55,7 @@ window.requestpolicy.requestLog = (function (self) {
     window.parent.requestpolicy.overlay.requestLog = self;
   }
 
-  Utils.getElementsByIdOnLoad(window, {
+  WindowUtils.getElementsByIdOnLoad(window, {
         tree: "requestpolicy-requestLog-tree"
       }, self, init);
 

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