Accessing hiddenDOMWindow at final-ui-startup leads to IsCallerChrome() returning false for Chrome code

NEW
Unassigned

Status

()

Core
DOM
5 years ago
5 years ago

People

(Reporter: MattN, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

On Windows and Linux where the hidden DOM Window is XHTML, simply accessing Services.appShell.hiddenDOMWindow during final-ui-startup would break things like PageThumbs.jsm's capture method.  It calls canvas.mozFetchAsStream[1] (which can only be called from chrome code) and IsCallerChrome() returns false. If I don't access Services.appShell.hiddenDOMWindow during startup then IsCallerChrome() returns true for the call to mozFetchAsStream.

STR:
1) Include |let hdw = Services.appShell.hiddenDOMWindow;| in a final-ui-startup observer.
2) Enable the browser environment in the scratchpad (devtools.chrome.enabled = true).
3) Open a scratchpad and set the environment to "Browser" from the menu bar.
4) Run the following code in a scratchpad with :

const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
let doc = Services.appShell.hiddenDOMWindow.document;
let canvas = doc.createElementNS(HTML_NAMESPACE, "canvas");
canvas.mozFetchAsStream(function() {
  Cu.reportError("callback called");
});

Expected result:
"Callback called" appears in the error console

Actual result:
"NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLCanvasElement.mozFetchAsStream] at..."
because IsCallerChrome() returns false in mozFetchAsStream.

[1] https://mxr.mozilla.org/mozilla-central/source/browser/components/thumbnails/PageThumbs.jsm?rev=960b6d4ea73b#140
You need to log in before you can comment on or make changes to this bug.