Fix for 40406. Add setter to XPConnect to set default JS context used to execute JS components when no appropriate context can be found.
The setter changes per-thread data - for the DOM/UI thread, this means that we can set the JS Context to one with DOM magic. This magic allows some DOM JS <-> XPConnect JS conversions to succeed, and in particular allows creation of a DOM window from within a JS component. Unblocks nsbeta2 work by Vishy and Pavlov. r=mccabe,vishy. a=brendan,sleestack.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsXPComFactory.h" /* template implementation of a XPCOM factory */
|
||||
#include "nsIXPConnect.h"
|
||||
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIWidget.h"
|
||||
@@ -67,7 +68,7 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
|
||||
static NS_DEFINE_CID(kMetaCharsetCID, NS_META_CHARSET_CID);
|
||||
|
||||
static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
|
||||
|
||||
// copied from nsEventQueue.cpp
|
||||
static char *gEQActivatedNotification = "nsIEventQueueActivated";
|
||||
@@ -210,6 +211,20 @@ nsAppShellService::CreateHiddenWindow()
|
||||
getter_AddRefs(newWindow));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mHiddenWindow = newWindow;
|
||||
|
||||
// Set XPConnect's fallback JSContext (used for JS Components)
|
||||
// to the DOM JSContext for this thread, so that DOM-to-XPConnect
|
||||
// conversions get the JSContext private magic they need to
|
||||
// succeed.
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIDOMWindow> junk;
|
||||
JSContext *cx;
|
||||
rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = xpc->SetSafeJSContextForCurrentThread(cx);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// RegisterTopLevelWindow(newWindow); -- Mac only
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user