From 6a456fa6d9c6b495b25873d2288d9240de05195d Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Fri, 16 Oct 2009 11:45:34 -0500 Subject: [PATCH] mshtml: Reimplement IHTMLLocation::get_href. --- dlls/mshtml/htmllocation.c | 93 +++++++++++++++++++++++++++++++++++++--- dlls/mshtml/tests/htmllocation.c | 4 +- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/dlls/mshtml/htmllocation.c b/dlls/mshtml/htmllocation.c index e21ec76016f..4655a6377a7 100644 --- a/dlls/mshtml/htmllocation.c +++ b/dlls/mshtml/htmllocation.c @@ -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) diff --git a/dlls/mshtml/tests/htmllocation.c b/dlls/mshtml/tests/htmllocation.c index 8cd7e1d9abb..671d4604516 100644 --- a/dlls/mshtml/tests/htmllocation.c +++ b/dlls/mshtml/tests/htmllocation.c @@ -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, -- 2.11.4.GIT