2 * Copyright 2009 Jacek Caban for CodeWeavers
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.
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.
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
33 #include "wine/debug.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
41 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
42 DECLSPEC_HIDDEN const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
43 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
45 static inline HTMLDocumentNode *impl_from_IInternetHostSecurityManager(IInternetHostSecurityManager *iface)
47 return CONTAINING_RECORD(iface, HTMLDocumentNode, IInternetHostSecurityManager_iface);
50 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
52 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
53 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
56 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
58 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
59 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
62 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
64 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
65 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
68 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
69 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
71 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
72 FIXME("(%p)->(%p %p %lx)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
76 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
77 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
79 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
82 TRACE("(%p)->(%d %p %d %p %d %x %x)\n", This, dwAction, pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
84 url = This->basedoc.window->url ? This->basedoc.window->url : about_blankW;
86 return IInternetSecurityManager_ProcessUrlAction(This->basedoc.window->secmgr, url, dwAction, pPolicy, cbPolicy,
87 pContext, cbContext, dwFlags, dwReserved);
90 static HRESULT confirm_safety_load(HTMLDocumentNode *This, struct CONFIRMSAFETY *cs, DWORD *ret)
92 IObjectSafety *obj_safety;
95 hres = IUnknown_QueryInterface(cs->pUnk, &IID_IObjectSafety, (void**)&obj_safety);
97 hres = IObjectSafety_SetInterfaceSafetyOptions(obj_safety, &IID_IDispatch,
98 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
99 IObjectSafety_Release(obj_safety);
100 *ret = SUCCEEDED(hres) ? URLPOLICY_ALLOW : URLPOLICY_DISALLOW;
102 CATID init_catid = CATID_SafeForInitializing;
104 hres = ICatInformation_IsClassOfCategories(This->catmgr, &cs->clsid, 1, &init_catid, 0, NULL);
108 *ret = hres == S_OK ? URLPOLICY_ALLOW : URLPOLICY_DISALLOW;
114 static HRESULT confirm_safety(HTMLDocumentNode *This, const WCHAR *url, struct CONFIRMSAFETY *cs, DWORD *ret)
116 DWORD policy, enabled_opts, supported_opts;
117 IObjectSafety *obj_safety;
120 TRACE("%s %p %s\n", debugstr_w(url), cs->pUnk, debugstr_guid(&cs->clsid));
122 /* FIXME: Check URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY */
124 hres = IInternetSecurityManager_ProcessUrlAction(This->basedoc.window->secmgr, url, URLACTION_SCRIPT_SAFE_ACTIVEX,
125 (BYTE*)&policy, sizeof(policy), NULL, 0, 0, 0);
126 if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
127 *ret = URLPOLICY_DISALLOW;
131 hres = IUnknown_QueryInterface(cs->pUnk, &IID_IObjectSafety, (void**)&obj_safety);
132 if(SUCCEEDED(hres)) {
133 hres = IObjectSafety_GetInterfaceSafetyOptions(obj_safety, &IID_IDispatchEx, &supported_opts, &enabled_opts);
137 enabled_opts = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
138 if(supported_opts & INTERFACE_USES_SECURITY_MANAGER)
139 enabled_opts |= INTERFACE_USES_SECURITY_MANAGER;
141 hres = IObjectSafety_SetInterfaceSafetyOptions(obj_safety, &IID_IDispatchEx, enabled_opts, enabled_opts);
143 enabled_opts &= ~INTERFACE_USES_SECURITY_MANAGER;
144 hres = IObjectSafety_SetInterfaceSafetyOptions(obj_safety, &IID_IDispatch, enabled_opts, enabled_opts);
146 IObjectSafety_Release(obj_safety);
149 *ret = URLPOLICY_DISALLOW;
153 CATID scripting_catid = CATID_SafeForScripting;
156 hres = CoCreateInstance(&CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER,
157 &IID_ICatInformation, (void**)&This->catmgr);
162 hres = ICatInformation_IsClassOfCategories(This->catmgr, &cs->clsid, 1, &scripting_catid, 0, NULL);
167 *ret = URLPOLICY_DISALLOW;
172 if(cs->dwFlags & CONFIRMSAFETYACTION_LOADOBJECT)
173 return confirm_safety_load(This, cs, ret);
175 *ret = URLPOLICY_ALLOW;
179 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
180 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
182 HTMLDocumentNode *This = impl_from_IInternetHostSecurityManager(iface);
186 TRACE("(%p)->(%s %p %p %p %d %x)\n", This, debugstr_guid(guidKey), ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
188 url = This->basedoc.window->url ? This->basedoc.window->url : about_blankW;
190 hres = IInternetSecurityManager_QueryCustomPolicy(This->basedoc.window->secmgr, url, guidKey, ppPolicy, pcbPolicy,
191 pContext, cbContext, dwReserved);
192 if(hres != HRESULT_FROM_WIN32(ERROR_NOT_FOUND))
195 if(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey)) {
196 IActiveScript *active_script;
197 struct CONFIRMSAFETY *cs;
200 if(cbContext != sizeof(struct CONFIRMSAFETY)) {
201 FIXME("wrong context size\n");
205 cs = (struct CONFIRMSAFETY*)pContext;
206 TRACE("cs = {%s %p %x}\n", debugstr_guid(&cs->clsid), cs->pUnk, cs->dwFlags);
208 hres = IUnknown_QueryInterface(cs->pUnk, &IID_IActiveScript, (void**)&active_script);
209 if(SUCCEEDED(hres)) {
210 FIXME("Got IAciveScript iface\n");
211 IActiveScript_Release(active_script);
215 hres = confirm_safety(This, url, cs, &policy);
219 *ppPolicy = CoTaskMemAlloc(sizeof(policy));
221 return E_OUTOFMEMORY;
223 *(DWORD*)*ppPolicy = policy;
224 *pcbPolicy = sizeof(policy);
225 TRACE("policy %x\n", policy);
229 FIXME("Unknown guidKey %s\n", debugstr_guid(guidKey));
233 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
234 InternetHostSecurityManager_QueryInterface,
235 InternetHostSecurityManager_AddRef,
236 InternetHostSecurityManager_Release,
237 InternetHostSecurityManager_GetSecurityId,
238 InternetHostSecurityManager_ProcessUrlAction,
239 InternetHostSecurityManager_QueryCustomPolicy
242 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode *This)
244 This->IInternetHostSecurityManager_iface.lpVtbl = &InternetHostSecurityManagerVtbl;