Hi,
I'm trying to write something that calls a function defined by the page
that I'm currently on.  Here's what I've got so far, with a little help
from IRC and the Greasemonkey source:
    var safeWin = XPCNativeWrapper(content);
    var sandbox = Components.utils.Sandbox(safeWin);
    sandbox.window = safeWin;
    sandbox.document = safeWin.document;
    sandbox.__proto__ = safeWin.wrappedJSObject;
    Components.utils.evalInSandbox("foo()", sandbox)
This all works fine, until foo() tries to make an XMLHttpRequest.  I
get the not particularly helpful error:
Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.open]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)"

I also tried the (presumably unsafe) variation:
    content.wrappedJSObject.foo()
which gives a slightly more useful error message:
Error: Access to 'chrome://browser/content/ajax.php from script denied
Source File: http://www.mydomain.com/test.html  Line: 18

which seems to suggest quite clearly that the sandbox is
misinterpretting the relative URL in the XMLHttpRequest to be relative
to the chrome path I am actually running from and not the http:// url
that it should be running from.  Any thoughts on how I can fix this,
short of changing the web page to use absolute url's (which indeed does
seem to fix the problem but may be infeasible in some situations)?
Thanks.

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to