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

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

Issue 2484413002: Enhance chrome.app.window API with title property
Patch Set: Rebase Created 4 years 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { 329 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) {
330 CHECK(id); 330 CHECK(id);
331 if (IsPinned(id)) { 331 if (IsPinned(id)) {
332 // Create a new shortcut controller. 332 // Create a new shortcut controller.
333 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 333 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
334 CHECK(iter != id_to_item_controller_map_.end()); 334 CHECK(iter != id_to_item_controller_map_.end());
335 SetItemStatus(id, ash::STATUS_CLOSED); 335 SetItemStatus(id, ash::STATUS_CLOSED);
336 std::string app_id = iter->second->app_id(); 336 std::string app_id = iter->second->app_id();
337 std::string launch_id = iter->second->launch_id(); 337 std::string launch_id = iter->second->launch_id();
338 iter->second = 338 std::string title = iter->second->title();
339 AppShortcutLauncherItemController::Create(app_id, launch_id, this); 339 iter->second = AppShortcutLauncherItemController::Create(app_id, launch_id,
340 title, this);
340 iter->second->set_shelf_id(id); 341 iter->second->set_shelf_id(id);
341 // Existing controller is destroyed and replaced by registering again. 342 // Existing controller is destroyed and replaced by registering again.
342 SetShelfItemDelegate(id, iter->second); 343 SetShelfItemDelegate(id, iter->second);
343 } else { 344 } else {
344 LauncherItemClosed(id); 345 LauncherItemClosed(id);
345 } 346 }
346 } 347 }
347 348
348 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 349 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
349 DCHECK(HasShelfIDToAppIDMapping(id)); 350 DCHECK(HasShelfIDToAppIDMapping(id));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 std::string app_id; 415 std::string app_id;
415 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP || 416 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP ||
416 type == ash::TYPE_WINDOWED_APP) && 417 type == ash::TYPE_WINDOWED_APP) &&
417 model_->GetShelfItemDelegate(id)->CanPin()); 418 model_->GetShelfItemDelegate(id)->CanPin());
418 } 419 }
419 420
420 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 421 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
421 ash::ShelfID id = GetShelfIDForAppID(app_id); 422 ash::ShelfID id = GetShelfIDForAppID(app_id);
422 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { 423 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) {
423 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), 424 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id),
424 model_->item_count(), 425 "", model_->item_count(),
425 ash::TYPE_WINDOWED_APP); 426 ash::TYPE_WINDOWED_APP);
426 id = GetShelfIDForAppID(app_id); 427 id = GetShelfIDForAppID(app_id);
427 } 428 }
428 CHECK(id); 429 CHECK(id);
429 GetLauncherItemController(id)->lock(); 430 GetLauncherItemController(id)->lock();
430 } 431 }
431 432
432 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 433 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
433 const std::string& app_id) { 434 const std::string& app_id) {
434 ash::ShelfID id = GetShelfIDForAppID(app_id); 435 ash::ShelfID id = GetShelfIDForAppID(app_id);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 ash::ShelfID id = GetShelfIDForAppID(app_id); 478 ash::ShelfID id = GetShelfIDForAppID(app_id);
478 if (id) { 479 if (id) {
479 LauncherItemController* controller = GetLauncherItemController(id); 480 LauncherItemController* controller = GetLauncherItemController(id);
480 controller->Activate(source); 481 controller->Activate(source);
481 return; 482 return;
482 } 483 }
483 484
484 // Create a temporary application launcher item and use it to see if there are 485 // Create a temporary application launcher item and use it to see if there are
485 // running instances. 486 // running instances.
486 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 487 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
487 AppShortcutLauncherItemController::Create(app_id, "", this)); 488 AppShortcutLauncherItemController::Create(app_id, "", "", this));
488 if (!app_controller->GetRunningApplications().empty()) 489 if (!app_controller->GetRunningApplications().empty())
489 app_controller->Activate(source); 490 app_controller->Activate(source);
490 else 491 else
491 LaunchApp(app_id, source, event_flags); 492 LaunchApp(app_id, source, event_flags);
492 } 493 }
493 494
494 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( 495 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType(
495 ash::ShelfID id) { 496 ash::ShelfID id) {
496 const Extension* extension = 497 const Extension* extension =
497 GetExtensionForAppID(GetAppIDForShelfID(id), profile()); 498 GetExtensionForAppID(GetAppIDForShelfID(id), profile());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { 838 ChromeLauncherControllerImpl::GetArcDeferredLauncher() {
838 return arc_deferred_launcher_.get(); 839 return arc_deferred_launcher_.get();
839 } 840 }
840 841
841 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( 842 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID(
842 ash::ShelfID id) { 843 ash::ShelfID id) {
843 LauncherItemController* controller = GetLauncherItemController(id); 844 LauncherItemController* controller = GetLauncherItemController(id);
844 return controller ? controller->launch_id() : base::EmptyString(); 845 return controller ? controller->launch_id() : base::EmptyString();
845 } 846 }
846 847
848 const std::string& ChromeLauncherControllerImpl::GetTitleForShelfID(
849 ash::ShelfID id) {
850 LauncherItemController* controller = GetLauncherItemController(id);
851 return controller ? controller->title() : base::EmptyString();
852 }
853
847 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { 854 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) {
848 // The base class implementation updates the helper and app icon loaders. 855 // The base class implementation updates the helper and app icon loaders.
849 ChromeLauncherController::AttachProfile(profile_to_attach); 856 ChromeLauncherController::AttachProfile(profile_to_attach);
850 857
851 pref_change_registrar_.Init(profile()->GetPrefs()); 858 pref_change_registrar_.Init(profile()->GetPrefs());
852 pref_change_registrar_.Add( 859 pref_change_registrar_.Add(
853 prefs::kPolicyPinnedLauncherApps, 860 prefs::kPolicyPinnedLauncherApps,
854 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 861 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
855 base::Unretained(this))); 862 base::Unretained(this)));
856 // Handling of prefs::kArcEnabled change should be called deferred to avoid 863 // Handling of prefs::kArcEnabled change should be called deferred to avoid
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 if (app_icon_loader) 1018 if (app_icon_loader)
1012 app_icon_loader->ClearImage(app_id); 1019 app_icon_loader->ClearImage(app_id);
1013 } 1020 }
1014 } 1021 }
1015 1022
1016 /////////////////////////////////////////////////////////////////////////////// 1023 ///////////////////////////////////////////////////////////////////////////////
1017 // ChromeLauncherControllerImpl protected: 1024 // ChromeLauncherControllerImpl protected:
1018 1025
1019 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 1026 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
1020 const ash::launcher::AppLauncherId& app_launcher_id, 1027 const ash::launcher::AppLauncherId& app_launcher_id,
1028 const std::string& title,
1021 int index) { 1029 int index) {
1022 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, 1030 return CreateAppShortcutLauncherItemWithType(app_launcher_id, title, index,
1023 ash::TYPE_APP_SHORTCUT); 1031 ash::TYPE_APP_SHORTCUT);
1024 } 1032 }
1025 1033
1026 /////////////////////////////////////////////////////////////////////////////// 1034 ///////////////////////////////////////////////////////////////////////////////
1027 // ChromeLauncherControllerImpl private: 1035 // ChromeLauncherControllerImpl private:
1028 1036
1029 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 1037 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
1030 RunningAppListIds list; 1038 RunningAppListIds list;
1031 for (int i = 0; i < model_->item_count(); i++) { 1039 for (int i = 0; i < model_->item_count(); i++) {
1032 ash::ShelfItemType type = model_->items()[i].type; 1040 ash::ShelfItemType type = model_->items()[i].type;
(...skipping 26 matching lines...) Expand all
1059 model_->Move(running_index, app_index); 1067 model_->Move(running_index, app_index);
1060 running_index++; 1068 running_index++;
1061 } 1069 }
1062 } 1070 }
1063 } 1071 }
1064 } 1072 }
1065 1073
1066 ash::ShelfID 1074 ash::ShelfID
1067 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1075 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1068 const ash::launcher::AppLauncherId& app_launcher_id, 1076 const ash::launcher::AppLauncherId& app_launcher_id,
1077 const std::string& title,
1069 int index, 1078 int index,
1070 ash::ShelfItemType shelf_item_type) { 1079 ash::ShelfItemType shelf_item_type) {
1071 AppShortcutLauncherItemController* controller = 1080 AppShortcutLauncherItemController* controller =
1072 AppShortcutLauncherItemController::Create( 1081 AppShortcutLauncherItemController::Create(
1073 app_launcher_id.app_id(), app_launcher_id.launch_id(), this); 1082 app_launcher_id.app_id(), app_launcher_id.launch_id(), title, this);
1074 ash::ShelfID shelf_id = 1083 ash::ShelfID shelf_id =
1075 InsertAppLauncherItem(controller, app_launcher_id.app_id(), 1084 InsertAppLauncherItem(controller, app_launcher_id.app_id(),
1076 ash::STATUS_CLOSED, index, shelf_item_type); 1085 ash::STATUS_CLOSED, index, shelf_item_type);
1077 return shelf_id; 1086 return shelf_id;
1078 } 1087 }
1079 1088
1080 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1089 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1081 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1090 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1082 CHECK(iter != id_to_item_controller_map_.end()); 1091 CHECK(iter != id_to_item_controller_map_.end());
1083 CHECK(iter->second); 1092 CHECK(iter->second);
(...skipping 14 matching lines...) Expand all
1098 if (IsAppPinned(app_id)) 1107 if (IsAppPinned(app_id))
1099 return; 1108 return;
1100 1109
1101 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1110 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1102 if (shelf_id) { 1111 if (shelf_id) {
1103 // App item exists, pin it 1112 // App item exists, pin it
1104 Pin(shelf_id); 1113 Pin(shelf_id);
1105 } else { 1114 } else {
1106 // Otherwise, create a shortcut item for it. 1115 // Otherwise, create a shortcut item for it.
1107 shelf_id = CreateAppShortcutLauncherItem( 1116 shelf_id = CreateAppShortcutLauncherItem(
1108 ash::launcher::AppLauncherId(app_id), model_->item_count()); 1117 ash::launcher::AppLauncherId(app_id), "", model_->item_count());
1109 SyncPinPosition(shelf_id); 1118 SyncPinPosition(shelf_id);
1110 } 1119 }
1111 } 1120 }
1112 1121
1113 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, 1122 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id,
1114 bool update_prefs) { 1123 bool update_prefs) {
1115 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1124 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1116 if (shelf_id && IsPinned(shelf_id)) 1125 if (shelf_id && IsPinned(shelf_id))
1117 UnpinAndUpdatePrefs(shelf_id, update_prefs); 1126 UnpinAndUpdatePrefs(shelf_id, update_prefs);
1118 } 1127 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 item.type == ash::TYPE_BROWSER_SHORTCUT) { 1268 item.type == ash::TYPE_BROWSER_SHORTCUT) {
1260 // Just move to required position or keep it inplace. 1269 // Just move to required position or keep it inplace.
1261 model_->Move(app_index, index); 1270 model_->Move(app_index, index);
1262 } else { 1271 } else {
1263 PinRunningAppInternal(index, item.id); 1272 PinRunningAppInternal(index, item.id);
1264 } 1273 }
1265 DCHECK_EQ(model_->ItemIndexByID(item.id), index); 1274 DCHECK_EQ(model_->ItemIndexByID(item.id), index);
1266 } else { 1275 } else {
1267 // This is fresh pin. Create new one. 1276 // This is fresh pin. Create new one.
1268 DCHECK_NE(app_id, extension_misc::kChromeAppId); 1277 DCHECK_NE(app_id, extension_misc::kChromeAppId);
1269 CreateAppShortcutLauncherItem(pref_app_launcher_id, index); 1278 CreateAppShortcutLauncherItem(pref_app_launcher_id, "", index);
1270 } 1279 }
1271 ++index; 1280 ++index;
1272 } 1281 }
1273 1282
1274 // At second step remove any pin to the right from the current index. 1283 // At second step remove any pin to the right from the current index.
1275 while (index < model_->item_count()) { 1284 while (index < model_->item_count()) {
1276 const ash::ShelfItem item = model_->items()[index]; 1285 const ash::ShelfItem item = model_->items()[index];
1277 if (item.type != ash::TYPE_APP_SHORTCUT) { 1286 if (item.type != ash::TYPE_APP_SHORTCUT) {
1278 ++index; 1287 ++index;
1279 continue; 1288 continue;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 LauncherItemController* controller = GetLauncherItemController(item.id); 1559 LauncherItemController* controller = GetLauncherItemController(item.id);
1551 if (!controller || controller->image_set_by_controller()) 1560 if (!controller || controller->image_set_by_controller())
1552 continue; 1561 continue;
1553 item.image = image; 1562 item.image = image;
1554 if (arc_deferred_launcher_) 1563 if (arc_deferred_launcher_)
1555 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1564 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1556 model_->Set(index, item); 1565 model_->Set(index, item);
1557 // It's possible we're waiting on more than one item, so don't break. 1566 // It's possible we're waiting on more than one item, so don't break.
1558 } 1567 }
1559 } 1568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698