1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/native_window_tracker_cocoa.h"
7 #import <AppKit/AppKit.h>
9 @interface BridgedNativeWindowTracker : NSObject {
14 - (id)initWithNSWindow:(NSWindow*)window;
15 - (bool)wasNSWindowClosed;
16 - (void)onWindowWillClose:(NSNotification*)notification;
20 @implementation BridgedNativeWindowTracker
22 - (id)initWithNSWindow:(NSWindow*)window {
24 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
25 [center addObserver:self
26 selector:@selector(onWindowWillClose:)
27 name:NSWindowWillCloseNotification
33 [[NSNotificationCenter defaultCenter] removeObserver:self];
37 - (bool)wasNSWindowClosed {
38 return window_ == nil;
41 - (void)onWindowWillClose:(NSNotification*)notification {
42 [[NSNotificationCenter defaultCenter]
44 name:NSWindowWillCloseNotification
51 NativeWindowTrackerCocoa::NativeWindowTrackerCocoa(gfx::NativeWindow window) {
52 bridge_.reset([[BridgedNativeWindowTracker alloc] initWithNSWindow:window]);
55 NativeWindowTrackerCocoa::~NativeWindowTrackerCocoa() {
58 bool NativeWindowTrackerCocoa::WasNativeWindowClosed() const {
59 return [bridge_ wasNSWindowClosed];
63 scoped_ptr<NativeWindowTracker> NativeWindowTracker::Create(
64 gfx::NativeWindow window) {
65 return scoped_ptr<NativeWindowTracker>(new NativeWindowTrackerCocoa(window));