Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Private Attributes
XPCIDispatchExtension Class Reference

#include <XPCDispPrivate.h>

List of all members.

Static Public Member Functions

static void InitStatics ()
 Reset the enabled flag if xpconnect is re-initialized.
static PRBool IsEnabled ()
 returns true if IDispatch extension is enabled
static void Enable ()
 Enables the IDispatch extension.
static void Disable ()
 Disables the IDispatch extension.
static JSBool Initialize (JSContext *aJSContext, JSObject *aGlobalJSObj)
 Initializes the IDispatch support system this exposes the ActiveXObject and COMObject to JS.
static JSBool DefineProperty (XPCCallContext &ccx, JSObject *obj, jsval idval, XPCWrappedNative *wrapperToReflectInterfaceNames, uintN propFlags, JSBool *resolved)
 This is the define property for the IDispatch system.
static JSBool Enumerate (XPCCallContext &ccx, JSObject *obj, XPCWrappedNative *wrapper)
 IDispatch system's enumeration function.
static nsresult IDispatchQIWrappedJS (nsXPCWrappedJS *self, void **aInstancePtr)
 This is the delegated QI called from the wrapped JS class DelegatedQueryInterface.

Static Private Attributes

static PRBool mIsEnabled = PR_TRUE

Detailed Description

Definition at line 1127 of file XPCDispPrivate.h.


Member Function Documentation

JSBool XPCIDispatchExtension::DefineProperty ( XPCCallContext ccx,
JSObject obj,
jsval  idval,
XPCWrappedNative wrapperToReflectInterfaceNames,
uintN  propFlags,
JSBool resolved 
) [static]

This is the define property for the IDispatch system.

It called from the XPConnect's DefineProperty

Parameters:
ccxan XPConnect call context
objthe JS object receiving the property
idvalID of the property to add
wrapperToReflectInterfaceNamesthe wrapper
propFlagsJS property flags
resolveda pointer to a JSBool, set to true if properly resolved

Definition at line 243 of file XPCIDispatchExtension.cpp.

