nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); if (globalObject) { nativeThis->Install(globalObject, trigger, &result); *rval = BOOLEAN_TO_JSVAL(result); return JS_TRUE; } }
nativeThis->Install(globalObject, trigger, &result); *rval = BOOLEAN_TO_JSVAL(result); return JS_TRUE;
InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){  nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);  *rval = JSVAL_FALSE;  if (nsnull == nativeThis  &&  (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )    return JS_FALSE;  // make sure XPInstall is enabled, return false if not  PRBool enabled = PR_FALSE;  nativeThis->UpdateEnabled(&enabled);  if (!enabled)      return JS_TRUE;  // get window.location to construct relative URLs  nsString baseURL;  JSObject* global = JS_GetGlobalObject(cx);  if (global)  {    jsval v;    if (JS_GetProperty(cx,global,"location",&v))    {      ConvertJSValToStr( baseURL, cx, v );      PRInt32 lastslash = baseURL.RFindChar('/');      if (lastslash != kNotFound)      {        baseURL.Truncate(lastslash+1);      }    }  }  // parse associative array of installs  if ( argc >= 1 && JSVAL_IS_OBJECT(argv[0]) )  {    nsXPITriggerInfo *trigger = new nsXPITriggerInfo();    if (!trigger)      return JS_FALSE;    JSIdArray *ida = JS_Enumerate( cx, JSVAL_TO_OBJECT(argv[0]) );    if ( ida )    {      jsval v;      const PRUnichar *name, *URL;      const PRUnichar *iconURL = nsnull;      for (int i = 0; i < ida->length; i++ )      {        JS_IdToValue( cx, ida->vector[i], &v );        name = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v ) ));        JS_GetUCProperty( cx, JSVAL_TO_OBJECT(argv[0]), NS_REINTERPRET_CAST(const jschar*, name), nsCRT::strlen(name), &v );        if ( JSVAL_IS_OBJECT(v) )         {                    jsval v2;          JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "URL", &v2 );          URL = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v2 ) ));          JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "IconURL", &v2 );          iconURL = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v2 ) ));        }        else         {        URL = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v ) ));        }        if ( name && URL )        {            nsXPITriggerItem *item = new nsXPITriggerItem( name, URL, iconURL );            if ( item )            {                if ( item->IsRelativeURL() )                {                  item->mURL.Insert( baseURL, 0 );                }                trigger->Add( item );            }            else                ; // XXX signal error somehow        }        else            ; // XXX need to signal error      }      JS_DestroyIdArray( cx, ida );    }    // save callback function if any (ignore bad args for now)    if ( argc >= 2 && JS_TypeOfValue(cx,argv[1]) == JSTYPE_FUNCTION )    {      trigger->SaveCallback( cx, argv[1] );    }    // pass on only if good stuff found    if (trigger->Size() > 0)    {        PRBool result;        nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);        if (scriptContext)        {            nsIScriptGlobalObject *globalObject =                scriptContext->GetGlobalObject();            if (globalObject)            {                nativeThis->Install(globalObject, trigger, &result);                *rval = BOOLEAN_TO_JSVAL(result);                return JS_TRUE;            }        }    }    else        delete trigger;  }  JS_ReportError(cx, "Incorrect arguments to InstallTrigger.Install()");  return JS_FALSE;}