--- a/browser/components/extensions/ext-utils.js
+++ b/browser/components/extensions/ext-utils.js
@@ -211,100 +211,104 @@ class BasePopup {
this.browser.addEventListener("DOMTitleChanged", this, true);
this.browser.addEventListener("DOMWindowClose", this, true);
this.browser.addEventListener("MozScrolledAreaChanged", this, true);
});
}
// Resizes the browser to match the preferred size of the content (debounced).
resizeBrowser() {
if (this.resizeTimeout == null) {
- this._resizeBrowser();
this.resizeTimeout = this.window.setTimeout(this._resizeBrowser.bind(this), RESIZE_TIMEOUT);
+ this._resizeBrowser(false);
}
}
- _resizeBrowser() {
- this.resizeTimeout = null;
-
- if (!this.browser) {
- return;
- }
-
- if (this.fixedWidth) {
- // If we're in a fixed-width area (namely a slide-in subview of the main
- // menu panel), we need to calculate the view height based on the
- // preferred height of the content document's root scrollable element at the
- // current width, rather than the complete preferred dimensions of the
- // content window.
-
- let doc = this.browser.contentDocument;
- if (!doc || !doc.documentElement) {
+ _resizeBrowser(clearTimeout = true) {
+ try {
+ if (!this.browser) {
return;
}
- let root = doc.documentElement;
- let body = doc.body;
- if (!body || doc.compatMode == "BackCompat") {
- // In quirks mode, the root element is used as the scroll frame, and the
- // body lies about its scroll geometry, and returns the values for the
- // root instead.
- body = root;
+ if (this.fixedWidth) {
+ // If we're in a fixed-width area (namely a slide-in subview of the main
+ // menu panel), we need to calculate the view height based on the
+ // preferred height of the content document's root scrollable element at the
+ // current width, rather than the complete preferred dimensions of the
+ // content window.
+
+ let doc = this.browser.contentDocument;
+ if (!doc || !doc.documentElement) {
+ return;
+ }
+
+ let root = doc.documentElement;
+ let body = doc.body;
+ if (!body || doc.compatMode == "BackCompat") {
+ // In quirks mode, the root element is used as the scroll frame, and the
+ // body lies about its scroll geometry, and returns the values for the
+ // root instead.
+ body = root;
+ }
+
+ // Compensate for any offsets (margin, padding, ...) between the scroll
+ // area of the body and the outer height of the document.
+ let getHeight = elem => elem.getBoundingClientRect(elem).height;
+ let bodyPadding = getHeight(root) - getHeight(body);
+
+ let height = Math.ceil(body.scrollHeight + bodyPadding);
+
+ // Figure out how much extra space we have on the side of the panel
+ // opposite the arrow.
+ let side = this.panel.getAttribute("side") == "top" ? "bottom" : "top";
+ let maxHeight = this.viewHeight + this.extraHeight[side];
+
+ height = Math.min(height, maxHeight);
+ this.browser.style.height = `${height}px`;
+
+ // Set a maximum height on the <panelview> element to our preferred
+ // maximum height, so that the PanelUI resizing code can make an accurate
+ // calculation. If we don't do this, the flex sizing logic will prevent us
+ // from ever reporting a preferred size smaller than the height currently
+ // available to us in the panel.
+ height = Math.max(height, this.viewHeight);
+ this.viewNode.style.maxHeight = `${height}px`;
+ } else {
+ let width, height;
+ try {
+ let w = {}, h = {};
+ this.browser.docShell.contentViewer.getContentSize(w, h);
+
+ width = w.value / this.window.devicePixelRatio;
+ height = h.value / this.window.devicePixelRatio;
+
+ // The width calculation is imperfect, and is often a fraction of a pixel
+ // too narrow, even after taking the ceiling, which causes lines of text
+ // to wrap.
+ width += 1;
+ } catch (e) {
+ // getContentSize can throw
+ [width, height] = [400, 400];
+ }
+
+ width = Math.ceil(Math.min(width, 800));
+ height = Math.ceil(Math.min(height, 600));
+
+ this.browser.style.width = `${width}px`;
+ this.browser.style.height = `${height}px`;
}
- // Compensate for any offsets (margin, padding, ...) between the scroll
- // area of the body and the outer height of the document.
- let getHeight = elem => elem.getBoundingClientRect(elem).height;
- let bodyPadding = getHeight(root) - getHeight(body);
-
- let height = Math.ceil(body.scrollHeight + bodyPadding);
-
- // Figure out how much extra space we have on the side of the panel
- // opposite the arrow.
- let side = this.panel.getAttribute("side") == "top" ? "bottom" : "top";
- let maxHeight = this.viewHeight + this.extraHeight[side];
-
- height = Math.min(height, maxHeight);
- this.browser.style.height = `${height}px`;
+ let event = new this.window.CustomEvent("WebExtPopupResized");
+ this.browser.dispatchEvent(event);
- // Set a maximum height on the <panelview> element to our preferred
- // maximum height, so that the PanelUI resizing code can make an accurate
- // calculation. If we don't do this, the flex sizing logic will prevent us
- // from ever reporting a preferred size smaller than the height currently
- // available to us in the panel.
- height = Math.max(height, this.viewHeight);
- this.viewNode.style.maxHeight = `${height}px`;
- } else {
- let width, height;
- try {
- let w = {}, h = {};
- this.browser.docShell.contentViewer.getContentSize(w, h);
-
- width = w.value / this.window.devicePixelRatio;
- height = h.value / this.window.devicePixelRatio;
-
- // The width calculation is imperfect, and is often a fraction of a pixel
- // too narrow, even after taking the ceiling, which causes lines of text
- // to wrap.
- width += 1;
- } catch (e) {
- // getContentSize can throw
- [width, height] = [400, 400];
+ this._resolveContentReady();
+ } finally {
+ if (clearTimeout) {
+ this.resizeTimeout = null;
}
-
- width = Math.ceil(Math.min(width, 800));
- height = Math.ceil(Math.min(height, 600));
-
- this.browser.style.width = `${width}px`;
- this.browser.style.height = `${height}px`;
}
-
- let event = new this.window.CustomEvent("WebExtPopupResized");
- this.browser.dispatchEvent(event);
-
- this._resolveContentReady();
}
}
global.PanelPopup = class PanelPopup extends BasePopup {
constructor(extension, imageNode, popupURL, browserStyle) {
let document = imageNode.ownerDocument;
let panel = document.createElement("panel");