Bug 1355760 - detect setImageElement to not run on Chrome browser tab;r=rickychien draft
authorFred Lin <gasolin@mozilla.com>
Thu, 13 Apr 2017 16:16:32 +0800
changeset 562446 1b79b787cfac594433c4ca831a99049958cdebcb
parent 561886 48958ca4267adc86ea57f3701645d5e0222d792e
child 624246 d5d8d74bdbb538b413eed80cc785b627b43b6017
push id54033
push userbmo:gasolin@mozilla.com
push dateFri, 14 Apr 2017 01:53:59 +0000
reviewersrickychien
bugs1355760
milestone55.0a1
Bug 1355760 - detect setImageElement to not run on Chrome browser tab;r=rickychien MozReview-Commit-ID: 4RODBcbmDBo
devtools/client/netmonitor/src/waterfall-background.js
--- a/devtools/client/netmonitor/src/waterfall-background.js
+++ b/devtools/client/netmonitor/src/waterfall-background.js
@@ -27,28 +27,42 @@ const STATE_KEYS = [
  * Creates the background displayed on each waterfall view in this container.
  */
 function WaterfallBackground() {
   this.canvas = document.createElementNS(HTML_NS, "canvas");
   this.ctx = this.canvas.getContext("2d");
   this.prevState = {};
 }
 
+/**
+ * Changes the element being used as the CSS background for a background
+ * with a given background element ID.
+ *
+ * The funtion wrap the Firefox only API. Waterfall Will not draw the
+ * vertical line when running on non-firefox browser.
+ * Could be fixed by Bug 1308695
+ */
+function setImageElement(imageElementId, imageElement) {
+  if (document.mozSetImageElement) {
+    document.mozSetImageElement(imageElementId, imageElement);
+  }
+}
+
 WaterfallBackground.prototype = {
   draw(state) {
     // Do a shallow compare of the previous and the new state
     const shouldUpdate = STATE_KEYS.some(key => this.prevState[key] !== state[key]);
     if (!shouldUpdate) {
       return;
     }
 
     this.prevState = state;
 
     if (state.waterfallWidth === null || state.scale === null) {
-      document.mozSetImageElement("waterfall-background", null);
+      setImageElement("waterfall-background", null);
       return;
     }
 
     // Nuke the context.
     let canvasWidth = this.canvas.width = state.waterfallWidth;
     // Awww yeah, 1px, repeats on Y axis.
     let canvasHeight = this.canvas.height = 1;
 
@@ -108,21 +122,21 @@ WaterfallBackground.prototype = {
 
     drawTimestamp(state.timingMarkers.firstDocumentLoadTimestamp,
                   REQUESTS_WATERFALL_LOAD_TICKS_COLOR_RGBA);
 
     // Flush the image data and cache the waterfall background.
     pixelArray.set(view8bit);
     this.ctx.putImageData(imageData, 0, 0);
 
-    document.mozSetImageElement("waterfall-background", this.canvas);
+    setImageElement("waterfall-background", this.canvas);
   },
 
   destroy() {
-    document.mozSetImageElement("waterfall-background", null);
+    setImageElement("waterfall-background", null);
   }
 };
 
 /**
  * Returns true if this is document is in RTL mode.
  * @return boolean
  */
 function isDocumentRTL(doc) {