{
    if(!JSVAL_IS_STRING(idval))
        return JS_FALSE;
    // Look up the native interface for IDispatch and then find a tearoff
    XPCNativeInterface* iface = XPCNativeInterface::GetNewOrUsed(ccx,
                                                                 "IDispatch");
    // The native interface isn't defined so just exit with an error
    if(iface == nsnull)
        return JS_FALSE;
    XPCWrappedNativeTearOff* to = 
        wrapperToReflectInterfaceNames->LocateTearOff(ccx, iface);
    // This object has no IDispatch interface so bail.
    if(to == nsnull)
        return JS_FALSE;
    // Look up the member in the interface
    const XPCDispInterface::Member * member = to->GetIDispatchInfo()->FindMember(idval);
    if(!member)
    {
        // IDispatch is case insensitive, so if we don't find a case sensitive
        // match, we'll try a more expensive case-insensisitive search
        // TODO: We need to create cleaner solution that doesn't create
        // multiple properties of different case on the JS Object
        member = to->GetIDispatchInfo()->FindMemberCI(ccx, idval);
        if(!member)
            return JS_FALSE;
    }
    // Get the function object
    jsval funval;
    if(!member->GetValue(ccx, iface, &funval))
        return JS_FALSE;
    // Protect the jsval 
    AUTO_MARK_JSVAL(ccx, funval);
    // clone a function we can use for this object 
    JSObject* funobj = xpc_CloneJSFunction(ccx, JSVAL_TO_OBJECT(funval), obj);
    if(!funobj)
        return JS_FALSE;
    jsid id;
    // If this is a function or a parameterized property
    if(member->IsFunction() || member->IsParameterizedProperty())
    {
        // define the function on the object
        AutoResolveName arn(ccx, idval);
        if(resolved)
            *resolved = JS_TRUE;
        return JS_ValueToId(ccx, idval, &id) &&
               OBJ_DEFINE_PROPERTY(ccx, obj, id, OBJECT_TO_JSVAL(funobj),
                                   nsnull, nsnull, propFlags, nsnull);
    }
    // Define the property on the object
    NS_ASSERTION(member->IsProperty(), "way broken!");
    propFlags |= JSPROP_GETTER | JSPROP_SHARED;
    if(member->IsSetter())
    {
        propFlags |= JSPROP_SETTER;
        propFlags &= ~JSPROP_READONLY;
    }
    AutoResolveName arn(ccx, idval);
    if(resolved)
        *resolved = JS_TRUE;
    return JS_ValueToId(ccx, idval, &id) &&
           OBJ_DEFINE_PROPERTY(ccx, obj, id, JSVAL_VOID,
                               (JSPropertyOp) funobj,
                               (JSPropertyOp) funobj,
                               propFlags, nsnull);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void XPCIDispatchExtension::Disable ( ) [inline, static]

Disables the IDispatch extension.

Definition at line 1147 of file XPCDispPrivate.h.

static void XPCIDispatchExtension::Enable ( ) [inline, static]

Enables the IDispatch extension.

Definition at line 1143 of file XPCDispPrivate.h.

JSBool XPCIDispatchExtension::Enumerate ( XPCCallContext ccx,
JSObject obj,
XPCWrappedNative wrapper 
) [static]

IDispatch system's enumeration function.

This is called from XPC_WN_Shared_Enumerate

Parameters:
ccxa XPConnect call context
objpointer to the JSObject
wrapperpointer to the wrapper
Returns:
true if the enumeration was successful

Definition at line 314 of file XPCIDispatchExtension.cpp.

{
    XPCNativeInterface* iface = XPCNativeInterface::GetNewOrUsed(
        ccx,&NSID_IDISPATCH);
    if(!iface)
        return JS_FALSE;

    XPCWrappedNativeTearOff* tearoff = wrapper->FindTearOff(ccx, iface);
    if(!tearoff)
        return JS_FALSE;

    XPCDispInterface* pInfo = tearoff->GetIDispatchInfo();
    PRUint32 members = pInfo->GetMemberCount();
    // Iterate over the members and force the properties to be resolved
    for(PRUint32 index = 0; index < members; ++index)
    {
        const XPCDispInterface::Member & member = pInfo->GetMember(index);
        jsval name = member.GetName();
        if(!xpc_ForcePropertyResolve(ccx, obj, name))
            return JS_FALSE;
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XPCIDispatchExtension::IDispatchQIWrappedJS ( nsXPCWrappedJS self,
void **  aInstancePtr 
) [static]

This is the delegated QI called from the wrapped JS class DelegatedQueryInterface.

Parameters:
selfpointer to the object
aInstancePtrpointer to an interface pointer to receive the QI'd pointer
Returns:
an XPCOM result

Definition at line 339 of file XPCIDispatchExtension.cpp.

{
    // Lookup the root and create a tearoff based on that
    nsXPCWrappedJS* root = self->GetRootWrapper();

    if(!root->IsValid())
    {
        *aInstancePtr = nsnull;
        return NS_NOINTERFACE;
    }
    XPCDispatchTearOff* tearOff = new XPCDispatchTearOff(root);
    if(!tearOff)
        return NS_ERROR_OUT_OF_MEMORY;
    tearOff->AddRef();
    *aInstancePtr = tearOff;
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool XPCIDispatchExtension::Initialize ( JSContext aJSContext,
JSObject aGlobalJSObj 
) [static]

Initializes the IDispatch support system this exposes the ActiveXObject and COMObject to JS.

Parameters:
aJSContexta JS context
aGlobalJSObja global JS object

Definition at line 219 of file XPCIDispatchExtension.cpp.

{
    xpcFunctionDefiner fd(aJSContext);
    JSFunction * func = fd.Define(aGlobalJSObj,
                                  XPCJSRuntime::IDX_ACTIVEX_OBJECT,
                                  ActiveXConstructor);
    if(!func)
        return JS_FALSE;

    JSObject * funcObject = JS_GetFunctionObject(func);
    if(!funcObject)
        return JS_FALSE;

    if(!fd.Define(funcObject, XPCJSRuntime::IDX_ACTIVEX_SUPPORTS, ActiveXSupports))
        return JS_FALSE;

#ifdef XPC_COMOBJECT
    if(!fd.Define(aGlobalJSObj, XPCJSRuntime::IDX_COM_OBJECT, COMObjectConstructor))
        return JS_FALSE;
#endif
    return JS_TRUE;
}

Here is the call graph for this function:

static void XPCIDispatchExtension::InitStatics ( ) [inline, static]

Reset the enabled flag if xpconnect is re-initialized.

Definition at line 1133 of file XPCDispPrivate.h.

Here is the caller graph for this function:

static PRBool XPCIDispatchExtension::IsEnabled ( ) [inline, static]

returns true if IDispatch extension is enabled

Returns:
true if IDispatch extension is enabled

Definition at line 1139 of file XPCDispPrivate.h.

{ return mIsEnabled; }

Member Data Documentation

Definition at line 1192 of file XPCDispPrivate.h.


The documentation for this class was generated from the following files: