Closing a window requires closing web contents now.

In this way, we can prevent the close of window by using beforeunload
handler.
This commit is contained in:
Cheng Zhao 2013-05-01 15:42:30 +08:00
parent 31d6be0e63
commit 9f1fe4d2c2
4 changed files with 91 additions and 3 deletions

View file

@ -21,6 +21,34 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
@interface AtomNSWindowDelegate : NSObject<NSWindowDelegate> {
@private
atom::NativeWindowMac* shell_;
}
- (id)initWithShell:(atom::NativeWindowMac*)shell;
@end
@implementation AtomNSWindowDelegate
- (id)initWithShell:(atom::NativeWindowMac*)shell {
if ((self = [super init]))
shell_ = shell;
return self;
}
- (BOOL)windowShouldClose:(id)window {
if (!shell_->CanClose()) {
shell_->RequestToDestroyWindow();
return NO;
}
[self release];
return YES;
}
@end
@interface AtomNSWindow : AtomEventProcessingWindow {
@private
atom::NativeWindowMac* shell_;
@ -70,6 +98,8 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
[atom_window setShell:this];
window_ = atom_window;
[window() setReleasedWhenClosed:NO];
[window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]];
// Disable fullscreen button when 'fullscreen' is specified to false.
bool fullscreen;
@ -84,7 +114,6 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
}
NativeWindowMac::~NativeWindowMac() {
Close();
[window() release];
}