[Pkg-mozext-commits] [perspectives-extension] 30/72: Redesign whitelist preference UI Fixes #136 (partly)

David Prévot taffit at moszumanska.debian.org
Thu Dec 11 02:12:48 UTC 2014


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

taffit pushed a commit to branch master
in repository perspectives-extension.

commit 505ddbd3b1cbceaa794edb5d83f3d18ba697981f
Author: Gerold Meisinger <gerold.meisinger at gmail.com>
Date:   Thu Jul 10 21:33:56 2014 +0100

    Redesign whitelist preference UI
    Fixes #136 (partly)
    
    added in preferences_dialog: converted whitelist textfield into a table with columns [domain, regex, active], domain column is sortable, regexes can be edited, active can be checked/unchecked, table supports multi row selection whos entries can be removed, added localizations (en, de) for columns and remove button
    added in prefs: new pref "extensions.perspectives.whitelist_disabled"
---
 plugin/chrome/content/css/preferences_dialog.css |   5 +
 plugin/chrome/content/preferences_dialog.js      | 141 ++++++++++++++++++++++-
 plugin/chrome/content/preferences_dialog.xul     |  21 +++-
 plugin/chrome/locale/de/dialogs.dtd              |   6 +-
 plugin/chrome/locale/en-US/dialogs.dtd           |   6 +-
 plugin/chrome/locale/es-MX/dialogs.dtd           |   8 +-
 plugin/chrome/locale/fi/dialogs.dtd              |   8 +-
 plugin/chrome/locale/fr/dialogs.dtd              |   8 +-
 plugin/chrome/locale/nl/dialogs.dtd              |   8 +-
 plugin/chrome/locale/pl/dialogs.dtd              |   8 +-
 plugin/chrome/locale/zh-CN/dialogs.dtd           |   8 +-
 plugin/defaults/preferences/prefs.js             |   3 +-
 12 files changed, 211 insertions(+), 19 deletions(-)

