mshtml: Use document encoding for scripts.

This commit is contained in:
Jacek Caban 2014-12-30 15:22:08 +01:00 committed by Alexandre Julliard
parent d4afbf5bd8
commit 127aa62a70
3 changed files with 44 additions and 4 deletions

View File

@ -115,6 +115,38 @@ HRESULT get_doc_elem_by_id(HTMLDocumentNode *doc, const WCHAR *id, HTMLElement *
return hres;
}
UINT get_document_charset(HTMLDocumentNode *doc)
{
nsAString charset_str;
UINT ret = 0;
nsresult nsres;
if(doc->charset)
return doc->charset;
nsAString_Init(&charset_str, NULL);
nsres = nsIDOMHTMLDocument_GetCharacterSet(doc->nsdoc, &charset_str);
if(NS_SUCCEEDED(nsres)) {
const PRUnichar *charset;
nsAString_GetData(&charset_str, &charset);
if(*charset) {
BSTR str = SysAllocString(charset);
ret = cp_from_charset_string(str);
SysFreeString(str);
}
}else {
ERR("GetCharset failed: %08x\n", nsres);
}
nsAString_Finish(&charset_str);
if(!ret)
return CP_UTF8;
return doc->charset = ret;
}
static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
{
return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);

View File

@ -749,6 +749,8 @@ struct HTMLDocumentNode {
BOOL skip_mutation_notif;
UINT charset;
struct list selection_list;
struct list range_list;
struct list plugin_hosts;
@ -807,6 +809,8 @@ void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR) DECLSPEC_HIDDEN;
void hide_tooltip(HTMLDocumentObj*) DECLSPEC_HIDDEN;
HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*) DECLSPEC_HIDDEN;
UINT get_document_charset(HTMLDocumentNode*) DECLSPEC_HIDDEN;
HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**) DECLSPEC_HIDDEN;
BOOL load_gecko(void) DECLSPEC_HIDDEN;

View File

@ -904,6 +904,7 @@ static const BSCallbackVtbl ScriptBSCVtbl = {
static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScriptElement *script_elem, WCHAR **ret)
{
UINT cp = CP_UTF8;
ScriptBSC *bsc;
IMoniker *mon;
WCHAR *text;
@ -961,18 +962,21 @@ static HRESULT bind_script_to_text(HTMLInnerWindow *window, IUri *uri, HTMLScrip
text[bsc->bsc.readed/sizeof(WCHAR)] = 0;
break;
case BOM_UTF8:
default: {
default:
/* FIXME: Try to use charset from HTTP headers first */
cp = get_document_charset(window->doc);
/* fall through */
case BOM_UTF8: {
DWORD len;
len = MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, NULL, 0);
len = MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.readed, NULL, 0);
text = heap_alloc((len+1)*sizeof(WCHAR));
if(!text) {
hres = E_OUTOFMEMORY;
break;
}
MultiByteToWideChar(CP_UTF8, 0, bsc->buf, bsc->bsc.readed, text, len);
MultiByteToWideChar(cp, 0, bsc->buf, bsc->bsc.readed, text, len);
text[len] = 0;
}
}