mshtml: Get rid of HTMLDocument_OnLoad and move its job to AsyncOpen.

This commit is contained in:
Jacek Caban 2006-02-09 12:19:33 +01:00 committed by Alexandre Julliard
parent ae23f8d8cb
commit 990e20c992
4 changed files with 102 additions and 69 deletions

View File

@ -32,6 +32,7 @@
#define NS_NOINTERFACE ((nsresult)0x80004002L) #define NS_NOINTERFACE ((nsresult)0x80004002L)
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult)0x80004001L) #define NS_ERROR_NOT_IMPLEMENTED ((nsresult)0x80004001L)
#define NS_ERROR_INVALID_ARG ((nsresult)0x80070057L) #define NS_ERROR_INVALID_ARG ((nsresult)0x80070057L)
#define NS_ERROR_UNEXPECTED ((nsresult)0x8000ffffL)
#define NS_FAILED(res) ((res) & 0x80000000) #define NS_FAILED(res) ((res) & 0x80000000)
#define NS_SUCCEEDED(res) (!NS_FAILED(res)) #define NS_SUCCEEDED(res) (!NS_FAILED(res))
@ -93,7 +94,7 @@ struct NSContainer {
HWND hwnd; HWND hwnd;
LPOLESTR url; /* hack */ BOOL load_call; /* hack */
}; };
#define HTMLDOC(x) ((IHTMLDocument2*) &(x)->lpHTMLDocument2Vtbl) #define HTMLDOC(x) ((IHTMLDocument2*) &(x)->lpHTMLDocument2Vtbl)
@ -139,7 +140,6 @@ void HTMLDocument_NSContainer_Destroy(HTMLDocument*);
void HTMLDocument_LockContainer(HTMLDocument*,BOOL); void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
void HTMLDocument_ShowContextMenu(HTMLDocument*,DWORD,POINT*); void HTMLDocument_ShowContextMenu(HTMLDocument*,DWORD,POINT*);
BOOL HTMLDocument_OnLoad(HTMLDocument*,LPCWSTR);
HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**); HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);

View File

@ -663,41 +663,28 @@ static nsrefcnt NSAPI nsURIContentListener_Release(nsIURIContentListener *iface)
return nsIWebBrowserChrome_Release(NSWBCHROME(This)); return nsIWebBrowserChrome_Release(NSWBCHROME(This));
} }
static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface, nsIURI *aURI, static nsresult NSAPI nsURIContentListener_OnStartURIOpen(nsIURIContentListener *iface,
PRBool *_retval) nsIURI *aURI, PRBool *_retval)
{ {
NSContainer *This = NSURICL_THIS(iface); NSContainer *This = NSURICL_THIS(iface);
BOOL do_load = TRUE; nsIWineURI *wine_uri;
nsresult nsres;
nsACString *spec_str = nsACString_Create(); nsACString *spec_str = nsACString_Create();
const char *spec;
nsresult nsres;
TRACE("(%p)->(%p %p)\n", This, aURI, _retval); nsIURI_GetSpec(aURI, spec_str);
nsACString_GetData(spec_str, &spec, NULL);
nsres = nsIURI_GetSpec(aURI, spec_str); TRACE("(%p)->(%p(%s) %p)\n", This, aURI, debugstr_a(spec), _retval);
if(NS_SUCCEEDED(nsres)) {
const char *spec = NULL;
LPWSTR specw;
int len;
nsACString_GetData(spec_str, &spec, NULL);
len = MultiByteToWideChar(CP_ACP, 0, spec, -1, NULL, 0);
specw = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, spec, -1, specw, -1);
if(strcmpW(This->url, specw)) /* hack */
do_load = HTMLDocument_OnLoad(This->doc, specw);
HeapFree(GetProcessHeap(), 0, specw);
}else {
ERR("GetSpec failed: %08lx\n", nsres);
}
nsACString_Destroy(spec_str); nsACString_Destroy(spec_str);
if(!do_load) { nsres = nsIURI_QueryInterface(aURI, &IID_nsIWineURI, (void**)&wine_uri);
*_retval = TRUE; if(NS_SUCCEEDED(nsres)) {
return NS_OK; nsIWineURI_SetNSContainer(wine_uri, This);
nsIWineURI_Release(wine_uri);
}else {
WARN("Could not get nsIWineURI interface: %08lx\n", nsres);
} }
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
@ -977,7 +964,7 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This)
if(NS_FAILED(nsres)) if(NS_FAILED(nsres))
ERR("SetParentURIContentListener failed: %08lx\n", nsres); ERR("SetParentURIContentListener failed: %08lx\n", nsres);
This->nscontainer->url = NULL; This->nscontainer->load_call = FALSE;
} }
void HTMLDocument_NSContainer_Destroy(HTMLDocument *This) void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
@ -992,7 +979,4 @@ void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
nsIWebBrowserStream_Release(This->nscontainer->stream); nsIWebBrowserStream_Release(This->nscontainer->stream);
HeapFree(GetProcessHeap(), 0, This->nscontainer); HeapFree(GetProcessHeap(), 0, This->nscontainer);
if(This->nscontainer->url)
CoTaskMemFree(This->nscontainer->url);
} }

