Bug 603676 - Fire a UIReadyDelayed event for panel and feedback initialization [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 12 Oct 2010 11:30:19 -0700
changeset 66823 65cd9cc9b9dee7a9fbfba39a2fe2ed856fac25bb
parent 66822 e71c692a1f165ec8dabfbc7eda4ab16fb0c07869
child 66824 663364184127782323b1ae6778df34051d42ba72
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs603676
Bug 603676 - Fire a UIReadyDelayed event for panel and feedback initialization [r=mfinkle]
mobile/app/profile/extensions/feedback@mobile.mozilla.org/content/overlay.js
mobile/chrome/content/browser-ui.js
--- a/mobile/app/profile/extensions/feedback@mobile.mozilla.org/content/overlay.js
+++ b/mobile/app/profile/extensions/feedback@mobile.mozilla.org/content/overlay.js
@@ -38,24 +38,21 @@
 var Feedback = {
   init: function(aEvent) {
     let appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
     document.getElementById("feedback-about").setAttribute("desc", appInfo.version);
 
     // A simple frame script to fill in the referrer page
     messageManager.loadFrameScript("data:,addMessageListener('Feedback:InitPage', function(m) { content.document.getElementById('id_url').value = m.json.referrer; });", true);
 
-    // Try to delay the widget initialization during startup
-    messageManager.addMessageListener("DOMContentLoaded", function() {
-      // We only want to delay one time
-      messageManager.removeMessageListener("DOMContentLoaded", arguments.callee, true);
-
-      // We unhide the panelUI so the XBL and settings can initialize
+    // Delay the widget initialization during startup.
+    window.addEventListener("UIReadyDelayed", function(aEvent) {
+      window.removeEventListener(aEvent.type, arguments.callee, false);
       document.getElementById("feedback-container").hidden = false;
-    });
+    }, false);
   },
 
   openFeedback: function(aURL) {
     let currentURL = Browser.selectedBrowser.currentURI.spec;
     let newTab = BrowserUI.newTab(aURL);
 
     // Tell the feedback page to fill in the referrer URL
     newTab.browser.messageManager.addMessageListener("DOMContentLoaded", function() {
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -440,25 +440,33 @@ var BrowserUI = {
     window.addEventListener("keydown", this, true);
 
     // listening escape to dismiss dialog on VK_ESCAPE
     window.addEventListener("keypress", this, true);
 
     // listening AppCommand to handle special keys
     window.addEventListener("AppCommand", this, true);
 
-    // Push the panel initialization out of the startup path
-    // (Using a message because we have no good way to delay-init [Bug 535366])
+    // We can delay some initialization until after startup.  We wait until
+    // the first page is shown, then dispatch a UIReadyDelayed event.
     messageManager.addMessageListener("pageshow", function() {
       if (getBrowser().currentURI.spec == "about:blank")
         return;
 
-      // We only want to delay one time
       messageManager.removeMessageListener("pageshow", arguments.callee, true);
 
+      let event = document.createEvent("Events");
+      event.initEvent("UIReadyDelayed", true, false);
+      window.dispatchEvent(event);
+    });
+
+    // Delay the panel UI and Sync initialization.
+    window.addEventListener("UIReadyDelayed", function(aEvent) {
+      window.removeEventListener(aEvent.type, arguments.callee, false);
+
       // We unhide the panelUI so the XBL and settings can initialize
       Elements.panelUI.hidden = false;
 
       // Init the views
       ExtensionsView.init();
       DownloadsView.init();
       PreferencesView.init();
       ConsoleView.init();
@@ -468,17 +476,17 @@ var BrowserUI = {
       Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
           .ensureContentProcess();
 #endif
 
 #ifdef MOZ_SERVICES_SYNC
       // Init the sync system
       WeaveGlue.init();
 #endif
-    });
+    }, false);
 
     FormHelperUI.init();
     FindHelperUI.init();
     PageActions.init();
   },
 
   uninit: function() {
     ExtensionsView.uninit();