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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc

Issue 2290603002: Enhance chrome.app.window API for shelf integration with pinning support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 3 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 #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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 347 }
348 348
349 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { 349 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) {
350 CHECK(id); 350 CHECK(id);
351 if (IsPinned(id)) { 351 if (IsPinned(id)) {
352 // Create a new shortcut controller. 352 // Create a new shortcut controller.
353 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 353 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
354 CHECK(iter != id_to_item_controller_map_.end()); 354 CHECK(iter != id_to_item_controller_map_.end());
355 SetItemStatus(id, ash::STATUS_CLOSED); 355 SetItemStatus(id, ash::STATUS_CLOSED);
356 std::string app_id = iter->second->app_id(); 356 std::string app_id = iter->second->app_id();
357 iter->second = AppShortcutLauncherItemController::Create(app_id, this); 357 std::string launch_id = "";
stevenjb 2016/08/30 16:12:51 ' = ""' unnecessary.
Andra Paraschiv 2016/08/31 10:57:18 Done.
358 if (iter->second->type() == LauncherItemController::TYPE_APP) {
359 AppWindowLauncherItemController* app_window_controller =
360 static_cast<AppWindowLauncherItemController*>(iter->second);
361 launch_id = app_window_controller->launch_id();
362 }
363 iter->second =
364 AppShortcutLauncherItemController::Create(app_id, launch_id, this);
358 iter->second->set_shelf_id(id); 365 iter->second->set_shelf_id(id);
359 // Existing controller is destroyed and replaced by registering again. 366 // Existing controller is destroyed and replaced by registering again.
360 SetShelfItemDelegate(id, iter->second); 367 SetShelfItemDelegate(id, iter->second);
361 } else { 368 } else {
362 LauncherItemClosed(id); 369 LauncherItemClosed(id);
363 } 370 }
364 } 371 }
365 372
366 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 373 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
367 DCHECK(HasShelfIDToAppIDMapping(id)); 374 DCHECK(HasShelfIDToAppIDMapping(id));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 ash::ShelfID id = GetShelfIDForAppID(app_id); 500 ash::ShelfID id = GetShelfIDForAppID(app_id);
494 if (id) { 501 if (id) {
495 LauncherItemController* controller = GetLauncherItemController(id); 502 LauncherItemController* controller = GetLauncherItemController(id);
496 controller->Activate(source); 503 controller->Activate(source);
497 return; 504 return;
498 } 505 }
499 506
500 // Create a temporary application launcher item and use it to see if there are 507 // Create a temporary application launcher item and use it to see if there are
501 // running instances. 508 // running instances.
502 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 509 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
503 AppShortcutLauncherItemController::Create(app_id, this)); 510 AppShortcutLauncherItemController::Create(app_id, "", this));
504 if (!app_controller->GetRunningApplications().empty()) 511 if (!app_controller->GetRunningApplications().empty())
505 app_controller->Activate(source); 512 app_controller->Activate(source);
506 else 513 else
507 LaunchApp(app_id, source, event_flags); 514 LaunchApp(app_id, source, event_flags);
508 } 515 }
509 516
510 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( 517 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType(
511 ash::ShelfID id) { 518 ash::ShelfID id) {
512 const Extension* extension = 519 const Extension* extension =
513 GetExtensionForAppID(GetAppIDForShelfID(id), profile_); 520 GetExtensionForAppID(GetAppIDForShelfID(id), profile_);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 895 }
889 896
890 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( 897 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged(
891 ash::WmShelf* shelf) {} 898 ash::WmShelf* shelf) {}
892 899
893 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( 900 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged(
894 ash::WmShelf* shelf) {} 901 ash::WmShelf* shelf) {}
895 902
896 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( 903 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
897 const std::string& app_id) { 904 const std::string& app_id) {
898 for (IDToItemControllerMap::const_iterator i = 905 // Get shelf id for app_id and empty launch_id.
899 id_to_item_controller_map_.begin(); 906 ash::ShelfID shelf_id = GetShelfIDForAppIDAndLaunchID(app_id, "");
stevenjb 2016/08/30 16:12:52 No need for intermediate |shelf_id|
Andra Paraschiv 2016/08/31 10:57:18 Done.
900 i != id_to_item_controller_map_.end(); ++i) { 907 return shelf_id;
901 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) 908 }
909
910 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID(
911 const std::string& app_id,
912 const std::string& launch_id) {
913 for (const auto& id_to_item_controller_pair : id_to_item_controller_map_) {
914 if (id_to_item_controller_pair.second->type() ==
915 LauncherItemController::TYPE_APP_PANEL)
902 continue; // Don't include panels 916 continue; // Don't include panels
903 if (i->second->app_id() == app_id) 917 // If app window controller, check app_id and launch_id.
stevenjb 2016/08/30 16:12:52 Move these comments inside the if clauses
Andra Paraschiv 2016/08/31 10:57:18 Done.
904 return i->first; 918 if (id_to_item_controller_pair.second->type() ==
919 LauncherItemController::TYPE_APP) {
920 AppWindowLauncherItemController* app_window_controller =
921 static_cast<AppWindowLauncherItemController*>(
922 id_to_item_controller_pair.second);
923 if ((app_window_controller->app_id() == app_id) &&
924 (app_window_controller->launch_id() == launch_id)) {
925 return id_to_item_controller_pair.first;
926 }
927 // If not browser shortcut controller, check app_id and launch_id.
928 } else if ((id_to_item_controller_pair.second->type() ==
929 LauncherItemController::TYPE_SHORTCUT) &&
930 (id_to_item_controller_pair.second->app_id() !=
931 extension_misc::kChromeAppId)) {
932 AppShortcutLauncherItemController* app_shortcut_controller =
933 static_cast<AppShortcutLauncherItemController*>(
934 id_to_item_controller_pair.second);
935 if ((app_shortcut_controller->app_id() == app_id) &&
936 (app_shortcut_controller->launch_id() == launch_id)) {
937 return id_to_item_controller_pair.first;
938 }
stevenjb 2016/08/30 16:12:51 These tests are the same, why cast them? e.g.: if
Andra Paraschiv 2016/08/31 10:57:18 Yes, they are the same, but we should include the
stevenjb 2016/08/31 18:24:27 Ahh, I didn't realize that launch_id() didn't exis
939 } else if (id_to_item_controller_pair.second->app_id() == app_id) {
940 return id_to_item_controller_pair.first;
941 }
905 } 942 }
906 return 0; 943 return 0;
907 } 944 }
908 945
909 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( 946 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping(
910 ash::ShelfID id) const { 947 ash::ShelfID id) const {
911 return id_to_item_controller_map_.find(id) != 948 return id_to_item_controller_map_.find(id) !=
912 id_to_item_controller_map_.end(); 949 id_to_item_controller_map_.end();
913 } 950 }
914 951
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 } 1091 }
1055 } 1092 }
1056 } 1093 }
1057 1094
1058 ash::ShelfID 1095 ash::ShelfID
1059 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1096 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1060 const std::string& app_id, 1097 const std::string& app_id,
1061 int index, 1098 int index,
1062 ash::ShelfItemType shelf_item_type) { 1099 ash::ShelfItemType shelf_item_type) {
1063 AppShortcutLauncherItemController* controller = 1100 AppShortcutLauncherItemController* controller =
1064 AppShortcutLauncherItemController::Create(app_id, this); 1101 AppShortcutLauncherItemController::Create(app_id, "", this);
1065 ash::ShelfID shelf_id = InsertAppLauncherItem( 1102 ash::ShelfID shelf_id = InsertAppLauncherItem(
1066 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); 1103 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type);
1067 return shelf_id; 1104 return shelf_id;
1068 } 1105 }
1069 1106
1070 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1107 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1071 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1108 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1072 CHECK(iter != id_to_item_controller_map_.end()); 1109 CHECK(iter != id_to_item_controller_map_.end());
1073 CHECK(iter->second); 1110 CHECK(iter->second);
1074 const std::string& app_id = iter->second->app_id(); 1111 const std::string& app_id = iter->second->app_id();
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 if (index == -1) 1719 if (index == -1)
1683 continue; 1720 continue;
1684 ash::ShelfItem item = model_->items()[index]; 1721 ash::ShelfItem item = model_->items()[index];
1685 item.image = image; 1722 item.image = image;
1686 if (arc_deferred_launcher_) 1723 if (arc_deferred_launcher_)
1687 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1724 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1688 model_->Set(index, item); 1725 model_->Set(index, item);
1689 // It's possible we're waiting on more than one item, so don't break. 1726 // It's possible we're waiting on more than one item, so don't break.
1690 } 1727 }
1691 } 1728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698