Bug 1521480 - move conversation-browser this._conv and this.progressListener setup from connectedCallback to constructor to make chat theme preview work properly. r=florian
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 21 Jan 2019 15:51:15 +0200
changeset 33405 2560743a5174
parent 33404 1b078853f30d
child 33406 51560879ea98
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1521480
Bug 1521480 - move conversation-browser this._conv and this.progressListener setup from connectedCallback to constructor to make chat theme preview work properly. r=florian
chat/content/conversation-browser.js
--- a/chat/content/conversation-browser.js
+++ b/chat/content/conversation-browser.js
@@ -4,28 +4,86 @@
 
 "use strict";
 
 /* global MozXULElement */
 /* global initHTMLDocument serializeSelection getCurrentTheme isNextMessage getHTMLForMessage insertHTMLForMessage */
 /* global smileTextNode */
 /* global cleanupImMarkup */
 
-(function () { // Make <browser> defined now. It's lazily defined.
-  delete document.createElement("browser");
+(function () {
+  // <browser> is lazily set up through setElementCreationCallback,
+  // i.e. put into customElements the first time it's really seen.
+  // Create a fake to ensure browser exists in customElements, since otherwise
+  // we can't extend it. Then make sure this fake doesn't stay around.
+  if (!customElements.get("browser")) {
+    delete document.createElement("browser");
+  }
 })();
 
 /**
  * The chat conversation browser, i.e. the main content on the chat tab.
  * @augments {MozBrowser}
  */
 class MozConversationBrowser extends customElements.get("browser") {
   constructor() {
     super();
 
+    this._conv = null;
+
+    // @implements {nsIWebProgressListener}
+    this.progressListener = {
+      onStateChange: (progress, request, stateFlags, status) => {
+        if (!((stateFlags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) &&
+              (stateFlags & Ci.nsIWebProgressListener.STATE_STOP))) {
+          return;
+        }
+        if (!this._loadState) {
+          initHTMLDocument(this._conv, this.theme, this.contentDocument);
+          this._loadState = 1;
+          this._exposeMethodsToContent();
+          return;
+        }
+        this.removeProgressListener(this.progressListener);
+
+        this.initMagicCopy();
+
+        // We need to reset these variables here to avoid a race
+        // condition if we are starting to display a new conversation
+        // but the display of the previous conversation wasn't finished.
+        // This can happen if the user quickly changes the selected
+        // conversation in the log viewer.
+        this._lastMessage = null;
+        this._lastMessageIsContext = true;
+        this._firstNonContextElt = null;
+        this._messageDisplayPending = false;
+        this._pendingMessages = [];
+        this._nextPendingMessageIndex = 0;
+        this._pendingMessagesDisplayed = 0;
+        this._displayPendingMessagesCalls = 0;
+        this._sessions = [];
+        if (this.progressBar)
+          this.progressBar.hidden = true;
+
+        this.onChatNodeContentLoad = this.onContentElementLoad.bind(this);
+        this.contentChatNode.addEventListener("load", this.onChatNodeContentLoad, true);
+
+        // Notify observers to get the conversation shown.
+        Services.obs.notifyObservers(this, "conversation-loaded");
+      },
+      onProgressChange(progress, request, curSelf, maxSelf, curTotal, maxTotal) { },
+      onLocationChange(aprogress, request, location) { },
+      onStatusChange(progress, request, status, message) { },
+      onSecurityChange(progress, request, state) { },
+      QueryInterface: ChromeUtils.generateQI([
+        Ci.nsIWebProgressListener,
+        Ci.nsISupportsWeakReference],
+      ),
+    };
+
     // Make sure to load URLs externally.
     this.addEventListener("click", (event) => {
       // Right click should open the context menu.
       if (event.button == 2)
         return;
 
       // The 'click' event is fired even when the link is
       // activated with the keyboard.
@@ -98,18 +156,16 @@ class MozConversationBrowser extends cus
       ChromeUtils.import("resource:///modules/imContentSink.jsm");
     if (!("smileImMarkup" in window))
       ChromeUtils.import("resource:///modules/imSmileys.jsm");
     if (!("getCurrentTheme" in window))
       ChromeUtils.import("resource:///modules/imThemes.jsm");
 
     this._theme = null;
 
-    this._conv = null;
-
     this._loadState = 0;
 
     this.autoCopyEnabled = false;
 
     this.magicCopyPref = "messenger.conversations.selections.magicCopyEnabled";
 
     this.magicCopyInitialized = false;
 
@@ -134,65 +190,16 @@ class MozConversationBrowser extends cus
     this._displayPendingMessagesCalls = 0;
     this._sessions = [];
 
     this.progressBar = null;
 
     this.addEventListener("scroll", this.browserScroll);
     this.addEventListener("resize", this.browserResize);
 
-    // @implements {nsIWebProgressListener}
-    this.progressListener = {
-      onStateChange: (progress, request, stateFlags, status) => {
-        if (!((stateFlags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) &&
-              (stateFlags & Ci.nsIWebProgressListener.STATE_STOP))) {
-          return;
-        }
-        if (!this._loadState) {
-          initHTMLDocument(this._conv, this.theme, this.contentDocument);
-          this._loadState = 1;
-          this._exposeMethodsToContent();
-          return;
-        }
-        this.removeProgressListener(this.progressListener);
-
-        this.initMagicCopy();
-
-        // We need to reset these variables here to avoid a race
-        // condition if we are starting to display a new conversation
-        // but the display of the previous conversation wasn't finished.
-        // This can happen if the user quickly changes the selected
-        // conversation in the log viewer.
-        this._lastMessage = null;
-        this._lastMessageIsContext = true;
-        this._firstNonContextElt = null;
-        this._messageDisplayPending = false;
-        this._pendingMessages = [];
-        this._nextPendingMessageIndex = 0;
-        this._pendingMessagesDisplayed = 0;
-        this._displayPendingMessagesCalls = 0;
-        this._sessions = [];
-        if (this.progressBar)
-          this.progressBar.hidden = true;
-
-        this.onChatNodeContentLoad = this.onContentElementLoad.bind(this);
-        this.contentChatNode.addEventListener("load", this.onChatNodeContentLoad, true);
-
-        // Notify observers to get the conversation shown.
-        Services.obs.notifyObservers(this, "conversation-loaded");
-      },
-      onProgressChange(progress, request, curSelf, maxSelf, curTotal, maxTotal) { },
-      onLocationChange(aprogress, request, location) { },
-      onStatusChange(progress, request, status, message) { },
-      onSecurityChange(progress, request, state) { },
-      QueryInterface: ChromeUtils.generateQI([
-        Ci.nsIWebProgressListener,
-        Ci.nsISupportsWeakReference],
-      ),
-    };
 
     // @implements {nsIObserver}
     this.prefObserver = (subject, topic, data) => {
       if (this.magicCopyEnabled) {
         this.enableMagicCopy();
       } else {
         this.disableMagicCopy();
       }