ConvertJSValToStr( baseURL, cx, v ); PRInt32 lastslash = baseURL.RFindChar('/'); if (lastslash != kNotFound) { baseURL.Truncate(lastslash+1); }
nsAutoString location; ConvertJSValToStr( location, cx, v ); NS_NewURI(getter_AddRefs(baseURL), location);
InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){  nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);  PRBool       nativeRet;  uint32       chromeType;  nsAutoString baseURL;  nsAutoString sourceURL;  nsAutoString name;  *rval = JSVAL_FALSE;  if (nsnull == nativeThis  &&  (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) ) {    return JS_FALSE;  }  // make sure XPInstall is enabled, return if not  PRBool enabled = PR_FALSE;  nativeThis->UpdateEnabled(&enabled);  if (!enabled)      return JS_TRUE;  // get window.location to construct relative URLs  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);      }    }  }  if ( argc >= 3 )  {    JS_ValueToECMAUint32(cx, argv[0], &chromeType);    ConvertJSValToStr(sourceURL, cx, argv[1]);    ConvertJSValToStr(name, cx, argv[2]);    if ( chromeType & CHROME_ALL )    {        // there's at least one known chrome type        nsXPITriggerItem* item = new nsXPITriggerItem(name.get(),                                                      sourceURL.get(),                                                       nsnull);        if (item && item->IsRelativeURL())            item->mURL.Insert( baseURL, 0 );        nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);        if (scriptContext)        {            nsIScriptGlobalObject *globalObject =                scriptContext->GetGlobalObject();            if (globalObject)            {                nsresult rv = nativeThis->InstallChrome(globalObject, chromeType, item, &nativeRet);                if (NS_FAILED(rv))                    return JS_FALSE;            }            else                return JS_FALSE;        }        else            return JS_FALSE;        *rval = BOOLEAN_TO_JSVAL(nativeRet);    }  }  return JS_TRUE;}