| 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, base::Optional<MenuItemList>) {} |
| 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 MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( |
| 619 ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( | |
| 620 const ash::ShelfItem& item) { | 630 const ash::ShelfItem& item) { |
| 621 LauncherItemController* controller = GetLauncherItemController(item.id); | 631 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 622 return controller ? controller->GetAppMenuItems(ui::EF_NONE) | 632 return controller ? controller->GetAppMenuItems(ui::EF_NONE) : MenuItemList(); |
| 623 : ash::ShelfAppMenuItemList(); | |
| 624 } | 633 } |
| 625 | 634 |
| 626 std::vector<content::WebContents*> | 635 std::vector<content::WebContents*> |
| 627 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 636 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| 628 const std::string& app_id) { | 637 const std::string& app_id) { |
| 629 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 638 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 630 // If there is no such item pinned to the launcher, no menu gets created. | 639 // If there is no such item pinned to the launcher, no menu gets created. |
| 631 if (!item || item->type != ash::TYPE_APP_SHORTCUT) | 640 if (!item || item->type != ash::TYPE_APP_SHORTCUT) |
| 632 return std::vector<content::WebContents*>(); | 641 return std::vector<content::WebContents*>(); |
| 633 LauncherItemController* controller = GetLauncherItemController(item->id); | 642 LauncherItemController* controller = GetLauncherItemController(item->id); |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 while (!browser_to_close.empty()) { | 1378 while (!browser_to_close.empty()) { |
| 1370 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); | 1379 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); |
| 1371 if (!tab_strip->empty()) | 1380 if (!tab_strip->empty()) |
| 1372 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 1381 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 1373 browser_to_close.pop_back(); | 1382 browser_to_close.pop_back(); |
| 1374 } | 1383 } |
| 1375 } | 1384 } |
| 1376 | 1385 |
| 1377 void ChromeLauncherControllerImpl::SetShelfItemDelegate( | 1386 void ChromeLauncherControllerImpl::SetShelfItemDelegate( |
| 1378 ash::ShelfID id, | 1387 ash::ShelfID id, |
| 1379 ash::ShelfItemDelegate* item_delegate) { | 1388 ash::mojom::ShelfItemDelegate* item_delegate) { |
| 1380 DCHECK_GT(id, 0); | 1389 DCHECK_GT(id, 0); |
| 1381 DCHECK(item_delegate); | 1390 DCHECK(item_delegate); |
| 1382 model_->SetShelfItemDelegate( | 1391 model_->SetShelfItemDelegate( |
| 1383 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); | 1392 id, base::WrapUnique<ash::mojom::ShelfItemDelegate>(item_delegate)); |
| 1384 } | 1393 } |
| 1385 | 1394 |
| 1386 void ChromeLauncherControllerImpl::ReleaseProfile() { | 1395 void ChromeLauncherControllerImpl::ReleaseProfile() { |
| 1387 if (app_sync_ui_state_) | 1396 if (app_sync_ui_state_) |
| 1388 app_sync_ui_state_->RemoveObserver(this); | 1397 app_sync_ui_state_->RemoveObserver(this); |
| 1389 | 1398 |
| 1390 app_updaters_.clear(); | 1399 app_updaters_.clear(); |
| 1391 | 1400 |
| 1392 prefs_observer_.reset(); | 1401 prefs_observer_.reset(); |
| 1393 | 1402 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) | 1436 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) |
| 1428 SyncPinPosition(item.id); | 1437 SyncPinPosition(item.id); |
| 1429 } | 1438 } |
| 1430 | 1439 |
| 1431 void ChromeLauncherControllerImpl::ShelfItemChanged( | 1440 void ChromeLauncherControllerImpl::ShelfItemChanged( |
| 1432 int index, | 1441 int index, |
| 1433 const ash::ShelfItem& old_item) {} | 1442 const ash::ShelfItem& old_item) {} |
| 1434 | 1443 |
| 1435 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | 1444 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
| 1436 ash::ShelfID id, | 1445 ash::ShelfID id, |
| 1437 ash::ShelfItemDelegate* item_delegate) { | 1446 ash::mojom::ShelfItemDelegate* item_delegate) { |
| 1438 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1447 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| 1439 // get into this state in the first place. | 1448 // get into this state in the first place. |
| 1440 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1449 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 1441 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | 1450 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
| 1442 return; | 1451 return; |
| 1443 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; | 1452 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; |
| 1444 id_to_item_controller_map_.erase(iter); | 1453 id_to_item_controller_map_.erase(iter); |
| 1445 } | 1454 } |
| 1446 | 1455 |
| 1447 /////////////////////////////////////////////////////////////////////////////// | 1456 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 LauncherItemController* controller = GetLauncherItemController(item.id); | 1499 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1491 if (!controller || controller->image_set_by_controller()) | 1500 if (!controller || controller->image_set_by_controller()) |
| 1492 continue; | 1501 continue; |
| 1493 item.image = image; | 1502 item.image = image; |
| 1494 if (arc_deferred_launcher_) | 1503 if (arc_deferred_launcher_) |
| 1495 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1504 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1496 model_->Set(index, item); | 1505 model_->Set(index, item); |
| 1497 // It's possible we're waiting on more than one item, so don't break. | 1506 // It's possible we're waiting on more than one item, so don't break. |
| 1498 } | 1507 } |
| 1499 } | 1508 } |
| OLD | NEW |