ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

activex.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 Jacek Caban for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 #include "wine/port.h"
00021 
00022 #include "jscript.h"
00023 #include "objsafe.h"
00024 #include "mshtmhst.h"
00025 
00026 #include "wine/debug.h"
00027 
00028 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
00029 
00030 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
00031 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
00032     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
00033 
00034 static IInternetHostSecurityManager *get_sec_mgr(script_ctx_t *ctx)
00035 {
00036     IInternetHostSecurityManager *secmgr;
00037     IServiceProvider *sp;
00038     HRESULT hres;
00039 
00040     if(!ctx->site)
00041         return NULL;
00042 
00043     if(ctx->secmgr)
00044         return ctx->secmgr;
00045 
00046     hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
00047     if(FAILED(hres))
00048         return NULL;
00049 
00050     hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager, &IID_IInternetHostSecurityManager,
00051             (void**)&secmgr);
00052     IServiceProvider_Release(sp);
00053     if(FAILED(hres))
00054         return NULL;
00055 
00056     return ctx->secmgr = secmgr;
00057 }
00058 
00059 static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid)
00060 {
00061     IInternetHostSecurityManager *secmgr;
00062     IObjectWithSite *obj_site;
00063     struct CONFIRMSAFETY cs;
00064     IClassFactoryEx *cfex;
00065     IClassFactory *cf;
00066     DWORD policy_size;
00067     BYTE *bpolicy;
00068     IUnknown *obj;
00069     DWORD policy;
00070     GUID guid;
00071     HRESULT hres;
00072 
00073     hres = CLSIDFromProgID(progid, &guid);
00074     if(FAILED(hres))
00075         return NULL;
00076 
00077     TRACE("GUID %s\n", debugstr_guid(&guid));
00078 
00079     secmgr = get_sec_mgr(ctx);
00080     if(!secmgr)
00081         return NULL;
00082 
00083     policy = 0;
00084     hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
00085             (BYTE*)&guid, sizeof(GUID), 0, 0);
00086     if(FAILED(hres) || policy != URLPOLICY_ALLOW)
00087         return NULL;
00088 
00089     hres = CoGetClassObject(&guid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf);
00090     if(FAILED(hres))
00091         return NULL;
00092 
00093     hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex);
00094     if(SUCCEEDED(hres)) {
00095         FIXME("Use IClassFactoryEx\n");
00096         IClassFactoryEx_Release(cfex);
00097     }
00098 
00099     hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj);
00100     if(FAILED(hres))
00101         return NULL;
00102 
00103     cs.clsid = guid;
00104     cs.pUnk = obj;
00105     cs.dwFlags = 0;
00106     hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY, &bpolicy, &policy_size,
00107             (BYTE*)&cs, sizeof(cs), 0);
00108     if(SUCCEEDED(hres)) {
00109         policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW;
00110         CoTaskMemFree(bpolicy);
00111     }
00112 
00113     if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
00114         IUnknown_Release(obj);
00115         return NULL;
00116     }
00117 
00118     hres = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (void**)&obj_site);
00119     if(SUCCEEDED(hres)) {
00120         IUnknown *ax_site;
00121 
00122         ax_site = create_ax_site(ctx);
00123         if(ax_site) {
00124             hres = IObjectWithSite_SetSite(obj_site, ax_site);
00125             IUnknown_Release(ax_site);
00126         }
00127         IObjectWithSite_Release(obj_site);
00128         if(!ax_site || FAILED(hres)) {
00129             IObjectWithSite_Release(obj_site);
00130             IUnknown_Release(obj);
00131             return NULL;
00132         }
00133     }
00134 
00135     return obj;
00136 }
00137 
00138 static HRESULT ActiveXObject_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
00139         VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
00140 {
00141     IDispatch *disp;
00142     IUnknown *obj;
00143     BSTR progid;
00144     HRESULT hres;
00145 
00146     TRACE("\n");
00147 
00148     if(flags != DISPATCH_CONSTRUCT) {
00149         FIXME("unsupported flags %x\n", flags);
00150         return E_NOTIMPL;
00151     }
00152 
00153     if(ctx->safeopt != (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)) {
00154         FIXME("Unsupported safeopt %x\n", ctx->safeopt);
00155         return E_NOTIMPL;
00156     }
00157 
00158     if(arg_cnt(dp) != 1) {
00159         FIXME("unsupported arg_cnt %d\n", arg_cnt(dp));
00160         return E_NOTIMPL;
00161     }
00162 
00163     hres = to_string(ctx, get_arg(dp,0), ei, &progid);
00164     if(FAILED(hres))
00165         return hres;
00166 
00167     obj = create_activex_object(ctx, progid);
00168     SysFreeString(progid);
00169     if(!obj)
00170         return throw_generic_error(ctx, ei, IDS_CREATE_OBJ_ERROR, NULL);
00171 
00172     hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&disp);
00173     IUnknown_Release(obj);
00174     if(FAILED(hres)) {
00175         FIXME("Object does not support IDispatch\n");
00176         return E_NOTIMPL;
00177     }
00178 
00179     V_VT(retv) = VT_DISPATCH;
00180     V_DISPATCH(retv) = disp;
00181     return S_OK;
00182 }
00183 
00184 HRESULT create_activex_constr(script_ctx_t *ctx, DispatchEx **ret)
00185 {
00186     DispatchEx *prototype;
00187     HRESULT hres;
00188 
00189     static const WCHAR ActiveXObjectW[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0};
00190 
00191     hres = create_object(ctx, NULL, &prototype);
00192     if(FAILED(hres))
00193         return hres;
00194 
00195     hres = create_builtin_function(ctx, ActiveXObject_value, ActiveXObjectW, NULL,
00196             PROPF_CONSTR|1, prototype, ret);
00197 
00198     jsdisp_release(prototype);
00199     return hres;
00200 }

Generated on Thu May 24 2012 04:24:34 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.