firstRunAddOns.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 //
37 // First-run wizard add-ons widget services.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // First-run wizard add-ons widget imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Songbird imports.
49 Components.utils.import("resource://app/jsmodules/AddOnUtils.jsm");
50 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
51 
52 
53 //------------------------------------------------------------------------------
54 //
55 // First-run wizard add-ons widget services defs.
56 //
57 //------------------------------------------------------------------------------
58 
59 // Component manager defs.
60 if (typeof(Cc) == "undefined")
61  var Cc = Components.classes;
62 if (typeof(Ci) == "undefined")
63  var Ci = Components.interfaces;
64 if (typeof(Cr) == "undefined")
65  var Cr = Components.results;
66 if (typeof(Cu) == "undefined")
67  var Cu = Components.utils;
68 
69 
70 //------------------------------------------------------------------------------
71 //
72 // First-run wizard add-ons widget services.
73 //
74 //------------------------------------------------------------------------------
75 
83 function firstRunAddOnsSvc(aWidget) {
84  this._widget = aWidget;
85 }
86 
87 // Define the object.
88 firstRunAddOnsSvc.prototype = {
89  // Set the constructor.
91 
92  //
93  // Public widget services fields.
94  //
95  // addOnBundle Add-on bundle object.
96  //
97 
98  addOnBundle: null,
99 
100 
101  //
102  // Internal widget services fields.
103  //
104  // _widget First-run wizard add-ons widget.
105  // _domEventListenerSet Set of DOM event listeners.
106  // _addOnBundleRunning True if the add-on bundle services are running.
107  // _addOnBundleLoader Add-on bundle loader object.
108  //
109 
110  _widget: null,
111  _domEventListenerSet: null,
112  _addOnBundleRunning: false,
113  _addOnBundleLoader: null,
114 
115 
116  //----------------------------------------------------------------------------
117  //
118  // Widget services.
119  //
120  //----------------------------------------------------------------------------
121 
126  initialize: function firstRunAddOnsSvc_initialize() {
127  var _this = this;
128  var func;
129 
130  // Get the first-run wizard page element.
131  var wizardPageElem = this._widget.parentNode;
132 
133  // Create a DOM event listener set.
134  this._domEventListenerSet = new DOMEventListenerSet();
135 
136  // Initialize the add-on bundle services.
137  this._addOnBundleInitialize();
138 
139  // Listen for page show events.
140  func = function() { return _this._doPageShow(); };
141  this._domEventListenerSet.add(wizardPageElem,
142  "pageshow",
143  func,
144  false);
145 
146  // Listen for first-run wizard connection reset events.
147  func = function() { return _this._doConnectionReset(); };
148  this._domEventListenerSet.add(firstRunWizard.wizardElem,
149  "firstRunConnectionReset",
150  func,
151  false);
152 
153  // Update the UI.
154  this._update();
155  },
156 
157 
162  finalize: function firstRunAddOnsSvc_finalize() {
163  // Remove DOM event listeners.
164  if (this._domEventListenerSet) {
165  this._domEventListenerSet.removeAll();
166  }
167  this._domEventListenerSet = null;
168 
169  // Finalize the add-on bundle services.
170  this._addOnBundleFinalize();
171 
172  // Clear object fields.
173  this._widget = null;
174  this.addOnBundle = null;
175  },
176 
177 
182  saveSettings: function firstRunAddOnsSvc_saveSettings() {
183  // Add all add-ons in bundle to recommended add-ons blacklist.
184  if (this.addOnBundle) {
185  var extensionCount = this.addOnBundle.bundleExtensionCount;
186  for (var i = 0; i < extensionCount; i++) {
187  // Get the bundle add-on ID.
188  var addOnID = this.addOnBundle.getExtensionAttribute(i, "id");
189 
190  // Add add-on to blacklist.
191  AddOnBundleLoader.addAddOnToBlacklist(addOnID);
192  }
193  }
194  },
195 
196 
197  //----------------------------------------------------------------------------
198  //
199  // Widget event handling services.
200  //
201  //----------------------------------------------------------------------------
202 
207  _doPageShow: function firstRunAddOnsSvc__doPageShow() {
208  // Start the add-on bundle services.
209  this._addOnBundleStart();
210 
211  // Update the UI.
212  this._update();
213  },
214 
215 
220  _doConnectionReset: function firstRunAddOnsSvc__doConnectionReset() {
221  // Do nothing if the add-on bundle successfully loaded.
222  if (this.addOnBundle)
223  return;
224 
225  // Re-initialize the add-on bundle services.
226  this._addOnBundleFinalize();
227  this._addOnBundleInitialize();
228 
229  // Continue the add-on bundle services. They shouldn't start running until
230  // after the first time the first-run add-ons page is shown.
231  this._addOnBundleContinue();
232  },
233 
234 
235  //----------------------------------------------------------------------------
236  //
237  // Widget add-on bundle services.
238  //
239  //----------------------------------------------------------------------------
240 
245  _addOnBundleInitialize:
246  function firstRunAddOnSvc__addOnBundleInitialize() {
247  // Initialize the add-on bundle fields.
248  this.addOnBundle = null;
249  this._addOnBundleLoader = null;
250  },
251 
252 
257  _addOnBundleFinalize:
258  function firstRunAddOnSvc__addOnBundleFinalize() {
259  // Cancel the add-on bundle loader.
260  if (this._addOnBundleLoader) {
261  this._addOnBundleLoader.cancel();
262  this._addOnBundleLoader = null;
263  }
264 
265  // Clear add-on bundle object fields.
266  this.addOnBundle = null;
267  },
268 
269 
274  _addOnBundleStart: function firstRunAddOnSvc__addOnBundleStart() {
275  // Mark the add-on bundle services running and continue.
276  this._addOnBundleRunning = true;
277  this._addOnBundleContinue();
278  },
279 
280 
285  _addOnBundleContinue: function firstRunAddOnSvc__addOnBundleContinue() {
286  // Do nothing if not running.
287  if (!this._addOnBundleRunning)
288  return;
289 
290  // Get the add-ons.
291  this._getAddOns();
292  },
293 
294 
299  _getAddOns: function firstRunAddOnsSvc__getAddOns() {
300  // Start loading the add-on bundle.
301  if (!this._addOnBundleLoader) {
302  // Add all installed add-ons to the blacklist. This prevents an add-on
303  // from being presented if it was previously installed and then
304  // uninstalled.
305  AddOnBundleLoader.addInstalledAddOnsToBlacklist();
306 
307  // Create an add-on bundle loader that filters out installed and
308  // blacklisted add-ons.
309  this._addOnBundleLoader = new AddOnBundleLoader();
310  this._addOnBundleLoader.filterInstalledAddOns = true;
311  this._addOnBundleLoader.filterBlacklistedAddOns = true;
312 
313  // Start the add-on bundle loader.
314  var _this = this;
315  var func = function() { _this._getAddOns(); };
316  this._addOnBundleLoader.start(func);
317  }
318 
319  // Get the add-on bundle.
320  if (this._addOnBundleLoader.complete &&
321  Components.isSuccessCode(this._addOnBundleLoader.result)) {
322  // Set add-on bundle property for the first-run add-on bundle widget
323  this.addOnBundle = this._addOnBundleLoader.addOnBundle;
324 
325  // Set the add-on bundle object for the add-on bundle element.
326  var addOnBundleElem = this._getElement("add_on_bundle");
327  addOnBundleElem.addOnBundle = this._addOnBundleLoader.addOnBundle;
328  }
329 
330  // Update the UI.
331  this._update();
332  },
333 
334 
335  //----------------------------------------------------------------------------
336  //
337  // Internal widget services.
338  //
339  //----------------------------------------------------------------------------
340 
345  _update: function firstRunAddOnsSvc__update() {
346  // If not loading the add-on bundle, select the no status panel.
347  var selectedPanel;
348  if (!this._addOnBundleLoader) {
349  selectedPanel = this._getElement("no_status");
350  }
351  // Otherwise, if the add-on bundle loading has not completed, select the
352  // loading status panel.
353  else if (!this._addOnBundleLoader.complete) {
354  selectedPanel = this._getElement("add_ons_loading_status");
355  }
356  // Otherwise, if the add-on bundle loading completed with success, select
357  // the add-on bundle panel.
358  else if (Components.isSuccessCode(this._addOnBundleLoader.result)) {
359  selectedPanel = this._getElement("add_on_bundle");
360  }
361  // Otherwise, select the load failed status panel.
362  else {
363  selectedPanel = this._getElement("add_ons_load_failed_status");
364  }
365 
366  // Select the panel.
367  var statusDeckElem = this._getElement("status_deck");
368  statusDeckElem.selectedPanel = selectedPanel;
369 
370  // Handle any connection errors.
371  //XXXeps ideally, we wouldn't handle non-connection errors as connection
372  //XXXeps errors.
373  if (this._addOnBundleLoader &&
374  this._addOnBundleLoader.complete &&
375  !Components.isSuccessCode(this._addOnBundleLoader.result)) {
376  firstRunWizard.handleConnectionError();
377  }
378  },
379 
380 
390  _getElement: function firstRunAddOnsSvc__getElement(aElementID) {
391  return document.getAnonymousElementByAttribute(this._widget,
392  "anonid",
393  aElementID);
394  }
395 }
396 
const Cu
function Fx prototype initialize
const Cc
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
DataRemote prototype constructor
var _this
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
function firstRunAddOnsSvc(aWidget)
_getSelectedPageStyle s i
function AddOnBundleLoader()
Definition: AddOnUtils.jsm:93