diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index ea56f5cee96..77af21f20ed 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -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); diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 4076f8d95f0..459be99d404 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -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; diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index 54e84e1d20c..757036c8686 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -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; } }