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
/
filCEAF408DE1FB29E2F6B09FFBDDCAFCB0
< prev
next >
Wrap
Text File
|
2010-07-12
|
21KB
|
735 lines
var gYaMFD = {
URL: {
"mfd-counter": "http://export.yandex.ru/for/{domain}/counters.xml",
"mfd-list": "http://mail.yandex.ru/for/{domain}/api/barlist",
},
__inited: false,
init: function() {
if (!this.__inited) {
this.__inited = true;
OBSERVER_SERVICE.addObserver(this, "cookie-changed", false);
OBSERVER_SERVICE.addObserver(this, "profile-before-change", false);
}
this._getCookies({
path: /^\/for/
}).forEach(function(aCookieData) {
this._setDataFromCookie(aCookieData);
}, this);
this.setUpdateTimer();
},
destroy: function() {
if (this.__inited) {
this.__inited = false;
OBSERVER_SERVICE.removeObserver(this, "profile-before-change", false);
OBSERVER_SERVICE.removeObserver(this, "cookie-changed", false);
this._logoutConnections.clear();
this.Users.clear();
}
},
appendSessionData: function(aXmlListsData) {
this.Users.appendSessionData(aXmlListsData);
},
getSessionDataForFlush: function() {
return this.Users.getSessionDataForFlush();
},
get isLogin() {
return !!this.Users.getAllAuthUsers().length;
},
getAllAuthUsers: function() {
return this.Users.getAllAuthUsers();
},
_setDataFromCookie: function(aCookieData, aValue) {
switch (aCookieData.name) {
case "yandex_login":
case "Eda_id":
break;
default:
return;
}
let cookieValue = arguments.length == 2 ? aValue : aCookieData.value;
this.Users.updateUser(aCookieData.path.replace(/^\/for\//, ""),
aCookieData.name == "yandex_login" ?
{ login: cookieValue } :
{ session: cookieValue });
},
_getCookies: function(aCookiesProps) {
let res = [];
let timeNow = parseInt(Date.now() / 1000, 10);
const nsICookie = Ci.nsICookie;
let cookiesEnum = gYaSearchService.cookieManager.enumerator;
outerloop:
while (cookiesEnum.hasMoreElements()) {
let cookie = cookiesEnum.getNext();
if (cookie && cookie instanceof nsICookie &&
cookie.host == ".yandex.ru" && (cookie.expires == 0 || timeNow < cookie.expires))
{
for (let [propName, propValue] in Iterator(aCookiesProps)) {
if (propValue instanceof RegExp) {
if (!propValue.test(cookie[propName]))
continue outerloop;
} else {
if (cookie[propName] != propValue)
continue outerloop;
}
}
let host = cookie.host;
let newCookie = {};
for each (let prop in ["name", "value", "host", "path", "expires"])
newCookie[prop] = cookie[prop];
res.push(newCookie);
}
}
return res;
},
_removeCookies: function(aCookiesProps) {
const cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
this._getCookies(aCookiesProps).forEach(function(aCookieData) {
try {
cookieManager.remove(aCookieData.host, aCookieData.name, aCookieData.path, false);
} catch (ex) {}
});
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "cookie-changed":
try {
aSubject.QueryInterface(Ci.nsICookie);
} catch(e) {}
if (!(aSubject && aSubject instanceof Ci.nsICookie))
return;
if (aSubject.host == ".yandex.ru" &&
aSubject.path.indexOf("/for/") == 0)
{
let val = "";
try {
val = aSubject.value.toString();
} catch(e) {}
if (aData == "deleted" || !val)
val = "";
this._setDataFromCookie(aSubject, val);
}
break;
case "profile-before-change":
this.destroy();
break;
default:
break;
}
},
getSessionCookie: function(aDomain, aLogin) {
let cookiesProps = {
path: "/for/" + aDomain,
name: "Eda_id"
};
return this._getCookies(cookiesProps)[0];
},
getLoginCookie: function(aDomain) {
let cookiesProps = {
path: "/for/" + aDomain,
name: "yandex_login"
};
return this._getCookies(cookiesProps)[0];
},
getDataForAllUsers: function() {
return this.Users.getDataForAllUsers();
},
getDataForUser: function(aLogin) {
return this.Users.getDataForUser(aLogin);
},
getTopAuth: function() {
return this.Users.getTopAuth();
},
isLoginHasAuth: function(aLogin) {
return this.Users.isLoginHasAuth(aLogin);
},
softDropAuthForLogin: function(aLogin) {
if (this.Users.softDropAuthForLogin(aLogin) == true)
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "mfd-list");
},
_getDomain: function(aBoxname) {
return aBoxname.split("@")[1];
},
dropAuthForDomain: function(aLogin, aCheckSwapUsersOnFinish) {
if (!aLogin)
return false;
let loginData = this.Users.getAuthUserForDomain(this._getDomain(aLogin));
if (!loginData)
return false;
return this.dropAuthForLogin(loginData.@boxname.toString(), false, aCheckSwapUsersOnFinish);
},
dropAuthForLogin: function(aLogin, aForgetLogin, aCheckSwapUsersOnFinish) {
if (!aLogin)
return false;
if (aForgetLogin)
gYaAuth.PasswordManager.removeUserData(aLogin, "mfd");
this._logoutConnections.cancel(aLogin);
let domain = this._getDomain(aLogin);
let url = "https://passport.yandex.ru/for/" + domain + "/passport?mode=logout&target=bar" +
"&yu=" + encodeURIComponent(gYaSearchService.yaAuth.Cookies.getYandexCookie("yandexuid", false) || "");
this.Users.softDropAuthForLogin(aLogin);
this._logoutConnections.add(aLogin,
gYaSearchService.xmlHttpRequest(url, {
callbackFunc: this._dropAuthForLoginCallback.bind(this, domain, aLogin, aCheckSwapUsersOnFinish)
}));
return true;
},
_dropAuthForLoginCallback: function(aReq, aDomain, aLogin, aCheckSwapUsersOnFinish) {
this._logoutConnections.remove(aLogin);
this._removeCookies({
name: "Eda_id",
path: "/for/" + aDomain
});
this._removeCookies({
name: "yandex_login",
path: "/for/" + aDomain
});
this._removeCookies({
name: "ed." + aDomain,
path: "/for"
});
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "login");
if (aCheckSwapUsersOnFinish)
gYaAuth.checkSwapUsers();
},
dropAuthForAllLogins: function() {
this.Users.getAllAuthUsers().forEach(function(aUserData) {
this.dropAuthForLogin(aUserData.boxname);
}, this);
},
_logoutConnections: {
_connections: {},
_getAliveConnection: function(aLogin) {
let connection = this._connections[aLogin];
try {
if (connection && connection.channel && connection.channel.isPending())
return connection;
} catch (ex) {}
return null;
},
add: function(aLogin, aRequest) {
this._connections[aLogin] = aRequest;
},
cancel: function(aLogin) {
let connection = this._getAliveConnection(aLogin);
if (connection)
connection.channel.cancel(Cr.NS_BINDING_ABORTED);
this.remove(aLogin);
},
remove: function(aLogin) {
delete this._connections[aLogin];
},
clear: function() {
this._connections = {};
}
},
_updateTimer: null,
setUpdateTimer: function(aTimeout) {
if (this._updateTimer)
this._updateTimer.cancel();
else
this._updateTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
if (typeof aTimeout == "undefined")
aTimeout = gYaSearchService.checkTimeOut._MailAndFeeds || 0;
let timeout = Math.max(0, aTimeout);
if (timeout > 0)
this._updateTimer.initWithCallback(this._updateTimerCallback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
},
_updateTimerCallback: {
notify: function() gYaMFD.updateDataForAllAccounts()
},
updateDataForAllAccounts: function() {
this.setUpdateTimer();
this.Users.getAllAuthUsers().forEach(function(aUser) {
this.refreshHTTPData("mfd-counter", aUser.boxname);
}, this);
},
checkNeedRefreshDataOnLocation: function(aURLPath, aDelay) {
let isMFDURL = /^for\//.test(aURLPath);
if (isMFDURL && aURLPath.match(/^for\/([^\/]*)\//)) {
let domain = RegExp.$1.toLowerCase();
if (domain) {
let loginData = this.Users.getAuthUserForDomain(domain);
if (loginData && loginData.@v.toString() > "0")
this.refreshHTTPData("mfd-counter", loginData.@boxname, aDelay || 70000);
}
}
return isMFDURL;
},
refreshHTTPData: function(aType, aLogin, aDelay) {
new G_Timer(
function() {
gYaMFD._refreshHTTPData(aType, aLogin);
}, aDelay || 10
)
},
_refreshHTTPData: function(aType, aLogin) {
let loginData = this.Users.getLoginData(aLogin);
if (!loginData)
return;
if (aType == "mfd-counter") {
let timeNow = Date.now();
let lastRequestTime = parseInt(loginData.@lastRequestTime.toString(), 10);
if (Math.abs(timeNow - lastRequestTime) < 10 * 1000)
return;
loginData.@lastRequestTime = timeNow;
}
let url = this.URL[aType].replace(/\{domain\}/, loginData.@domain);
gYaSearchService.refreshHTTPData(aType, {
url: url,
login: aLogin
});
},
onResponse: function(aDataType, aResponseText, aData) {
let loginData = this.Users.getLoginData(aData.login);
if (!loginData)
return;
let counterValue;
switch (aDataType) {
case "mfd-counter":
let counterData = gYaSearchService.safeE4Xml(aResponseText, null, "s");
if (!counterData)
return;
if (counterData.toXMLString() === "<s/>") {
this.softDropAuthForLogin(aData.login);
return;
}
let errorStr = counterData.@e.toString() || "0";
counterValue = (errorStr == "0" ? (parseInt(counterData.@v, 10) || 0) : 0);
loginData.@v = counterValue;
loginData.@lastVisited = Date.now();
if (counterValue > 0) {
this.refreshHTTPData("mfd-list", aData.login);
} else {
if (errorStr != "0")
loginData.list = <list/>;
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "mfd-list");
}
loginData.@e = errorStr;
break;
case "mfd-list":
counterValue = parseInt(loginData.@v, 10) || 0;
let permCounterValue = parseInt(loginData.@permCounter, 10) || 0;
let msgURLPrefix = "http://mail.yandex.ru/for/" + loginData.@domain + "/message?ids=";
let listData = gYaSearchService.parseMailListXMLString(aResponseText,
loginData.@mailLastMaxId.toString(),
msgURLPrefix);
if (!listData)
return;
if (listData == "No Auth") {
this.softDropAuthForLogin(aData.login);
return;
}
loginData.list = listData.list;
if (listData.newLastMaxId)
loginData.@mailLastMaxId = listData.newLastMaxId;
if (listData.newMailCounter > 0) {
if (listData.newMailCounter == gYaSearchService.maxUnreadInXML) {
let tmp = counterValue - permCounterValue;
listData.newMailCounter = tmp >= gYaSearchService.maxUnreadInXML ? tmp : 0;
}
gYaSearchService.notifyAboutNewItems("mailList", listData.newMailCounter,
{ from: listData.newLastItem.@from.toString(),
title: listData.newLastItem.@title.toString(),
mfdDomain: "/for/" + loginData.@domain.toString() });
}
loginData.@permCounter = counterValue;
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "mfd-list");
break;
default:
return;
}
},
decMailCounter: function(aMailId) {
this.Users.decMailCounter(aMailId);
}
};
(function() {
let UsersData = <mfd/>;
let Users = {
_users: {},
clear: function() {},
appendSessionData: function(aXMLListsData) {
for each (let savedLoginData in aXMLListsData.login) {
let boxname = savedLoginData.@boxname.toString();
if (boxname && /@/.test(boxname)) {
let loginData = UsersData.login.(@boxname == boxname)[0];
if (!loginData)
loginData = this._createEmptyLoginData(boxname);
["permCounter", "lastVisited", "mailLastMaxId"]
.forEach(function(aPropName) {
this["@" + aPropName] = (savedLoginData["@" + aPropName] || "").toString();
}, loginData);
loginData.@domain = boxname.split("@")[1];
if (!loginData.parent())
UsersData.appendChild(loginData);
}
}
},
getSessionDataForFlush: function() {
let mfdXML = <mfd/>;
for each (let loginData in UsersData.login) {
let clonedLogin = <login boxname={loginData.@boxname.toString()}
permCounter={loginData.@permCounter.toString()}
lastVisited={loginData.@lastVisited.toString()}
mailLastMaxId={loginData.@mailLastMaxId.toString()}/>;
mfdXML.appendChild(clonedLogin);
}
return mfdXML;
},
_createEmptyLoginData: function(aLogin) {
let nodeBefore = UsersData.login.(@boxname > aLogin)[0] || null;
let loginData = <login boxname={aLogin} domain={aLogin.split("@")[1]}
auth="false" v="0" permCounter="0">
<list/>
</login>;
UsersData.insertChildBefore(nodeBefore, loginData);
let user = gYaAuth.Users.addUser(aLogin);
user.auth.loginState = gYaAuth.LOGIN_STATES.NO_AUTH;
return loginData;
},
updateUser: function(aDomain, aCookiesData) {
aDomain = aDomain.replace(/^\/for\//, "");
let loginData,
authBefore = "false";
if (aCookiesData.login) {
loginData = UsersData.login.(@boxname == aCookiesData.login)[0] ||
this._createEmptyLoginData(aCookiesData.login);
authBefore = loginData.@auth.toString();
let sessionCookie = gYaMFD.getSessionCookie(aDomain, aCookiesData.login);
if (!sessionCookie) {
gYaMFD.softDropAuthForLogin(aCookiesData.login);
} else {
this.softDropAuthForDomain(aDomain);
loginData.@auth = true;
}
}
if ("session" in aCookiesData) {
if (!aCookiesData.session) {
this.softDropAuthForDomain(aDomain);
} else {
let loginCookie = gYaMFD.getLoginCookie(aDomain);
let login = loginCookie ? loginCookie.value : "";
if (login) {
loginData = UsersData.login.(@boxname == login)[0] ||
this._createEmptyLoginData(login);
authBefore = loginData.@auth.toString();
if (!aCookiesData.session) {
gYaMFD.softDropAuthForLogin(aCookiesData.login);
} else {
loginData.@auth = true;
}
}
}
}
if (loginData) {
let user = gYaAuth.Users.addUser(loginData.@boxname.toString());
let authAfter = loginData.@auth.toString();
if (authAfter == "true") {
user.auth.loginState = gYaAuth.LOGIN_STATES.AUTH;
} else {
if (user.auth.loginState == gYaAuth.LOGIN_STATES.AUTH)
user.auth.loginState = gYaAuth.LOGIN_STATES.NO_AUTH;
}
if (authAfter != authBefore)
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "login");
if (authAfter == "true" && authBefore == "false") {
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "mfd-list");
gYaMFD.refreshHTTPData("mfd-counter", loginData.@boxname.toString());
}
}
},
getLoginData: function(aLogin) {
return UsersData.login.(@boxname == aLogin)[0];
},
getAllAuthUsers: function() {
let result = [];
for each (let loginData in UsersData.login.(@auth == "true")) {
result.push({
domain: loginData.@domain.toString(),
boxname: loginData.@boxname.toString()
});
}
return result;
},
getDataForAllUsers: function() {
let counter = 0;
let listsArray = [];
for each (let loginData in UsersData.login.(@auth == "true")) {
counter += parseInt(loginData.@v.toString(), 10);
let list = loginData.list;
list.@boxname = loginData.@boxname.toString();
list.@domain = loginData.@domain.toString();
list.@type = "mfd";
list.@counter = loginData.@v;
listsArray.push(list);
}
let lists = <lists/>;
listsArray
.sort(function(a,b) (a.@boxname > b.@boxname) ? 1 : (a.@boxname < b.@boxname) ? -1 : 0)
.forEach(function(aList) lists.appendChild(aList));
return {
counter: counter,
lists: lists
}
},
getDataForUser: function(aLogin) {
let loginData = UsersData.login.(@boxname == aLogin).(@auth == "true");
if (!loginData)
return null;
let list = loginData.list;
list.@boxname = loginData.@boxname.toString();
list.@domain = loginData.@domain.toString();
list.@type = "mfd";
list.@counter = loginData.@v;
return {
counter: parseInt(loginData.@v, 10),
list: loginData.list
}
},
isLoginHasAuth: function(aLogin) {
return !!UsersData.login.(@auth == "true").(@boxname == aLogin.toLowerCase())[0];
},
getTopAuth: function() {
let resultLoginData = null;
for each (let loginData in UsersData.login.(@auth == "true")) {
if (!resultLoginData || resultLoginData.@boxname > loginData.@boxname)
resultLoginData = loginData;
}
if (!resultLoginData)
return null;
return {
"domain": resultLoginData.@domain.toString(),
"username": resultLoginData.@boxname.toString().split("@")[0],
"boxname": resultLoginData.@boxname.toString()
}
},
softDropAuthForDomain: function(aDomain) {
for each (let loginData in UsersData.login.(@auth == "true")) {
if (loginData.@boxname.toString().split("@")[1] == aDomain)
gYaMFD.softDropAuthForLogin(loginData.@boxname.toString());
}
},
softDropAuthForLogin: function(aLogin) {
let loginData = this.getLoginData(aLogin);
if (loginData && loginData.@auth.toString() == "true") {
loginData.@auth = false;
let user = gYaAuth.Users.getUser(aLogin);
if (user)
user.auth.loginState = gYaAuth.LOGIN_STATES.NO_AUTH;
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "login");
return true;
}
return false;
},
getAuthUserForDomain: function(aDomain) {
if (aDomain) {
for each (let loginData in UsersData.login.(@auth == "true"))
if (loginData.@boxname.toString().split("@")[1] == aDomain)
return loginData;
}
return null;
},
decMailCounter: function(aMailId) {
let item = UsersData.login.list.item.item.(@url == aMailId)[0];
if (!item)
return;
let parent = item.parent();
let loginData = parent.parent().parent();
delete parent.item[item.childIndex()];
if (!parent.item.length())
delete parent.parent().item[parent.childIndex()];
let counterValue = parseInt(loginData.@v, 10) || 0;
loginData.@v = Math.max(0, --counterValue);
let permCounterValue = parseInt(loginData.@permCounter, 10) || 0;
loginData.@permCounter = Math.max(0, --permCounterValue);
new G_Timer(function(){
OBSERVER_SERVICE.notifyObservers(null, "Ya-Refresh-Data", "mfd-list");
}, 1);
loginData.@lastRequestTime = 0;
gYaMFD.refreshHTTPData("mfd-counter", loginData.@boxname, 10000);
}
};
gYaMFD.Users = Users;
}());