[Pkg-mozext-commits] [requestpolicy] 55/280: [refact] requestLog: coding style changes
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:29:59 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 9915d8c1c8052c7ac750032cf788e1bb082d4451
Author: Martin Kimmerle <dev at 256k.de>
Date: Mon Dec 8 01:33:14 2014 +0100
[refact] requestLog: coding style changes
---
src/content/ui/overlay.js | 14 +-
src/content/ui/request-log-tree-view.js | 189 ++++++---------------
.../{request-log.js => request-log.interface.js} | 72 +++++---
src/content/ui/request-log.js | 74 +++-----
src/content/ui/request-log.xul | 3 +-
5 files changed, 133 insertions(+), 219 deletions(-)
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index eb3d4b2..bb4cc6d 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -85,7 +85,7 @@ requestpolicy.overlay = (function() {
let self = {
// This is set by request-log.js when it is initialized. We don't need to worry
// about setting it here.
- requestLogTreeView : null
+ requestLog: null
};
@@ -617,8 +617,8 @@ requestpolicy.overlay = (function() {
* destUri
*/
self.observeAllowedRequest = function(originUri, destUri) {
- if (self.requestLogTreeView) {
- self.requestLogTreeView.addAllowedRequest(originUri, destUri);
+ if (self.requestLog) {
+ self.requestLog.addAllowedRequest(originUri, destUri);
}
};
@@ -634,8 +634,8 @@ requestpolicy.overlay = (function() {
*/
self.observeBlockedRequest = function(originUri, destUri) {
self._updateNotificationDueToBlockedContent();
- if (self.requestLogTreeView) {
- self.requestLogTreeView.addBlockedRequest(originUri, destUri);
+ if (self.requestLog) {
+ self.requestLog.addBlockedRequest(originUri, destUri);
}
};
@@ -1223,7 +1223,7 @@ requestpolicy.overlay = (function() {
self.clearRequestLog = function() {
- self.requestLogTreeView.clear();
+ self.requestLog.clear();
};
self.toggleRequestLog = function() {
@@ -1246,7 +1246,7 @@ requestpolicy.overlay = (function() {
requestLogFrame.setAttribute("src", "about:blank");
requestLog.hidden = requestLogSplitter.hidden = closeRequestLog.hidden = true;
//openRequestLog.hidden = false;
- self.requestLogTreeView = null;
+ self.requestLog = null;
}
};
diff --git a/src/content/ui/request-log-tree-view.js b/src/content/ui/request-log-tree-view.js
index c5a0d2b..7369554 100644
--- a/src/content/ui/request-log-tree-view.js
+++ b/src/content/ui/request-log-tree-view.js
@@ -21,11 +21,9 @@
* ***** END LICENSE BLOCK *****
*/
-if (!window.requestpolicy) {
- window.requestpolicy = {};
-}
+window.requestpolicy = window.requestpolicy || {};
-window.requestpolicy.requestLogTreeView = (function () {
+window.requestpolicy.requestLog = (function (self) {
const Ci = Components.interfaces;
const Cc = Components.classes;
@@ -38,206 +36,129 @@ window.requestpolicy.requestLogTreeView = (function () {
- let self = {
- _treebox : null,
+ self.treebox = null;
- _emptyMessageDisplayed : true,
-
- _visibleData : [],
-
- _columnNameToIndexMap : {
- "requestpolicy-requestLog-origin" : 0,
- "requestpolicy-requestLog-destination" : 1,
- "requestpolicy-requestLog-blocked" : 2,
- "requestpolicy-requestLog-time" : 3
- },
-
- _aserv : Components.classes["@mozilla.org/atom-service;1"]
- .getService(Components.interfaces.nsIAtomService),
-
- init : function(e) {
- var message = StringUtils.strbundle.GetStringFromName("requestLogIsEmpty");
- var directions = StringUtils.strbundle
- .GetStringFromName("requestLogDirections");
- self._visibleData.push([message, directions, false, ""]);
- },
-
- clear : function(e) {
- var count = self.rowCount;
- if (count == 0) {
- return;
- }
- self._visibleData = [];
- if (!self._treebox) {
- return;
- }
- self._treebox.rowCountChanged(0, -count);
- },
+ self.columnNameToIndexMap = {
+ "requestpolicy-requestLog-origin" : 0,
+ "requestpolicy-requestLog-destination" : 1,
+ "requestpolicy-requestLog-blocked" : 2,
+ "requestpolicy-requestLog-time" : 3
+ };
- addAllowedRequest : function(originUri, destUri) {
- if (self._emptyMessageDisplayed) {
- // If this were to be called in a multithreaded manner, there's probably
- // a race condition here.
- self._visibleData.shift();
- self._emptyMessageDisplayed = false;
- self._treebox.rowCountChanged(0, -1);
- }
- self._visibleData.push([
- originUri,
- destUri,
- false,
- (new Date()).toLocaleTimeString()
- ]);
- if (!self._treebox) {
- return;
- }
- self._treebox.rowCountChanged(0, 1);
- },
+ let aserv = Cc["@mozilla.org/atom-service;1"].getService(Ci.nsIAtomService);
- addBlockedRequest : function(originUri, destUri) {
- if (self._emptyMessageDisplayed) {
- // If this were to be called in a multithreaded manner, there's probably
- // a race condition here.
- self._visibleData.shift();
- self._emptyMessageDisplayed = false;
- self._treebox.rowCountChanged(0, -1);
- }
- self._visibleData.push([
- originUri,
- destUri,
- true,
- (new Date()).toLocaleTimeString()
- ]);
- if (!self._treebox) {
- return;
- }
- self._treebox.rowCountChanged(0, 1);
- },
- _getVisibleItemAtIndex : function(index) {
- return self._visibleData[self._visibleData.length - index - 1];
- },
+ function getVisibleItemAtIndex(index) {
+ return self.visibleData[self.visibleData.length - index - 1];
+ };
- // Start of interface.
- // see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Tutorial/Custom_Tree_Views
+ // the interface.
+ // see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Tutorial/Custom_Tree_Views
+ self.treeView = {
/**
* "This property should be set to the total number of rows in the tree."
* (getter function)
*/
- get rowCount () {
- return self._visibleData.length;
+ get: function() {
+ return self.visibleData.length;
},
/**
* "This method should return the text contents at the specified row and
* column."
*/
- setTree : function(_treebox) {
- self._treebox = _treebox;
+ setTree: function(_treebox) {
+ self.treebox = _treebox;
},
/**
* This method is called once to set the tree element on the view.
*/
- getCellText : function(index, column) {
+ getCellText: function(index, column) {
// Row 0 is actually the last element in the array so that we don't have to
// unshift() the array and can just push().
// TODO: Do an actual speed test with push vs. unshift to see if it matters
// with this javascript array implementation, though I'm assuming it does.
- var columnIndex = self._columnNameToIndexMap[column.id];
+ var columnIndex = self.columnNameToIndexMap[column.id];
if (columnIndex != 2) {
- return self._getVisibleItemAtIndex(index)[self._columnNameToIndexMap[column.id]];
+ return getVisibleItemAtIndex(index)[self.columnNameToIndexMap[column.id]];
}
},
- isContainer : function(index) {
+ isContainer: function(index) {
return false;
},
- isContainerOpen : function(index) {
+ isContainerOpen: function(index) {
return false;
},
- isContainerEmpty : function(index) {
+ isContainerEmpty: function(index) {
return false;
},
- isSeparator : function(index) {
+ isSeparator: function(index) {
return false;
},
- isSorted : function() {
+ isSorted: function() {
return false;
},
- isEditable : function(index, column) {
+ isEditable: function(index, column) {
return false;
},
- getParentIndex : function(index) {
+ getParentIndex: function(index) {
return -1;
},
- getLevel : function(index) {
+ getLevel: function(index) {
return 0;
},
- hasNextSibling : function(index, after) {
+ hasNextSibling: function(index, after) {
return false;
},
- toggleOpenState : function(index) {
- },
+ toggleOpenState: function(index) {},
- getImageSrc : function(index, column) {
- if (self._columnNameToIndexMap[column.id] == 2) {
- if (self._getVisibleItemAtIndex(index)[2]) {
+ getImageSrc: function(index, column) {
+ if (self.columnNameToIndexMap[column.id] == 2) {
+ if (getVisibleItemAtIndex(index)[2]) {
return "chrome://requestpolicy/skin/dot.png";
}
}
},
- getProgressMode : function(index, column) {
- },
+ getProgressMode: function(index, column) {},
+ getCellValue: function(index, column) {},
+ cycleHeader: function(col, elem) {},
+ selectionChanged: function() {},
+ cycleCell: function(index, column) {},
+ performAction: function(action) {},
+ performActionOnCell: function(action, index, column) {},
- getCellValue : function(index, column) {
- },
-
- cycleHeader : function(col, elem) {
- },
-
- selectionChanged : function() {
- },
-
- cycleCell : function(index, column) {
- },
-
- performAction : function(action) {
- },
-
- performActionOnCell : function(action, index, column) {
- },
-
- getRowProperties : function(index, props) {
- var returnValue = (self._getVisibleItemAtIndex(index)[2]) ? "blocked" : "allowed";
+ getRowProperties: function(index, props) {
+ var returnValue = (getVisibleItemAtIndex(index)[2]) ? "blocked" : "allowed";
if (props) {
// Gecko version < 22
- props.AppendElement(self._aserv.getAtom(returnValue));
+ props.AppendElement(aserv.getAtom(returnValue));
} else {
// Gecko version >= 22
return returnValue;
}
},
- getCellProperties : function(index, column, props) {
- if (self._columnNameToIndexMap[column.id] == 2) {
- if (self._getVisibleItemAtIndex(index)[2]) {
+ getCellProperties: function(index, column, props) {
+ if (self.columnNameToIndexMap[column.id] == 2) {
+ if (getVisibleItemAtIndex(index)[2]) {
if (props) {
// Gecko version < 22
- props.AppendElement(self._aserv.getAtom("blocked"));
+ props.AppendElement(aserv.getAtom("blocked"));
} else {
// Gecko version >= 22
return "blocked";
@@ -246,17 +167,13 @@ window.requestpolicy.requestLogTreeView = (function () {
}
},
- getColumnProperties : function(column, props) {
+ getColumnProperties: function(column, props) {
if (!props) {
return "";
}
}
-
};
+
return self;
-}());
+}(window.requestpolicy.requestLog || {}));
-// Initialize when the window DOM is loaded.
-addEventListener("load", function(event) {
- window.requestpolicy.requestLogTreeView.init();
-}, false);
diff --git a/src/content/ui/request-log.js b/src/content/ui/request-log.interface.js
similarity index 62%
copy from src/content/ui/request-log.js
copy to src/content/ui/request-log.interface.js
index ebf9cf9..180bb39 100644
--- a/src/content/ui/request-log.js
+++ b/src/content/ui/request-log.interface.js
@@ -21,6 +21,7 @@
* ***** END LICENSE BLOCK *****
*/
+window.requestpolicy = window.requestpolicy || {};
window.requestpolicy.requestLog = (function (self) {
@@ -32,29 +33,26 @@ window.requestpolicy.requestLog = (function (self) {
Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm", mod);
Cu.import("resource://gre/modules/Services.jsm", mod);
mod.ScriptLoader.importModules([
+ "string-utils",
"domain-util",
- "string-utils"
+ "utils"
], mod);
- let Services = mod.Services, DomainUtil = mod.DomainUtil,
- StringUtils = mod.StringUtils;
+ let Services = mod.Services, StringUtils = mod.StringUtils,
+ DomainUtil = mod.DomainUtil, Utils = mod.Utils;
- let initialized = false;
- let tree = null;
-
- self.init = function() {
- if (initialized) {
+ self.clear = function(e) {
+ var count = self.rowCount;
+ if (count == 0) {
return;
}
- initialized = true;
-
- tree = document.getElementById("requestpolicy-requestLog-tree");
- tree.view = window.requestpolicy.requestLogTreeView;
-
- // Give the requestpolicyOverlay direct access to the tree view.
- window.parent.requestpolicy.overlay.requestLogTreeView = window.requestpolicy.requestLogTreeView;
+ self.visibleData = [];
+ if (!self.treebox) {
+ return;
+ }
+ self.treebox.rowCountChanged(0, -count);
};
/**
@@ -62,8 +60,8 @@ window.requestpolicy.requestLog = (function (self) {
* selected when the context menu was opened.
*/
self.copyToClipboard = function(columnName) {
- var content = tree.view.getCellText(tree.currentIndex,
- tree.columns.getNamedColumn(columnName));
+ var content = self.treeView.getCellText(self.tree.currentIndex,
+ self.tree.columns.getNamedColumn(columnName));
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
@@ -75,8 +73,8 @@ window.requestpolicy.requestLog = (function (self) {
* selected when the context menu was opened.
*/
self.openInNewTab = function(columnName) {
- var content = tree.view.getCellText(tree.currentIndex,
- tree.columns.getNamedColumn(columnName));
+ var content = self.treeView.getCellText(self.tree.currentIndex,
+ self.tree.columns.getNamedColumn(columnName));
var forbidden = true;
try {
@@ -95,12 +93,38 @@ window.requestpolicy.requestLog = (function (self) {
return;
}
- Utils.getChromeWindow(window).gBrowser.addTab(content);
+ window.top.openUILinkIn(content, "tab", {relatedToCurrent: true});
};
+
+
+
+ function addRequest(request) {
+ if (self.isEmptyMessageDisplayed) {
+ // If this were to be called in a multithreaded manner, there's probably
+ // a race condition here.
+ self.visibleData.shift();
+ self.isEmptyMessageDisplayed = false;
+ self.treebox.rowCountChanged(0, -1);
+ }
+ self.visibleData.push(request);
+
+ if (!self.treebox) {
+ return;
+ }
+
+ self.treebox.rowCountChanged(0, 1);
+ }
+
+ self.addAllowedRequest = function(originURI, destURI) {
+ addRequest([originURI, destURI, false, (new Date()).toLocaleTimeString()]);
+ };
+
+ self.addBlockedRequest = function(originURI, destURI) {
+ addRequest([originURI, destURI, true, (new Date()).toLocaleTimeString()]);
+ };
+
+
+
return self;
}(window.requestpolicy.requestLog || {}));
-
-addEventListener("load", function(event) {
- window.requestpolicy.requestLog.init(event);
-}, false);
diff --git a/src/content/ui/request-log.js b/src/content/ui/request-log.js
index ebf9cf9..fe59c64 100644
--- a/src/content/ui/request-log.js
+++ b/src/content/ui/request-log.js
@@ -21,6 +21,7 @@
* ***** END LICENSE BLOCK *****
*/
+window.requestpolicy = window.requestpolicy || {};
window.requestpolicy.requestLog = (function (self) {
@@ -30,77 +31,48 @@ window.requestpolicy.requestLog = (function (self) {
let mod = {};
Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm", mod);
- Cu.import("resource://gre/modules/Services.jsm", mod);
mod.ScriptLoader.importModules([
- "domain-util",
"string-utils"
], mod);
- let Services = mod.Services, DomainUtil = mod.DomainUtil,
- StringUtils = mod.StringUtils;
+ let StringUtils = mod.StringUtils;
let initialized = false;
- let tree = null;
+ self.isEmptyMessageDisplayed = true;
+ self.tree = null;
+ self.visibleData = [];
- self.init = function() {
+
+ function showLogIsEmptyMessage() {
+ var message = StringUtils.strbundle.GetStringFromName("requestLogIsEmpty");
+ var directions = StringUtils.strbundle
+ .GetStringFromName("requestLogDirections");
+ self.visibleData.push([message, directions, false, ""]);
+ };
+
+
+ function init() {
if (initialized) {
return;
}
initialized = true;
- tree = document.getElementById("requestpolicy-requestLog-tree");
- tree.view = window.requestpolicy.requestLogTreeView;
+ self.tree = document.getElementById("requestpolicy-requestLog-tree");
+ self.tree.view = self.treeView;
- // Give the requestpolicyOverlay direct access to the tree view.
- window.parent.requestpolicy.overlay.requestLogTreeView = window.requestpolicy.requestLogTreeView;
- };
+ // Give the requestpolicy overlay direct access to the the request log.
+ window.parent.requestpolicy.overlay.requestLog = self;
- /**
- * Copy the content of a cell to the clipboard. The row used will be the one
- * selected when the context menu was opened.
- */
- self.copyToClipboard = function(columnName) {
- var content = tree.view.getCellText(tree.currentIndex,
- tree.columns.getNamedColumn(columnName));
-
- const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
- .getService(Components.interfaces.nsIClipboardHelper);
- clipboardHelper.copyString(content);
+ showLogIsEmptyMessage();
};
- /**
- * Open the content of a cell in a new tab. The row used will be the one
- * selected when the context menu was opened.
- */
- self.openInNewTab = function(columnName) {
- var content = tree.view.getCellText(tree.currentIndex,
- tree.columns.getNamedColumn(columnName));
-
- var forbidden = true;
- try {
- var uri = DomainUtil.getUriObject(content);
- if (uri.scheme == 'http' || uri.scheme == 'https' || uri.scheme == 'ftp') {
- forbidden = false;
- }
- } catch (e) {
- }
+ window.addEventListener("load", function(event) {
+ init(event);
+ }, false);
- if (forbidden) {
- var alertTitle = StringUtils.strbundle.GetStringFromName("actionForbidden");
- var alertText = StringUtils.strbundle
- .GetStringFromName("urlCanOnlyBeCopiedToClipboard");
- Services.prompt.alert(null, alertTitle, alertText);
- return;
- }
- Utils.getChromeWindow(window).gBrowser.addTab(content);
- };
return self;
}(window.requestpolicy.requestLog || {}));
-
-addEventListener("load", function(event) {
- window.requestpolicy.requestLog.init(event);
-}, false);
diff --git a/src/content/ui/request-log.xul b/src/content/ui/request-log.xul
index a07c6eb..199960f 100644
--- a/src/content/ui/request-log.xul
+++ b/src/content/ui/request-log.xul
@@ -28,8 +28,9 @@
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript" src="request-log-tree-view.js" />
<script type="application/x-javascript" src="request-log.js" />
+ <script type="application/x-javascript" src="request-log.interface.js" />
+ <script type="application/x-javascript" src="request-log-tree-view.js" />
<popupset>
<menupopup id="requestpolicyRequestLogContext">
--
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