mHaveFiredOnStartRequest = PR_TRUE;  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request); NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE);    nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); if (httpChannel) { PRUint32 responseCode = 0; rv = httpChannel->GetResponseStatus(&responseCode); if (NS_FAILED(rv) || responseCode > 206) {     mRequestFailed = PR_TRUE; return NS_ERROR_FAILURE; }
PRUint32 responseCode = 0; rv = httpChannel->GetResponseStatus(&responseCode); if (NS_FAILED(rv) || responseCode != 200) { return NS_ERROR_FAILURE;
nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request,                                           nsISupports* aContext){  nsresult  rv = NS_OK;  if (mHaveFiredOnStartRequest) {      return NS_OK;  }  mHaveFiredOnStartRequest = PR_TRUE;  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);  NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE);  // deal with 404 (Not Found) HTTP response,  // just return, this causes the request to be ignored.  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));  if (httpChannel) {    PRUint32 responseCode = 0;    rv = httpChannel->GetResponseStatus(&responseCode);    if (NS_FAILED(rv) || responseCode > 206) { // not normal      // NPP_Notify() will be called from OnStopRequest      // in ns4xPluginStreamListener::CleanUpStream      // return error will cancel this request      // ...and we also need to tell the plugin that      mRequestFailed = PR_TRUE;      return NS_ERROR_FAILURE;    }  }  nsCAutoString contentType;  rv = channel->GetContentType(contentType);  if (NS_FAILED(rv))     return rv;  // do a little sanity check to make sure our frame isn't gone  // by getting the tag type and checking for an error, we can determine if  // the frame is gone  if (mOwner) {    nsCOMPtr<nsIPluginTagInfo2> pti2 = do_QueryInterface(mOwner);    NS_ENSURE_TRUE(pti2, NS_ERROR_FAILURE);    nsPluginTagType tagType;    if (NS_FAILED(pti2->GetTagType(&tagType)))      return NS_ERROR_FAILURE;  // something happened to our object frame, so bail!    // Now that we know the content type, tell the DOM element.    nsCOMPtr<nsIDOMElement> element;    pti2->GetDOMElement(getter_AddRefs(element));    nsCOMPtr<nsIDOMHTMLObjectElement> object(do_QueryInterface(element));    if (object) {      object->SetType(NS_ConvertASCIItoUTF16(contentType));    } else {      nsCOMPtr<nsIDOMHTMLEmbedElement> embed(do_QueryInterface(element));      if (embed) {        embed->SetType(NS_ConvertASCIItoUTF16(contentType));      }    }  }  // Get the notification callbacks from the channel and save it as  // week ref we'll use it in nsPluginStreamInfo::RequestRead() when  // we'll create channel for byte range request.  nsCOMPtr<nsIInterfaceRequestor> callbacks;  channel->GetNotificationCallbacks(getter_AddRefs(callbacks));  if (callbacks)    mWeakPtrChannelCallbacks = do_GetWeakReference(callbacks);  nsCOMPtr<nsILoadGroup> loadGroup;  channel->GetLoadGroup(getter_AddRefs(loadGroup));  if (loadGroup)    mWeakPtrChannelLoadGroup = do_GetWeakReference(loadGroup);  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) || length == -1) {    // check out if this is file channel    nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel);    if (fileChannel) {      // file does not exist      mRequestFailed = PR_TRUE;      return NS_ERROR_FAILURE;    }    mPluginStreamInfo->SetLength(PRUint32(0));  }  else {    mPluginStreamInfo->SetLength(length);  }  mPluginStreamInfo->SetRequest(request);  nsCAutoString aContentType;  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;  nsCAutoString urlSpec;  aURL->GetSpec(urlSpec);  mPluginStreamInfo->SetURL(urlSpec.get());  if (!aContentType.IsEmpty())    mPluginStreamInfo->SetContentType(aContentType.get());#ifdef PLUGIN_LOGGING  PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NOISY,  ("nsPluginStreamListenerPeer::OnStartRequest this=%p request=%p mime=%s, url=%s\n",  this, request, aContentType.get(), urlSpec.get()));  PR_LogFlush();#endif  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 InstantiateEmbeddedPlugin()  // NOTE: we don't want to try again if we didn't get the MIME type this time  if ((nsnull == mInstance) && (nsnull != mOwner) && (!aContentType.IsEmpty()))  {    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->InstantiateEmbeddedPlugin(aContentType.get(), aURL, mOwner);      else        rv = mHost->SetUpPluginInstance(aContentType.get(), 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)          {            nsCOMPtr<nsIPluginInstance> inst = mInstance;            ((nsPluginNativeWindow*)window)->CallSetWindow(inst);          }        }      }    }  }  //  // Set up the stream listener...  //  rv = SetUpStreamListener(request, aURL);  if (NS_FAILED(rv)) return rv;  return rv;}