mac: Destroy the app delegate before running destruction callbacks

Otherwise users might be able to access wrapper functions after they are
destroyed.
This commit is contained in:
Cheng Zhao 2015-11-04 17:23:27 +08:00
parent 75f49477ca
commit 84410a7e1c
3 changed files with 9 additions and 2 deletions

View file

@ -128,6 +128,10 @@ void AtomBrowserMainParts::PostMainMessageLoopStart() {
void AtomBrowserMainParts::PostMainMessageLoopRun() {
brightray::BrowserMainParts::PostMainMessageLoopRun();
#if defined(OS_MACOSX)
FreeAppDelegate();
#endif
// Make sure destruction callbacks are called before message loop is
// destroyed, otherwise some objects that need to be deleted on IO thread
// won't be freed.

View file

@ -46,7 +46,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
void PostMainMessageLoopRun() override;
#if defined(OS_MACOSX)
void PreMainMessageLoopStart() override;
void PostDestroyThreads() override;
#endif
private:
@ -56,6 +55,10 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
void HandleShutdownSignals();
#endif
#if defined(OS_MACOSX)
void FreeAppDelegate();
#endif
// A fake BrowserProcess object that used to feed the source code from chrome.
scoped_ptr<BrowserProcess> fake_browser_process_;

View file

@ -34,7 +34,7 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
}
void AtomBrowserMainParts::PostDestroyThreads() {
void AtomBrowserMainParts::FreeAppDelegate() {
[[NSApp delegate] release];
[NSApp setDelegate:nil];
}