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
This commit is contained in:
Marshall Greenblatt 2012-05-29 18:06:22 +00:00
parent 71773b5bbc
commit 584bd26331
2 changed files with 13 additions and 1 deletions

View File

@ -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);

View File

@ -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);