mac: Don't rely on autorelease to delete window delegate
When quiting while closing window, it will leave the window delegate out of the autorelease pool and crash. Fixes #881.
This commit is contained in:
parent
9f9f772ff5
commit
62f9c3def0
2 changed files with 12 additions and 13 deletions
|
@ -14,6 +14,8 @@
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
|
|
||||||
|
@class AtomNSWindow;
|
||||||
|
@class AtomNSWindowDelegate;
|
||||||
@class FullSizeContentView;
|
@class FullSizeContentView;
|
||||||
class SkRegion;
|
class SkRegion;
|
||||||
|
|
||||||
|
@ -102,7 +104,8 @@ class NativeWindowMac : public NativeWindow {
|
||||||
// whehter we can drag.
|
// whehter we can drag.
|
||||||
void InstallDraggableRegionView();
|
void InstallDraggableRegionView();
|
||||||
|
|
||||||
base::scoped_nsobject<NSWindow> window_;
|
base::scoped_nsobject<AtomNSWindow> window_;
|
||||||
|
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||||
|
|
||||||
// The view that will fill the whole frameless window.
|
// The view that will fill the whole frameless window.
|
||||||
base::scoped_nsobject<FullSizeContentView> content_view_;
|
base::scoped_nsobject<FullSizeContentView> content_view_;
|
||||||
|
|
|
@ -140,7 +140,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
|
|
||||||
- (void)windowWillClose:(NSNotification*)notification {
|
- (void)windowWillClose:(NSNotification*)notification {
|
||||||
shell_->NotifyWindowClosed();
|
shell_->NotifyWindowClosed();
|
||||||
[self autorelease];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)windowShouldClose:(id)window {
|
- (BOOL)windowShouldClose:(id)window {
|
||||||
|
@ -323,21 +322,18 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||||
width,
|
width,
|
||||||
height);
|
height);
|
||||||
|
|
||||||
AtomNSWindow* atomWindow = [[AtomNSWindow alloc]
|
window_.reset([[AtomNSWindow alloc]
|
||||||
initWithContentRect:cocoa_bounds
|
initWithContentRect:cocoa_bounds
|
||||||
styleMask:NSTitledWindowMask | NSClosableWindowMask |
|
styleMask:NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
NSMiniaturizableWindowMask | NSResizableWindowMask |
|
||||||
NSTexturedBackgroundWindowMask
|
NSTexturedBackgroundWindowMask
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:YES];
|
defer:YES]);
|
||||||
|
[window_ setShell:this];
|
||||||
|
[window_ setEnableLargerThanScreen:enable_larger_than_screen_];
|
||||||
|
|
||||||
[atomWindow setShell:this];
|
window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]);
|
||||||
[atomWindow setEnableLargerThanScreen:enable_larger_than_screen_];
|
[window_ setDelegate:window_delegate_];
|
||||||
window_.reset(atomWindow);
|
|
||||||
|
|
||||||
AtomNSWindowDelegate* delegate =
|
|
||||||
[[AtomNSWindowDelegate alloc] initWithShell:this];
|
|
||||||
[window_ setDelegate:delegate];
|
|
||||||
|
|
||||||
if (transparent_) {
|
if (transparent_) {
|
||||||
// Make window has transparent background.
|
// Make window has transparent background.
|
||||||
|
@ -358,7 +354,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||||
// Enable the NSView to accept first mouse event.
|
// Enable the NSView to accept first mouse event.
|
||||||
bool acceptsFirstMouse = false;
|
bool acceptsFirstMouse = false;
|
||||||
options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
|
options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
|
||||||
[delegate setAcceptsFirstMouse:acceptsFirstMouse];
|
[window_delegate_ setAcceptsFirstMouse:acceptsFirstMouse];
|
||||||
|
|
||||||
// Disable fullscreen button when 'fullscreen' is specified to false.
|
// Disable fullscreen button when 'fullscreen' is specified to false.
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
|
@ -743,7 +739,7 @@ void NativeWindowMac::HandleKeyboardEvent(
|
||||||
event.type == content::NativeWebKeyboardEvent::Char)
|
event.type == content::NativeWebKeyboardEvent::Char)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.os_event.window == window_) {
|
if (event.os_event.window == window_.get()) {
|
||||||
EventProcessingWindow* event_window =
|
EventProcessingWindow* event_window =
|
||||||
static_cast<EventProcessingWindow*>(window_);
|
static_cast<EventProcessingWindow*>(window_);
|
||||||
DCHECK([event_window isKindOfClass:[EventProcessingWindow class]]);
|
DCHECK([event_window isKindOfClass:[EventProcessingWindow class]]);
|
||||||
|
|
Loading…
Reference in a new issue