nsresult  rv = NS_OK;  if (mHaveFiredOnStartRequest) { return NS_OK; }  mHaveFiredOnStartRequest = PR_TRUE;  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);  if (!channel) return NS_ERROR_FAILURE;  nsCOMPtr<nsICachingChannel> cacheChannel = do_QueryInterface(channel, &rv); if (cacheChannel) rv = cacheChannel->SetCacheAsFile(PR_TRUE);  if (NS_FAILED(rv)) {  rv = SetupPluginCacheFile(channel); if (NS_FAILED(rv)) NS_WARNING("No Cache Aval.  Some plugins wont work OR we don't have a URL"); }  char* aContentType = nsnull; rv = channel->GetContentType(&aContentType); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIURI> aURL; rv = channel->GetURI(getter_AddRefs(aURL)); if (NS_FAILED(rv)) return rv;  if (nsnull != aContentType) mPluginStreamInfo->SetContentType(aContentType);  nsPluginWindow    *window = nsnull;         if ((nsnull == mInstance) && (nsnull != mOwner) && (nsnull != aContentType)) { mOwner->GetInstance(mInstance); mOwner->GetWindow(window);  if ((nsnull == mInstance) && (nsnull != mHost) && (nsnull != window)) {  nsPluginMode mode; mOwner->GetMode(&mode); if (mode == nsPluginMode_Embedded) rv = mHost->InstantiateEmbededPlugin(aContentType, aURL, mOwner); else rv = mHost->SetUpPluginInstance(aContentType, aURL, mOwner);  if (NS_OK == rv) {  mOwner->GetInstance(mInstance);  if (nsnull != mInstance) { mInstance->Start(); mOwner->CreateWidget();    if (window->window) mInstance->SetWindow(window); } } } }  nsCRT::free(aContentType);     PRInt32 length;  rv = channel->GetContentLength(&length);    if (NS_FAILED(rv)) { mPluginStreamInfo->SetLength(-1); } else { mPluginStreamInfo->SetLength(length); }   rv = SetUpStreamListener(request, aURL); if (NS_FAILED(rv)) return rv;  return rv;
return NS_OK;
nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aContext){  nsresult  rv = NS_OK;  if (mHaveFiredOnStartRequest) {      return NS_OK;  }  mHaveFiredOnStartRequest = PR_TRUE;  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);  if (!channel)      return NS_ERROR_FAILURE;  nsCOMPtr<nsICachingChannel> cacheChannel = do_QueryInterface(channel, &rv);  if (cacheChannel)        rv = cacheChannel->SetCacheAsFile(PR_TRUE);        if (NS_FAILED(rv)) {    // The channel doesn't want to do our bidding, lets cache it to disk ourselves    rv = SetupPluginCacheFile(channel);    if (NS_FAILED(rv))      NS_WARNING("No Cache Aval.  Some plugins wont work OR we don't have a URL");    }  char* aContentType = nsnull;  rv = channel->GetContentType(&aContentType);  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIURI> aURL;  rv = channel->GetURI(getter_AddRefs(aURL));  if (NS_FAILED(rv)) return rv;  if (nsnull != aContentType)	  mPluginStreamInfo->SetContentType(aContentType);  nsPluginWindow    *window = nsnull;  // if we don't have an nsIPluginInstance (mInstance), it means  // we weren't able to load a plugin previously because we  // didn't have the mimetype.  Now that we do (aContentType),  // we'll try again with SetUpPluginInstance()   // which is called by InstantiateEmbededPlugin()  // NOTE: we don't want to try again if we didn't get the MIME type this time  if ((nsnull == mInstance) && (nsnull != mOwner) && (nsnull != aContentType))  {    mOwner->GetInstance(mInstance);    mOwner->GetWindow(window);    if ((nsnull == mInstance) && (nsnull != mHost) && (nsnull != window))    {      // determine if we need to try embedded again. FullPage takes a different code path      nsPluginMode mode;      mOwner->GetMode(&mode);      if (mode == nsPluginMode_Embedded)        rv = mHost->InstantiateEmbededPlugin(aContentType, aURL, mOwner);      else        rv = mHost->SetUpPluginInstance(aContentType, aURL, mOwner);      if (NS_OK == rv)      {		// GetInstance() adds a ref        mOwner->GetInstance(mInstance);        if (nsnull != mInstance)        {          mInstance->Start();          mOwner->CreateWidget();          // If we've got a native window, the let the plugin know          // about it.          if (window->window)            mInstance->SetWindow(window);        }      }    }  }  nsCRT::free(aContentType);  //  // Set up the stream listener...  //  PRInt32 length;  rv = channel->GetContentLength(&length);  // it's possible for the server to not send a Content-Length.  We should  // still work in this case.  if (NS_FAILED(rv)) {    mPluginStreamInfo->SetLength(-1);  }  else {    mPluginStreamInfo->SetLength(length);  }  rv = SetUpStreamListener(request, aURL);  if (NS_FAILED(rv)) return rv;  return rv;}