Bug 1355760 - detect setImageElement to not run on Chrome browser tab;r=rickychien
MozReview-Commit-ID: 4RODBcbmDBo
--- 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) {