xref: /reactos/dll/win32/mshtml/htmllocation.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright 2008 Jacek Caban for CodeWeavers
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8*c2c66affSColin Finck  *
9*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*c2c66affSColin Finck  * Lesser General Public License for more details.
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17*c2c66affSColin Finck  */
18*c2c66affSColin Finck 
19*c2c66affSColin Finck #include "mshtml_private.h"
20*c2c66affSColin Finck 
get_url(HTMLLocation * This,const WCHAR ** ret)21*c2c66affSColin Finck static HRESULT get_url(HTMLLocation *This, const WCHAR **ret)
22*c2c66affSColin Finck {
23*c2c66affSColin Finck     if(!This->window || !This->window->base.outer_window || !This->window->base.outer_window->url) {
24*c2c66affSColin Finck         FIXME("No current URL\n");
25*c2c66affSColin Finck         return E_NOTIMPL;
26*c2c66affSColin Finck     }
27*c2c66affSColin Finck 
28*c2c66affSColin Finck     *ret = This->window->base.outer_window->url;
29*c2c66affSColin Finck     return S_OK;
30*c2c66affSColin Finck }
31*c2c66affSColin Finck 
get_uri(HTMLLocation * This)32*c2c66affSColin Finck static IUri *get_uri(HTMLLocation *This)
33*c2c66affSColin Finck {
34*c2c66affSColin Finck     if(!This->window || !This->window->base.outer_window)
35*c2c66affSColin Finck         return NULL;
36*c2c66affSColin Finck     return This->window->base.outer_window->uri;
37*c2c66affSColin Finck }
38*c2c66affSColin Finck 
get_url_components(HTMLLocation * This,URL_COMPONENTSW * url)39*c2c66affSColin Finck static HRESULT get_url_components(HTMLLocation *This, URL_COMPONENTSW *url)
40*c2c66affSColin Finck {
41*c2c66affSColin Finck     const WCHAR *doc_url;
42*c2c66affSColin Finck     HRESULT hres;
43*c2c66affSColin Finck 
44*c2c66affSColin Finck     hres = get_url(This, &doc_url);
45*c2c66affSColin Finck     if(FAILED(hres))
46*c2c66affSColin Finck         return hres;
47*c2c66affSColin Finck 
48*c2c66affSColin Finck     if(!InternetCrackUrlW(doc_url, 0, 0, url)) {
49*c2c66affSColin Finck         FIXME("InternetCrackUrlW failed: 0x%08x\n", GetLastError());
50*c2c66affSColin Finck         SetLastError(0);
51*c2c66affSColin Finck         return E_FAIL;
52*c2c66affSColin Finck     }
53*c2c66affSColin Finck 
54*c2c66affSColin Finck     return S_OK;
55*c2c66affSColin Finck }
56*c2c66affSColin Finck 
impl_from_IHTMLLocation(IHTMLLocation * iface)57*c2c66affSColin Finck static inline HTMLLocation *impl_from_IHTMLLocation(IHTMLLocation *iface)
58*c2c66affSColin Finck {
59*c2c66affSColin Finck     return CONTAINING_RECORD(iface, HTMLLocation, IHTMLLocation_iface);
60*c2c66affSColin Finck }
61*c2c66affSColin Finck 
HTMLLocation_QueryInterface(IHTMLLocation * iface,REFIID riid,void ** ppv)62*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_QueryInterface(IHTMLLocation *iface, REFIID riid, void **ppv)
63*c2c66affSColin Finck {
64*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
65*c2c66affSColin Finck 
66*c2c66affSColin Finck     TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
67*c2c66affSColin Finck 
68*c2c66affSColin Finck     if(IsEqualGUID(&IID_IUnknown, riid)) {
69*c2c66affSColin Finck         *ppv = &This->IHTMLLocation_iface;
70*c2c66affSColin Finck     }else if(IsEqualGUID(&IID_IHTMLLocation, riid)) {
71*c2c66affSColin Finck         *ppv = &This->IHTMLLocation_iface;
72*c2c66affSColin Finck     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
73*c2c66affSColin Finck         return *ppv ? S_OK : E_NOINTERFACE;
74*c2c66affSColin Finck     }else {
75*c2c66affSColin Finck         *ppv = NULL;
76*c2c66affSColin Finck         WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
77*c2c66affSColin Finck         return E_NOINTERFACE;
78*c2c66affSColin Finck     }
79*c2c66affSColin Finck 
80*c2c66affSColin Finck     IUnknown_AddRef((IUnknown*)*ppv);
81*c2c66affSColin Finck     return S_OK;
82*c2c66affSColin Finck }
83*c2c66affSColin Finck 
HTMLLocation_AddRef(IHTMLLocation * iface)84*c2c66affSColin Finck static ULONG WINAPI HTMLLocation_AddRef(IHTMLLocation *iface)
85*c2c66affSColin Finck {
86*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
87*c2c66affSColin Finck     LONG ref = InterlockedIncrement(&This->ref);
88*c2c66affSColin Finck 
89*c2c66affSColin Finck     TRACE("(%p) ref=%d\n", This, ref);
90*c2c66affSColin Finck 
91*c2c66affSColin Finck     return ref;
92*c2c66affSColin Finck }
93*c2c66affSColin Finck 
HTMLLocation_Release(IHTMLLocation * iface)94*c2c66affSColin Finck static ULONG WINAPI HTMLLocation_Release(IHTMLLocation *iface)
95*c2c66affSColin Finck {
96*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
97*c2c66affSColin Finck     LONG ref = InterlockedDecrement(&This->ref);
98*c2c66affSColin Finck 
99*c2c66affSColin Finck     TRACE("(%p) ref=%d\n", This, ref);
100*c2c66affSColin Finck 
101*c2c66affSColin Finck     if(!ref) {
102*c2c66affSColin Finck         if(This->window)
103*c2c66affSColin Finck             This->window->location = NULL;
104*c2c66affSColin Finck         release_dispex(&This->dispex);
105*c2c66affSColin Finck         heap_free(This);
106*c2c66affSColin Finck     }
107*c2c66affSColin Finck 
108*c2c66affSColin Finck     return ref;
109*c2c66affSColin Finck }
110*c2c66affSColin Finck 
HTMLLocation_GetTypeInfoCount(IHTMLLocation * iface,UINT * pctinfo)111*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_GetTypeInfoCount(IHTMLLocation *iface, UINT *pctinfo)
112*c2c66affSColin Finck {
113*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
114*c2c66affSColin Finck     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
115*c2c66affSColin Finck }
116*c2c66affSColin Finck 
HTMLLocation_GetTypeInfo(IHTMLLocation * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)117*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_GetTypeInfo(IHTMLLocation *iface, UINT iTInfo,
118*c2c66affSColin Finck                                               LCID lcid, ITypeInfo **ppTInfo)
119*c2c66affSColin Finck {
120*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
121*c2c66affSColin Finck     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
122*c2c66affSColin Finck }
123*c2c66affSColin Finck 
HTMLLocation_GetIDsOfNames(IHTMLLocation * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)124*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_GetIDsOfNames(IHTMLLocation *iface, REFIID riid,
125*c2c66affSColin Finck                                                 LPOLESTR *rgszNames, UINT cNames,
126*c2c66affSColin Finck                                                 LCID lcid, DISPID *rgDispId)
127*c2c66affSColin Finck {
128*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
129*c2c66affSColin Finck     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
130*c2c66affSColin Finck             lcid, rgDispId);
131*c2c66affSColin Finck }
132*c2c66affSColin Finck 
HTMLLocation_Invoke(IHTMLLocation * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)133*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_Invoke(IHTMLLocation *iface, DISPID dispIdMember,
134*c2c66affSColin Finck                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
135*c2c66affSColin Finck                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
136*c2c66affSColin Finck {
137*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
138*c2c66affSColin Finck     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
139*c2c66affSColin Finck             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
140*c2c66affSColin Finck }
141*c2c66affSColin Finck 
HTMLLocation_put_href(IHTMLLocation * iface,BSTR v)142*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
143*c2c66affSColin Finck {
144*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
145*c2c66affSColin Finck 
146*c2c66affSColin Finck     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
147*c2c66affSColin Finck 
148*c2c66affSColin Finck     if(!This->window || !This->window->base.outer_window) {
149*c2c66affSColin Finck         FIXME("No window available\n");
150*c2c66affSColin Finck         return E_FAIL;
151*c2c66affSColin Finck     }
152*c2c66affSColin Finck 
153*c2c66affSColin Finck     return navigate_url(This->window->base.outer_window, v, This->window->base.outer_window->uri, BINDING_NAVIGATED);
154*c2c66affSColin Finck }
155*c2c66affSColin Finck 
HTMLLocation_get_href(IHTMLLocation * iface,BSTR * p)156*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
157*c2c66affSColin Finck {
158*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
159*c2c66affSColin Finck     URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
160*c2c66affSColin Finck     WCHAR *buf = NULL, *url_path = NULL;
161*c2c66affSColin Finck     HRESULT hres, ret;
162*c2c66affSColin Finck     DWORD len = 0;
163*c2c66affSColin Finck     int i;
164*c2c66affSColin Finck 
165*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
166*c2c66affSColin Finck 
167*c2c66affSColin Finck     if(!p)
168*c2c66affSColin Finck         return E_POINTER;
169*c2c66affSColin Finck 
170*c2c66affSColin Finck     url.dwSchemeLength = 1;
171*c2c66affSColin Finck     url.dwHostNameLength = 1;
172*c2c66affSColin Finck     url.dwUrlPathLength = 1;
173*c2c66affSColin Finck     url.dwExtraInfoLength = 1;
174*c2c66affSColin Finck     hres = get_url_components(This, &url);
175*c2c66affSColin Finck     if(FAILED(hres))
176*c2c66affSColin Finck         return hres;
177*c2c66affSColin Finck 
178*c2c66affSColin Finck     switch(url.nScheme) {
179*c2c66affSColin Finck     case INTERNET_SCHEME_FILE:
180*c2c66affSColin Finck         {
181*c2c66affSColin Finck             /* prepend a slash */
182*c2c66affSColin Finck             url_path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
183*c2c66affSColin Finck             if(!url_path)
184*c2c66affSColin Finck                 return E_OUTOFMEMORY;
185*c2c66affSColin Finck             url_path[0] = '/';
186*c2c66affSColin Finck             memcpy(url_path + 1, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
187*c2c66affSColin Finck             url.lpszUrlPath = url_path;
188*c2c66affSColin Finck             url.dwUrlPathLength = url.dwUrlPathLength + 1;
189*c2c66affSColin Finck         }
190*c2c66affSColin Finck         break;
191*c2c66affSColin Finck 
192*c2c66affSColin Finck     case INTERNET_SCHEME_HTTP:
193*c2c66affSColin Finck     case INTERNET_SCHEME_HTTPS:
194*c2c66affSColin Finck     case INTERNET_SCHEME_FTP:
195*c2c66affSColin Finck         if(!url.dwUrlPathLength) {
196*c2c66affSColin Finck             /* add a slash if it's blank */
197*c2c66affSColin Finck             url_path = url.lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, 1 * sizeof(WCHAR));
198*c2c66affSColin Finck             if(!url.lpszUrlPath)
199*c2c66affSColin Finck                 return E_OUTOFMEMORY;
200*c2c66affSColin Finck             url.lpszUrlPath[0] = '/';
201*c2c66affSColin Finck             url.dwUrlPathLength = 1;
202*c2c66affSColin Finck         }
203*c2c66affSColin Finck         break;
204*c2c66affSColin Finck 
205*c2c66affSColin Finck     default:
206*c2c66affSColin Finck         break;
207*c2c66affSColin Finck     }
208*c2c66affSColin Finck 
209*c2c66affSColin Finck     /* replace \ with / */
210*c2c66affSColin Finck     for(i = 0; i < url.dwUrlPathLength; ++i)
211*c2c66affSColin Finck         if(url.lpszUrlPath[i] == '\\')
212*c2c66affSColin Finck             url.lpszUrlPath[i] = '/';
213*c2c66affSColin Finck 
214*c2c66affSColin Finck     if(InternetCreateUrlW(&url, ICU_ESCAPE, NULL, &len)) {
215*c2c66affSColin Finck         FIXME("InternetCreateUrl succeeded with NULL buffer?\n");
216*c2c66affSColin Finck         ret = E_FAIL;
217*c2c66affSColin Finck         goto cleanup;
218*c2c66affSColin Finck     }
219*c2c66affSColin Finck 
220*c2c66affSColin Finck     if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
221*c2c66affSColin Finck         FIXME("InternetCreateUrl failed with error: %08x\n", GetLastError());
222*c2c66affSColin Finck         SetLastError(0);
223*c2c66affSColin Finck         ret = E_FAIL;
224*c2c66affSColin Finck         goto cleanup;
225*c2c66affSColin Finck     }
226*c2c66affSColin Finck     SetLastError(0);
227*c2c66affSColin Finck 
228*c2c66affSColin Finck     buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
229*c2c66affSColin Finck     if(!buf) {
230*c2c66affSColin Finck         ret = E_OUTOFMEMORY;
231*c2c66affSColin Finck         goto cleanup;
232*c2c66affSColin Finck     }
233*c2c66affSColin Finck 
234*c2c66affSColin Finck     if(!InternetCreateUrlW(&url, ICU_ESCAPE, buf, &len)) {
235*c2c66affSColin Finck         FIXME("InternetCreateUrl failed with error: %08x\n", GetLastError());
236*c2c66affSColin Finck         SetLastError(0);
237*c2c66affSColin Finck         ret = E_FAIL;
238*c2c66affSColin Finck         goto cleanup;
239*c2c66affSColin Finck     }
240*c2c66affSColin Finck 
241*c2c66affSColin Finck     *p = SysAllocStringLen(buf, len);
242*c2c66affSColin Finck     if(!*p) {
243*c2c66affSColin Finck         ret = E_OUTOFMEMORY;
244*c2c66affSColin Finck         goto cleanup;
245*c2c66affSColin Finck     }
246*c2c66affSColin Finck 
247*c2c66affSColin Finck     ret = S_OK;
248*c2c66affSColin Finck 
249*c2c66affSColin Finck cleanup:
250*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, buf);
251*c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, url_path);
252*c2c66affSColin Finck 
253*c2c66affSColin Finck     return ret;
254*c2c66affSColin Finck }
255*c2c66affSColin Finck 
HTMLLocation_put_protocol(IHTMLLocation * iface,BSTR v)256*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)
257*c2c66affSColin Finck {
258*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
259*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
260*c2c66affSColin Finck     return E_NOTIMPL;
261*c2c66affSColin Finck }
262*c2c66affSColin Finck 
HTMLLocation_get_protocol(IHTMLLocation * iface,BSTR * p)263*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_protocol(IHTMLLocation *iface, BSTR *p)
264*c2c66affSColin Finck {
265*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
266*c2c66affSColin Finck     BSTR protocol, ret;
267*c2c66affSColin Finck     unsigned len;
268*c2c66affSColin Finck     IUri *uri;
269*c2c66affSColin Finck     HRESULT hres;
270*c2c66affSColin Finck 
271*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
272*c2c66affSColin Finck 
273*c2c66affSColin Finck     if(!p)
274*c2c66affSColin Finck         return E_POINTER;
275*c2c66affSColin Finck 
276*c2c66affSColin Finck     if(!(uri = get_uri(This))) {
277*c2c66affSColin Finck         FIXME("No current URI\n");
278*c2c66affSColin Finck         return E_NOTIMPL;
279*c2c66affSColin Finck     }
280*c2c66affSColin Finck 
281*c2c66affSColin Finck     hres = IUri_GetSchemeName(uri, &protocol);
282*c2c66affSColin Finck     if(FAILED(hres))
283*c2c66affSColin Finck         return hres;
284*c2c66affSColin Finck     if(hres == S_FALSE) {
285*c2c66affSColin Finck         SysFreeString(protocol);
286*c2c66affSColin Finck         *p = NULL;
287*c2c66affSColin Finck         return S_OK;
288*c2c66affSColin Finck     }
289*c2c66affSColin Finck 
290*c2c66affSColin Finck     len = SysStringLen(protocol);
291*c2c66affSColin Finck     ret = SysAllocStringLen(protocol, len+1);
292*c2c66affSColin Finck     SysFreeString(protocol);
293*c2c66affSColin Finck     if(!ret)
294*c2c66affSColin Finck         return E_OUTOFMEMORY;
295*c2c66affSColin Finck 
296*c2c66affSColin Finck     ret[len] = ':';
297*c2c66affSColin Finck     *p = ret;
298*c2c66affSColin Finck     return S_OK;
299*c2c66affSColin Finck }
300*c2c66affSColin Finck 
HTMLLocation_put_host(IHTMLLocation * iface,BSTR v)301*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_host(IHTMLLocation *iface, BSTR v)
302*c2c66affSColin Finck {
303*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
304*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
305*c2c66affSColin Finck     return E_NOTIMPL;
306*c2c66affSColin Finck }
307*c2c66affSColin Finck 
HTMLLocation_get_host(IHTMLLocation * iface,BSTR * p)308*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
309*c2c66affSColin Finck {
310*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
311*c2c66affSColin Finck     URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
312*c2c66affSColin Finck     HRESULT hres;
313*c2c66affSColin Finck 
314*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
315*c2c66affSColin Finck 
316*c2c66affSColin Finck     if(!p)
317*c2c66affSColin Finck         return E_POINTER;
318*c2c66affSColin Finck 
319*c2c66affSColin Finck     url.dwHostNameLength = 1;
320*c2c66affSColin Finck     hres = get_url_components(This, &url);
321*c2c66affSColin Finck     if(FAILED(hres))
322*c2c66affSColin Finck         return hres;
323*c2c66affSColin Finck 
324*c2c66affSColin Finck     if(!url.dwHostNameLength){
325*c2c66affSColin Finck         *p = NULL;
326*c2c66affSColin Finck         return S_OK;
327*c2c66affSColin Finck     }
328*c2c66affSColin Finck 
329*c2c66affSColin Finck     if(url.nPort) {
330*c2c66affSColin Finck         /* <hostname>:<port> */
331*c2c66affSColin Finck         const WCHAR format[] = {'%','u',0};
332*c2c66affSColin Finck         DWORD len = url.dwHostNameLength + 1 + 5;
333*c2c66affSColin Finck         WCHAR *buf;
334*c2c66affSColin Finck 
335*c2c66affSColin Finck         buf = *p = SysAllocStringLen(NULL, len);
336*c2c66affSColin Finck         memcpy(buf, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
337*c2c66affSColin Finck         buf[url.dwHostNameLength] = ':';
338*c2c66affSColin Finck         snprintfW(buf + url.dwHostNameLength + 1, 6, format, url.nPort);
339*c2c66affSColin Finck     }else
340*c2c66affSColin Finck         *p = SysAllocStringLen(url.lpszHostName, url.dwHostNameLength);
341*c2c66affSColin Finck 
342*c2c66affSColin Finck     if(!*p)
343*c2c66affSColin Finck         return E_OUTOFMEMORY;
344*c2c66affSColin Finck     return S_OK;
345*c2c66affSColin Finck }
346*c2c66affSColin Finck 
HTMLLocation_put_hostname(IHTMLLocation * iface,BSTR v)347*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_hostname(IHTMLLocation *iface, BSTR v)
348*c2c66affSColin Finck {
349*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
350*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
351*c2c66affSColin Finck     return E_NOTIMPL;
352*c2c66affSColin Finck }
353*c2c66affSColin Finck 
HTMLLocation_get_hostname(IHTMLLocation * iface,BSTR * p)354*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_hostname(IHTMLLocation *iface, BSTR *p)
355*c2c66affSColin Finck {
356*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
357*c2c66affSColin Finck     BSTR hostname;
358*c2c66affSColin Finck     IUri *uri;
359*c2c66affSColin Finck     HRESULT hres;
360*c2c66affSColin Finck 
361*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
362*c2c66affSColin Finck 
363*c2c66affSColin Finck     if(!p)
364*c2c66affSColin Finck         return E_POINTER;
365*c2c66affSColin Finck 
366*c2c66affSColin Finck     if(!(uri = get_uri(This))) {
367*c2c66affSColin Finck         FIXME("No current URI\n");
368*c2c66affSColin Finck         return E_NOTIMPL;
369*c2c66affSColin Finck     }
370*c2c66affSColin Finck 
371*c2c66affSColin Finck     hres = IUri_GetHost(uri, &hostname);
372*c2c66affSColin Finck     if(hres == S_OK) {
373*c2c66affSColin Finck         *p = hostname;
374*c2c66affSColin Finck     }else if(hres == S_FALSE) {
375*c2c66affSColin Finck         SysFreeString(hostname);
376*c2c66affSColin Finck         *p = NULL;
377*c2c66affSColin Finck     }else {
378*c2c66affSColin Finck         return hres;
379*c2c66affSColin Finck     }
380*c2c66affSColin Finck 
381*c2c66affSColin Finck     return S_OK;
382*c2c66affSColin Finck }
383*c2c66affSColin Finck 
HTMLLocation_put_port(IHTMLLocation * iface,BSTR v)384*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_port(IHTMLLocation *iface, BSTR v)
385*c2c66affSColin Finck {
386*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
387*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
388*c2c66affSColin Finck     return E_NOTIMPL;
389*c2c66affSColin Finck }
390*c2c66affSColin Finck 
HTMLLocation_get_port(IHTMLLocation * iface,BSTR * p)391*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_port(IHTMLLocation *iface, BSTR *p)
392*c2c66affSColin Finck {
393*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
394*c2c66affSColin Finck     DWORD port;
395*c2c66affSColin Finck     IUri *uri;
396*c2c66affSColin Finck     HRESULT hres;
397*c2c66affSColin Finck 
398*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
399*c2c66affSColin Finck 
400*c2c66affSColin Finck     if(!p)
401*c2c66affSColin Finck         return E_POINTER;
402*c2c66affSColin Finck 
403*c2c66affSColin Finck     if(!(uri = get_uri(This))) {
404*c2c66affSColin Finck         FIXME("No current URI\n");
405*c2c66affSColin Finck         return E_NOTIMPL;
406*c2c66affSColin Finck     }
407*c2c66affSColin Finck 
408*c2c66affSColin Finck     hres = IUri_GetPort(uri, &port);
409*c2c66affSColin Finck     if(FAILED(hres))
410*c2c66affSColin Finck         return hres;
411*c2c66affSColin Finck 
412*c2c66affSColin Finck     if(hres == S_OK) {
413*c2c66affSColin Finck         static const WCHAR formatW[] = {'%','u',0};
414*c2c66affSColin Finck         WCHAR buf[12];
415*c2c66affSColin Finck 
416*c2c66affSColin Finck         sprintfW(buf, formatW, port);
417*c2c66affSColin Finck         *p = SysAllocString(buf);
418*c2c66affSColin Finck     }else {
419*c2c66affSColin Finck         *p = SysAllocStringLen(NULL, 0);
420*c2c66affSColin Finck     }
421*c2c66affSColin Finck 
422*c2c66affSColin Finck     if(!*p)
423*c2c66affSColin Finck         return E_OUTOFMEMORY;
424*c2c66affSColin Finck     return S_OK;
425*c2c66affSColin Finck }
426*c2c66affSColin Finck 
HTMLLocation_put_pathname(IHTMLLocation * iface,BSTR v)427*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_pathname(IHTMLLocation *iface, BSTR v)
428*c2c66affSColin Finck {
429*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
430*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
431*c2c66affSColin Finck     return E_NOTIMPL;
432*c2c66affSColin Finck }
433*c2c66affSColin Finck 
HTMLLocation_get_pathname(IHTMLLocation * iface,BSTR * p)434*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_pathname(IHTMLLocation *iface, BSTR *p)
435*c2c66affSColin Finck {
436*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
437*c2c66affSColin Finck     URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
438*c2c66affSColin Finck     HRESULT hres;
439*c2c66affSColin Finck 
440*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
441*c2c66affSColin Finck 
442*c2c66affSColin Finck     if(!p)
443*c2c66affSColin Finck         return E_POINTER;
444*c2c66affSColin Finck 
445*c2c66affSColin Finck     url.dwUrlPathLength = 1;
446*c2c66affSColin Finck     url.dwExtraInfoLength = 1;
447*c2c66affSColin Finck     hres = get_url_components(This, &url);
448*c2c66affSColin Finck     if(FAILED(hres))
449*c2c66affSColin Finck         return hres;
450*c2c66affSColin Finck 
451*c2c66affSColin Finck     if(url.dwUrlPathLength && url.lpszUrlPath[0] == '/')
452*c2c66affSColin Finck         *p = SysAllocStringLen(url.lpszUrlPath + 1, url.dwUrlPathLength - 1);
453*c2c66affSColin Finck     else
454*c2c66affSColin Finck         *p = SysAllocStringLen(url.lpszUrlPath, url.dwUrlPathLength);
455*c2c66affSColin Finck 
456*c2c66affSColin Finck     if(!*p)
457*c2c66affSColin Finck         return E_OUTOFMEMORY;
458*c2c66affSColin Finck     return S_OK;
459*c2c66affSColin Finck }
460*c2c66affSColin Finck 
HTMLLocation_put_search(IHTMLLocation * iface,BSTR v)461*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_search(IHTMLLocation *iface, BSTR v)
462*c2c66affSColin Finck {
463*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
464*c2c66affSColin Finck     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
465*c2c66affSColin Finck     return E_NOTIMPL;
466*c2c66affSColin Finck }
467*c2c66affSColin Finck 
HTMLLocation_get_search(IHTMLLocation * iface,BSTR * p)468*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_search(IHTMLLocation *iface, BSTR *p)
469*c2c66affSColin Finck {
470*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
471*c2c66affSColin Finck     BSTR query;
472*c2c66affSColin Finck     IUri *uri;
473*c2c66affSColin Finck     HRESULT hres;
474*c2c66affSColin Finck 
475*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
476*c2c66affSColin Finck 
477*c2c66affSColin Finck     if(!p)
478*c2c66affSColin Finck         return E_POINTER;
479*c2c66affSColin Finck 
480*c2c66affSColin Finck     if(!(uri = get_uri(This))) {
481*c2c66affSColin Finck         FIXME("No current URI\n");
482*c2c66affSColin Finck         return E_NOTIMPL;
483*c2c66affSColin Finck     }
484*c2c66affSColin Finck 
485*c2c66affSColin Finck     hres = IUri_GetQuery(uri, &query);
486*c2c66affSColin Finck     if(hres == S_OK) {
487*c2c66affSColin Finck         *p = query;
488*c2c66affSColin Finck     }else if(hres == S_FALSE) {
489*c2c66affSColin Finck         SysFreeString(query);
490*c2c66affSColin Finck         *p = NULL;
491*c2c66affSColin Finck     }else {
492*c2c66affSColin Finck         return hres;
493*c2c66affSColin Finck     }
494*c2c66affSColin Finck 
495*c2c66affSColin Finck     return S_OK;
496*c2c66affSColin Finck }
497*c2c66affSColin Finck 
HTMLLocation_put_hash(IHTMLLocation * iface,BSTR v)498*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_put_hash(IHTMLLocation *iface, BSTR v)
499*c2c66affSColin Finck {
500*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
501*c2c66affSColin Finck 
502*c2c66affSColin Finck     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
503*c2c66affSColin Finck 
504*c2c66affSColin Finck     if(!This->window || !This->window->base.outer_window) {
505*c2c66affSColin Finck         FIXME("No window available\n");
506*c2c66affSColin Finck         return E_FAIL;
507*c2c66affSColin Finck     }
508*c2c66affSColin Finck 
509*c2c66affSColin Finck     return navigate_url(This->window->base.outer_window, v, This->window->base.outer_window->uri, 0);
510*c2c66affSColin Finck }
511*c2c66affSColin Finck 
HTMLLocation_get_hash(IHTMLLocation * iface,BSTR * p)512*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p)
513*c2c66affSColin Finck {
514*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
515*c2c66affSColin Finck     BSTR hash;
516*c2c66affSColin Finck     IUri *uri;
517*c2c66affSColin Finck     HRESULT hres;
518*c2c66affSColin Finck 
519*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, p);
520*c2c66affSColin Finck 
521*c2c66affSColin Finck     if(!p)
522*c2c66affSColin Finck         return E_POINTER;
523*c2c66affSColin Finck 
524*c2c66affSColin Finck     if(!(uri = get_uri(This))) {
525*c2c66affSColin Finck         FIXME("No current URI\n");
526*c2c66affSColin Finck         return E_NOTIMPL;
527*c2c66affSColin Finck     }
528*c2c66affSColin Finck 
529*c2c66affSColin Finck     hres = IUri_GetFragment(uri, &hash);
530*c2c66affSColin Finck     if(hres == S_OK) {
531*c2c66affSColin Finck         *p = hash;
532*c2c66affSColin Finck     }else if(hres == S_FALSE) {
533*c2c66affSColin Finck         SysFreeString(hash);
534*c2c66affSColin Finck         *p = NULL;
535*c2c66affSColin Finck     }else {
536*c2c66affSColin Finck         return hres;
537*c2c66affSColin Finck     }
538*c2c66affSColin Finck 
539*c2c66affSColin Finck     return S_OK;
540*c2c66affSColin Finck }
541*c2c66affSColin Finck 
HTMLLocation_reload(IHTMLLocation * iface,VARIANT_BOOL flag)542*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag)
543*c2c66affSColin Finck {
544*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
545*c2c66affSColin Finck     FIXME("(%p)->(%x)\n", This, flag);
546*c2c66affSColin Finck     return E_NOTIMPL;
547*c2c66affSColin Finck }
548*c2c66affSColin Finck 
HTMLLocation_replace(IHTMLLocation * iface,BSTR bstr)549*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr)
550*c2c66affSColin Finck {
551*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
552*c2c66affSColin Finck 
553*c2c66affSColin Finck     TRACE("(%p)->(%s)\n", This, debugstr_w(bstr));
554*c2c66affSColin Finck 
555*c2c66affSColin Finck     if(!This->window || !This->window->base.outer_window) {
556*c2c66affSColin Finck         FIXME("No window available\n");
557*c2c66affSColin Finck         return E_FAIL;
558*c2c66affSColin Finck     }
559*c2c66affSColin Finck 
560*c2c66affSColin Finck     return navigate_url(This->window->base.outer_window, bstr, This->window->base.outer_window->uri,
561*c2c66affSColin Finck             BINDING_NAVIGATED|BINDING_REPLACE);
562*c2c66affSColin Finck }
563*c2c66affSColin Finck 
HTMLLocation_assign(IHTMLLocation * iface,BSTR bstr)564*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_assign(IHTMLLocation *iface, BSTR bstr)
565*c2c66affSColin Finck {
566*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
567*c2c66affSColin Finck     TRACE("(%p)->(%s)\n", This, debugstr_w(bstr));
568*c2c66affSColin Finck     return IHTMLLocation_put_href(iface, bstr);
569*c2c66affSColin Finck }
570*c2c66affSColin Finck 
HTMLLocation_toString(IHTMLLocation * iface,BSTR * String)571*c2c66affSColin Finck static HRESULT WINAPI HTMLLocation_toString(IHTMLLocation *iface, BSTR *String)
572*c2c66affSColin Finck {
573*c2c66affSColin Finck     HTMLLocation *This = impl_from_IHTMLLocation(iface);
574*c2c66affSColin Finck 
575*c2c66affSColin Finck     TRACE("(%p)->(%p)\n", This, String);
576*c2c66affSColin Finck 
577*c2c66affSColin Finck     return IHTMLLocation_get_href(&This->IHTMLLocation_iface, String);
578*c2c66affSColin Finck }
579*c2c66affSColin Finck 
580*c2c66affSColin Finck static const IHTMLLocationVtbl HTMLLocationVtbl = {
581*c2c66affSColin Finck     HTMLLocation_QueryInterface,
582*c2c66affSColin Finck     HTMLLocation_AddRef,
583*c2c66affSColin Finck     HTMLLocation_Release,
584*c2c66affSColin Finck     HTMLLocation_GetTypeInfoCount,
585*c2c66affSColin Finck     HTMLLocation_GetTypeInfo,
586*c2c66affSColin Finck     HTMLLocation_GetIDsOfNames,
587*c2c66affSColin Finck     HTMLLocation_Invoke,
588*c2c66affSColin Finck     HTMLLocation_put_href,
589*c2c66affSColin Finck     HTMLLocation_get_href,
590*c2c66affSColin Finck     HTMLLocation_put_protocol,
591*c2c66affSColin Finck     HTMLLocation_get_protocol,
592*c2c66affSColin Finck     HTMLLocation_put_host,
593*c2c66affSColin Finck     HTMLLocation_get_host,
594*c2c66affSColin Finck     HTMLLocation_put_hostname,
595*c2c66affSColin Finck     HTMLLocation_get_hostname,
596*c2c66affSColin Finck     HTMLLocation_put_port,
597*c2c66affSColin Finck     HTMLLocation_get_port,
598*c2c66affSColin Finck     HTMLLocation_put_pathname,
599*c2c66affSColin Finck     HTMLLocation_get_pathname,
600*c2c66affSColin Finck     HTMLLocation_put_search,
601*c2c66affSColin Finck     HTMLLocation_get_search,
602*c2c66affSColin Finck     HTMLLocation_put_hash,
603*c2c66affSColin Finck     HTMLLocation_get_hash,
604*c2c66affSColin Finck     HTMLLocation_reload,
605*c2c66affSColin Finck     HTMLLocation_replace,
606*c2c66affSColin Finck     HTMLLocation_assign,
607*c2c66affSColin Finck     HTMLLocation_toString
608*c2c66affSColin Finck };
609*c2c66affSColin Finck 
610*c2c66affSColin Finck static const tid_t HTMLLocation_iface_tids[] = {
611*c2c66affSColin Finck     IHTMLLocation_tid,
612*c2c66affSColin Finck     0
613*c2c66affSColin Finck };
614*c2c66affSColin Finck static dispex_static_data_t HTMLLocation_dispex = {
615*c2c66affSColin Finck     NULL,
616*c2c66affSColin Finck     DispHTMLLocation_tid,
617*c2c66affSColin Finck     NULL,
618*c2c66affSColin Finck     HTMLLocation_iface_tids
619*c2c66affSColin Finck };
620*c2c66affSColin Finck 
621*c2c66affSColin Finck 
HTMLLocation_Create(HTMLInnerWindow * window,HTMLLocation ** ret)622*c2c66affSColin Finck HRESULT HTMLLocation_Create(HTMLInnerWindow *window, HTMLLocation **ret)
623*c2c66affSColin Finck {
624*c2c66affSColin Finck     HTMLLocation *location;
625*c2c66affSColin Finck 
626*c2c66affSColin Finck     location = heap_alloc(sizeof(*location));
627*c2c66affSColin Finck     if(!location)
628*c2c66affSColin Finck         return E_OUTOFMEMORY;
629*c2c66affSColin Finck 
630*c2c66affSColin Finck     location->IHTMLLocation_iface.lpVtbl = &HTMLLocationVtbl;
631*c2c66affSColin Finck     location->ref = 1;
632*c2c66affSColin Finck     location->window = window;
633*c2c66affSColin Finck 
634*c2c66affSColin Finck     init_dispex(&location->dispex, (IUnknown*)&location->IHTMLLocation_iface, &HTMLLocation_dispex);
635*c2c66affSColin Finck 
636*c2c66affSColin Finck     *ret = location;
637*c2c66affSColin Finck     return S_OK;
638*c2c66affSColin Finck }
639