Andrew Eikum : mshtml: Reimplement IHTMLLocation::get_href.

Alexandre Julliard julliard at winehq.org
Mon Oct 19 09:56:12 CDT 2009


Module: wine
Branch: master
Commit: 6a456fa6d9c6b495b25873d2288d9240de05195d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6a456fa6d9c6b495b25873d2288d9240de05195d

Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Fri Oct 16 11:45:34 2009 -0500

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 e21ec76..4655a63 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 8cd7e1d..671d460 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,




More information about the wine-cvs mailing list