firstRunAppUpdate.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  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
27 
36 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38 //
39 // First-run wizard application update widget services.
40 //
41 //------------------------------------------------------------------------------
42 //------------------------------------------------------------------------------
43 
44 // Component manager defs.
45 if (!("Cc" in this))
46  this["Cc"] = Components.classes;
47 if (!("Ci" in this))
48  this["Ci"] = Components.interfaces;
49 if (!("Cr" in this))
50  this["Cr"] = Components.results;
51 if (!("Cu" in this))
52  this["Cu"] = Components.utils;
53 
54 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
55 Cu.import("resource://app/jsmodules/DebugUtils.jsm");
56 
57 //------------------------------------------------------------------------------
58 //
59 // First-run wizard application update widget services configuration.
60 //
61 //------------------------------------------------------------------------------
62 
64  /***** public getters *****/
65  get updateCheckState() this.mUpdateCheckState,
66 
67  get update() this.mUpdate,
68  set update(val) this.mUpdate = val,
69 
70  /***** member variables *****/
71 
75  mUpdateService: null,
76 
80  mUpdateChecker: null,
81 
85  mUpdate: null,
86 
90  mStringBundle: null,
91 
96  mUpdateCheckState: null,
97  K_HAS_UPDATE_STATE_FALSE: 0, // Check complete, no update
98  K_HAS_UPDATE_STATE_TRUE: 1, // Check complete, has update
99  K_HAS_UPDATE_STATE_UNKNOWN: 2, // Not started check yet
100  K_HAS_UPDATE_STATE_CHECKING: 3, // Check in progress
101 
102  /***** public functions *****/
103 
104  LOG: DebugUtils.generateLogFunction("firstRunAppUpdate", 3),
105  TRACE: DebugUtils.generateLogFunction("firstRunAppUpdate", 5),
106 
112  getString: function firstRunAppUpdate_getString(key, args) {
113  if (args) {
114  return this.mStringBundle.format(key, args);
115  }
116  return this.mStringBundle.get(key);
117  },
118 
122  init: function firstRunAppUpdate_init() {
123  this.TRACE(arguments.callee.name);
124  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_UNKNOWN;
125  this.wrappedJSObject = this;
126  addEventListener("pageshow", this.onPageShow, false);
127  addEventListener("unload", this.onUnload, false);
128  },
129 
130  onUnload: function firstRunAppUpdate_onUnload(aEvent) {
131  removeEventListener("unload", arguments.callee, false);
132  removeEventListener("pageshow", firstRunAppUpdate.onPageShow, false);
133  },
134 
138  onPageShow: function firstRunAppUpdate_onPageShow(event) {
139  let currentPage = document.documentElement.currentPage;
140  let id = currentPage.id.replace(/_(.)/g,
141  function(x, y) y.toUpperCase());
142  if (("onPageShow_" + id) in firstRunAppUpdate) {
143  firstRunAppUpdate.TRACE("on page show: " + id);
144  firstRunAppUpdate["onPageShow_" + id]();
145  }
146  },
147 
151  onPageShow_firstRunWelcomePage: function firstRunAppUpdate_WelcomePage() {
152  this.TRACE(arguments.callee.name);
153  let doCheck =
154  Application.prefs.getValue("songbird.firstrun.check.app-update", false);
155  if (!doCheck) {
156  // checking for app updates on first run is disabled
157  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_FALSE;
158  }
159  else if (this.mUpdateCheckState == this.K_HAS_UPDATE_STATE_UNKNOWN) {
160  this.checkForUpdate();
161  }
162  },
163 
170  checkForUpdate: function firstRunAppUpdate_checkForUpdate() {
171  this.TRACE(arguments.callee.name);
172  if (!this.mUpdateService.canApplyUpdates) {
173  // we can't actually apply any updates anyway :|
174  this.TRACE("Can't apply updates, skipping");
175  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_FALSE;
176  this.onUpdateStateChange();
177  }
178  else {
179  this.TRACE("Checking for updates...");
180  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_CHECKING;
181  this.mUpdateChecker.checkForUpdates(this, true);
182  }
183  },
184 
185  /***** XPCOM interfaces *****/
186 
190  onProgress: function firstRunAppUpdate_onProgress(aRequest,
191  aPosition,
192  aTotal)
193  {
194  /* ignore */
195  },
196 
197  onCheckComplete: function firstRunAppUpdate_onCheckComplete(aRequest,
198  aUpdates,
199  aUpdateCount)
200  {
201  this.LOG("update check complete: " + aUpdateCount + " updates found");
202  var update = this.mUpdateService.selectUpdate(aUpdates, aUpdateCount);
203  if (update) {
204  this.mUpdate = update;
205  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_TRUE;
206  }
207  else {
208  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_FALSE;
209  }
210  this.onUpdateStateChange();
211  },
212 
213  onError: function firstRunAppUpdate_onError(aRequest, aUpdate) {
214  this.LOG("update check error");
215  let currentPage = document.documentElement.currentPage;
216  if (currentPage.id == "first_run_app_update_check_page") {
217  // if we're on the checking page, we need to bail
218  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_FALSE;
219  }
220  else {
221  // flip the state back to unknown so we can re-check if we end up going
222  // to the check for updates page again
223  this.mUpdateCheckState = this.K_HAS_UPDATE_STATE_UNKNOWN;
224  }
225  // If we're on the checking page, advance
226  this.onUpdateStateChange();
227  },
228 
229  /* helper for nsIUpdateCheckListener */
230  onUpdateStateChange: function firstRunAppUpdate_onUpdateStateChange() {
231  let currentPage = document.documentElement.currentPage;
232  if (currentPage.id != "first_run_app_update_check_page") {
233  return;
234  }
235  this.mUpdateChecker = null;
236  let nextId = null;
237  if (this.mUpdateCheckState == this.K_HAS_UPDATE_STATE_TRUE) {
238  this.TRACE("Update state change: found update");
239  nextId = currentPage.getAttribute("next");
240  }
241  else {
242  // no update
243  this.TRACE("Update state change: no update");
244  nextId = currentPage.getAttribute("next_skip");
245  }
246  // always use goTo rather than advance because we never want rewind() to
247  // get back to this page
248  document.documentElement.goTo(nextId);
249  },
250 
251  /***** XPCOM goop *****/
252  QueryInterface:XPCOMUtils.generateQI([Ci.nsIUpdateCheckListener])
253 };
254 
259 XPCOMUtils.defineLazyServiceGetter(firstRunAppUpdate,
260  "mUpdateService",
261  "@mozilla.org/updates/update-service;1",
262  "nsIApplicationUpdateService2");
263 XPCOMUtils.defineLazyGetter(firstRunAppUpdate,
264  "mUpdateChecker",
265  function() {
266  return Cc["@mozilla.org/updates/update-checker;1"]
267  .createInstance(Ci.nsIUpdateChecker);
268  });
269 XPCOMUtils.defineLazyGetter(firstRunAppUpdate,
270  "mStringBundle",
271  function() {
272  return new SBStringBundle("chrome://mozapps/locale/update/updates.properties");
273  });
274 
278 addEventListener("load",
279  function(aEvent) {
280  removeEventListener(aEvent.type, arguments.callee, false);
281  firstRunAppUpdate.init();
282  },
283  false);
const Cu
const Cc
var args
Definition: alert.js:8
#define LOG(args)
var Application
Definition: sbAboutDRM.js:37
menuItem id
Definition: FeedWriter.js:971
var _
var event
sbOSDControlService prototype QueryInterface
var firstRunAppUpdate
_window init
Definition: FeedWriter.js:1144
function TRACE(s)
this _dialogInput val(dateText)
function SBStringBundle(aBundle)
return null
Definition: FeedWriter.js:1143
return!aWindow arguments!aWindow arguments[0]
const Ci
this removeEventListener("load", this.__SS_restore, true)
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36
addEventListener("load", function(aEvent){removeEventListener(aEvent.type, arguments.callee, false);firstRunAppUpdate.init();}, false)
function onPageShow()