Bug 1519755 - Fix more XBL binding errors at Lightning startup. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 14 Jan 2019 15:20:56 +1300
changeset 34194 582cf461149a7a0dbfa49dcc7da6c08a0d011061
parent 34193 a08967bc50305608b5921bd17d1e770111a16e1a
child 34195 f9cedb1d783436235deb2a82c838c2f8a223aa40
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersphilipp
bugs1519755
Bug 1519755 - Fix more XBL binding errors at Lightning startup. r=philipp
calendar/base/content/agenda-listbox.xml
calendar/base/content/calendar-chrome-startup.js
calendar/base/content/calendar-management.js
calendar/base/content/widgets/calendar-list-tree.xml
calendar/lightning/content/messenger-overlay-sidebar.js
--- a/calendar/base/content/agenda-listbox.xml
+++ b/calendar/base/content/agenda-listbox.xml
@@ -106,25 +106,22 @@
                                              flat="true"/>
           </xul:hbox>
         </xul:vbox>
       </xul:hbox>
     </content>
     <implementation>
       <field name="mAllDayItem">null</field>;
 
-      <constructor><![CDATA[
-          this.mAllDayItem = document.getAnonymousElementByAttribute(this, "anonid", "allday-item");
-      ]]></constructor>
-
       <method name="setOccurrence">
         <parameter name="aOccurrence"/>
         <parameter name="aPeriod"/>
         <body><![CDATA[
             this.mOccurrence = aOccurrence;
+            this.mAllDayItem = document.getAnonymousElementByAttribute(this, "anonid", "allday-item");
             this.mAllDayItem.occurrence = aOccurrence;
             let dateFormatter = cal.getDateFormatter();
             let periodStartDate = aPeriod.start.clone();
             periodStartDate.isDate = true;
             let periodEndDate = aPeriod.end;
             let startDate = this.mOccurrence[cal.dtz.startDateProp(this.mOccurrence)]
                                 .getInTimezone(cal.dtz.defaultTimezone);
             let endDate = this.mOccurrence[cal.dtz.endDateProp(this.mOccurrence)]
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -7,25 +7,25 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 /* exported commonInitCalendar, commonFinishCalendar */
 
 /**
  * Common initialization steps for calendar chrome windows.
  */
-function commonInitCalendar() {
+async function commonInitCalendar() {
     // load locale specific default values for preferences
     setLocaleDefaultPreferences();
 
     // Move around toolbarbuttons and whatever is needed in the UI.
     migrateCalendarUI();
 
     // Load the Calendar Manager
-    loadCalendarManager();
+    await loadCalendarManager();
 
     // set up the unifinder
     prepareCalendarToDoUnifinder();
 
     // Make sure we update ourselves if the program stays open over midnight
     scheduleMidnightUpdate(refreshUIBits);
 
     // Set up the command controller from calendar-common-sets.js
--- a/calendar/base/content/calendar-management.js
+++ b/calendar/base/content/calendar-management.js
@@ -78,20 +78,23 @@ function promptDeleteCalendar(aCalendar)
 
         calMgr.removeCalendar(aCalendar, removeFlags);
     }
 }
 
 /**
  * Called to initialize the calendar manager for a window.
  */
-function loadCalendarManager() {
+async function loadCalendarManager() {
     // Set up the composite calendar in the calendar list widget.
     let tree = document.getElementById("calendar-list-tree-widget");
     let compositeCalendar = cal.view.getCompositeCalendar(window);
+    if (!tree.__lookupSetter__("compositeCalendar")) {
+        await new Promise(resolve => tree.addEventListener("bindingattached", resolve, { once: true }));
+    }
     tree.compositeCalendar = compositeCalendar;
 
     // Initialize our composite observer
     compositeCalendar.addObserver(compositeObserver);
 
     // Create the home calendar if no calendar exists.
     let calendars = cal.getCalendarManager().getCalendars({});
     if (calendars.length) {
--- a/calendar/base/content/widgets/calendar-list-tree.xml
+++ b/calendar/base/content/widgets/calendar-list-tree.xml
@@ -13,16 +13,18 @@
     <!--
       - This binding implements a full calendar list, that automatically adds
       - and removes calendars when a calendar is registered or unregistered.
       -->
     <implementation>
       <constructor><![CDATA[
           let calMgr = cal.getCalendarManager();
           calMgr.addObserver(this.calMgrObserver);
+
+          this.dispatchEvent(new CustomEvent("bindingattached", { bubbles: false }));
       ]]></constructor>
       <destructor><![CDATA[
           let calMgr = cal.getCalendarManager();
           calMgr.removeObserver(this.calMgrObserver);
           this.calMgrObserver.listTree = null;
       ]]></destructor>
 
       <field name="mAddingFromComposite">false</field>
--- a/calendar/lightning/content/messenger-overlay-sidebar.js
+++ b/calendar/lightning/content/messenger-overlay-sidebar.js
@@ -368,25 +368,25 @@ var calendarItemTabType = {
 window.addEventListener("load", (e) => {
     let tabmail = document.getElementById("tabmail");
     tabmail.registerTabType(calendarTabType);
     tabmail.registerTabType(calendarItemTabType);
     tabmail.registerTabMonitor(calendarTabMonitor);
 });
 
 
-function ltnOnLoad(event) {
+async function ltnOnLoad(event) {
     // Check if the binary component was loaded
     checkCalendarBinaryComponent();
 
     document.getElementById("calendarDisplayDeck")
             .addEventListener("select", LtnObserveDisplayDeckChange, true);
 
     // Take care of common initialization
-    commonInitCalendar();
+    await commonInitCalendar();
 
     // Add an unload function to the window so we don't leak any listeners
     window.addEventListener("unload", ltnFinish);
 
     // Set up invitations manager
     scheduleInvitationsUpdate(FIRST_DELAY_STARTUP);
     cal.getCalendarManager().addObserver(gInvitationsCalendarManagerObserver);