Jacek Caban | 2ea2392 | 2009-09-29 00:10:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 Jacek Caban for CodeWeavers |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 | */ |
| 18 | |
| 19 | #include "config.h" |
| 20 | #include "wine/port.h" |
| 21 | |
| 22 | #include "jscript.h" |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 23 | #include "objsafe.h" |
Jacek Caban | 960d7f9 | 2009-10-02 13:54:51 +0200 | [diff] [blame] | 24 | #include "mshtmhst.h" |
Jacek Caban | 2ea2392 | 2009-09-29 00:10:50 +0200 | [diff] [blame] | 25 | |
| 26 | #include "wine/debug.h" |
| 27 | |
| 28 | WINE_DEFAULT_DEBUG_CHANNEL(jscript); |
| 29 | |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 30 | /* Defined as extern in urlmon.idl, but not exported by uuid.lib */ |
| 31 | const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY = |
| 32 | {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}}; |
| 33 | |
| 34 | static IInternetHostSecurityManager *get_sec_mgr(script_ctx_t *ctx) |
| 35 | { |
| 36 | IInternetHostSecurityManager *secmgr; |
| 37 | IServiceProvider *sp; |
| 38 | HRESULT hres; |
| 39 | |
| 40 | if(!ctx->site) |
| 41 | return NULL; |
| 42 | |
| 43 | if(ctx->secmgr) |
| 44 | return ctx->secmgr; |
| 45 | |
| 46 | hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp); |
| 47 | if(FAILED(hres)) |
| 48 | return NULL; |
| 49 | |
| 50 | hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager, &IID_IInternetHostSecurityManager, |
| 51 | (void**)&secmgr); |
| 52 | IServiceProvider_Release(sp); |
| 53 | if(FAILED(hres)) |
| 54 | return NULL; |
| 55 | |
| 56 | return ctx->secmgr = secmgr; |
| 57 | } |
| 58 | |
| 59 | static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid) |
| 60 | { |
| 61 | IInternetHostSecurityManager *secmgr; |
Jacek Caban | 4462fb3 | 2009-10-04 22:01:27 +0200 | [diff] [blame] | 62 | IObjectWithSite *obj_site; |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 63 | struct CONFIRMSAFETY cs; |
Jacek Caban | 960d7f9 | 2009-10-02 13:54:51 +0200 | [diff] [blame] | 64 | IClassFactoryEx *cfex; |
| 65 | IClassFactory *cf; |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 66 | DWORD policy_size; |
| 67 | BYTE *bpolicy; |
| 68 | IUnknown *obj; |
| 69 | DWORD policy; |
| 70 | GUID guid; |
| 71 | HRESULT hres; |
| 72 | |
| 73 | hres = CLSIDFromProgID(progid, &guid); |
| 74 | if(FAILED(hres)) |
| 75 | return NULL; |
| 76 | |
| 77 | TRACE("GUID %s\n", debugstr_guid(&guid)); |
| 78 | |
| 79 | secmgr = get_sec_mgr(ctx); |
| 80 | if(!secmgr) |
| 81 | return NULL; |
| 82 | |
| 83 | policy = 0; |
| 84 | hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy), |
| 85 | (BYTE*)&guid, sizeof(GUID), 0, 0); |
| 86 | if(FAILED(hres) || policy != URLPOLICY_ALLOW) |
| 87 | return NULL; |
| 88 | |
Jacek Caban | d168f71 | 2009-11-17 00:03:06 +0100 | [diff] [blame] | 89 | hres = CoGetClassObject(&guid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf); |
Jacek Caban | 960d7f9 | 2009-10-02 13:54:51 +0200 | [diff] [blame] | 90 | if(FAILED(hres)) |
| 91 | return NULL; |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 92 | |
Jacek Caban | 960d7f9 | 2009-10-02 13:54:51 +0200 | [diff] [blame] | 93 | hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex); |
| 94 | if(SUCCEEDED(hres)) { |
| 95 | FIXME("Use IClassFactoryEx\n"); |
| 96 | IClassFactoryEx_Release(cfex); |
| 97 | } |
| 98 | |
| 99 | hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj); |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 100 | if(FAILED(hres)) |
| 101 | return NULL; |
| 102 | |
| 103 | cs.clsid = guid; |
| 104 | cs.pUnk = obj; |
| 105 | cs.dwFlags = 0; |
| 106 | hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &bpolicy, &policy_size, |
| 107 | (BYTE*)&cs, sizeof(cs), 0); |
| 108 | if(SUCCEEDED(hres)) { |
| 109 | policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW; |
| 110 | CoTaskMemFree(bpolicy); |
| 111 | } |
| 112 | |
| 113 | if(FAILED(hres) || policy != URLPOLICY_ALLOW) { |
| 114 | IUnknown_Release(obj); |
| 115 | return NULL; |
| 116 | } |
| 117 | |
Jacek Caban | 4462fb3 | 2009-10-04 22:01:27 +0200 | [diff] [blame] | 118 | hres = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (void**)&obj_site); |
| 119 | if(SUCCEEDED(hres)) { |
Jacek Caban | 06f26f5 | 2009-10-06 21:23:14 +0200 | [diff] [blame] | 120 | IUnknown *ax_site; |
| 121 | |
| 122 | ax_site = create_ax_site(ctx); |
| 123 | if(ax_site) { |
| 124 | hres = IObjectWithSite_SetSite(obj_site, ax_site); |
| 125 | IUnknown_Release(ax_site); |
| 126 | } |
Jacek Caban | 4462fb3 | 2009-10-04 22:01:27 +0200 | [diff] [blame] | 127 | IObjectWithSite_Release(obj_site); |
Jacek Caban | 06f26f5 | 2009-10-06 21:23:14 +0200 | [diff] [blame] | 128 | if(!ax_site || FAILED(hres)) { |
| 129 | IObjectWithSite_Release(obj_site); |
| 130 | IUnknown_Release(obj); |
| 131 | return NULL; |
| 132 | } |
Jacek Caban | 4462fb3 | 2009-10-04 22:01:27 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 135 | return obj; |
| 136 | } |
| 137 | |
Jacek Caban | 2ea2392 | 2009-09-29 00:10:50 +0200 | [diff] [blame] | 138 | static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, |
| 139 | VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) |
| 140 | { |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 141 | IDispatch *disp; |
| 142 | IUnknown *obj; |
| 143 | BSTR progid; |
| 144 | HRESULT hres; |
| 145 | |
| 146 | TRACE("\n"); |
| 147 | |
| 148 | if(flags != DISPATCH_CONSTRUCT) { |
| 149 | FIXME("unsupported flags %x\n", flags); |
| 150 | return E_NOTIMPL; |
| 151 | } |
| 152 | |
| 153 | if(ctx->safeopt != (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)) { |
| 154 | FIXME("Unsupported safeopt %x\n", ctx->safeopt); |
| 155 | return E_NOTIMPL; |
| 156 | } |
| 157 | |
| 158 | if(arg_cnt(dp) != 1) { |
Francois Gouget | fe935e8 | 2009-10-08 11:23:19 +0200 | [diff] [blame] | 159 | FIXME("unsupported arg_cnt %d\n", arg_cnt(dp)); |
Jacek Caban | 6d4533a | 2009-09-30 14:34:47 +0200 | [diff] [blame] | 160 | return E_NOTIMPL; |
| 161 | } |
| 162 | |
| 163 | hres = to_string(ctx, get_arg(dp,0), ei, &progid); |
| 164 | if(FAILED(hres)) |
| 165 | return hres; |
| 166 | |
| 167 | obj = create_activex_object(ctx, progid); |
| 168 | SysFreeString(progid); |
| 169 | if(!obj) |
| 170 | return throw_generic_error(ctx, ei, IDS_CREATE_OBJ_ERROR, NULL); |
| 171 | |
| 172 | hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&disp); |
| 173 | IUnknown_Release(obj); |
| 174 | if(FAILED(hres)) { |
| 175 | FIXME("Object does not support IDispatch\n"); |
| 176 | return E_NOTIMPL; |
| 177 | } |
| 178 | |
| 179 | V_VT(retv) = VT_DISPATCH; |
| 180 | V_DISPATCH(retv) = disp; |
| 181 | return S_OK; |
Jacek Caban | 2ea2392 | 2009-09-29 00:10:50 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | HRESULT create_activex_constr(script_ctx_t *ctx, DispatchEx **ret) |
| 185 | { |
| 186 | DispatchEx *prototype; |
| 187 | HRESULT hres; |
| 188 | |
| 189 | static const WCHAR ActiveXObjectW[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0}; |
| 190 | |
| 191 | hres = create_object(ctx, NULL, &prototype); |
| 192 | if(FAILED(hres)) |
| 193 | return hres; |
| 194 | |
Piotr Caban | 662a852 | 2009-10-13 22:08:43 +0200 | [diff] [blame] | 195 | hres = create_builtin_function(ctx, ActiveXObject_value, ActiveXObjectW, NULL, |
| 196 | PROPF_CONSTR|1, prototype, ret); |
Jacek Caban | 2ea2392 | 2009-09-29 00:10:50 +0200 | [diff] [blame] | 197 | |
| 198 | jsdisp_release(prototype); |
| 199 | return hres; |
| 200 | } |