Bug 975042 - Basic Xray infrastructure and boilerplate. r=peterv

All of this machinery asserts if it actually get used. But it won't be used at
present, because we have an empty whitelist of JSProtoKeys.
This commit is contained in:
Bobby Holley 2014-03-20 23:47:23 -03:00
parent ba01d93b50
commit 2b514f18c9
3 changed files with 104 additions and 4 deletions

View File

@ -359,15 +359,23 @@ SelectWrapper(bool securityWrapper, bool wantXrays, XrayType xrayType,
if (!securityWrapper) {
if (xrayType == XrayForWrappedNative)
return &PermissiveXrayXPCWN::singleton;
return &PermissiveXrayDOM::singleton;
else if (xrayType == XrayForDOMObject)
return &PermissiveXrayDOM::singleton;
MOZ_ASSERT(xrayType == XrayForJSObject);
return &PermissiveXrayJS::singleton;
}
// This is a security wrapper. Use the security versions and filter.
if (xrayType == XrayForWrappedNative)
return &FilteringWrapper<SecurityXrayXPCWN,
CrossOriginAccessiblePropertiesOnly>::singleton;
return &FilteringWrapper<SecurityXrayDOM,
CrossOriginAccessiblePropertiesOnly>::singleton;
else if (xrayType == XrayForDOMObject)
return &FilteringWrapper<SecurityXrayDOM,
CrossOriginAccessiblePropertiesOnly>::singleton;
// There's never any reason to expose pure JS objects to non-subsuming actors.
// Just use an opaque wrapper in this case.
MOZ_ASSERT(xrayType == XrayForJSObject);
return &FilteringWrapper<CrossCompartmentSecurityWrapper, Opaque>::singleton;
}
JSObject *

View File

@ -1,4 +1,3 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
*
@ -39,6 +38,13 @@ namespace xpc {
using namespace XrayUtils;
// Whitelist for the standard ES classes we can Xray to.
static bool
IsJSXraySupported(JSProtoKey key)
{
return false;
}
XrayType
GetXrayType(JSObject *obj)
{
@ -50,6 +56,10 @@ GetXrayType(JSObject *obj)
if (IS_WN_CLASS(clasp) || clasp->ext.innerObject)
return XrayForWrappedNative;
JSProtoKey standardProto = IdentifyStandardInstanceOrPrototype(obj);
if (IsJSXraySupported(standardProto))
return XrayForJSObject;
return NotXray;
}
@ -279,8 +289,81 @@ public:
static DOMXrayTraits singleton;
};
class JSXrayTraits : public XrayTraits
{
public:
enum {
HasPrototype = 1
};
static const XrayType Type = XrayForJSObject;
virtual bool resolveNativeProperty(JSContext *cx, HandleObject wrapper,
HandleObject holder, HandleId id,
MutableHandle<JSPropertyDescriptor> desc, unsigned flags)
{
MOZ_ASSUME_UNREACHABLE("resolveNativeProperty hook should never be called with HasPrototype = 1");
}
virtual bool resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, HandleObject wrapper,
HandleObject holder, HandleId id,
MutableHandle<JSPropertyDescriptor> desc, unsigned flags)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
MutableHandle<JSPropertyDescriptor> desc,
Handle<JSPropertyDescriptor> existingDesc, bool *defined)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static bool enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
AutoIdVector &props)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static bool call(JSContext *cx, HandleObject wrapper,
const JS::CallArgs &args, js::Wrapper& baseInstance)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static bool construct(JSContext *cx, HandleObject wrapper,
const JS::CallArgs &args, js::Wrapper& baseInstance)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
{
return false;
}
typedef ResolvingIdDummy ResolvingIdImpl;
bool getPrototypeOf(JSContext *cx, JS::HandleObject wrapper,
JS::HandleObject target,
JS::MutableHandleObject protop)
{
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
virtual void preserveWrapper(JSObject *target) {
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper) {
MOZ_ASSUME_UNREACHABLE("Not yet implemented");
}
static JSXrayTraits singleton;
};
XPCWrappedNativeXrayTraits XPCWrappedNativeXrayTraits::singleton;
DOMXrayTraits DOMXrayTraits::singleton;
JSXrayTraits JSXrayTraits::singleton;
XrayTraits*
GetXrayTraits(JSObject *obj)
@ -290,6 +373,8 @@ GetXrayTraits(JSObject *obj)
return &DOMXrayTraits::singleton;
case XrayForWrappedNative:
return &XPCWrappedNativeXrayTraits::singleton;
case XrayForJSObject:
return &JSXrayTraits::singleton;
default:
return nullptr;
}
@ -1958,6 +2043,10 @@ template<>
SecurityXrayDOM SecurityXrayDOM::singleton(0);
template class SecurityXrayDOM;
template<>
PermissiveXrayJS PermissiveXrayJS::singleton(0);
template class PermissiveXrayJS;
template<>
SCSecurityXrayXPCWN SCSecurityXrayXPCWN::singleton(0);
template class SCSecurityXrayXPCWN;

View File

@ -49,11 +49,13 @@ HasNativeProperty(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id,
class XrayTraits;
class XPCWrappedNativeXrayTraits;
class DOMXrayTraits;
class JSXrayTraits;
enum XrayType {
XrayForDOMObject,
XrayForWrappedNative,
XrayForJSObject,
NotXray
};
@ -143,6 +145,7 @@ class XrayWrapper : public Base {
#define SecurityXrayXPCWN xpc::XrayWrapper<js::CrossCompartmentSecurityWrapper, xpc::XPCWrappedNativeXrayTraits>
#define PermissiveXrayDOM xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::DOMXrayTraits>
#define SecurityXrayDOM xpc::XrayWrapper<js::CrossCompartmentSecurityWrapper, xpc::DOMXrayTraits>
#define PermissiveXrayJS xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::JSXrayTraits>
#define SCSecurityXrayXPCWN xpc::XrayWrapper<js::SameCompartmentSecurityWrapper, xpc::XPCWrappedNativeXrayTraits>
class SandboxProxyHandler : public js::Wrapper {