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
31 #include "wine/debug.h"
33 #include "mshtml_private.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");
45 *ret = This->window->doc_obj->url;
49 static HRESULT get_url_components(HTMLLocation *This, URL_COMPONENTSW *url)
54 hres = get_url(This, &doc_url);
58 if(!InternetCrackUrlW(doc_url, 0, 0, url)) {
59 FIXME("InternetCrackUrlW failed: 0x%08x\n", GetLastError());
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);
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;
86 IUnknown_AddRef((IUnknown*)*ppv);
90 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
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);
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);
113 This->window->location = NULL;
114 release_dispex(&This->dispex);
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");
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);
171 TRACE("(%p)->(%p)\n", This, p);
176 hres = get_url(This, &url);
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));
191 static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
193 HTMLLocation *This = HTMLLOCATION_THIS(iface);
194 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
197 TRACE("(%p)->(%p)\n", This, p);
202 url.dwSchemeLength = 1;
203 hres = get_url_components(This, &url);
207 if(!url.dwSchemeLength) {
208 FIXME("Unexpected blank protocol\n");
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);
217 return E_OUTOFMEMORY;
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));
228 static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
230 HTMLLocation *This = HTMLLOCATION_THIS(iface);
231 FIXME("(%p)->(%p)\n", This, p);
239 static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
241 HTMLLocation *This = HTMLLOCATION_THIS(iface);
242 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
246 static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
248 HTMLLocation *This = HTMLLOCATION_THIS(iface);
249 FIXME("(%p)->(%p)\n", This, p);
257 static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
259 HTMLLocation *This = HTMLLOCATION_THIS(iface);
260 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
264 static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
266 HTMLLocation *This = HTMLLOCATION_THIS(iface);
267 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
270 TRACE("(%p)->(%p)\n", This, p);
275 hres = get_url_components(This, &url);
280 const WCHAR format[] = {'%','d',0};
282 snprintfW(buf, 6, format, url.nPort);
283 *p = SysAllocString(buf);
285 const WCHAR empty[] = {0};
286 *p = SysAllocString(empty);
290 return E_OUTOFMEMORY;
294 static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
296 HTMLLocation *This = HTMLLOCATION_THIS(iface);
297 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
301 static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
303 HTMLLocation *This = HTMLLOCATION_THIS(iface);
304 WCHAR buf[INTERNET_MAX_PATH_LENGTH];
305 URL_COMPONENTSW url = {sizeof(url)};
306 const WCHAR *doc_url;
310 TRACE("(%p)->(%p)\n", This, p);
315 hres = get_url(This, &doc_url);
319 hres = CoInternetParseUrl(doc_url, PARSE_PATH_FROM_URL, 0, buf, sizeof(buf), &size, 0);
320 if(SUCCEEDED(hres)) {
321 *p = SysAllocString(buf);
323 return E_OUTOFMEMORY;
327 url.dwUrlPathLength = 1;
328 hres = get_url_components(This, &url);
332 if(!url.dwUrlPathLength) {
337 *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
339 return E_OUTOFMEMORY;
343 static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
345 HTMLLocation *This = HTMLLOCATION_THIS(iface);
346 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
350 static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
352 HTMLLocation *This = HTMLLOCATION_THIS(iface);
353 FIXME("(%p)->(%p)\n", This, p);
361 static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
363 HTMLLocation *This = HTMLLOCATION_THIS(iface);
364 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
368 static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
370 HTMLLocation *This = HTMLLOCATION_THIS(iface);
371 FIXME("(%p)->(%p)\n", This, p);
379 static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
381 HTMLLocation *This = HTMLLOCATION_THIS(iface);
382 FIXME("(%p)->(%x)\n", This, flag);
386 static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
388 HTMLLocation *This = HTMLLOCATION_THIS(iface);
389 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
393 static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
395 HTMLLocation *This = HTMLLOCATION_THIS(iface);
396 FIXME("(%p)->(%s)\n", This, debugstr_w(bstr));
400 static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
402 HTMLLocation *This = HTMLLOCATION_THIS(iface);
403 FIXME("(%p)->(%p)\n", This, String);
407 #undef HTMLLOCATION_THIS
409 static const IHTMLLocationVtbl HTMLLocationVtbl = {
410 HTMLLocation_QueryInterface,
412 HTMLLocation_Release,
413 HTMLLocation_GetTypeInfoCount,
414 HTMLLocation_GetTypeInfo,
415 HTMLLocation_GetIDsOfNames,
417 HTMLLocation_put_href,
418 HTMLLocation_get_href,
419 HTMLLocation_put_protocol,
420 HTMLLocation_get_protocol,
421 HTMLLocation_put_host,
422 HTMLLocation_get_host,
423 HTMLLocation_put_hostname,
424 HTMLLocation_get_hostname,
425 HTMLLocation_put_port,
426 HTMLLocation_get_port,
427 HTMLLocation_put_pathname,
428 HTMLLocation_get_pathname,
429 HTMLLocation_put_search,
430 HTMLLocation_get_search,
431 HTMLLocation_put_hash,
432 HTMLLocation_get_hash,
434 HTMLLocation_replace,
436 HTMLLocation_toString
439 static const tid_t HTMLLocation_iface_tids[] = {
443 static dispex_static_data_t HTMLLocation_dispex = {
445 DispHTMLLocation_tid,
447 HTMLLocation_iface_tids
451 HRESULT HTMLLocation_Create(HTMLWindow *window, HTMLLocation **ret)
453 HTMLLocation *location;
455 location = heap_alloc(sizeof(*location));
457 return E_OUTOFMEMORY;
459 location->lpHTMLLocationVtbl = &HTMLLocationVtbl;
461 location->window = window;
463 init_dispex(&location->dispex, (IUnknown*)HTMLLOCATION(location), &HTMLLocation_dispex);