Chromium Code Reviews| 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" | |
| 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" |
| 20 #include "extensions/browser/extension_registry.h" | |
| 16 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/l10n/l10n_util_mac.h" | 23 #include "ui/base/l10n/l10n_util_mac.h" |
| 19 | 24 |
| 25 using extensions::ExtensionRegistry; | |
| 26 | |
| 20 namespace { | 27 namespace { |
| 21 | 28 |
| 22 // Gets an item from the main menu given the tag of the top level item | 29 // 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|. | 30 // |menu_tag| and the tag of the item |item_tag|. |
| 24 NSMenuItem* GetItemByTag(NSInteger menu_tag, NSInteger item_tag) { | 31 NSMenuItem* GetItemByTag(NSInteger menu_tag, NSInteger item_tag) { |
| 25 return [[[[NSApp mainMenu] itemWithTag:menu_tag] submenu] | 32 return [[[[NSApp mainMenu] itemWithTag:menu_tag] submenu] |
| 26 itemWithTag:item_tag]; | 33 itemWithTag:item_tag]; |
| 27 } | 34 } |
| 28 | 35 |
| 29 // Finds a top level menu item using |menu_tag| and creates a new NSMenuItem | 36 // Finds a top level menu item using |menu_tag| and creates a new NSMenuItem |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 base::mac::ScopedNSAutoreleasePool pool; | 295 base::mac::ScopedNSAutoreleasePool pool; |
| 289 | 296 |
| 290 id window = [notification object]; | 297 id window = [notification object]; |
| 291 NSString* name = [notification name]; | 298 NSString* name = [notification name]; |
| 292 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { | 299 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { |
| 293 extensions::AppWindow* appWindow = | 300 extensions::AppWindow* appWindow = |
| 294 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 301 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 295 window); | 302 window); |
| 296 | 303 |
| 297 const extensions::Extension* extension = NULL; | 304 const extensions::Extension* extension = NULL; |
| 305 // Try and look if there is a relevant app window. Otherwise, look at the | |
|
jackhou1
2014/12/11 02:43:18
Maybe something like:
// If there is no correspon
mitchellj
2014/12/12 00:03:45
Acknowledged.
| |
| 306 // browser window | |
| 298 if (appWindow) | 307 if (appWindow) |
| 299 extension = appWindow->GetExtension(); | 308 extension = appWindow->GetExtension(); |
| 309 else { | |
| 310 Browser* browser = chrome::FindBrowserWithWindow(window); | |
| 311 if (browser && browser->is_app()) { | |
| 312 ExtensionRegistry* registry = | |
| 313 ExtensionRegistry::Get(browser->profile()); | |
| 314 const extensions::Extension* temp = registry->GetExtensionById( | |
| 315 web_app::GetExtensionIdFromApplicationName(browser->app_name()), | |
| 316 ExtensionRegistry::ENABLED); | |
| 317 if (temp->is_hosted_app()) | |
| 318 extension = temp; | |
| 319 } | |
| 320 } | |
| 300 | 321 |
| 301 if (extension) | 322 if (extension) |
| 302 [self addMenuItems:extension]; | 323 [self addMenuItems:extension]; |
| 303 else | 324 else |
| 304 [self removeMenuItems]; | 325 [self removeMenuItems]; |
| 305 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { | 326 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { |
| 306 // If there are any other windows that can become main, leave the menu. It | 327 // 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 | 328 // will be changed when another window becomes main. Otherwise, restore the |
| 308 // Chrome menu. | 329 // Chrome menu. |
| 309 for (NSWindow* w : [NSApp windows]) { | 330 for (NSWindow* w : [NSApp windows]) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 [hideDoppelganger_ disable]; | 388 [hideDoppelganger_ disable]; |
| 368 [quitDoppelganger_ disable]; | 389 [quitDoppelganger_ disable]; |
| 369 [newDoppelganger_ disable]; | 390 [newDoppelganger_ disable]; |
| 370 [openDoppelganger_ disable]; | 391 [openDoppelganger_ disable]; |
| 371 } | 392 } |
| 372 | 393 |
| 373 - (void)quitCurrentPlatformApp { | 394 - (void)quitCurrentPlatformApp { |
| 374 extensions::AppWindow* appWindow = | 395 extensions::AppWindow* appWindow = |
| 375 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 396 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 376 [NSApp keyWindow]); | 397 [NSApp keyWindow]); |
| 377 if (appWindow) | 398 if (appWindow) { |
| 378 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); | 399 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); |
| 400 } else { | |
| 401 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]); | |
| 402 if (browser && browser->is_app()) { | |
| 403 ExtensionRegistry* registry = ExtensionRegistry::Get(browser->profile()); | |
| 404 const extensions::Extension* extension = registry->GetExtensionById( | |
| 405 web_app::GetExtensionIdFromApplicationName(browser->app_name()), | |
| 406 ExtensionRegistry::ENABLED); | |
| 407 if (extension->is_hosted_app()) | |
| 408 apps::ExtensionAppShimHandler::QuitHostedAppForWindow(browser, | |
| 409 extension); | |
| 410 } | |
| 411 } | |
| 379 } | 412 } |
| 380 | 413 |
| 381 - (void)hideCurrentPlatformApp { | 414 - (void)hideCurrentPlatformApp { |
| 382 extensions::AppWindow* appWindow = | 415 extensions::AppWindow* appWindow = |
| 383 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 416 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 384 [NSApp keyWindow]); | 417 [NSApp keyWindow]); |
| 385 if (appWindow) | 418 if (appWindow) { |
| 386 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); | 419 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); |
| 420 } else { | |
| 421 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]); | |
| 422 if (browser && browser->is_app()) { | |
|
jackhou1
2014/12/11 02:43:18
This logic of "browser->is_app() && extension->is_
mitchellj
2014/12/12 00:03:45
Done.
| |
| 423 ExtensionRegistry* registry = ExtensionRegistry::Get(browser->profile()); | |
| 424 const extensions::Extension* extension = registry->GetExtensionById( | |
| 425 web_app::GetExtensionIdFromApplicationName(browser->app_name()), | |
| 426 ExtensionRegistry::ENABLED); | |
| 427 if (extension->is_hosted_app()) | |
| 428 apps::ExtensionAppShimHandler::HideHostedApp(browser->profile(), | |
| 429 extension->id()); | |
| 430 } | |
| 431 } | |
| 387 } | 432 } |
| 388 | 433 |
| 389 - (void)focusCurrentPlatformApp { | 434 - (void)focusCurrentPlatformApp { |
| 390 extensions::AppWindow* appWindow = | 435 extensions::AppWindow* appWindow = |
| 391 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( | 436 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( |
| 392 [NSApp keyWindow]); | 437 [NSApp keyWindow]); |
| 393 if (appWindow) | 438 if (appWindow) |
| 394 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); | 439 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); |
| 395 } | 440 } |
| 396 | 441 |
| 397 @end | 442 @end |
| OLD | NEW |