Call window.shutdown when native window is closed

The root view will now be serialized and saved to local
storage when the window is closed or the application is
terminated.
This commit is contained in:
Kevin Sawicki 2012-10-11 13:07:07 -07:00
parent b3ce062be9
commit 8c0f443c75
4 changed files with 28 additions and 3 deletions

View File

@ -168,6 +168,11 @@
}
- (void)applicationWillTerminate:(NSNotification *)notification {
NSInteger windowCount = [[self windows] count];
for(int i = 0; i < windowCount; i++) {
NSWindow *window = [[self windows] objectAtIndex:i];
[window performClose:0];
}
CefShutdown();
}

View File

@ -14,9 +14,8 @@ class AtomCefRenderProcessHandler : public CefRenderProcessHandler {
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE;
void Reload(CefRefPtr<CefBrowser> browser);
void Shutdown(CefRefPtr<CefBrowser> browser);
bool CallMessageReceivedHandler(CefRefPtr<CefV8Context> context, CefRefPtr<CefProcessMessage> message);
IMPLEMENT_REFCOUNTING(AtomCefRenderProcessHandler);

View File

@ -27,6 +27,10 @@ bool AtomCefRenderProcessHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser>
Reload(browser);
return true;
}
else if (name == "shutdown") {
Shutdown(browser);
return true;
}
else {
return CallMessageReceivedHandler(browser->GetMainFrame()->GetV8Context(), message);
}
@ -47,6 +51,17 @@ void AtomCefRenderProcessHandler::Reload(CefRefPtr<CefBrowser> browser) {
context->Exit();
}
void AtomCefRenderProcessHandler::Shutdown(CefRefPtr<CefBrowser> browser) {
CefRefPtr<CefV8Context> context = browser->GetMainFrame()->GetV8Context();
CefRefPtr<CefV8Value> global = context->GetGlobal();
context->Enter();
CefV8ValueList arguments;
CefRefPtr<CefV8Value> shutdownFunction = global->GetValue("shutdown");
shutdownFunction->ExecuteFunction(global, arguments);
context->Exit();
}
bool AtomCefRenderProcessHandler::CallMessageReceivedHandler(CefRefPtr<CefV8Context> context, CefRefPtr<CefProcessMessage> message) {
context->Enter();

View File

@ -143,8 +143,14 @@
}
}
- (BOOL)windowShouldClose:(id)window {
- (void)windowWillClose:(NSNotification *)notification {
if (_cefClient && _cefClient->GetBrowser()) {
_cefClient->GetBrowser()->SendProcessMessage(PID_RENDERER, CefProcessMessage::Create("shutdown"));
}
[self autorelease];
}
- (BOOL)windowShouldClose:(id)window {
return YES;
}