| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" | 5 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 366 } |
| 367 | 367 |
| 368 - (void)windowMainStatusChanged:(NSNotification*)notification { | 368 - (void)windowMainStatusChanged:(NSNotification*)notification { |
| 369 // A Yosemite AppKit bug causes this notification to be sent during the | 369 // A Yosemite AppKit bug causes this notification to be sent during the |
| 370 // -dealloc for a specific NSWindow. Any autoreleases sent to that window | 370 // -dealloc for a specific NSWindow. Any autoreleases sent to that window |
| 371 // must be drained before the window finishes -dealloc. In this method, an | 371 // must be drained before the window finishes -dealloc. In this method, an |
| 372 // autorelease is sent by the invocation of [NSApp windows]. | 372 // autorelease is sent by the invocation of [NSApp windows]. |
| 373 // http://crbug.com/406944. | 373 // http://crbug.com/406944. |
| 374 base::mac::ScopedNSAutoreleasePool pool; | 374 base::mac::ScopedNSAutoreleasePool pool; |
| 375 | 375 |
| 376 id window = [notification object]; | |
| 377 NSString* name = [notification name]; | 376 NSString* name = [notification name]; |
| 378 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { | 377 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { |
| 378 id window = [notification object]; |
| 379 extensions::AppWindow* appWindow = | 379 extensions::AppWindow* appWindow = |
| 380 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 380 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 381 window); | 381 window); |
| 382 | 382 |
| 383 const extensions::Extension* extension = NULL; | 383 const extensions::Extension* extension = NULL; |
| 384 // If there is no corresponding AppWindow, this could be a hosted app, so | 384 // If there is no corresponding AppWindow, this could be a hosted app, so |
| 385 // check for a browser. | 385 // check for a browser. |
| 386 if (appWindow) | 386 if (appWindow) |
| 387 extension = appWindow->GetExtension(); | 387 extension = appWindow->GetExtension(); |
| 388 else | 388 else |
| 389 extension = apps::ExtensionAppShimHandler::GetAppForBrowser( | 389 extension = apps::ExtensionAppShimHandler::GetAppForBrowser( |
| 390 chrome::FindBrowserWithWindow(window)); | 390 chrome::FindBrowserWithWindow(window)); |
| 391 | 391 |
| 392 if (extension) | 392 if (extension) |
| 393 [self addMenuItems:extension]; | 393 [self addMenuItems:extension]; |
| 394 else | 394 else |
| 395 [self removeMenuItems]; | 395 [self removeMenuItems]; |
| 396 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { | 396 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { |
| 397 // If there are any other windows that can become main, leave the menu. It | 397 // Always reset back to the Chrome menu. This once scanned [NSApp windows] |
| 398 // will be changed when another window becomes main. Otherwise, restore the | 398 // to predict whether we could expect another Chrome window to become main, |
| 399 // Chrome menu. | 399 // and skip the reset. However, panels need to do strange things during |
| 400 for (NSWindow* w : [NSApp windows]) { | 400 // window close to ensure panels never get chosen for key status over a |
| 401 if ([w canBecomeMainWindow] && ![w isEqual:window] && [w isOnActiveSpace]) | 401 // browser window (which is likely because they are given an elevated |
| 402 return; | 402 // [NSWindow level]). Trying to handle this case is not robust. |
| 403 } | 403 // Unfortunately, resetting the menu to Chrome unconditionally means that |
| 404 | 404 // if another packaged app window becomes key, the menu will flicker. |
| 405 // TODO(tapted): Investigate restoring the logic when the panel code is |
| 406 // removed. |
| 405 [self removeMenuItems]; | 407 [self removeMenuItems]; |
| 406 } else { | 408 } else { |
| 407 NOTREACHED(); | 409 NOTREACHED(); |
| 408 } | 410 } |
| 409 } | 411 } |
| 410 | 412 |
| 411 - (void)addMenuItems:(const extensions::Extension*)app { | 413 - (void)addMenuItems:(const extensions::Extension*)app { |
| 412 NSString* appId = base::SysUTF8ToNSString(app->id()); | 414 NSString* appId = base::SysUTF8ToNSString(app->id()); |
| 413 NSString* title = base::SysUTF8ToNSString(app->name()); | 415 NSString* title = base::SysUTF8ToNSString(app->name()); |
| 414 | 416 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 514 |
| 513 - (void)focusCurrentPlatformApp { | 515 - (void)focusCurrentPlatformApp { |
| 514 extensions::AppWindow* appWindow = | 516 extensions::AppWindow* appWindow = |
| 515 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 517 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 516 [NSApp keyWindow]); | 518 [NSApp keyWindow]); |
| 517 if (appWindow) | 519 if (appWindow) |
| 518 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); | 520 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
| 519 } | 521 } |
| 520 | 522 |
| 521 @end | 523 @end |
| OLD | NEW |