mshtml: Correctly handle utf-16 encoded pages.

This commit is contained in:
Jacek Caban 2007-04-12 21:25:08 +02:00 committed by Alexandre Julliard
parent f44e289a86
commit 58a261b7d1
3 changed files with 33 additions and 14 deletions

View File

@ -165,6 +165,7 @@ typedef struct {
nsLoadFlags load_flags;
nsIURI *original_uri;
char *content;
char *charset;
} nsChannel;
typedef struct {

View File

@ -37,6 +37,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
#define CONTENT_LENGTH "Content-Length"
#define UTF16_STR "utf-16"
#define NSINSTREAM(x) ((nsIInputStream*) &(x)->lpInputStreamVtbl)
@ -399,31 +400,37 @@ static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *if
TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
if(This->nslistener) {
if(!This->nsstream) {
if(!This->nsstream)
This->nsstream = create_nsprotocol_stream(pstgmed->u.pstm);
nsres = nsIStreamListener_OnStartRequest(This->nslistener,
(nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
if(NS_FAILED(nsres))
FIXME("OnStartRequest failed: %08x\n", nsres);
}
do {
hres = IStream_Read(pstgmed->u.pstm, This->nsstream->buf, sizeof(This->nsstream->buf),
&This->nsstream->buf_size);
if(!This->nsstream->buf_size)
break;
if(!This->readed && This->nsstream->buf_size >= 2 && *(WORD*)This->nsstream->buf == 0xfeff) {
This->nschannel->charset = mshtml_alloc(sizeof(UTF16_STR));
memcpy(This->nschannel->charset, UTF16_STR, sizeof(UTF16_STR));
}
if(!This->readed) {
nsres = nsIStreamListener_OnStartRequest(This->nslistener,
(nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
if(NS_FAILED(nsres))
FIXME("OnStartRequest failed: %08x\n", nsres);
}
This->readed += This->nsstream->buf_size;
nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
(nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
NSINSTREAM(This->nsstream), This->readed, This->nsstream->buf_size);
if(NS_FAILED(nsres))
FIXME("OnDataAvailable failed: %08x\n", nsres);
ERR("OnDataAvailable failed: %08x\n", nsres);
if(This->nsstream->buf_size)
FIXME("buffer is not empty!\n");
This->readed += This->nsstream->buf_size;
}while(hres == S_OK);
}else {
BYTE buf[1024];

View File

@ -221,6 +221,7 @@ static nsrefcnt NSAPI nsChannel_Release(nsIHttpChannel *iface)
if(This->original_uri)
nsIURI_Release(This->original_uri);
mshtml_free(This->content);
mshtml_free(This->charset);
mshtml_free(This);
}
@ -512,11 +513,20 @@ static nsresult NSAPI nsChannel_GetContentCharset(nsIHttpChannel *iface,
TRACE("(%p)->(%p)\n", This, aContentCharset);
if(This->channel)
return nsIChannel_GetContentCharset(This->channel, aContentCharset);
if(This->charset) {
nsACString_SetData(aContentCharset, This->charset);
return NS_OK;
}
FIXME("default action not implemented\n");
return NS_ERROR_NOT_IMPLEMENTED;
if(This->channel) {
nsresult nsres = nsIChannel_GetContentCharset(This->channel, aContentCharset);
const char *ch;
nsACString_GetData(aContentCharset, &ch, NULL);
return nsres;
}
nsACString_SetData(aContentCharset, "");
return NS_OK;
}
static nsresult NSAPI nsChannel_SetContentCharset(nsIHttpChannel *iface,
@ -1871,6 +1881,7 @@ static nsresult NSAPI nsIOService_NewChannelFromURI(nsIIOService *iface, nsIURI
ret->notif_callback = NULL;
ret->load_flags = 0;
ret->content = NULL;
ret->charset = NULL;
nsIURI_AddRef(aURI);
ret->original_uri = aURI;