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

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: Refactored code and addressed comments 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"
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"
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
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 Browser* browser = chrome::FindBrowserWithWindow(window);
308 if (browser && browser->is_app()) {
309 const extensions::Extension* temp =
310 apps::ExtensionAppShimHandler::GetAppExtension(
jackhou1 2014/12/12 00:48:29 You can assign this directly to |extension|.
mitchellj 2014/12/12 03:46:23 Done.
311 browser->profile(), web_app::GetExtensionIdFromApplicationName(
312 browser->app_name()));
313 if (temp)
314 extension = temp;
315 }
316 }
300 317
301 if (extension) 318 if (extension)
302 [self addMenuItems:extension]; 319 [self addMenuItems:extension];
303 else 320 else
304 [self removeMenuItems]; 321 [self removeMenuItems];
305 } else if ([name isEqualToString:NSWindowWillCloseNotification]) { 322 } else if ([name isEqualToString:NSWindowWillCloseNotification]) {
306 // If there are any other windows that can become main, leave the menu. It 323 // 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 324 // will be changed when another window becomes main. Otherwise, restore the
308 // Chrome menu. 325 // Chrome menu.
309 for (NSWindow* w : [NSApp windows]) { 326 for (NSWindow* w : [NSApp windows]) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 [hideDoppelganger_ disable]; 384 [hideDoppelganger_ disable];
368 [quitDoppelganger_ disable]; 385 [quitDoppelganger_ disable];
369 [newDoppelganger_ disable]; 386 [newDoppelganger_ disable];
370 [openDoppelganger_ disable]; 387 [openDoppelganger_ disable];
371 } 388 }
372 389
373 - (void)quitCurrentPlatformApp { 390 - (void)quitCurrentPlatformApp {
374 extensions::AppWindow* appWindow = 391 extensions::AppWindow* appWindow =
375 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 392 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
376 [NSApp keyWindow]); 393 [NSApp keyWindow]);
377 if (appWindow) 394 if (appWindow) {
378 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow); 395 apps::ExtensionAppShimHandler::QuitAppForWindow(appWindow);
396 } else {
397 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]);
398 if (!browser || !browser->is_app())
jackhou1 2014/12/12 00:48:29 What do you think of adding something like const
mitchellj 2014/12/12 03:46:23 Done.
399 return;
400
401 const extensions::Extension* extension =
402 apps::ExtensionAppShimHandler::GetAppExtension(
403 browser->profile(),
404 web_app::GetExtensionIdFromApplicationName(browser->app_name()));
405 if (extension)
406 apps::ExtensionAppShimHandler::QuitHostedAppForWindow(browser, extension);
407 }
379 } 408 }
380 409
381 - (void)hideCurrentPlatformApp { 410 - (void)hideCurrentPlatformApp {
382 extensions::AppWindow* appWindow = 411 extensions::AppWindow* appWindow =
383 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 412 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
384 [NSApp keyWindow]); 413 [NSApp keyWindow]);
385 if (appWindow) 414 if (appWindow) {
386 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow); 415 apps::ExtensionAppShimHandler::HideAppForWindow(appWindow);
416 } else {
417 Browser* browser = chrome::FindBrowserWithWindow([NSApp keyWindow]);
418 if (!browser || !browser->is_app())
419 return;
420
421 const extensions::Extension* extension =
422 apps::ExtensionAppShimHandler::GetAppExtension(
423 browser->profile(),
424 web_app::GetExtensionIdFromApplicationName(browser->app_name()));
425 if (extension)
426 apps::ExtensionAppShimHandler::HideHostedApp(browser->profile(),
427 extension->id());
428 }
387 } 429 }
388 430
389 - (void)focusCurrentPlatformApp { 431 - (void)focusCurrentPlatformApp {
390 extensions::AppWindow* appWindow = 432 extensions::AppWindow* appWindow =
391 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile( 433 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(
392 [NSApp keyWindow]); 434 [NSApp keyWindow]);
393 if (appWindow) 435 if (appWindow)
394 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow); 436 apps::ExtensionAppShimHandler::FocusAppForWindow(appWindow);
395 } 437 }
396 438
397 @end 439 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698