Bug 1440949 - Allow plain JS objects to request addon interposition;r=kmag

This is needed to allow interposition for gBrowser, which will change from a DOM node
into a plain JS object in Bug 1392352.  An object can set the `requiresAddonInterpositions`
property to enable this feature.

MozReview-Commit-ID: 4Uw5xzgZtXO

--HG--
extra : rebase_source : 203fe656da3ecd514d4e27ad0eeb4885cf4e9b0b
This commit is contained in:
Brian Grinstead 2018-02-26 13:37:15 -08:00
parent 0c3ddfb661
commit e13938f94f

View File

@ -38,20 +38,36 @@ ReportASCIIErrorWithId(JSContext* cx, const char* msg, HandleId id)
JS_ReportErrorUTF8(cx, msg, bytes.ptr());
}
bool
RequiresInterpositions(JSContext* cx, HandleObject unwrapped)
{
Rooted<PropertyDescriptor> desc(cx);
JSAutoCompartment ac(cx, unwrapped);
if (!JS_GetOwnPropertyDescriptor(cx, unwrapped, "requiresAddonInterpositions", &desc)) {
JS_ClearPendingException(cx);
return false;
}
return desc.hasValue() && desc.value().isTrue();
}
bool
InterposeProperty(JSContext* cx, HandleObject target, const nsIID* iid, HandleId id,
MutableHandle<PropertyDescriptor> descriptor)
{
// We only want to do interpostion on DOM instances and
// wrapped natives.
// We only want to do interpostion on DOM instances,
// wrapped natives, or if the object explicitly requests it.
RootedObject unwrapped(cx, UncheckedUnwrap(target));
const js::Class* clasp = js::GetObjectClass(unwrapped);
bool isCPOW = jsipc::IsWrappedCPOW(unwrapped);
if (!mozilla::dom::IsDOMClass(clasp) &&
!IS_WN_CLASS(clasp) &&
!IS_PROTO_CLASS(clasp) &&
clasp != &OuterWindowProxyClass &&
!isCPOW) {
!isCPOW &&
!RequiresInterpositions(cx, unwrapped)) {
return true;
}