mshtml: Properly release DispatchEx data.
[wine/multimedia.git] / dlls / mshtml / htmllocation.c
blob8637838b776a55be57f227b8ae20c13b874dd0f0
1 /*
2 * Copyright 2008 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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "ole2.h"
28 #include "wininet.h"
29 #include "shlwapi.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "resource.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface)
40 static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
42 HTMLLocation *This = HTMLLOCATION_THIS(iface);
44 *ppv = NULL;
46 if(IsEqualGUID(&IID_IUnknown, riid)) {
47 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
48 *ppv = HTMLLOCATION(This);
49 }else if(IsEqualGUID(&IID_IHTMLLocation, riid)) {
50 TRACE("(%p)->(IID_IHTMLLocation %p)\n", This, ppv);
51 *ppv = HTMLLOCATION(This);
52 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
53 return *ppv ? S_OK : E_NOINTERFACE;
56 if(*ppv) {
57 IUnknown_AddRef((IUnknown*)*ppv);
58 return S_OK;
61 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
62 return E_NOINTERFACE;
65 static ULONG WINAPI HTMLLocation_AddRef(IHTMLLocation *iface)
67 HTMLLocation *This = HTMLLOCATION_THIS(iface);
68 LONG ref = InterlockedIncrement(&This->ref);
70 TRACE("(%p) ref=%d\n", This, ref);
72 return ref;
75 static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
77 HTMLLocation *This = HTMLLOCATION_THIS(iface);
78 LONG ref = InterlockedDecrement(&This->ref);
80 TRACE("(%p) ref=%d\n", This, ref);
82 if(!ref) {
83 if(This->doc && This->doc->location == This)
84 This->doc->location = NULL;
85 release_dispex(&This->dispex);
86 heap_free(This);
89 return ref;
92 static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
94 HTMLLocation *This = HTMLLOCATION_THIS(iface);
95 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
98 static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
99 LCID lcid, ITypeInfo **ppTInfo)
101 HTMLLocation *This = HTMLLOCATION_THIS(iface);
102 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
105 static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
106 LPOLESTR *rgszNames, UINT cNames,
107 LCID lcid, DISPID *rgDispId)
109 HTMLLocation *This = HTMLLOCATION_THIS(iface);
110 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
113 static HRESULT WINAPI HTMLLocation_Invoke(IHTMLLocation *iface, DISPID dispIdMember,
114 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
115 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
117 HTMLLocation *This = HTMLLOCATION_THIS(iface);
118 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
119 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
122 static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
124 HTMLLocation *This = HTMLLOCATION_THIS(iface);
125 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
126 return E_NOTIMPL;
129 static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
131 HTMLLocation *This = HTMLLOCATION_THIS(iface);
133 TRACE("(%p)->(%p)\n", This, p);
135 if(!p)
136 return E_POINTER;
138 if(!This->doc || !This->doc->url) {
139 FIXME("No current URL\n");
140 return E_NOTIMPL;
143 *p = SysAllocString(This->doc->url);
145 return S_OK;
148 static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
150 HTMLLocation *This = HTMLLOCATION_THIS(iface);
151 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
152 return E_NOTIMPL;
155 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
157 HTMLLocation *This = HTMLLOCATION_THIS(iface);
158 FIXME("(%p)->(%p)\n", This, p);
159 return E_NOTIMPL;
162 static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
164 HTMLLocation *This = HTMLLOCATION_THIS(iface);
165 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
166 return E_NOTIMPL;
169 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
171 HTMLLocation *This = HTMLLOCATION_THIS(iface);
172 FIXME("(%p)->(%p)\n", This, p);
173 return E_NOTIMPL;
176 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
178 HTMLLocation *This = HTMLLOCATION_THIS(iface);
179 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
180 return E_NOTIMPL;
183 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
185 HTMLLocation *This = HTMLLOCATION_THIS(iface);
186 FIXME("(%p)->(%p)\n", This, p);
187 return E_NOTIMPL;
190 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
192 HTMLLocation *This = HTMLLOCATION_THIS(iface);
193 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
194 return E_NOTIMPL;
197 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
199 HTMLLocation *This = HTMLLOCATION_THIS(iface);
200 FIXME("(%p)->(%p)\n", This, p);
201 return E_NOTIMPL;
204 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
206 HTMLLocation *This = HTMLLOCATION_THIS(iface);
207 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
208 return E_NOTIMPL;
211 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
213 HTMLLocation *This = HTMLLOCATION_THIS(iface);
214 WCHAR buf[INTERNET_MAX_PATH_LENGTH];
215 URL_COMPONENTSW url = {sizeof(url)};
216 DWORD size = 0;
217 HRESULT hres;
219 TRACE("(%p)->(%p)\n", This, p);
221 if(!This->doc || !This->doc->url) {
222 FIXME("No current URL\n");
223 return E_NOTIMPL;
226 hres = CoInternetParseUrl(This->doc->url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
227 if(SUCCEEDED(hres)) {
228 *p = SysAllocString(buf);
229 if(!*p)
230 return E_OUTOFMEMORY;
231 return S_OK;
234 url.dwUrlPathLength = 1;
235 if(!InternetCrackUrlW(This->doc->url, 0, 0, &url)) {
236 FIXME("InternetCrackUrl failed\n");
237 return E_FAIL;
240 if(!url.dwUrlPathLength) {
241 *p = NULL;
242 return S_OK;
245 *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
246 if(!*p)
247 return E_OUTOFMEMORY;
248 return S_OK;
251 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
253 HTMLLocation *This = HTMLLOCATION_THIS(iface);
254 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
255 return E_NOTIMPL;
258 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
260 HTMLLocation *This = HTMLLOCATION_THIS(iface);
261 FIXME("(%p)->(%p)\n", This, p);
262 return E_NOTIMPL;
265 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
267 HTMLLocation *This = HTMLLOCATION_THIS(iface);
268 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
269 return E_NOTIMPL;
272 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
274 HTMLLocation *This = HTMLLOCATION_THIS(iface);
275 FIXME("(%p)->(%p)\n", This, p);
276 return E_NOTIMPL;
279 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
281 HTMLLocation *This = HTMLLOCATION_THIS(iface);
282 FIXME("(%p)->(%x)\n", This, flag);
283 return E_NOTIMPL;
286 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
288 HTMLLocation *This = HTMLLOCATION_THIS(iface);
289 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
290 return E_NOTIMPL;
293 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
295 HTMLLocation *This = HTMLLOCATION_THIS(iface);
296 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
297 return E_NOTIMPL;
300 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
302 HTMLLocation *This = HTMLLOCATION_THIS(iface);
303 FIXME("(%p)->(%p)\n", This, String);
304 return E_NOTIMPL;
307 static HRESULT HTMLLocation_value(IUnknown *iface, LCID lcid, WORD flags, DISPPARAMS *params,
308 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
310 HTMLLocation *This = HTMLLOCATION_THIS(iface);
311 HRESULT hres;
313 TRACE("(%p)\n", This);
315 switch(flags) {
316 case DISPATCH_PROPERTYGET: {
317 BSTR str;
319 hres = IHTMLLocation_get_href(HTMLLOCATION(This), &str);
320 if(FAILED(hres))
321 return hres;
323 V_VT(res) = VT_BSTR;
324 V_BSTR(res) = str;
325 break;
327 default:
328 FIXME("unimplemented flags %x\n", flags);
329 return E_NOTIMPL;
332 return S_OK;
335 #undef HTMLLOCATION_THIS
337 static const IHTMLLocationVtbl HTMLLocationVtbl = {
338 HTMLLocation_QueryInterface,
339 HTMLLocation_AddRef,
340 HTMLLocation_Release,
341 HTMLLocation_GetTypeInfoCount,
342 HTMLLocation_GetTypeInfo,
343 HTMLLocation_GetIDsOfNames,
344 HTMLLocation_Invoke,
345 HTMLLocation_put_href,
346 HTMLLocation_get_href,
347 HTMLLocation_put_protocol,
348 HTMLLocation_get_protocol,
349 HTMLLocation_put_host,
350 HTMLLocation_get_host,
351 HTMLLocation_put_hostname,
352 HTMLLocation_get_hostname,
353 HTMLLocation_put_port,
354 HTMLLocation_get_port,
355 HTMLLocation_put_pathname,
356 HTMLLocation_get_pathname,
357 HTMLLocation_put_search,
358 HTMLLocation_get_search,
359 HTMLLocation_put_hash,
360 HTMLLocation_get_hash,
361 HTMLLocation_reload,
362 HTMLLocation_replace,
363 HTMLLocation_assign,
364 HTMLLocation_toString
367 static const dispex_static_data_vtbl_t HTMLLocation_dispex_vtbl = {
368 HTMLLocation_value,
369 NULL,
370 NULL
373 static const tid_t HTMLLocation_iface_tids[] = {
374 IHTMLLocation_tid,
377 static dispex_static_data_t HTMLLocation_dispex = {
378 &HTMLLocation_dispex_vtbl,
379 DispHTMLLocation_tid,
380 NULL,
381 HTMLLocation_iface_tids
385 HTMLLocation *HTMLLocation_Create(HTMLDocument *doc)
387 HTMLLocation *ret = heap_alloc(sizeof(*ret));
389 ret->lpHTMLLocationVtbl = &HTMLLocationVtbl;
390 ret->ref = 1;
391 ret->doc = doc;
393 init_dispex(&ret->dispex, (IUnknown*)HTMLLOCATION(ret), &HTMLLocation_dispex);
395 return ret;