Jacek Caban : mshtml: Use document encoding for scripts.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Dec 30 16:48:14 CST 2014


Module: wine
Branch: master
Commit: 127aa62a7030f07bea46ae8cb629f3ca2acd1aac
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=127aa62a7030f07bea46ae8cb629f3ca2acd1aac

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Dec 30 15:22:08 2014 +0100

mshtml: Use document encoding for scripts.

---

 dlls/mshtml/htmldoc.c        | 32 ++++++++++++++++++++++++++++++++
 dlls/mshtml/mshtml_private.h |  4 ++++
 dlls/mshtml/script.c         | 12 ++++++++----
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index ea56f5c..77af21f 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 4076f8d..459be99 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 54e84e1..757036c 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;
     }
     }




More information about the wine-cvs mailing list