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
/
fil3C94B6E2F359B9E12F12DBE383F345F7
< prev
next >
Wrap
Text File
|
2010-07-12
|
12KB
|
288 lines
function OverlayProvider(barApplication) {
this._application = barApplication;
this._logger = barApplication.core.Log4Moz.repository.getLogger(barApplication.name + ".XULOverlay");
this._commonItemPattern = new RegExp("^" + this._application.name + "\\.cb\\-(\\S+)\\-inst\\-(.+)$");
this._defaultItemPattern = new RegExp("^" + this._application.name + "\\.cb\\-default\\-(\\d+)$");
this._defaultSetIDs = {};
this._unicodeConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
this._unicodeConverter.charset = "UTF-8";
this._DOMSerializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].getService(Ci.nsIDOMSerializer);
this._overlayDocScel = ' \
<!DOCTYPE overlay [ \
<!ENTITY app.name "' + this._application.name + '"> \
<!ENTITY % barDTD SYSTEM "chrome://' + this._application.name + '/locale/custombar.dtd"> \
%barDTD; \
]> \
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> \
<script type="application/x-javascript" src="chrome://&app.name;/content/custombar/overlay_ctrl.js"/> \
<toolbarpalette id="BrowserToolbarPalette"/> \
</overlay>';
};
OverlayProvider.prototype = {
constructor: OverlayProvider,
clear: function Overlay_clear() {
this._overlayDoc = null;
},
newURI: function Overlay_newURI(aSpec, aOriginalCharset, aBaseURI) {
if (!aSpec)
return null;
let content = "";
try {
switch (aSpec.toLowerCase()) {
case "browser-overlay":
content = btoa(this._getBrowserOverlay());
break;
default:
return null;
}
}
catch (e) {
this._logger.error(this._application.core.Lib.misc.formatError(e));
this._logger.debug(e.stack);
}
let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
uri.spec = "data:application/vnd.mozilla.xul+xml;base64," + content;
return uri;
},
get currentSetIds() {
if (!this._currentSetIds)
this._currentSetIds = this._readCurrentSetIds();
return this._currentSetIds;
},
parseWidgetItemId: function Overlay_parseWidgetItemId(itemID, fullMode) {
var match = null;
if (match = itemID.match(this._commonItemPattern))
return {
prototypeID: match[1],
instanceID: match[2]
};
if (match = itemID.match(this._defaultItemPattern)) {
let presetItemIndex = parseInt(match[1], 10);
let presetWidgetInfo = this._application.defaultWidgetsInfo[presetItemIndex];
if (presetWidgetInfo) {
let itemInfo = {
prototypeID: presetWidgetInfo.protoID,
instanceID: 0,
isFromDefaultSet: true
};
if (fullMode) {
let instID;
if (presetItemIndex in this._defaultSetIDs)
itemInfo.instanceID = this._defaultSetIDs[presetItemIndex];
else
itemInfo.instanceID = this._defaultSetIDs[presetItemIndex] = this._application.getNewWidgetInstanceID();
itemInfo.settings = this._application.core.Lib.sysutils.copyObj(presetWidgetInfo.settings);
}
return itemInfo;
}
}
return null;
},
compileWidgetItemId: function Overlay_compileWidgetItemId(protoID, instanceID) {
return this._application.name + ".cb-" + protoID + "-inst-" + instanceID;
},
widgetItemRemoved: function Overlay_widgetItemRemoved(instID) {
for (let key in this._defaultSetIDs) {
if (this._defaultSetIDs[key] == instID) {
delete this._defaultSetIDs[key];
}
}
},
addProtoIDsToPalette: function Overlay_addProtoIDsToPalette(aNewProtoIDs) {
for each (let browserWindow in this._application.core.Lib.misc.getNavigatorWindows()) {
let doc = browserWindow.document;
let toolbox = doc.getElementById("navigator-toolbox");
let palette = toolbox.palette;
var [paletteItems, defaultSetIDs] = this._makePaletteItems(doc, aNewProtoIDs);
for each (let paletteItem in paletteItems) {
if (!palette.getElementsByAttribute("id", paletteItem.id).length)
palette.appendChild(paletteItem);
}
}
},
makePaletteItem: function Overlay_makePaletteItem(doc, widgetProto, instanceID) {
let toolbarItem;
if (!Ci.nsIWorker) {
let toolbox = doc.getElementById("navigator-toolbox");
palette = toolbox ? toolbox.palette : null;
if (palette) {
let existItem = palette.getElementsByTagName("toolbaritem")[0];
if (existItem) {
toolbarItem = existItem.cloneNode(false);
Array.slice(toolbarItem.attributes).forEach(function(attr) toolbarItem.removeAttribute(attr.name));
}
}
}
if (!toolbarItem)
toolbarItem = doc.createElementNS(this._consts.STR_XUL_NS, "toolbaritem");
toolbarItem.setAttribute("id", this.compileWidgetItemId(widgetProto.id, instanceID));
toolbarItem.setAttribute("xb-proto-id", widgetProto.id);
toolbarItem.setAttribute("xb-app", this._application.name);
toolbarItem.setAttribute("xb-widget", "true");
toolbarItem.setAttribute("label", widgetProto.name);
toolbarItem.setAttribute("image", widgetProto.unit.unitPackage.resolvePath(widgetProto.iconPath));
return toolbarItem;
},
_commonItemPattern: null,
_defaultItemPattern: null,
_defaultSetIDs: null,
_overlayDocScel: undefined,
_unicodeConverter: null,
_DOMSerializer: null,
_overlayDoc: null,
_logger: null,
_consts: {
STR_XUL_NS: "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
WARN_NO_SUCH_WIDGET: "No such widget ",
ERR_CREATE_ITEM: "Could not add widget palette item",
ERR_PACKAGE_REQUIRED: "Widget package required"
},
_getBrowserOverlay: function Overlay__getBrowserOverlay() {
this._overlayDoc = this._createBrowserOverlay();
return this._unicodeConverter.ConvertFromUnicode(this._DOMSerializer.serializeToString(this._overlayDoc));
},
_createBrowserOverlay: function Overlay__createBrowserOverlay() {
const DOMParser = Cc["@mozilla.org/xmlextras/domparser;1"].getService(Ci.nsIDOMParser);
var overlayDoc = DOMParser.parseFromString(this._overlayDocScel, "text/xml");
var toolbarPalette = overlayDoc.getElementById("BrowserToolbarPalette");
var [paletteItems, defaultSetIDs] = this._makePaletteItems(overlayDoc);
for each (let paletteItem in paletteItems)
toolbarPalette.appendChild(paletteItem);
return overlayDoc;
},
_makePaletteItems: function Overlay_makePaletteItems(overlayDoc, aProtoIDs) {
var paletteItems = [];
var defaultSetIDs = [];
var currentSetIDsData = this._readCurrentSetIds();
var widgetLibrary = this._application.widgetLibrary;
let protoIDs = arguments.length == 1 ? widgetLibrary.getWidgetProtoIDs() : (aProtoIDs || []);
for each (let protoID in protoIDs) {
let widgetProto = null;
try {
widgetProto = widgetLibrary.getWidgetProto(protoID);
}
catch (e) {
this._logger.error(this._consts.ERR_CREATE_ITEM + ". " +
this._application.core.Lib.misc.formatError(e));
continue;
}
let isUsed = false;
let protoInstHash = currentSetIDsData[widgetProto.id] || null;
if (protoInstHash) {
isUsed = true;
for each (let instID in protoInstHash) {
paletteItems.push(this.makePaletteItem(overlayDoc, widgetProto, instID));
this._application.getNewWidgetInstanceID();
if (widgetProto.isUnique)
break;
}
}
if (!widgetProto.isUnique || !isUsed) {
paletteItems.push(this.makePaletteItem(overlayDoc, widgetProto, 0));
}
}
if (arguments.length == 1) {
var presetItemsInfo = this._application.defaultWidgetsInfo;
var itemIndex = 0;
for each (let presetItemInfo in presetItemsInfo) {
let widgetProto = null;
try {
widgetProto = widgetLibrary.getWidgetProto(presetItemInfo.protoID);
}
catch (e) {
this._logger.error(this._consts.ERR_CREATE_ITEM + ". " +
this._application.core.Lib.misc.formatError(e));
continue;
}
let itemID = this._application.name + ".cb-default-" + itemIndex;
let paletteItem = this.makePaletteItem(overlayDoc, widgetProto, 0);
paletteItem.setAttribute("id", itemID);
paletteItems.push(paletteItem);
defaultSetIDs.push(itemID);
itemIndex++;
}
}
return [paletteItems, defaultSetIDs];
},
_readCurrentSetIds: function Overlay_readCurrentSetIds() {
var result = {};
var rdfService = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
var localStoreDataSource = rdfService.GetDataSource("rdf:local-store");
var allResources = localStoreDataSource.GetAllResources();
var currentSetResource = rdfService.GetResource("currentset");
while (allResources.hasMoreElements()) {
let res = allResources.getNext().QueryInterface(Ci.nsIRDFResource);
let tool = res.Value;
if (tool) {
var toolbarResource = rdfService.GetResource(tool);
var currentSetTarget = localStoreDataSource.GetTarget(toolbarResource, currentSetResource, true);
var currentSetStr = "";
if (currentSetTarget instanceof Ci.nsIRDFLiteral)
currentSetStr = currentSetTarget.Value;
if (currentSetStr) {
var currentSetIds = currentSetStr.split(",");
for (let i = 0, len = currentSetIds.length; i < len ; i++) {
var barWidgetIDMatch = currentSetIds[i].match(this._commonItemPattern);
if (barWidgetIDMatch) {
var widgetProtoID = barWidgetIDMatch[1];
var widgetInstance = barWidgetIDMatch[2];
var instArray = result[widgetProtoID];
if (!instArray) {
instArray = [];
result[widgetProtoID] = instArray;
}
instArray.push(widgetInstance);
}
}
}
}
}
return result;
}
};