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 #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
);
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
;
57 IUnknown_AddRef((IUnknown
*)*ppv
);
61 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
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
);
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
);
83 if(This
->doc
&& This
->doc
->location
== This
)
84 This
->doc
->location
= NULL
;
85 release_dispex(&This
->dispex
);
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
));
129 static HRESULT WINAPI
HTMLLocation_get_href(IHTMLLocation
*iface
, BSTR
*p
)
131 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
133 TRACE("(%p)->(%p)\n", This
, p
);
138 if(!This
->doc
|| !This
->doc
->url
) {
139 FIXME("No current URL\n");
143 *p
= SysAllocString(This
->doc
->url
);
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
));
155 static HRESULT WINAPI
HTMLLocation_get_protocol(IHTMLLocation
*iface
, BSTR
*p
)
157 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
158 FIXME("(%p)->(%p)\n", This
, p
);
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
));
169 static HRESULT WINAPI
HTMLLocation_get_host(IHTMLLocation
*iface
, BSTR
*p
)
171 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
172 FIXME("(%p)->(%p)\n", This
, p
);
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
));
183 static HRESULT WINAPI
HTMLLocation_get_hostname(IHTMLLocation
*iface
, BSTR
*p
)
185 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
186 FIXME("(%p)->(%p)\n", This
, p
);
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
));
197 static HRESULT WINAPI
HTMLLocation_get_port(IHTMLLocation
*iface
, BSTR
*p
)
199 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
200 FIXME("(%p)->(%p)\n", This
, p
);
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
));
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
)};
219 TRACE("(%p)->(%p)\n", This
, p
);
221 if(!This
->doc
|| !This
->doc
->url
) {
222 FIXME("No current URL\n");
226 hres
= CoInternetParseUrl(This
->doc
->url
, PARSE_PATH_FROM_URL
, 0, buf
, sizeof(buf
), &size
, 0);
227 if(SUCCEEDED(hres
)) {
228 *p
= SysAllocString(buf
);
230 return E_OUTOFMEMORY
;
234 url
.dwUrlPathLength
= 1;
235 if(!InternetCrackUrlW(This
->doc
->url
, 0, 0, &url
)) {
236 FIXME("InternetCrackUrl failed\n");
240 if(!url
.dwUrlPathLength
) {
245 *p
= SysAllocStringLen(url
.lpszUrlPath
, url
.dwUrlPathLength
);
247 return E_OUTOFMEMORY
;
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
));
258 static HRESULT WINAPI
HTMLLocation_get_search(IHTMLLocation
*iface
, BSTR
*p
)
260 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
261 FIXME("(%p)->(%p)\n", This
, p
);
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
));
272 static HRESULT WINAPI
HTMLLocation_get_hash(IHTMLLocation
*iface
, BSTR
*p
)
274 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
275 FIXME("(%p)->(%p)\n", This
, p
);
279 static HRESULT WINAPI
HTMLLocation_reload(IHTMLLocation
*iface
, VARIANT_BOOL flag
)
281 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
282 FIXME("(%p)->(%x)\n", This
, flag
);
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
));
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
));
300 static HRESULT WINAPI
HTMLLocation_toString(IHTMLLocation
*iface
, BSTR
*String
)
302 HTMLLocation
*This
= HTMLLOCATION_THIS(iface
);
303 FIXME("(%p)->(%p)\n", This
, String
);
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
);
313 TRACE("(%p)\n", This
);
316 case DISPATCH_PROPERTYGET
: {
319 hres
= IHTMLLocation_get_href(HTMLLOCATION(This
), &str
);
328 FIXME("unimplemented flags %x\n", flags
);
335 #undef HTMLLOCATION_THIS
337 static const IHTMLLocationVtbl HTMLLocationVtbl
= {
338 HTMLLocation_QueryInterface
,
340 HTMLLocation_Release
,
341 HTMLLocation_GetTypeInfoCount
,
342 HTMLLocation_GetTypeInfo
,
343 HTMLLocation_GetIDsOfNames
,
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
,
362 HTMLLocation_replace
,
364 HTMLLocation_toString
367 static const dispex_static_data_vtbl_t HTMLLocation_dispex_vtbl
= {
373 static const tid_t HTMLLocation_iface_tids
[] = {
377 static dispex_static_data_t HTMLLocation_dispex
= {
378 &HTMLLocation_dispex_vtbl
,
379 DispHTMLLocation_tid
,
381 HTMLLocation_iface_tids
385 HTMLLocation
*HTMLLocation_Create(HTMLDocument
*doc
)
387 HTMLLocation
*ret
= heap_alloc(sizeof(*ret
));
389 ret
->lpHTMLLocationVtbl
= &HTMLLocationVtbl
;
393 init_dispex(&ret
->dispex
, (IUnknown
*)HTMLLOCATION(ret
), &HTMLLocation_dispex
);