From 2865a5f1137aa90e5ed30fa9f4d71f5ee8d7eb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Fri, 25 Nov 2022 19:10:03 +0200 Subject: [PATCH] mshtml: Implement location.reload(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53927 Signed-off-by: Gabriel Ivăncescu --- dlls/mshtml/htmllocation.c | 17 +++++++++++++-- dlls/mshtml/mshtml_private.h | 1 + dlls/mshtml/olecmd.c | 24 ++++++++++++++-------- dlls/mshtml/tests/htmldoc.c | 20 ++++++++++++++++++ dlls/mshtml/tests/reload.js | 40 ++++++++++++++++++++++++++++++++++++ dlls/mshtml/tests/rsrc.rc | 3 +++ dlls/mshtml/tests/script.c | 1 + 7 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 dlls/mshtml/tests/reload.js diff --git a/dlls/mshtml/htmllocation.c b/dlls/mshtml/htmllocation.c index d0abb42f2b2..5376b3b8329 100644 --- a/dlls/mshtml/htmllocation.c +++ b/dlls/mshtml/htmllocation.c @@ -582,8 +582,21 @@ static HRESULT WINAPI HTMLLocation_get_hash(IHTMLLocation *iface, BSTR *p) static HRESULT WINAPI HTMLLocation_reload(IHTMLLocation *iface, VARIANT_BOOL flag) { HTMLLocation *This = impl_from_IHTMLLocation(iface); - FIXME("(%p)->(%x)\n", This, flag); - return E_NOTIMPL; + + TRACE("(%p)->(%x)\n", This, flag); + + if(!This->window) { + FIXME("No window available\n"); + return E_FAIL; + } + + /* reload is supposed to fail if called from a script with different origin, but IE doesn't care */ + if(!is_main_content_window(This->window->base.outer_window)) { + FIXME("Unsupported on iframe\n"); + return E_NOTIMPL; + } + + return reload_page(This->window->base.outer_window); } static HRESULT WINAPI HTMLLocation_replace(IHTMLLocation *iface, BSTR bstr) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 804db0b1bdf..751e3ffbce5 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -1094,6 +1094,7 @@ HRESULT async_start_doc_binding(HTMLOuterWindow*,HTMLInnerWindow*) DECLSPEC_HIDD void abort_window_bindings(HTMLInnerWindow*) DECLSPEC_HIDDEN; void set_download_state(HTMLDocumentObj*,int) DECLSPEC_HIDDEN; void call_docview_84(HTMLDocumentObj*) DECLSPEC_HIDDEN; +HRESULT reload_page(HTMLOuterWindow*) DECLSPEC_HIDDEN; void set_ready_state(HTMLOuterWindow*,READYSTATE) DECLSPEC_HIDDEN; HRESULT get_readystate_string(READYSTATE,BSTR*) DECLSPEC_HIDDEN; diff --git a/dlls/mshtml/olecmd.c b/dlls/mshtml/olecmd.c index 40c36bceb0a..ac5a22ef16a 100644 --- a/dlls/mshtml/olecmd.c +++ b/dlls/mshtml/olecmd.c @@ -449,10 +449,23 @@ static void refresh_destr(task_t *_task) free(task); } +HRESULT reload_page(HTMLOuterWindow *window) +{ + refresh_task_t *task; + + task = malloc(sizeof(*task)); + if(!task) + return E_OUTOFMEMORY; + + IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface); + task->window = window; + + return push_task(&task->header, refresh_proc, refresh_destr, window->task_magic); +} + static HRESULT exec_refresh(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) { HTMLDocumentObj *doc_obj; - refresh_task_t *task; HRESULT hres; TRACE("(%p)->(%ld %s %p)\n", doc, nCmdexecopt, debugstr_variant(pvaIn), pvaOut); @@ -478,14 +491,7 @@ static HRESULT exec_refresh(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *p if(!doc->outer_window) return E_UNEXPECTED; - task = malloc(sizeof(*task)); - if(!task) - return E_OUTOFMEMORY; - - IHTMLWindow2_AddRef(&doc->outer_window->base.IHTMLWindow2_iface); - task->window = doc->outer_window; - - return push_task(&task->header, refresh_proc, refresh_destr, doc->outer_window->task_magic); + return reload_page(doc->outer_window); } static HRESULT exec_stop(HTMLDocumentNode *doc, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c index b496d562fb1..a4a2207d4d2 100644 --- a/dlls/mshtml/tests/htmldoc.c +++ b/dlls/mshtml/tests/htmldoc.c @@ -1142,6 +1142,7 @@ static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, D case 3000030: case 3000031: case 3000032: + case 3000033: /* TODO */ return S_OK; } @@ -6399,6 +6400,24 @@ static void test_refresh(IHTMLDocument2 *doc) test_download(DWL_VERBDONE|DWL_HTTP|DWL_ONREADY_LOADING|DWL_REFRESH|DWL_EX_GETHOSTINFO); } +static void test_reload(IHTMLDocument2 *doc) +{ + IHTMLLocation *location; + HRESULT hres; + + trace("Reload...\n"); + + location = NULL; + hres = IHTMLDocument2_get_location(doc, &location); + ok(hres == S_OK, "get_location failed: %08lx\n", hres); + ok(location != NULL, "location == NULL\n"); + + hres = IHTMLLocation_reload(location, VARIANT_FALSE); + IHTMLLocation_Release(location); + + test_download(DWL_VERBDONE|DWL_HTTP|DWL_ONREADY_LOADING|DWL_REFRESH|DWL_EX_GETHOSTINFO); +} + static void test_open_window(IHTMLDocument2 *doc, BOOL do_block) { IHTMLWindow2 *window, *new_window; @@ -8216,6 +8235,7 @@ static void test_HTMLDocument_http(BOOL with_wbapp) test_put_href(doc, FALSE, L"#test", L"http://test.winehq.org/tests/winehq_snapshot/#test", FALSE, TRUE, 0); test_travellog(doc); test_refresh(doc); + test_reload(doc); } test_put_href(doc, FALSE, NULL, L"javascript:external%20&&undefined", TRUE, FALSE, 0); test_put_href(doc, FALSE, NULL, L"about:blank", FALSE, FALSE, support_wbapp ? DWL_EXPECT_HISTUPDATE : 0); diff --git a/dlls/mshtml/tests/reload.js b/dlls/mshtml/tests/reload.js new file mode 100644 index 00000000000..04bdf9fcb90 --- /dev/null +++ b/dlls/mshtml/tests/reload.js @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Gabriel Ivăncescu for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +var tests = []; + +async_test("reload", function() { + if(sessionStorage.getItem("skip reload test")) { + next_test(); + return; + } + + var script = document.createElement("script"); + script.src ="http://winetest.different.org/jsstream.php?reload"; + document.getElementsByTagName("head")[0].appendChild(script); + + external.writeStream("reload", + ' try {' + + ' window.location.reload();' + + ' sessionStorage.setItem("skip reload test", true);' + + ' }catch(e) {' + + ' ok(false, "reload with different origin threw " + e.number);' + + ' }' + + ' next_test()' + ); +}); diff --git a/dlls/mshtml/tests/rsrc.rc b/dlls/mshtml/tests/rsrc.rc index e60e37198de..10b92ab78cb 100644 --- a/dlls/mshtml/tests/rsrc.rc +++ b/dlls/mshtml/tests/rsrc.rc @@ -64,6 +64,9 @@ events.js HTML "events.js" /* @makedep: documentmode.js */ documentmode.js HTML "documentmode.js" +/* @makedep: reload.js */ +reload.js HTML "reload.js" + /* @makedep: blank.html */ blank.html HTML "blank.html" diff --git a/dlls/mshtml/tests/script.c b/dlls/mshtml/tests/script.c index d7d7e7361c3..b27b68b5bd1 100644 --- a/dlls/mshtml/tests/script.c +++ b/dlls/mshtml/tests/script.c @@ -4088,6 +4088,7 @@ static void run_js_tests(void) run_script_as_http_with_mode("documentmode.js", "11", "edge;123"); run_script_as_http_with_mode("asyncscriptload.js", NULL, "9"); + run_script_as_http_with_mode("reload.js", NULL, "11"); } static BOOL init_registry(BOOL init)