[Pkg-mozext-commits] [wot] 65/226: Added cleaning on uninstall. Cleaned the code from debug.

David Prévot taffit at moszumanska.debian.org
Fri May 1 00:35:35 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 65118381ab35b7de8409172a84681a85f5660830
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date:   Fri Jan 4 16:47:12 2013 +0200

    Added cleaning on uninstall. Cleaned the code from debug.
---
 content/api.js                  | 16 ++++++-------
 content/config.js               |  4 ++--
 content/core.js                 | 51 ++++++++++++++++++++++++++++++++++++++++-
 content/injections/wot_proxy.js |  6 ++---
 content/surveys.js              | 40 ++++++++++++++------------------
 content/ui.js                   |  6 +----
 content/util.js                 |  9 +-------
 7 files changed, 81 insertions(+), 51 deletions(-)

diff --git a/content/api.js b/content/api.js
index f846582..c330d84 100644
--- a/content/api.js
+++ b/content/api.js
@@ -1,6 +1,6 @@
 /*
 	api.js
-	Copyright © 2005-2012  WOT Services Oy <info at mywot.com>
+	Copyright © 2005 - 2013  WOT Services Oy <info at mywot.com>
 
 	This file is part of WOT.
 
@@ -230,8 +230,6 @@ var wot_api_query =
 					wot_cache.set(hostname, "time", Date.now());
 
 					if (request.status == 200) {
-
-						// here is the point to process /query response and extract a FBL question
 						wot_cache.add_query(
 							request.responseXML.getElementsByTagName(
 								WOT_SERVICE_XML_QUERY),
@@ -808,7 +806,7 @@ var wot_api_feedback =
 	{
 		try {
 			if (!wot_util.isenabled() || !url || !choice || !question) {
-				dump("wot_api_feedback.send() - invalid params were given\n");
+//				dump("wot_api_feedback.send() - invalid params were given\n");
 				return;
 			}
 
@@ -818,7 +816,7 @@ var wot_api_feedback =
 				wot_prefs.witness_key, nonce));
 
 			if (!context) {
-				dump("wot_api_feedback.send() - no context was given\n");
+//				dump("wot_api_feedback.send() - no context was given\n");
 				return;
 			}
 
@@ -826,7 +824,7 @@ var wot_api_feedback =
 				wot_hash.strtobin(url));
 
 			if (!crypted) {
-				dump("wot_api_feedback.send() - url encryption failed\n");
+//				dump("wot_api_feedback.send() - url encryption failed\n");
 				return;
 			}
 
@@ -842,7 +840,7 @@ var wot_api_feedback =
 			var request = new XMLHttpRequest();
 
 			if (!request) {
-				dump("wot_api_feedback.send() - failed to create Request object\n");
+//				dump("wot_api_feedback.send() - failed to create Request object\n");
 				return;
 			}
 
@@ -854,7 +852,7 @@ var wot_api_feedback =
 			{
 				try {
 					if (request.status == 200) {
-						dump("wot_api_feedback.onload: answer submitted successfully\n");
+//						dump("wot_api_feedback.onload: answer submitted successfully\n");
 					}
 				} catch (e) {
 					dump("wot_api_feedback.onload: failed with " + e + "\n");
@@ -862,7 +860,7 @@ var wot_api_feedback =
 			};
 
 			request.send(null);
-			dump("wot_api_feedback.send() feedback was sent\n");
+//			dump("wot_api_feedback.send() feedback was sent\n");
 
 		} catch (e) {
 			dump("wot_api_feedback.send: failed with " + e + "\n");
diff --git a/content/config.js b/content/config.js
index 14b1d1e..aaba65d 100644
--- a/content/config.js
+++ b/content/config.js
@@ -1,6 +1,6 @@
 /*
 	config.js
-	Copyright © 2005 - 2012  WOT Services Oy <info at mywot.com>
+	Copyright © 2005 - 2013  WOT Services Oy <info at mywot.com>
 
 	This file is part of WOT.
 
@@ -19,7 +19,7 @@
 */
 
 const WOT_PLATFORM = "firefox";
