zhangqd / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
0 stars 1 forks source link

CefLifeSpanHandler::DoClose called before JS beforeunload #1230

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attach a native 'beforeunload' handler using 'addEventListener' from within 
CefRenderProcessHandler::OnContextCreated().
2. Close the browser.
3. CefLifeSpanHandler::DoClose() is called before 'beforeunload' handler, 
therefore ignoring it's attempt to prevent the page from closing.

What is the expected output? What do you see instead?
I expect 'beforeunload' to be called before DoClose, as the comments in 
<cef_life_span_handler.h> indicate. However the DoClose in the browser process 
happens before and ignores the return value of 'beforeunload' in the render 
process.

What version of the product are you using? On what operating system?
I'm using prebuild 32 bit windows binaries of 
dev channel: 2014-03-07 CEF 3.1846.1630 - Chromium 34.0.1846.0 r251746
and branch 1750: 2014-03-07 CEF 3.1750.1631 - Chromium 33.0.1750.117 

Please provide any additional information below.
It works OK with 
branch 1650: 2014-01-17 CEF 3.1650.1567 - Chromium 31.0.1650.57

I do inject 'beforeunload' in CefRenderProcessHandler::OnContextCreated() so 
that I can query all tabs (of a multi-tabbed browser) whether it is OK to 
close, and abort the close for all of them if one tab doesn't allow, as Google 
Chrome browser itself behaves.
Because my handler is registered before any normal java-script handler, it is 
called only if no handler is registered in script, so I use my handler to know 
that the page can close before javascript 'unload' gets called, ensuring 
expected behavior to scripts.

Original issue reported on code.google.com by elenabaj...@gmail.com on 13 Mar 2014 at 5:10

GoogleCodeExporter commented 9 years ago
This is most likely a problem in chrome. I suspect it may have something to do 
with this:
https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/preren
der/prerender_manager.cc&sq=package:chromium&l=628&dr=C&ct=rc&cd=5&q=NeedToFireB
eforeUnload
https://code.google.com/p/chromium/issues/detail?id=304932

I found a workaround for my case. Instead of adding a native 'beforeunload' 
listener as a hook between javascript 'beforeunload' and 'unload' event 
listeners, to prevent 'unload' event listeners from being called if the user 
aborted the closing in one of the tabs, I now simulate a navigation to 
'about:blank', which I abort in CefLoadHandler::OnLoadingStateChange. But since 
CefJSDialogHandler::OnBeforeUnloadDialog() is called between them (if called at 
all), I have the opportunity to ask the user whether it's OK to close each tab 
(that requests this) without actually closing any of them, and in the end 
either close all of them or none.

You may delete this issue.

Original comment by elenabaj...@gmail.com on 17 Mar 2014 at 9:01

GoogleCodeExporter commented 9 years ago
CEF is transitioning from Google Code to Bitbucket project hosting. If you 
would like to continue receiving notifications on this issue please add 
yourself as a Watcher at the new location: 
https://bitbucket.org/chromiumembedded/cef/issue/1230

Original comment by magreenb...@gmail.com on 14 Mar 2015 at 3:30