From 2e6353d4bc6ffbac0d226d1f932c586c4dda9d9a Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 4 Jan 2010 00:38:57 +0100 Subject: [PATCH] mshtml: Use nsIDocShell to load a page in set_moniker. --- dlls/mshtml/mshtml_private.h | 3 +- dlls/mshtml/navigate.c | 59 +++++++++++++++++++----------------- dlls/mshtml/nsembed.c | 23 +------------- dlls/mshtml/nsiface.idl | 6 +++- dlls/mshtml/nsio.c | 48 +++++++++++++++++++++++------ dlls/mshtml/persist.c | 33 +++++++++----------- 6 files changed, 92 insertions(+), 80 deletions(-) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 6629dc8dc72..491bc2aa527 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -52,7 +52,6 @@ typedef struct HTMLDOMNode HTMLDOMNode; typedef struct ConnectionPoint ConnectionPoint; typedef struct BSCallback BSCallback; -typedef struct nsChannelBSC nsChannelBSC; typedef struct event_target_t event_target_t; /* NOTE: make sure to keep in sync with dispex.c */ @@ -425,7 +424,6 @@ struct NSContainer { HWND hwnd; - nsChannelBSC *bscallback; /* hack */ HWND reset_focus; /* hack */ }; @@ -687,6 +685,7 @@ HRESULT create_doc_uri(HTMLWindow*,WCHAR*,nsIWineURI**); HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD); HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*); HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*); +HRESULT load_nsuri(HTMLWindow*,nsIWineURI*,DWORD); void call_property_onchanged(ConnectionPoint*,DISPID); HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*); diff --git a/dlls/mshtml/navigate.c b/dlls/mshtml/navigate.c index 7cfc10eec23..b85de92e33d 100644 --- a/dlls/mshtml/navigate.c +++ b/dlls/mshtml/navigate.c @@ -1253,14 +1253,39 @@ HRESULT hlink_frame_navigate(HTMLDocument *doc, LPCWSTR url, return hres; } +HRESULT load_nsuri(HTMLWindow *window, nsIWineURI *uri, DWORD flags) +{ + nsIWebNavigation *web_navigation; + nsIDocShell *doc_shell; + nsresult nsres; + + nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation); + if(NS_FAILED(nsres)) { + ERR("Could not get nsIWebNavigation interface: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell); + nsIWebNavigation_Release(web_navigation); + if(NS_FAILED(nsres)) { + ERR("Could not get nsIDocShell: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)uri, NULL, flags, FALSE); + nsIDocShell_Release(doc_shell); + if(NS_FAILED(nsres)) { + WARN("LoadURI failed: %08x\n", nsres); + return E_FAIL; + } + + return S_OK; +} HRESULT navigate_url(HTMLWindow *window, const WCHAR *new_url, const WCHAR *base_url) { WCHAR url[INTERNET_MAX_URL_LENGTH]; - nsIWebNavigation *web_navigation; - nsIDocShell *doc_shell; nsIWineURI *uri; - nsresult nsres; HRESULT hres; if(!new_url) { @@ -1294,31 +1319,11 @@ HRESULT navigate_url(HTMLWindow *window, const WCHAR *new_url, const WCHAR *base TRACE("hlink_frame_navigate failed: %08x\n", hres); } - nsres = get_nsinterface((nsISupports*)window->nswindow, &IID_nsIWebNavigation, (void**)&web_navigation); - if(NS_FAILED(nsres)) { - ERR("Could not get nsIWebNavigation interface: %08x\n", nsres); - return E_FAIL; - } - - nsres = nsIWebNavigation_QueryInterface(web_navigation, &IID_nsIDocShell, (void**)&doc_shell); - nsIWebNavigation_Release(web_navigation); - if(NS_FAILED(nsres)) { - ERR("Could not get nsIDocShell: %08x\n", nsres); - return E_FAIL; - } - hres = create_doc_uri(window, url, &uri); - if(FAILED(hres)) { - nsIDocShell_Release(doc_shell); + if(FAILED(hres)) return hres; - } - nsres = nsIDocShell_LoadURI(doc_shell, (nsIURI*)uri, NULL, 0, FALSE); - nsIDocShell_Release(doc_shell); - if(NS_FAILED(nsres)) { - WARN("LoadURI failed: %08x\n", nsres); - return E_FAIL; - } - - return S_OK; + hres = load_nsuri(window, uri, LOAD_FLAGS_NONE); + nsIWineURI_Release(uri); + return hres; } diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c index 773ebeda243..68588977697 100644 --- a/dlls/mshtml/nsembed.c +++ b/dlls/mshtml/nsembed.c @@ -1172,28 +1172,7 @@ static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener nsIWineURI_SetNSContainer(wine_uri, This); nsIWineURI_SetIsDocumentURI(wine_uri, TRUE); - if(This->bscallback) { - IMoniker *mon = get_channelbsc_mon(This->bscallback); - - if(mon) { - LPWSTR wine_url; - HRESULT hres; - - hres = IMoniker_GetDisplayName(mon, NULL, 0, &wine_url); - if(SUCCEEDED(hres)) { - nsIWineURI_SetWineURL(wine_uri, wine_url); - CoTaskMemFree(wine_url); - }else { - WARN("GetDisplayName failed: %08x\n", hres); - } - - IMoniker_Release(mon); - } - - *_retval = FALSE; - }else if(This->doc) { - *_retval = translate_url(This->doc->basedoc.doc_obj, wine_uri); - } + *_retval = translate_url(This->doc->basedoc.doc_obj, wine_uri); } nsIWineURI_Release(wine_uri); diff --git a/dlls/mshtml/nsiface.idl b/dlls/mshtml/nsiface.idl index 4111e12b5f2..af117622001 100644 --- a/dlls/mshtml/nsiface.idl +++ b/dlls/mshtml/nsiface.idl @@ -1706,7 +1706,8 @@ interface nsIBaseWindow : nsISupports nsresult SetTitle(const PRUnichar *aTitle); } -cpp_quote("#define LOAD_FLAGS_NONE 0") +cpp_quote("#define LOAD_FLAGS_NONE 0x00000") +cpp_quote("#define LOAD_INITIAL_DOCUMENT_URI 0x80000") [ object, @@ -2835,11 +2836,14 @@ interface nsIWineURI : nsIURL { typedef struct NSContainer NSContainer; typedef struct HTMLWindow HTMLWindow; + typedef struct nsChannelBSC nsChannelBSC; nsresult GetNSContainer(NSContainer **aNSContainer); nsresult SetNSContainer(NSContainer *aNSContainer); nsresult GetWindow(HTMLWindow **aHTMLWindow); nsresult SetWindow(HTMLWindow *aHTMLWindow); + nsresult GetChannelBSC(nsChannelBSC **aChannelBSC); + nsresult SetChannelBSC(nsChannelBSC *aChannelBSC); nsresult GetIsDocumentURI(PRBool *aIsDocumentURI); nsresult SetIsDocumentURI(PRBool aIsDocumentURI); nsresult GetWineURL(LPCWSTR *aURL); diff --git a/dlls/mshtml/nsio.c b/dlls/mshtml/nsio.c index 4b865b887cb..46fdcbc320c 100644 --- a/dlls/mshtml/nsio.c +++ b/dlls/mshtml/nsio.c @@ -38,8 +38,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml); -#define LOAD_INITIAL_DOCUMENT_URI 0x80000 - #define NS_IOSERVICE_CLASSNAME "nsIOService" #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1" @@ -60,6 +58,7 @@ typedef struct { nsIURL *nsurl; NSContainer *container; windowref_t *window_ref; + nsChannelBSC *channel_bsc; LPWSTR wine_url; PRBool is_doc_uri; BOOL use_wine_url; @@ -774,15 +773,17 @@ static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListen return NS_ERROR_UNEXPECTED; } - if(is_doc_uri && (This->load_flags & LOAD_INITIAL_DOCUMENT_URI) && window == window->doc_obj->basedoc.window) { - if(window->doc_obj->nscontainer->bscallback) { - NSContainer *nscontainer = window->doc_obj->nscontainer; + if(is_doc_uri && window == window->doc_obj->basedoc.window) { + nsChannelBSC *channel_bsc; - channelbsc_set_channel(nscontainer->bscallback, This, aListener, aContext); + nsIWineURI_GetChannelBSC(This->uri, &channel_bsc); + if(channel_bsc) { + channelbsc_set_channel(channel_bsc, This, aListener, aContext); + IUnknown_Release((IUnknown*)channel_bsc); - if(nscontainer->doc->mime) { + if(window->doc_obj->mime) { heap_free(This->content_type); - This->content_type = heap_strdupWtoA(nscontainer->doc->mime); + This->content_type = heap_strdupWtoA(window->doc_obj->mime); } open = FALSE; @@ -798,8 +799,7 @@ static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListen if(open) nsres = async_open(This, window, is_doc_uri, aListener, aContext); - if(window) - IHTMLWindow2_Release(HTMLWINDOW2(window)); + IHTMLWindow2_Release(HTMLWINDOW2(window)); return nsres; } @@ -2057,6 +2057,32 @@ static nsresult NSAPI nsURI_SetWindow(nsIWineURI *iface, HTMLWindow *aHTMLWindow return NS_OK; } +static nsresult NSAPI nsURI_GetChannelBSC(nsIWineURI *iface, nsChannelBSC **aChannelBSC) +{ + nsURI *This = NSURI_THIS(iface); + + TRACE("(%p)->(%p)\n", This, aChannelBSC); + + if(This->channel_bsc) + IUnknown_AddRef((IUnknown*)This->channel_bsc); + *aChannelBSC = This->channel_bsc; + return NS_OK; +} + +static nsresult NSAPI nsURI_SetChannelBSC(nsIWineURI *iface, nsChannelBSC *aChannelBSC) +{ + nsURI *This = NSURI_THIS(iface); + + TRACE("(%p)->(%p)\n", This, aChannelBSC); + + if(This->channel_bsc) + IUnknown_Release((IUnknown*)This->channel_bsc); + if(aChannelBSC) + IUnknown_AddRef((IUnknown*)aChannelBSC); + This->channel_bsc = aChannelBSC; + return NS_OK; +} + static nsresult NSAPI nsURI_GetIsDocumentURI(nsIWineURI *iface, PRBool *aIsDocumentURI) { nsURI *This = NSURI_THIS(iface); @@ -2175,6 +2201,8 @@ static const nsIWineURIVtbl nsWineURIVtbl = { nsURI_SetNSContainer, nsURI_GetWindow, nsURI_SetWindow, + nsURI_GetChannelBSC, + nsURI_SetChannelBSC, nsURI_GetIsDocumentURI, nsURI_SetIsDocumentURI, nsURI_GetWineURL, diff --git a/dlls/mshtml/persist.c b/dlls/mshtml/persist.c index e6a54ac2eff..d3014b8d330 100644 --- a/dlls/mshtml/persist.c +++ b/dlls/mshtml/persist.c @@ -172,8 +172,8 @@ static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BO LPOLESTR url = NULL; docobj_task_t *task; download_proc_task_t *download_task; + nsIWineURI *nsuri; HRESULT hres; - nsresult nsres; if(pibc) { IUnknown *unk = NULL; @@ -254,8 +254,22 @@ static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BO } } + hres = create_doc_uri(This->window, url, &nsuri); + CoTaskMemFree(url); + if(FAILED(hres)) + return hres; + bscallback = create_channelbsc(mon); + nsIWineURI_SetChannelBSC(nsuri, bscallback); + hres = load_nsuri(This->window, nsuri, LOAD_INITIAL_DOCUMENT_URI); + nsIWineURI_SetChannelBSC(nsuri, NULL); + if(SUCCEEDED(hres)) + set_window_bscallback(This->window, bscallback); + IUnknown_Release((IUnknown*)bscallback); + if(FAILED(hres)) + return hres; + if(This->doc_obj->frame) { task = heap_alloc(sizeof(docobj_task_t)); task->doc = This->doc_obj; @@ -267,23 +281,6 @@ static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BO download_task->set_download = set_download; push_task(&download_task->header, set_downloading_proc, This->doc_obj->basedoc.task_magic); - if(This->doc_obj->nscontainer) { - This->doc_obj->nscontainer->bscallback = bscallback; - nsres = nsIWebNavigation_LoadURI(This->doc_obj->nscontainer->navigation, url, - LOAD_FLAGS_NONE, NULL, NULL, NULL); - This->doc_obj->nscontainer->bscallback = NULL; - if(NS_FAILED(nsres)) { - WARN("LoadURI failed: %08x\n", nsres); - IUnknown_Release((IUnknown*)bscallback); - CoTaskMemFree(url); - return E_FAIL; - } - } - - set_window_bscallback(This->window, bscallback); - IUnknown_Release((IUnknown*)bscallback); - CoTaskMemFree(url); - return S_OK; }