nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mContainer));
nsHTTPIndex::OnStartRequest(nsIRequest *request, nsISupports* aContext){  nsresult rv;  mParser = do_CreateInstance(NS_DIRINDEXPARSER_CONTRACTID, &rv);  if (NS_FAILED(rv)) return rv;    rv = mParser->SetEncoding(mEncoding.get());  if (NS_FAILED(rv)) return rv;  rv = mParser->SetListener(this);  if (NS_FAILED(rv)) return rv;  rv = mParser->OnStartRequest(request,aContext);  if (NS_FAILED(rv)) return rv;  // This should only run once...  // Unless we don't have a container to start with  // (ie called from bookmarks as an rdf datasource)  if (mBindToGlobalObject && mRequestor) {    mBindToGlobalObject = PR_FALSE;    // Now get the content viewer container's script object.    nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_GetInterface(mRequestor));    NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_FAILURE);    nsIScriptContext *context = scriptGlobal->GetContext();    NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);    JSContext* jscontext = NS_REINTERPRET_CAST(JSContext*,                                               context->GetNativeContext());    JSObject* global = JS_GetGlobalObject(jscontext);    // Using XPConnect, wrap the HTTP index object...    static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);    nsCOMPtr<nsIXPConnect> xpc(do_GetService(kXPConnectCID, &rv));    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;    rv = xpc->WrapNative(jscontext,                         global,                         NS_STATIC_CAST(nsIHTTPIndex*, this),                         NS_GET_IID(nsIHTTPIndex),                         getter_AddRefs(wrapper));    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to xpconnect-wrap http-index");    if (NS_FAILED(rv)) return rv;    JSObject* jsobj;    rv = wrapper->GetJSObject(&jsobj);    NS_ASSERTION(NS_SUCCEEDED(rv),                 "unable to get jsobj from xpconnect wrapper");    if (NS_FAILED(rv)) return rv;    jsval jslistener = OBJECT_TO_JSVAL(jsobj);    // ...and stuff it into the global context    PRBool ok;    ok = JS_SetProperty(jscontext, global, "HTTPIndex", &jslistener);    NS_ASSERTION(ok, "unable to set Listener property");    if (! ok)      return NS_ERROR_FAILURE;  }  if (!aContext) {    nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));    NS_ASSERTION(channel, "request should be a channel");    // lets hijack the notifications:    channel->SetNotificationCallbacks(this);    // now create the top most resource    nsCOMPtr<nsIURI> uri;    channel->GetURI(getter_AddRefs(uri));          nsCAutoString entryuriC;    uri->GetSpec(entryuriC);    nsCOMPtr<nsIRDFResource> entry;    rv = mDirRDF->GetResource(entryuriC, getter_AddRefs(entry));        NS_ConvertUTF8toUCS2 uriUnicode(entryuriC);    nsCOMPtr<nsIRDFLiteral> URLVal;    rv = mDirRDF->GetLiteral(uriUnicode.get(), getter_AddRefs(URLVal));    Assert(entry, kNC_URL, URLVal, PR_TRUE);    mDirectory = do_QueryInterface(entry);  }  else  {    // Get the directory from the context    mDirectory = do_QueryInterface(aContext);  }  if (!mDirectory) {      request->Cancel(NS_BINDING_ABORTED);      return NS_BINDING_ABORTED;  }  // Mark the directory as "loading"  rv = Assert(mDirectory, kNC_Loading,                           kTrueLiteral, PR_TRUE);  if (NS_FAILED(rv)) return rv;  return NS_OK;}