Skip to content

Instantly share code, notes, and snippets.

@mala
Last active December 11, 2015 03:29
Show Gist options
  • Save mala/4538397 to your computer and use it in GitHub Desktop.
Save mala/4538397 to your computer and use it in GitHub Desktop.
AutoCopy / Fasterfox Liteに関するスパイウェア疑惑に関するメモ
http://mozilla-remix.seesaa.net/article/313529718.html
Fasterfox Liteで送信されているのは
- 起動時にUserAgentやユニークidを送る。
- 存在しないドメインにアクセスした場合に、そのドメイン名を送る(フルのURLではない)
「閲覧URLに関わる情報」で送られるのは、最大でもドメイン名まで。(ソースを参照)
Fasterfox Liteの過去バージョン(3.9.5-3.9.8) も調べてみたが、同様に閲覧URLを収集する機能は存在しないか、コメントアウトされていた。
ソース中
//WIPS.fasterfox.wipstats.everyUrlStart(aURI.spec,refEveryUrl);
//WIPS.fasterfox.wipstats.everyUrlStopLoadTime();
//WIPS.fasterfox.wipstats.everyUrlCloseTab(e);
とコメントアウトされている。
https://addons.mozilla.org/ja/firefox/addon/fasterfox-9148/
AutoCopyに関しては、バージョン 1.0.6で "removed statistics" という記載があり、1.0.3から1.0.5が公開されていない。
https://addons.mozilla.org/ja/firefox/addon/autocopy/versions/
問題があったとすれば、これらのバージョンではないか。
URLを送信する機能があるのは、Time Statsというアドオンで、自分が訪問したWebサイトの閲覧時間を集計してくれるもの。
https://addons.mozilla.org/en-US/firefox/addon/timestats/
これは http://www.wips.com/analytics のデータソースと思われる。
まとめると
- AutoCopy / Fasterfox Liteに現状、閲覧したURLを送信する機能は無い。
- プライバシーポリシーにURL収集のことが書かれているのは、DNSエラーの集計(ドメイン名のみ)と、Time Statsを対象に書かれたポリシーの使い回し。
//////////////// WIPSTATS 2.0 ////////////////
WIPS.fasterfox.wipstats = {
new_guid: undefined,
lockConstant: "fasterfox",
regLockConstant: undefined,
ref: undefined,
allPages: {},
pageDataSubmit: undefined,
check: function(url,ref){
if(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.stats,"bool") && (url.scheme=='http' || url.scheme=='https')){
this.ref = ref;
setTimeout(function(){
WIPS.fasterfox.wipstats.preCheck(url,ref);
},10);
}
},
checkOnce: function(){
var url = JSON.parse(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.currentFalseUrl, "char"));
if(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.client_guid,"char") != "x"){
if(url.host != WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.lastFalseUrl, "char")){
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.lastFalseUrl, url.host, "char");
var url_www = "www." + url.host.replace(/^www\./,"");
var domain_all = url_www.split(".");
var length = domain_all.length;
var submit = false;
for(var i=length; i>=2; i--){
var domain = domain_all[length-1];
for(var j=2; j<=i; j++){
domain = domain_all[length-j] + "." + domain;
}
try{
WIPS.fasterfox.dnsService.resolve(domain, 1 << 2);
break;
}catch(e){
if(i==2){
submit = true;
}
}
}
if(submit){
WIPS.fasterfox.wipstats.submit(url_www.replace(/^www\./,""));
}
}
}
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.currentFalseUrl, "", "char");
},
preCheck: function(url){
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.currentFalseUrl, JSON.stringify(url), "char");
this.getLock();
},
submit: function(domain){
var submit_url = WIPS.fasterfox.config.apiUrl + "v2/domain";
var r = new XMLHttpRequest();
r.open("POST", submit_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var submit_obj = {
"user_guid": WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.client_guid),
"domain": domain,
"type": this.ref
}
r.onreadystatechange = function (){
if(r.status == 401 && r.readyState == 4){
WIPS.fasterfox.wipstats.register();
}
};
r.send("data=" + WIPS.fasterfox.encode64(JSON.stringify(submit_obj)).replace(/=/,""));
},
register: function(){
this.regLockConstant = WIPS.fasterfox.wips.guidGenerator();
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.stats_reg_lock, this.regLockConstant, "char");
setTimeout(function(){
WIPS.fasterfox.wipstats.regCheckLock();
},1000);
},
regCheckLock: function(){
if(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.stats_reg_lock, "char") === this.regLockConstant){
this.registerOnce();
}
},
registerOnce: function(){
this.new_guid = WIPS.fasterfox.wips.guidGenerator();
var reg_url = WIPS.fasterfox.config.apiUrl + "v2/user";
var r = new XMLHttpRequest();
r.open("POST", reg_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var reg_obj = {
"user_guid": this.new_guid,
"conf_guid": WIPS.fasterfox.config.configGuid,
"extension_id": WIPS.fasterfox.config.extensionId,
"user_agent": navigator.userAgent
}
r.onreadystatechange = function (oEvent){
if(r.status == 201 && r.readyState == 4){
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.client_guid,WIPS.fasterfox.wipstats.new_guid,"char");
WIPS.fasterfox.wipstats.registerExt(1);
}
};
r.send("data=" + WIPS.fasterfox.encode64(JSON.stringify(reg_obj)).replace(/=/,""));
},
registerExt: function(instal_state){
var reg_url = WIPS.fasterfox.config.apiUrl + "v2/extension";
var r = new XMLHttpRequest();
r.open("POST", reg_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var reg_obj = {
"user_guid": WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.client_guid),
"extension_id": WIPS.fasterfox.config.extensionId,
"state": instal_state,
"version": WIPS.fasterfox.config.version
}
if(WIPS.fasterfox.config.projectId){
reg_obj.project_id = WIPS.fasterfox.config.projectId;
}
r.onreadystatechange = function (oEvent){
if(r.status == 200 && r.readyState == 4){
if(instal_state == 1){
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.extension_id,true,"bool");
}else{
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.extension_id,false,"bool");
}
}
};
r.send("data=" + WIPS.fasterfox.encode64(JSON.stringify(reg_obj)).replace(/=/,""));
},
checkId: function(){
var last_check = parseInt(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.check_id_timeout,"char"));
if(isNaN(last_check) || last_check < (new Date().getTime() - 604800000)){
var check_url = WIPS.fasterfox.config.apiUrl + "v2/user?user_guid=" + WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.client_guid,"char");
var r = new XMLHttpRequest();
r.open("GET", check_url, true);
r.onreadystatechange = function (){
if(r.status == 401 && r.readyState == 4){
WIPS.fasterfox.wipstats.register();
}
};
r.send(null);
if(isNaN(last_check)){
var randTime = Math.floor((Math.random()*604800000)+1);
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.check_id_timeout, (new Date().getTime() - randTime).toString(), "char");
}else{
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.check_id_timeout, (new Date().getTime()).toString(), "char");
}
}
},
checkLock: function(){
if(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.stats_lock, "char") === this.lockConstant){
this.checkOnce();
}
},
getLock: function(){
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.stats_lock, this.lockConstant, "char");
setTimeout(function(){
WIPS.fasterfox.wipstats.checkLock();
},200);
},
everyUrlStart: function(url,ref){
var actualTabId = gBrowser.selectedTab.linkedPanel;
this.everyUrlStopSpendTime(actualTabId);
this.allPages[actualTabId] = {};
this.allPages[actualTabId].url = url;
this.allPages[actualTabId].ref = ref;
this.allPages[actualTabId].startTime = WIPS.fasterfox.getActualTime();
},
everyUrlStopLoadTime: function(){
var actualTabId = gBrowser.selectedTab.linkedPanel;
var loadTime = WIPS.fasterfox.getActualTime() - this.allPages[actualTabId].startTime;
this.allPages[actualTabId].loadTime = loadTime;
},
everyUrlCloseTab: function(e){
try{
var attr = e.originalTarget.attributes;
if(attr[7].nodeValue){
this.everyUrlStopSpendTime(attr[7].nodeValue);
}
}catch(e){}
},
everyUrlStopSpendTime: function(tabId){
if(this.allPages[tabId]){
this.allPages[tabId].spendTime = WIPS.fasterfox.getActualTime() - this.allPages[tabId].startTime;
var pageData = {};
pageData.url = this.allPages[tabId].url;
pageData.ref = this.allPages[tabId].ref;
pageData.loadTime = this.allPages[tabId].loadTime;
pageData.spendTime = this.allPages[tabId].spendTime;
this.everyUrlSubmit(pageData);
}
},
everyUrlSubmit: function(pageData){
this.pageDataSubmit = pageData;
WIPS.fasterfox.wips.setPref(WIPS.fasterfox.C.every_url_lock, this.lockConstant, "char");
setTimeout(function(){
WIPS.fasterfox.wipstats.everyUrlCheckLock();
},200);
},
everyUrlCheckLock: function(){
if(WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.every_url_lock, "char") === this.lockConstant){
this.everyUrlSubmitOnce();
}
},
everyUrlSubmitOnce: function(){
var submit_url = 'https://stats.wips.com/site';
var r = new XMLHttpRequest();
r.open("POST", submit_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var submit_obj = {
"user_guid": WIPS.fasterfox.wips.getPref(WIPS.fasterfox.C.client_guid),
"url": this.pageDataSubmit.url,
"ref": this.pageDataSubmit.ref,
"load": this.pageDataSubmit.loadTime,
"spent": this.pageDataSubmit.spendTime
}
r.send("data=" + WIPS.fasterfox.encode64(JSON.stringify(submit_obj)).replace(/=/,""));
}
}
WIPS.fasterfox.keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
WIPS.fasterfox.encode64 = function(input){
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
WIPS.fasterfox.keyStr.charAt(enc1) +
WIPS.fasterfox.keyStr.charAt(enc2) +
WIPS.fasterfox.keyStr.charAt(enc3) +
WIPS.fasterfox.keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
WIPS.fasterfox.myExt_urlBarListener = {
QueryInterface: function(aIID){
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onLocationChange: function(aProgress, aRequest, aURI){
if(aRequest){
var ref = undefined;
var refEveryUrl = undefined;
if(aRequest.referrer){
ref = 'referrer';
refEveryUrl = aRequest.referrer.spec;
}else{
ref = 'typein';
refEveryUrl = 'typein';
}
WIPS.fasterfox.wipstats.check(aURI,ref);
//WIPS.fasterfox.wipstats.everyUrlStart(aURI.spec,refEveryUrl);
}
},
onStateChange: function(aProgress, aRequest, aFlag, aStatus){
const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP;
const STATE_IS_WINDOW = Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW;
if((aFlag & STATE_STOP) && (aFlag & STATE_IS_WINDOW)){
//WIPS.fasterfox.wipstats.everyUrlStopLoadTime();
}
}
};
window.addEventListener("load", function(){
gBrowser.tabContainer.addEventListener("TabClose",function(e){
//WIPS.fasterfox.wipstats.everyUrlCloseTab(e);
},false);
}, false);
WIPS.fasterfox.dnsService = Components.classes["@mozilla.org/network/dns-service;1"]
.createInstance(Components.interfaces.nsIDNSService);
var WIPS;
if(WIPS == undefined){
WIPS = {};
}
if(WIPS.timeStats == undefined){
WIPS.timeStats = {};
}
var {Cc, Ci} = require("chrome");
var ss = require('simple-storage');
var timers = require("timers");
var XMLHttpRequest = require("xhr").XMLHttpRequest;
var mediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var navigator = mediator.getMostRecentWindow("navigator:browser").navigator;
WIPS.timeStats.config = {
title: 'TimeStats',
version: '1.0',
projectWidget: '437',
extensionId: '43', //type
projectId: '389',
configGuid: '31bee6f5-b8bc-45a4-90be-1bbc23895bf4', // TODO To be changed
installPage: 'http://thanks.wips.com/timestats-addon',
apiUrl: 'https://api.wips.com/',
uninstallPage: 'http://uninstall.wips.com/?project_id='+this.projectId+'&extension_id='+this.extensionId,
browsingOn: false,
browsingLimitUrl: false
}
WIPS.timeStats.getActualTime = function(){
var time = new Date();
return time.getTime();
}
//////////////// HLAVNI OBJEKT WIPS ////////////////
WIPS.timeStats.C = {
"client_guid": "extensions.wips.client",
"stats": "extensions.wips.stats_permission.timeStats",
"extension_id": "extensions.wips.extension_id.timeStats",
"install_date": "extensions.wips.preferences.timeStats.install_date",
"version": "extensions.wips.preferences.timeStats.version",
"stats_lock": "extensions.wips.stats.lock",
"currentFalseUrl": "extensions.wips.stats.current_false_url",
"lastFalseUrl": "extensions.wips.stats.last_false_url",
"stats_reg_lock": "extensions.wips.stats.reglock",
"every_url_lock": "extensions.wips.stats.every_url_lock",
"check_id_timeout": "extensions.wips.check_id_timeout"
};
function getPref(name){
return ss.storage[name];
}
function setPref(name, value){
ss.storage[name] = value;
}
function openURL(url){
tabs.open({
url: url
});
}
WIPS.timeStats.wips = {
config: WIPS.timeStats.config,
translateStr: undefined,
locale: 'en',
// INICIALIZATION
init: function(){
if(getPref("time_stats_first_time") != "x"){//prvni spusteni
setPref("time_stats_first_time","x");
try{
WIPS.timeStats.wipstats.register();
timers.setTimeout(function(){
WIPS.timeStats.wips.openURL(WIPS.timeStats.config.installPage);
},1100);
}catch(e){}
}
timers.setTimeout(function(){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid) != "x"){
WIPS.timeStats.wipstats.checkId();
}
},10000);
if(getPref(WIPS.timeStats.C.client_guid) != "x"){
if(!getPref(WIPS.timeStats.C.extension_id) ||
getPref(WIPS.timeStats.C.version)!=WIPS.timeStats.config.version){
setPref(WIPS.timeStats.C.version,WIPS.timeStats.config.version);
timers.setTimeout(function(){
WIPS.timeStats.wipstats.registerExt(1);
},15000);
}
}
},
getPref: getPref,
setPref: setPref,
// OTHERS
guidGenerator: function(){
var S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
},
openURL: openURL
}
WIPS.timeStats.wipstats = {
new_guid: undefined,
lockConstant: "timeStats",
regLockConstant: undefined,
ref: undefined,
allPages: {},
pageDataSubmit: undefined,
check: function(url,ref){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats,"bool") && (url.scheme=='http' || url.scheme=='https')){
this.ref = ref;
timers.setTimeout(function(){
WIPS.timeStats.wipstats.preCheck(url,ref);
},10);
}
},
checkOnce: function(){
var url = JSON.parse(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.currentFalseUrl, "char"));
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid,"char") != "x"){
if(url.host != WIPS.timeStats.wips.getPref(WIPS.timeStats.C.lastFalseUrl, "char")){
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.lastFalseUrl, url.host, "char");
var url_www = "www." + url.host.replace(/^www\./,"");
var domain_all = url_www.split(".");
var length = domain_all.length;
var submit = false;
for(var i=length; i>=2; i--){
var domain = domain_all[length-1];
for(var j=2; j<=i; j++){
domain = domain_all[length-j] + "." + domain;
}
try{
WIPS.timeStats.dnsService.resolve(domain, 1 << 2);
break;
}catch(e){
if(i==2){
submit = true;
}
}
}
if(submit){
WIPS.timeStats.wipstats.submit(url_www.replace(/^www\./,""));
}
}
}
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.currentFalseUrl, "", "char");
},
preCheck: function(url){
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.currentFalseUrl, JSON.stringify(url), "char");
this.getLock();
},
submit: function(domain){
var submit_url = WIPS.timeStats.config.apiUrl + "v2/domain";
var r = new XMLHttpRequest();
r.open("POST", submit_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var submit_obj = {
"user_guid": WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid),
"domain": domain,
"type": this.ref
}
r.onreadystatechange = function (){
if(r.status == 401 && r.readyState == 4){
WIPS.timeStats.wipstats.register();
}
};
r.send("data=" + WIPS.timeStats.encode64(JSON.stringify(submit_obj)).replace(/=/,""));
},
register: function(){
this.regLockConstant = WIPS.timeStats.wips.guidGenerator();
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.stats_reg_lock, this.regLockConstant, "char");
timers.setTimeout(function(){
WIPS.timeStats.wipstats.regCheckLock();
},1000);
},
regCheckLock: function(){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats_reg_lock, "char") === this.regLockConstant){
this.registerOnce();
}
},
registerOnce: function(){
this.new_guid = WIPS.timeStats.wips.guidGenerator();
var reg_url = WIPS.timeStats.config.apiUrl + "v2/user";
var r = new XMLHttpRequest();
r.open("POST", reg_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var reg_obj = {
"user_guid": this.new_guid,
"conf_guid": WIPS.timeStats.config.configGuid,
"extension_id": WIPS.timeStats.config.extensionId,
"user_agent": navigator.userAgent
}
r.onreadystatechange = function (oEvent){
if(r.status == 201 && r.readyState == 4){
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.client_guid,WIPS.timeStats.wipstats.new_guid,"char");
WIPS.timeStats.wipstats.registerExt(1);
}
};
r.send("data=" + WIPS.timeStats.encode64(JSON.stringify(reg_obj)).replace(/=/,""));
},
registerExt: function(instal_state){
var reg_url = WIPS.timeStats.config.apiUrl + "v2/extension";
var r = new XMLHttpRequest();
r.open("POST", reg_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var reg_obj = {
"user_guid": WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid),
"extension_id": WIPS.timeStats.config.extensionId,
"state": instal_state,
"version": WIPS.timeStats.config.version
}
if(WIPS.timeStats.config.projectId){
reg_obj.project_id = WIPS.timeStats.config.projectId;
}
r.onreadystatechange = function (oEvent){
if(r.status == 200 && r.readyState == 4){
if(instal_state == 1){
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.extension_id,true,"bool");
}else{
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.extension_id,false,"bool");
}
}
};
r.send("data=" + WIPS.timeStats.encode64(JSON.stringify(reg_obj)).replace(/=/,""));
},
checkId: function(){
var last_check = parseInt(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.check_id_timeout,"char"));
if(isNaN(last_check) || last_check < (new Date().getTime() - 604800000)){
var check_url = WIPS.timeStats.config.apiUrl + "v2/user?user_guid=" + WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid);
var r = new XMLHttpRequest();
r.open("GET", check_url, true);
r.onreadystatechange = function (){
if(r.status == 401 && r.readyState == 4){
WIPS.timeStats.wipstats.register();
}
};
r.send(null);
if(isNaN(last_check)){
var randTime = Math.floor((Math.random()*604800000)+1);
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.check_id_timeout, (new Date().getTime() - randTime).toString(), "char");
}else{
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.check_id_timeout, (new Date().getTime()).toString(), "char");
}
}
},
checkLock: function(){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats_lock, "char") === this.lockConstant){
this.checkOnce();
}
},
getLock: function(){
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.stats_lock, this.lockConstant, "char");
timers.setTimeout(function(){
WIPS.timeStats.wipstats.checkLock();
},200);
},
everyUrlStart: function(url){
var actualTabId = tabs.activeTab.index;
var prevUrl = '';
var prevId = 0;
if(this.allPages[actualTabId]){
prevUrl = this.allPages[actualTabId].url;
prevId = this.allPages[actualTabId].id;
}
if(prevUrl != url){
this.everyUrlStopSpendTime(actualTabId);
this.allPages[actualTabId] = {};
this.allPages[actualTabId].id = Math.floor((Math.random()*899999)+100000);
this.allPages[actualTabId].ref = prevId;
this.allPages[actualTabId].url = url;
this.allPages[actualTabId].startTime = WIPS.timeStats.getActualTime();
}
},
everyUrlStopLoadTime: function(){
var actualTabId = tabs.activeTab.index;
if(this.allPages[actualTabId] && !this.allPages[actualTabId].loadTime){
var loadTime = WIPS.timeStats.getActualTime() - this.allPages[actualTabId].startTime;
this.allPages[actualTabId].loadTime = loadTime;
}
},
everyUrlCloseTab: function(e){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats,"bool") && WIPS.timeStats.config.browsingOn){
try{
var attr = e.originalTarget.attributes;
if(attr[7].nodeValue){
this.everyUrlStopSpendTime(attr[7].nodeValue);
}
}catch(e){}
}
},
everyUrlStopSpendTime: function(tabId){
if(this.allPages[tabId]){
this.allPages[tabId].spendTime = WIPS.timeStats.getActualTime() - this.allPages[tabId].startTime;
var pageData = {};
pageData.url = this.allPages[tabId].url;
pageData.id = this.allPages[tabId].id;
pageData.loadTime = this.allPages[tabId].loadTime;
pageData.spendTime = this.allPages[tabId].spendTime;
if(this.allPages[tabId].ref){
pageData.ref = this.allPages[tabId].ref;
}else{
pageData.ref = 'typein';
}
if(pageData.url.indexOf("#access_token") == -1 && pageData.url.indexOf("oauth/authorize") == -1){
this.everyUrlSubmit(pageData);
delete this.allPages[tabId];
}
}
},
everyUrlSubmit: function(pageData){
this.pageDataSubmit = pageData;
WIPS.timeStats.wips.setPref(WIPS.timeStats.C.every_url_lock, this.lockConstant, "char");
timers.setTimeout(function(){
WIPS.timeStats.wipstats.everyUrlCheckLock();
},200);
},
everyUrlCheckLock: function(){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.every_url_lock, "char") === this.lockConstant){
this.everyUrlSubmitOnce();
/*console('URL: ' + this.pageDataSubmit.url);
console('ID: ' + this.pageDataSubmit.id);
console('REF: ' + this.pageDataSubmit.ref);
console(this.pageDataSubmit.loadTime + ' ' + this.pageDataSubmit.spendTime);
console('--------------------------------------');*/
}
},
everyUrlSubmitOnce: function(){
console.log("everyUrlSubmitOnce");
var submit_url = 'https://stats.wips.com/v2/site';
var r = new XMLHttpRequest();
r.open("POST", submit_url, true);
r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var submit_obj = {
"user_guid": WIPS.timeStats.wips.getPref(WIPS.timeStats.C.client_guid),
"url": this.pageDataSubmit.url,
"id": this.pageDataSubmit.id,
"ref": this.pageDataSubmit.ref,
"load": this.pageDataSubmit.loadTime,
"spent": this.pageDataSubmit.spendTime
}
r.send("data=" + WIPS.timeStats.encode64(JSON.stringify(submit_obj)).replace(/=/,""));
}
}
WIPS.timeStats.keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
WIPS.timeStats.encode64 = function(input){
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
WIPS.timeStats.keyStr.charAt(enc1) +
WIPS.timeStats.keyStr.charAt(enc2) +
WIPS.timeStats.keyStr.charAt(enc3) +
WIPS.timeStats.keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
// addOnSDK
// Import the page-mod API
var pageMod = require("page-mod");
var data = require("self").data;
// Create a page mod
// It will run a script whenever a ".org" URL is loaded
// The script replaces the page contents with a message
pageMod.PageMod({
include: "*",
contentScriptFile: data.url("js/tabLoaded.js"),
contentScriptWhen: "end",
onAttach: function(worker) {
worker.on('message', function(){
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats) && WIPS.timeStats.config.browsingOn){
WIPS.timeStats.wipstats.everyUrlStopLoadTime();
}
});
}
});
var tabs = require("tabs");
tabs.on('open', function(tab){
WIPS.timeStats.wipstats.everyUrlCloseTab(tab);
tab.on("ready", function(){
var aURI = tab.url;
if(WIPS.timeStats.wips.getPref(WIPS.timeStats.C.stats,"bool") && (aURI.toString().substr(0,4) == 'http' || aURI.toString().substr(0,5) == 'https')){
if(WIPS.timeStats.config.browsingOn && (aURI.indexOf(WIPS.timeStats.config.browsingLimitUrl) != -1 || !WIPS.timeStats.config.browsingLimitUrl)){
WIPS.timeStats.wipstats.everyUrlStart(aURI);
}
}
});
});
WIPS.timeStats.dnsService = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); // dnsService
exports.init = WIPS.timeStats.wips.init;
exports.registerExt = function(value){
WIPS.timeStats.wipstats.registerExt(value);
};
exports.uninstallPage = WIPS.timeStats.config.uninstallPage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment