| Index: chrome/browser/ui/cocoa/native_window_deletion_observer_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/native_window_deletion_observer_cocoa.mm b/chrome/browser/ui/cocoa/native_window_deletion_observer_cocoa.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f566cd632cc2e2b15317b93c81ff9e168bf106b3
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/cocoa/native_window_deletion_observer_cocoa.mm
|
| @@ -0,0 +1,69 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/cocoa/native_window_deletion_observer_cocoa.h"
|
| +
|
| +#import <AppKit/AppKit.h>
|
| +
|
| +@interface BridgedNativeWindowDeletionObserver : NSObject {
|
| + @private
|
| + NSWindow* window_;
|
| +}
|
| +
|
| +- (id)initWithNSWindow:(NSWindow*)window;
|
| +- (bool)isNSWindowAlive;
|
| +- (void)onWindowWillClose:(NSNotification*)notification;
|
| +
|
| +@end
|
| +
|
| +@implementation BridgedNativeWindowDeletionObserver
|
| +
|
| +- (id)initWithNSWindow:(NSWindow*)window {
|
| + window_ = window;
|
| + NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
| + [center addObserver:self
|
| + selector:@selector(onWindowWillClose:)
|
| + name:NSWindowWillCloseNotification
|
| + object:window_];
|
| + return self;
|
| +}
|
| +
|
| +- (void)dealloc {
|
| + [[NSNotificationCenter defaultCenter] removeObserver:self];
|
| + [super dealloc];
|
| +}
|
| +
|
| +- (bool)isNSWindowAlive {
|
| + return window_;
|
| +}
|
| +
|
| +- (void)onWindowWillClose:(NSNotification*)notification {
|
| + [[NSNotificationCenter defaultCenter]
|
| + removeObserver:self
|
| + name:NSWindowWillCloseNotification
|
| + object:window_];
|
| + window_ = nil;
|
| +}
|
| +
|
| +@end
|
| +
|
| +NativeWindowDeletionObserverCocoa::NativeWindowDeletionObserverCocoa(
|
| + gfx::NativeWindow window) {
|
| + bridge_.reset([[BridgedNativeWindowDeletionObserver alloc]
|
| + initWithNSWindow:window]);
|
| +}
|
| +
|
| +NativeWindowDeletionObserverCocoa::~NativeWindowDeletionObserverCocoa() {
|
| +}
|
| +
|
| +bool NativeWindowDeletionObserverCocoa::IsNativeWindowAlive() const {
|
| + return [bridge_ isNSWindowAlive];
|
| +}
|
| +
|
| +// static
|
| +scoped_ptr<NativeWindowDeletionObserver> NativeWindowDeletionObserver::Create(
|
| + gfx::NativeWindow window) {
|
| + return scoped_ptr<NativeWindowDeletionObserver>(
|
| + new NativeWindowDeletionObserverCocoa(window));
|
| +}
|
|
|