Jacek Caban : mshtml: Use return_nsstr_variant in IHTMLBodyElement::get_bgColor.

Alexandre Julliard julliard at winehq.org
Fri Jun 5 14:16:53 CDT 2020


Module: wine
Branch: master
Commit: 7f465761c2f898ca5dde5a357576b44ba47b8bc5
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7f465761c2f898ca5dde5a357576b44ba47b8bc5

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Jun  5 18:27:01 2020 +0200

mshtml: Use return_nsstr_variant in IHTMLBodyElement::get_bgColor.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmlbody.c       | 21 ++++-----------------
 dlls/mshtml/mshtml_private.h |  1 +
 dlls/mshtml/nsembed.c        | 22 +++++++++++++---------
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/dlls/mshtml/htmlbody.c b/dlls/mshtml/htmlbody.c
index 981d93f9b4..a49f8162c0 100644
--- a/dlls/mshtml/htmlbody.c
+++ b/dlls/mshtml/htmlbody.c
@@ -407,27 +407,14 @@ static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIA
 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
 {
     HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
-    nsAString strColor;
+    nsAString nsstr;
     nsresult nsres;
-    HRESULT hres;
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    nsAString_Init(&strColor, NULL);
-    nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &strColor);
-    if(NS_SUCCEEDED(nsres)) {
-        const PRUnichar *color;
-
-        nsAString_GetData(&strColor, &color);
-        V_VT(p) = VT_BSTR;
-        hres = nscolor_to_str(color, &V_BSTR(p));
-    }else {
-        ERR("SetBgColor failed: %08x\n", nsres);
-        hres = E_FAIL;
-    }
-
-    nsAString_Finish(&strColor);
-    return hres;
+    nsAString_Init(&nsstr, NULL);
+    nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &nsstr);
+    return return_nsstr_variant(nsres, &nsstr, NSSTR_COLOR, p);
 }
 
 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 565a2428ba..7b2f927e19 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -982,6 +982,7 @@ UINT32 nsAString_GetData(const nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
 void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
 
 #define NSSTR_IMPLICIT_PX    0x01
+#define NSSTR_COLOR          0x02
 
 HRESULT map_nsresult(nsresult) DECLSPEC_HIDDEN;
 HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 2d1eb817dc..9a23785ca6 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -964,14 +964,15 @@ HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
 
 HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, unsigned flags, VARIANT *p)
 {
+    HRESULT hres = S_OK;
+
     if(NS_FAILED(nsres)) {
         ERR("failed: %08x\n", nsres);
         nsAString_Finish(nsstr);
-        return E_FAIL;
+        return map_nsresult(nsres);
     }
 
     if(NS_StringGetIsVoid(nsstr)) {
-        TRACE("ret null\n");
         V_VT(p) = VT_NULL;
     }else {
         const WCHAR *str;
@@ -989,20 +990,23 @@ HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, unsigned flags, V
                 if(iter == str + len && dot) len = dot - str;
             }
         }
-        TRACE("ret %s\n", debugstr_wn(str, len));
-        if(*str) {
+        if(flags & NSSTR_COLOR) {
+            hres = nscolor_to_str(str, &V_BSTR(p));
+        }else if(*str) {
             V_BSTR(p) = SysAllocStringLen(str, len);
-            if(!V_BSTR(p)) {
-                nsAString_Finish(nsstr);
-                return E_OUTOFMEMORY;
-            }
+            if(!V_BSTR(p))
+                hres = E_OUTOFMEMORY;
         }else {
             V_BSTR(p) = NULL;
         }
-        V_VT(p) = VT_BSTR;
+        if(SUCCEEDED(hres))
+            V_VT(p) = VT_BSTR;
     }
 
     nsAString_Finish(nsstr);
+    if(FAILED(hres))
+        return hres;
+    TRACE("ret %s\n", debugstr_variant(p));
     return S_OK;
 }
 




More information about the wine-cvs mailing list