Jacek Caban : mshtml: Use proper codepage in nsIIOService::NewURI.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Oct 13 11:18:10 CDT 2014


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sat Oct 11 17:35:19 2014 +0200

mshtml: Use proper codepage in nsIIOService::NewURI.

---

 dlls/mshtml/main.c           | 32 ++++++++++++++++++++++++++++++++
 dlls/mshtml/mshtml_private.h |  1 +
 dlls/mshtml/nsio.c           | 19 ++++++++++++++++---
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/dlls/mshtml/main.c b/dlls/mshtml/main.c
index ce9222f..e5cf325 100644
--- a/dlls/mshtml/main.c
+++ b/dlls/mshtml/main.c
@@ -35,6 +35,7 @@
 #include "optary.h"
 #include "rpcproxy.h"
 #include "shlguid.h"
+#include "mlang.h"
 
 #include "wine/debug.h"
 
@@ -50,6 +51,35 @@ DWORD mshtml_tls = TLS_OUT_OF_INDEXES;
 static HINSTANCE shdoclc = NULL;
 static HDC display_dc;
 static WCHAR *status_strings[IDS_STATUS_LAST-IDS_STATUS_FIRST+1];
+static IMultiLanguage2 *mlang;
+
+UINT cp_from_charset_string(BSTR charset)
+{
+    MIMECSETINFO info;
+    HRESULT hres;
+
+    if(!mlang) {
+        IMultiLanguage2 *new_mlang;
+
+        hres = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
+                &IID_IMultiLanguage2, (void**)&new_mlang);
+        if(FAILED(hres)) {
+            ERR("Could not create CMultiLanguage instance\n");
+            return CP_UTF8;
+        }
+
+        if(InterlockedCompareExchangePointer((void**)&mlang, new_mlang, NULL))
+            IMultiLanguage2_Release(new_mlang);
+    }
+
+    hres = IMultiLanguage2_GetCharsetInfo(mlang, charset, &info);
+    if(FAILED(hres)) {
+        FIXME("GetCharsetInfo failed: %08x\n", hres);
+        return CP_UTF8;
+    }
+
+    return info.uiInternetEncoding;
+}
 
 static void thread_detach(void)
 {
@@ -83,6 +113,8 @@ static void process_detach(void)
         TlsFree(mshtml_tls);
     if(display_dc)
         DeleteObject(display_dc);
+    if(mlang)
+        IMultiLanguage2_Release(mlang);
 
     free_strings();
 }
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 31c08ad..b69fd26 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -1195,6 +1195,7 @@ static inline void windowref_release(windowref_t *ref)
         heap_free(ref);
 }
 
+UINT cp_from_charset_string(BSTR) DECLSPEC_HIDDEN;
 HDC get_display_dc(void) DECLSPEC_HIDDEN;
 HINSTANCE get_shdoclc(void) DECLSPEC_HIDDEN;
 void set_statustext(HTMLDocumentObj*,INT,LPCWSTR) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/nsio.c b/dlls/mshtml/nsio.c
index b5c766c..78ad0a6 100644
--- a/dlls/mshtml/nsio.c
+++ b/dlls/mshtml/nsio.c
@@ -3317,6 +3317,7 @@ static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *
     WCHAR new_spec[INTERNET_MAX_URL_LENGTH];
     HTMLOuterWindow *window = NULL;
     const char *spec = NULL;
+    UINT cp = CP_UTF8;
     IUri *urlmon_uri;
     nsresult nsres;
     HRESULT hres;
@@ -3343,10 +3344,22 @@ static nsresult NSAPI nsIOService_NewURI(nsIIOService *iface, const nsACString *
         }
     }
 
-    if(aOriginCharset && strcasecmp(aOriginCharset, "utf-8"))
-        FIXME("Unsupported charset %s\n", debugstr_a(aOriginCharset));
+    if(aOriginCharset && *aOriginCharset && strncasecmp(aOriginCharset, "utf", 3)) {
+        BSTR charset;
+        int len;
 
-    MultiByteToWideChar(CP_UTF8, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
+        len = MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, NULL, 0);
+        charset = SysAllocStringLen(NULL, len-1);
+        if(!charset)
+            return NS_ERROR_OUT_OF_MEMORY;
+        MultiByteToWideChar(CP_UTF8, 0, aOriginCharset, -1, charset, len);
+
+        cp = cp_from_charset_string(charset);
+
+        SysFreeString(charset);
+    }
+
+    MultiByteToWideChar(cp, 0, spec, -1, new_spec, sizeof(new_spec)/sizeof(WCHAR));
 
     if(base_wine_uri) {
         hres = combine_url(base_wine_uri->uri, new_spec, &urlmon_uri);




More information about the wine-cvs mailing list