trigger->Add( item );
rv = InstallTriggerCheckLoadURIFromScript(cx, icon); if (NS_FAILED(rv)) abortLoad = PR_TRUE;
InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){   nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)    JS_GetInstancePrivate(cx, obj, &InstallTriggerGlobalClass, argv);  if (!nativeThis)    return JS_FALSE;  *rval = JSVAL_FALSE;  if (nsnull == nativeThis  &&  (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )    return JS_TRUE;  // make sure XPInstall is enabled, return false if not  nsIScriptGlobalObject *globalObject = nsnull;  nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);  if (scriptContext)      globalObject = scriptContext->GetGlobalObject();  PRBool enabled = PR_FALSE;  nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);  if (!enabled || !globalObject)      return JS_TRUE;  // get window.location to construct relative URLs  nsCOMPtr<nsIURI> baseURL;  JSObject* global = JS_GetGlobalObject(cx);  if (global)  {    jsval v;    if (JS_GetProperty(cx,global,"location",&v))    {      nsAutoString location;      ConvertJSValToStr( location, cx, v );      NS_NewURI(getter_AddRefs(baseURL), location);    }  }  // if we can't create a security manager we might be in the wizard, allow  PRBool abortLoad = PR_FALSE;  nsCOMPtr<nsIScriptSecurityManager> secman(      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));  // 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 && !abortLoad; i++ )      {        JS_IdToValue( cx, ida->vector[i], &v );        name = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v ) ));        URL = iconURL = nsnull;        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;          if (JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "URL", &v2 ))            URL = NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars( JS_ValueToString( cx, v2 ) ));          if (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 )        {            // Get relative URL to load            nsAutoString xpiURL(URL);            if (baseURL)            {                nsCAutoString resolvedURL;                baseURL->Resolve(NS_ConvertUTF16toUTF8(xpiURL), resolvedURL);                xpiURL = NS_ConvertUTF8toUTF16(resolvedURL);            }            // Make sure we're allowed to load this URL            if (secman)            {                nsCOMPtr<nsIURI> uri;                nsresult rv = NS_NewURI(getter_AddRefs(uri), xpiURL);                if (NS_SUCCEEDED(rv))                {                    rv = secman->CheckLoadURIFromScript(cx, uri);                    if (NS_FAILED(rv))                        abortLoad = PR_TRUE;                }            }            nsAutoString icon(iconURL);            if (iconURL && baseURL)            {                nsCAutoString resolvedIcon;                baseURL->Resolve(NS_ConvertUTF16toUTF8(icon), resolvedIcon);                icon = NS_ConvertUTF8toUTF16(resolvedIcon);            }            nsXPITriggerItem *item = new nsXPITriggerItem( name, xpiURL.get(), icon.get() );            if ( item )            {                trigger->Add( item );            }            else                abortLoad = PR_TRUE;        }        else            abortLoad = PR_TRUE;      }      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 (!abortLoad && trigger->Size() > 0)    {        PRBool result;        nativeThis->Install(globalObject, trigger, &result);        *rval = BOOLEAN_TO_JSVAL(result);        return JS_TRUE;    }    // didn't pass it on so we must delete trigger    delete trigger;  }  JS_ReportError(cx, "Incorrect arguments to InstallTrigger.Install()");  return JS_FALSE;}