Bug 771202 - Add a PostTransplant nsIXPCScriptable hook. r=peterv

This commit is contained in:
Bobby Holley 2012-07-13 10:55:14 +02:00
parent 125cde6303
commit 79ab421362
5 changed files with 55 additions and 1 deletions

View File

@ -4784,6 +4784,14 @@ nsDOMClassInfo::PostCreate(nsIXPConnectWrappedNative *wrapper,
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsDOMClassInfo::PostTransplant(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj)
{
MOZ_NOT_REACHED("nsDOMClassInfo::PostTransplant Don't call me!");
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp,
@ -8195,6 +8203,15 @@ nsElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
NS_IMETHODIMP
nsElementSH::PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
{
// XBL bindings are reapplied asynchronously when the node is inserted into a
// new document and frame construction occurs.
return NS_OK;
}
// Generic array scriptable helper.
@ -8738,6 +8755,14 @@ nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
NS_IMETHODIMP
nsDocumentSH::PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
{
// Nothing to do here.
return NS_OK;
}
// HTMLDocument helper
static nsresult
@ -9861,6 +9886,14 @@ nsHTMLPluginObjElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
}
NS_IMETHODIMP
nsHTMLPluginObjElementSH::PostTransplant(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj)
{
// XXXbholley - Implement me!
return NS_OK;
}
NS_IMETHODIMP
nsHTMLPluginObjElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *obj, jsid id,

View File

@ -562,6 +562,8 @@ public:
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
NS_IMETHOD PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
@ -749,6 +751,8 @@ public:
NS_IMETHOD GetFlags(PRUint32* aFlags);
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
NS_IMETHOD PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
@ -903,6 +907,8 @@ public:
JSObject *globalObj, JSObject **parentObj);
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
NS_IMETHOD PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval);
NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,

View File

@ -37,7 +37,7 @@
* to *_retval unless they want to return PR_FALSE.
*/
[uuid(782d317e-0727-4ccd-8a5b-f5d237f3b03c)]
[uuid(c4788e02-3239-490a-8aeb-60fad08303fd)]
interface nsIXPCScriptable : nsISupports
{
/* bitflags used for 'flags' (only 32 bits available!) */
@ -88,9 +88,16 @@ interface nsIXPCScriptable : nsISupports
void create(in nsIXPConnectWrappedNative wrapper,
in JSContextPtr cx, in JSObjectPtr obj);
// Both methods here are protected by WANT_POSTCREATE. If you want to do
// something after a wrapper is created, there's a good chance you also
// want to do something when the wrapper is transplanted to a new
// compartment.
void postCreate(in nsIXPConnectWrappedNative wrapper,
in JSContextPtr cx, in JSObjectPtr obj);
void postTransplant(in nsIXPConnectWrappedNative wrapper,
in JSContextPtr cx, in JSObjectPtr obj);
boolean addProperty(in nsIXPConnectWrappedNative wrapper,
in JSContextPtr cx, in JSObjectPtr obj, in jsid id,
in JSValPtr vp);

View File

@ -105,6 +105,9 @@ NS_IMETHODIMP XPC_MAP_CLASSNAME::Create(nsIXPConnectWrappedNative *wrapper, JSCo
#ifndef XPC_MAP_WANT_POSTCREATE
NS_IMETHODIMP XPC_MAP_CLASSNAME::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
{NS_ERROR("never called"); return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHODIMP XPC_MAP_CLASSNAME::PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext * cx, JSObject * obj)
{NS_ERROR("never called"); return NS_ERROR_NOT_IMPLEMENTED;}
#endif
#ifndef XPC_MAP_WANT_ADDPROPERTY

View File

@ -1652,6 +1652,11 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
return NS_ERROR_FAILURE;
}
}
// Call the scriptable hook to indicate that we transplanted.
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if (si->GetFlags().WantPostCreate())
(void) si->GetCallback()->PostTransplant(wrapper, ccx, flat);
}
// Now we can just fix up the parent and return the wrapper