Jacek Caban : jscript: Added ActiveXObject constructor implementation.

Alexandre Julliard julliard at winehq.org
Wed Sep 30 10:56:10 CDT 2009


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 30 14:34:47 2009 +0200

jscript: Added ActiveXObject constructor implementation.

---

 dlls/jscript/Makefile.in   |    2 +-
 dlls/jscript/activex.c     |  124 +++++++++++++++++++++++++++++++++++++++++++-
 dlls/jscript/error.c       |    5 ++
 dlls/jscript/jscript.c     |    6 ++
 dlls/jscript/jscript.h     |    4 +-
 dlls/jscript/jscript_En.rc |    1 +
 dlls/jscript/resource.h    |    1 +
 7 files changed, 139 insertions(+), 4 deletions(-)

diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in
index d9d490a..6373796 100644
--- a/dlls/jscript/Makefile.in
+++ b/dlls/jscript/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = jscript.dll
-IMPORTS   = oleaut32 user32 advapi32 kernel32
+IMPORTS   = oleaut32 ole32 user32 advapi32 kernel32
 
 RC_SRCS = \
 	jscript_De.rc \
diff --git a/dlls/jscript/activex.c b/dlls/jscript/activex.c
index eada0c2..2029edf 100644
--- a/dlls/jscript/activex.c
+++ b/dlls/jscript/activex.c
@@ -20,16 +20,136 @@
 #include "wine/port.h"
 
 #include "jscript.h"
+#include "objsafe.h"
 
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
 
+/* Defined as extern in urlmon.idl, but not exported by uuid.lib */
+const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
+    {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
+
+static IInternetHostSecurityManager *get_sec_mgr(script_ctx_t *ctx)
+{
+    IInternetHostSecurityManager *secmgr;
+    IServiceProvider *sp;
+    HRESULT hres;
+
+    if(!ctx->site)
+        return NULL;
+
+    if(ctx->secmgr)
+        return ctx->secmgr;
+
+    hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
+    if(FAILED(hres))
+        return NULL;
+
+    hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager, &IID_IInternetHostSecurityManager,
+            (void**)&secmgr);
+    IServiceProvider_Release(sp);
+    if(FAILED(hres))
+        return NULL;
+
+    return ctx->secmgr = secmgr;
+}
+
+static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid)
+{
+    IInternetHostSecurityManager *secmgr;
+    struct CONFIRMSAFETY cs;
+    DWORD policy_size;
+    BYTE *bpolicy;
+    IUnknown *obj;
+    DWORD policy;
+    GUID guid;
+    HRESULT hres;
+
+    hres = CLSIDFromProgID(progid, &guid);
+    if(FAILED(hres))
+        return NULL;
+
+    TRACE("GUID %s\n", debugstr_guid(&guid));
+
+    secmgr = get_sec_mgr(ctx);
+    if(!secmgr)
+        return NULL;
+
+    policy = 0;
+    hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
+            (BYTE*)&guid, sizeof(GUID), 0, 0);
+    if(FAILED(hres) || policy != URLPOLICY_ALLOW)
+        return NULL;
+
+    /* FIXME: Use IClassFactoryEx */
+
+    hres = CoCreateInstance(&guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void**)&obj);
+    if(FAILED(hres))
+        return NULL;
+
+    cs.clsid = guid;
+    cs.pUnk = obj;
+    cs.dwFlags = 0;
+    hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &bpolicy, &policy_size,
+            (BYTE*)&cs, sizeof(cs), 0);
+    if(SUCCEEDED(hres)) {
+        policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW;
+        CoTaskMemFree(bpolicy);
+    }
+
+    if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
+        IUnknown_Release(obj);
+        return NULL;
+    }
+
+    return obj;
+}
+
 static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    IDispatch *disp;
