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/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 "apps/app_shim/app_shim_mac.h" | 10 #include "apps/app_shim/app_shim_mac.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "chrome/browser/ui/app_list/app_list_positioner.h" | 23 #include "chrome/browser/ui/app_list/app_list_positioner.h" |
24 #include "chrome/browser/ui/app_list/app_list_service.h" | 24 #include "chrome/browser/ui/app_list/app_list_service.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" | 27 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
28 #include "chrome/browser/ui/browser_commands.h" | 28 #include "chrome/browser/ui/browser_commands.h" |
29 #include "chrome/browser/ui/extensions/application_launch.h" | 29 #include "chrome/browser/ui/extensions/application_launch.h" |
30 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 30 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
31 #include "chrome/browser/web_applications/web_app.h" | 31 #include "chrome/browser/web_applications/web_app.h" |
32 #include "chrome/browser/web_applications/web_app_mac.h" | 32 #include "chrome/browser/web_applications/web_app_mac.h" |
33 #include "chrome/common/chrome_switches.h" | |
33 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
34 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 35 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
35 #include "chrome/common/mac/app_mode_common.h" | 36 #include "chrome/common/mac/app_mode_common.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 #include "grit/chrome_unscaled_resources.h" | 39 #include "grit/chrome_unscaled_resources.h" |
39 #include "grit/google_chrome_strings.h" | 40 #include "grit/google_chrome_strings.h" |
40 #include "net/base/url_util.h" | 41 #include "net/base/url_util.h" |
41 #import "ui/app_list/cocoa/app_list_view_controller.h" | 42 #import "ui/app_list/cocoa/app_list_view_controller.h" |
42 #import "ui/app_list/cocoa/app_list_window_controller.h" | 43 #import "ui/app_list/cocoa/app_list_window_controller.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
61 | 62 |
62 // Returns whether |window_| is scheduled to be closed when the animation ends. | 63 // Returns whether |window_| is scheduled to be closed when the animation ends. |
63 - (BOOL)isClosing; | 64 - (BOOL)isClosing; |
64 | 65 |
65 // Animate |window| to show or close it, after cancelling any current animation. | 66 // Animate |window| to show or close it, after cancelling any current animation. |
66 // Translates from the current location to |targetOrigin| and fades in or out. | 67 // Translates from the current location to |targetOrigin| and fades in or out. |
67 - (void)animateWindow:(NSWindow*)window | 68 - (void)animateWindow:(NSWindow*)window |
68 targetOrigin:(NSPoint)targetOrigin | 69 targetOrigin:(NSPoint)targetOrigin |
69 closing:(BOOL)closing; | 70 closing:(BOOL)closing; |
70 | 71 |
72 // Called on the UI thread once the animation has completed to reset the | |
73 // animation state, close the window (if it is a close animation), and possibly | |
74 // terminate Chrome. | |
75 - (void)cleanupOnUIThread; | |
76 | |
71 @end | 77 @end |
72 | 78 |
73 namespace { | 79 namespace { |
74 | 80 |
75 // Version of the app list shortcut version installed. | 81 // Version of the app list shortcut version installed. |
76 const int kShortcutVersion = 1; | 82 const int kShortcutVersion = 1; |
77 | 83 |
78 // Duration of show and hide animations. | 84 // Duration of show and hide animations. |
79 const NSTimeInterval kAnimationDuration = 0.2; | 85 const NSTimeInterval kAnimationDuration = 0.2; |
80 | 86 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 } | 359 } |
354 } | 360 } |
355 | 361 |
356 static bool init_called = false; | 362 static bool init_called = false; |
357 if (init_called) | 363 if (init_called) |
358 return; | 364 return; |
359 | 365 |
360 init_called = true; | 366 init_called = true; |
361 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, | 367 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, |
362 AppListServiceMac::GetInstance()); | 368 AppListServiceMac::GetInstance()); |
369 | |
370 // Handle the case where Chrome was not running and was started with the app | |
371 // launcher shim. The profile has not yet been loaded. To improve response | |
372 // times, start animating an empty window which will be populated via | |
373 // OnShimLaunch(). Note that if --silent-launch is not also passed, the window | |
374 // will instead populate via StartupBrowserCreator::Launch(). Shim-initiated | |
375 // lanuches will always have --silent-launch. | |
jackhou1
2014/01/17 06:10:53
lanuches -> launches
tapted
2014/01/17 06:21:03
Done.
| |
376 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList)) | |
377 ShowWindowNearDock(); | |
363 } | 378 } |
364 | 379 |
365 Profile* AppListServiceMac::GetCurrentAppListProfile() { | 380 Profile* AppListServiceMac::GetCurrentAppListProfile() { |
366 return profile_; | 381 return profile_; |
367 } | 382 } |
368 | 383 |
369 void AppListServiceMac::CreateForProfile(Profile* requested_profile) { | 384 void AppListServiceMac::CreateForProfile(Profile* requested_profile) { |
370 if (profile_ == requested_profile) | 385 if (profile_ == requested_profile) |
371 return; | 386 return; |
372 | 387 |
373 profile_ = requested_profile; | 388 profile_ = requested_profile; |
374 | 389 |
375 if (window_controller_) { | 390 if (!window_controller_) |
376 // Clear the search box. | |
377 [[window_controller_ appListViewController] searchBoxModel] | |
tapted
2014/01/17 04:42:40
note: this logic is refactored into the view contr
| |
378 ->SetText(base::string16()); | |
379 } else { | |
380 window_controller_.reset([[AppListWindowController alloc] init]); | 391 window_controller_.reset([[AppListWindowController alloc] init]); |
381 } | |
382 | 392 |
383 scoped_ptr<app_list::AppListViewDelegate> delegate( | 393 scoped_ptr<app_list::AppListViewDelegate> delegate( |
384 new AppListViewDelegate(profile_, GetControllerDelegate())); | 394 new AppListViewDelegate(profile_, GetControllerDelegate())); |
385 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; | 395 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; |
386 } | 396 } |
387 | 397 |
388 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { | 398 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { |
389 if (requested_profile->IsManaged()) | 399 if (requested_profile->IsManaged()) |
390 return; | 400 return; |
391 | 401 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 return [window_controller_ window]; | 456 return [window_controller_ window]; |
447 } | 457 } |
448 | 458 |
449 AppListControllerDelegate* AppListServiceMac::GetControllerDelegate() { | 459 AppListControllerDelegate* AppListServiceMac::GetControllerDelegate() { |
450 return controller_delegate_.get(); | 460 return controller_delegate_.get(); |
451 } | 461 } |
452 | 462 |
453 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, | 463 void AppListServiceMac::OnShimLaunch(apps::AppShimHandler::Host* host, |
454 apps::AppShimLaunchType launch_type, | 464 apps::AppShimLaunchType launch_type, |
455 const std::vector<base::FilePath>& files) { | 465 const std::vector<base::FilePath>& files) { |
456 if (IsAppListVisible()) | 466 if (profile_ && IsAppListVisible()) { |
457 DismissAppList(); | 467 DismissAppList(); |
458 else | 468 } else { |
469 // Start by showing a possibly empty window to handle the case where Chrome | |
470 // is running, but hasn't yet loaded the app launcher profile. | |
471 ShowWindowNearDock(); | |
459 Show(); | 472 Show(); |
473 } | |
460 | 474 |
461 // Always close the shim process immediately. | 475 // Always close the shim process immediately. |
462 host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST); | 476 host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST); |
463 } | 477 } |
464 | 478 |
465 void AppListServiceMac::OnShimClose(apps::AppShimHandler::Host* host) {} | 479 void AppListServiceMac::OnShimClose(apps::AppShimHandler::Host* host) {} |
466 | 480 |
467 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host, | 481 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host, |
468 apps::AppShimFocusType focus_type, | 482 apps::AppShimFocusType focus_type, |
469 const std::vector<base::FilePath>& files) {} | 483 const std::vector<base::FilePath>& files) {} |
470 | 484 |
471 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host, | 485 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host, |
472 bool hidden) {} | 486 bool hidden) {} |
473 | 487 |
474 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {} | 488 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {} |
475 | 489 |
476 void AppListServiceMac::ShowWindowNearDock() { | 490 void AppListServiceMac::ShowWindowNearDock() { |
477 if (IsAppListVisible()) | 491 if (IsAppListVisible()) |
478 return; | 492 return; |
479 | 493 |
494 if (!window_controller_) { | |
495 // Note that this will start showing an unpopulated window, the caller needs | |
496 // to ensure it will be populated later. | |
497 window_controller_.reset([[AppListWindowController alloc] init]); | |
498 } | |
499 | |
480 NSWindow* window = GetAppListWindow(); | 500 NSWindow* window = GetAppListWindow(); |
481 DCHECK(window); | 501 DCHECK(window); |
482 NSPoint target_origin; | 502 NSPoint target_origin; |
483 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_); | 503 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_); |
484 [window setFrameOrigin:last_start_origin_]; | 504 [window setFrameOrigin:last_start_origin_]; |
485 | 505 |
486 // Before activating, see if an application other than Chrome is currently the | 506 // Before activating, see if an application other than Chrome is currently the |
487 // active application, so that it can be reactivated when dismissing. | 507 // active application, so that it can be reactivated when dismissing. |
488 previously_active_application_.reset([ActiveApplicationNotChrome() retain]); | 508 previously_active_application_.reset([ActiveApplicationNotChrome() retain]); |
489 | 509 |
490 [animation_controller_ animateWindow:[window_controller_ window] | 510 [animation_controller_ animateWindow:[window_controller_ window] |
491 targetOrigin:target_origin | 511 targetOrigin:target_origin |
492 closing:NO]; | 512 closing:NO]; |
493 [window makeKeyAndOrderFront:nil]; | 513 [window makeKeyAndOrderFront:nil]; |
494 [NSApp activateIgnoringOtherApps:YES]; | 514 [NSApp activateIgnoringOtherApps:YES]; |
495 RecordAppListLaunch(); | 515 RecordAppListLaunch(); |
496 } | 516 } |
497 | 517 |
518 void AppListServiceMac::WindowAnimationDidEnd() { | |
519 [animation_controller_ cleanupOnUIThread]; | |
520 } | |
521 | |
498 // static | 522 // static |
499 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { | 523 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { |
500 return AppListServiceMac::GetInstance(); | 524 return AppListServiceMac::GetInstance(); |
501 } | 525 } |
502 | 526 |
503 // static | 527 // static |
504 void AppListService::InitAll(Profile* initial_profile) { | 528 void AppListService::InitAll(Profile* initial_profile) { |
505 AppListServiceMac::GetInstance()->Init(initial_profile); | 529 AppListServiceMac::GetInstance()->Init(initial_profile); |
506 } | 530 } |
507 | 531 |
(...skipping 30 matching lines...) Expand all Loading... | |
538 [animation_ setDelegate:self]; | 562 [animation_ setDelegate:self]; |
539 | 563 |
540 if (closing) { | 564 if (closing) { |
541 [animation_ setAnimationCurve:NSAnimationEaseIn]; | 565 [animation_ setAnimationCurve:NSAnimationEaseIn]; |
542 window_.reset([window retain]); | 566 window_.reset([window retain]); |
543 } else { | 567 } else { |
544 [window setAlphaValue:0.0f]; | 568 [window setAlphaValue:0.0f]; |
545 [animation_ setAnimationCurve:NSAnimationEaseOut]; | 569 [animation_ setAnimationCurve:NSAnimationEaseOut]; |
546 window_.reset(); | 570 window_.reset(); |
547 } | 571 } |
572 [animation_ setAnimationBlockingMode:NSAnimationNonblockingThreaded]; | |
548 [animation_ startAnimation]; | 573 [animation_ startAnimation]; |
549 } | 574 } |
550 | 575 |
551 - (void)animationDidEnd:(NSAnimation*)animation { | 576 - (void)cleanupOnUIThread { |
577 bool closing = [self isClosing]; | |
552 [window_ close]; | 578 [window_ close]; |
553 window_.reset(); | 579 window_.reset(); |
554 animation_.reset(); | 580 animation_.reset(); |
555 | 581 |
556 apps::AppShimHandler::MaybeTerminate(); | 582 if (closing) |
583 apps::AppShimHandler::MaybeTerminate(); | |
584 } | |
585 | |
586 - (void)animationDidEnd:(NSAnimation*)animation { | |
587 content::BrowserThread::PostTask( | |
588 content::BrowserThread::UI, | |
589 FROM_HERE, | |
590 base::Bind(&AppListServiceMac::WindowAnimationDidEnd, | |
591 base::Unretained(AppListServiceMac::GetInstance()))); | |
557 } | 592 } |
558 | 593 |
559 @end | 594 @end |
OLD | NEW |