Jon
Jon

Reputation: 31

iFrame in Firefox hidden window with a contentWindow.history?

I'm trying to run a hosted script with content privileges in my Firefox extension. To do this, I create a content iframe in the hidden window pointed at a html file that pulls the script. This script requires the 'history' be available, but the iframes created in the hidden window have no history for some reason.

Chromebug reports this for the iframe's contentWindow.history:

object does not support history (nsIDOMHistory)

And the script gives this error when its not available:

Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.length]

Any ideas?

Upvotes: 1

Views: 1647

Answers (2)

Neil
Neil

Reputation: 55432

It turns out that the hidden window's URL used to be about:blank, but this was apparently a security flaw, so it is now resource://gre/res/hiddenWindow.html (or resource://gre-resources/hiddenWindow.html on trunk) so it doesn't have the chrome privileges that a XUL browser element needs in order to be able to wire up its own session history, or even to access its own content document.

Even using a XUL iframe element you have to be careful since none of its properties work, again because it is running without chrome privileges. So you have to do stuff like iframeElement.boxObject.QueryInterface(Components.interfaces.nsIContainerBoxObject).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow) to retrieve its content window.

Upvotes: 1

Neil
Neil

Reputation: 55432

A <browser type="content"> will automatically wire up session history by default, while an <iframe type="content"> will not, but you could always wire it up yourself manually.

Don't forget to ensure that your element is created in the XUL namespace. I believe the hidden window is the about:blank HTML document except on the Mac.

Upvotes: 0

Related Questions