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 "apps/app_shim/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
8 #include "apps/shell_window.h" | 8 #include "apps/app_window.h" |
9 #include "apps/shell_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" | 13 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" |
14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
18 | 18 |
19 namespace { | 19 namespace { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 addObserver:self | 273 addObserver:self |
274 selector:@selector(windowMainStatusChanged:) | 274 selector:@selector(windowMainStatusChanged:) |
275 name:NSWindowWillCloseNotification | 275 name:NSWindowWillCloseNotification |
276 object:nil]; | 276 object:nil]; |
277 } | 277 } |
278 | 278 |
279 - (void)windowMainStatusChanged:(NSNotification*)notification { | 279 - (void)windowMainStatusChanged:(NSNotification*)notification { |
280 id window = [notification object]; | 280 id window = [notification object]; |
281 NSString* name = [notification name]; | 281 NSString* name = [notification name]; |
282 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { | 282 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { |
283 apps::ShellWindow* shellWindow = | 283 apps::AppWindow* appWindow = |
284 apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | 284 apps::AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile(window); |
285 window); | 285 if (appWindow) |
286 if (shellWindow) | 286 [self addMenuItems:appWindow->extension()]; |
287 [self addMenuItems:shellWindow->extension()]; | |
288 else | 287 else |
289 [self removeMenuItems]; | 288 [self removeMenuItems]; |
290 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { | 289 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { |
291 // If there are any other windows that can become main, leave the menu. It | 290 // If there are any other windows that can become main, leave the menu. It |
292 // will be changed when another window becomes main. Otherwise, restore the | 291 // will be changed when another window becomes main. Otherwise, restore the |
293 // Chrome menu. | 292 // Chrome menu. |
294 for (NSWindow* w : [NSApp windows]) { | 293 for (NSWindow* w : [NSApp windows]) { |
295 if ([w canBecomeMainWindow] && ![w isEqual:window]) | 294 if ([w canBecomeMainWindow] && ![w isEqual:window]) |
296 return; | 295 return; |
297 } | 296 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 [item setHidden:NO]; | 348 [item setHidden:NO]; |
350 | 349 |
351 [aboutDoppelganger_ disable]; | 350 [aboutDoppelganger_ disable]; |
352 [hideDoppelganger_ disable]; | 351 [hideDoppelganger_ disable]; |
353 [quitDoppelganger_ disable]; | 352 [quitDoppelganger_ disable]; |
354 [newDoppelganger_ disable]; | 353 [newDoppelganger_ disable]; |
355 [openDoppelganger_ disable]; | 354 [openDoppelganger_ disable]; |
356 } | 355 } |
357 | 356 |
358 - (void)quitCurrentPlatformApp { | 357 - (void)quitCurrentPlatformApp { |
359 apps::ShellWindow* shellWindow = | 358 apps::AppWindow* appWindow = |
360 apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | 359 apps::AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( |
361 [NSApp keyWindow]); | 360 [NSApp keyWindow]); |
362 if (shellWindow) | 361 if (appWindow) |
363 apps::ExtensionAppShimHandler::QuitAppForWindow(shellWindow); | 362 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); |
364 } | 363 } |
365 | 364 |
366 - (void)hideCurrentPlatformApp { | 365 - (void)hideCurrentPlatformApp { |
367 apps::ShellWindow* shellWindow = | 366 apps::AppWindow* appWindow = |
368 apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | 367 apps::AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( |
369 [NSApp keyWindow]); | 368 [NSApp keyWindow]); |
370 if (shellWindow) | 369 if (appWindow) |
371 apps::ExtensionAppShimHandler::HideAppForWindow(shellWindow); | 370 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); |
372 } | 371 } |
373 | 372 |
374 - (void)focusCurrentPlatformApp { | 373 - (void)focusCurrentPlatformApp { |
375 apps::ShellWindow* shellWindow = | 374 apps::AppWindow* appWindow = |
376 apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | 375 apps::AppWindowRegistry::GetAppWindowForNativeWindowAnyProfile( |
377 [NSApp keyWindow]); | 376 [NSApp keyWindow]); |
378 if (shellWindow) | 377 if (appWindow) |
379 apps::ExtensionAppShimHandler::FocusAppForWindow(shellWindow); | 378 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
380 } | 379 } |
381 | 380 |
382 @end | 381 @end |
OLD | NEW |