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

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: Created 4 years, 1 month 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 333
334 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { 334 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) {
335 CHECK(id); 335 CHECK(id);
336 if (IsPinned(id)) { 336 if (IsPinned(id)) {
337 // Create a new shortcut controller. 337 // Create a new shortcut controller.
338 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 338 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
339 CHECK(iter != id_to_item_controller_map_.end()); 339 CHECK(iter != id_to_item_controller_map_.end());
340 SetItemStatus(id, ash::STATUS_CLOSED); 340 SetItemStatus(id, ash::STATUS_CLOSED);
341 std::string app_id = iter->second->app_id(); 341 std::string app_id = iter->second->app_id();
342 std::string launch_id = iter->second->launch_id(); 342 std::string launch_id = iter->second->launch_id();
343 iter->second = 343 std::string title = iter->second->title();
344 AppShortcutLauncherItemController::Create(app_id, launch_id, this); 344 iter->second = AppShortcutLauncherItemController::Create(app_id, launch_id,
345 title, this);
345 iter->second->set_shelf_id(id); 346 iter->second->set_shelf_id(id);
346 // Existing controller is destroyed and replaced by registering again. 347 // Existing controller is destroyed and replaced by registering again.
347 SetShelfItemDelegate(id, iter->second); 348 SetShelfItemDelegate(id, iter->second);
348 } else { 349 } else {
349 LauncherItemClosed(id); 350 LauncherItemClosed(id);
350 } 351 }
351 } 352 }
352 353
353 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 354 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
354 DCHECK(HasShelfIDToAppIDMapping(id)); 355 DCHECK(HasShelfIDToAppIDMapping(id));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 std::string app_id; 420 std::string app_id;
420 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP || 421 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP ||
421 type == ash::TYPE_WINDOWED_APP) && 422 type == ash::TYPE_WINDOWED_APP) &&
422 model_->GetShelfItemDelegate(id)->CanPin()); 423 model_->GetShelfItemDelegate(id)->CanPin());
423 } 424 }
424 425
425 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 426 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
426 ash::ShelfID id = GetShelfIDForAppID(app_id); 427 ash::ShelfID id = GetShelfIDForAppID(app_id);
427 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { 428 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) {
428 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), 429 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id),
429 model_->item_count(), 430 "", model_->item_count(),
430 ash::TYPE_WINDOWED_APP); 431 ash::TYPE_WINDOWED_APP);
431 id = GetShelfIDForAppID(app_id); 432 id = GetShelfIDForAppID(app_id);
432 } 433 }
433 CHECK(id); 434 CHECK(id);
434 id_to_item_controller_map_[id]->lock(); 435 id_to_item_controller_map_[id]->lock();
435 } 436 }
436 437
437 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 438 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
438 const std::string& app_id) { 439 const std::string& app_id) {
439 ash::ShelfID id = GetShelfIDForAppID(app_id); 440 ash::ShelfID id = GetShelfIDForAppID(app_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 ash::ShelfID id = GetShelfIDForAppID(app_id); 485 ash::ShelfID id = GetShelfIDForAppID(app_id);
485 if (id) { 486 if (id) {
486 LauncherItemController* controller = GetLauncherItemController(id); 487 LauncherItemController* controller = GetLauncherItemController(id);
487 controller->Activate(source); 488 controller->Activate(source);
488 return; 489 return;
489 } 490 }
490 491
491 // Create a temporary application launcher item and use it to see if there are 492 // Create a temporary application launcher item and use it to see if there are
492 // running instances. 493 // running instances.
493 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 494 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
494 AppShortcutLauncherItemController::Create(app_id, "", this)); 495 AppShortcutLauncherItemController::Create(app_id, "", "", this));
495 if (!app_controller->GetRunningApplications().empty()) 496 if (!app_controller->GetRunningApplications().empty())
496 app_controller->Activate(source); 497 app_controller->Activate(source);
497 else 498 else
498 LaunchApp(app_id, source, event_flags); 499 LaunchApp(app_id, source, event_flags);
499 } 500 }
500 501
501 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( 502 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType(
502 ash::ShelfID id) { 503 ash::ShelfID id) {
503 const Extension* extension = 504 const Extension* extension =
504 GetExtensionForAppID(GetAppIDForShelfID(id), profile()); 505 GetExtensionForAppID(GetAppIDForShelfID(id), profile());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { 845 ChromeLauncherControllerImpl::GetArcDeferredLauncher() {
845 return arc_deferred_launcher_.get(); 846 return arc_deferred_launcher_.get();
846 } 847 }
847 848
848 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( 849 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID(
849 ash::ShelfID id) { 850 ash::ShelfID id) {
850 LauncherItemController* controller = GetLauncherItemController(id); 851 LauncherItemController* controller = GetLauncherItemController(id);
851 return controller ? controller->launch_id() : base::EmptyString(); 852 return controller ? controller->launch_id() : base::EmptyString();
852 } 853 }
853 854
855 const std::string& ChromeLauncherControllerImpl::GetTitleForShelfID(
856 ash::ShelfID id) {
857 LauncherItemController* controller = GetLauncherItemController(id);
858 return controller ? controller->title() : base::EmptyString();
859 }
860
854 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { 861 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) {
855 // The base class implementation updates the helper and app icon loaders. 862 // The base class implementation updates the helper and app icon loaders.
856 ChromeLauncherController::AttachProfile(profile_to_attach); 863 ChromeLauncherController::AttachProfile(profile_to_attach);
857 864
858 pref_change_registrar_.Init(profile()->GetPrefs()); 865 pref_change_registrar_.Init(profile()->GetPrefs());
859 pref_change_registrar_.Add( 866 pref_change_registrar_.Add(
860 prefs::kPolicyPinnedLauncherApps, 867 prefs::kPolicyPinnedLauncherApps,
861 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, 868 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref,
862 base::Unretained(this))); 869 base::Unretained(this)));
863 // Handling of prefs::kArcEnabled change should be called deferred to avoid 870 // Handling of prefs::kArcEnabled change should be called deferred to avoid
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 if (app_icon_loader) 1025 if (app_icon_loader)
1019 app_icon_loader->ClearImage(app_id); 1026 app_icon_loader->ClearImage(app_id);
1020 } 1027 }
1021 } 1028 }
1022 1029
1023 /////////////////////////////////////////////////////////////////////////////// 1030 ///////////////////////////////////////////////////////////////////////////////
1024 // ChromeLauncherControllerImpl protected: 1031 // ChromeLauncherControllerImpl protected:
1025 1032
1026 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 1033 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
1027 const ash::launcher::AppLauncherId& app_launcher_id, 1034 const ash::launcher::AppLauncherId& app_launcher_id,
1035 const std::string& title,
1028 int index) { 1036 int index) {
1029 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, 1037 return CreateAppShortcutLauncherItemWithType(app_launcher_id, title, index,
1030 ash::TYPE_APP_SHORTCUT); 1038 ash::TYPE_APP_SHORTCUT);
1031 } 1039 }
1032 1040
1033 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( 1041 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest(
1034 ash::ShelfID id) { 1042 ash::ShelfID id) {
1035 return id_to_item_controller_map_[id]->app_id(); 1043 return id_to_item_controller_map_[id]->app_id();
1036 } 1044 }
1037 1045
1038 /////////////////////////////////////////////////////////////////////////////// 1046 ///////////////////////////////////////////////////////////////////////////////
1039 // ChromeLauncherControllerImpl private: 1047 // ChromeLauncherControllerImpl private:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 model_->Move(running_index, app_index); 1079 model_->Move(running_index, app_index);
1072 running_index++; 1080 running_index++;
1073 } 1081 }
1074 } 1082 }
1075 } 1083 }
1076 } 1084 }
1077 1085
1078 ash::ShelfID 1086 ash::ShelfID
1079 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1087 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1080 const ash::launcher::AppLauncherId& app_launcher_id, 1088 const ash::launcher::AppLauncherId& app_launcher_id,
1089 const std::string& title,
1081 int index, 1090 int index,
1082 ash::ShelfItemType shelf_item_type) { 1091 ash::ShelfItemType shelf_item_type) {
1083 AppShortcutLauncherItemController* controller = 1092 AppShortcutLauncherItemController* controller =
1084 AppShortcutLauncherItemController::Create( 1093 AppShortcutLauncherItemController::Create(
1085 app_launcher_id.app_id(), app_launcher_id.launch_id(), this); 1094 app_launcher_id.app_id(), app_launcher_id.launch_id(), title, this);
1086 ash::ShelfID shelf_id = 1095 ash::ShelfID shelf_id =
1087 InsertAppLauncherItem(controller, app_launcher_id.app_id(), 1096 InsertAppLauncherItem(controller, app_launcher_id.app_id(),
1088 ash::STATUS_CLOSED, index, shelf_item_type); 1097 ash::STATUS_CLOSED, index, shelf_item_type);
1089 return shelf_id; 1098 return shelf_id;
1090 } 1099 }
1091 1100
1092 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1101 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1093 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1102 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1094 CHECK(iter != id_to_item_controller_map_.end()); 1103 CHECK(iter != id_to_item_controller_map_.end());
1095 CHECK(iter->second); 1104 CHECK(iter->second);
(...skipping 14 matching lines...) Expand all
1110 if (IsAppPinned(app_id)) 1119 if (IsAppPinned(app_id))
1111 return; 1120 return;
1112 1121
1113 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1122 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1114 if (shelf_id) { 1123 if (shelf_id) {
1115 // App item exists, pin it 1124 // App item exists, pin it
1116 Pin(shelf_id); 1125 Pin(shelf_id);
1117 } else { 1126 } else {
1118 // Otherwise, create a shortcut item for it. 1127 // Otherwise, create a shortcut item for it.
1119 shelf_id = CreateAppShortcutLauncherItem( 1128 shelf_id = CreateAppShortcutLauncherItem(
1120 ash::launcher::AppLauncherId(app_id), model_->item_count()); 1129 ash::launcher::AppLauncherId(app_id), "", model_->item_count());
1121 SyncPinPosition(shelf_id); 1130 SyncPinPosition(shelf_id);
1122 } 1131 }
1123 } 1132 }
1124 1133
1125 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, 1134 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id,
1126 bool update_prefs) { 1135 bool update_prefs) {
1127 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1136 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id);
1128 if (shelf_id && IsPinned(shelf_id)) 1137 if (shelf_id && IsPinned(shelf_id))
1129 UnpinAndUpdatePrefs(shelf_id, update_prefs); 1138 UnpinAndUpdatePrefs(shelf_id, update_prefs);
1130 } 1139 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 item.type == ash::TYPE_BROWSER_SHORTCUT) { 1280 item.type == ash::TYPE_BROWSER_SHORTCUT) {
1272 // Just move to required position or keep it inplace. 1281 // Just move to required position or keep it inplace.
1273 model_->Move(app_index, index); 1282 model_->Move(app_index, index);
1274 } else { 1283 } else {
1275 PinRunningAppInternal(index, item.id); 1284 PinRunningAppInternal(index, item.id);
1276 } 1285 }
1277 DCHECK_EQ(model_->ItemIndexByID(item.id), index); 1286 DCHECK_EQ(model_->ItemIndexByID(item.id), index);
1278 } else { 1287 } else {
1279 // This is fresh pin. Create new one. 1288 // This is fresh pin. Create new one.
1280 DCHECK_NE(app_id, extension_misc::kChromeAppId); 1289 DCHECK_NE(app_id, extension_misc::kChromeAppId);
1281 CreateAppShortcutLauncherItem(pref_app_launcher_id, index); 1290 CreateAppShortcutLauncherItem(pref_app_launcher_id, "", index);
1282 } 1291 }
1283 ++index; 1292 ++index;
1284 } 1293 }
1285 1294
1286 // At second step remove any pin to the right from the current index. 1295 // At second step remove any pin to the right from the current index.
1287 while (index < model_->item_count()) { 1296 while (index < model_->item_count()) {
1288 const ash::ShelfItem item = model_->items()[index]; 1297 const ash::ShelfItem item = model_->items()[index];
1289 if (item.type != ash::TYPE_APP_SHORTCUT) { 1298 if (item.type != ash::TYPE_APP_SHORTCUT) {
1290 ++index; 1299 ++index;
1291 continue; 1300 continue;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 if (index == -1) 1578 if (index == -1)
1570 continue; 1579 continue;
1571 ash::ShelfItem item = model_->items()[index]; 1580 ash::ShelfItem item = model_->items()[index];
1572 item.image = image; 1581 item.image = image;
1573 if (arc_deferred_launcher_) 1582 if (arc_deferred_launcher_)
1574 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1583 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1575 model_->Set(index, item); 1584 model_->Set(index, item);
1576 // It's possible we're waiting on more than one item, so don't break. 1585 // It's possible we're waiting on more than one item, so don't break.
1577 } 1586 }
1578 } 1587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698