diff --git a/plugin/chrome/content/css/preferences_dialog.css b/plugin/chrome/content/css/preferences_dialog.css
new file mode 100644
index 0000000..f66d3ff
--- /dev/null
+++ b/plugin/chrome/content/css/preferences_dialog.css
@@ -0,0 +1,5 @@
+treechildren::-moz-tree-checkbox(checked)
+{
+    /* https://developer.mozilla.org/en-US/docs/Tree_Widget_Changes#Checkbox_columns */
+    list-style-image: url("chrome://global/skin/checkbox/cbox-check.gif");
+}
diff --git a/plugin/chrome/content/preferences_dialog.js b/plugin/chrome/content/preferences_dialog.js
index 447079a..5fa97e3 100644
--- a/plugin/chrome/content/preferences_dialog.js
+++ b/plugin/chrome/content/preferences_dialog.js
@@ -17,7 +17,7 @@
 */
 
 var Pers_pref = {
-	root_prefs : Components.classes["@mozilla.org/preferences-service;1"].
+	root_prefs: Components.classes["@mozilla.org/preferences-service;1"].
 				getService(Components.interfaces.nsIPrefBranch),
 
 	disable_quorum_text: function(is_disabled) {
@@ -58,6 +58,120 @@ var Pers_pref = {
 
 	},
 
+	// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsITreeView
+	// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Tutorial/Custom_Tree_Views
+	whitelist_treeView: {
+		rows      : [],   // [{domain: string, host_regex: string, enabled: bool}]
+		selection : null, // nsITreeSelection
+
+		init: function(whitelist_enabled_str, whitelist_disabled_str) {
+			var whitelist_enabled  = whitelist_enabled_str.length  > 0 ? whitelist_enabled_str.split (",") : [];
+			var whitelist_disabled = whitelist_disabled_str.length > 0 ? whitelist_disabled_str.split(",") : [];
+
+			var push_host_regexes = function(host_regexes, enabled, rows) {
+				host_regexes.forEach(function(host_regex) {
+					// TODO: support better subdomain handling in UI
+					var host_prefix = "\\.";
+					var domain = host_regex.substring(host_regex.indexOf(host_prefix) + host_prefix.length, host_regex.length - 1).replace(host_prefix, ".");
+
+					rows.push({domain: domain, host_regex: host_regex, enabled: enabled});
+				});
+			};
+
+			this.rows = [];
+			push_host_regexes(whitelist_enabled , true , this.rows);
+			push_host_regexes(whitelist_disabled, false, this.rows);
+
+			this.rows.sort(function(a, b) {
+				return a.domain.localeCompare(b.domain);
+			});
+		},
+		serialize: function() {
+			var whitelist_enabled  = [];
+			var whitelist_disabled = [];
+			this.rows.forEach(function(row) {
+				if(row.enabled) {
+					whitelist_enabled.push (row.host_regex);
+				} else {
+					whitelist_disabled.push(row.host_regex);
+				}
+			});
+
+			return [ {pref: "perspectives.whitelist"                    , value: whitelist_enabled .join(",")}
+				   , {pref: "extensions.perspectives.whitelist_disabled", value: whitelist_disabled.join(",")}
+				   ];
+		},
+		removeSelected: function() {
+			if(this.selection.getRangeCount() > 0) {
+				var new_rows = [];
+				var copy_idx = 0;
+
+				for(var i = 0; i < this.selection.getRangeCount(); i++) {
+					var min = {};
+					var max = {};
+					this.selection.getRangeAt(i, min, max);
+
+					for(var j = copy_idx; j < min.value; j++) {
+						new_rows.push(this.rows[j]);
+					}
+					copy_idx = max.value + 1;
+				}
+
+				// copy rest
+				for(var j = copy_idx; j < this.rows.length; j++) {
+					new_rows.push(this.rows[j]);
+				}
+
+				this.rows = new_rows;
+			}
+		},
+
+		get rowCount() {
+			return this.rows.length;
+		},
+		getCellText: function(row, col) {
+			return this.rows[row][col.id];
+		},
+		setCellText: function(row, col, value) {
+			this.rows[row][col.id] = value;
+		},
+		getCellValue: function(row, col) {
+			return this.rows[row][col.id];
+		},
+		setCellValue: function(row, col, value) {
+			this.rows[row][col.id] = value === "true";
+		},
+		cycleHeader: function(col) {
+			if(col.id === "domain") {
+				this.rows.reverse();
+				var elem = document.getElementById("domain");
+				var order = elem.getAttribute("sortDirection") !== "ascending";
+				elem.setAttribute("sortDirection", order ? "ascending" : "descending");
+			}
+		},
+		getLevel: function(row) {
+			return 0;
+		},
+		getImageSrc: function(row, col) {
+			return null;
+		},
+		isContainer: function(row) {
+			return false;
+		},
+		isEditable: function(row, col) {
+			return true;
+		},
+		isSeparator: function(row) {
+			return false;
+		},
+		isSorted: function() {
+			return true;
+		},
+		setTree: function(treebox) {
+			this.treebox = treebox;
+		}
+	},
+
 	// extra validation on some of the preference values
 	save_button_clicked: function() {
 		var ret = true;
@@ -70,6 +184,7 @@ var Pers_pref = {
 			Pers_util.pers_alert(e);
 			ret = false;
 		}
+
 		try {
 			if (this.root_prefs.getIntPref("perspectives.quorum_thresh") < 1) {
 				this.root_prefs.setIntPref("perspectives.quorum_thresh", 1);
@@ -80,6 +195,17 @@ var Pers_pref = {
 			Pers_util.pers_alert(e);
 			ret = false;
 		}
+
+		try {
+			var whitelist_prefs = Pers_pref.whitelist_treeView.serialize();
+			for(var i = 0; i < whitelist_prefs.length; i++) {
+				this.root_prefs.setCharPref(whitelist_prefs[i].pref, whitelist_prefs[i].value);
+			}
+		} catch (e) {
+			Pers_util.pers_alert(e);
+			ret = false;
+		}
+
 		try {
 			var add_list = document.getElementById("additional_notary_list");
 			var l = Pers_util.loadNotaryListFromString(add_list.value);
@@ -98,7 +224,7 @@ var Pers_pref = {
 			// list to show based on whether the checkbox is selected.
 			var auto_update = document.getElementById("enable_default_list_auto_update").checked;
 			if(auto_update) {
-				Pers_util.update_default_notary_list_from_web(this.root_prefs);
+				Pers_util.update_default_notary_list_from_web (this.root_prefs);
 			} else {
 				Pers_util.update_default_notary_list_from_file(this.root_prefs);
 			}
@@ -113,11 +239,16 @@ var Pers_pref = {
 		try {
 			Pers_pref.security_class_change();
 			Pers_pref.disable_reminder_box();
-			var default_notary_text = this.root_prefs.getCharPref("perspectives.default_notary_list");
-			document.getElementById("default_notary_list").value = default_notary_text;
+
+			var whitelist          = this.root_prefs.getCharPref("perspectives.whitelist");
+			var whitelist_disabled = this.root_prefs.getCharPref("extensions.perspectives.whitelist_disabled");
+			Pers_pref.whitelist_treeView.init(whitelist, whitelist_disabled);
+			document.getElementById('whitelist').view = Pers_pref.whitelist_treeView;
+
+			document.getElementById("default_notary_list").value = this.root_prefs.getCharPref("perspectives.default_notary_list");
 		} catch(e) {
 			Pers_util.pers_alert(e);
 		}
 	}
-}
+};
 
diff --git a/plugin/chrome/content/preferences_dialog.xul b/plugin/chrome/content/preferences_dialog.xul
index c87dc9f..231c147 100644
--- a/plugin/chrome/content/preferences_dialog.xul
+++ b/plugin/chrome/content/preferences_dialog.xul
@@ -1,5 +1,7 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<?xml-stylesheet href="chrome://perspectives/content/css/preferences_dialog.css" type="text/css"?>
+
 <!DOCTYPE prefwindow SYSTEM "chrome://perspectives/locale/dialogs.dtd">
 
 <prefwindow
@@ -61,10 +63,6 @@
                     name="extensions.perspectives.contact_in_private_browsing_mode"
                     type="bool"/>
             <preference
-                    id  ="whitelist"
-                    name="perspectives.whitelist"
-                    type="string"/>
-            <preference
                     id  ="additional_notary_list"
                     name="perspectives.additional_notary_list"
                     type="string"/>
@@ -136,7 +134,20 @@
                             <checkbox label     ="&PermanentlytrustcertificatesvalidatedbyPerspectives;"
                                       preference="exception-perm"/>
                             <label value="&AutoTrust;:"/>
-                            <textbox preference="whitelist" id="whitelist" size="40"/>
+                            <tree id="whitelist" rows="10" seltype="multiple" editable="true" hidecolumnpicker="true">
+                                <treecols>
+                                    <!-- Why is the ascending sortDirectionIndicator looking down? => use descending -->
+                                    <treecol id="domain"     label="Domain"  flex="1"        sortDirection="descending"/>
+                                    <treecol id="host_regex" label="Regex"   flex="2"        editable="true"/>
+                                    <treecol id="enabled"    label="Enabled" type="checkbox" editable="true"/>
+                                </treecols>
+
+                                <treechildren/>
+                            </tree>
+                            <hbox>
+                                <spacer flex="1"/>
+                                <button label="&AutoTrustRemove;" onclick="Pers_pref.whitelist_treeView.removeSelected();"/>
+                            </hbox>
                         </groupbox>
                     </vbox>
                     <spacer flex="1"/>
diff --git a/plugin/chrome/locale/de/dialogs.dtd b/plugin/chrome/locale/de/dialogs.dtd
index 61ae155..cc5fd49 100644
--- a/plugin/chrome/locale/de/dialogs.dtd
+++ b/plugin/chrome/locale/de/dialogs.dtd
@@ -43,7 +43,11 @@
 <!ENTITY SubmitReport "Bericht absenden">
 <!ENTITY DetailedInformation "Detaillierte Informationen">
 <!ENTITY CertificateValidation "Zertifikatsüberprüfung">
-<!ENTITY AutoTrust "Zertifikaten von folgenden Webseiten automatisch vertrauen">
+<!ENTITY AutoTrust        "Zertifikaten von folgenden Webseiten automatisch vertrauen">
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Aktiv">
+<!ENTITY AutoTrustRemove  "Löschen">
 <!ENTITY DefaultNotaryServers "Standard-Notarserver">
 <!ENTITY UseDefaultNotaries "Liste der Standard-Notarserver benutzen">
 <!ENTITY AdditionalNotaryServers "Zusätzliche Notarserver">
diff --git a/plugin/chrome/locale/en-US/dialogs.dtd b/plugin/chrome/locale/en-US/dialogs.dtd
index 16d474a..f37073a 100644
--- a/plugin/chrome/locale/en-US/dialogs.dtd
+++ b/plugin/chrome/locale/en-US/dialogs.dtd
@@ -44,7 +44,11 @@
 <!ENTITY SubmitReport "Submit Report">
 <!ENTITY DetailedInformation "Detailed Information">
 <!ENTITY CertificateValidation "Certificate Validation">
-<!ENTITY AutoTrust "Automatically trust certificates for the following sites">
+<!ENTITY AutoTrust        "Automatically trust certificates for the following sites">
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
 <!ENTITY DefaultNotaryServers "Default Notary Servers">
 <!ENTITY UseDefaultNotaries "Use default notary server list">
 <!ENTITY AdditionalNotaryServers "Additional Notary Servers">
diff --git a/plugin/chrome/locale/es-MX/dialogs.dtd b/plugin/chrome/locale/es-MX/dialogs.dtd
index b9a349f..2c68d51 100644
--- a/plugin/chrome/locale/es-MX/dialogs.dtd
+++ b/plugin/chrome/locale/es-MX/dialogs.dtd
@@ -47,7 +47,13 @@
 <!ENTITY SubmitReport "Mandar Reporte">
 <!ENTITY DetailedInformation "Información Detallada">
 <!ENTITY CertificateValidation "Validación de Certificado">
-<!ENTITY AutoTrust "Confiar automáticamente en los certificados de los siguientes sitios">
+<!ENTITY AutoTrust        "Confiar automáticamente en los certificados de los siguientes sitios">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "Servidores de Notaría por Default">
 <!ENTITY UseDefaultNotaries "Usar la lista de servidores de notaría por default">
 <!ENTITY AdditionalNotaryServers "Servidores de Notaría Adicionales">
diff --git a/plugin/chrome/locale/fi/dialogs.dtd b/plugin/chrome/locale/fi/dialogs.dtd
index 250738c..75e23ed 100644
--- a/plugin/chrome/locale/fi/dialogs.dtd
+++ b/plugin/chrome/locale/fi/dialogs.dtd
@@ -47,7 +47,13 @@
 <!ENTITY SubmitReport "Lähetä raportti">
 <!ENTITY DetailedInformation "Tarkemmat tiedot">
 <!ENTITY CertificateValidation "Sertifikaatin tarkastus">
-<!ENTITY AutoTrust "Luota automaattisesti kaikkiin sertifikaatteihin tällä sivustolla">
+<!ENTITY AutoTrust        "Luota automaattisesti kaikkiin sertifikaatteihin tällä sivustolla">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "Default Notary Servers">
 <!ENTITY UseDefaultNotaries "Use default notary server list">
 <!ENTITY AdditionalNotaryServers "Additional Notary Servers">
diff --git a/plugin/chrome/locale/fr/dialogs.dtd b/plugin/chrome/locale/fr/dialogs.dtd
index 8dfd107..02d5d1c 100644
--- a/plugin/chrome/locale/fr/dialogs.dtd
+++ b/plugin/chrome/locale/fr/dialogs.dtd
@@ -47,7 +47,13 @@
 <!ENTITY SubmitReport "Soumettre un rapport">
 <!ENTITY DetailedInformation "Informations détaillées">
 <!ENTITY CertificateValidation "Validation du certificat">
-<!ENTITY AutoTrust "Faire confiance automatiquement aux certificats pour les sites suivants">
+<!ENTITY AutoTrust        "Faire confiance automatiquement aux certificats pour les sites suivants">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "Serveurs Notaires par défaut">
 <!ENTITY UseDefaultNotaries "Utiliser la liste des serveurs Notaires par défaut">
 <!ENTITY AdditionalNotaryServers "Serveurs Notaires additionnels">
diff --git a/plugin/chrome/locale/nl/dialogs.dtd b/plugin/chrome/locale/nl/dialogs.dtd
index 9fa5adb..1d61c87 100644
--- a/plugin/chrome/locale/nl/dialogs.dtd
+++ b/plugin/chrome/locale/nl/dialogs.dtd
@@ -44,7 +44,13 @@
 <!ENTITY SubmitReport "Submit Report">
 <!ENTITY DetailedInformation "Detailed Information">
 <!ENTITY CertificateValidation "Certificate Validation">
-<!ENTITY AutoTrust "Automatically trust certificates for the following sites">
+<!ENTITY AutoTrust        "Automatically trust certificates for the following sites">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "Default Notary Servers">
 <!ENTITY UseDefaultNotaries "Use default notary server list">
 <!ENTITY AdditionalNotaryServers "Additional Notary Servers">
diff --git a/plugin/chrome/locale/pl/dialogs.dtd b/plugin/chrome/locale/pl/dialogs.dtd
index 474228b..7d6b547 100644
--- a/plugin/chrome/locale/pl/dialogs.dtd
+++ b/plugin/chrome/locale/pl/dialogs.dtd
@@ -48,7 +48,13 @@
 <!ENTITY SubmitReport "Wyślij raport">
 <!ENTITY DetailedInformation "Szczegółowe informacje">
 <!ENTITY CertificateValidation "Weryfikacja certyfikatu">
-<!ENTITY AutoTrust "Automatycznie ufaj certyfikatom następujących stron">
+<!ENTITY AutoTrust        "Automatycznie ufaj certyfikatom następujących stron">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "Domyślne serwery notarialne">
 <!ENTITY UseDefaultNotaries "Użyj domyślnej listy serwerów notarialnych">
 <!ENTITY AdditionalNotaryServers "Dodatkowe serwery notarialne">
diff --git a/plugin/chrome/locale/zh-CN/dialogs.dtd b/plugin/chrome/locale/zh-CN/dialogs.dtd
index 1fb1fc5..b4b0514 100644
--- a/plugin/chrome/locale/zh-CN/dialogs.dtd
+++ b/plugin/chrome/locale/zh-CN/dialogs.dtd
@@ -47,7 +47,13 @@
 <!ENTITY SubmitReport "提交报告">
 <!ENTITY DetailedInformation "详细信息">
 <!ENTITY CertificateValidation "证书验证">
-<!ENTITY AutoTrust "自动信任下列站点的证书">
+<!ENTITY AutoTrust        "自动信任下列站点的证书">
+<!-- TODO translate -->
+<!ENTITY AutoTrustDomain  "Domain">
+<!ENTITY AutoTrustRegex   "Regex">
+<!ENTITY AutoTrustEnabled "Enabled">
+<!ENTITY AutoTrustRemove  "Remove">
+<!-- -->
 <!ENTITY DefaultNotaryServers "默认认证服务器">
 <!ENTITY UseDefaultNotaries "使用默认认证服务器列表">
 <!ENTITY AdditionalNotaryServers "其它认证服务器">
diff --git a/plugin/defaults/preferences/prefs.js b/plugin/defaults/preferences/prefs.js
index e2e67f9..9bed1e3 100755
--- a/plugin/defaults/preferences/prefs.js
+++ b/plugin/defaults/preferences/prefs.js
@@ -18,7 +18,8 @@ pref("perspectives.max_timespan_for_inconsistency_test", 7);
 pref("perspectives.weak_consistency_time_limit", 30);
 pref("perspectives.trust_https_with_weak_consistency", true);
 pref("extensions.perspectives.max_cache_age_sec", 10000);
-pref("perspectives.whitelist", "");
+pref("perspectives.whitelist"                    , "");
+pref("extensions.perspectives.whitelist_disabled", "");
 pref("perspectives.prompt_update_all_https_setting", true);
 pref("perspectives.additional_notary_list", "");
 pref("perspectives.default_notary_list","");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/perspectives-extension.git



More information about the Pkg-mozext-commits mailing list