From e85796faf3b382ee673cf40a9d4146e2be23d756 Mon Sep 17 00:00:00 2001 From: Marshall Culpepper Date: Mon, 14 Jan 2013 23:40:51 -0800 Subject: [PATCH] Bug 823695: Part 1 - Send update errors after the shell is ready in B2G. r=fabrice --- b2g/chrome/content/shell.js | 6 ++++-- b2g/components/UpdatePrompt.js | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 2e45c3c2fad..0e916ba541c 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -1005,9 +1005,11 @@ window.addEventListener('ContentStart', function cr_onContentStart() { window.addEventListener('ContentStart', function update_onContentStart() { let updatePrompt = Cc["@mozilla.org/updates/update-prompt;1"] .createInstance(Ci.nsIUpdatePrompt); + if (!updatePrompt) { + return; + } - let content = shell.contentBrowser.contentWindow; - content.addEventListener("mozContentEvent", updatePrompt.wrappedJSObject); + updatePrompt.wrappedJSObject.handleContentStart(shell); }); (function geolocationStatusTracker() { diff --git a/b2g/components/UpdatePrompt.js b/b2g/components/UpdatePrompt.js index d2f4497bcb3..7640461b514 100644 --- a/b2g/components/UpdatePrompt.js +++ b/b2g/components/UpdatePrompt.js @@ -118,6 +118,7 @@ UpdatePrompt.prototype = { _applyPromptTimer: null, _waitingForIdle: false, _updateCheckListner: null, + _pendingEvents: [], get applyPromptTimeout() { return Services.prefs.getIntPref(PREF_APPLY_PROMPT_TIMEOUT); @@ -127,6 +128,16 @@ UpdatePrompt.prototype = { return Services.prefs.getIntPref(PREF_APPLY_IDLE_TIMEOUT); }, + handleContentStart: function UP_handleContentStart(shell) { + let content = shell.contentBrowser.contentWindow; + content.addEventListener("mozContentEvent", this); + + for (let i = 0; i < this._pendingEvents.length; i++) { + shell.sendChromeEvent(this._pendingEvents[i]); + } + this._pendingEvents.length = 0; + }, + // nsIUpdatePrompt // FIXME/bug 737601: we should have users opt-in to downloading @@ -237,16 +248,17 @@ UpdatePrompt.prototype = { }, sendChromeEvent: function UP_sendChromeEvent(aType, aDetail) { - let browser = Services.wm.getMostRecentWindow("navigator:browser"); - if (!browser) { - log("Warning: Couldn't send update event " + aType + - ": no content browser"); - return false; - } - let detail = aDetail || {}; detail.type = aType; + let browser = Services.wm.getMostRecentWindow("navigator:browser"); + if (!browser) { + this._pendingEvents.push(detail); + log("Warning: Couldn't send update event " + aType + + ": no content browser. Will send again when content becomes available."); + return false; + } + browser.shell.sendChromeEvent(detail); return true; },