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" |
11 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" | 11 #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" |
12 #include "chrome/browser/apps/app_window_registry_util.h" | 12 #include "chrome/browser/apps/app_window_registry_util.h" |
13 #include "chrome/browser/profiles/profile.h" | |
13 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" | 14 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" |
15 #include "chrome/browser/ui/browser.h" | |
16 #include "chrome/browser/ui/browser_finder.h" | |
17 #include "chrome/browser/web_applications/web_app_mac.h" | |
jackhou1
2014/12/12 04:42:49
No need for web_app_mac.h any more.
mitchellj
2014/12/14 22:28:57
Done.
| |
14 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
15 #include "extensions/browser/app_window/app_window.h" | 19 #include "extensions/browser/app_window/app_window.h" |
16 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
17 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/l10n/l10n_util_mac.h" | 22 #include "ui/base/l10n/l10n_util_mac.h" |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // Gets an item from the main menu given the tag of the top level item | 26 // Gets an item from the main menu given the tag of the top level item |
23 // |menu_tag| and the tag of the item |item_tag|. | 27 // |menu_tag| and the tag of the item |item_tag|. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 base::mac::ScopedNSAutoreleasePool pool; | 292 base::mac::ScopedNSAutoreleasePool pool; |
289 | 293 |
290 id window = [notification object]; | 294 id window = [notification object]; |
291 NSString* name = [notification name]; | 295 NSString* name = [notification name]; |
292 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { | 296 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { |
293 extensions::AppWindow* appWindow = | 297 extensions::AppWindow* appWindow = |
294 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 298 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
295 window); | 299 window); |
296 | 300 |
297 const extensions::Extension* extension = NULL; | 301 const extensions::Extension* extension = NULL; |
302 // If there is no corresponding AppWindow, this could be a hosted app, so | |
303 // check for a browser. | |
298 if (appWindow) | 304 if (appWindow) |
299 extension = appWindow->GetExtension(); | 305 extension = appWindow->GetExtension(); |
306 else | |
307 extension = apps::ExtensionAppShimHandler::GetAppForBrowser( | |
308 chrome::FindBrowserWithWindow(window)); | |
300 | 309 |
301 if (extension) | 310 if (extension) |
302 [self addMenuItems:extension]; | 311 [self addMenuItems:extension]; |
303 else | 312 else |
304 [self removeMenuItems]; | 313 [self removeMenuItems]; |
305 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { | 314 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { |
306 // If there are any other windows that can become main, leave the menu. It | 315 // If there are any other windows that can become main, leave the menu. It |
307 // will be changed when another window becomes main. Otherwise, restore the | 316 // will be changed when another window becomes main. Otherwise, restore the |
308 // Chrome menu. | 317 // Chrome menu. |
309 for (NSWindow* w : [NSApp windows]) { | 318 for (NSWindow* w : [NSApp windows]) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 [hideDoppelganger_ disable]; | 376 [hideDoppelganger_ disable]; |
368 [quitDoppelganger_ disable]; | 377 [quitDoppelganger_ disable]; |
369 [newDoppelganger_ disable]; | 378 [newDoppelganger_ disable]; |
370 [openDoppelganger_ disable]; | 379 [openDoppelganger_ disable]; |
371 } | 380 } |
372 | 381 |
373 - (void)quitCurrentPlatformApp { | 382 - (void)quitCurrentPlatformApp { |
374 extensions::AppWindow* appWindow = | 383 extensions::AppWindow* appWindow = |
375 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 384 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
376 [NSApp keyWindow]); | 385 [NSApp keyWindow]); |
377 if (appWindow) | 386 if (appWindow) { |
378 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); | 387 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); |
388 } else { | |
389 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]); | |
390 const extensions::Extension* extension = | |
391 apps::ExtensionAppShimHandler::GetAppForBrowser(browser); | |
392 if (extension) | |
393 apps::ExtensionAppShimHandler::QuitHostedAppForWindow(browser->profile(), | |
394 extension->id()); | |
395 } | |
379 } | 396 } |
380 | 397 |
381 - (void)hideCurrentPlatformApp { | 398 - (void)hideCurrentPlatformApp { |
382 extensions::AppWindow* appWindow = | 399 extensions::AppWindow* appWindow = |
383 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 400 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
384 [NSApp keyWindow]); | 401 [NSApp keyWindow]); |
385 if (appWindow) | 402 if (appWindow) { |
386 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); | 403 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); |
404 } else { | |
405 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]); | |
406 const extensions::Extension* extension = | |
407 apps::ExtensionAppShimHandler::GetAppForBrowser(browser); | |
408 if (extension) | |
409 apps::ExtensionAppShimHandler::HideHostedApp(browser->profile(), | |
410 extension->id()); | |
411 } | |
387 } | 412 } |
388 | 413 |
389 - (void)focusCurrentPlatformApp { | 414 - (void)focusCurrentPlatformApp { |
390 extensions::AppWindow* appWindow = | 415 extensions::AppWindow* appWindow = |
391 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 416 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
392 [NSApp keyWindow]); | 417 [NSApp keyWindow]); |
393 if (appWindow) | 418 if (appWindow) |
394 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); | 419 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
395 } | 420 } |
396 | 421 |
397 @end | 422 @end |
OLD | NEW |