Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm

Issue 790043002: Hosted apps on OS X now act more like a native app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@creating-app-shims-2
Patch Set: Added comments and refactored app_controller_mac Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
15 #include "extensions/browser/app_window/app_window.h" 18 #include "extensions/browser/app_window/app_window.h"
16 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
17 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/l10n/l10n_util_mac.h" 21 #include "ui/base/l10n/l10n_util_mac.h"
19 22
20 namespace { 23 namespace {
21 24
22 // Gets an item from the main menu given the tag of the top level item 25 // 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|. 26 // |menu_tag| and the tag of the item |item_tag|.
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 base::mac::ScopedNSAutoreleasePool pool; 291 base::mac::ScopedNSAutoreleasePool pool;
289 292
290 id window = [notification object]; 293 id window = [notification object];
291 NSString* name = [notification name]; 294 NSString* name = [notification name];
292 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) { 295 if ([name isEqualToString:NSWindowDidBecomeMainNotification]) {
293 extensions::AppWindow* appWindow = 296 extensions::AppWindow* appWindow =
294 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 297 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
295 window); 298 window);
296 299
297 const extensions::Extension* extension = NULL; 300 const extensions::Extension* extension = NULL;
301 // If there is no corresponding AppWindow, this could be a hosted app, so
302 // check for a browser.
298 if (appWindow) 303 if (appWindow)
299 extension = appWindow->GetExtension(); 304 extension = appWindow->GetExtension();
305 else
306 extension = apps::ExtensionAppShimHandler::GetAppForBrowser(
307 chrome::FindBrowserWithWindow(window));
300 308
301 if (extension) 309 if (extension)
302 [self addMenuItems:extension]; 310 [self addMenuItems:extension];
303 else 311 else
304 [self removeMenuItems]; 312 [self removeMenuItems];
305 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { 313 } else if ([name isEqualToString:NSWindowWillCloseNotification]) {
306 // If there are any other windows that can become main, leave the menu. It 314 // 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 315 // will be changed when another window becomes main. Otherwise, restore the
308 // Chrome menu. 316 // Chrome menu.
309 for (NSWindow* w : [NSApp windows]) { 317 for (NSWindow* w : [NSApp windows]) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 [hideDoppelganger_ disable]; 375 [hideDoppelganger_ disable];
368 [quitDoppelganger_ disable]; 376 [quitDoppelganger_ disable];
369 [newDoppelganger_ disable]; 377 [newDoppelganger_ disable];
370 [openDoppelganger_ disable]; 378 [openDoppelganger_ disable];
371 } 379 }
372 380
373 - (void)quitCurrentPlatformApp { 381 - (void)quitCurrentPlatformApp {
374 extensions::AppWindow* appWindow = 382 extensions::AppWindow* appWindow =
375 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 383 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
376 [NSApp keyWindow]); 384 [NSApp keyWindow]);
377 if (appWindow) 385 if (appWindow) {
378 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); 386 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow);
387 } else {
388 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]);
389 const extensions::Extension* extension =
390 apps::ExtensionAppShimHandler::GetAppForBrowser(browser);
391 if (extension)
392 apps::ExtensionAppShimHandler::QuitHostedAppForWindow(browser->profile(),
393 extension->id());
394 }
379 } 395 }
380 396
381 - (void)hideCurrentPlatformApp { 397 - (void)hideCurrentPlatformApp {
382 extensions::AppWindow* appWindow = 398 extensions::AppWindow* appWindow =
383 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 399 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
384 [NSApp keyWindow]); 400 [NSApp keyWindow]);
385 if (appWindow) 401 if (appWindow) {
386 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); 402 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow);
403 } else {
404 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]);
405 const extensions::Extension* extension =
406 apps::ExtensionAppShimHandler::GetAppForBrowser(browser);
407 if (extension)
408 apps::ExtensionAppShimHandler::HideHostedApp(browser->profile(),
409 extension->id());
410 }
387 } 411 }
388 412
389 - (void)focusCurrentPlatformApp { 413 - (void)focusCurrentPlatformApp {
390 extensions::AppWindow* appWindow = 414 extensions::AppWindow* appWindow =
391 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 415 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
392 [NSApp keyWindow]); 416 [NSApp keyWindow]);
393 if (appWindow) 417 if (appWindow)
394 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); 418 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow);
395 } 419 }
396 420
397 @end 421 @end
OLDNEW
« no previous file with comments | « chrome/browser/apps/app_shim/extension_app_shim_handler_mac.cc ('k') | chrome/browser/ui/cocoa/browser_window_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698