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
/
fil15422A702B5854BAE1380B3E1254C8F3
< prev
next >
Wrap
Text File
|
2010-07-12
|
12KB
|
356 lines
var gFinalHeight = 50;
var gSlideIncrement = 1;
var gSlideTime = 10;
var gAlertListener = null;
var gAlertTextClickable = false;
var gAlertCookie = "";
var gExtensionStrings = null;
var gObserverIndex = -1;
var gExtensionManager = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager)
.QueryInterface(Ci.nsIExtensionManager_MOZILLA_1_8_BRANCH);
var gYaSearchService = Cc["@yandex.ru/yasearch;1"].getService(Ci.nsIYaSearch).wrappedJSObject;
var gAddonId = gYaSearchService.EXT_ID;
var gAddonXPIUrl = null;
function getBrandShortName() {
var brandStrings = document.getElementById("brandStrings");
return brandStrings.getString("brandShortName");
}
function getExtensionString(key, strings) {
if (strings)
return gExtensionStrings.getFormattedString(key, strings);
return gExtensionStrings.getString(key);
}
function prefillAlertInfo() {
gExtensionStrings = document.getElementById("yasearch-string-bundle-alerts");
var args = window.arguments;
gAlertCookie = args[3];
gAlertListener = args[4];
document.getElementById('alertImage').setAttribute('src', args[0]);
document.getElementById('alertTitleLabel').setAttribute('value', args[1]);
document.getElementById('alertTextDescription').innerHTML = args[2].replace(/(<\/?)/g, '$1html:');
for each (var a in document.getElementById('alertTextDescription').getElementsByTagName("a")) {
if (a.hasAttribute) {
a.setAttribute("tooltiptext", a.title || a.href);
if (a.href == "https://download.yandex.ru/bar/firefox/YandexBar.xpi" && gAlertCookie == "error") {
a.parentNode.style.display = "none";
document.getElementById("yaInstallActions").hidden = false;
_startUpdate(false);
}
}
}
}
function onAlertLoad() {
try {
var prefService = Cc["@mozilla.org/preferences-service;1"].getService();
prefService = prefService.QueryInterface(Ci.nsIPrefService);
var prefBranch = prefService.getBranch(null);
gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
} catch (ex) {}
gSlideTime /= 2;
sizeToContent();
var contentDim = document.getElementById("alertBox").boxObject;
if (window.innerWidth == contentDim.width + 1)
--window.innerWidth;
gFinalHeight = window.outerHeight;
window.outerHeight = 1;
_moveAlert();
setTimeout(animateAlert, gSlideTime);
}
function _moveAlert() {
window.moveTo(10, screen.availTop + screen.availHeight - window.outerHeight);
}
function animateAlert() {
if (window.outerHeight < gFinalHeight) {
window.outerHeight += gSlideIncrement;
_moveAlert();
setTimeout(animateAlert, gSlideTime);
}
}
function closeAlert() {
if (gAlertListener)
gAlertListener.observe(null, "alertfinished", gAlertCookie);
gExtensionManager.removeUpdateListenerAt(gObserverIndex);
window.close();
}
function onAlertClick(aEvent) {
if (gAlertListener)
gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
var target = aEvent.target;
if (target.localName.toLowerCase() == "a" && target.hasAttribute("href"))
gYaSearchService.loadURI(target.getAttribute("href"), "tab");
return false;
}
function _startUpdate(aVisible) {
gExtensionManager.update([gExtensionManager.getItemForID(gAddonId)], 1, false, new UpdateCheckListener(aVisible));
}
function startUpdate() {
document.getElementById("progressStatus").value = getExtensionString("updatingMsg");
document.getElementById("alertBox").hidden = true;
document.getElementById("progress").hidden = false;
_startUpdate(true);
sizeToContent();
_moveAlert();
}
function skipInstall() {
gAlertCookie = "cancelled";
closeAlert();
}
function restartApp() {
const nsIAppStartup = Ci.nsIAppStartup;
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", null);
if (cancelQuit.data)
return;
os.notifyObservers(null, "quit-application-granted", null);
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var windows = wm.getEnumerator(null);
while (windows.hasMoreElements()) {
var win = windows.getNext();
if (("tryToClose" in win) && !win.tryToClose())
return;
}
Cc["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
}
function DownloadManager() {
this._statusFormatKBMB = getExtensionString("statusFormatKBMB");
this._statusFormatKBKB = getExtensionString("statusFormatKBKB");
this._statusFormatMBMB = getExtensionString("statusFormatMBMB");
}
DownloadManager.prototype = {
_statusFormatKBMB : null,
_statusFormatKBKB : null,
_statusFormatMBMB : null,
onProgress: function(aAddon, aValue, aMaxValue) {
if (aAddon.id != gAddonId)
return;
document.getElementById("addonsProgress").value = Math.round((aValue / aMaxValue) * 100);
var status = document.getElementById("addonsProgressStatus");
var KBProgress = parseInt(aValue/1024 + .5);
var KBTotal = parseInt(aMaxValue/1024 + .5);
var statusPrevious = status.value;
var statusCurrent = this._formatKBytes(KBProgress, KBTotal);
if (statusCurrent != statusPrevious)
status.value = statusCurrent;
},
onStateChange: function(aAddon, aState, aValue) {
if (aAddon.id != gAddonId)
return;
const nsIXPIProgressDialog = Ci.nsIXPIProgressDialog;
switch (aState) {
case nsIXPIProgressDialog.DOWNLOAD_START:
setThrobberStatus(true);
document.getElementById("progressStatus").value = getExtensionString("downloadStartMsg");
break;
case nsIXPIProgressDialog.DOWNLOAD_DONE:
setThrobberStatus(false);
document.getElementById("progressStatus").value = getExtensionString("downloadDoneMsg");
break;
case nsIXPIProgressDialog.INSTALL_START:
document.getElementById("progressStatus").value = getExtensionString("installStartMsg");
break;
case nsIXPIProgressDialog.INSTALL_DONE:
setThrobberStatus(false);
if (aValue == 0 || aValue == 999) {
gAlertCookie = "installed";
document.getElementById("progressStatus").value = getExtensionString("installDoneSuccessMsg");
document.getElementById("yaRestartAppButton").disabled = false;
break;
} else if (aValue == -210) {
gAlertCookie = "cancelled";
document.getElementById("progressStatus").value = getExtensionString("installDoneCancelledMsg");
break;
}
document.getElementById("progressStatus").value = getExtensionString("installDoneErrorMsg");
var xpinstallStrings = document.getElementById("xpinstallStrings");
try {
var msg = xpinstallStrings.getString("error" + aValue);
}
catch (e) {
msg = xpinstallStrings.getFormattedString("unknown.error", [aValue]);
}
var title = getExtensionString("errorInstallTitle");
var message = getExtensionString("errorInstallMsg", [getBrandShortName(), aAddon.xpiURL, msg]);
var ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
ps.alert(window, title, message + "\n" + aValue);
break;
case nsIXPIProgressDialog.DIALOG_CLOSE:
gExtensionManager.sortTypeByProperty(Ci.nsIUpdateItem.TYPE_ADDON, "name", true);
break;
}
},
_formatKBytes: function (aKBytes, aTotalKBytes) {
var progressHasMB = parseInt(aKBytes/1000) > 0;
var totalHasMB = parseInt(aTotalKBytes/1000) > 0;
var format = "";
if (!progressHasMB && !totalHasMB) {
format = this._statusFormatKBKB;
format = this._replaceInsert(format, 1, aKBytes);
format = this._replaceInsert(format, 2, aTotalKBytes);
}
else if (progressHasMB && totalHasMB) {
format = this._statusFormatMBMB;
format = this._replaceInsert(format, 1, (aKBytes / 1000).toFixed(1));
format = this._replaceInsert(format, 2, (aTotalKBytes / 1000).toFixed(1));
}
else if (totalHasMB && !progressHasMB) {
format = this._statusFormatKBMB;
format = this._replaceInsert(format, 1, aKBytes);
format = this._replaceInsert(format, 2, (aTotalKBytes / 1000).toFixed(1));
}
return format;
},
_replaceInsert: function (text, index, value) {
return text.replace(new RegExp("#"+index), value);
},
QueryInterface: function (aIID) {
if (!aIID.equals(Ci.nsIAddonUpdateListener) &&
!aIID.equals(Ci.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
function setThrobberStatus(aState) {
document.getElementById("progressImage").setAttribute("class", aState ? "addonThrobber throbber" : "");
}
function UpdateCheckListener(aVisible) {
this._addons = [];
this._visible = aVisible;
}
UpdateCheckListener.prototype = {
_addons: [],
_visible: false,
onUpdateStarted: function() {},
onUpdateEnded: function() {
if (!this._visible)
return;
if (this._addons.length == 1) {
setThrobberStatus(true);
document.getElementById("progressStatus").value = getExtensionString("updateFoundMsg");
gAddonXPIUrl = this._addons[0].xpiURL;
if (/\.xpi$/.test(gAddonXPIUrl)) {
try {
var cacheSession = Cc["@mozilla.org/network/cache-service;1"]
.getService(Ci.nsICacheService)
.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
var cacheEntryDescriptor = cacheSession.openCacheEntry(gAddonXPIUrl, Ci.nsICacheEntryDescriptor, false);
if (cacheEntryDescriptor) {
cacheEntryDescriptor.doom();
cacheEntryDescriptor.close();
}
} catch(e) {}
}
gObserverIndex = gExtensionManager.addUpdateListener(new DownloadManager());
gExtensionManager.addDownloads(this._addons, this._addons.length, true);
} else {
document.getElementById("progressStatus").value = getExtensionString("updateNotFoundMsg");
}
},
onAddonUpdateStarted: function(addon) {
setThrobberStatus(true);
},
// TODO: remove this. not used
onAddonUpdateEnded: function(addon, status) {
if (!this._visible)
return;
setThrobberStatus(false);
const nsIAUCL = Ci.nsIAddonUpdateCheckListener;
switch (status) {
case nsIAUCL.STATUS_UPDATE:
this._addons.push(addon);
break;
case nsIAUCL.STATUS_FAILURE:
document.getElementById("progressStatus").value = getExtensionString("updateFailedMsg");
break;
case nsIAUCL.STATUS_DISABLED:
document.getElementById("progressStatus").value = getExtensionString("updateDisabledMsg");
break;
}
document.getElementById("yaInstallButton").disabled = false;
},
QueryInterface: function(iid) {
if (!iid.equals(Ci.nsIAddonUpdateCheckListener) &&
!iid.equals(Ci.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};