From 584bd26331ff4703bd95e490d5a7259474250d3c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 29 May 2012 18:06:22 +0000 Subject: [PATCH] Windows: Allow the JS dialog message hook to be shared across multiple browser windows (issue #605). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@654 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/javascript_dialog.h | 1 + libcef/browser/javascript_dialog_win.cc | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libcef/browser/javascript_dialog.h b/libcef/browser/javascript_dialog.h index bb6825468..14a598689 100644 --- a/libcef/browser/javascript_dialog.h +++ b/libcef/browser/javascript_dialog.h @@ -58,6 +58,7 @@ class CefJavaScriptDialog { static bool UninstallMessageHook(); static LRESULT CALLBACK GetMsgProc(int code, WPARAM wparam, LPARAM lparam); static HHOOK msg_hook_; + static int msg_hook_user_count_; #endif DISALLOW_COPY_AND_ASSIGN(CefJavaScriptDialog); diff --git a/libcef/browser/javascript_dialog_win.cc b/libcef/browser/javascript_dialog_win.cc index 3e6cf1edf..d24422203 100644 --- a/libcef/browser/javascript_dialog_win.cc +++ b/libcef/browser/javascript_dialog_win.cc @@ -16,6 +16,7 @@ class CefJavaScriptDialog; HHOOK CefJavaScriptDialog::msg_hook_ = NULL; +int CefJavaScriptDialog::msg_hook_user_count_ = 0; INT_PTR CALLBACK CefJavaScriptDialog::DialogProc(HWND dialog, UINT message, WPARAM wparam, @@ -192,8 +193,12 @@ LRESULT CALLBACK CefJavaScriptDialog::GetMsgProc(int code, WPARAM wparam, // static bool CefJavaScriptDialog::InstallMessageHook() { + msg_hook_user_count_++; + // Make sure we only call this once. - DCHECK(msg_hook_ == NULL); + if (msg_hook_ != NULL) + return true; + msg_hook_ = ::SetWindowsHookEx(WH_GETMESSAGE, &CefJavaScriptDialog::GetMsgProc, NULL, @@ -204,6 +209,12 @@ bool CefJavaScriptDialog::InstallMessageHook() { // static bool CefJavaScriptDialog::UninstallMessageHook() { + msg_hook_user_count_--; + DCHECK_GE(msg_hook_user_count_, 0); + + if (msg_hook_user_count_ > 0) + return true; + DCHECK(msg_hook_ != NULL); BOOL result = ::UnhookWindowsHookEx(msg_hook_); DCHECK(result);