diff options
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 22 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.cc | 9 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 5 |
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 |