Bug 788914 - Kill partially transparent wrappers. r=mrbkap

This commit is contained in:
Bobby Holley 2012-09-11 01:05:10 -07:00
parent a34d4a4ba8
commit e5ff464782
6 changed files with 15 additions and 46 deletions

View File

@ -2170,7 +2170,7 @@ bool
nsDOMClassInfo::ObjectIsNativeWrapper(JSContext* cx, JSObject* obj)
{
return xpc::WrapperFactory::IsXrayWrapper(obj) &&
!xpc::WrapperFactory::IsPartiallyTransparent(obj);
!xpc::WrapperFactory::IsXOW(obj);
}
nsDOMClassInfo::nsDOMClassInfo(nsDOMClassInfoData* aData) : mData(aData)

View File

@ -38,7 +38,7 @@ UnwrapNW(JSContext *cx, unsigned argc, jsval *vp)
}
if (xpc::WrapperFactory::IsXrayWrapper(obj) &&
!xpc::WrapperFactory::IsPartiallyTransparent(obj)) {
!xpc::WrapperFactory::IsXOW(obj)) {
return JS_GetProperty(cx, obj, "wrappedJSObject", vp);
}

View File

@ -295,10 +295,6 @@ AccessCheck::isScriptAccessOnly(JSContext *cx, JSObject *wrapper)
if (flags & WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG) {
if (flags & WrapperFactory::SOW_FLAG)
return !isSystemOnlyAccessPermitted(cx);
if (flags & WrapperFactory::PARTIALLY_TRANSPARENT)
return !XrayUtils::IsTransparent(cx, wrapper);
return true;
}

View File

@ -126,13 +126,13 @@ template<> SOW SOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
template<> SCSOW SCSOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::SOW_FLAG);
template<> XOW XOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
WrapperFactory::XOW_FLAG);
template<> PXOW PXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
WrapperFactory::XOW_FLAG);
template<> DXOW DXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
WrapperFactory::XOW_FLAG);
template<> NNXOW NNXOW::singleton(WrapperFactory::SCRIPT_ACCESS_ONLY_FLAG |
WrapperFactory::PARTIALLY_TRANSPARENT);
WrapperFactory::XOW_FLAG);
template<> LW LW::singleton(WrapperFactory::SHADOWING_FORBIDDEN);
template<> XLW XLW::singleton(WrapperFactory::SHADOWING_FORBIDDEN);

View File

@ -18,8 +18,8 @@ class WrapperFactory {
enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1,
IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1,
SCRIPT_ACCESS_ONLY_FLAG = IS_XRAY_WRAPPER_FLAG << 1,
PARTIALLY_TRANSPARENT = SCRIPT_ACCESS_ONLY_FLAG << 1,
SOW_FLAG = PARTIALLY_TRANSPARENT << 1,
XOW_FLAG = SCRIPT_ACCESS_ONLY_FLAG << 1,
SOW_FLAG = XOW_FLAG << 1,
// Prevent scripts from shadowing native properties.
// NB: Applies only to Xray wrappers.
@ -38,8 +38,8 @@ class WrapperFactory {
return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG);
}
static bool IsPartiallyTransparent(JSObject *wrapper) {
return HasWrapperFlag(wrapper, PARTIALLY_TRANSPARENT);
static bool IsXOW(JSObject *wrapper) {
return HasWrapperFlag(wrapper, XOW_FLAG);
}
static bool HasWaiveXrayFlag(JSObject *wrapper) {

View File

@ -910,23 +910,6 @@ nodePrincipal_getter(JSContext *cx, JSHandleObject wrapper, JSHandleId id, JSMut
return true;
}
static bool
ContentScriptHasUniversalXPConnect()
{
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
if (ssm) {
// Double-check that the subject principal according to CAPS is a content
// principal rather than the system principal. If it is, this check is
// meaningless.
NS_ASSERTION(!AccessCheck::callerIsChrome(), "About to do a meaningless security check!");
bool privileged;
if (NS_SUCCEEDED(ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged)) && privileged)
return true;
}
return false;
}
bool
XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper,
JSObject *wrapper, JSObject *holder, jsid id,
@ -936,7 +919,7 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, js::Wrapper &jsWra
// in the wrapper's compartment here, not the wrappee.
MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx));
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (!WrapperFactory::IsPartiallyTransparent(wrapper) &&
if (!WrapperFactory::IsXOW(wrapper) &&
(((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) ||
id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) &&
Is<nsINode>(wrapper)) ||
@ -1298,16 +1281,7 @@ namespace XrayUtils {
bool
IsTransparent(JSContext *cx, JSObject *wrapper)
{
if (WrapperFactory::HasWaiveXrayFlag(wrapper))
return true;
if (!WrapperFactory::IsPartiallyTransparent(wrapper))
return false;
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
// We don't need to check for system principal here, because only content
// scripts have Partially Transparent wrappers.
return ContentScriptHasUniversalXPConnect();
return WrapperFactory::HasWaiveXrayFlag(wrapper);
}
JSObject *
@ -1414,10 +1388,9 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, JSObject *wrappe
if (!holder)
return false;
// Partially transparent wrappers (which used to be known as XOWs) don't
// have a .wrappedJSObject property.
// XOWs don't have a .wrappedJSObject property.
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (!WrapperFactory::IsPartiallyTransparent(wrapper) &&
if (!WrapperFactory::IsXOW(wrapper) &&
id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT)) {
bool status;
Wrapper::Action action = set ? Wrapper::SET : Wrapper::GET;
@ -1608,7 +1581,7 @@ XrayWrapper<Base, Traits>::enumerate(JSContext *cx, JSObject *wrapper, unsigned
return js::GetPropertyNames(cx, obj, flags, &props);
}
if (WrapperFactory::IsPartiallyTransparent(wrapper)) {
if (WrapperFactory::IsXOW(wrapper)) {
JS_ReportError(cx, "Not allowed to enumerate cross origin objects");
return false;
}