49 if (typeof(
Cc) ==
"undefined")
50 var
Cc = Components.classes;
51 if (typeof(
Ci) ==
"undefined")
52 var
Ci = Components.interfaces;
53 if (typeof(
Cr) ==
"undefined")
54 var
Cr = Components.results;
55 if (typeof(
Cu) ==
"undefined")
56 var
Cu = Components.utils;
73 this._widget = aWidget;
87 restartRequired:
false,
103 _addOnInstallList:
null,
104 _nextAddOnToInstall: 0,
105 _addOnFileDownloader:
null,
118 initialize:
function addOnBundleInstallerSvc_initialize() {
126 finalize:
function addOnBundleInstallerSvc_finalize() {
128 if (this._addOnFileDownloader) {
129 this._addOnFileDownloader.listener =
null;
130 this._addOnFileDownloader.cancel();
131 this._addOnFileDownloader =
null;
136 this._addOnBundle =
null;
137 this._addOnInstallList =
null;
147 install:
function addOnBundleInstallerSvc_install(aAddOnBundle) {
149 this._addOnBundle = aAddOnBundle;
152 this._addOnInstallList = [];
153 var extensionCount = this._addOnBundle.bundleExtensionCount;
154 for (var
i = 0;
i < extensionCount;
i++) {
155 if (this._addOnBundle.getExtensionInstallFlag(
i)) {
156 var installInfo = { index:
i,
failed:
false };
157 this._addOnInstallList.push(installInfo);
162 this._downloadNextAddOnStart();
170 cancel:
function addOnBundleInstallerSvc_cancel() {
171 if (this._addOnFileDownloader) {
172 this._addOnFileDownloader.listener =
null;
173 this._addOnFileDownloader.cancel();
174 this._addOnFileDownloader =
null;
189 onProgress:
function addOnBundleInstallerSvc_onProgress() {
199 onComplete:
function addOnBundleInstallerSvc_onComplete() {
204 this._downloadNextAddOnComplete();
218 _update:
function addOnBundleInstallerSvc__update() {
220 var currentAddOnIndex =
221 this._addOnInstallList[this._nextAddOnToInstall].index;
224 var currentAddOnLabelElem = this._getElement(
"current_add_on_label");
225 currentAddOnLabelElem.value =
226 this._addOnBundle.getExtensionAttribute(currentAddOnIndex,
"name");
229 var totalProgressLabelElem = this._getElement(
"total_progress_label");
230 totalProgressLabelElem.value =
232 [ this._nextAddOnToInstall + 1,
233 this._addOnInstallList.length ]);
236 var progressMeterElem = this._getElement(
"progressmeter");
237 if (this._addOnFileDownloader)
238 progressMeterElem.value = this._addOnFileDownloader.percentComplete;
240 progressMeterElem.value = 0;
248 _downloadNextAddOnStart:
249 function addOnBundleInstallerSvc__downloadNextAddOnStart() {
251 if (this._nextAddOnToInstall == this._addOnInstallList.length) {
252 this._installAllAddOns();
258 this._addOnInstallList[this._nextAddOnToInstall].index;
261 this._addOnFileDownloader =
262 Cc[
"@songbirdnest.com/Songbird/FileDownloader;1"]
263 .createInstance(Ci.sbIFileDownloader);
264 this._addOnFileDownloader.listener =
this;
265 this._addOnFileDownloader.sourceURISpec =
266 this._addOnBundle.getExtensionAttribute(nextAddOnIndex,
"url");
267 this._addOnFileDownloader.destinationFileExtension =
"xpi";
270 this._addOnFileDownloader.start();
281 _downloadNextAddOnComplete:
282 function addOnBundleInstallerSvc__downloadNextAddOnComplete() {
284 var installInfo = this._addOnInstallList[this._nextAddOnToInstall];
285 if (this._addOnFileDownloader.succeeded)
286 installInfo.file = this._addOnFileDownloader.destinationFile;
288 installInfo.failed =
true;
289 this._addOnFileDownloader.listener =
null;
290 this._addOnFileDownloader =
null;
293 this._nextAddOnToInstall++;
294 this._downloadNextAddOnStart();
302 _installAllAddOns:
function addOnBundleInstallerSvc__installAddOns() {
304 for (var
i = 0;
i < this._addOnInstallList.length;
i++) {
305 var installInfo = this._addOnInstallList[
i];
306 if (!installInfo.failed)
307 this._installAddOnFile(installInfo);
311 this._widget.errorCount = this._presentErrors();
314 var
event = document.createEvent(
"Events");
315 event.initEvent(
"complete",
true,
true);
316 this._widget.dispatchEvent(
event);
327 function addOnBundleInstallerSvc__installAddOnFile(aInstallInfo) {
329 if (!aInstallInfo.file) {
330 aInstallInfo.failed =
true;
335 var extensionManager = Cc[
"@mozilla.org/extensions/manager;1"]
336 .getService(Ci.nsIExtensionManager);
340 extensionManager.installItemFromFile(aInstallInfo.file,
"app-profile");
341 this.restartRequired =
true;
344 Cu.reportError(
"Error installing add-on: " + ex);
347 aInstallInfo.failed =
true;
351 aInstallInfo.file.remove(
false);
361 _presentErrors:
function addOnBundleInstallerSvc__presentErrors() {
365 var errorListBoxElem = this._getElement(
"error_listbox");
366 for (var
i = 0;
i < this._addOnInstallList.length;
i++) {
368 var installInfo = this._addOnInstallList[
i];
369 if (!installInfo.failed)
376 var addOnBundleIndex = installInfo.index;
377 var addOnName = this._addOnBundle.getExtensionAttribute(addOnBundleIndex,
379 errorListBoxElem.appendItem(addOnName);
383 if (errorCount > 0) {
386 (
"add_on_bundle_installer.error.description1",
388 var descriptionTextNode = document.createTextNode(description);
389 var errorDescriptionElem = this._getElement(
"error_description_1");
390 errorDescriptionElem.appendChild(descriptionTextNode);
394 (
"add_on_bundle_installer.error.description2",
397 descriptionTextNode = document.createTextNode(description);
398 errorDescriptionElem = this._getElement(
"error_description_2");
399 errorDescriptionElem.appendChild(descriptionTextNode);
402 var statusDeckElem = this._getElement(
"status_deck");
403 var errorPanelElem = this._getElement(
"error_panel");
404 statusDeckElem.selectedPanel = errorPanelElem;
421 _getElement:
function addOnBundleInstallerSvc__getElement(aElementID) {
422 return document.getAnonymousElementByAttribute(this._widget,
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function SBStringBrandShortName()
function SBFormattedCountString(aKeyBase, aCount, aParams, aDefault, aStringBundle)
DataRemote prototype constructor
_getSelectedPageStyle s i
function addOnBundleInstallerSvc(aWidget)