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 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 #include "components/sync_preferences/pref_service_syncable.h" | 77 #include "components/sync_preferences/pref_service_syncable.h" |
78 #include "components/user_manager/user_manager.h" | 78 #include "components/user_manager/user_manager.h" |
79 #include "content/public/browser/navigation_entry.h" | 79 #include "content/public/browser/navigation_entry.h" |
80 #include "content/public/browser/web_contents.h" | 80 #include "content/public/browser/web_contents.h" |
81 #include "extensions/common/extension.h" | 81 #include "extensions/common/extension.h" |
82 #include "ui/aura/window.h" | 82 #include "ui/aura/window.h" |
83 #include "ui/aura/window_event_dispatcher.h" | 83 #include "ui/aura/window_event_dispatcher.h" |
84 #include "ui/base/l10n/l10n_util.h" | 84 #include "ui/base/l10n/l10n_util.h" |
85 #include "ui/base/resource/resource_bundle.h" | 85 #include "ui/base/resource/resource_bundle.h" |
86 #include "ui/base/window_open_disposition.h" | 86 #include "ui/base/window_open_disposition.h" |
| 87 #include "ui/display/types/display_constants.h" |
87 #include "ui/keyboard/keyboard_util.h" | 88 #include "ui/keyboard/keyboard_util.h" |
88 #include "ui/resources/grit/ui_resources.h" | 89 #include "ui/resources/grit/ui_resources.h" |
89 #include "ui/wm/core/window_animations.h" | 90 #include "ui/wm/core/window_animations.h" |
90 | 91 |
91 using extensions::Extension; | 92 using extensions::Extension; |
92 using extension_misc::kGmailAppId; | 93 using extension_misc::kGmailAppId; |
93 using content::WebContents; | 94 using content::WebContents; |
94 | 95 |
95 namespace { | 96 namespace { |
96 | 97 |
97 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { | 98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { |
98 display::Display display = | 99 display::Display display = |
99 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); | 100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); |
100 DCHECK(display.is_valid()); | 101 DCHECK(display.is_valid()); |
101 return display.id(); | 102 return display.id(); |
102 } | 103 } |
103 | 104 |
| 105 // A callback that does nothing after shelf item selection handling. |
| 106 void NoopCallback(ash::ShelfAction, std::vector<ash::mojom::MenuItemPtr>) {} |
| 107 |
| 108 // Calls ItemSelected with |source|, default arguments, and no callback. |
| 109 void SelectItemWithSource(ash::mojom::ShelfItemDelegate* delegate, |
| 110 ash::ShelfLaunchSource source) { |
| 111 delegate->ItemSelected(nullptr, display::kInvalidDisplayId, source, |
| 112 base::Bind(&NoopCallback)); |
| 113 } |
| 114 |
104 } // namespace | 115 } // namespace |
105 | 116 |
106 // A class to get events from ChromeOS when a user gets changed or added. | 117 // A class to get events from ChromeOS when a user gets changed or added. |
107 class ChromeLauncherControllerUserSwitchObserver | 118 class ChromeLauncherControllerUserSwitchObserver |
108 : public user_manager::UserManager::UserSessionStateObserver { | 119 : public user_manager::UserManager::UserSessionStateObserver { |
109 public: | 120 public: |
110 ChromeLauncherControllerUserSwitchObserver( | 121 ChromeLauncherControllerUserSwitchObserver( |
111 ChromeLauncherControllerImpl* controller) | 122 ChromeLauncherControllerImpl* controller) |
112 : controller_(controller) { | 123 : controller_(controller) { |
113 DCHECK(user_manager::UserManager::IsInitialized()); | 124 DCHECK(user_manager::UserManager::IsInitialized()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!controller) | 424 if (!controller) |
414 return; // In case invoked from menu and item closed while menu up. | 425 return; // In case invoked from menu and item closed while menu up. |
415 | 426 |
416 // Launching some items replaces the associated item controller instance, | 427 // Launching some items replaces the associated item controller instance, |
417 // which destroys the app and launch id strings; making copies avoid crashes. | 428 // which destroys the app and launch id strings; making copies avoid crashes. |
418 LaunchApp(ash::AppLauncherId(controller->app_id(), controller->launch_id()), | 429 LaunchApp(ash::AppLauncherId(controller->app_id(), controller->launch_id()), |
419 ash::LAUNCH_FROM_UNKNOWN, event_flags); | 430 ash::LAUNCH_FROM_UNKNOWN, event_flags); |
420 } | 431 } |
421 | 432 |
422 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { | 433 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { |
423 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | 434 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
424 if (!delegate) | 435 if (!delegate) |
425 return; // May happen if menu closed. | 436 return; // May happen if menu closed. |
426 delegate->Close(); | 437 delegate->Close(); |
427 } | 438 } |
428 | 439 |
429 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { | 440 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { |
430 const ash::ShelfItem* item = GetItem(id); | 441 const ash::ShelfItem* item = GetItem(id); |
431 return item && item->status != ash::STATUS_CLOSED; | 442 return item && item->status != ash::STATUS_CLOSED; |
432 } | 443 } |
433 | 444 |
434 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { | 445 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { |
435 if (!HasShelfIDToAppIDMapping(id)) | 446 if (!HasShelfIDToAppIDMapping(id)) |
436 return false; | 447 return false; |
437 | 448 |
438 std::string app_id = GetAppIDForShelfID(id); | 449 std::string app_id = GetAppIDForShelfID(id); |
439 const Extension* extension = GetExtensionForAppID(app_id, profile()); | 450 const Extension* extension = GetExtensionForAppID(app_id, profile()); |
440 // An extension can be synced / updated at any time and therefore not be | 451 // An extension can be synced / updated at any time and therefore not be |
441 // available. | 452 // available. |
442 return extension ? extension->is_platform_app() : false; | 453 return extension ? extension->is_platform_app() : false; |
443 } | 454 } |
444 | 455 |
445 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, | 456 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, |
446 ash::ShelfLaunchSource source, | 457 ash::ShelfLaunchSource source, |
447 int event_flags) { | 458 int event_flags) { |
448 // If there is an existing non-shortcut controller for this app, open it. | 459 // If there is an existing non-shortcut controller for this app, open it. |
449 ash::ShelfID id = GetShelfIDForAppID(app_id); | 460 ash::ShelfID id = GetShelfIDForAppID(app_id); |
450 if (id) { | 461 if (id) { |
451 model_->GetShelfItemDelegate(id)->ItemSelectedBySource(source); | 462 SelectItemWithSource(model_->GetShelfItemDelegate(id), source); |
452 return; | 463 return; |
453 } | 464 } |
454 | 465 |
455 // Create a temporary application launcher item and use it to see if there are | 466 // Create a temporary application launcher item and use it to see if there are |
456 // running instances. | 467 // running instances. |
457 std::unique_ptr<AppShortcutLauncherItemController> controller( | 468 std::unique_ptr<AppShortcutLauncherItemController> controller( |
458 AppShortcutLauncherItemController::Create(app_id, std::string(), this)); | 469 AppShortcutLauncherItemController::Create(app_id, std::string(), this)); |
459 if (!controller->GetRunningApplications().empty()) | 470 if (!controller->GetRunningApplications().empty()) |
460 controller->ItemSelectedBySource(source); | 471 SelectItemWithSource(controller.get(), source); |
461 else | 472 else |
462 LaunchApp(ash::AppLauncherId(app_id), source, event_flags); | 473 LaunchApp(ash::AppLauncherId(app_id), source, event_flags); |
463 } | 474 } |
464 | 475 |
465 void ChromeLauncherControllerImpl::SetLauncherItemImage( | 476 void ChromeLauncherControllerImpl::SetLauncherItemImage( |
466 ash::ShelfID shelf_id, | 477 ash::ShelfID shelf_id, |
467 const gfx::ImageSkia& image) { | 478 const gfx::ImageSkia& image) { |
468 const ash::ShelfItem* item = GetItem(shelf_id); | 479 const ash::ShelfItem* item = GetItem(shelf_id); |
469 if (item) { | 480 if (item) { |
470 ash::ShelfItem new_item = *item; | 481 ash::ShelfItem new_item = *item; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ash::MultiProfileUMA::RecordTeleportAction( | 574 ash::MultiProfileUMA::RecordTeleportAction( |
564 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER); | 575 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER); |
565 manager->ShowWindowForUser(native_window, current_account_id); | 576 manager->ShowWindowForUser(native_window, current_account_id); |
566 window->Activate(); | 577 window->Activate(); |
567 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 578 return ash::SHELF_ACTION_WINDOW_ACTIVATED; |
568 } | 579 } |
569 } | 580 } |
570 | 581 |
571 if (window->IsActive() && allow_minimize) { | 582 if (window->IsActive() && allow_minimize) { |
572 window->Minimize(); | 583 window->Minimize(); |
573 return ash::SHELF_ACTION_NONE; | 584 return ash::SHELF_ACTION_WINDOW_MINIMIZED; |
574 } | 585 } |
575 | 586 |
576 window->Show(); | 587 window->Show(); |
577 window->Activate(); | 588 window->Activate(); |
578 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 589 return ash::SHELF_ACTION_WINDOW_ACTIVATED; |
579 } | 590 } |
580 | 591 |
581 void ChromeLauncherControllerImpl::ActiveUserChanged( | 592 void ChromeLauncherControllerImpl::ActiveUserChanged( |
582 const std::string& user_email) { | 593 const std::string& user_email) { |
583 // Store the order of running applications for the user which gets inactive. | 594 // Store the order of running applications for the user which gets inactive. |
(...skipping 24 matching lines...) Expand all Loading... |
608 ash::Shell::GetInstance()->CreateKeyboard(); | 619 ash::Shell::GetInstance()->CreateKeyboard(); |
609 } | 620 } |
610 | 621 |
611 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( | 622 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
612 Profile* profile) { | 623 Profile* profile) { |
613 // Switch the running applications to the new user. | 624 // Switch the running applications to the new user. |
614 for (auto& controller : app_window_controllers_) | 625 for (auto& controller : app_window_controllers_) |
615 controller->AdditionalUserAddedToSession(profile); | 626 controller->AdditionalUserAddedToSession(profile); |
616 } | 627 } |
617 | 628 |
618 ash::ShelfAppMenuItemList | 629 std::vector<ash::mojom::MenuItemPtr> |
619 ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( | 630 ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( |
620 const ash::ShelfItem& item) { | 631 const ash::ShelfItem& item) { |
621 LauncherItemController* controller = GetLauncherItemController(item.id); | 632 LauncherItemController* controller = GetLauncherItemController(item.id); |
622 return controller ? controller->GetAppMenuItems(ui::EF_NONE) | 633 return controller ? controller->GetAppMenuItems(ui::EF_NONE) |
623 : ash::ShelfAppMenuItemList(); | 634 : std::vector<ash::mojom::MenuItemPtr>(); |
624 } | 635 } |
625 | 636 |
626 std::vector<content::WebContents*> | 637 std::vector<content::WebContents*> |
627 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 638 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
628 const std::string& app_id) { | 639 const std::string& app_id) { |
629 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 640 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
630 // If there is no such item pinned to the launcher, no menu gets created. | 641 // If there is no such item pinned to the launcher, no menu gets created. |
631 if (!item || item->type != ash::TYPE_APP_SHORTCUT) | 642 if (!item || item->type != ash::TYPE_APP_SHORTCUT) |
632 return std::vector<content::WebContents*>(); | 643 return std::vector<content::WebContents*>(); |
633 LauncherItemController* controller = GetLauncherItemController(item->id); | 644 LauncherItemController* controller = GetLauncherItemController(item->id); |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 while (!browser_to_close.empty()) { | 1380 while (!browser_to_close.empty()) { |
1370 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); | 1381 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); |
1371 if (!tab_strip->empty()) | 1382 if (!tab_strip->empty()) |
1372 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 1383 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
1373 browser_to_close.pop_back(); | 1384 browser_to_close.pop_back(); |
1374 } | 1385 } |
1375 } | 1386 } |
1376 | 1387 |
1377 void ChromeLauncherControllerImpl::SetShelfItemDelegate( | 1388 void ChromeLauncherControllerImpl::SetShelfItemDelegate( |
1378 ash::ShelfID id, | 1389 ash::ShelfID id, |
1379 ash::ShelfItemDelegate* item_delegate) { | 1390 ash::mojom::ShelfItemDelegate* item_delegate) { |
1380 DCHECK_GT(id, 0); | 1391 DCHECK_GT(id, 0); |
1381 DCHECK(item_delegate); | 1392 DCHECK(item_delegate); |
1382 model_->SetShelfItemDelegate( | 1393 model_->SetShelfItemDelegate( |
1383 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); | 1394 id, base::WrapUnique<ash::mojom::ShelfItemDelegate>(item_delegate)); |
1384 } | 1395 } |
1385 | 1396 |
1386 void ChromeLauncherControllerImpl::ReleaseProfile() { | 1397 void ChromeLauncherControllerImpl::ReleaseProfile() { |
1387 if (app_sync_ui_state_) | 1398 if (app_sync_ui_state_) |
1388 app_sync_ui_state_->RemoveObserver(this); | 1399 app_sync_ui_state_->RemoveObserver(this); |
1389 | 1400 |
1390 app_updaters_.clear(); | 1401 app_updaters_.clear(); |
1391 | 1402 |
1392 prefs_observer_.reset(); | 1403 prefs_observer_.reset(); |
1393 | 1404 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) | 1438 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) |
1428 SyncPinPosition(item.id); | 1439 SyncPinPosition(item.id); |
1429 } | 1440 } |
1430 | 1441 |
1431 void ChromeLauncherControllerImpl::ShelfItemChanged( | 1442 void ChromeLauncherControllerImpl::ShelfItemChanged( |
1432 int index, | 1443 int index, |
1433 const ash::ShelfItem& old_item) {} | 1444 const ash::ShelfItem& old_item) {} |
1434 | 1445 |
1435 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | 1446 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
1436 ash::ShelfID id, | 1447 ash::ShelfID id, |
1437 ash::ShelfItemDelegate* item_delegate) { | 1448 ash::mojom::ShelfItemDelegate* item_delegate) { |
1438 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1449 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
1439 // get into this state in the first place. | 1450 // get into this state in the first place. |
1440 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1451 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
1441 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | 1452 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
1442 return; | 1453 return; |
1443 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; | 1454 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; |
1444 id_to_item_controller_map_.erase(iter); | 1455 id_to_item_controller_map_.erase(iter); |
1445 } | 1456 } |
1446 | 1457 |
1447 /////////////////////////////////////////////////////////////////////////////// | 1458 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 LauncherItemController* controller = GetLauncherItemController(item.id); | 1501 LauncherItemController* controller = GetLauncherItemController(item.id); |
1491 if (!controller || controller->image_set_by_controller()) | 1502 if (!controller || controller->image_set_by_controller()) |
1492 continue; | 1503 continue; |
1493 item.image = image; | 1504 item.image = image; |
1494 if (arc_deferred_launcher_) | 1505 if (arc_deferred_launcher_) |
1495 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1506 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1496 model_->Set(index, item); | 1507 model_->Set(index, item); |
1497 // It's possible we're waiting on more than one item, so don't break. | 1508 // It's possible we're waiting on more than one item, so don't break. |
1498 } | 1509 } |
1499 } | 1510 } |
OLD | NEW |