summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 01:07:32 +0000
committerandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 01:07:32 +0000
commitdd6ab128e8f9928a978d60d66ae8a46b2f8ff3d8 (patch)
treeeacd2b8cd9ed5c35c036ae6108c6b4b7fa725c79
parent3abf757860d29f2939b70b6ac862981169d61939 (diff)
downloadchromium_src-dd6ab128e8f9928a978d60d66ae8a46b2f8ff3d8.zip
chromium_src-dd6ab128e8f9928a978d60d66ae8a46b2f8ff3d8.tar.gz
chromium_src-dd6ab128e8f9928a978d60d66ae8a46b2f8ff3d8.tar.bz2
[Mac] Fix for a bug where extensions were not being notified when no window was in focus on the mac.
BUG=32932 TEST=check bug. Review URL: http://codereview.chromium.org/2847062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52981 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/app_controller_mac.mm22
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc9
-rw-r--r--chrome/common/notification_type.h5
3 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index e06cc60..6214edd 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -141,6 +141,7 @@ void RecordLastRunAppBundlePath() {
- (void)getUrl:(NSAppleEventDescriptor*)event
withReply:(NSAppleEventDescriptor*)reply;
- (void)windowLayeringDidChange:(NSNotification*)inNotification;
+- (void)checkForAnyKeyWindows;
- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
- (BOOL)shouldQuitWithInProgressDownloads;
- (void)showPreferencesWindow:(id)sender
@@ -398,6 +399,27 @@ void RecordLastRunAppBundlePath() {
// update the UI based on the new main window.
- (void)windowLayeringDidChange:(NSNotification*)notify {
[self delayedFixCloseMenuItemKeyEquivalents];
+
+ if ([notify name] == NSWindowDidResignKeyNotification) {
+ // If a window is closed, this notification is fired but |[NSApp keyWindow]|
+ // returns nil regardless of whether any suitable candidates for the key
+ // window remain. It seems that the new key window for the app is not set
+ // until after this notification is fired, so a check is performed after the
+ // run loop is allowed to spin.
+ [self performSelector:@selector(checkForAnyKeyWindows)
+ withObject:nil
+ afterDelay:0.0];
+ }
+}
+
+- (void)checkForAnyKeyWindows {
+ if ([NSApp keyWindow])
+ return;
+
+ NotificationService::current()->Notify(
+ NotificationType::NO_KEY_WINDOW,
+ NotificationService::AllSources(),
+ NotificationService::NoDetails());
}
// Called when the number of tabs changes in one of the browser windows. The
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 55cf6fd..62d1751 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -104,6 +104,11 @@ void ExtensionBrowserEventRouter::Init(Profile* profile) {
views::FocusManager::GetWidgetFocusManager()->AddFocusChangeListener(this);
#elif defined(TOOLKIT_GTK)
ActiveWindowWatcherX::AddObserver(this);
+#elif defined(OS_MACOSX)
+ // Needed for when no suitable window can be passed to an extension as the
+ // currently focused window.
+ registrar_.Add(this, NotificationType::NO_KEY_WINDOW,
+ NotificationService::AllSources());
#endif
// Init() can happen after the browser is running, so catch up with any
@@ -397,6 +402,10 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type,
} else if (type == NotificationType::BROWSER_WINDOW_READY) {
const Browser* browser = Source<const Browser>(source).ptr();
OnBrowserWindowReady(browser);
+#if defined(OS_MACOSX)
+ } else if (type == NotificationType::NO_KEY_WINDOW) {
+ OnBrowserSetLastActive(NULL);
+#endif
} else {
NOTREACHED();
}
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 19b0465..bf0d053 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -218,6 +218,11 @@ class NotificationType {
// This message is sent when the application is terminating (Mac OS X only
// at present). No source or details are passed.
APP_TERMINATING,
+
+ // This notification is sent when the app has no key window, such as when
+ // all windows are closed but the app is still active. No source or details
+ // are provided.
+ NO_KEY_WINDOW,
#endif
// This is sent when the user has chosen to exit the app, but before any