| 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.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include "ash/multi_profile_uma.h" | 7 #include "ash/multi_profile_uma.h" |
| 8 #include "ash/public/cpp/shelf_item.h" | 8 #include "ash/public/cpp/shelf_item.h" |
| 9 #include "ash/public/interfaces/constants.mojom.h" | 9 #include "ash/public/interfaces/constants.mojom.h" |
| 10 #include "ash/resources/grit/ash_resources.h" | 10 #include "ash/resources/grit/ash_resources.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 RemoveShelfItem(id); | 347 RemoveShelfItem(id); |
| 348 } | 348 } |
| 349 | 349 |
| 350 bool ChromeLauncherController::IsPinned(const ash::ShelfID& id) { | 350 bool ChromeLauncherController::IsPinned(const ash::ShelfID& id) { |
| 351 const ash::ShelfItem* item = GetItem(id); | 351 const ash::ShelfItem* item = GetItem(id); |
| 352 return item && ItemTypeIsPinned(*item); | 352 return item && ItemTypeIsPinned(*item); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void ChromeLauncherController::SetV1AppStatus(const std::string& app_id, | 355 void ChromeLauncherController::SetV1AppStatus(const std::string& app_id, |
| 356 ash::ShelfItemStatus status) { | 356 ash::ShelfItemStatus status) { |
| 357 ash::ShelfID id = GetShelfIDForAppID(app_id); | 357 ash::ShelfID id(app_id); |
| 358 const ash::ShelfItem* item = GetItem(id); | 358 const ash::ShelfItem* item = GetItem(id); |
| 359 if (item) { | 359 if (item) { |
| 360 if (!IsPinned(id) && status == ash::STATUS_CLOSED) | 360 if (!IsPinned(id) && status == ash::STATUS_CLOSED) |
| 361 RemoveShelfItem(id); | 361 RemoveShelfItem(id); |
| 362 else | 362 else |
| 363 SetItemStatus(id, status); | 363 SetItemStatus(id, status); |
| 364 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { | 364 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { |
| 365 InsertAppLauncherItem( | 365 InsertAppLauncherItem( |
| 366 AppShortcutLauncherItemController::Create(ash::ShelfID(app_id)), status, | 366 AppShortcutLauncherItemController::Create(ash::ShelfID(app_id)), status, |
| 367 model_->item_count(), ash::TYPE_APP); | 367 model_->item_count(), ash::TYPE_APP); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 378 return; // May happen if menu closed. | 378 return; // May happen if menu closed. |
| 379 delegate->Close(); | 379 delegate->Close(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 bool ChromeLauncherController::IsOpen(const ash::ShelfID& id) { | 382 bool ChromeLauncherController::IsOpen(const ash::ShelfID& id) { |
| 383 const ash::ShelfItem* item = GetItem(id); | 383 const ash::ShelfItem* item = GetItem(id); |
| 384 return item && item->status != ash::STATUS_CLOSED; | 384 return item && item->status != ash::STATUS_CLOSED; |
| 385 } | 385 } |
| 386 | 386 |
| 387 bool ChromeLauncherController::IsPlatformApp(const ash::ShelfID& id) { | 387 bool ChromeLauncherController::IsPlatformApp(const ash::ShelfID& id) { |
| 388 std::string app_id = GetAppIDForShelfID(id); | |
| 389 const extensions::Extension* extension = | 388 const extensions::Extension* extension = |
| 390 GetExtensionForAppID(app_id, profile()); | 389 GetExtensionForAppID(id.app_id, profile()); |
| 391 // An extension can be synced / updated at any time and therefore not be | 390 // An extension can be synced / updated at any time and therefore not be |
| 392 // available. | 391 // available. |
| 393 return extension ? extension->is_platform_app() : false; | 392 return extension ? extension->is_platform_app() : false; |
| 394 } | 393 } |
| 395 | 394 |
| 396 void ChromeLauncherController::LaunchApp(const ash::ShelfID& id, | 395 void ChromeLauncherController::LaunchApp(const ash::ShelfID& id, |
| 397 ash::ShelfLaunchSource source, | 396 ash::ShelfLaunchSource source, |
| 398 int event_flags) { | 397 int event_flags) { |
| 399 launcher_controller_helper_->LaunchApp(id, source, event_flags); | 398 launcher_controller_helper_->LaunchApp(id, source, event_flags); |
| 400 } | 399 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 425 const ash::ShelfItem* item = GetItem(shelf_id); | 424 const ash::ShelfItem* item = GetItem(shelf_id); |
| 426 if (item) { | 425 if (item) { |
| 427 ash::ShelfItem new_item = *item; | 426 ash::ShelfItem new_item = *item; |
| 428 new_item.image = image; | 427 new_item.image = image; |
| 429 model_->Set(model_->ItemIndexByID(shelf_id), new_item); | 428 model_->Set(model_->ItemIndexByID(shelf_id), new_item); |
| 430 } | 429 } |
| 431 } | 430 } |
| 432 | 431 |
| 433 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, | 432 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, |
| 434 AppState app_state) { | 433 AppState app_state) { |
| 435 std::string app_id = launcher_controller_helper_->GetAppID(contents); | 434 ash::ShelfID shelf_id(launcher_controller_helper_->GetAppID(contents)); |
| 436 | 435 |
| 437 // Check if the gMail app is loaded and it matches the given content. | 436 // Check if the gMail app is loaded and it matches the given content. |
| 438 // This special treatment is needed to address crbug.com/234268. | 437 // This special treatment is needed to address crbug.com/234268. |
| 439 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 438 if (shelf_id.IsNull() && ContentCanBeHandledByGmailApp(contents)) |
| 440 app_id = kGmailAppId; | 439 shelf_id = ash::ShelfID(kGmailAppId); |
| 441 | 440 |
| 442 // Check the old |app_id| for a tab. If the contents has changed we need to | 441 // If the tab changed apps, remove its association with the previous app item. |
| 443 // remove it from the previous app. | |
| 444 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { | 442 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { |
| 445 std::string last_app_id = web_contents_to_app_id_[contents]; | 443 ash::ShelfID old_id(web_contents_to_app_id_[contents]); |
| 446 if (last_app_id != app_id) { | 444 if (old_id != shelf_id && GetItem(old_id) != nullptr) { |
| 447 ash::ShelfID id = GetShelfIDForAppID(last_app_id); | 445 // Since GetAppState() will use |web_contents_to_app_id_| we remove |
| 448 if (!id.IsNull()) { | 446 // the connection before calling it. |
| 449 // Since GetAppState() will use |web_contents_to_app_id_| we remove | 447 web_contents_to_app_id_.erase(contents); |
| 450 // the connection before calling it. | 448 SetItemStatus(old_id, GetAppState(old_id.app_id)); |
| 451 web_contents_to_app_id_.erase(contents); | |
| 452 SetItemStatus(id, GetAppState(last_app_id)); | |
| 453 } | |
| 454 } | 449 } |
| 455 } | 450 } |
| 456 | 451 |
| 457 if (app_state == APP_STATE_REMOVED) | 452 if (app_state == APP_STATE_REMOVED) |
| 458 web_contents_to_app_id_.erase(contents); | 453 web_contents_to_app_id_.erase(contents); |
| 459 else | 454 else |
| 460 web_contents_to_app_id_[contents] = app_id; | 455 web_contents_to_app_id_[contents] = shelf_id.app_id; |
| 461 | 456 |
| 462 ash::ShelfID id = GetShelfIDForAppID(app_id); | 457 SetItemStatus(shelf_id, (app_state == APP_STATE_WINDOW_ACTIVE || |
| 463 if (!id.IsNull()) { | 458 app_state == APP_STATE_ACTIVE) |
| 464 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || | 459 ? ash::STATUS_ACTIVE |
| 465 app_state == APP_STATE_ACTIVE) | 460 : GetAppState(shelf_id.app_id)); |
| 466 ? ash::STATUS_ACTIVE | |
| 467 : GetAppState(app_id)); | |
| 468 } | |
| 469 } | 461 } |
| 470 | 462 |
| 471 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( | 463 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( |
| 472 content::WebContents* contents) { | 464 content::WebContents* contents) { |
| 473 std::string app_id = launcher_controller_helper_->GetAppID(contents); | 465 std::string app_id = launcher_controller_helper_->GetAppID(contents); |
| 474 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 466 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
| 475 app_id = kGmailAppId; | 467 app_id = kGmailAppId; |
| 476 | 468 |
| 477 ash::ShelfID id = GetShelfIDForAppID(app_id); | |
| 478 // If there is no dedicated app item, use the browser shortcut item. | 469 // If there is no dedicated app item, use the browser shortcut item. |
| 479 return id.IsNull() ? GetShelfIDForAppID(kChromeAppId) : id; | 470 const ash::ShelfItem* item = GetItem(ash::ShelfID(app_id)); |
| 471 return item ? item->id : ash::ShelfID(kChromeAppId); |
| 480 } | 472 } |
| 481 | 473 |
| 482 void ChromeLauncherController::SetRefocusURLPatternForTest( | 474 void ChromeLauncherController::SetRefocusURLPatternForTest( |
| 483 const ash::ShelfID& id, | 475 const ash::ShelfID& id, |
| 484 const GURL& url) { | 476 const GURL& url) { |
| 485 const ash::ShelfItem* item = GetItem(id); | 477 const ash::ShelfItem* item = GetItem(id); |
| 486 if (item && !IsPlatformApp(id) && | 478 if (item && !IsPlatformApp(id) && |
| 487 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { | 479 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { |
| 488 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | 480 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
| 489 AppShortcutLauncherItemController* item_controller = | 481 AppShortcutLauncherItemController* item_controller = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 ash::MenuItemList ChromeLauncherController::GetAppMenuItemsForTesting( | 559 ash::MenuItemList ChromeLauncherController::GetAppMenuItemsForTesting( |
| 568 const ash::ShelfItem& item) { | 560 const ash::ShelfItem& item) { |
| 569 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id); | 561 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id); |
| 570 return delegate ? delegate->GetAppMenuItems(ui::EF_NONE) | 562 return delegate ? delegate->GetAppMenuItems(ui::EF_NONE) |
| 571 : ash::MenuItemList(); | 563 : ash::MenuItemList(); |
| 572 } | 564 } |
| 573 | 565 |
| 574 std::vector<content::WebContents*> | 566 std::vector<content::WebContents*> |
| 575 ChromeLauncherController::GetV1ApplicationsFromAppId( | 567 ChromeLauncherController::GetV1ApplicationsFromAppId( |
| 576 const std::string& app_id) { | 568 const std::string& app_id) { |
| 577 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 569 const ash::ShelfItem* item = GetItem(ash::ShelfID(app_id)); |
| 578 // If there is no such item pinned to the launcher, no menu gets created. | 570 // If there is no such item pinned to the launcher, no menu gets created. |
| 579 if (!item || item->type != ash::TYPE_PINNED_APP) | 571 if (!item || item->type != ash::TYPE_PINNED_APP) |
| 580 return std::vector<content::WebContents*>(); | 572 return std::vector<content::WebContents*>(); |
| 581 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); | 573 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); |
| 582 AppShortcutLauncherItemController* item_controller = | 574 AppShortcutLauncherItemController* item_controller = |
| 583 static_cast<AppShortcutLauncherItemController*>(delegate); | 575 static_cast<AppShortcutLauncherItemController*>(delegate); |
| 584 return item_controller->GetRunningApplications(); | 576 return item_controller->GetRunningApplications(); |
| 585 } | 577 } |
| 586 | 578 |
| 587 void ChromeLauncherController::ActivateShellApp(const std::string& app_id, | 579 void ChromeLauncherController::ActivateShellApp(const std::string& app_id, |
| 588 int window_index) { | 580 int window_index) { |
| 589 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 581 const ash::ShelfItem* item = GetItem(ash::ShelfID(app_id)); |
| 590 if (item && | 582 if (item && |
| 591 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { | 583 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { |
| 592 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); | 584 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); |
| 593 AppWindowLauncherItemController* item_controller = | 585 AppWindowLauncherItemController* item_controller = |
| 594 delegate->AsAppWindowLauncherItemController(); | 586 delegate->AsAppWindowLauncherItemController(); |
| 595 item_controller->ActivateIndexedApp(window_index); | 587 item_controller->ActivateIndexedApp(window_index); |
| 596 } | 588 } |
| 597 } | 589 } |
| 598 | 590 |
| 599 bool ChromeLauncherController::IsWebContentHandledByApplication( | 591 bool ChromeLauncherController::IsWebContentHandledByApplication( |
| 600 content::WebContents* web_contents, | 592 content::WebContents* web_contents, |
| 601 const std::string& app_id) { | 593 const std::string& app_id) { |
| 602 if ((web_contents_to_app_id_.find(web_contents) != | 594 if ((web_contents_to_app_id_.find(web_contents) != |
| 603 web_contents_to_app_id_.end()) && | 595 web_contents_to_app_id_.end()) && |
| 604 (web_contents_to_app_id_[web_contents] == app_id)) | 596 (web_contents_to_app_id_[web_contents] == app_id)) |
| 605 return true; | 597 return true; |
| 606 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); | 598 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); |
| 607 } | 599 } |
| 608 | 600 |
| 609 bool ChromeLauncherController::ContentCanBeHandledByGmailApp( | 601 bool ChromeLauncherController::ContentCanBeHandledByGmailApp( |
| 610 content::WebContents* web_contents) { | 602 content::WebContents* web_contents) { |
| 611 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); | 603 if (GetItem(ash::ShelfID(kGmailAppId)) != nullptr) { |
| 612 if (!id.IsNull()) { | |
| 613 const GURL url = web_contents->GetURL(); | 604 const GURL url = web_contents->GetURL(); |
| 614 // We need to extend the application matching for the gMail app beyond the | 605 // We need to extend the application matching for the gMail app beyond the |
| 615 // manifest file's specification. This is required because of the namespace | 606 // manifest file's specification. This is required because of the namespace |
| 616 // overlap with the offline app ("/mail/mu/"). | 607 // overlap with the offline app ("/mail/mu/"). |
| 617 if (!base::MatchPattern(url.path(), "/mail/mu/*") && | 608 if (!base::MatchPattern(url.path(), "/mail/mu/*") && |
| 618 base::MatchPattern(url.path(), "/mail/*") && | 609 base::MatchPattern(url.path(), "/mail/*") && |
| 619 GetExtensionForAppID(kGmailAppId, profile()) && | 610 GetExtensionForAppID(kGmailAppId, profile()) && |
| 620 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url)) | 611 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url)) |
| 621 return true; | 612 return true; |
| 622 } | 613 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 648 const extensions::Extension* extension = | 639 const extensions::Extension* extension = |
| 649 GetExtensionForAppID(app_id, profile()); | 640 GetExtensionForAppID(app_id, profile()); |
| 650 if (extension) | 641 if (extension) |
| 651 return base::UTF8ToUTF16(extension->name()); | 642 return base::UTF8ToUTF16(extension->name()); |
| 652 } | 643 } |
| 653 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 644 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 654 } | 645 } |
| 655 | 646 |
| 656 BrowserShortcutLauncherItemController* | 647 BrowserShortcutLauncherItemController* |
| 657 ChromeLauncherController::GetBrowserShortcutLauncherItemController() { | 648 ChromeLauncherController::GetBrowserShortcutLauncherItemController() { |
| 658 ash::ShelfID id = GetShelfIDForAppID(kChromeAppId); | 649 ash::ShelfID id(kChromeAppId); |
| 659 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | 650 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
| 660 DCHECK(delegate) << "There should be always be a browser shortcut item."; | 651 DCHECK(delegate) << "There should be always be a browser shortcut item."; |
| 661 return static_cast<BrowserShortcutLauncherItemController*>(delegate); | 652 return static_cast<BrowserShortcutLauncherItemController*>(delegate); |
| 662 } | 653 } |
| 663 | 654 |
| 664 bool ChromeLauncherController::ShelfBoundsChangesProbablyWithUser( | 655 bool ChromeLauncherController::ShelfBoundsChangesProbablyWithUser( |
| 665 ash::WmShelf* shelf, | 656 ash::WmShelf* shelf, |
| 666 const AccountId& account_id) const { | 657 const AccountId& account_id) const { |
| 667 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); | 658 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); |
| 668 if (!other_profile || other_profile == profile()) | 659 if (!other_profile || other_profile == profile()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 687 void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) { | 678 void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) { |
| 688 if (user_switch_observer_.get()) | 679 if (user_switch_observer_.get()) |
| 689 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 680 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| 690 } | 681 } |
| 691 | 682 |
| 692 ArcAppDeferredLauncherController* | 683 ArcAppDeferredLauncherController* |
| 693 ChromeLauncherController::GetArcDeferredLauncher() { | 684 ChromeLauncherController::GetArcDeferredLauncher() { |
| 694 return arc_deferred_launcher_.get(); | 685 return arc_deferred_launcher_.get(); |
| 695 } | 686 } |
| 696 | 687 |
| 697 const std::string& ChromeLauncherController::GetLaunchIDForShelfID( | |
| 698 const ash::ShelfID& id) { | |
| 699 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | |
| 700 return delegate ? delegate->launch_id() : base::EmptyString(); | |
| 701 } | |
| 702 | |
| 703 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | 688 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
| 704 const std::string& app_id) { | 689 const std::string& app_id) { |
| 705 for (const auto& app_icon_loader : app_icon_loaders_) { | 690 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 706 if (app_icon_loader->CanLoadImageForApp(app_id)) | 691 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 707 return app_icon_loader.get(); | 692 return app_icon_loader.get(); |
| 708 } | 693 } |
| 709 | 694 |
| 710 return nullptr; | 695 return nullptr; |
| 711 } | 696 } |
| 712 | 697 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { | 741 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { |
| 757 app_icon_loaders_.clear(); | 742 app_icon_loaders_.clear(); |
| 758 for (auto& loader : loaders) | 743 for (auto& loader : loaders) |
| 759 app_icon_loaders_.push_back(std::move(loader)); | 744 app_icon_loaders_.push_back(std::move(loader)); |
| 760 } | 745 } |
| 761 | 746 |
| 762 void ChromeLauncherController::SetProfileForTest(Profile* profile) { | 747 void ChromeLauncherController::SetProfileForTest(Profile* profile) { |
| 763 profile_ = profile; | 748 profile_ = profile; |
| 764 } | 749 } |
| 765 | 750 |
| 766 ash::ShelfID ChromeLauncherController::GetShelfIDForAppID( | |
| 767 const std::string& app_id) { | |
| 768 return model_->GetShelfIDForAppID(app_id); | |
| 769 } | |
| 770 | |
| 771 ash::ShelfID ChromeLauncherController::GetShelfIDForAppIDAndLaunchID( | |
| 772 const std::string& app_id, | |
| 773 const std::string& launch_id) { | |
| 774 return model_->GetShelfIDForAppIDAndLaunchID(app_id, launch_id); | |
| 775 } | |
| 776 | |
| 777 const std::string& ChromeLauncherController::GetAppIDForShelfID( | |
| 778 const ash::ShelfID& id) { | |
| 779 return model_->GetAppIDForShelfID(id); | |
| 780 } | |
| 781 | |
| 782 void ChromeLauncherController::PinAppWithID(const std::string& app_id) { | 751 void ChromeLauncherController::PinAppWithID(const std::string& app_id) { |
| 783 model_->PinAppWithID(app_id); | 752 model_->PinAppWithID(app_id); |
| 784 } | 753 } |
| 785 | 754 |
| 786 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { | 755 bool ChromeLauncherController::IsAppPinned(const std::string& app_id) { |
| 787 return model_->IsAppPinned(app_id); | 756 return model_->IsAppPinned(app_id); |
| 788 } | 757 } |
| 789 | 758 |
| 790 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) { | 759 void ChromeLauncherController::UnpinAppWithID(const std::string& app_id) { |
| 791 model_->UnpinAppWithID(app_id); | 760 model_->UnpinAppWithID(app_id); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 816 if (app_icon_loader) | 785 if (app_icon_loader) |
| 817 app_icon_loader->UpdateImage(app_id); | 786 app_icon_loader->UpdateImage(app_id); |
| 818 } | 787 } |
| 819 | 788 |
| 820 void ChromeLauncherController::OnAppUninstalledPrepared( | 789 void ChromeLauncherController::OnAppUninstalledPrepared( |
| 821 content::BrowserContext* browser_context, | 790 content::BrowserContext* browser_context, |
| 822 const std::string& app_id) { | 791 const std::string& app_id) { |
| 823 // Since we might have windowed apps of this type which might have | 792 // Since we might have windowed apps of this type which might have |
| 824 // outstanding locks which needs to be removed. | 793 // outstanding locks which needs to be removed. |
| 825 const Profile* profile = Profile::FromBrowserContext(browser_context); | 794 const Profile* profile = Profile::FromBrowserContext(browser_context); |
| 826 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); | 795 ash::ShelfID shelf_id(app_id); |
| 827 if (!shelf_id.IsNull()) | 796 if (GetItem(shelf_id) != nullptr) |
| 828 CloseWindowedAppsFromRemovedExtension(app_id, profile); | 797 CloseWindowedAppsFromRemovedExtension(app_id, profile); |
| 829 | 798 |
| 830 if (IsAppPinned(app_id)) { | 799 // Some apps may be removed locally. Unpin the item without removing the pin |
| 831 if (profile == this->profile() && !shelf_id.IsNull()) { | 800 // position from profile preferences. When needed, it is automatically deleted |
| 832 // Some apps may be removed locally. Unpin the item without removing the | 801 // on app list model update. |
| 833 // pin position from profile preferences. When needed, it is automatically | 802 if (IsAppPinned(app_id) && profile == this->profile()) |
| 834 // deleted on app list model update. | 803 UnpinShelfItemInternal(shelf_id); |
| 835 UnpinShelfItemInternal(shelf_id); | |
| 836 } | |
| 837 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | |
| 838 if (app_icon_loader) | |
| 839 app_icon_loader->ClearImage(app_id); | |
| 840 } | |
| 841 } | 804 } |
| 842 | 805 |
| 843 /////////////////////////////////////////////////////////////////////////////// | 806 /////////////////////////////////////////////////////////////////////////////// |
| 844 // AppIconLoaderDelegate: | 807 // AppIconLoaderDelegate: |
| 845 | 808 |
| 846 void ChromeLauncherController::OnAppImageUpdated(const std::string& app_id, | 809 void ChromeLauncherController::OnAppImageUpdated(const std::string& app_id, |
| 847 const gfx::ImageSkia& image) { | 810 const gfx::ImageSkia& image) { |
| 848 // TODO: need to get this working for shortcuts. | 811 // TODO: need to get this working for shortcuts. |
| 849 for (int index = 0; index < model_->item_count(); ++index) { | 812 for (int index = 0; index < model_->item_count(); ++index) { |
| 850 ash::ShelfItem item = model_->items()[index]; | 813 ash::ShelfItem item = model_->items()[index]; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 int index) { | 849 int index) { |
| 887 return InsertAppLauncherItem( | 850 return InsertAppLauncherItem( |
| 888 AppShortcutLauncherItemController::Create(shelf_id), ash::STATUS_CLOSED, | 851 AppShortcutLauncherItemController::Create(shelf_id), ash::STATUS_CLOSED, |
| 889 index, ash::TYPE_PINNED_APP); | 852 index, ash::TYPE_PINNED_APP); |
| 890 } | 853 } |
| 891 | 854 |
| 892 void ChromeLauncherController::RememberUnpinnedRunningApplicationOrder() { | 855 void ChromeLauncherController::RememberUnpinnedRunningApplicationOrder() { |
| 893 RunningAppListIds list; | 856 RunningAppListIds list; |
| 894 for (int i = 0; i < model_->item_count(); i++) { | 857 for (int i = 0; i < model_->item_count(); i++) { |
| 895 if (model_->items()[i].type == ash::TYPE_APP) | 858 if (model_->items()[i].type == ash::TYPE_APP) |
| 896 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); | 859 list.push_back(model_->items()[i].id.app_id); |
| 897 } | 860 } |
| 898 const std::string user_email = | 861 const std::string user_email = |
| 899 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); | 862 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); |
| 900 last_used_running_application_order_[user_email] = list; | 863 last_used_running_application_order_[user_email] = list; |
| 901 } | 864 } |
| 902 | 865 |
| 903 void ChromeLauncherController::RestoreUnpinnedRunningApplicationOrder( | 866 void ChromeLauncherController::RestoreUnpinnedRunningApplicationOrder( |
| 904 const std::string& user_id) { | 867 const std::string& user_id) { |
| 905 const RunningAppListIdMap::iterator app_id_list = | 868 const RunningAppListIdMap::iterator app_id_list = |
| 906 last_used_running_application_order_.find(user_id); | 869 last_used_running_application_order_.find(user_id); |
| 907 if (app_id_list == last_used_running_application_order_.end()) | 870 if (app_id_list == last_used_running_application_order_.end()) |
| 908 return; | 871 return; |
| 909 | 872 |
| 910 // Find the first insertion point for running applications. | 873 // Find the first insertion point for running applications. |
| 911 int running_index = model_->FirstRunningAppIndex(); | 874 int running_index = model_->FirstRunningAppIndex(); |
| 912 for (const std::string& app_id : app_id_list->second) { | 875 for (const std::string& app_id : app_id_list->second) { |
| 913 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 876 const ash::ShelfItem* item = GetItem(ash::ShelfID(app_id)); |
| 914 if (item && item->type == ash::TYPE_APP) { | 877 if (item && item->type == ash::TYPE_APP) { |
| 915 int app_index = model_->ItemIndexByID(item->id); | 878 int app_index = model_->ItemIndexByID(item->id); |
| 916 DCHECK_GE(app_index, 0); | 879 DCHECK_GE(app_index, 0); |
| 917 if (running_index != app_index) | 880 if (running_index != app_index) |
| 918 model_->Move(running_index, app_index); | 881 model_->Move(running_index, app_index); |
| 919 running_index++; | 882 running_index++; |
| 920 } | 883 } |
| 921 } | 884 } |
| 922 } | 885 } |
| 923 | 886 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 947 } | 910 } |
| 948 | 911 |
| 949 void ChromeLauncherController::SyncPinPosition(const ash::ShelfID& shelf_id) { | 912 void ChromeLauncherController::SyncPinPosition(const ash::ShelfID& shelf_id) { |
| 950 DCHECK(should_sync_pin_changes_); | 913 DCHECK(should_sync_pin_changes_); |
| 951 DCHECK(!shelf_id.IsNull()); | 914 DCHECK(!shelf_id.IsNull()); |
| 952 | 915 |
| 953 const int max_index = model_->item_count(); | 916 const int max_index = model_->item_count(); |
| 954 const int index = model_->ItemIndexByID(shelf_id); | 917 const int index = model_->ItemIndexByID(shelf_id); |
| 955 DCHECK_GT(index, 0); | 918 DCHECK_GT(index, 0); |
| 956 | 919 |
| 957 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 920 ash::ShelfID shelf_id_before; |
| 958 DCHECK(!app_id.empty()); | |
| 959 const std::string& launch_id = GetLaunchIDForShelfID(shelf_id); | |
| 960 | |
| 961 std::string app_id_before; | |
| 962 std::string launch_id_before; | |
| 963 std::vector<ash::ShelfID> shelf_ids_after; | 921 std::vector<ash::ShelfID> shelf_ids_after; |
| 964 | 922 |
| 965 for (int i = index - 1; i > 0; --i) { | 923 for (int i = index - 1; i > 0; --i) { |
| 966 const ash::ShelfID shelf_id_before = model_->items()[i].id; | 924 shelf_id_before = model_->items()[i].id; |
| 967 if (IsPinned(shelf_id_before)) { | 925 if (IsPinned(shelf_id_before)) |
| 968 app_id_before = GetAppIDForShelfID(shelf_id_before); | |
| 969 DCHECK(!app_id_before.empty()); | |
| 970 launch_id_before = GetLaunchIDForShelfID(shelf_id_before); | |
| 971 break; | 926 break; |
| 972 } | |
| 973 } | 927 } |
| 974 | 928 |
| 975 for (int i = index + 1; i < max_index; ++i) { | 929 for (int i = index + 1; i < max_index; ++i) { |
| 976 const ash::ShelfID shelf_id_after = model_->items()[i].id; | 930 const ash::ShelfID& shelf_id_after = model_->items()[i].id; |
| 977 if (IsPinned(shelf_id_after)) { | 931 if (IsPinned(shelf_id_after)) |
| 978 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); | 932 shelf_ids_after.push_back(shelf_id_after); |
| 979 DCHECK(!app_id_after.empty()); | |
| 980 const std::string launch_id_after = GetLaunchIDForShelfID(shelf_id_after); | |
| 981 shelf_ids_after.push_back(ash::ShelfID(app_id_after, launch_id_after)); | |
| 982 } | |
| 983 } | 933 } |
| 984 | 934 |
| 985 ash::ShelfID shelf_id_before = ash::ShelfID(app_id_before, launch_id_before); | 935 SetPinPosition(profile(), shelf_id, shelf_id_before, shelf_ids_after); |
| 986 SetPinPosition(profile(), ash::ShelfID(app_id, launch_id), shelf_id_before, | |
| 987 shelf_ids_after); | |
| 988 } | 936 } |
| 989 | 937 |
| 990 void ChromeLauncherController::OnSyncModelUpdated() { | 938 void ChromeLauncherController::OnSyncModelUpdated() { |
| 991 UpdateAppLaunchersFromPref(); | 939 UpdateAppLaunchersFromPref(); |
| 992 } | 940 } |
| 993 | 941 |
| 994 void ChromeLauncherController::OnIsSyncingChanged() { | 942 void ChromeLauncherController::OnIsSyncingChanged() { |
| 995 UpdateAppLaunchersFromPref(); | 943 UpdateAppLaunchersFromPref(); |
| 996 } | 944 } |
| 997 | 945 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); | 1410 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
| 1463 | 1411 |
| 1464 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); | 1412 const int app_list_index = model_->GetItemIndexForType(ash::TYPE_APP_LIST); |
| 1465 DCHECK_GE(app_list_index, 0); | 1413 DCHECK_GE(app_list_index, 0); |
| 1466 ash::ShelfItem item = model_->items()[app_list_index]; | 1414 ash::ShelfItem item = model_->items()[app_list_index]; |
| 1467 if (item.title != title) { | 1415 if (item.title != title) { |
| 1468 item.title = title; | 1416 item.title = title; |
| 1469 model_->Set(app_list_index, item); | 1417 model_->Set(app_list_index, item); |
| 1470 } | 1418 } |
| 1471 } | 1419 } |
| OLD | NEW |