[Pkg-mozext-commits] [wot] 32/226: #10 Detect HTTPS Everywhere and default to HTTPS if installed

David Prévot taffit at moszumanska.debian.org
Fri May 1 00:35:31 UTC 2015


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

taffit pushed a commit to branch master
in repository wot.

commit 15564d8ae560342377bf5b4e6e6994726c2730e7
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date:   Mon Aug 27 15:02:02 2012 +0300

    #10 Detect HTTPS Everywhere and default to HTTPS if installed
---
 content/api.js  |  8 ++++----
 content/core.js | 25 ++++++++++++++++++++++++-
 content/my.js   |  3 ++-
 content/util.js |  2 +-
 4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/content/api.js b/content/api.js
index eb4a25c..ff5158f 100644
--- a/content/api.js
+++ b/content/api.js
@@ -66,7 +66,7 @@ var wot_api_link =
 
 			var request = new XMLHttpRequest();
 
-			request.open("GET", WOT_SERVICE_NORMAL +
+			request.open("GET", wot_core.wot_service_url() +
 					wot_crypto.authenticate_query(qs));
 
 			new wot_cookie_remover(request);
@@ -209,7 +209,7 @@ var wot_api_query =
 
 			wot_cache.add_nonce(nonce, hostname);
 
-			request.open("GET", WOT_SERVICE_NORMAL +
+			request.open("GET", wot_core.wot_service_url() +
 				wot_crypto.authenticate_query(qs));
 
 			new wot_cookie_remover(request);
@@ -772,7 +772,7 @@ var wot_api_submit =
 				return;
 			}
 
-			request.open("GET", WOT_SERVICE_NORMAL +
+			request.open("GET", wot_core.wot_service_url() +
 					wot_crypto.authenticate_query(qs));
 
 			new wot_cookie_remover(request);
@@ -833,7 +833,7 @@ var wot_api_update =
 			/* Build a request */
 			var request = new XMLHttpRequest();
 
-			request.open("GET", WOT_SERVICE_NORMAL +
+			request.open("GET", wot_core.wot_service_url() +
 				WOT_SERVICE_API_UPDATE +
 				"?id="		+ wot_prefs.witness_id +
 				"&nonce="	+ wot_crypto.nonce() +
diff --git a/content/core.js b/content/core.js
index cf3c02c..6c5ccba 100644
--- a/content/core.js
+++ b/content/core.js
@@ -97,10 +97,29 @@ var wot_core =
 	pending: {},
 	purged: Date.now(),
 	loaded: false,
-	
+	force_https: false,
+
+	detect_environment: function()
+	{
+		// check if there is HTTPSEveryWhere addon also installed
+		var is_https_everywhere = false;
+		try {
+			var https_everywhere =
+				Components.classes["@eff.org/https-everywhere;1"]
+					.getService(Components.interfaces.nsISupports).wrappedJSObject;
+			is_https_everywhere = true;
+		} catch (e) {
+			is_https_everywhere = false; // there is no HTTPS EveryWhere
+		}
+
+		this.force_https = this.force_https || is_https_everywhere; // forced to use https if "HTTPS EveryWhere" addon is also installed
+	},
+
 	init: function()
 	{
 		try {
+
+			this.detect_environment();
 			window.addEventListener("load", function(e) {
 					window.removeEventListener("load", arguments.callee, true);
 					wot_core.load();
@@ -654,6 +673,10 @@ var wot_core =
 		} catch (e) {
 			dump("wot_core.update: failed with " + e + "\n");
 		}
+	},
+
+	wot_service_url: function() {
+		return this.force_https ? WOT_SERVICE_SECURE : WOT_SERVICE_NORMAL;
 	}
 };
 
diff --git a/content/my.js b/content/my.js
index 9d10127..c015b73 100644
--- a/content/my.js
+++ b/content/my.js
@@ -75,7 +75,8 @@ var wot_my_session =
 			var ios = Components.classes["@mozilla.org/network/io-service;1"].
 						getService(Components.interfaces.nsIIOService);
 
-			var uri = ios.newURI("http://" + WOT_MY_COOKIE_DOMAIN + "/", "",
+			var scheme = wot_core.force_https ? "https://" : "http://";
+			var uri = ios.newURI(scheme + WOT_MY_COOKIE_DOMAIN + "/", "",
 						null);
 
 			var cs = Components.classes["@mozilla.org/cookieService;1"].
diff --git a/content/util.js b/content/util.js
index 43e18bc..c9df854 100644
--- a/content/util.js
+++ b/content/util.js
@@ -209,7 +209,7 @@ var wot_url =
 					url += "/" + tab;
 				}
 
-				if (secure) {
+				if (secure || wot_core.force_https) {
 					url = url.replace(/^http\:/, "https:");
 				}
 

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



More information about the Pkg-mozext-commits mailing list