50 addOnBundleURLPref:
"songbird.url.firstrun",
51 addOnBundleBlacklistPref:
"songbird.recommended_addons.update.blacklist",
52 addOnBundleDataLoadTimeout: 15000,
53 addOnBundleCacheFileName:
"recommendedAddOnBundle.xml"
63 Components.utils.import(
"resource://app/jsmodules/RDFHelper.jsm");
72 const Cc = Components.classes;
73 const Ci = Components.interfaces;
74 const Cr = Components.results;
75 const Cu = Components.utils;
103 function AddOnBundleLoader_addInstalledAddOnsToBlacklist() {
105 var installedAddOnList =
RDFHelper.help(
"rdf:addon-metadata",
106 "urn:songbird:addon:root",
110 for (var
i = 0;
i < installedAddOnList.length;
i++) {
111 this.addAddOnToBlacklist(installedAddOnList[
i].
id);
123 function AddOnBundleLoader_addAddOnToBlacklist(aAddOnID) {
130 .getService(
Ci.fuelIApplication);
132 Application.prefs.getValue(
AddOnUtilsCfg.addOnBundleBlacklistPref,
"");
133 if (blacklist.length > 0)
134 blacklist = blacklist.split(
",");
139 for (var
i = 0;
i < blacklist.length;
i++) {
140 if (blacklist[
i] == aAddOnID)
145 blacklist.push(aAddOnID);
146 Application.prefs.setValue(
AddOnUtilsCfg.addOnBundleBlacklistPref,
147 blacklist.join(
","));
171 filterInstalledAddOns:
false,
172 filterBlacklistedAddOns:
false,
173 readFromCache:
false,
188 _completionCallback:
null,
206 start:
function AddOnBundleLoader_start(aCompletionCallback) {
207 this._completionCallback = aCompletionCallback;
208 this._loadAddOnBundle();
216 cancel:
function AddOnBundleLoader_cancel() {
219 this._cancelled =
true;
222 this.addOnBundle =
null;
223 this._completionCallback =
null;
240 onDownloadComplete:
function AddOnBundleLoader_onDownloadComplete(aBundle) {
241 this.complete =
true;
242 this._loadAddOnBundle();
253 onError:
function AddOnBundleLoader_onDownloadComplete_onError(aBundle) {
254 this.result =
Cr.NS_ERROR_FAILURE;
255 this.complete =
true;
256 this._loadAddOnBundle();
270 _loadAddOnBundle:
function AddOnBundleLoader__loadAddOnBundle() {
276 if (!this.addOnBundle) {
278 this.addOnBundle =
Cc[
"@songbirdnest.com/Songbird/Bundle;1"]
279 .createInstance(
Ci.sbIBundle);
280 this.addOnBundle.bundleId =
"firstrun";
283 if (this.readFromCache)
284 this._readAddOnBundleFromCache();
286 this._readAddOnBundleFromServer();
294 if (Components.isSuccessCode(
this.result)) {
296 if (!this.readFromCache)
297 this._writeAddOnBundleToCache();
300 if (this.filterBlacklistedAddOns)
301 this._removeBlacklistedAddOns();
304 if (this.filterInstalledAddOns)
305 this._removeInstalledAddOns();
309 if (this._completionCallback)
310 this._completionCallback(
this);
318 _readAddOnBundleFromServer:
319 function AddOnBundleLoader__readAddOnBundleFromServer() {
321 var Application =
Cc[
"@mozilla.org/fuel/application;1"]
322 .getService(
Ci.fuelIApplication);
323 this.addOnBundle.bundleURL = Application.prefs.getValue
324 (this._cfg.addOnBundleURLPref,
329 this.addOnBundle.addBundleDataListener(
this);
330 this.addOnBundle.retrieveBundleData
331 (this._cfg.addOnBundleDataLoadTimeout);
337 this.result =
Cr.NS_ERROR_FAILURE;
338 this.complete =
true;
347 _readAddOnBundleFromCache:
348 function AddOnBundleLoader__readAddOnBundleFromCache() {
350 var recommendedAddOnBundleFile = this._getRecommendedAddOnCacheFile();
353 if (!recommendedAddOnBundleFile.exists()) {
354 this.result =
Cr.NS_ERROR_FAILURE;
355 this.complete =
true;
359 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
360 .getService(
Ci.nsIIOService);
361 var fileURI = ioService.newFileURI(recommendedAddOnBundleFile);
362 this.addOnBundle.bundleURL = fileURI.spec;
366 this.addOnBundle.retrieveLocalBundleData();
367 this.complete =
true;
373 this.result =
Cr.NS_ERROR_FAILURE;
374 this.complete =
true;
383 _writeAddOnBundleToCache:
384 function AddOnBundleLoader__writeAddOnBundleToCache() {
386 var recommendedAddOnBundleFile = this._getRecommendedAddOnCacheFile();
389 var outputStream =
Cc[
"@mozilla.org/network/file-output-stream;1"]
390 .createInstance(
Ci.nsIFileOutputStream);
391 outputStream.init(recommendedAddOnBundleFile,
398 outputStream.write(this.addOnBundle.bundleDataText,
399 this.addOnBundle.bundleDataText.length);
403 outputStream.close();
414 _getRecommendedAddOnCacheFile:
415 function AddOnBundleLoader__getRecommendedAddOnCacheFile() {
417 var recommendedAddOnBundleFile =
418 Cc[
"@mozilla.org/file/directory_service;1"]
419 .getService(
Ci.nsIProperties)
420 .get(
"ProfD",
Ci.nsIFile);
421 recommendedAddOnBundleFile.append(this._cfg.addOnBundleCacheFileName);
423 return recommendedAddOnBundleFile;
431 _removeInstalledAddOns:
function AddOnBundleLoader__removeInstalledAddOns() {
433 var installedAddOnList =
RDFHelper.help(
"rdf:addon-metadata",
434 "urn:songbird:addon:root",
438 var installedAddOnTable = {};
439 for (var
i = 0;
i < installedAddOnList.length;
i++) {
440 var installedAddOn = installedAddOnList[
i];
441 installedAddOnTable[installedAddOn.id] = installedAddOn;
445 var extensionCount = this.addOnBundle.bundleExtensionCount;
446 for (var
i = extensionCount - 1;
i >= 0;
i--) {
448 var addOnID = this.addOnBundle.getExtensionAttribute(
i,
"id");
451 if (installedAddOnTable[addOnID])
452 this.addOnBundle.removeExtension(
i);
461 _removeBlacklistedAddOns:
462 function AddOnBundleLoader__removeBlacklistedAddOns() {
464 var Application =
Cc[
"@mozilla.org/fuel/application;1"]
465 .getService(
Ci.fuelIApplication);
467 Application.prefs.getValue(this._cfg.addOnBundleBlacklistPref,
"");
468 if (blacklist.length > 0)
469 blacklist = blacklist.split(
",");
474 var blacklistedAddOnTable = {};
475 for (var
i = 0;
i < blacklist.length;
i++) {
476 var blacklistedAddOnID = blacklist[
i];
477 blacklistedAddOnTable[blacklistedAddOnID] =
true;
481 var extensionCount = this.addOnBundle.bundleExtensionCount;
482 for (var
i = extensionCount - 1;
i >= 0;
i--) {
484 var addOnID = this.addOnBundle.getExtensionAttribute(
i,
"id");
487 if (blacklistedAddOnTable[addOnID])
488 this.addOnBundle.removeExtension(
i);
const DEFAULT_PERMISSIONS
function RDFHelper(aRdf, aDatasource, aResource, aNamespaces)
DataRemote prototype constructor
_getSelectedPageStyle s i
function AddOnBundleLoader()