[Pkg-mozext-commits] [requestpolicy] 54/100: [menu] show numRequests also for origin & otherOrigins

David Prévot taffit at moszumanska.debian.org
Fri Dec 12 22:56:58 UTC 2014


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

taffit pushed a commit to branch master
in repository requestpolicy.

commit 446e54bfae856edf1a01c12a8a1698ddfa90332e
Author: myrdd <myrdd at users.noreply.github.com>
Date:   Sat Oct 4 20:52:04 2014 +0200

    [menu] show numRequests also for origin & otherOrigins
    
    this feature is now complete
    
    also, now the flag will be shown in front of the origin(s)
    that flag is specific to that origin, so it might be that the "main"
    origin has no red flag, but an other origin.
    
    There is now a new file: GUILocation.jsm. It contains several classes
    which are used in menu.js. The "Destination" class has been renamed to
    "GUIDestination" which is now located in GUILocation.jsm.
---
 src/content/menu.js             | 280 +++++++++++++++++++++++-----------------
 src/content/overlay.xul         |   7 +-
 src/modules/GUILocation.jsm     | 264 +++++++++++++++++++++++++++++++++++++
 src/modules/PolicyManager.jsm   | 121 +----------------
 src/skin/requestpolicy.css      |  35 ++++-
 tests/html/other_origins_1.html |   5 +-
 6 files changed, 468 insertions(+), 244 deletions(-)

diff --git a/src/content/menu.js b/src/content/menu.js
index 4610121..cc3fb13 100644
--- a/src/content/menu.js
+++ b/src/content/menu.js
@@ -28,7 +28,7 @@ Components.utils.import("resource://requestpolicy/DomainUtil.jsm", rp.mod);
 Components.utils.import("resource://requestpolicy/Logger.jsm", rp.mod);
 Components.utils.import("resource://requestpolicy/Ruleset.jsm", rp.mod);
 Components.utils.import("resource://requestpolicy/RequestUtil.jsm", rp.mod);
