diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index ba57e3e7605..a606dace389 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -508,8 +508,15 @@ static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
{
- FIXME("(%p)->(%p)\n", iface, p);
- return E_NOTIMPL;
+ HTMLDocument *This = HTMLDOC_THIS(iface);
+
+ static const WCHAR about_blank_url[] =
+ {'a','b','o','u','t',':','b','l','a','n','k',0};
+
+ TRACE("(%p)->(%p)\n", iface, p);
+
+ *p = SysAllocString(This->url ? This->url : about_blank_url);
+ return S_OK;
}
static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index b9f5d613412..562373677e6 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -102,6 +102,7 @@ struct HTMLDocument {
BSCallback *bscallback;
IMoniker *mon;
+ BSTR url;
HWND hwnd;
HWND tooltips_hwnd;
diff --git a/dlls/mshtml/persist.c b/dlls/mshtml/persist.c
index f933b73d293..58ca42229f0 100644
--- a/dlls/mshtml/persist.c
+++ b/dlls/mshtml/persist.c
@@ -115,11 +115,27 @@ static nsIInputStream *get_post_data_stream(IBindCtx *bctx)
void set_current_mon(HTMLDocument *This, IMoniker *mon)
{
- if(This->mon)
+ HRESULT hres;
+
+ if(This->mon) {
IMoniker_Release(This->mon);
- if(mon)
- IMoniker_AddRef(mon);
+ This->mon = NULL;
+ }
+
+ if(This->url) {
+ SysFreeString(This->url);
+ This->url = NULL;
+ }
+
+ if(!mon)
+ return;
+
+ IMoniker_AddRef(mon);
This->mon = mon;
+
+ hres = IMoniker_GetDisplayName(mon, NULL, NULL, &This->url);
+ if(FAILED(hres))
+ WARN("GetDisplayName failed: %08x\n", hres);
}
static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BOOL *bind_complete)
@@ -674,4 +690,5 @@ void HTMLDocument_Persist_Init(HTMLDocument *This)
This->bscallback = NULL;
This->mon = NULL;
+ This->url = NULL;
}
diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c
index af5d7a40806..619d36eb7c7 100644
--- a/dlls/mshtml/tests/htmldoc.c
+++ b/dlls/mshtml/tests/htmldoc.c
@@ -2189,8 +2189,10 @@ static void test_ConnectionPointContainer(IUnknown *unk)
static void test_GetCurMoniker(IUnknown *unk, IMoniker *exmon, LPCWSTR exurl)
{
+ IHTMLDocument2 *doc;
IPersistMoniker *permon;
IMoniker *mon = (void*)0xdeadbeef;
+ BSTR doc_url = (void*)0xdeadbeef;
HRESULT hres;
hres = IUnknown_QueryInterface(unk, &IID_IPersistMoniker, (void**)&permon);
@@ -2198,12 +2200,32 @@ static void test_GetCurMoniker(IUnknown *unk, IMoniker *exmon, LPCWSTR exurl)
if(FAILED(hres))
return;
+ hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&doc);
+ ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
+
+ hres = IHTMLDocument2_get_URL(doc, &doc_url);
+ ok(hres == S_OK, "get_URL failed: %08x\n", hres);
+
hres = IPersistMoniker_GetCurMoniker(permon, &mon);
IPersistMoniker_Release(permon);
if(exmon) {
+ BSTR url;
+ BOOL exb = expect_GetDisplayName;
+ BOOL clb = called_GetDisplayName;
+
ok(hres == S_OK, "GetCurrentMoniker failed: %08x\n", hres);
ok(mon == exmon, "mon(%p) != exmon(%p)\n", mon, exmon);
+
+ SET_EXPECT(GetDisplayName);
+ hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
+ ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
+ CHECK_CALLED(GetDisplayName);
+ expect_GetDisplayName = exb;
+ called_GetDisplayName = clb;
+
+ SysFreeString(url);
+ ok(!lstrcmpW(url, doc_url), "url != doc_url\n");
}else if(exurl) {
BSTR url;
@@ -2213,13 +2235,18 @@ static void test_GetCurMoniker(IUnknown *unk, IMoniker *exmon, LPCWSTR exurl)
ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
ok(!lstrcmpW(url, exurl), "unexpected url\n");
+ ok(!lstrcmpW(url, doc_url), "url != doc_url\n");
+
SysFreeString(url);
}else {
ok(hres == E_UNEXPECTED,
"GetCurrentMoniker failed: %08x, expected E_UNEXPECTED\n", hres);
ok(mon == (IMoniker*)0xdeadbeef, "mon=%p\n", mon);
+ ok(!lstrcmpW(doc_url, about_blank_url), "doc_url is not about:blank\n");
}
+ SysFreeString(doc_url);
+ IHTMLDocument_Release(doc);
if(mon && mon != (void*)0xdeadbeef)
IMoniker_Release(mon);
}