View File

@ -26,6 +26,7 @@
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
#include "ole2.h" #include "ole2.h"
#include "shlguid.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/unicode.h" #include "wine/unicode.h"
@ -34,6 +35,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(mshtml); WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
#define LOAD_INITIAL_DOCUMENT_URI 0x80000
#define NS_IOSERVICE_CLASSNAME "nsIOService" #define NS_IOSERVICE_CLASSNAME "nsIOService"
#define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1" #define NS_IOSERVICE_CONTRACTID "@mozilla.org/network/io-service;1"
@ -65,6 +68,76 @@ typedef struct {
#define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl) #define NSHTTPCHANNEL(x) ((nsIHttpChannel*) &(x)->lpHttpChannelVtbl)
#define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl) #define NSURI(x) ((nsIURI*) &(x)->lpWineURIVtbl)
static BOOL exec_shldocvw_67(NSContainer *container, LPCWSTR url)
{
IOleCommandTarget *cmdtrg = NULL;
HRESULT hres;
hres = IOleClientSite_QueryInterface(container->doc->client, &IID_IOleCommandTarget,
(void**)&cmdtrg);
if(SUCCEEDED(hres)) {
VARIANT varUrl, varRes;
V_VT(&varUrl) = VT_BSTR;
V_BSTR(&varUrl) = SysAllocString(url);
V_VT(&varRes) = VT_BOOL;
hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
IOleCommandTarget_Release(cmdtrg);
SysFreeString(V_BSTR(&varUrl));
if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
TRACE("got VARIANT_FALSE, do not load\n");
return FALSE;
}
}
return TRUE;
}
static BOOL before_async_open(nsChannel *This)
{
nsACString *uri_str;
NSContainer *container;
PRUint32 load_flags = 0;
const char *uria;
LPWSTR uri;
DWORD len;
BOOL ret = TRUE;
nsIChannel_GetLoadFlags(This->channel, &load_flags);
TRACE("load_flags = %08lx\n", load_flags);
if(!(load_flags & LOAD_INITIAL_DOCUMENT_URI))
return TRUE;
nsIWineURI_GetNSContainer(This->uri, &container);
if(!container) {
WARN("container = NULL\n");
return TRUE;
}
if(container->load_call) {
nsIWebBrowserChrome_Release(NSWBCHROME(container));
return TRUE;
}
uri_str = nsACString_Create();
nsIWineURI_GetSpec(This->uri, uri_str);
nsACString_GetData(uri_str, &uria, NULL);
len = MultiByteToWideChar(CP_ACP, 0, uria, -1, NULL, 0);
uri = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, uria, -1, uri, len);
nsACString_Destroy(uri_str);
ret = exec_shldocvw_67(container, uri);
nsIWebBrowserChrome_Release(NSWBCHROME(container));
HeapFree(GetProcessHeap(), 0, uri);
return ret;
}
#define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface) #define NSCHANNEL_THIS(iface) DEFINE_THIS(nsChannel, HttpChannel, iface)
static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result) static nsresult NSAPI nsChannel_QueryInterface(nsIHttpChannel *iface, nsIIDRef riid, nsQIResult result)
@ -311,7 +384,14 @@ static nsresult NSAPI nsChannel_AsyncOpen(nsIHttpChannel *iface, nsIStreamListen
nsISupports *aContext) nsISupports *aContext)
{ {
nsChannel *This = NSCHANNEL_THIS(iface); nsChannel *This = NSCHANNEL_THIS(iface);
TRACE("(%p)->(%p %p)\n", This, aListener, aContext); TRACE("(%p)->(%p %p)\n", This, aListener, aContext);
if(!before_async_open(This)) {
TRACE("canceled\n");
return NS_ERROR_UNEXPECTED;
}
return nsIChannel_AsyncOpen(This->channel, aListener, aContext); return nsIChannel_AsyncOpen(This->channel, aListener, aContext);
} }

