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

Side by Side Diff: chrome/browser/ui/app_list/app_list_service_mac.mm

Issue 782673002: MacViews: tryjobs for toolkit_views=1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 months 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/app_list/app_list_service_mac.h" 5 #import "chrome/browser/ui/app_list/app_list_service_mac.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #import "chrome/browser/app_controller_mac.h" 17 #import "chrome/browser/app_controller_mac.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/profiles/profile_info_cache.h" 20 #include "chrome/browser/profiles/profile_info_cache.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/app_list/app_list_controller_delegate_impl.h"
23 #include "chrome/browser/ui/app_list/app_list_positioner.h" 22 #include "chrome/browser/ui/app_list/app_list_positioner.h"
24 #include "chrome/browser/ui/app_list/app_list_service.h" 23 #include "chrome/browser/ui/app_list/app_list_service.h"
24 #include "chrome/browser/ui/app_list/app_list_service_cocoa_mac.h"
25 #include "chrome/browser/ui/app_list/app_list_service_impl.h" 25 #include "chrome/browser/ui/app_list/app_list_service_impl.h"
26 #include "chrome/browser/ui/app_list/app_list_util.h" 26 #include "chrome/browser/ui/app_list/app_list_util.h"
27 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
28 #include "chrome/browser/ui/browser_commands.h" 27 #include "chrome/browser/ui/browser_commands.h"
29 #include "chrome/browser/ui/extensions/application_launch.h" 28 #include "chrome/browser/ui/extensions/application_launch.h"
30 #include "chrome/browser/web_applications/web_app.h" 29 #include "chrome/browser/web_applications/web_app.h"
31 #include "chrome/browser/web_applications/web_app_mac.h" 30 #include "chrome/browser/web_applications/web_app_mac.h"
32 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/chrome_version_info.h" 32 #include "chrome/common/chrome_version_info.h"
34 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 33 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
35 #include "chrome/common/mac/app_mode_common.h" 34 #include "chrome/common/mac/app_mode_common.h"
36 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
37 #include "chrome/grit/google_chrome_strings.h" 36 #include "chrome/grit/google_chrome_strings.h"
38 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
39 #include "extensions/browser/extension_system.h" 38 #include "extensions/browser/extension_system.h"
40 #include "extensions/common/manifest_handlers/file_handler_info.h" 39 #include "extensions/common/manifest_handlers/file_handler_info.h"
41 #include "grit/chrome_unscaled_resources.h" 40 #include "grit/chrome_unscaled_resources.h"
42 #include "net/base/url_util.h" 41 #include "net/base/url_util.h"
43 #import "ui/app_list/cocoa/app_list_view_controller.h" 42 #include "ui/app_list/app_list_switches.h"
44 #import "ui/app_list/cocoa/app_list_window_controller.h"
45 #include "ui/app_list/search_box_model.h" 43 #include "ui/app_list/search_box_model.h"
46 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
48 #include "ui/gfx/display.h" 46 #include "ui/gfx/display.h"
49 #include "ui/gfx/screen.h" 47 #include "ui/gfx/screen.h"
50 48
49 #if defined(TOOLKIT_VIEWS)
50 #include "chrome/browser/ui/app_list/app_list_service_views_mac.h"
51 #endif
52
51 namespace gfx { 53 namespace gfx {
52 class ImageSkia; 54 class ImageSkia;
53 } 55 }
54 56
55 // Controller for animations that show or hide the app list. 57 // Controller for animations that show or hide the app list.
56 @interface AppListAnimationController : NSObject<NSAnimationDelegate> { 58 @interface AppListAnimationController : NSObject<NSAnimationDelegate> {
57 @private 59 @private
58 // When closing, the window to close. Retained until the animation ends. 60 // When closing, the window to close. Retained until the animation ends.
59 base::scoped_nsobject<NSWindow> window_; 61 base::scoped_nsobject<NSWindow> window_;
60 // The animation started and owned by |self|. Reset when the animation ends. 62 // The animation started and owned by |self|. Reset when the animation ends.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]); 255 NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]);
254 AppListServiceMac::FindAnchorPoint(window_size, 256 AppListServiceMac::FindAnchorPoint(window_size,
255 display, 257 display,
256 primary_display_height, 258 primary_display_height,
257 cursor_is_visible, 259 cursor_is_visible,
258 cursor, 260 cursor,
259 target_origin, 261 target_origin,
260 start_origin); 262 start_origin);
261 } 263 }
262 264
265 AppListServiceMac* GetActiveInstance() {
266 if (app_list::switches::IsMacViewsAppListListEnabled()) {
267 #if defined(TOOLKIT_VIEWS)
268 return AppListServiceViewsMac::GetInstance();
269 #else
270 NOTREACHED();
271 #endif
272 }
273 return AppListServiceCocoaMac::GetInstance();
274 }
275
263 } // namespace 276 } // namespace
264 277
265 AppListServiceMac::AppListServiceMac() 278 AppListServiceMac::AppListServiceMac() {
266 : profile_(NULL),
267 controller_delegate_(new AppListControllerDelegateImpl(this)) {
268 animation_controller_.reset([[AppListAnimationController alloc] init]); 279 animation_controller_.reset([[AppListAnimationController alloc] init]);
269 } 280 }
270 281
271 AppListServiceMac::~AppListServiceMac() {} 282 AppListServiceMac::~AppListServiceMac() {}
272 283
273 // static 284 // static
274 AppListServiceMac* AppListServiceMac::GetInstance() {
275 return Singleton<AppListServiceMac,
276 LeakySingletonTraits<AppListServiceMac> >::get();
277 }
278
279 // static
280 void AppListServiceMac::FindAnchorPoint(const gfx::Size& window_size, 285 void AppListServiceMac::FindAnchorPoint(const gfx::Size& window_size,
281 const gfx::Display& display, 286 const gfx::Display& display,
282 int primary_display_height, 287 int primary_display_height,
283 bool cursor_is_visible, 288 bool cursor_is_visible,
284 const gfx::Point& cursor, 289 const gfx::Point& cursor,
285 NSPoint* target_origin, 290 NSPoint* target_origin,
286 NSPoint* start_origin) { 291 NSPoint* start_origin) {
287 AppListPositioner positioner(display, window_size, 0); 292 AppListPositioner positioner(display, window_size, 0);
288 AppListPositioner::ScreenEdge dock_location = DockLocationInDisplay(display); 293 AppListPositioner::ScreenEdge dock_location = DockLocationInDisplay(display);
289 294
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (kShortcutVersion > installed_shortcut_version) 367 if (kShortcutVersion > installed_shortcut_version)
363 CreateShortcut(); 368 CreateShortcut();
364 } 369 }
365 } 370 }
366 371
367 static bool init_called = false; 372 static bool init_called = false;
368 if (init_called) 373 if (init_called)
369 return; 374 return;
370 375
371 init_called = true; 376 init_called = true;
372 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, 377 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, this);
373 AppListServiceMac::GetInstance());
374 378
375 // Handle the case where Chrome was not running and was started with the app 379 // Handle the case where Chrome was not running and was started with the app
376 // launcher shim. The profile has not yet been loaded. To improve response 380 // launcher shim. The profile has not yet been loaded. To improve response
377 // times, start animating an empty window which will be populated via 381 // times, start animating an empty window which will be populated via
378 // OnShimLaunch(). Note that if --silent-launch is not also passed, the window 382 // OnShimLaunch(). Note that if --silent-launch is not also passed, the window
379 // will instead populate via StartupBrowserCreator::Launch(). Shim-initiated 383 // will instead populate via StartupBrowserCreator::Launch(). Shim-initiated
380 // launches will always have --silent-launch. 384 // launches will always have --silent-launch.
381 if (base::CommandLine::ForCurrentProcess()-> 385 if (base::CommandLine::ForCurrentProcess()->
382 HasSwitch(switches::kShowAppList)) { 386 HasSwitch(switches::kShowAppList)) {
383 // Do not show the launcher window when the profile is locked. 387 // Do not show the launcher window when the profile is locked.
384 const ProfileInfoCache& profile_info_cache = 388 const ProfileInfoCache& profile_info_cache =
385 g_browser_process->profile_manager()->GetProfileInfoCache(); 389 g_browser_process->profile_manager()->GetProfileInfoCache();
386 size_t profile_index = profile_info_cache. 390 size_t profile_index = profile_info_cache.
387 GetIndexOfProfileWithPath(profile_path); 391 GetIndexOfProfileWithPath(profile_path);
388 if (profile_index != std::string::npos && 392 if (profile_index != std::string::npos &&
389 !profile_info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) 393 !profile_info_cache.ProfileIsSigninRequiredAtIndex(profile_index) &&
394 ReadyToShow())
390 ShowWindowNearDock(); 395 ShowWindowNearDock();
391 } 396 }
392 } 397 }
393 398
394 Profile* AppListServiceMac::GetCurrentAppListProfile() {
395 return profile_;
396 }
397
398 void AppListServiceMac::ShowForProfile(Profile* requested_profile) {
399 CreateForProfile(requested_profile);
400 ShowWindowNearDock();
401 }
402
403 void AppListServiceMac::DismissAppList() { 399 void AppListServiceMac::DismissAppList() {
404 if (!IsAppListVisible()) 400 if (!IsAppListVisible())
405 return; 401 return;
406 402
403 NSWindow* app_list_window = GetNativeWindow();
407 // If the app list is currently the main window, it will activate the next 404 // If the app list is currently the main window, it will activate the next
408 // Chrome window when dismissed. But if a different application was active 405 // Chrome window when dismissed. But if a different application was active
409 // when the app list was shown, activate that instead. 406 // when the app list was shown, activate that instead.
410 base::scoped_nsobject<NSRunningApplication> prior_app; 407 base::scoped_nsobject<NSRunningApplication> prior_app;
411 if ([[window_controller_ window] isMainWindow]) 408 if ([app_list_window isMainWindow])
412 prior_app.swap(previously_active_application_); 409 prior_app.swap(previously_active_application_);
413 else 410 else
414 previously_active_application_.reset(); 411 previously_active_application_.reset();
415 412
416 // If activation is successful, the app list will lose main status and try to 413 // If activation is successful, the app list will lose main status and try to
417 // close itself again. It can't be closed in this runloop iteration without 414 // close itself again. It can't be closed in this runloop iteration without
418 // OSX deciding to raise the next Chrome window, and _then_ activating the 415 // OSX deciding to raise the next Chrome window, and _then_ activating the
419 // application on top. This also occurs if no activation option is given. 416 // application on top. This also occurs if no activation option is given.
420 if ([prior_app activateWithOptions:NSApplicationActivateIgnoringOtherApps]) 417 if ([prior_app activateWithOptions:NSApplicationActivateIgnoringOtherApps])
421 return; 418 return;
422 419
423 [animation_controller_ animateWindow:[window_controller_ window] 420 [animation_controller_ animateWindow:app_list_window
424 targetOrigin:last_start_origin_ 421 targetOrigin:last_start_origin_
425 closing:YES]; 422 closing:YES];
426 } 423 }
427 424
428 void AppListServiceMac::ShowForCustomLauncherPage(Profile* profile) { 425 void AppListServiceMac::ShowForCustomLauncherPage(Profile* profile) {
429 NOTIMPLEMENTED(); 426 NOTIMPLEMENTED();
430 } 427 }
431 428
432 bool AppListServiceMac::IsAppListVisible() const { 429 bool AppListServiceMac::IsAppListVisible() const {
433 return [[window_controller_ window] isVisible] && 430 return [GetNativeWindow() isVisible] &&
434 ![animation_controller_ isClosing]; 431 ![animation_controller_ isClosing];
435 } 432 }
436 433
437 void AppListServiceMac::EnableAppList(Profile* initial_profile, 434 void AppListServiceMac::EnableAppList(Profile* initial_profile,
438 AppListEnableSource enable_source) { 435 AppListEnableSource enable_source) {
439 AppListServiceImpl::EnableAppList(initial_profile, enable_source); 436 AppListServiceImpl::EnableAppList(initial_profile, enable_source);
440 AppController* controller = [NSApp delegate]; 437 AppController* controller = [NSApp delegate];
441 [controller initAppShimMenuController]; 438 [controller initAppShimMenuController];
442 } 439 }
443 440
444 void AppListServiceMac::CreateShortcut() { 441 void AppListServiceMac::CreateShortcut() {
445 CreateAppListShim(GetProfilePath( 442 CreateAppListShim(GetProfilePath(
446 g_browser_process->profile_manager()->user_data_dir())); 443 g_browser_process->profile_manager()->user_data_dir()));
447 } 444 }
448 445
449 void AppListServiceMac::CreateForProfile(Profile* requested_profile) {
450 DCHECK(requested_profile);
451 InvalidatePendingProfileLoads();
452 if (profile_ && requested_profile->IsSameProfile(profile_))
453 return;
454
455 profile_ = requested_profile->GetOriginalProfile();
456 SetProfilePath(profile_->GetPath());
457
458 if (!window_controller_)
459 window_controller_.reset([[AppListWindowController alloc] init]);
460
461 [[window_controller_ appListViewController] setDelegate:nil];
462 [[window_controller_ appListViewController]
463 setDelegate:GetViewDelegate(profile_)];
464 }
465
466 void AppListServiceMac::DestroyAppList() {
467 // Due to reference counting, Mac can't guarantee that the widget is deleted,
468 // but mac supports a visible app list with a NULL profile, so there's also no
469 // need to tear it down completely.
470 DismissAppList();
471 [[window_controller_ appListViewController] setDelegate:NULL];
472
473 profile_ = NULL;
474 }
475
476 NSWindow* AppListServiceMac::GetAppListWindow() { 446 NSWindow* AppListServiceMac::GetAppListWindow() {
477 return [window_controller_ window]; 447 return GetNativeWindow();
478 }
479
480 AppListControllerDelegate* AppListServiceMac::GetControllerDelegate() {
481 return controller_delegate_.get();
482 } 448 }
483 449
484 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, 450 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host,
485 apps::AppShimLaunchType launch_type, 451 apps::AppShimLaunchType launch_type,
486 const std::vector<base::FilePath>& files) { 452 const std::vector<base::FilePath>& files) {
487 if (profile_ && IsAppListVisible()) { 453 if (GetCurrentAppListProfile() && IsAppListVisible()) {
488 DismissAppList(); 454 DismissAppList();
489 } else { 455 } else {
490 // Start by showing a possibly empty window to handle the case where Chrome 456 // Start by showing a possibly empty window to handle the case where Chrome
491 // is running, but hasn't yet loaded the app launcher profile. 457 // is running, but hasn't yet loaded the app launcher profile.
492 ShowWindowNearDock(); 458 if (ReadyToShow())
459 ShowWindowNearDock();
493 Show(); 460 Show();
494 } 461 }
495 462
496 // Always close the shim process immediately. 463 // Always close the shim process immediately.
497 host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST); 464 host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST);
498 } 465 }
499 466
500 void AppListServiceMac::OnShimClose(apps::AppShimHandler::Host* host) {} 467 void AppListServiceMac::OnShimClose(apps::AppShimHandler::Host* host) {}
501 468
502 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host, 469 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host,
503 apps::AppShimFocusType focus_type, 470 apps::AppShimFocusType focus_type,
504 const std::vector<base::FilePath>& files) {} 471 const std::vector<base::FilePath>& files) {}
505 472
506 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host, 473 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host,
507 bool hidden) {} 474 bool hidden) {}
508 475
509 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {} 476 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {}
510 477
511 void AppListServiceMac::ShowWindowNearDock() { 478 void AppListServiceMac::ShowWindowNearDock() {
512 if (IsAppListVisible()) 479 if (IsAppListVisible())
513 return; 480 return;
514 481
515 if (!window_controller_) {
516 // Note that this will start showing an unpopulated window, the caller needs
517 // to ensure it will be populated later.
518 window_controller_.reset([[AppListWindowController alloc] init]);
519 }
520
521 NSWindow* window = GetAppListWindow(); 482 NSWindow* window = GetAppListWindow();
522 DCHECK(window); 483 DCHECK(window);
523 NSPoint target_origin; 484 NSPoint target_origin;
524 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_); 485 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_);
525 [window setFrameOrigin:last_start_origin_]; 486 [window setFrameOrigin:last_start_origin_];
526 487
527 // Before activating, see if an application other than Chrome is currently the 488 // Before activating, see if an application other than Chrome is currently the
528 // active application, so that it can be reactivated when dismissing. 489 // active application, so that it can be reactivated when dismissing.
529 previously_active_application_.reset([ActiveApplicationNotChrome() retain]); 490 previously_active_application_.reset([ActiveApplicationNotChrome() retain]);
530 491
531 [animation_controller_ animateWindow:[window_controller_ window] 492 [animation_controller_ animateWindow:window
532 targetOrigin:target_origin 493 targetOrigin:target_origin
533 closing:NO]; 494 closing:NO];
534 [window makeKeyAndOrderFront:nil]; 495 [window makeKeyAndOrderFront:nil];
535 [NSApp activateIgnoringOtherApps:YES]; 496 [NSApp activateIgnoringOtherApps:YES];
536 RecordAppListLaunch(); 497 RecordAppListLaunch();
537 } 498 }
538 499
539 void AppListServiceMac::WindowAnimationDidEnd() { 500 void AppListServiceMac::WindowAnimationDidEnd() {
540 [animation_controller_ cleanupOnUIThread]; 501 [animation_controller_ cleanupOnUIThread];
541 } 502 }
542 503
543 // static 504 // static
544 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { 505 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
545 return AppListServiceMac::GetInstance(); 506 return GetActiveInstance();
546 } 507 }
547 508
548 // static 509 // static
549 void AppListService::InitAll(Profile* initial_profile, 510 void AppListService::InitAll(Profile* initial_profile,
550 const base::FilePath& profile_path) { 511 const base::FilePath& profile_path) {
551 AppListServiceMac::GetInstance()->InitWithProfilePath(initial_profile, 512 GetActiveInstance()->InitWithProfilePath(initial_profile, profile_path);
552 profile_path);
553 } 513 }
554 514
555 @implementation AppListAnimationController 515 @implementation AppListAnimationController
556 516
557 - (BOOL)isClosing { 517 - (BOOL)isClosing {
558 return !!window_; 518 return !!window_;
559 } 519 }
560 520
561 - (void)animateWindow:(NSWindow*)window 521 - (void)animateWindow:(NSWindow*)window
562 targetOrigin:(NSPoint)targetOrigin 522 targetOrigin:(NSPoint)targetOrigin
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 570
611 if (closing) 571 if (closing)
612 apps::AppShimHandler::MaybeTerminate(); 572 apps::AppShimHandler::MaybeTerminate();
613 } 573 }
614 574
615 - (void)animationDidEnd:(NSAnimation*)animation { 575 - (void)animationDidEnd:(NSAnimation*)animation {
616 content::BrowserThread::PostTask( 576 content::BrowserThread::PostTask(
617 content::BrowserThread::UI, 577 content::BrowserThread::UI,
618 FROM_HERE, 578 FROM_HERE,
619 base::Bind(&AppListServiceMac::WindowAnimationDidEnd, 579 base::Bind(&AppListServiceMac::WindowAnimationDidEnd,
620 base::Unretained(AppListServiceMac::GetInstance()))); 580 base::Unretained(GetActiveInstance())));
621 } 581 }
622 582
623 @end 583 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698