+    IUnknown *obj;
+    BSTR progid;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    if(flags != DISPATCH_CONSTRUCT) {
+        FIXME("unsupported flags %x\n", flags);
+        return E_NOTIMPL;
+    }
+
+    if(ctx->safeopt != (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)) {
+        FIXME("Unsupported safeopt %x\n", ctx->safeopt);
+        return E_NOTIMPL;
+    }
+
+    if(arg_cnt(dp) != 1) {
+        FIXME("unsuported arg_cnt %d\n", arg_cnt(dp));
+        return E_NOTIMPL;
+    }
+
+    hres = to_string(ctx, get_arg(dp,0), ei, &progid);
+    if(FAILED(hres))
+        return hres;
+
+    obj = create_activex_object(ctx, progid);
+    SysFreeString(progid);
+    if(!obj)
+        return throw_generic_error(ctx, ei, IDS_CREATE_OBJ_ERROR, NULL);
+
+    hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&disp);
+    IUnknown_Release(obj);
+    if(FAILED(hres)) {
+        FIXME("Object does not support IDispatch\n");
+        return E_NOTIMPL;
+    }
+
+    V_VT(retv) = VT_DISPATCH;
+    V_DISPATCH(retv) = disp;
+    return S_OK;
 }
 
 HRESULT create_activex_constr(script_ctx_t *ctx, DispatchEx **ret)
diff --git a/dlls/jscript/error.c b/dlls/jscript/error.c
index 91bc95a..9530a4c 100644
--- a/dlls/jscript/error.c
+++ b/dlls/jscript/error.c
@@ -429,6 +429,11 @@ HRESULT throw_eval_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR
     return throw_error(ctx, ei, id, str, ctx->eval_error_constr);
 }
 
+HRESULT throw_generic_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
+{
+    return throw_error(ctx, ei, id, str, ctx->error_constr);
+}
+
 HRESULT throw_range_error(script_ctx_t *ctx, jsexcept_t *ei, UINT id, const WCHAR *str)
 {
     return throw_error(ctx, ei, id, str, ctx->range_error_constr);
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 1efe8e1..90a5b47 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -351,6 +351,11 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface)
             This->ctx->named_items = NULL;
         }
 
+        if(This->ctx->secmgr) {
+            IInternetHostSecurityManager_Release(This->ctx->secmgr);
+            This->ctx->secmgr = NULL;
+        }
+
         if(This->ctx->site) {
             IActiveScriptSite_Release(This->ctx->site);
             This->ctx->site = NULL;
@@ -554,6 +559,7 @@ static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
 
     ctx->ref = 1;
     ctx->state = SCRIPTSTATE_UNINITIALIZED;
+    ctx->safeopt = This->safeopt;
     jsheap_init(&ctx->tmp_heap);
 
     ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 9190110..533be57 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -214,6 +214,7 @@ HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const WCHAR*,cons
 HRESULT Function_value(script_ctx_t*,vdisp_t*,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
 
 HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
+HRESULT throw_generic_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 HRESULT throw_regexp_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
@@ -221,7 +222,6 @@ HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
 
-
 HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
 HRESULT create_math(script_ctx_t*,DispatchEx**);
 HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
@@ -260,6 +260,8 @@ struct _script_ctx_t {
     exec_ctx_t *exec_ctx;
     named_item_t *named_items;
     IActiveScriptSite *site;
+    IInternetHostSecurityManager *secmgr;
+    DWORD safeopt;
     LCID lcid;
 
     jsheap_t tmp_heap;
diff --git a/dlls/jscript/jscript_En.rc b/dlls/jscript/jscript_En.rc
index 7962ad3..14be9bd 100644
--- a/dlls/jscript/jscript_En.rc
+++ b/dlls/jscript/jscript_En.rc
@@ -24,6 +24,7 @@ STRINGTABLE DISCARDABLE
 {
     IDS_TO_PRIMITIVE        "Error converting object to primitive type"
     IDS_INVALID_CALL_ARG    "Invalid procedure call or argument"
+    IDS_CREATE_OBJ_ERROR    "Automation server can't create object"
     IDS_NO_PROPERTY         "Object doesn't support this property or method"
     IDS_ARG_NOT_OPT         "Argument not optional"
     IDS_SYNTAX_ERROR        "Syntax error"
diff --git a/dlls/jscript/resource.h b/dlls/jscript/resource.h
index fcebcb9..17c0df0 100644
--- a/dlls/jscript/resource.h
+++ b/dlls/jscript/resource.h
@@ -20,6 +20,7 @@
 
 #define IDS_TO_PRIMITIVE                    0x0001
 #define IDS_INVALID_CALL_ARG                0x0005
+#define IDS_CREATE_OBJ_ERROR                0x01AD
 #define IDS_NO_PROPERTY                     0x01B6
 #define IDS_ARG_NOT_OPT                     0x01c1
 #define IDS_SYNTAX_ERROR                    0x03EA




More information about the wine-cvs mailing list