Cannot dismiss alert generated during onresize

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Cannot dismiss alert generated during onresize

Postby mikeyk730 » Fri Apr 23, 2010 1:17 pm

I am using CEF r72. I have built cefclient without TEST_SINGLE_THREADED_MESSAGE_LOOP defined. The effect of this to use a separate thread for UI.

If I load the following HTML in cefclient and resize the window, I get an alert as expected. However, I cannot dismiss or interact with the alert in any way. The application is effectively hung. If I give focus to another application, I cannot get focus back to cefclient.

Code: Select all
<html>
  <head>
    <script type="text/javascript">
      function resizeit(){
       alert("resized!");
      }
      window.onresize = resizeit;
    </script>
  </head>
  <body>
    <p>resize the window</p>   
  </body>
</html>


I am trying to understand why this is happening. From what I can tell in VS 2008, both threads are blocked:
The main thread is in EndDeferWindowPos (handling WM_SIZE in the WndProc of cefclient.cpp)
The UI thread is in BrowserWebViewDelegate::ShowJavaScriptAlert

This only happens if I use a separate thread for UI. Does anybody have an idea what is wrong? What state should the threads be in when the message box is up?
mikeyk730
Newbie
 
Posts: 4
Joined: Fri Apr 23, 2010 12:45 pm

Re: Cannot dismiss alert generated during onresize

Postby magreenblatt » Fri Apr 23, 2010 10:31 pm

The EndDeferWindowPos call on the application thread is blocked waiting for a response from the browser window which it's trying to reposition. The browser window, which lives on the UI thread, is already blocked showing the alert message box. Hence the deadlock. You can probably avoid the deadlock by creating your own alert implementation in CefHandler::HandleJSAlert that doesn't block the UI thread. For instance, have CefHandler::HandleJSAlert send a message to the application thread and have the application thread show the message box instead.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cannot dismiss alert generated during onresize

Postby mikeyk730 » Wed May 05, 2010 12:56 pm

I had been approaching the problem from a different angle -- trying to prevent the resize call in the application thread from blocking. I replaced the DeferWindowPos family of functions with a call to SetWindowPos with the SWP_ASYNCWINDOWPOS flag. Based on the following documentation of SWP_ASYNCWINDOWPOS, I thought I could avoid blocking the application thread:

If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.


Unfortunately, this didn't help my original problem. I experienced the same deadlock, this time with SetWindowPos blocking the application thread.

I'll look into your suggestion of overriding HandleJSAlert instead. Thanks for the response!
mikeyk730
Newbie
 
Posts: 4
Joined: Fri Apr 23, 2010 12:45 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 59 guests