mshtml: Use IUriBuilder for IURI::SetQuery implementation.

This commit is contained in:
Jacek Caban 2010-11-12 12:31:41 +01:00 committed by Alexandre Julliard
parent 16fbd05080
commit 98f5bc384b

View File

@ -63,8 +63,9 @@ struct nsWineURI {
NSContainer *container;
windowref_t *window_ref;
nsChannelBSC *channel_bsc;
LPWSTR wine_url;
BSTR wine_url;
IUri *uri;
IUriBuilder *uri_builder;
BOOL is_doc_uri;
};
@ -248,12 +249,12 @@ HRESULT set_wine_url(nsWineURI *This, LPCWSTR url)
TRACE("(%p)->(%s)\n", This, debugstr_w(url));
if(url) {
WCHAR *new_url;
BSTR new_url;
new_url = heap_strdupW(url);
new_url = SysAllocString(url);
if(!new_url)
return E_OUTOFMEMORY;
heap_free(This->wine_url);
SysFreeString(This->wine_url);
This->wine_url = new_url;
}else {
heap_free(This->wine_url);
@ -1529,19 +1530,74 @@ static const nsIHttpChannelInternalVtbl nsHttpChannelInternalVtbl = {
static BOOL ensure_uri(nsWineURI *This)
{
if(!This->uri) {
HRESULT hres;
if(This->uri)
return TRUE;
if(This->uri_builder) {
hres = IUriBuilder_CreateUriSimple(This->uri_builder, 0, 0, &This->uri);
if(FAILED(hres)) {
WARN("CreateUriSimple failed: %08x\n", hres);
return FALSE;
}
return TRUE;
}
hres = CreateUri(This->wine_url, 0, 0, &This->uri);
if(FAILED(hres)) {
WARN("CreateUri failed: %08x\n", hres);
return FALSE;
}
return TRUE;
}
static void invalidate_uri(nsWineURI *This)
{
if(This->uri) {
IUri_Release(This->uri);
This->uri = NULL;
}
}
static BOOL ensure_uri_builder(nsWineURI *This)
{
if(!This->uri_builder) {
HRESULT hres;
hres = CreateUri(This->wine_url, 0, 0, &This->uri);
if(!ensure_uri(This))
return FALSE;
hres = CreateIUriBuilder(This->uri, 0, 0, &This->uri_builder);
if(FAILED(hres)) {
WARN("CreateUri failed: %08x\n", hres);
WARN("CreateIUriBulder failed: %08x\n", hres);
return FALSE;
}
}
invalidate_uri(This);
return TRUE;
}
/* Temporary helper */
static void sync_wine_url(nsWineURI *This)
{
BSTR new_url;
HRESULT hres;
if(!ensure_uri(This))
return;
hres = IUri_GetDisplayUri(This->uri, &new_url);
if(FAILED(hres))
return;
SysFreeString(This->wine_url);
This->wine_url = new_url;
}
static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *ret)
{
char *vala;
@ -1568,14 +1624,6 @@ static nsresult get_uri_string(nsWineURI *This, Uri_PROPERTY prop, nsACString *r
return NS_OK;
}
static void invalidate_uri(nsWineURI *This)
{
if(This->uri) {
IUri_Release(This->uri);
This->uri = NULL;
}
}
#define NSURI_THIS(iface) DEFINE_THIS(nsWineURI, IURL, iface)
static nsresult NSAPI nsURI_QueryInterface(nsIURL *iface, nsIIDRef riid, void **result)
@ -1635,7 +1683,7 @@ static nsrefcnt NSAPI nsURI_Release(nsIURL *iface)
nsIURI_Release(This->nsuri);
if(This->uri)
IUri_Release(This->uri);
heap_free(This->wine_url);
SysFreeString(This->wine_url);
heap_free(This);
}
@ -2189,55 +2237,26 @@ static nsresult NSAPI nsURL_GetQuery(nsIURL *iface, nsACString *aQuery)
static nsresult NSAPI nsURL_SetQuery(nsIURL *iface, const nsACString *aQuery)
{
nsWineURI *This = NSURI_THIS(iface);
const WCHAR *ptr1, *ptr2;
const char *query;
WCHAR *new_url, *ptr;
DWORD len, size;
const char *querya;
WCHAR *query;
HRESULT hres;
TRACE("(%p)->(%s)\n", This, debugstr_nsacstr(aQuery));
invalidate_uri(This);
if(!ensure_uri_builder(This))
return NS_ERROR_UNEXPECTED;
if(This->nsurl)
nsIURL_SetQuery(This->nsurl, aQuery);
nsACString_GetData(aQuery, &querya);
query = heap_strdupAtoW(querya);
if(!query)
return NS_ERROR_OUT_OF_MEMORY;
if(!This->wine_url)
return NS_OK;
hres = IUriBuilder_SetQuery(This->uri_builder, query);
heap_free(query);
if(FAILED(hres))
return NS_ERROR_UNEXPECTED;
nsACString_GetData(aQuery, &query);
size = len = MultiByteToWideChar(CP_ACP, 0, query, -1, NULL, 0);
ptr1 = strchrW(This->wine_url, '?');
if(ptr1) {
size += ptr1-This->wine_url;
ptr2 = strchrW(ptr1, '#');
if(ptr2)
size += strlenW(ptr2);
}else {
ptr1 = This->wine_url + strlenW(This->wine_url);
ptr2 = NULL;
size += strlenW(This->wine_url);
}
if(*query)
size++;
new_url = heap_alloc(size*sizeof(WCHAR));
memcpy(new_url, This->wine_url, (ptr1-This->wine_url)*sizeof(WCHAR));
ptr = new_url + (ptr1-This->wine_url);
if(*query) {
*ptr++ = '?';
MultiByteToWideChar(CP_ACP, 0, query, -1, ptr, len);
ptr += len-1;
}
if(ptr2)
strcpyW(ptr, ptr2);
else
*ptr = 0;
TRACE("setting %s\n", debugstr_w(new_url));
heap_free(This->wine_url);
This->wine_url = new_url;
sync_wine_url(This);
return NS_OK;
}