Bug 658909 - Remove GWNOJO from JSObject2NativeInterface. r=mrbkap

This commit is contained in:
Bobby Holley 2013-03-16 22:58:15 -07:00
parent 8a60c09a1f
commit 0d540a32dd
3 changed files with 25 additions and 13 deletions

View File

@ -1032,22 +1032,25 @@ XPCConvert::JSObject2NativeInterface(JSContext* cx,
// If we're looking at a security wrapper, see now if we're allowed to
// pass it to C++. If we are, then fall through to the code below. If
// we aren't, throw an exception eagerly.
JSObject* inner = nullptr;
if (XPCWrapper::IsSecurityWrapper(src)) {
inner = XPCWrapper::Unwrap(cx, src, false);
if (!inner) {
if (pErr)
*pErr = NS_ERROR_XPC_SECURITY_MANAGER_VETO;
return false;
}
JSObject* inner = js::UnwrapObjectChecked(src, /* stopAtOuter = */ false);
// Hack - For historical reasons, wrapped chrome JS objects have been
// passable as native interfaces. We'd like to fix this, but it
// involves fixing the contacts API and PeerConnection to stop using
// COWs. This needs to happen, but for now just preserve the old
// behavior.
if (!inner && MOZ_UNLIKELY(xpc::WrapperFactory::IsCOW(src)))
inner = js::UnwrapObject(src);
if (!inner) {
if (pErr)
*pErr = NS_ERROR_XPC_SECURITY_MANAGER_VETO;
return false;
}
// Is this really a native xpcom object with a wrapper?
XPCWrappedNative* wrappedNative =
XPCWrappedNative::GetWrappedNativeOfJSObject(cx,
inner
? inner
: src);
XPCWrappedNative* wrappedNative = nullptr;
if (IS_WN_WRAPPER(inner))
wrappedNative = XPCWrappedNative::Get(inner);
if (wrappedNative) {
iface = wrappedNative->GetIdentityObject();
return NS_SUCCEEDED(iface->QueryInterface(*iid, dest));

View File

@ -39,6 +39,13 @@ Wrapper XrayWaiver(WrapperFactory::WAIVE_XRAY_WRAPPER_FLAG);
// off it.
WaiveXrayWrapper WaiveXrayWrapper::singleton(0);
bool
WrapperFactory::IsCOW(JSObject *obj)
{
return IsWrapper(obj) &&
Wrapper::wrapperHandler(obj) == &ChromeObjectWrapper::singleton;
}
JSObject *
WrapperFactory::GetXrayWaiver(JSObject *obj)
{

View File

@ -39,6 +39,8 @@ class WrapperFactory {
return !js::UnwrapObjectChecked(obj);
}
static bool IsCOW(JSObject *wrapper);
static JSObject *GetXrayWaiver(JSObject *obj);
static JSObject *CreateXrayWaiver(JSContext *cx, JSObject *obj);
static JSObject *WaiveXray(JSContext *cx, JSObject *obj);