-Components.utils.import("resource://requestpolicy/PolicyManager.jsm", rp.mod);
+Components.utils.import("resource://requestpolicy/GUILocation.jsm", rp.mod);
 
 requestpolicy.menu = {
 
@@ -40,6 +40,9 @@ requestpolicy.menu = {
   _menu : null,
 
   _originItem : null,
+  _originDomainnameItem : null,
+  _originNumRequestsItem : null,
+
   _otherOriginsList : null,
   _blockedDestinationsList : null,
   _mixedDestinationsList : null,
@@ -63,6 +66,9 @@ requestpolicy.menu = {
       this._menu = document.getElementById("rp-popup");
 
       this._originItem = document.getElementById("rp-origin");
+      this._originDomainnameItem = document.getElementById('rp-origin-domainname');
+      this._originNumRequestsItem = document.getElementById('rp-origin-num-requests');
+
       this._otherOriginsList = document.getElementById("rp-other-origins-list");
       this._blockedDestinationsList = document
             .getElementById("rp-blocked-destinations-list");
@@ -157,8 +163,12 @@ requestpolicy.menu = {
   },
 
   _populateMenuForUncontrollableOrigin : function() {
-    this._originItem.setAttribute('value',
+    this._originDomainnameItem.setAttribute('value',
         this._strbundle.getFormattedString('noOrigin', []));
+    this._originNumRequestsItem.setAttribute('value', '');
+    this._originItem.removeAttribute("default-policy");
+    this._originItem.removeAttribute("requests-blocked");
+
     this._removeChildren(this._otherOriginsList);
     this._removeChildren(this._blockedDestinationsList);
     this._removeChildren(this._mixedDestinationsList);
@@ -174,100 +184,140 @@ requestpolicy.menu = {
 
   _populateList : function(list, values) {
     this._removeChildren(list);
-    if (values[0] && values[0] instanceof rp.mod.Destination) {
+
+    // check whether there are objects of GUILocation or just strings
+    var guiLocations = values[0] && (values[0] instanceof rp.mod.GUILocation);
+
+    if (true === guiLocations) {
       // get prefs
       var sorting = this._rpService.prefs.getCharPref('menu.sorting');
-      var showNumRequests = this._rpService.prefs.getBoolPref('menu.info.showNumRequests')
+      var showNumRequests = this._rpService.prefs.
+          getBoolPref('menu.info.showNumRequests');
 
       if (sorting == "numRequests") {
-        values.sort(rp.mod.Destination.sortByNumRequestsCompareFunction);
+        values.sort(rp.mod.GUILocation.sortByNumRequestsCompareFunction);
       } else if (sorting == "destName") {
-        values.sort(rp.mod.Destination.compareFunction);
+        values.sort(rp.mod.GUILocation.compareFunction);
       }
 
       for (var i in values) {
-        var value = values[i];
+        var guiLocation = values[i];
+        var props = guiLocation.properties;
+
+        var num = undefined;
         if (true === showNumRequests) {
-          if (value.properties.numAllowedRequests > 0 && value.properties.numBlockedRequests > 0) {
-            var counters = value.properties.numRequests
-                + " (" + value.properties.numBlockedRequests
-                + "+" + value.properties.numAllowedRequests + ")";
-          } else {
-            var counters = value.properties.numRequests;
+          num = props.numRequests;
+          if (props.numAllowedRequests > 0 && props.numBlockedRequests > 0) {
+            num += " (" + props.numBlockedRequests +
+                "+" + props.numAllowedRequests + ")";
           }
-          var newitem = this._addListItem(list, 'rp-od-item', value.dest, counters);
-        } else {
-          var newitem = this._addListItem(list, 'rp-od-item', value.dest);
         }
+        var newitem = this._addListItem(list, 'rp-od-item', guiLocation, num);
+
         newitem.setAttribute("default-policy",
-                            (value.properties.numDefaultPolicyRequests > 0 ? "true" : "false"));
+            (props.numDefaultPolicyRequests > 0 ? "true" : "false"));
+        newitem.setAttribute("requests-blocked",
+            (props.numBlockedRequests > 0 ? "true" : "false"));
       }
     } else {
       values.sort();
       for (var i in values) {
-        var newitem = this._addListItem(list, 'rp-od-item', values[i]);
+        this._addListItem(list, 'rp-od-item', values[i]);
       }
     }
-    //this._disableIfNoChildren(list);
   },
 
   _populateOrigin : function() {
-    this._originItem.setAttribute('value', this._currentBaseDomain);
+    this._originDomainnameItem.setAttribute("value", this._currentBaseDomain);
+
+    var showNumRequests = this._rpService.prefs.
+        getBoolPref('menu.info.showNumRequests');
+
+    var props = this._getOriginGUILocationProperties();
+
+    var numRequests = '';
+    if (true === showNumRequests) {
+      if (props.numAllowedRequests > 0 && props.numBlockedRequests > 0) {
+        numRequests = props.numRequests + " (" +
+            props.numBlockedRequests + "+" + props.numAllowedRequests + ")";
+      } else {
+        numRequests = props.numRequests;
+      }
+    }
+    this._originNumRequestsItem.setAttribute("value", numRequests);
+
+    this._originItem.setAttribute("default-policy",
+        (props.numDefaultPolicyRequests > 0 ? "true" : "false"));
+    this._originItem.setAttribute("requests-blocked",
+        (props.numBlockedRequests > 0 ? "true" : "false"));
   },
 
   _populateOtherOrigins : function() {
-    var values = this._getOtherOrigins();
-    this._populateList(this._otherOriginsList, values);
-    document.getElementById('rp-other-origins').hidden = values.length == 0;
+    var guiOrigins = this._getOtherOriginsAsGUILocations();
+    this._populateList(this._otherOriginsList, guiOrigins);
+    document.getElementById('rp-other-origins').hidden = guiOrigins.length == 0;
   },
 
   _populateDestinations : function(originIdentifier) {
-    var rawBlocked = this._getBlockedDestinations();
-    var rawAllowed = this._getAllowedDestinations();
-    var blocked = [];
-    var mixed = [];
-    var allowed = [];
+    var destsWithBlockedRequests = this._getBlockedDestinationsAsGUILocations();
+    var destsWithAllowedRequests = this._getAllowedDestinationsAsGUILocations();
+
+    var destsWithSolelyBlockedRequests = [];
+    var destsMixed = [];
+    var destsWithSolelyAllowedRequests = [];
 
     // Set operations would be nice. These are small arrays, so keep it simple.
-    for (var i = 0; i < rawBlocked.length; i++) {
-      let dest = rawBlocked[i];
-      if (false === rp.mod.Destination.existsInArray(dest, rawAllowed)) {
-        blocked.push(dest);
+    for (var i = 0; i < destsWithBlockedRequests.length; i++) {
+      let blockedGUIDest = destsWithBlockedRequests[i];
+
+      if (false === rp.mod.GUILocation.existsInArray(blockedGUIDest,
+          destsWithAllowedRequests)) {
+        destsWithSolelyBlockedRequests.push(blockedGUIDest);
       } else {
-        // we assume that `dest` is a Destination getUriObject.
-        mixed.push(dest);
+        destsMixed.push(blockedGUIDest);
       }
     }
-    for (var i = 0; i < rawAllowed.length; i++) {
-      let dest = rawAllowed[i];
-      var indexRawBlocked = rp.mod.Destination.indexOfDestInArray(dest, rawBlocked);
-      var indexMixed = rp.mod.Destination.indexOfDestInArray(dest, mixed);
+    for (var i = 0; i < destsWithAllowedRequests.length; i++) {
+      let allowedGUIDest = destsWithAllowedRequests[i];
+
+      var indexRawBlocked = rp.mod.GUIDestination.
+          indexOfDestInArray(allowedGUIDest, destsWithBlockedRequests);
+      var destsMixedIndex = rp.mod.GUIDestination.
+          indexOfDestInArray(allowedGUIDest, destsMixed);
 
       if (indexRawBlocked == -1) {
-        allowed.push(dest);
+        destsWithSolelyAllowedRequests.push(allowedGUIDest);
       } else {
-        if (indexMixed != -1) {
+        if (destsMixedIndex != -1) {
           rp.mod.Logger.info(rp.mod.Logger.TYPE_INTERNAL,
-              "Merging dest: <" + dest.dest + ">");
-          mixed[indexMixed] = rp.mod.Destination.merge(dest, mixed[indexMixed]);
+              "Merging dest: <" + allowedGUIDest + ">");
+          destsMixed[destsMixedIndex] = rp.mod.GUIDestination.merge(
+              allowedGUIDest, destsMixed[destsMixedIndex]);
         } else {
-          // if the dest is in rawBlocked and rawAllowed, but not in mixed.
-          // this should never happen, the mixed destination should be added in the rawBlocked-loop.
-          rp.mod.Logger.warning(rp.mod.Logger.TYPE_INTERNAL,
-              "mixed dest was not added to `mixed` list: <" + dest.dest + ">");
-          mixed.push(dest);
+          // If the allowedGUIDest is in destsWithBlockedRequests and
+          // destsWithAllowedRequests, but not in destsMixed.
+          // This should never happen, the destsMixed destination should have
+          // been added in the destsWithBlockedRequests-loop.
+          rp.mod.Logger.warning(rp.mod.Logger.TYPE_INTERNAL, "mixed dest was" +
+              " not added to `destsMixed` list: <" + dest.dest + ">");
+          destsMixed.push(allowedGUIDest);
         }
       }
     }
 
-    this._populateList(this._blockedDestinationsList, blocked);
-    document.getElementById('rp-blocked-destinations').hidden = blocked.length == 0;
+    this._populateList(this._blockedDestinationsList,
+        destsWithSolelyBlockedRequests);
+    document.getElementById('rp-blocked-destinations').hidden =
+        destsWithSolelyBlockedRequests.length == 0;
 
-    this._populateList(this._mixedDestinationsList, mixed);
-    document.getElementById('rp-mixed-destinations').hidden = mixed.length == 0;
+    this._populateList(this._mixedDestinationsList, destsMixed);
+    document.getElementById('rp-mixed-destinations').hidden =
+        destsMixed.length == 0;
 
-    this._populateList(this._allowedDestinationsList, allowed);
-    document.getElementById('rp-allowed-destinations').hidden = allowed.length == 0;
+    this._populateList(this._allowedDestinationsList,
+        destsWithSolelyAllowedRequests);
+    document.getElementById('rp-allowed-destinations').hidden =
+        destsWithSolelyAllowedRequests.length == 0;
   },
 
   _populateDetails : function() {
@@ -446,7 +496,7 @@ requestpolicy.menu = {
   _activateOriginItem : function(item) {
     if (item.id == 'rp-origin') {
       // it's _the_ origin
-      this._currentlySelectedOrigin = item.value;
+      this._currentlySelectedOrigin = this._originDomainnameItem.value;
     } else if (item.parentNode.id == 'rp-other-origins-list') {
       // it's an otherOrigin
       this._currentlySelectedOrigin = item.getElementsByClassName("domainname")[0].value;
@@ -605,67 +655,21 @@ requestpolicy.menu = {
  // else there will be errors from within RequestUtil.
 
 
-
-  /* This function iterates through all requests of a destBase, looks for
-   * properties and returns them.
-   */
-  _extractRequestProperties : function(request, ruleAction) {
-    var properties = {
-      numRequests : 0,
-      numDefaultPolicyRequests : 0,
-      numAllowedRequests : 0,
-      numBlockedRequests : 0
-    };
-
-    var ruleActionCounter = 0;
-
-    for (var destIdent in request) {
-      for (var destUri in request[destIdent]) {
-        for (var i in request[destIdent][destUri]) {
-          ++properties.numRequests;
-          ++ruleActionCounter;
-          //rp.mod.Logger.dump("reason: "+ request[destIdent][destUri].resultReason
-          //    + " -- default: "+request[destIdent][destUri].isDefaultPolicyUsed());
-          if ( request[destIdent][destUri][i].isDefaultPolicyUsed() ) {
-            ++properties.numDefaultPolicyRequests;
-          }
-        }
-      }
-    }
-
-    switch (ruleAction) {
-      case rp.mod.RULE_ACTION_ALLOW:
-        properties.numAllowedRequests = ruleActionCounter;
-        break;
-
-      case rp.mod.RULE_ACTION_DENY:
-        properties.numBlockedRequests = ruleActionCounter;
-        break;
-
-      default:
-        break;
-    }
-
-    return properties;
-  },
-
-  _getBlockedDestinations : function() {
+  _getBlockedDestinationsAsGUILocations : function() {
     var reqSet = rp.mod.RequestUtil.getDeniedRequests(
           this._currentlySelectedOrigin, this._allRequestsOnDocument);
     var requests = reqSet.getAllMergedOrigins();
 
     var result = [];
     for (var destBase in requests) {
-      var properties = this._extractRequestProperties(requests[destBase],
-                                                      rp.mod.RULE_ACTION_DENY);
-      result.push(new rp.mod.Destination(destBase, properties));
-      //rp.mod.Logger.dump("destBase : "+destBase);
-      //rp.mod.Logger.vardump(properties, "properties");
+      var properties = new rp.mod.GUILocationProperties();
+      properties.accumulate(requests[destBase], rp.mod.RULE_ACTION_DENY);
+      result.push(new rp.mod.GUIDestination(destBase, properties));
     }
     return result;
   },
 
-  _getAllowedDestinations : function() {
+  _getAllowedDestinationsAsGUILocations : function() {
     var reqSet = rp.mod.RequestUtil.getAllowedRequests(
           this._currentlySelectedOrigin, this._allRequestsOnDocument);
     var requests = reqSet.getAllMergedOrigins();
@@ -682,21 +686,49 @@ requestpolicy.menu = {
         }
       }
 
-      var properties = this._extractRequestProperties(requests[destBase],
-                                                      rp.mod.RULE_ACTION_ALLOW);
-      result.push(new rp.mod.Destination(destBase, properties));
+      var properties = new rp.mod.GUILocationProperties();
+      properties.accumulate(requests[destBase], rp.mod.RULE_ACTION_ALLOW);
+      result.push(new rp.mod.GUIDestination(destBase, properties));
     }
     return result;
   },
 
-  _getOtherOrigins : function() {
-    var requests = this._allRequestsOnDocument.getAll();
+  /**
+   * TODO: optimize this for performance (_getOriginGUILocationProperties and
+   * _getOtherOriginsAsGUILocations could be merged.)
+   *
+   * @return {GUILocationProperties}
+   *         the properties of the "main" origin (the one in the location bar).
+   */
+  _getOriginGUILocationProperties : function() {
+    var allRequests = this._allRequestsOnDocument.getAll();
 
     var allowSameDomain = this._rpService.isDefaultAllow() ||
           this._rpService.isDefaultAllowSameDomain();
 
-    var result = [];
-    for (var originUri in requests) {
+    var properties = new rp.mod.GUILocationProperties();
+
+    for (var originUri in allRequests) {
+      var originBase = rp.mod.DomainUtil.getDomain(originUri);
+      if (originBase != this._currentBaseDomain) {
+        continue;
+      }
+
+      for (var destBase in allRequests[originUri]) {
+        properties.accumulate(allRequests[originUri][destBase]);
+      }
+    }
+    return properties;
+  },
+
+  _getOtherOriginsAsGUILocations : function() {
+    var allRequests = this._allRequestsOnDocument.getAll();
+
+    var allowSameDomain = this._rpService.isDefaultAllow() ||
+          this._rpService.isDefaultAllowSameDomain();
+
+    var guiOrigins = [];
+    for (var originUri in allRequests) {
       var originBase = rp.mod.DomainUtil.getDomain(originUri);
       if (originBase == this._currentBaseDomain) {
         continue;
@@ -710,25 +742,35 @@ requestpolicy.menu = {
       //  continue;
       //}
 
-      for (var destBase in requests[originUri]) {
+      var guiOriginsIndex = rp.mod.GUIOrigin.indexOfOriginInArray(originBase,
+          guiOrigins);
+      var properties;
+      if (guiOriginsIndex == -1) {
+        properties = new rp.mod.GUILocationProperties();
+      } else {
+        properties = guiOrigins[guiOriginsIndex].properties;
+      }
+
+      for (var destBase in allRequests[originUri]) {
         // Search for a destBase which wouldn't be allowed by the default policy.
         // TODO: some users might want to know those "other origins" as well.
         //       this should be made possible.
 
         // For everybody except users with default deny who are not allowing all
-        // requests to the same domain:
+        // guiOrigins to the same domain:
         // Only list other origins where there is a destination from that origin
         // that is at a different domain, not just a different subdomain.
         if (allowSameDomain && destBase == originBase) {
           continue;
         }
-        if (result.indexOf(originBase) == -1) {
-          result.push(originBase);
-          break;
-        }
+        properties.accumulate(allRequests[originUri][destBase]);
+      }
+
+      if (guiOriginsIndex == -1) {
+        guiOrigins.push(new rp.mod.GUIOrigin(originBase, properties));
       }
     }
-    return result;
+    return guiOrigins;
   },
 
   _sanitizeJsFunctionArg : function(str) {
diff --git a/src/content/overlay.xul b/src/content/overlay.xul
index 5030c84..384a29c 100644
--- a/src/content/overlay.xul
+++ b/src/content/overlay.xul
@@ -73,8 +73,11 @@
       <vbox id="rp-contents">
         <hbox id="rp-main">
           <vbox id="rp-origins-destinations">
-            <label id="rp-origin" class="rp-od-item"
-                   onclick="requestpolicy.menu.itemSelected(event);"/>
+            <hbox id="rp-origin" class="rp-od-item"
+                  onclick="requestpolicy.menu.itemSelected(event);">
+              <label id="rp-origin-domainname" class="domainname" flex="2" />
+              <label id="rp-origin-num-requests" class="numRequests" />
+            </hbox>
             <vbox id="rp-other-origins">
               <label id="rp-other-origins-title" value="&rp.menu.otherOrigins;" />
               <vbox id="rp-other-origins-list" class="rp-label-list" />
diff --git a/src/modules/GUILocation.jsm b/src/modules/GUILocation.jsm
new file mode 100644
index 0000000..c1c70d5
--- /dev/null
+++ b/src/modules/GUILocation.jsm
@@ -0,0 +1,264 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2011 Justin Samuel
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+var EXPORTED_SYMBOLS = [
+  "GUILocation",
+  "GUIOrigin",
+  "GUIDestination",
+  "GUILocationProperties"
+];
+
+
+if (!rp) {
+  var rp = {mod : {}};
+}
+
+Components.utils.import("resource://requestpolicy/Ruleset.jsm", rp.mod);
+
+
+
+
+function GUILocation(value, properties) {
+  this.value = value || null;
+  this.properties = properties || null;
+}
+
+GUILocation.prototype.toString = function() {
+  return this.value;
+}
+
+/**
+ * @static
+ */
+GUILocation.merge = function (guiLocation, location1, location2) {
+  return new guiLocation(
+    location1.value,  // we assume: location1.value == location2.value
+    GUILocationProperties.merge(location1.properties, location2.properties));
+};
+
+/**
+ * @static
+ */
+GUILocation.existsInArray = function (locationString, locations) {
+  return (GUILocation.indexOfLocationInArray(locationString, locations) != -1);
+};
+
+/**
+ * @static
+ * @param {String}
+ *          locationString The location saved in GUILocation.value
+ * @param {String}
+ *          locations Array of GUILocation objects
+ * @return {int} The index of the first GUILocation object which contains the
+ *          specified locationString. If it doesn't exist, it returns -1.
+ */
+GUILocation.indexOfLocationInArray = function (locationString, locations) {
+  if (locationString instanceof GUILocation) {
+    locationString = locationString.value;
+  }
+  for (var i in locations) {
+    if (locations[i].value == locationString) {
+      return i;
+    }
+  }
+  return -1;
+};
+
+/**
+ * compare functions used to sort an Array of GUIDestination objects.
+ *
+ * @static
+ */
+GUILocation.sortByNumRequestsCompareFunction = function (a, b) {
+  return GUIDestination.compareFunction(a, b, "sortByNumRequests");
+};
+GUILocation.compareFunction = function (a, b, sortType) {
+  var a_default = (a.properties.numDefaultPolicyRequests > 0);
+  var b_default = (b.properties.numDefaultPolicyRequests > 0);
+
+  if (a_default !== b_default) {
+    if (a_default === true) {
+      // default-policy destinations first.
+      return -1;
+    } else {
+      return 1
+    }
+  }
+
+  if (sortType == "sortByNumRequests") {
+    if (a.properties.numRequests > b.properties.numRequests) {
+      return -1;
+    }
+    if (a.properties.numRequests < b.properties.numRequests) {
+      return 1;
+    }
+  }
+
+
+  if (a.value > b.value) {
+    return 1;
+  }
+  if (a.value < b.value) {
+    return -1;
+  }
+  return 0;
+};
+
+
+
+
+
+/**
+ * GUIOrigin objects are used to hand over not only "origin" strings, like
+ * "example.com", but also properties which might be useful to display more
+ * information on the GUI.
+ */
+function GUIOrigin(origin, properties) {
+  GUILocation.call(this, origin, properties);
+}
+GUIOrigin.prototype = new GUILocation;
+
+/**
+ * @static
+ */
+GUIOrigin.merge = function (origin1, origin2) {
+  return GUILocation.merge(GUIOrigin, origin1, origin2);
+};
+
+GUIOrigin.indexOfOriginInArray = GUILocation.indexOfLocationInArray;
+
+
+
+
+
+/**
+ * GUIDestination objects are used to hand over not only "destination" strings,
+ * like "example.com", but also properties which might be useful to display more
+ * information on the GUI.
+ */
+function GUIDestination(dest, properties) {
+  GUILocation.call(this, dest, properties);
+}
+GUIDestination.prototype = new GUILocation;
+
+/**
+ * @static
+ */
+GUIDestination.merge = function (dest1, dest2) {
+  return GUILocation.merge(GUIDestination, dest1, dest2);
+};
+
+GUIDestination.indexOfDestInArray = GUILocation.indexOfLocationInArray;
+
+
+
+
+
+
+function GUILocationProperties(value, properties) {
+  this.reset();
+}
+
+GUILocationProperties.prototype.reset = function() {
+  this.numRequests = 0;
+  this.numDefaultPolicyRequests = 0;
+  this.numAllowedRequests = 0;
+  this.numBlockedRequests = 0;
+};
+
+/**
+  * This function iterates through all requests of a destBase (or originBase),
+  * looks for properties and returns them.
+  *
+  * @param {Array} requests
+  *        the [originBase|destBase] multidimensional array.
+  * @param {boolean} ruleAction
+  *        (optional) If specified, all requests will be counted as a request
+  *        with the specified rule action without being checked.
+  *        Otherwise the ruleAction will be checked for every single request.
+  */
+GUILocationProperties.prototype.accumulate = function (requests,
+    ruleAction) {
+  var extractRuleActions = (undefined === ruleAction);
+  var ruleActionCounter = 0;
+
+  for (var destIdent in requests) {
+    for (var destUri in requests[destIdent]) {
+      for (var i in requests[destIdent][destUri]) {
+        ++this.numRequests;
+
+        // depending on ruleAction:
+        if (!extractRuleActions) {
+          ++ruleActionCounter;
+        } else if (requests[destIdent][destUri][i].isAllowed) {
+          ++this.numAllowedRequests;
+        } else {
+          ++this.numBlockedRequests;
+        }
+
+        if ( requests[destIdent][destUri][i].isDefaultPolicyUsed() ) {
+          ++this.numDefaultPolicyRequests;
+        }
+      }
+    }
+  }
+
+  switch (ruleAction) {
+    case rp.mod.RULE_ACTION_ALLOW:
+      this.numAllowedRequests += ruleActionCounter;
+      break;
+
+    case rp.mod.RULE_ACTION_DENY:
+      this.numBlockedRequests += ruleActionCounter;
+      break;
+
+    default:
+      break;
+  }
+};
+
+/**
+ * @static
+ */
+GUILocationProperties.requestCountProperties = [
+  "numRequests",
+  "numDefaultPolicyRequests",
+  "numBlockedRequests",
+  "numAllowedRequests"
+];
+
+/**
+ * @static
+ *
+ * Merge the given GUILocationProperties object to a new object
+ */
+GUILocationProperties.merge = function (prop1, prop2) {
+  var requestCountProperties = GUILocationProperties.requestCountProperties;
+  var newObj = new GUILocationProperties();
+
+  for (var i in requestCountProperties) {
+    var propertyName = requestCountProperties[i];
+    newObj[propertyName] += prop1[propertyName] + prop2[propertyName];
+  }
+
+  return newObj;
+};
diff --git a/src/modules/PolicyManager.jsm b/src/modules/PolicyManager.jsm
index 9d50157..40abb1c 100644
--- a/src/modules/PolicyManager.jsm
+++ b/src/modules/PolicyManager.jsm
@@ -22,8 +22,7 @@
 
 var EXPORTED_SYMBOLS = [
   "PolicyManager",
-  "RULES_CHANGED_TOPIC",
-  "Destination"
+  "RULES_CHANGED_TOPIC"
 ];
 
 const CI = Components.interfaces;
@@ -76,124 +75,6 @@ function notifyRulesChanged() {
 
 
 
-/**
- * Destination objects are used to hand over not only "destination" strings, like
- * "example.com", but also properties which might be useful to display more
- * information on the GUI.
- */
-function Destination(dest, properties) {
-  this.dest = dest;
-
-  if (properties != undefined) {
-    this.properties = properties;
-  } else {
-    this.properties = [];
-  }
-}
-Destination.prototype = {
-  dest : null,
-  properties : null
-};
-
-/**
- * @static
- */
-Destination.merge = function (dest1, dest2) {
-  // we assume: dest1.dest == dest2.dest
-  var dest = new Destination(dest1.dest);
-  dest.properties = {};
-
-  var destCounterProperties = [
-    "numRequests",
-    "numDefaultPolicyRequests",
-    "numBlockedRequests",
-    "numAllowedRequests"
-  ];
-
-  for (var i in destCounterProperties) {
-    var p = destCounterProperties[i];
-    dest.properties[p] = 0;
-
-    if (dest1.properties[p]) {
-      dest.properties[p] += dest1.properties[p];
-    }
-    if (dest2.properties[p]) {
-      dest.properties[p] += dest2.properties[p];
-    }
-  }
-
-  return dest;
-}
-
-/**
- * @static
- */
-Destination.existsInArray = function (destString, dests) {
-  return (Destination.indexOfDestInArray(destString, dests) != -1);
-}
-
-/**
- * @static
- * @param {String}
- *          destString The destination saved in Destination.dest
- * @param {String}
- *          dests Array of Destination objects
- * @return {int} The index of the first Destination object which contains the
- *          specified destString. If it doesn't exist, it returns -1.
- */
-Destination.indexOfDestInArray = function (destString, dests) {
-  if (destString instanceof Destination) {
-    destString = destString.dest;
-  }
-  for (var i in dests) {
-    if (dests[i].dest == destString) {
-      return i;
-    }
-  }
-  return -1;
-}
-
-/**
- * compare functions used to sort an Array of Destination objects.
- *
- * @static
- */
-Destination.sortByNumRequestsCompareFunction = function (a, b) {
-  return Destination.compareFunction(a, b, "sortByNumRequests");
-}
-Destination.compareFunction = function (a, b, sortType) {
-  var a_default = (a.properties.numDefaultPolicyRequests > 0);
-  var b_default = (b.properties.numDefaultPolicyRequests > 0);
-
-  if (a_default !== b_default) {
-    if (a_default === true) {
-      // default-policy destinations first.
-      return -1;
-    } else {
-      return 1
-    }
-  }
-
-  if (sortType == "sortByNumRequests") {
-    if (a.properties.numRequests > b.properties.numRequests) {
-      return -1;
-    }
-    if (a.properties.numRequests < b.properties.numRequests) {
-      return 1;
-    }
-  }
-
-
-  if (a.dest > b.dest) {
-    return 1;
-  }
-  if (a.dest < b.dest) {
-    return -1;
-  }
-  return 0;
-}
-
-
 
 /**
  * Provides a simplified interface to handling multiple
diff --git a/src/skin/requestpolicy.css b/src/skin/requestpolicy.css
index 3701b2d..8952014 100644
--- a/src/skin/requestpolicy.css
+++ b/src/skin/requestpolicy.css
@@ -234,11 +234,29 @@ toolbar[iconsize="small"] #requestpolicyToolbarButton[requestpolicyPermissive="t
   margin-bottom: 14px;
 }
 
-#rp-origin {
+#rp-origin #rp-origin-domainname {
   font-size: 1.2em;
   color : #555;
   padding-right: 10px;
 }
+#rp-origin #rp-origin-num-requests {
+  font-size: 1.2em;
+  color: #777;
+}
+#rp-origin[requests-blocked="true"] {
+  background-image:
+    url(chrome://requestpolicy/skin/requestpolicy-icon-blocked.png);
+}
+#rp-origin[requests-blocked="false"] {
+  background-image:
+    url(chrome://requestpolicy/skin/requestpolicy-icon-allowed.png);
+}
+#rp-origin[requests-blocked] {
+  background-position: left center;
+  background-repeat: no-repeat;
+  background-size: 14px 14px;
+  padding-left: 20px;
+}
 
 .rp-label-list {
   /*margin-left : 10px;*/
@@ -249,6 +267,21 @@ toolbar[iconsize="small"] #requestpolicyToolbarButton[requestpolicyPermissive="t
   padding-bottom: 1em;
   border-bottom: 1px solid #eee;
 }
+#rp-other-origins [requests-blocked="true"] {
+  background-image:
+    url(chrome://requestpolicy/skin/requestpolicy-icon-blocked.png);
+}
+#rp-other-origins [requests-blocked="false"] {
+  background-image:
+    url(chrome://requestpolicy/skin/requestpolicy-icon-allowed.png);
+}
+#rp-other-origins [requests-blocked] {
+  background-position: left center;
+  background-repeat: no-repeat;
+  background-size: 14px 14px;
+  padding-left: 20px;
+}
+
 #rp-other-origins-title {
   color: #aaa;
 }
diff --git a/tests/html/other_origins_1.html b/tests/html/other_origins_1.html
index e6e2550..fe564e1 100644
--- a/tests/html/other_origins_1.html
+++ b/tests/html/other_origins_1.html
@@ -3,7 +3,8 @@
 </head>
 <body>
 
-<iframe src="http://www.otherdomain.test/iframe-to-other-site.html"></iframe>
+<iframe src="http://www.thirddomain.test/iframe_1.html"
+    width="600" height="300"></iframe>
 
 </body>
-</html>
\ No newline at end of file
+</html>

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