push 8b07bf1f08b23b9893a622b47d2be359556765b1
[wine/hacks.git] / dlls / mshtml / htmllocation.c
blobe21ec76016f3c2d667062e72c7c1396b9fda2ef4
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 static HRESULT get_url(HTMLLocation *This, const WCHAR **ret)
40 if(!This->window || !This->window->doc_obj || !This->window->doc_obj->url) {
41 FIXME("No current URL\n");
42 return E_NOTIMPL;
45 *ret = This->window->doc_obj->url;
46 return S_OK;
49 static HRESULT get_url_components(HTMLLocation *This, URL_COMPONENTSW *url)
51 const WCHAR *doc_url;
52 HRESULT hres;
54 hres = get_url(This, &doc_url);
55 if(FAILED(hres))
56 return hres;
58 if(!InternetCrackUrlW(doc_url, 0, 0, url)) {
59 FIXME("InternetCrackUrlW failed: 0x%08x\n", GetLastError());
60 SetLastError(0);
61 return E_FAIL;
64 return S_OK;
67 #define HTMLLOCATION_THIS(iface) DEFINE_THIS(HTMLLocation, HTMLLocation, iface)
69 static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
71 HTMLLocation *This = HTMLLOCATION_THIS(iface);
73 *ppv = NULL;
75 if(IsEqualGUID(&IID_IUnknown, riid)) {
76 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
77 *ppv = HTMLLOCATION(This);
78 }else if(IsEqualGUID(&IID_IHTMLLocation, riid)) {
79 TRACE("(%p)->(IID_IHTMLLocation %p)\n", This, ppv);
80 *ppv = HTMLLOCATION(This);
81 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
82 return *ppv ? S_OK : E_NOINTERFACE;
85 if(*ppv) {
86 IUnknown_AddRef((IUnknown*)*ppv);
87 return S_OK;
90 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
91 return E_NOINTERFACE;
94 static ULONG WINAPI HTMLLocation_AddRef(IHTMLLocation *iface)
96 HTMLLocation *This = HTMLLOCATION_THIS(iface);
97 LONG ref = InterlockedIncrement(&This->ref);
99 TRACE("(%p) ref=%d\n", This, ref);
101 return ref;
104 static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
106 HTMLLocation *This = HTMLLOCATION_THIS(iface);
107 LONG ref = InterlockedDecrement(&This->ref);
109 TRACE("(%p) ref=%d\n", This, ref);
111 if(!ref) {
112 if(This->window)
113 This->window->location = NULL;
114 release_dispex(&This->dispex);
115 heap_free(This);
118 return ref;
121 static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
123 HTMLLocation *This = HTMLLOCATION_THIS(iface);
124 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
127 static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
128 LCID lcid, ITypeInfo **ppTInfo)
130 HTMLLocation *This = HTMLLOCATION_THIS(iface);
131 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
134 static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
135 LPOLESTR *rgszNames, UINT cNames,
136 LCID lcid, DISPID *rgDispId)
138 HTMLLocation *This = HTMLLOCATION_THIS(iface);
139 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
142 static HRESULT WINAPI HTMLLocation_Invoke(IHTMLLocation *iface, DISPID dispIdMember,
143 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
144 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
146 HTMLLocation *This = HTMLLOCATION_THIS(iface);
147 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
148 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
151 static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
153 HTMLLocation *This = HTMLLOCATION_THIS(iface);
155 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
157 if(!This->window || !This->window->doc) {
158 FIXME("No document available\n");
159 return E_FAIL;
162 return navigate_url(This->window->doc, v);
165 static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
167 HTMLLocation *This = HTMLLOCATION_THIS(iface);
168 const WCHAR *url;
169 HRESULT hres;
171 TRACE("(%p)->(%p)\n", This, p);
173 if(!p)
174 return E_POINTER;
176 hres = get_url(This, &url);
177 if(FAILED(hres))
178 return hres;
180 *p = SysAllocString(url);
181 return *p ? S_OK : E_OUTOFMEMORY;
184 static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
186 HTMLLocation *This = HTMLLOCATION_THIS(iface);
187 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
188 return E_NOTIMPL;
191 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
193 HTMLLocation *This = HTMLLOCATION_THIS(iface);
194 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
195 HRESULT hres;
197 TRACE("(%p)->(%p)\n", This, p);
199 if(!p)
200 return E_POINTER;
202 url.dwSchemeLength = 1;
203 hres = get_url_components(This, &url);
204 if(FAILED(hres))
205 return hres;
207 if(!url.dwSchemeLength) {
208 FIXME("Unexpected blank protocol\n");
209 return E_NOTIMPL;
210 }else {
211 WCHAR buf[url.dwSchemeLength + 1];
212 memcpy(buf, url.lpszScheme, url.dwSchemeLength * sizeof(WCHAR));
213 buf[url.dwSchemeLength] = ':';
214 *p = SysAllocStringLen(buf, url.dwSchemeLength + 1);
216 if(!*p)
217 return E_OUTOFMEMORY;
218 return S_OK;
221 static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
223 HTMLLocation *This = HTMLLOCATION_THIS(iface);
224 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
225 return E_NOTIMPL;
228 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
230 HTMLLocation *This = HTMLLOCATION_THIS(iface);
231 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
232 HRESULT hres;
234 TRACE("(%p)->(%p)\n", This, p);
236 if(!p)
237 return E_POINTER;
239 url.dwHostNameLength = 1;
240 hres = get_url_components(This, &url);
241 if(FAILED(hres))
242 return hres;
244 if(!url.dwHostNameLength){
245 *p = NULL;
246 return S_OK;
249 if(url.nPort) {
250 /* <hostname>:<port> */
251 const WCHAR format[] = {'%','d',0};
252 DWORD len = url.dwHostNameLength + 1 + 5 + 1;
253 WCHAR buf[len];
255 memcpy(buf, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
256 buf[url.dwHostNameLength] = ':';
257 snprintfW(buf + url.dwHostNameLength + 1, 6, format, url.nPort);
258 *p = SysAllocString(buf);
259 }else
260 *p = SysAllocStringLen(url.lpszHostName, url.dwHostNameLength);
262 if(!*p)
263 return E_OUTOFMEMORY;
264 return S_OK;
267 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
269 HTMLLocation *This = HTMLLOCATION_THIS(iface);
270 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
271 return E_NOTIMPL;
274 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
276 HTMLLocation *This = HTMLLOCATION_THIS(iface);
277 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
278 HRESULT hres;
280 TRACE("(%p)->(%p)\n", This, p);
282 if(!p)
283 return E_POINTER;
285 url.dwHostNameLength = 1;
286 hres = get_url_components(This, &url);
287 if(FAILED(hres))
288 return hres;
290 if(!url.dwHostNameLength){
291 *p = NULL;
292 return S_OK;
295 *p = SysAllocStringLen(url.lpszHostName, url.dwHostNameLength);
296 if(!*p)
297 return E_OUTOFMEMORY;
298 return S_OK;
301 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
303 HTMLLocation *This = HTMLLOCATION_THIS(iface);
304 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
310 HTMLLocation *This = HTMLLOCATION_THIS(iface);
311 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
312 HRESULT hres;
314 TRACE("(%p)->(%p)\n", This, p);
316 if(!p)
317 return E_POINTER;
319 hres = get_url_components(This, &url);
320 if(FAILED(hres))
321 return hres;
323 if(url.nPort) {
324 const WCHAR format[] = {'%','d',0};
325 WCHAR buf[6];
326 snprintfW(buf, 6, format, url.nPort);
327 *p = SysAllocString(buf);
328 }else {
329 const WCHAR empty[] = {0};
330 *p = SysAllocString(empty);
333 if(!*p)
334 return E_OUTOFMEMORY;
335 return S_OK;
338 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
340 HTMLLocation *This = HTMLLOCATION_THIS(iface);
341 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
342 return E_NOTIMPL;
345 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
347 HTMLLocation *This = HTMLLOCATION_THIS(iface);
348 WCHAR buf[INTERNET_MAX_PATH_LENGTH];
349 URL_COMPONENTSW url = {sizeof(url)};
350 const WCHAR *doc_url;
351 DWORD size = 0;
352 HRESULT hres;
354 TRACE("(%p)->(%p)\n", This, p);
356 if(!p)
357 return E_POINTER;
359 hres = get_url(This, &doc_url);
360 if(FAILED(hres))
361 return hres;
363 hres = CoInternetParseUrl(doc_url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
364 if(SUCCEEDED(hres)) {
365 *p = SysAllocString(buf);
366 if(!*p)
367 return E_OUTOFMEMORY;
368 return S_OK;
371 url.dwUrlPathLength = 1;
372 hres = get_url_components(This, &url);
373 if(FAILED(hres))
374 return hres;
376 if(!url.dwUrlPathLength) {
377 *p = NULL;
378 return S_OK;
381 *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
382 if(!*p)
383 return E_OUTOFMEMORY;
384 return S_OK;
387 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
389 HTMLLocation *This = HTMLLOCATION_THIS(iface);
390 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
391 return E_NOTIMPL;
394 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
396 HTMLLocation *This = HTMLLOCATION_THIS(iface);
397 FIXME("(%p)->(%p)\n", This, p);
399 if(!p)
400 return E_POINTER;
402 return E_NOTIMPL;
405 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
407 HTMLLocation *This = HTMLLOCATION_THIS(iface);
408 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
409 return E_NOTIMPL;
412 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
414 HTMLLocation *This = HTMLLOCATION_THIS(iface);
415 FIXME("(%p)->(%p)\n", This, p);
417 if(!p)
418 return E_POINTER;
420 return E_NOTIMPL;
423 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
425 HTMLLocation *This = HTMLLOCATION_THIS(iface);
426 FIXME("(%p)->(%x)\n", This, flag);
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
432 HTMLLocation *This = HTMLLOCATION_THIS(iface);
433 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
439 HTMLLocation *This = HTMLLOCATION_THIS(iface);
440 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
441 return E_NOTIMPL;
444 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
446 HTMLLocation *This = HTMLLOCATION_THIS(iface);
447 FIXME("(%p)->(%p)\n", This, String);
448 return E_NOTIMPL;
451 #undef HTMLLOCATION_THIS
453 static const IHTMLLocationVtbl HTMLLocationVtbl = {
454 HTMLLocation_QueryInterface,
455 HTMLLocation_AddRef,
456 HTMLLocation_Release,
457 HTMLLocation_GetTypeInfoCount,
458 HTMLLocation_GetTypeInfo,
459 HTMLLocation_GetIDsOfNames,
460 HTMLLocation_Invoke,
461 HTMLLocation_put_href,
462 HTMLLocation_get_href,
463 HTMLLocation_put_protocol,
464 HTMLLocation_get_protocol,
465 HTMLLocation_put_host,
466 HTMLLocation_get_host,
467 HTMLLocation_put_hostname,
468 HTMLLocation_get_hostname,
469 HTMLLocation_put_port,
470 HTMLLocation_get_port,
471 HTMLLocation_put_pathname,
472 HTMLLocation_get_pathname,
473 HTMLLocation_put_search,
474 HTMLLocation_get_search,
475 HTMLLocation_put_hash,
476 HTMLLocation_get_hash,
477 HTMLLocation_reload,
478 HTMLLocation_replace,
479 HTMLLocation_assign,
480 HTMLLocation_toString
483 static const tid_t HTMLLocation_iface_tids[] = {
484 IHTMLLocation_tid,
487 static dispex_static_data_t HTMLLocation_dispex = {
488 NULL,
489 DispHTMLLocation_tid,
490 NULL,
491 HTMLLocation_iface_tids
495 HRESULT HTMLLocation_Create(HTMLWindow *window, HTMLLocation **ret)
497 HTMLLocation *location;
499 location = heap_alloc(sizeof(*location));
500 if(!location)
501 return E_OUTOFMEMORY;
503 location->lpHTMLLocationVtbl = &HTMLLocationVtbl;
504 location->ref = 1;
505 location->window = window;
507 init_dispex(&location->dispex, (IUnknown*)HTMLLOCATION(location), &HTMLLocation_dispex);
509 *ret = location;
510 return S_OK;