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
/
filA832FDCDC392E4342F2960667EFF9E7F
< prev
next >
Wrap
Text File
|
2010-07-12
|
11KB
|
353 lines
var YaBookmarksUtils = {
get stringBundleSet() {
if (!this._strBS)
this._strBS = document.getElementById("yasearch-string-bundle-bookmarks");
return this._strBS;
},
__IOService: null,
get _IOService() {
if (!this.__IOService)
this.__IOService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return this.__IOService;
},
__missedIconCache: null,
_openCacheEntry: function(aKey, aAccess) {
try {
if (!this.__missedIconCache) {
const CACHE_SERVICE = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
this.__missedIconCache = CACHE_SERVICE.createSession("YandexMissedFaviconCache", Ci.nsICache.STORE_ANYWHERE, true);
if (!this.__missedIconCache)
return null;
}
return this.__missedIconCache.openCacheEntry(aKey, aAccess, true);
} catch(e) {}
return null;
},
__httpCacheSession: null,
get httpCacheSession() {
if (!this.__httpCacheSession) {
const CACHE_SERVICE = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
this.__httpCacheSession = CACHE_SERVICE.createSession("HTTP", Ci.nsICache.STORE_ANYWHERE, true);
this.__httpCacheSession.doomEntriesIfExpired = false;
}
return this.__httpCacheSession;
},
checkExpirationTime: function(aKey) {
try {
var cacheEntryDescriptor = this.httpCacheSession.openCacheEntry(aKey, Ci.nsICacheEntryDescriptor, false);
var expired = false;
var expirationTime = cacheEntryDescriptor.lastModified + 2592000;
if (cacheEntryDescriptor.expirationTime < expirationTime) {
cacheEntryDescriptor.setExpirationTime(expirationTime);
cacheEntryDescriptor.markValid();
expired = true;
}
cacheEntryDescriptor.close();
if (expired) {
try {
cacheEntryDescriptor = this.httpCacheSession.openCacheEntry(aKey, Ci.nsICache.ACCESS_READ, false);
} catch(ex) {}
}
} catch(e) { }
},
addToMissedIconCache: function(aKey, aError) {
var entry = this._openCacheEntry(aKey, Ci.nsICache.ACCESS_READ_WRITE);
if (!entry)
return;
if (entry.accessGranted == Ci.nsICache.ACCESS_WRITE) {
entry.setMetaDataElement("Icon", "Missed");
entry.setExpirationTime(parseInt(Date.now()/1000, 10) + (aError ? 86400 : 3600));
}
entry.markValid();
entry.close();
},
_isIconKnownMissing: function(aKey) {
let e = this._openCacheEntry(aKey, Ci.nsICache.ACCESS_READ);
if (e) {
e.close();
return true;
}
return false;
},
_makeURI: function(aURL) {
let uri = null;
try {
uri = this._IOService.newURI(aURL, null, null);
} catch(e) {
return false;
}
return uri;
},
_getHttpURIForURL: function(aURL) {
let uri = this._makeURI(aURL);
return (uri && /^https?$/.test(uri.scheme)) ? uri : false;
},
getFaviconURL: function(aURL) {
if (!aURL)
return false;
let uri = this._getHttpURIForURL(aURL);
if (!uri)
return false;
let url = uri.prePath + "/favicon.ico";
return this._isIconKnownMissing(url) ? false : url;
},
getFaviconURI: function(aURL) {
let url = this.getFaviconURL(aURL);
return url ? this._getHttpURIForURL(url) : false;
},
setFaviconForURL: function(aURL, aItem) {
return false;
},
onDragStart: function(aEvent, aXferData, aDragAction) {
var target = aEvent.target;
if (!/bookmark\-item/.test(target.getAttribute("class")))
return false;
switch (target.localName) {
case "menuitem":
let mozUrlData = target.getAttribute("statustext") + "\n" + target.getAttribute("label");
if ("dataTransfer" in aEvent) {
aEvent.dataTransfer.setData("text/x-moz-url", mozUrlData);
aEvent.dataTransfer.effectAllowed = "copyLink";
} else {
aXferData.data = new TransferData();
aXferData.data.addDataForFlavour("text/x-moz-url", mozUrlData);
}
break;
case "menu":
if (!("dataTransfer" in aEvent))
return false;
let folderId = target.getAttribute("yafolderid");
let bookmarkFolder = Ya.nsIYa.bookmarksRawXml.bookmarks..folder.(@id == folderId)[0];
if (!bookmarkFolder)
return false;
function createLink(linkElement) {
return {
title: linkElement.@name.toString(),
type: "text/x-moz-place",
uri: linkElement.@url.toString()
}
}
function createFolder(folderElement) {
let data = {
title: folderElement.@name.toString(),
type: "text/x-moz-place-container",
children: []
};
for each (var folder in folderElement.folder)
data.children.push(createFolder(folder));
for each (var link in folderElement.links.link)
data.children.push(createLink(link));
return data;
}
let dt = aEvent.dataTransfer;
dt.setData("text/x-moz-place-container", YaUtils.JSON.stringify(createFolder(bookmarkFolder)));
dt.effectAllowed = "copy";
break;
default:
return false;
}
return true;
},
hidePopups: function() {
[document.getElementById("yasearch-bookmarks-menupopup")]
.forEach(function(popup) {
if (popup && popup.hidePopup)
popup.hidePopup();
});
},
bookmarksPopupHidden: function(aEvent) {
delete this.popupTarget;
},
bookmarksPopupShow: function(aPopup) {
this.popupTarget = /bookmark\-item/.test(document.popupNode.getAttribute("class")) ? document.popupNode : null;
if (!this.popupTarget)
return false;
let menuItems = aPopup.getElementsByTagName("menuitem"),
menuItemsLength = menuItems.length,
targetIsFolder = (this.popupTarget.localName == "menu");
for (var i = 0; i < 3; i++)
menuItems[i].hidden = targetIsFolder;
menuItems[3].hidden = !targetIsFolder;
menuItems[menuItemsLength - 2].hidden = targetIsFolder;
menuItems[menuItemsLength - 1].hidden = !targetIsFolder;
if (targetIsFolder) {
let lastChild = this.popupTarget.firstChild.lastChild;
menuItems[3].setAttribute("disabled", !(lastChild && lastChild.localName == "menuitem"));
}
return true;
},
getFolderId: function(aEvent) {
var target = aEvent ? aEvent.target : this.popupTarget;
target = target.localName == "menu" ? target : target.parentNode.parentNode;
return target.hasAttribute("yafolderid") ? target.getAttribute("yafolderid") : null;
},
getItemID: function(aItem) {
return aItem.getAttribute("yafolderid") || aItem.getAttribute("yalinkid") || null;
},
addBookmark: function() {
Ya.addBookmark(this.getFolderId());
},
deleteBookmark: function() {
var target = this.popupTarget;
this.hidePopups();
var type = target.localName == "menu" ? "folder" : "link",
name = target.getAttribute("label") || "";
var rv = Ya.nsIYa.promptService.confirm(window,
this.stringBundleSet.getString("ConfirmDelete" + type + "Title"),
this.stringBundleSet.getFormattedString("ConfirmDelete" + type + "Msg", [name]));
if (rv)
Ya.nsIYa.bookmarksDeleteItem({ type: type,
id: this.getItemID(target),
callback: this.deleteBookmarkCallback });
},
deleteBookmarkCallback: function(aErrorType) {
if (!aErrorType)
return;
let t1 = [YaBookmarksUtils.stringBundleSet.getString("Action_delete_InTitle")];
let t2 = [YaBookmarksUtils.stringBundleSet.getString("Action_delete_InMessage")];
if (aErrorType == "input")
t2.unshift(t1);
let errorType = "Error_" + aErrorType + "_";
Ya.nsIYa.promptService.alert(window,
YaBookmarksUtils.stringBundleSet.getFormattedString(errorType + "Title", t1),
YaBookmarksUtils.stringBundleSet.getFormattedString(errorType + "Message", t2)
);
},
get _bmsvc() {
delete this._bmsvc;
return this._bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
},
copyFolderToPersonalPanel: function(aBookmarkFolderId) {
let bookmarkFolder = Ya.nsIYa.bookmarksRawXml.bookmarks..folder.(@id == aBookmarkFolderId)[0];
if (!bookmarkFolder)
return null;
return this._createFolder(this._bmsvc.toolbarFolder, bookmarkFolder);
},
_createFolder: function(aPlacesFolderId, aBookmarkFolder) {
let bmsvc = this._bmsvc;
let newFolderId = bmsvc.createFolder(aPlacesFolderId, aBookmarkFolder.@name.toString(), bmsvc.DEFAULT_INDEX);
for each (var folder in aBookmarkFolder.folder)
this._createFolder(newFolderId, folder);
for each (var link in aBookmarkFolder.links.link)
this._createLink(newFolderId, link);
return newFolderId;
},
copyLinkToPersonalPanel: function(aBookmarkLinkId) {
let bookmarkLink = Ya.nsIYa.bookmarksRawXml.bookmarks..link.(@id == aBookmarkLinkId)[0];
if (!bookmarkLink)
return null;
return this._createLink(this._bmsvc.toolbarFolder, bookmarkLink);
},
_createLink: function(aPlacesFolderId, aBookmarkLink) {
let uri = this._makeURI(aBookmarkLink.@url.toString());
if (!uri)
return null;
let name = aBookmarkLink.@name.toString();
let bmsvc = this._bmsvc;
return bmsvc.insertBookmark(aPlacesFolderId, uri, bmsvc.DEFAULT_INDEX, name);
},
copyBookmarkToPersonalPanel: function() {
var target = this.popupTarget;
if (target.localName === "menu" && target.hasAttribute("yafolderid"))
return this.copyFolderToPersonalPanel(target.getAttribute("yafolderid"));
if (target.localName === "menuitem" && target.hasAttribute("yalinkid"))
return this.copyLinkToPersonalPanel(target.getAttribute("yalinkid"));
return null;
},
editBookmark: function() {
Ya.addBookmark(this.getFolderId(), this.getItemID(this.popupTarget));
},
openBookmark: function(aPlace) {
Ya.loadURI(this.popupTarget.getAttribute("statustext"), aPlace);
},
openAllInTabs: function(aEvent) {
Ya.loadURIsInTabs(Ya.nsIYa.bookmarksGetLinksInFolder(this.getFolderId(aEvent)));
this.hidePopups();
}
};