Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / apps / app_shim_menu_controller_mac.mm
index b64b87d..971172c 100644 (file)
@@ -4,15 +4,16 @@
 
 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h"
 
-#include "apps/app_shim/extension_app_shim_handler_mac.h"
-#include "apps/shell_window.h"
-#include "apps/shell_window_registry.h"
+#include "base/mac/scoped_nsautorelease_pool.h"
 #include "base/strings/sys_string_conversions.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
+#include "chrome/browser/apps/app_window_registry_util.h"
 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
+#include "chrome/grit/generated_resources.h"
+#include "extensions/browser/app_window/app_window.h"
 #include "extensions/common/extension.h"
-#include "grit/generated_resources.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/l10n/l10n_util_mac.h"
 
@@ -277,14 +278,26 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
 }
 
 - (void)windowMainStatusChanged:(NSNotification*)notification {
+  // A Yosemite AppKit bug causes this notification to be sent during the
+  // -dealloc for a specific NSWindow. Any autoreleases sent to that window
+  // must be drained before the window finishes -dealloc. In this method, an
+  // autorelease is sent by the invocation of [NSApp windows].
+  // http://crbug.com/406944.
+  base::mac::ScopedNSAutoreleasePool pool;
+
   id window = [notification object];
   NSString* name = [notification name];
   if ([name isEqualToString:NSWindowDidBecomeMainNotification]) {
-    apps::ShellWindow* shellWindow =
-        apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
+    extensions::AppWindow* appWindow =
+        AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
             window);
-    if (shellWindow)
-      [self addMenuItems:shellWindow->extension()];
+
+    const extensions::Extension* extension = NULL;
+    if (appWindow)
+      extension = appWindow->GetExtension();
+
+    if (extension)
+      [self addMenuItems:extension];
     else
       [self removeMenuItems];
   } else if ([name isEqualToString:NSWindowWillCloseNotification]) {
@@ -356,27 +369,27 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
 }
 
 - (void)quitCurrentPlatformApp {
-  apps::ShellWindow* shellWindow =
-      apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
+  extensions::AppWindow* appWindow =
+      AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
           [NSApp keyWindow]);
-  if (shellWindow)
-    apps::ExtensionAppShimHandler::QuitAppForWindow(shellWindow);
+  if (appWindow)
+    apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow);
 }
 
 - (void)hideCurrentPlatformApp {
-  apps::ShellWindow* shellWindow =
-      apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
+  extensions::AppWindow* appWindow =
+      AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
           [NSApp keyWindow]);
-  if (shellWindow)
-    apps::ExtensionAppShimHandler::HideAppForWindow(shellWindow);
+  if (appWindow)
+    apps::ExtensionAppShimHandler::HideAppForWindow(appWindow);
 }
 
 - (void)focusCurrentPlatformApp {
-  apps::ShellWindow* shellWindow =
-      apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
+  extensions::AppWindow* appWindow =
+      AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
           [NSApp keyWindow]);
-  if (shellWindow)
-    apps::ExtensionAppShimHandler::FocusAppForWindow(shellWindow);
+  if (appWindow)
+    apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow);
 }
 
 @end