View File

@ -362,18 +362,15 @@ static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAva
* It uses Gecko's LoadURI instead of IMoniker's BindToStorage. Should we improve * It uses Gecko's LoadURI instead of IMoniker's BindToStorage. Should we improve
* it (to do so we'd have to use not frozen interfaces)? * it (to do so we'd have to use not frozen interfaces)?
*/ */
LPOLESTR old_url = This->nscontainer->url; This->nscontainer->load_call = TRUE;
This->nscontainer->url = url;
nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url, nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
LOAD_FLAGS_NONE, NULL, NULL, NULL); LOAD_FLAGS_NONE, NULL, NULL, NULL);
if(NS_SUCCEEDED(nsres)) { This->nscontainer->load_call = FALSE;
CoTaskMemFree(old_url);
if(NS_SUCCEEDED(nsres))
return S_OK; return S_OK;
}else { else
WARN("LoadURI failed: %08lx\n", nsres); WARN("LoadURI failed: %08lx\n", nsres);
This->nscontainer->url = old_url;
}
} }
/* FIXME: Use grfMode */ /* FIXME: Use grfMode */
@ -563,34 +560,6 @@ static const IPersistFileVtbl PersistFileVtbl = {
PersistFile_GetCurFile PersistFile_GetCurFile
}; };
BOOL HTMLDocument_OnLoad(HTMLDocument *This, LPCWSTR url)
{
IOleCommandTarget *cmdtrg = NULL;
HRESULT hres;
TRACE("(%p)->(%s)\n", This, debugstr_w(url));
hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&cmdtrg);
if(SUCCEEDED(hres)) {
VARIANT varUrl, varRes;
V_VT(&varUrl) = VT_BSTR;
V_BSTR(&varUrl) = SysAllocString(url);
V_VT(&varRes) = VT_BOOL;
hres = IOleCommandTarget_Exec(cmdtrg, &CGID_ShellDocView, 67, 0, &varUrl, &varRes);
SysFreeString(V_BSTR(&varUrl));
if(SUCCEEDED(hres) && !V_BOOL(&varRes)) {
TRACE("got VARIANT_FALSE, do not load\n");
IOleCommandTarget_Release(cmdtrg);
return FALSE;
}
}
return TRUE;
}
void HTMLDocument_Persist_Init(HTMLDocument *This) void HTMLDocument_Persist_Init(HTMLDocument *This)
{ {
This->lpPersistMonikerVtbl = &PersistMonikerVtbl; This->lpPersistMonikerVtbl = &PersistMonikerVtbl;