home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil892922B099213BB43E3E5EE220ED8F90
< prev
next >
Wrap
Text File
|
2010-07-12
|
14KB
|
432 lines
var gYaDefence = {
_lastChangedTimestamp: 0,
OVERRIDE_TIME_MONITORING: 5000,
_init: function() {
OBSERVER_SERVICE.addObserver(this, "quit-application-granted", false);
OBSERVER_SERVICE.addObserver(this, "profile-after-change", false);
OBSERVER_SERVICE.addObserver(this, "profile-before-change", false);
OBSERVER_SERVICE.addObserver(this, "Ya-GUID-Response", false);
},
_uninit: function() {
OBSERVER_SERVICE.removeObserver(this, "Ya-GUID-Response");
OBSERVER_SERVICE.removeObserver(this, "profile-before-change");
OBSERVER_SERVICE.removeObserver(this, "profile-after-change");
OBSERVER_SERVICE.removeObserver(this, "quit-application-granted");
},
_profileInit: function() {
if (this.homepageDefenceEnabled && this.protectedHomepage === null && this.currentHomepage !== null) {
this.protectedHomepage = this.currentHomepage;
}
else if (/\.start2\.mozilla\.com/.test(this.currentHomepage) &&
/firefox\.yandex\./.test(this.protectedHomepage))
{
gYaSearchService.setBrowserHomePage(this.protectedHomepage);
}
else if (/\.start2\.mozilla\.com/.test(this.protectedHomepage) &&
/firefox\.yandex\./.test(this.currentHomepage))
{
this.protectedHomepage = this.currentHomepage;
}
this.checkTimesChanged();
var prefBranchInternal = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal);
prefBranchInternal.addObserver("yasearch.defence.homepage", this, false);
prefBranchInternal.addObserver("browser.startup.homepage", this, false);
prefBranchInternal.addObserver("yasearch.general.server.time", this, false);
this.checkIsHomepageChanged();
this.initFirstSearchHook();
},
_profileUninit: function() {
var prefBranchInternal = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranchInternal);
prefBranchInternal.removeObserver("yasearch.defence.homepage", this);
prefBranchInternal.removeObserver("browser.startup.homepage", this);
prefBranchInternal.removeObserver("yasearch.general.server.time", this);
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "quit-application-granted":
this._uninit();
break;
case "profile-after-change":
OBSERVER_SERVICE.addObserver(this, "browser-ui-startup-complete", false);
break;
case "browser-ui-startup-complete":
OBSERVER_SERVICE.removeObserver(this, "browser-ui-startup-complete");
this._profileInit();
break;
case "profile-before-change":
this._profileUninit();
break;
case "nsPref:changed":
switch (aData) {
case "yasearch.general.server.time":
var currentTimeValues = this.getChangesTimeValues();
if (currentTimeValues.start && currentTimeValues.nvalid) {
var serverTime = G_DateUtils.serverTime;
if (serverTime) {
currentTimeValues.start = serverTime;
currentTimeValues.nvalid = 0;
this.setChangesTimeValues(currentTimeValues);
}
}
break;
case "yasearch.defence.homepage.enabled":
if (this.homepageDefenceEnabled)
this.protectedHomepage = this.currentHomepage;
break;
case "browser.startup.homepage":
if (this.OVERRIDE_TIME_MONITORING > (Date.now() - this._lastChangedTimestamp) &&
this.checkIsHomepageChanged(true))
{
this.homepageDefenceEnabled = false;
} else {
this._lastChangedTimestamp = 0;
this.checkTimesChanged();
}
break;
default:
break;
}//switch
break;//case "nsPref:changed"
case "Ya-GUID-Response":
if (aData == "SENDED") {
this.changesTime = null;
this.fSearchValue = "SENDED";
}
break;
default:
break;
}//switch
},
get homepageDefenceEnabled() {
return gYaSearchService.getBoolPref("yasearch.defence.homepage.enabled");
},
set homepageDefenceEnabled(val) {
gYaSearchService.setBoolPref("yasearch.defence.homepage.enabled", !!val);
return this.homepageDefenceEnabled;
},
get currentHomepage() {
return gYaSearchService.getBrowserHomePage();
},
get protectedHomepage() {
return gYaSearchService.getComplexValue("yasearch.defence.homepage.protected");
},
set protectedHomepage(aValue) {
gYaSearchService.setComplexValue("yasearch.defence.homepage.protected", aValue);
return this.protectedHomepage;
},
isYandexHomepage: function(aHomePageType) {
switch (aHomePageType) {
case "current":
case "protected":
return this._isYandexHomepage(this.getHostOrURLFromString(this[aHomePageType + "Homepage"]));
}
return null;
},
_isYandexHomepage: function(aHost) {
return /(^|www\.)(yandex\.(ru|ua|kz|by|net|com)|ya\.ru)$/i.test(aHost) ||
"ru.start3.mozilla.com" === aHost;
},
isYandexHost: function(aHost) {
return gYaSearchService.isYandexHost(aHost) || this._isYandexHomepage(aHost);
},
getHostOrURLFromString: function(aString) {
var urlStr = (aString || "").toString().split("|")[0].replace(/^\s+|\s+$/g, "");
var domainStr = urlStr;
try {
var uri = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService).newURI(urlStr, null, null);
if (/^(https?|file)$/.test(uri.scheme))
domainStr = uri.host;//without port
} catch(e) {}
return domainStr;
},
checkIsHomepageChanged: function(aIsChangedAgain) {
if (!this.homepageDefenceEnabled)
return null;
let res = this._getProtectedDiff();
if (res && this.isYandexHost(res.protectedHost) && this.isYandexHost(res.currentHost)) {
this.protectedHomepage = this.currentHomepage;
res = false;
}
if (res)
this.showHomepageAlert(aIsChangedAgain);
return res;
},
_getProtectedDiff: function() {
let protectedHp = this.protectedHomepage;
if (protectedHp === null)
return null;
let currentHp = this.currentHomepage;
let protectedHost = this.getHostOrURLFromString(protectedHp);
let currentHost = this.getHostOrURLFromString(currentHp);
if (protectedHost === currentHost)
return false;
return {
protectedHost: protectedHost,
currentHost: currentHost
};
},
__notifTimer: null,
showHomepageAlert: function(aIsChangedAgain) {
this.__notifTimer = new G_Timer(function() {
if (gYaSearchService.isFirstDOMWinStuffDone) {
if (gYaDefence.__notifTimer)
gYaDefence.__notifTimer.cancel();
new G_Timer(function() {
gYaDefence._showHomepageAlert(aIsChangedAgain);
}, 400);
}
}, 1000, true, 15);
},
_showHomepageAlert: function(aIsChangedAgain) {
const winType = "alert:YaHomepageDefenceAlert";
var alertWindow = gYaSearchService.getWindow(winType);
if (alertWindow) {
alertWindow.focus();
} else {
let flags = "chrome,popup=yes";
if (!gYaSearchService.AppInfo.browser.isGreaterThenFx35)
flags += ",titlebar=no";
alertWindow = gYaSearchService.windowWatcher.openWindow(null, CHROME_CONTENT + "alerts/defence.alert.xul",
"_blank", flags, null);
alertWindow.arguments = [CHROME_IMAGES + "bar-logo.png", aIsChangedAgain];
}
},
homepageAlertCallback: function(aAcceptCurrent, aProtectEnabled) {
if (!aProtectEnabled)
this.homepageDefenceEnabled = aProtectEnabled;
if (aAcceptCurrent) {
this.protectedHomepage = this.currentHomepage;
} else {
if (this.isYandexHomepage("protected"))
this.setChangesTimeValues({prtwrk: 1});
gYaSearchService.setBrowserHomePage(this.protectedHomepage);
let URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"].getService(Components.interfaces.nsIURIFixup);
let protectedURL = (this.protectedHomepage || "").toString().split("|")[0].replace(/^\s+|\s+$/g, "");
try {
protectedURL = URIFixup.createFixupURI(protectedURL, URIFixup.FIXUP_FLAG_NONE);
if (protectedURL && protectedURL.spec) {
let browser = gYaSearchService.getWindow("navigator:browser");
if (browser && 'gBrowser' in browser) {
try {
browser.gBrowser.loadTabs([protectedURL.spec], false, false);
} catch(e) {}
}
}
} catch(e) {}
this._lastChangedTimestamp = Date.now();
}
},
_yaChangesPrefName: "yasearch.defence.homepage.changes",
getChangesTimeValues: function() {
var res = {start: 0, total: 0, prtwrk: 0, nvalid: 0};
var pref = (gYaSearchService.getCharPref(this._yaChangesPrefName) || "").split("|");
if (pref.length == 4) {
res.start = gYaSearchService.parseIntFromStr(pref[0]);
res.total = gYaSearchService.parseIntFromStr(pref[1]);
res.prtwrk = Math.min(1, gYaSearchService.parseIntFromStr(pref[2]));
res.nvalid = Math.min(1, gYaSearchService.parseIntFromStr(pref[3]));
}
if (!res.start && res.nvalid)
res.nvalid = 0;
if (res.total > (350 * DAY_SECS))
res.total = 0;
return res;
},
setChangesTimeValues: function(aTimeObject) {
var currentTime = this.getChangesTimeValues()
timePrefArray = [];
["start", "total", "prtwrk", "nvalid"]
.forEach(function(aType) {
if (aType in aTimeObject)
currentTime[aType] = aTimeObject[aType];
timePrefArray.push(currentTime[aType]);
})
gYaSearchService.setCharPref(this._yaChangesPrefName, timePrefArray.join("|"));
},
_changesTimeWasCalculated: 0,
TIME_CALCULATED_FLAG_TOTAL: 1,
TIME_CALCULATED_FLAG_PRTWRK: 2,
get changesTime() {
var res = "";
this._changesTimeWasCalculated = 0;
var currentTimeValues = this.getChangesTimeValues();
if (currentTimeValues.start == 0 && currentTimeValues.total > 0) {
if (!this.isYandexHomepage("current") &&
(!this.homepageDefenceEnabled || !this.isYandexHomepage("protected")))
{
var time = Math.max(0, Math.ceil(currentTimeValues.total / DAY_SECS));
if (time) {
res += "&yahpchange=" + encodeURIComponent(time);
this._changesTimeWasCalculated += this.TIME_CALCULATED_FLAG_TOTAL;
}
}
}
if (currentTimeValues.prtwrk == 1) {
res += "&prtwrk=1";
this._changesTimeWasCalculated += this.TIME_CALCULATED_FLAG_PRTWRK;
}
return res;
},
set changesTime(val) {
if (val === null && this._changesTimeWasCalculated) {
var newTimesData = {};
if (this._changesTimeWasCalculated & this.TIME_CALCULATED_FLAG_TOTAL)
newTimesData.total = 0;
if (this._changesTimeWasCalculated & this.TIME_CALCULATED_FLAG_PRTWRK)
newTimesData.prtwrk = 0;
this.setChangesTimeValues(newTimesData);
}
return null;
},
checkTimesChanged: function() {
var currentTimeValues = this.getChangesTimeValues();
if (currentTimeValues.start == 0) {
if (this.isYandexHomepage("current")) {
currentTimeValues.start = Date.now();
currentTimeValues.nvalid = 1;
}
} else {
if (!this.isYandexHomepage("current")) {
if (currentTimeValues.start > 0 && !currentTimeValues.nvalid) {
if (G_DateUtils.serverTime > currentTimeValues.start)
currentTimeValues.total += (G_DateUtils.serverTime - currentTimeValues.start);
}
currentTimeValues.start = 0;
currentTimeValues.nvalid = 0;
}
}
this.setChangesTimeValues(currentTimeValues);
},
FIRST_SEARCH_PREF_NAME: "yasearch.general.search.first",
fSearchValue: null,
fSearchStatData: null,
initFirstSearchHook: function() {
var fSearchPrefValue = gYaSearchService.getIntPref(this.FIRST_SEARCH_PREF_NAME);
if (fSearchPrefValue == 0 || fSearchPrefValue == 1) {
delete this.fSearchStatData;
this.__defineGetter__("fSearchStatData", function() {
if (gYaSearchService.getIntPref(this.FIRST_SEARCH_PREF_NAME) == 1)
return "&action=firstsearch";
return null;
});
delete this.fSearchValue;
this.__defineSetter__("fSearchValue", function(aValue) {
switch (aValue) {
case "SENDING":
if (gYaSearchService.getIntPref(this.FIRST_SEARCH_PREF_NAME) == 0)
gYaSearchService.setIntPref(this.FIRST_SEARCH_PREF_NAME, 1);
break;
case "SENDED":
if (gYaSearchService.getIntPref(this.FIRST_SEARCH_PREF_NAME) == 1)
gYaSearchService.setIntPref(this.FIRST_SEARCH_PREF_NAME, 2);
break;
default:
break;
}
});
var origGetSearchEngineUrl = gYaSearchService.getSearchEngineUrl;
gYaSearchService.getSearchEngineUrl = function() {
var result = origGetSearchEngineUrl.apply(this, arguments);
if (result && result.isYandexSearch)
gYaDefence.fSearchValue = "SENDING";
return result;
}
}
}
}
gYaDefence._init();