Cocoa window restoration and CEF runloop

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.

Cocoa window restoration and CEF runloop

Postby tomst » Mon Apr 25, 2016 4:24 pm

Hi,

I'm trying to use Cocoa's native window restoration with CEF. cefclient_mac.mm says:

Code: Select all
// The default |-terminate:| implementation ends the process by calling exit(),
// and thus never leaves the main run loop. This is unsuitable for Chromium
// since Chromium depends on leaving the main run loop to perform an orderly
// shutdown.


This rules out the option of using [NSApp terminate:] directly (which causes CEF to crash in CefForceShutdown). However, in order to make window restoration work, I need to call the native implementation of [NSApp terminate:] because calling CefQuitMessageLoop() does not call my document's window:willEncodeRestorableState: method. Another option of terminating the app I was thinking about was to call [NSApp terminate:], and then override "applicationWillTerminate:" (which is called after the restoration state is serialized), and give CEF some time to clean up using CefQuitMessageLoop(); / CefDoMessageLoopWork();, however I wasn't able to come up with a working implementation.

Is there a way to use Cocoa's native [NSApp terminate:] together with CEF to enable native window restoration?

Thanks
Thomas
tomst
Techie
 
Posts: 43
Joined: Fri Aug 22, 2014 4:38 pm

Re: Cocoa window restoration and CEF runloop

Postby magreenblatt » Mon Apr 25, 2016 6:20 pm

If you can figure out what [NSApp terminate:] does related to window restoration then you could just do that in your shutdown code instead of relying on the default [NSApp terminate:] implementation to do it for you.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cocoa window restoration and CEF runloop

Postby tomst » Tue Apr 26, 2016 3:17 am

Thanks for the suggestion. Those are some private methods in NSPersistentUIManager which I'd rather not call directly. I figured out a way that wouldn't crash the application when exiting though. Not sure if it's the correct way to shut down, but it appears to work for now. I call the native [NSApp terminate:], and then implemented applicationWillTerminate: as follows:

Code: Select all
// In the app delegate
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
    // This method is executed after the window restoration state is saved.
    CefShutdown();
}


On a related note, I'm also trying to restore fullscreen windows. If Cocoa restores a fullscreen window, I'd like to make the website aware of it. I was thinking of calling "webkitRequestFullscreen" in the JavaScript if the restored window is fullscreen, but Chromium doesn't let you call it explicitly ("API can only be initiated by a user gesture."). Any ideas what I could do here?
tomst
Techie
 
Posts: 43
Joined: Fri Aug 22, 2014 4:38 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 89 guests