-const WOT_VERSION  = "20130102";
+const WOT_VERSION  = "20130105";
 
 /*
  * Constants
diff --git a/content/core.js b/content/core.js
index 85d58c1..4ce5268 100644
--- a/content/core.js
+++ b/content/core.js
@@ -1,6 +1,6 @@
 /*
 	core.js
-	Copyright © 2005 - 2012  WOT Services Oy <info at mywot.com>
+	Copyright © 2005 - 2013  WOT Services Oy <info at mywot.com>
 
 	This file is part of WOT.
 
@@ -98,6 +98,7 @@ var wot_core =
 	purged: Date.now(),
 	loaded: false,
 	force_https: false,
+	is_beingUninstalled: false,
 
 	detect_environment: function()
 	{
@@ -166,6 +167,13 @@ var wot_core =
 				wot_core.update();
 			}, 250);
 
+			try {
+				Components.utils.import("resource://gre/modules/AddonManager.jsm");
+				AddonManager.addAddonListener(wot_core.install_listener);
+			} catch (e) {
+				dump("wot_core.load() setting up uninstall listener failed with " + e + "\n");
+			}
+
 			var browser = getBrowser();
 			this.listener = new wot_listener(browser);
 			browser.addProgressListener(this.listener);
@@ -181,6 +189,19 @@ var wot_core =
 		}
 	},
 
+	install_listener: {
+		onUninstalling: function(addon) {
+			if (addon.id == WOT_GUID) {
+				wot_core.is_beingUninstalled = true;
+			}
+		},
+		onOperationCancelled: function(addon) {
+			if (addon.id == WOT_GUID) {
+				wot_core.is_beingUninstalled = (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) != 0;
+			}
+		}
+	},
+
 	unload: function()
 	{
 		try {
@@ -206,11 +227,22 @@ var wot_core =
 				this.browser = null;
 			}
 
+			// do pre-cleaning on uninstall (before modules are unloaded)
+			if (wot_core.is_beingUninstalled) {
+				wot_core.clean_search_rules();
+			}
+
 			for (var i in wot_modules) {
 				if (typeof(wot_modules[i].obj.unload) == "function") {
 					wot_modules[i].obj.unload();
 				}
 			}
+
+			// do past-cleaning on uninstall
+			if (wot_core.is_beingUninstalled) {
+				wot_core.clean_profile_dir();
+			}
+
 		} catch (e) {
 			dump("wot_core.unload: failed with " + e + "\n");
 		}
@@ -696,6 +728,23 @@ var wot_core =
 		} else {
 			return "x";
 		}
+	},
+
+	clean_search_rules: function () {
+		// removes search rules from preferences
+		wot_prefs.deleteBranch(WOT_SEARCH);
+	},
+
+	clean_profile_dir: function () {
+		// removes only WOT dir in the profile folder
+		try {
+			var nsiDir = FileUtils.getDir("ProfD", [wot_file.wot_dir], false);
+			if (nsiDir && nsiDir.exists()) {
+				nsiDir.remove(true);    // 'true' for recursive removal
+			}
+		} catch (e) {
+			dump("wot_core.clean_profile_dir() failed with " + e + "\n");
+		}
 	}
 };
 
diff --git a/content/injections/wot_proxy.js b/content/injections/wot_proxy.js
index 36bf8e9..e1afe26 100644
--- a/content/injections/wot_proxy.js
+++ b/content/injections/wot_proxy.js
@@ -1,6 +1,6 @@
 /*
 	wot_proxy.js
-	Copyright © 2012 -   WOT Services Oy <info at mywot.com>
+	Copyright © 2012 - 2013  WOT Services Oy <info at mywot.com>
 
 	This file is part of WOT.
 
@@ -24,13 +24,13 @@
 * */
 
 var wot = {
-	version: "20130102",    // TODO: init this value from the add-on core code
+	version: "20130105",    // TODO: init this value from the add-on core code
 	platform: "firefox",
 	debug: false,           // when changing this, don't forget to switch ga_id value also!
 	default_component: 0,
 	enable_surveys: true,   // Feedback loop engine
 
-	ga_id: "UA-35564069-1", // test: UA-35564069-1 , live: UA-2412412-8
+	ga_id: "UA-2412412-8", // test: UA-35564069-1 , live: UA-2412412-8
 
 	// environment (browser, etc)
 	env: {
diff --git a/content/surveys.js b/content/surveys.js
index 273bdc9..10eeff5 100644
--- a/content/surveys.js
+++ b/content/surveys.js
@@ -41,7 +41,7 @@ var wot_surveys = {
 
 	_asked: {},
 
-	global_calm_period: 1 * 24 * 3600, // Time in seconds after asking a question before we can ask next question
+	global_calm_period: 3 * 24 * 3600, // Time in seconds after asking a question before we can ask next question
 	site_calm_period:   10 * 24 * 3600, // delay between asking for the particular website if user hasn't given the feedback yet
 	site_max_reask_tries: 3,    // How many times we can ask a user for the feedback about the website
 	always_ask:         ['api.mywot.com', 'fb.mywot.com'],
@@ -169,7 +169,6 @@ var wot_surveys = {
 
 	inject_javascript: function (content)
 	{
-		dump("Going to inject JS into FBL form\n");
 		var sandbox = wot_surveys.get_or_create_sandbox(content);
 
 		var contents = "",
@@ -297,8 +296,6 @@ var wot_surveys = {
 			var question_text = wot_cache.get(hostname, "question_text");
 			var choices_number = wot_cache.get(hostname, "choices_number");
 
-			dump("SHOW: id, text : " + String(question_id) + " , " + String(question_text) + "\n");
-
 			if (choices_number > 0) {
 				var question = {
 					target: hostname,
@@ -334,31 +331,31 @@ var wot_surveys = {
 
 		try {
 			if(!wot_surveys.asked.is_loaded()) return false; // data isn't ready for process
-			dump("if(!wot_surveys.asked.is_loaded()) passed.\n");
+//			dump("if(!wot_surveys.asked.is_loaded()) passed.\n");
 
 			if(!(question && question.id !== undefined && question.text && question.choices)) {
 				// no question was given for the current website - do nothing
-				dump("is_tts: empty or no question test NOT PASSED\n");
+//				dump("is_tts: empty or no question test NOT PASSED\n");
 				return false;
 			}
-			dump("is_tts: question test passed.\n");
+//			dump("is_tts: question test passed.\n");
 
 			// on special domains we should always show the survey if there is a special password given (for testing purposes)
 			// e.g. try this url http://api.mywot.com/test.html#surveymewot
 			if (ws.always_ask.indexOf(hostname) >= 0 && url && url.indexOf(ws.always_ask_passwd) >= 0) {
-				dump("is_tts: Magic 'always show' test PASSED\n");
+//				dump("is_tts: Magic 'always show' test PASSED\n");
 				return true;
 			}
 
 			if (ws.is_optedout() || !wot_prefs.getBool("feedback_enabled", true)) {
-				dump("is_tts: Opted-out test NOT PASSED\n");
+//				dump("is_tts: Opted-out test NOT PASSED\n");
 				return false;
 			}
 
 			// check if have asked the user more than X days ago or never before
 			var lasttime = ws.get_lasttime_asked();
 			if (lasttime && wot_util.time_since(lasttime) < ws.global_calm_period) {
-				dump("is_tts: Last time test NOT PASSED\n");
+//				dump("is_tts: Last time test NOT PASSED\n");
 				return false;
 			}
 
@@ -368,23 +365,23 @@ var wot_surveys = {
 			var asked_count = ws.asked.get(hostname, question.id, "count");
 
 			if (asked_status === ws.FLAGS.submited) {
-				dump("is_tts: 'Already gave feedback for the website' test NOT PASSED\n");
+//				dump("is_tts: 'Already gave feedback for the website' test NOT PASSED\n");
 				return false;
 			}
 			// all other statuses ("closed" and "none") are subject to show FBL again after delay
 
 			if (asked_count >= ws.site_max_reask_tries) {
-				dump("is_tts: Max asked times NOT PASSED\n");
+//				dump("is_tts: Max asked times NOT PASSED\n");
 				return false;
 			}
 
 			// If we have never showed the FBL for this site before, or more than "delay"
 			if (!(asked_time === null || wot_util.time_since(asked_time) >= ws.site_calm_period)) {
-				dump("is_tts: 'Calm delay for the website' test NOT PASSED\n");
+//				dump("is_tts: 'Calm delay for the website' test NOT PASSED\n");
 				return false;
 			}
 
-			dump("is_tts: already asked test passed -> show it!\n");
+//			dump("is_tts: already asked test passed -> show it!\n");
 			return true;
 		} catch (e) {
 			dump("wot_surveys.is_tts() failed with " + e + "\n");
@@ -457,7 +454,6 @@ var wot_surveys = {
 		if (time === false) {
 			time = "";
 		}
-		dump("wot_survey.set_lasttime_asked(" + time + ") is invoked\n");
 		wot_prefs.setChar("feedback_lasttimeasked", String(time));
 	},
 
@@ -539,7 +535,7 @@ var wot_surveys = {
 				// try un-json data (DON'T call any methods of data_json since it is unsafe!)
 				var data = JSON.parse(data_json);
 
-				dump("wot_surveys.sandpoxapi.wot_post(): " + JSON.stringify(data) + "\n");
+//				dump("wot_surveys.sandpoxapi.wot_post(): " + JSON.stringify(data) + "\n");
 
 				if (data && data.message && data.data) {
 					wot_surveys.dispatch(data.message, data.data, sandbox);
@@ -569,7 +565,7 @@ var wot_surveys = {
 			if (name) {
 				res = wot_hashtable.get(name);
 			} else {
-				dump("wot_survey.asked._get_name() returned NULL\n");
+//				dump("wot_survey.asked._get_name() returned NULL\n");
 			}
 			return res;
 		},
@@ -578,9 +574,9 @@ var wot_surveys = {
 			var name = wot_surveys.asked._get_name(hostname, question_id, prop);
 			if (name) {
 				wot_hashtable.set(name, value);
-				dump("HashT_set: " + name + " == " + value + "\n");
+//				dump("HashT_set: " + name + " == " + value + "\n");
 			} else {
-				dump("wot_survey.asked._get_name() returned NULL\n");
+//				dump("wot_survey.asked._get_name() returned NULL\n");
 			}
 		},
 
@@ -669,7 +665,7 @@ var wot_surveys = {
 									var count = qd['count'] || 0;
 
 									if (time && status !== null) {
-										dump("Reading 'asked' file: " + hostname + "/ " + question_id + "\n");
+//										dump("Reading 'asked' file: " + hostname + "/ " + question_id + "\n");
 										wot_surveys.asked.set(hostname, question_id, "status", status);
 										wot_surveys.asked.set(hostname, question_id, "time", time);
 										wot_surveys.asked.set(hostname, question_id, "count", count);
@@ -679,7 +675,7 @@ var wot_surveys = {
 						}
 
 					} else {
-						dump("FBL: no data in file storage found\n");
+//						dump("FBL: no data in file storage found\n");
 					}
 
 				} catch (e) {
@@ -717,9 +713,7 @@ var wot_surveys = {
 			} catch (e) {
 				dump("wot_surveys.asked.dump_to_file() failed with " + e + "\n");
 			}
-
 		}
-
 	}
 
 };
diff --git a/content/ui.js b/content/ui.js
index 772d2fb..fc91a43 100644
--- a/content/ui.js
+++ b/content/ui.js
@@ -112,11 +112,7 @@ var wot_status = {
 			if (type == WOT_WARNING_NOTIFICATION || type == WOT_WARNING_DOM) {
 				wot_warning.add(wot_core.hostname, content, type);
 			} else {
-				if(type != WOT_WARNING_BLOCK) {
-					wot_warning.hide(content);
-					// TODO: here we should put a call for FBL showing
-//					wot_surveys.inject();
-				}
+				if(type != WOT_WARNING_BLOCK) wot_warning.hide(content);
 			}
 		} catch (e) {
 			dump("wot_status.update: failed with " + e + "\n");
diff --git a/content/util.js b/content/util.js
index 21c8759..11e5a0a 100644
--- a/content/util.js
+++ b/content/util.js
@@ -1,6 +1,6 @@
 /*
 	util.js
-	Copyright © 2005-2012  WOT Services Oy <info at mywot.com>
+	Copyright © 2005 - 2013  WOT Services Oy <info at mywot.com>
 
 	This file is part of WOT.
 
@@ -23,7 +23,6 @@ var wot_util =
 	reportError: function(params)
 	{
 		Components.utils.reportError(JSON.stringify(arguments));
-
 	},
 
 	isenabled: function()
@@ -1116,11 +1115,5 @@ var wot_file = {
 			dump("wot_file.save_json() failed with " + e + "\n");
 			callback(false);   // report about failed attempt to save
 		}
-	},
-
-	remove: function (filename, callback)
-	{
-		// TODO: implement a function which will delete the file (for the case of uninstalling the addon)
 	}
-
 };

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