mshtml: Reimplement IHTMLLocation::get_href.

This commit is contained in:
Andrew Eikum 2009-10-16 11:45:34 -05:00 committed by Alexandre Julliard
parent 192a838cd0
commit 6a456fa6d9
2 changed files with 90 additions and 7 deletions

View File

@ -165,20 +165,103 @@ static HRESULT WINAPI HTMLLocation_put_href(IHTMLLocation *iface, BSTR v)
static HRESULT WINAPI HTMLLocation_get_href(IHTMLLocation *iface, BSTR *p)
{
HTMLLocation *This = HTMLLOCATION_THIS(iface);
const WCHAR *url;
HRESULT hres;
URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW)};
WCHAR *buf = NULL, *url_path = NULL;
HRESULT hres, ret;
DWORD len = 0;
int i;
TRACE("(%p)->(%p)\n", This, p);
if(!p)
return E_POINTER;
hres = get_url(This, &url);
url.dwSchemeLength = 1;
url.dwHostNameLength = 1;
url.dwUrlPathLength = 1;
url.dwExtraInfoLength = 1;
hres = get_url_components(This, &url);
if(FAILED(hres))
return hres;
*p = SysAllocString(url);
return *p ? S_OK : E_OUTOFMEMORY;
switch(url.nScheme) {
case INTERNET_SCHEME_FILE:
{
/* prepend a slash */
url_path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
if(!url_path)
return E_OUTOFMEMORY;
url_path[0] = '/';
memcpy(url_path + 1, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
url.lpszUrlPath = url_path;
url.dwUrlPathLength = url.dwUrlPathLength + 1;
}
break;
case INTERNET_SCHEME_HTTP:
case INTERNET_SCHEME_HTTPS:
case INTERNET_SCHEME_FTP:
if(!url.dwUrlPathLength) {
/* add a slash if it's blank */
url_path = url.lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, 1 * sizeof(WCHAR));
if(!url.lpszUrlPath)
return E_OUTOFMEMORY;
url.lpszUrlPath[0] = '/';
url.dwUrlPathLength = 1;
}
break;
default:
break;
}
/* replace \ with / */
for(i = 0; i < url.dwUrlPathLength; ++i)
if(url.lpszUrlPath[i] == '\\')
url.lpszUrlPath[i] = '/';
if(InternetCreateUrlW(&url, ICU_ESCAPE, NULL, &len)) {
FIXME("InternetCreateUrl succeeded with NULL buffer?\n");
ret = E_FAIL;
goto cleanup;
}
if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
FIXME("InternetCreateUrl failed with error: %08x\n", GetLastError());
SetLastError(0);
ret = E_FAIL;
goto cleanup;
}
SetLastError(0);
buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if(!buf) {
ret = E_OUTOFMEMORY;
goto cleanup;
}
if(!InternetCreateUrlW(&url, ICU_ESCAPE, buf, &len)) {
FIXME("InternetCreateUrl failed with error: %08x\n", GetLastError());
SetLastError(0);
ret = E_FAIL;
goto cleanup;
}
*p = SysAllocStringLen(buf, len);
if(!*p) {
ret = E_OUTOFMEMORY;
goto cleanup;
}
ret = S_OK;
cleanup:
if(buf)
HeapFree(GetProcessHeap(), 0, buf);
if(url_path)
HeapFree(GetProcessHeap(), 0, url_path);
return ret;
}
static HRESULT WINAPI HTMLLocation_put_protocol(IHTMLLocation *iface, BSTR v)

View File

@ -56,7 +56,7 @@ static const WCHAR http_url[] = {'h','t','t','p',':','/','/','w','w','w','.','w'
static const struct location_test http_test = {
"HTTP",
http_url,
"http://www.winehq.org/?search#hash", FALSE,
"http://www.winehq.org/?search#hash", TRUE,
"http:", TRUE,
"www.winehq.org:80", TRUE,
"www.winehq.org", TRUE,
@ -112,7 +112,7 @@ static const WCHAR file_url[] = {'f','i','l','e',':','/','/','C',':','\\','w','i
static const struct location_test file_test = {
"FILE",
file_url,
"file:///C:/windows/win.ini", FALSE,
"file:///C:/windows/win.ini", TRUE,
"file:", TRUE,
NULL, TRUE,
NULL, TRUE,