diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-11 23:30:20 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-11 23:30:20 +0000 |
commit | 27880fce23eeb00b6c60ca36dfd91aa39f606b1b (patch) | |
tree | 1c72564399a8815db6f86e81866b993e5713414d /chrome/browser/cocoa/info_bubble_window.mm | |
parent | 407de99c16b61413193265bf09bb01b87081596b (diff) | |
download | chromium_src-27880fce23eeb00b6c60ca36dfd91aa39f606b1b.zip chromium_src-27880fce23eeb00b6c60ca36dfd91aa39f606b1b.tar.gz chromium_src-27880fce23eeb00b6c60ca36dfd91aa39f606b1b.tar.bz2 |
[Mac] Properly cleans up any open info bubble popup windows upon app shutdown.
BUG=37717
TEST=none
Review URL: http://codereview.chromium.org/863005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/info_bubble_window.mm')
-rw-r--r-- | chrome/browser/cocoa/info_bubble_window.mm | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/chrome/browser/cocoa/info_bubble_window.mm b/chrome/browser/cocoa/info_bubble_window.mm index d803ad5..0a65367 100644 --- a/chrome/browser/cocoa/info_bubble_window.mm +++ b/chrome/browser/cocoa/info_bubble_window.mm @@ -4,8 +4,13 @@ #import "chrome/browser/cocoa/info_bubble_window.h" +#include "base/basictypes.h" #include "base/logging.h" #include "base/scoped_nsobject.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/notification_type.h" #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" namespace { @@ -24,6 +29,37 @@ const NSTimeInterval kMinimumTimeInterval = - (void)finishCloseAfterAnimation; @end +// A helper class to proxy app notifications to the window. +class AppNotificationBridge : public NotificationObserver { + public: + explicit AppNotificationBridge(InfoBubbleWindow* owner) : owner_(owner) { + registrar_.Add(this, NotificationType::APP_TERMINATING, + NotificationService::AllSources()); + } + + // Overridden from NotificationObserver. + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::APP_TERMINATING: + [owner_ appIsTerminating]; + break; + default: + NOTREACHED() << L"Unexpected notification"; + } + } + + private: + // The object we need to inform when we get a notification. Weak. Owns us. + InfoBubbleWindow* owner_; + + // Used for registering to receive notifications and automatic clean up. + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(AppNotificationBridge); +}; + // A delegate object for watching the alphaValue animation on InfoBubbleWindows. // An InfoBubbleWindow instance cannot be the delegate for its own animation // because CAAnimations retain their delegates, and since the InfoBubbleWindow @@ -72,6 +108,7 @@ const NSTimeInterval kMinimumTimeInterval = [self setOpaque:NO]; [self setHasShadow:YES]; delayOnClose_ = YES; + notificationBridge_.reset(new AppNotificationBridge(self)); // Start invisible. Will be made visible when ordered front. [self setAlphaValue:0.0]; @@ -89,21 +126,10 @@ const NSTimeInterval kMinimumTimeInterval = [NSMutableDictionary dictionaryWithDictionary:[self animations]]; [animations setObject:alphaAnimation forKey:@"alphaValue"]; [self setAnimations:animations]; - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(appIsTerminating) - name:NSApplicationWillTerminateNotification - object:[NSApplication sharedApplication]]; } return self; } -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - // According to // http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953, // NSBorderlessWindowMask windows cannot become key or main. In this |