NS_IMETHODIMP ProgressListenerAdaptor::OnStatusChange( nsIWebProgress* web_progress, nsIRequest* request, nsresult status, const PRUnichar* message) { if (NS_FAILED(status)) { if (m_progress && !m_progress->IsCancelled()) m_progress->OnError(ns2wx(message)); } return NS_OK; }
NS_IMETHODIMP nsProtocolHandlerImpl::NewChannel(nsIURI *aURI, nsIChannel **_retval) { ns_smartptr<nsIServiceManager> service_mgr; nsresult res; res = NS_GetServiceManager(&service_mgr.p); if (NS_FAILED(res)) return res; ns_smartptr<nsIInputStreamChannel> input_stream_channel(nsCreateInstance("@mozilla.org/network/input-stream-channel;1")); ns_smartptr<nsIChannel> channel(input_stream_channel); nsCString nsspec; res = aURI->GetSpec(nsspec); if (NS_FAILED(res)) return res; wxString wxSpec = ns2wx(nsspec); nsCString nsContentType; nsString nsContent; wxString contentType = m_handler->GetContentType(wxSpec); wxString content = m_handler->GetContent(wxSpec); wx2ns(contentType, nsContentType); wx2ns(content, nsContent); channel->SetContentType(nsContentType); /* XXX: Is UTF-8 the best encoding all the time? */ channel->SetContentCharset(NS_LITERAL_CSTRING("utf-8")); input_stream_channel->SetURI(aURI); ns_smartptr<nsIScriptableUnicodeConverter> unicode_converter(nsCreateInstance("@mozilla.org/intl/scriptableunicodeconverter")); unicode_converter->SetCharset("UTF-8"); nsIInputStream* input_stream; res = unicode_converter->ConvertToInputStream(nsContent, &input_stream); if (NS_FAILED(res)) return res; input_stream_channel->SetContentStream(input_stream); *_retval = channel; NS_ADDREF(*_retval); return NS_OK; }