| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() { | 257 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() { |
| 258 // Reset the BrowserStatusMonitor as it has a weak pointer to this. | 258 // Reset the BrowserStatusMonitor as it has a weak pointer to this. |
| 259 browser_status_monitor_.reset(); | 259 browser_status_monitor_.reset(); |
| 260 | 260 |
| 261 // Reset the app window controllers here since it has a weak pointer to this. | 261 // Reset the app window controllers here since it has a weak pointer to this. |
| 262 app_window_controllers_.clear(); | 262 app_window_controllers_.clear(); |
| 263 | 263 |
| 264 model_->RemoveObserver(this); | 264 model_->RemoveObserver(this); |
| 265 if (ash::Shell::HasInstance()) | 265 if (ash::Shell::HasInstance()) |
| 266 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 266 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
| 267 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 267 for (const auto& pair : id_to_item_controller_map_) { |
| 268 i != id_to_item_controller_map_.end(); ++i) { | 268 int index = model_->ItemIndexByID(pair.first); |
| 269 int index = model_->ItemIndexByID(i->first); | |
| 270 // A "browser proxy" is not known to the model and this removal does | 269 // A "browser proxy" is not known to the model and this removal does |
| 271 // therefore not need to be propagated to the model. | 270 // therefore not need to be propagated to the model. |
| 272 if (index != -1 && | 271 if (index != -1 && |
| 273 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) | 272 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) |
| 274 model_->RemoveItemAt(index); | 273 model_->RemoveItemAt(index); |
| 275 } | 274 } |
| 276 | 275 |
| 277 // Release all profile dependent resources. | 276 // Release all profile dependent resources. |
| 278 ReleaseProfile(); | 277 ReleaseProfile(); |
| 279 | 278 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 294 } | 293 } |
| 295 | 294 |
| 296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 295 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
| 297 LauncherItemController* controller, | 296 LauncherItemController* controller, |
| 298 const std::string& app_id, | 297 const std::string& app_id, |
| 299 ash::ShelfItemStatus status) { | 298 ash::ShelfItemStatus status) { |
| 300 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(), | 299 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(), |
| 301 ash::TYPE_APP); | 300 ash::TYPE_APP); |
| 302 } | 301 } |
| 303 | 302 |
| 304 const ash::ShelfItem& ChromeLauncherControllerImpl::GetItem( | 303 const ash::ShelfItem* ChromeLauncherControllerImpl::GetItem( |
| 305 ash::ShelfID id) const { | 304 ash::ShelfID id) const { |
| 306 const int index = model_->ItemIndexByID(id); | 305 const int index = model_->ItemIndexByID(id); |
| 307 DCHECK_GE(index, 0); | 306 if (index >= 0 && index < model_->item_count()) |
| 308 return model_->items()[index]; | 307 return &model_->items()[index]; |
| 308 return nullptr; |
| 309 } | 309 } |
| 310 | 310 |
| 311 void ChromeLauncherControllerImpl::SetItemType(ash::ShelfID id, | 311 void ChromeLauncherControllerImpl::SetItemType(ash::ShelfID id, |
| 312 ash::ShelfItemType type) { | 312 ash::ShelfItemType type) { |
| 313 const int index = model_->ItemIndexByID(id); | 313 const ash::ShelfItem* item = GetItem(id); |
| 314 DCHECK_GE(index, 0); | 314 if (item && item->type != type) { |
| 315 ash::ShelfItem item = model_->items()[index]; | 315 ash::ShelfItem new_item = *item; |
| 316 if (item.type != type) { | 316 new_item.type = type; |
| 317 item.type = type; | 317 model_->Set(model_->ItemIndexByID(id), new_item); |
| 318 model_->Set(index, item); | |
| 319 } | 318 } |
| 320 } | 319 } |
| 321 | 320 |
| 322 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, | 321 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, |
| 323 ash::ShelfItemStatus status) { | 322 ash::ShelfItemStatus status) { |
| 324 const int index = model_->ItemIndexByID(id); | 323 const ash::ShelfItem* item = GetItem(id); |
| 325 DCHECK_GE(index, 0); | 324 if (item && item->status != status) { |
| 326 ash::ShelfItem item = model_->items()[index]; | 325 ash::ShelfItem new_item = *item; |
| 327 if (item.status != status) { | 326 new_item.status = status; |
| 328 item.status = status; | 327 model_->Set(model_->ItemIndexByID(id), new_item); |
| 329 model_->Set(index, item); | |
| 330 } | 328 } |
| 331 } | 329 } |
| 332 | 330 |
| 333 void ChromeLauncherControllerImpl::SetItemController( | 331 void ChromeLauncherControllerImpl::SetItemController( |
| 334 ash::ShelfID id, | 332 ash::ShelfID id, |
| 335 LauncherItemController* controller) { | 333 LauncherItemController* controller) { |
| 336 CHECK(controller); | 334 CHECK(controller); |
| 337 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 335 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 338 CHECK(iter != id_to_item_controller_map_.end()); | 336 CHECK(iter != id_to_item_controller_map_.end()); |
| 339 controller->set_shelf_id(id); | 337 controller->set_shelf_id(id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 356 iter->second->set_shelf_id(id); | 354 iter->second->set_shelf_id(id); |
| 357 // Existing controller is destroyed and replaced by registering again. | 355 // Existing controller is destroyed and replaced by registering again. |
| 358 SetShelfItemDelegate(id, iter->second); | 356 SetShelfItemDelegate(id, iter->second); |
| 359 } else { | 357 } else { |
| 360 LauncherItemClosed(id); | 358 LauncherItemClosed(id); |
| 361 } | 359 } |
| 362 } | 360 } |
| 363 | 361 |
| 364 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { | 362 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { |
| 365 DCHECK(HasShelfIDToAppIDMapping(id)); | 363 DCHECK(HasShelfIDToAppIDMapping(id)); |
| 366 | 364 const ash::ShelfItem* item = GetItem(id); |
| 367 int index = model_->ItemIndexByID(id); | 365 if (item && item->type == ash::TYPE_APP) |
| 368 DCHECK_GE(index, 0); | 366 SetItemType(id, ash::TYPE_APP_SHORTCUT); |
| 369 | 367 else if (!item || item->type != ash::TYPE_APP_SHORTCUT) |
| 370 ash::ShelfItem item = model_->items()[index]; | |
| 371 | |
| 372 if (item.type == ash::TYPE_APP) { | |
| 373 item.type = ash::TYPE_APP_SHORTCUT; | |
| 374 model_->Set(index, item); | |
| 375 } else if (item.type != ash::TYPE_APP_SHORTCUT) { | |
| 376 return; | 368 return; |
| 377 } | |
| 378 | 369 |
| 379 SyncPinPosition(id); | 370 SyncPinPosition(id); |
| 380 } | 371 } |
| 381 | 372 |
| 382 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 373 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
| 383 UnpinAndUpdatePrefs(id, true /* update_prefs */); | 374 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
| 384 } | 375 } |
| 385 | 376 |
| 386 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, | 377 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
| 387 bool update_prefs) { | 378 bool update_prefs) { |
| 388 LauncherItemController* controller = GetLauncherItemController(id); | 379 LauncherItemController* controller = GetLauncherItemController(id); |
| 389 CHECK(controller); | 380 CHECK(controller); |
| 390 | 381 |
| 391 if (update_prefs) { | 382 if (update_prefs) { |
| 392 ash::launcher::RemovePinPosition( | 383 ash::launcher::RemovePinPosition( |
| 393 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), | 384 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), |
| 394 GetLaunchIDForShelfID(id))); | 385 GetLaunchIDForShelfID(id))); |
| 395 } | 386 } |
| 396 | 387 |
| 397 if (GetItem(id).status != ash::STATUS_CLOSED || controller->locked()) | 388 const ash::ShelfItem* item = GetItem(id); |
| 389 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) |
| 398 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 390 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
| 399 else | 391 else |
| 400 LauncherItemClosed(id); | 392 LauncherItemClosed(id); |
| 401 } | 393 } |
| 402 | 394 |
| 403 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 395 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
| 404 int index = model_->ItemIndexByID(id); | 396 const ash::ShelfItem* item = GetItem(id); |
| 405 if (index < 0) | 397 return item && (item->type == ash::TYPE_APP_SHORTCUT || |
| 406 return false; | 398 item->type == ash::TYPE_BROWSER_SHORTCUT); |
| 407 ash::ShelfItemType type = model_->items()[index].type; | |
| 408 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); | |
| 409 } | 399 } |
| 410 | 400 |
| 411 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) { | 401 void ChromeLauncherControllerImpl::TogglePinned(ash::ShelfID id) { |
| 412 if (!HasShelfIDToAppIDMapping(id)) | 402 if (!HasShelfIDToAppIDMapping(id)) |
| 413 return; // May happen if item closed with menu open. | 403 return; // May happen if item closed with menu open. |
| 414 | 404 |
| 415 if (IsPinned(id)) | 405 if (IsPinned(id)) |
| 416 Unpin(id); | 406 Unpin(id); |
| 417 else | 407 else |
| 418 Pin(id); | 408 Pin(id); |
| 419 } | 409 } |
| 420 | 410 |
| 421 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { | 411 bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { |
| 422 int index = model_->ItemIndexByID(id); | 412 const ash::ShelfItem* item = GetItem(id); |
| 423 if (index == -1) | 413 return (item && (item->type == ash::TYPE_APP_SHORTCUT || |
| 424 return false; | 414 item->type == ash::TYPE_APP) && |
| 425 | |
| 426 ash::ShelfItemType type = model_->items()[index].type; | |
| 427 std::string app_id; | |
| 428 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && | |
| 429 model_->GetShelfItemDelegate(id)->CanPin()); | 415 model_->GetShelfItemDelegate(id)->CanPin()); |
| 430 } | 416 } |
| 431 | 417 |
| 432 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { | 418 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { |
| 433 ash::ShelfID id = GetShelfIDForAppID(app_id); | 419 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 434 if (id == ash::kInvalidShelfID) { | 420 if (id == ash::kInvalidShelfID) { |
| 435 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), | 421 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), |
| 436 model_->item_count(), ash::TYPE_APP); | 422 model_->item_count(), ash::TYPE_APP); |
| 437 id = GetShelfIDForAppID(app_id); | 423 id = GetShelfIDForAppID(app_id); |
| 438 } | 424 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 458 } | 444 } |
| 459 | 445 |
| 460 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { | 446 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { |
| 461 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | 447 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
| 462 if (!delegate) | 448 if (!delegate) |
| 463 return; // May happen if menu closed. | 449 return; // May happen if menu closed. |
| 464 delegate->Close(); | 450 delegate->Close(); |
| 465 } | 451 } |
| 466 | 452 |
| 467 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { | 453 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { |
| 468 const int index = model_->ItemIndexByID(id); | 454 const ash::ShelfItem* item = GetItem(id); |
| 469 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED; | 455 return item && item->status != ash::STATUS_CLOSED; |
| 470 } | 456 } |
| 471 | 457 |
| 472 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { | 458 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { |
| 473 if (!HasShelfIDToAppIDMapping(id)) | 459 if (!HasShelfIDToAppIDMapping(id)) |
| 474 return false; | 460 return false; |
| 475 | 461 |
| 476 std::string app_id = GetAppIDForShelfID(id); | 462 std::string app_id = GetAppIDForShelfID(id); |
| 477 const Extension* extension = GetExtensionForAppID(app_id, profile()); | 463 const Extension* extension = GetExtensionForAppID(app_id, profile()); |
| 478 // An extension can be synced / updated at any time and therefore not be | 464 // An extension can be synced / updated at any time and therefore not be |
| 479 // available. | 465 // available. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 510 if (!extension) | 496 if (!extension) |
| 511 return extensions::LAUNCH_TYPE_DEFAULT; | 497 return extensions::LAUNCH_TYPE_DEFAULT; |
| 512 | 498 |
| 513 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()), | 499 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()), |
| 514 extension); | 500 extension); |
| 515 } | 501 } |
| 516 | 502 |
| 517 void ChromeLauncherControllerImpl::SetLauncherItemImage( | 503 void ChromeLauncherControllerImpl::SetLauncherItemImage( |
| 518 ash::ShelfID shelf_id, | 504 ash::ShelfID shelf_id, |
| 519 const gfx::ImageSkia& image) { | 505 const gfx::ImageSkia& image) { |
| 520 int index = model_->ItemIndexByID(shelf_id); | 506 const ash::ShelfItem* item = GetItem(shelf_id); |
| 521 if (index == -1) | 507 if (item) { |
| 522 return; | 508 ash::ShelfItem new_item = *item; |
| 523 ash::ShelfItem item = model_->items()[index]; | 509 new_item.image = image; |
| 524 item.image = image; | 510 model_->Set(model_->ItemIndexByID(shelf_id), new_item); |
| 525 model_->Set(index, item); | 511 } |
| 526 } | 512 } |
| 527 | 513 |
| 528 void ChromeLauncherControllerImpl::SetLaunchType( | 514 void ChromeLauncherControllerImpl::SetLaunchType( |
| 529 ash::ShelfID id, | 515 ash::ShelfID id, |
| 530 extensions::LaunchType launch_type) { | 516 extensions::LaunchType launch_type) { |
| 531 LauncherItemController* controller = GetLauncherItemController(id); | 517 LauncherItemController* controller = GetLauncherItemController(id); |
| 532 if (!controller) | 518 if (!controller) |
| 533 return; | 519 return; |
| 534 | 520 |
| 535 extensions::SetLaunchType(profile(), controller->app_id(), launch_type); | 521 extensions::SetLaunchType(profile(), controller->app_id(), launch_type); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | 575 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
| 590 return model_->items()[browser_index].id; | 576 return model_->items()[browser_index].id; |
| 591 } | 577 } |
| 592 | 578 |
| 593 return id; | 579 return id; |
| 594 } | 580 } |
| 595 | 581 |
| 596 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( | 582 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( |
| 597 ash::ShelfID id, | 583 ash::ShelfID id, |
| 598 const GURL& url) { | 584 const GURL& url) { |
| 599 int index = model_->ItemIndexByID(id); | 585 const ash::ShelfItem* item = GetItem(id); |
| 600 if (index == -1) { | 586 if (item && !IsPlatformApp(id) && |
| 601 NOTREACHED() << "Invalid launcher id"; | 587 (item->type == ash::TYPE_APP_SHORTCUT || item->type == ash::TYPE_APP)) { |
| 602 return; | |
| 603 } | |
| 604 | |
| 605 ash::ShelfItemType type = model_->items()[index].type; | |
| 606 if ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_APP) && | |
| 607 !IsPlatformApp(id)) { | |
| 608 LauncherItemController* controller = GetLauncherItemController(id); | 588 LauncherItemController* controller = GetLauncherItemController(id); |
| 609 DCHECK(controller); | 589 DCHECK(controller); |
| 610 AppShortcutLauncherItemController* app_controller = | 590 AppShortcutLauncherItemController* app_controller = |
| 611 static_cast<AppShortcutLauncherItemController*>(controller); | 591 static_cast<AppShortcutLauncherItemController*>(controller); |
| 612 app_controller->set_refocus_url(url); | 592 app_controller->set_refocus_url(url); |
| 613 } else { | 593 } else { |
| 614 NOTREACHED() << "Invalid launcher type"; | 594 NOTREACHED() << "Invalid launcher item or type"; |
| 615 } | 595 } |
| 616 } | 596 } |
| 617 | 597 |
| 618 ash::ShelfItemDelegate::PerformedAction | 598 ash::ShelfItemDelegate::PerformedAction |
| 619 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 599 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
| 620 ui::BaseWindow* window, | 600 ui::BaseWindow* window, |
| 621 bool allow_minimize) { | 601 bool allow_minimize) { |
| 622 // In separated desktop mode we might have to teleport a window back to the | 602 // In separated desktop mode we might have to teleport a window back to the |
| 623 // current user. | 603 // current user. |
| 624 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == | 604 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( | 660 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
| 681 Profile* profile) { | 661 Profile* profile) { |
| 682 // Switch the running applications to the new user. | 662 // Switch the running applications to the new user. |
| 683 for (auto& controller : app_window_controllers_) | 663 for (auto& controller : app_window_controllers_) |
| 684 controller->AdditionalUserAddedToSession(profile); | 664 controller->AdditionalUserAddedToSession(profile); |
| 685 } | 665 } |
| 686 | 666 |
| 687 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( | 667 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( |
| 688 const ash::ShelfItem& item, | 668 const ash::ShelfItem& item, |
| 689 int event_flags) { | 669 int event_flags) { |
| 690 // Make sure that there is a controller associated with the id and that the | |
| 691 // extension itself is a valid application and not a panel. | |
| 692 LauncherItemController* controller = GetLauncherItemController(item.id); | 670 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 693 if (!controller || !GetShelfIDForAppID(controller->app_id())) | 671 return controller ? controller->GetApplicationList(event_flags) |
| 694 return ChromeLauncherAppMenuItems(); | 672 : ChromeLauncherAppMenuItems(); |
| 695 | |
| 696 return controller->GetApplicationList(event_flags); | |
| 697 } | 673 } |
| 698 | 674 |
| 699 std::vector<content::WebContents*> | 675 std::vector<content::WebContents*> |
| 700 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 676 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| 701 const std::string& app_id) { | 677 const std::string& app_id) { |
| 702 ash::ShelfID id = GetShelfIDForAppID(app_id); | 678 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 703 // If there is no such item pinned to the launcher, no menu gets created. | 679 // If there is no such item pinned to the launcher, no menu gets created. |
| 704 if (id != ash::kInvalidShelfID && | 680 if (!item || item->type != ash::TYPE_APP_SHORTCUT) |
| 705 GetItem(id).type == ash::TYPE_APP_SHORTCUT) { | 681 return std::vector<content::WebContents*>(); |
| 706 LauncherItemController* controller = GetLauncherItemController(id); | 682 LauncherItemController* controller = GetLauncherItemController(item->id); |
| 707 AppShortcutLauncherItemController* app_controller = | 683 AppShortcutLauncherItemController* app_controller = |
| 708 static_cast<AppShortcutLauncherItemController*>(controller); | 684 static_cast<AppShortcutLauncherItemController*>(controller); |
| 709 return app_controller->GetRunningApplications(); | 685 return app_controller->GetRunningApplications(); |
| 710 } | |
| 711 return std::vector<content::WebContents*>(); | |
| 712 } | 686 } |
| 713 | 687 |
| 714 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, | 688 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
| 715 int window_index) { | 689 int window_index) { |
| 716 ash::ShelfID id = GetShelfIDForAppID(app_id); | 690 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 717 if (id != ash::kInvalidShelfID && GetItem(id).type == ash::TYPE_APP) { | 691 if (item && item->type == ash::TYPE_APP) { |
| 718 LauncherItemController* controller = GetLauncherItemController(id); | 692 LauncherItemController* controller = GetLauncherItemController(item->id); |
| 719 AppWindowLauncherItemController* app_window_controller = | 693 AppWindowLauncherItemController* app_window_controller = |
| 720 static_cast<AppWindowLauncherItemController*>(controller); | 694 static_cast<AppWindowLauncherItemController*>(controller); |
| 721 app_window_controller->ActivateIndexedApp(window_index); | 695 app_window_controller->ActivateIndexedApp(window_index); |
| 722 } | 696 } |
| 723 } | 697 } |
| 724 | 698 |
| 725 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( | 699 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
| 726 content::WebContents* web_contents, | 700 content::WebContents* web_contents, |
| 727 const std::string& app_id) { | 701 const std::string& app_id) { |
| 728 if ((web_contents_to_app_id_.find(web_contents) != | 702 if ((web_contents_to_app_id_.find(web_contents) != |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 const extensions::Extension* extension = | 748 const extensions::Extension* extension = |
| 775 GetExtensionForAppID(app_id, profile()); | 749 GetExtensionForAppID(app_id, profile()); |
| 776 if (extension) | 750 if (extension) |
| 777 return base::UTF8ToUTF16(extension->name()); | 751 return base::UTF8ToUTF16(extension->name()); |
| 778 } | 752 } |
| 779 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 753 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 780 } | 754 } |
| 781 | 755 |
| 782 BrowserShortcutLauncherItemController* | 756 BrowserShortcutLauncherItemController* |
| 783 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { | 757 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
| 784 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 758 for (const auto& pair : id_to_item_controller_map_) { |
| 785 i != id_to_item_controller_map_.end(); ++i) { | 759 const ash::ShelfItem* item = GetItem(pair.first); |
| 786 int index = model_->ItemIndexByID(i->first); | 760 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT) |
| 787 const ash::ShelfItem& item = model_->items()[index]; | 761 return static_cast<BrowserShortcutLauncherItemController*>(pair.second); |
| 788 if (item.type == ash::TYPE_BROWSER_SHORTCUT) | |
| 789 return static_cast<BrowserShortcutLauncherItemController*>(i->second); | |
| 790 } | 762 } |
| 791 NOTREACHED() | 763 NOTREACHED() |
| 792 << "There should be always be a BrowserShortcutLauncherItemController."; | 764 << "There should be always be a BrowserShortcutLauncherItemController."; |
| 793 return nullptr; | 765 return nullptr; |
| 794 } | 766 } |
| 795 | 767 |
| 796 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 768 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
| 797 const ash::ShelfID id) { | 769 const ash::ShelfID id) { |
| 798 if (!HasShelfIDToAppIDMapping(id)) | 770 if (!HasShelfIDToAppIDMapping(id)) |
| 799 return nullptr; | 771 return nullptr; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 if (GetPinnableForAppID(shelf_app_id, profile()) == | 909 if (GetPinnableForAppID(shelf_app_id, profile()) == |
| 938 AppListControllerDelegate::PIN_EDITABLE) | 910 AppListControllerDelegate::PIN_EDITABLE) |
| 939 DoPinAppWithID(shelf_app_id); | 911 DoPinAppWithID(shelf_app_id); |
| 940 else | 912 else |
| 941 NOTREACHED(); | 913 NOTREACHED(); |
| 942 } | 914 } |
| 943 | 915 |
| 944 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { | 916 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { |
| 945 const std::string shelf_app_id = | 917 const std::string shelf_app_id = |
| 946 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 918 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
| 947 for (IDToItemControllerMap::const_iterator i = | 919 for (const auto& pair : id_to_item_controller_map_) { |
| 948 id_to_item_controller_map_.begin(); | 920 if (IsPinned(pair.first) && pair.second->app_id() == shelf_app_id) |
| 949 i != id_to_item_controller_map_.end(); ++i) { | |
| 950 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id) | |
| 951 return true; | 921 return true; |
| 952 } | 922 } |
| 953 return false; | 923 return false; |
| 954 } | 924 } |
| 955 | 925 |
| 956 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { | 926 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| 957 const std::string shelf_app_id = | 927 const std::string shelf_app_id = |
| 958 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 928 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
| 959 if (GetPinnableForAppID(shelf_app_id, profile()) == | 929 if (GetPinnableForAppID(shelf_app_id, profile()) == |
| 960 AppListControllerDelegate::PIN_EDITABLE) | 930 AppListControllerDelegate::PIN_EDITABLE) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 | 1007 |
| 1038 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( | 1008 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( |
| 1039 const std::string& user_id) { | 1009 const std::string& user_id) { |
| 1040 const RunningAppListIdMap::iterator app_id_list = | 1010 const RunningAppListIdMap::iterator app_id_list = |
| 1041 last_used_running_application_order_.find(user_id); | 1011 last_used_running_application_order_.find(user_id); |
| 1042 if (app_id_list == last_used_running_application_order_.end()) | 1012 if (app_id_list == last_used_running_application_order_.end()) |
| 1043 return; | 1013 return; |
| 1044 | 1014 |
| 1045 // Find the first insertion point for running applications. | 1015 // Find the first insertion point for running applications. |
| 1046 int running_index = model_->FirstRunningAppIndex(); | 1016 int running_index = model_->FirstRunningAppIndex(); |
| 1047 for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); | 1017 for (const std::string& app_id : app_id_list->second) { |
| 1048 app_id != app_id_list->second.end(); ++app_id) { | 1018 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 1049 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); | 1019 if (item && item->type == ash::TYPE_APP) { |
| 1050 if (shelf_id) { | 1020 int app_index = model_->ItemIndexByID(item->id); |
| 1051 int app_index = model_->ItemIndexByID(shelf_id); | |
| 1052 DCHECK_GE(app_index, 0); | 1021 DCHECK_GE(app_index, 0); |
| 1053 if (model_->items()[app_index].type == ash::TYPE_APP) { | 1022 if (running_index != app_index) |
| 1054 if (running_index != app_index) | 1023 model_->Move(running_index, app_index); |
| 1055 model_->Move(running_index, app_index); | 1024 running_index++; |
| 1056 running_index++; | |
| 1057 } | |
| 1058 } | 1025 } |
| 1059 } | 1026 } |
| 1060 } | 1027 } |
| 1061 | 1028 |
| 1062 ash::ShelfID | 1029 ash::ShelfID |
| 1063 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( | 1030 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( |
| 1064 const ash::launcher::AppLauncherId& app_launcher_id, | 1031 const ash::launcher::AppLauncherId& app_launcher_id, |
| 1065 int index, | 1032 int index, |
| 1066 ash::ShelfItemType shelf_item_type) { | 1033 ash::ShelfItemType shelf_item_type) { |
| 1067 AppShortcutLauncherItemController* controller = | 1034 AppShortcutLauncherItemController* controller = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, | 1076 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id, |
| 1110 bool update_prefs) { | 1077 bool update_prefs) { |
| 1111 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); | 1078 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); |
| 1112 if (shelf_id && IsPinned(shelf_id)) | 1079 if (shelf_id && IsPinned(shelf_id)) |
| 1113 UnpinAndUpdatePrefs(shelf_id, update_prefs); | 1080 UnpinAndUpdatePrefs(shelf_id, update_prefs); |
| 1114 } | 1081 } |
| 1115 | 1082 |
| 1116 void ChromeLauncherControllerImpl::PinRunningAppInternal( | 1083 void ChromeLauncherControllerImpl::PinRunningAppInternal( |
| 1117 int index, | 1084 int index, |
| 1118 ash::ShelfID shelf_id) { | 1085 ash::ShelfID shelf_id) { |
| 1086 DCHECK_EQ(GetItem(shelf_id)->type, ash::TYPE_APP); |
| 1087 SetItemType(shelf_id, ash::TYPE_APP_SHORTCUT); |
| 1119 int running_index = model_->ItemIndexByID(shelf_id); | 1088 int running_index = model_->ItemIndexByID(shelf_id); |
| 1120 ash::ShelfItem item = model_->items()[running_index]; | |
| 1121 DCHECK_EQ(item.type, ash::TYPE_APP); | |
| 1122 item.type = ash::TYPE_APP_SHORTCUT; | |
| 1123 model_->Set(running_index, item); | |
| 1124 // The |ShelfModel|'s weight system might reposition the item to a | |
| 1125 // new index, so we get the index again. | |
| 1126 running_index = model_->ItemIndexByID(shelf_id); | |
| 1127 if (running_index < index) | 1089 if (running_index < index) |
| 1128 --index; | 1090 --index; |
| 1129 if (running_index != index) | 1091 if (running_index != index) |
| 1130 model_->Move(running_index, index); | 1092 model_->Move(running_index, index); |
| 1131 } | 1093 } |
| 1132 | 1094 |
| 1133 void ChromeLauncherControllerImpl::UnpinRunningAppInternal(int index) { | 1095 void ChromeLauncherControllerImpl::UnpinRunningAppInternal(int index) { |
| 1134 DCHECK_GE(index, 0); | 1096 DCHECK(index >= 0 && index < model_->item_count()); |
| 1135 ash::ShelfItem item = model_->items()[index]; | 1097 ash::ShelfItem item = model_->items()[index]; |
| 1136 DCHECK_EQ(item.type, ash::TYPE_APP_SHORTCUT); | 1098 DCHECK_EQ(item.type, ash::TYPE_APP_SHORTCUT); |
| 1137 item.type = ash::TYPE_APP; | 1099 SetItemType(item.id, ash::TYPE_APP); |
| 1138 model_->Set(index, item); | |
| 1139 } | 1100 } |
| 1140 | 1101 |
| 1141 void ChromeLauncherControllerImpl::SyncPinPosition(ash::ShelfID shelf_id) { | 1102 void ChromeLauncherControllerImpl::SyncPinPosition(ash::ShelfID shelf_id) { |
| 1142 DCHECK(shelf_id); | 1103 DCHECK(shelf_id); |
| 1143 if (ignore_persist_pinned_state_change_) | 1104 if (ignore_persist_pinned_state_change_) |
| 1144 return; | 1105 return; |
| 1145 | 1106 |
| 1146 const int max_index = model_->item_count(); | 1107 const int max_index = model_->item_count(); |
| 1147 const int index = model_->ItemIndexByID(shelf_id); | 1108 const int index = model_->ItemIndexByID(shelf_id); |
| 1148 DCHECK_GT(index, 0); | 1109 DCHECK_GT(index, 0); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 LauncherItemController* controller = GetLauncherItemController(item.id); | 1491 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1531 if (!controller || controller->image_set_by_controller()) | 1492 if (!controller || controller->image_set_by_controller()) |
| 1532 continue; | 1493 continue; |
| 1533 item.image = image; | 1494 item.image = image; |
| 1534 if (arc_deferred_launcher_) | 1495 if (arc_deferred_launcher_) |
| 1535 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1496 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1536 model_->Set(index, item); | 1497 model_->Set(index, item); |
| 1537 // It's possible we're waiting on more than one item, so don't break. | 1498 // It's possible we're waiting on more than one item, so don't break. |
| 1538 } | 1499 } |
| 1539 } | 1500 } |
| OLD | NEW |