mshtml: Make load_gecko thread safe.

This commit is contained in:
Jacek Caban 2007-02-13 18:06:25 +01:00 committed by Alexandre Julliard
parent 92f675749f
commit bdf2bf93a8
3 changed files with 48 additions and 20 deletions

View File

@ -358,7 +358,7 @@ static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
return FALSE;
}
void install_wine_gecko(void)
BOOL install_wine_gecko(void)
{
HANDLE hsem;
@ -374,4 +374,6 @@ void install_wine_gecko(void)
ReleaseSemaphore(hsem, 1, NULL);
CloseHandle(hsem);
return TRUE;
}

View File

@ -370,7 +370,7 @@ HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
void release_nodes(HTMLDocument*);
void install_wine_gecko(void);
BOOL install_wine_gecko(void);
/* editor */
void handle_edit_event(HTMLDocument*,nsIDOMEvent*);

View File

@ -321,30 +321,13 @@ static void set_profile(void)
nsIProfile_Release(profile);
}
static BOOL load_gecko(void)
static BOOL init_xpcom(PRUnichar *gre_path)
{
nsresult nsres;
nsIObserver *pStartNotif;
nsIComponentRegistrar *registrar = NULL;
nsAString path;
nsIFile *gre_dir;
PRUnichar gre_path[MAX_PATH];
static BOOL tried_load = FALSE;
TRACE("()\n");
if(tried_load)
return pCompMgr != NULL;
tried_load = TRUE;
if(!load_wine_gecko(gre_path) && !load_mozctl(gre_path) && !load_mozilla(gre_path)) {
install_wine_gecko();
if(!load_wine_gecko(gre_path)) {
MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
return FALSE;
}
}
nsAString_Init(&path, gre_path);
nsres = NS_NewLocalFile(&path, FALSE, &gre_dir);
@ -408,6 +391,49 @@ static BOOL load_gecko(void)
return TRUE;
}
static CRITICAL_SECTION cs_load_gecko;
static CRITICAL_SECTION_DEBUG cs_load_gecko_dbg =
{
0, 0, &cs_load_gecko,
{ &cs_load_gecko_dbg.ProcessLocksList, &cs_load_gecko_dbg.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": load_gecko") }
};
static CRITICAL_SECTION cs_load_gecko = { &cs_load_gecko_dbg, -1, 0, 0, 0, 0 };
static BOOL load_gecko(void)
{
PRUnichar gre_path[MAX_PATH];
BOOL ret = FALSE;
static LONG loading_thread;
TRACE("()\n");
/* load_gecko may be called recursively */
if(loading_thread == GetCurrentThreadId())
return pCompMgr != NULL;
EnterCriticalSection(&cs_load_gecko);
if(!loading_thread) {
loading_thread = GetCurrentThreadId();
if(load_wine_gecko(gre_path)
|| load_mozctl(gre_path)
|| load_mozilla(gre_path)
|| (install_wine_gecko() && load_wine_gecko(gre_path)))
ret = init_xpcom(gre_path);
else
MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
}else {
ret = pCompMgr != NULL;
}
LeaveCriticalSection(&cs_load_gecko);
return ret;
}
void *nsalloc(size_t size)
{
return nsIMemory_Alloc(nsmem, size);