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

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

Issue 2290603002: Enhance chrome.app.window API for shelf integration with pinning support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 348 }
349 349
350 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { 350 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) {
351 CHECK(id); 351 CHECK(id);
352 if (IsPinned(id)) { 352 if (IsPinned(id)) {
353 // Create a new shortcut controller. 353 // Create a new shortcut controller.
354 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 354 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
355 CHECK(iter != id_to_item_controller_map_.end()); 355 CHECK(iter != id_to_item_controller_map_.end());
356 SetItemStatus(id, ash::STATUS_CLOSED); 356 SetItemStatus(id, ash::STATUS_CLOSED);
357 std::string app_id = iter->second->app_id(); 357 std::string app_id = iter->second->app_id();
358 iter->second = AppShortcutLauncherItemController::Create(app_id, this); 358 std::string app_shelf_id = iter->second->app_id();
359 if (iter->second->type() == LauncherItemController::TYPE_APP) {
360 AppWindowLauncherItemController* app_window_controller =
361 static_cast<AppWindowLauncherItemController*>(iter->second);
362 app_shelf_id = app_window_controller->app_shelf_id();
363 }
364 iter->second =
365 AppShortcutLauncherItemController::Create(app_id, app_shelf_id, this);
359 iter->second->set_shelf_id(id); 366 iter->second->set_shelf_id(id);
360 // Existing controller is destroyed and replaced by registering again. 367 // Existing controller is destroyed and replaced by registering again.
361 SetShelfItemDelegate(id, iter->second); 368 SetShelfItemDelegate(id, iter->second);
362 } else { 369 } else {
363 LauncherItemClosed(id); 370 LauncherItemClosed(id);
364 } 371 }
365 } 372 }
366 373
367 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 374 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
368 DCHECK(HasShelfIDToAppIDMapping(id)); 375 DCHECK(HasShelfIDToAppIDMapping(id));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return false; 428 return false;
422 429
423 ash::ShelfItemType type = model_->items()[index].type; 430 ash::ShelfItemType type = model_->items()[index].type;
424 std::string app_id; 431 std::string app_id;
425 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP || 432 return ((type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_PLATFORM_APP ||
426 type == ash::TYPE_WINDOWED_APP) && 433 type == ash::TYPE_WINDOWED_APP) &&
427 model_->GetShelfItemDelegate(id)->CanPin()); 434 model_->GetShelfItemDelegate(id)->CanPin());
428 } 435 }
429 436
430 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 437 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
431 ash::ShelfID id = GetShelfIDForAppID(app_id); 438 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
432 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { 439 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) {
433 CreateAppShortcutLauncherItemWithType(app_id, model_->item_count(), 440 CreateAppShortcutLauncherItemWithType(app_id, model_->item_count(),
434 ash::TYPE_WINDOWED_APP); 441 ash::TYPE_WINDOWED_APP);
435 id = GetShelfIDForAppID(app_id); 442 id = GetShelfIDForAppID(app_id, app_id);
436 } 443 }
437 CHECK(id); 444 CHECK(id);
438 id_to_item_controller_map_[id]->lock(); 445 id_to_item_controller_map_[id]->lock();
439 } 446 }
440 447
441 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 448 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
442 const std::string& app_id) { 449 const std::string& app_id) {
443 ash::ShelfID id = GetShelfIDForAppID(app_id); 450 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
444 CHECK(id); 451 CHECK(id);
445 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); 452 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id));
446 LauncherItemController* controller = id_to_item_controller_map_[id]; 453 LauncherItemController* controller = id_to_item_controller_map_[id];
447 controller->unlock(); 454 controller->unlock();
448 if (!controller->locked() && !IsPinned(id)) 455 if (!controller->locked() && !IsPinned(id))
449 CloseLauncherItem(id); 456 CloseLauncherItem(id);
450 } 457 }
451 458
452 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { 459 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) {
453 LauncherItemController* controller = GetLauncherItemController(id); 460 LauncherItemController* controller = GetLauncherItemController(id);
(...skipping 30 matching lines...) Expand all
484 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id, 491 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id,
485 ash::LaunchSource source, 492 ash::LaunchSource source,
486 int event_flags) { 493 int event_flags) {
487 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); 494 launcher_controller_helper_->LaunchApp(app_id, source, event_flags);
488 } 495 }
489 496
490 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, 497 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id,
491 ash::LaunchSource source, 498 ash::LaunchSource source,
492 int event_flags) { 499 int event_flags) {
493 // If there is an existing non-shortcut controller for this app, open it. 500 // If there is an existing non-shortcut controller for this app, open it.
494 ash::ShelfID id = GetShelfIDForAppID(app_id); 501 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
495 if (id) { 502 if (id) {
496 LauncherItemController* controller = GetLauncherItemController(id); 503 LauncherItemController* controller = GetLauncherItemController(id);
497 controller->Activate(source); 504 controller->Activate(source);
498 return; 505 return;
499 } 506 }
500 507
501 // Create a temporary application launcher item and use it to see if there are 508 // Create a temporary application launcher item and use it to see if there are
502 // running instances. 509 // running instances.
503 std::unique_ptr<AppShortcutLauncherItemController> app_controller( 510 std::unique_ptr<AppShortcutLauncherItemController> app_controller(
504 AppShortcutLauncherItemController::Create(app_id, this)); 511 AppShortcutLauncherItemController::Create(app_id, app_id, this));
505 if (!app_controller->GetRunningApplications().empty()) 512 if (!app_controller->GetRunningApplications().empty())
506 app_controller->Activate(source); 513 app_controller->Activate(source);
507 else 514 else
508 LaunchApp(app_id, source, event_flags); 515 LaunchApp(app_id, source, event_flags);
509 } 516 }
510 517
511 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( 518 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType(
512 ash::ShelfID id) { 519 ash::ShelfID id) {
513 const Extension* extension = 520 const Extension* extension =
514 GetExtensionForAppID(GetAppIDForShelfID(id), profile_); 521 GetExtensionForAppID(GetAppIDForShelfID(id), profile_);
(...skipping 12 matching lines...) Expand all
527 int index = model_->ItemIndexByID(shelf_id); 534 int index = model_->ItemIndexByID(shelf_id);
528 if (index == -1) 535 if (index == -1)
529 return; 536 return;
530 ash::ShelfItem item = model_->items()[index]; 537 ash::ShelfItem item = model_->items()[index];
531 item.image = image; 538 item.image = image;
532 model_->Set(index, item); 539 model_->Set(index, item);
533 } 540 }
534 541
535 bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( 542 bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher(
536 const std::string& app_id) { 543 const std::string& app_id) {
537 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); 544 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id, app_id));
538 if (index < 0) 545 if (index < 0)
539 return false; 546 return false;
540 547
541 ash::ShelfItemType type = model_->items()[index].type; 548 ash::ShelfItemType type = model_->items()[index].type;
542 return type == ash::TYPE_WINDOWED_APP; 549 return type == ash::TYPE_WINDOWED_APP;
543 } 550 }
544 551
545 void ChromeLauncherControllerImpl::SetLaunchType( 552 void ChromeLauncherControllerImpl::SetLaunchType(
546 ash::ShelfID id, 553 ash::ShelfID id,
547 extensions::LaunchType launch_type) { 554 extensions::LaunchType launch_type) {
(...skipping 16 matching lines...) Expand all
564 // Check if the gMail app is loaded and it matches the given content. 571 // Check if the gMail app is loaded and it matches the given content.
565 // This special treatment is needed to address crbug.com/234268. 572 // This special treatment is needed to address crbug.com/234268.
566 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 573 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
567 app_id = kGmailAppId; 574 app_id = kGmailAppId;
568 575
569 // Check the old |app_id| for a tab. If the contents has changed we need to 576 // Check the old |app_id| for a tab. If the contents has changed we need to
570 // remove it from the previous app. 577 // remove it from the previous app.
571 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 578 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
572 std::string last_app_id = web_contents_to_app_id_[contents]; 579 std::string last_app_id = web_contents_to_app_id_[contents];
573 if (last_app_id != app_id) { 580 if (last_app_id != app_id) {
574 ash::ShelfID id = GetShelfIDForAppID(last_app_id); 581 ash::ShelfID id = GetShelfIDForAppID(last_app_id, last_app_id);
575 if (id) { 582 if (id) {
576 // Since GetAppState() will use |web_contents_to_app_id_| we remove 583 // Since GetAppState() will use |web_contents_to_app_id_| we remove
577 // the connection before calling it. 584 // the connection before calling it.
578 web_contents_to_app_id_.erase(contents); 585 web_contents_to_app_id_.erase(contents);
579 SetItemStatus(id, GetAppState(last_app_id)); 586 SetItemStatus(id, GetAppState(last_app_id));
580 } 587 }
581 } 588 }
582 } 589 }
583 590
584 if (app_state == APP_STATE_REMOVED) 591 if (app_state == APP_STATE_REMOVED)
585 web_contents_to_app_id_.erase(contents); 592 web_contents_to_app_id_.erase(contents);
586 else 593 else
587 web_contents_to_app_id_[contents] = app_id; 594 web_contents_to_app_id_[contents] = app_id;
588 595
589 ash::ShelfID id = GetShelfIDForAppID(app_id); 596 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
590 if (id) { 597 if (id) {
591 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || 598 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE ||
592 app_state == APP_STATE_ACTIVE) 599 app_state == APP_STATE_ACTIVE)
593 ? ash::STATUS_ACTIVE 600 ? ash::STATUS_ACTIVE
594 : GetAppState(app_id)); 601 : GetAppState(app_id));
595 } 602 }
596 } 603 }
597 604
598 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( 605 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents(
599 content::WebContents* contents) { 606 content::WebContents* contents) {
600 DCHECK(contents); 607 DCHECK(contents);
601 608
602 std::string app_id = launcher_controller_helper_->GetAppID(contents); 609 std::string app_id = launcher_controller_helper_->GetAppID(contents);
603 610
604 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) 611 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents))
605 app_id = kGmailAppId; 612 app_id = kGmailAppId;
606 613
607 ash::ShelfID id = GetShelfIDForAppID(app_id); 614 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
608 615
609 if (app_id.empty() || !id) { 616 if (app_id.empty() || !id) {
610 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); 617 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
611 return model_->items()[browser_index].id; 618 return model_->items()[browser_index].id;
612 } 619 }
613 620
614 return id; 621 return id;
615 } 622 }
616 623
617 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( 624 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 for (auto& controller : app_window_controllers_) 711 for (auto& controller : app_window_controllers_)
705 controller->AdditionalUserAddedToSession(profile); 712 controller->AdditionalUserAddedToSession(profile);
706 } 713 }
707 714
708 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( 715 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList(
709 const ash::ShelfItem& item, 716 const ash::ShelfItem& item,
710 int event_flags) { 717 int event_flags) {
711 // Make sure that there is a controller associated with the id and that the 718 // Make sure that there is a controller associated with the id and that the
712 // extension itself is a valid application and not a panel. 719 // extension itself is a valid application and not a panel.
713 LauncherItemController* controller = GetLauncherItemController(item.id); 720 LauncherItemController* controller = GetLauncherItemController(item.id);
714 if (!controller || !GetShelfIDForAppID(controller->app_id())) 721 if (!controller ||
722 !GetShelfIDForAppID(controller->app_id(), controller->app_id()))
715 return ChromeLauncherAppMenuItems(); 723 return ChromeLauncherAppMenuItems();
716 724
717 return controller->GetApplicationList(event_flags); 725 return controller->GetApplicationList(event_flags);
718 } 726 }
719 727
720 std::vector<content::WebContents*> 728 std::vector<content::WebContents*>
721 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( 729 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId(
722 const std::string& app_id) { 730 const std::string& app_id) {
723 ash::ShelfID id = GetShelfIDForAppID(app_id); 731 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
724 732
725 // If there is no such an item pinned to the launcher, no menu gets created. 733 // If there is no such an item pinned to the launcher, no menu gets created.
726 if (id) { 734 if (id) {
727 LauncherItemController* controller = GetLauncherItemController(id); 735 LauncherItemController* controller = GetLauncherItemController(id);
728 DCHECK(controller); 736 DCHECK(controller);
729 if (controller->type() == LauncherItemController::TYPE_SHORTCUT) 737 if (controller->type() == LauncherItemController::TYPE_SHORTCUT)
730 return GetV1ApplicationsFromController(controller); 738 return GetV1ApplicationsFromController(controller);
731 } 739 }
732 return std::vector<content::WebContents*>(); 740 return std::vector<content::WebContents*>();
733 } 741 }
734 742
735 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, 743 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id,
736 int index) { 744 int index) {
737 ash::ShelfID id = GetShelfIDForAppID(app_id); 745 ash::ShelfID id = GetShelfIDForAppID(app_id, app_id);
738 if (id) { 746 if (id) {
739 LauncherItemController* controller = GetLauncherItemController(id); 747 LauncherItemController* controller = GetLauncherItemController(id);
740 if (controller && controller->type() == LauncherItemController::TYPE_APP) { 748 if (controller && controller->type() == LauncherItemController::TYPE_APP) {
741 AppWindowLauncherItemController* app_window_controller = 749 AppWindowLauncherItemController* app_window_controller =
742 static_cast<AppWindowLauncherItemController*>(controller); 750 static_cast<AppWindowLauncherItemController*>(controller);
743 app_window_controller->ActivateIndexedApp(index); 751 app_window_controller->ActivateIndexedApp(index);
744 } 752 }
745 } 753 }
746 } 754 }
747 755
748 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( 756 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication(
749 content::WebContents* web_contents, 757 content::WebContents* web_contents,
750 const std::string& app_id) { 758 const std::string& app_id) {
751 if ((web_contents_to_app_id_.find(web_contents) != 759 if ((web_contents_to_app_id_.find(web_contents) !=
752 web_contents_to_app_id_.end()) && 760 web_contents_to_app_id_.end()) &&
753 (web_contents_to_app_id_[web_contents] == app_id)) 761 (web_contents_to_app_id_[web_contents] == app_id))
754 return true; 762 return true;
755 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); 763 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents));
756 } 764 }
757 765
758 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( 766 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp(
759 content::WebContents* web_contents) { 767 content::WebContents* web_contents) {
760 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); 768 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId, kGmailAppId);
761 if (id) { 769 if (id) {
762 const GURL url = web_contents->GetURL(); 770 const GURL url = web_contents->GetURL();
763 // We need to extend the application matching for the gMail app beyond the 771 // We need to extend the application matching for the gMail app beyond the
764 // manifest file's specification. This is required because of the namespace 772 // manifest file's specification. This is required because of the namespace
765 // overlap with the offline app ("/mail/mu/"). 773 // overlap with the offline app ("/mail/mu/").
766 if (!base::MatchPattern(url.path(), "/mail/mu/*") && 774 if (!base::MatchPattern(url.path(), "/mail/mu/*") &&
767 base::MatchPattern(url.path(), "/mail/*") && 775 base::MatchPattern(url.path(), "/mail/*") &&
768 GetExtensionForAppID(kGmailAppId, profile_) && 776 GetExtensionForAppID(kGmailAppId, profile_) &&
769 GetExtensionForAppID(kGmailAppId, profile_)->OverlapsWithOrigin(url)) 777 GetExtensionForAppID(kGmailAppId, profile_)->OverlapsWithOrigin(url))
770 return true; 778 return true;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 shelf->auto_hide_behavior()); 895 shelf->auto_hide_behavior());
888 } 896 }
889 897
890 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( 898 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged(
891 ash::Shelf* shelf) {} 899 ash::Shelf* shelf) {}
892 900
893 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( 901 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged(
894 ash::Shelf* shelf) {} 902 ash::Shelf* shelf) {}
895 903
896 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( 904 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
897 const std::string& app_id) { 905 const std::string& app_id,
906 const std::string& app_shelf_id) {
898 for (IDToItemControllerMap::const_iterator i = 907 for (IDToItemControllerMap::const_iterator i =
899 id_to_item_controller_map_.begin(); 908 id_to_item_controller_map_.begin();
900 i != id_to_item_controller_map_.end(); ++i) { 909 i != id_to_item_controller_map_.end(); ++i) {
stevenjb 2016/08/29 15:56:30 Convert this to a C++11 style iterator
Andra Paraschiv 2016/08/30 09:58:24 Done.
901 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) 910 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL)
902 continue; // Don't include panels 911 continue; // Don't include panels
903 if (i->second->app_id() == app_id) 912 // If app window controller, check app_id and app_shelf_id.
913 if (i->second->type() == LauncherItemController::TYPE_APP) {
914 AppWindowLauncherItemController* app_window_controller =
915 static_cast<AppWindowLauncherItemController*>(i->second);
916 if ((app_window_controller->app_id() == app_id) &&
917 (app_window_controller->app_shelf_id() == app_shelf_id)) {
918 return i->first;
919 }
920 // If not browser shortcut controller, check app_id and app_shelf_id.
921 } else if ((i->second->type() == LauncherItemController::TYPE_SHORTCUT) &&
922 (i->second->app_id() != extension_misc::kChromeAppId)) {
923 AppShortcutLauncherItemController* app_shortcut_controller =
924 static_cast<AppShortcutLauncherItemController*>(i->second);
925 if ((app_shortcut_controller->app_id() == app_id) &&
926 (app_shortcut_controller->app_shelf_id() == app_shelf_id)) {
927 return i->first;
928 }
929 } else if (i->second->app_id() == app_id) {
904 return i->first; 930 return i->first;
931 }
905 } 932 }
906 return 0; 933 return 0;
907 } 934 }
908 935
909 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( 936 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping(
910 ash::ShelfID id) const { 937 ash::ShelfID id) const {
911 return id_to_item_controller_map_.find(id) != 938 return id_to_item_controller_map_.find(id) !=
912 id_to_item_controller_map_.end(); 939 id_to_item_controller_map_.end();
913 } 940 }
914 941
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if (app_icon_loader) 996 if (app_icon_loader)
970 app_icon_loader->UpdateImage(app_id); 997 app_icon_loader->UpdateImage(app_id);
971 } 998 }
972 999
973 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( 1000 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared(
974 content::BrowserContext* browser_context, 1001 content::BrowserContext* browser_context,
975 const std::string& app_id) { 1002 const std::string& app_id) {
976 // Since we might have windowed apps of this type which might have 1003 // Since we might have windowed apps of this type which might have
977 // outstanding locks which needs to be removed. 1004 // outstanding locks which needs to be removed.
978 const Profile* profile = Profile::FromBrowserContext(browser_context); 1005 const Profile* profile = Profile::FromBrowserContext(browser_context);
979 if (GetShelfIDForAppID(app_id)) 1006 if (GetShelfIDForAppID(app_id, app_id))
980 CloseWindowedAppsFromRemovedExtension(app_id, profile); 1007 CloseWindowedAppsFromRemovedExtension(app_id, profile);
981 1008
982 if (IsAppPinned(app_id)) { 1009 if (IsAppPinned(app_id)) {
983 if (profile == profile_) 1010 if (profile == profile_)
984 DoUnpinAppWithID(app_id); 1011 DoUnpinAppWithID(app_id);
985 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1012 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
986 if (app_icon_loader) 1013 if (app_icon_loader)
987 app_icon_loader->ClearImage(app_id); 1014 app_icon_loader->ClearImage(app_id);
988 } 1015 }
989 } 1016 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 const std::string& user_id) { 1061 const std::string& user_id) {
1035 const RunningAppListIdMap::iterator app_id_list = 1062 const RunningAppListIdMap::iterator app_id_list =
1036 last_used_running_application_order_.find(user_id); 1063 last_used_running_application_order_.find(user_id);
1037 if (app_id_list == last_used_running_application_order_.end()) 1064 if (app_id_list == last_used_running_application_order_.end())
1038 return; 1065 return;
1039 1066
1040 // Find the first insertion point for running applications. 1067 // Find the first insertion point for running applications.
1041 int running_index = model_->FirstRunningAppIndex(); 1068 int running_index = model_->FirstRunningAppIndex();
1042 for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); 1069 for (RunningAppListIds::iterator app_id = app_id_list->second.begin();
1043 app_id != app_id_list->second.end(); ++app_id) { 1070 app_id != app_id_list->second.end(); ++app_id) {
1044 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); 1071 ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id, *app_id);
1045 if (shelf_id) { 1072 if (shelf_id) {
1046 int app_index = model_->ItemIndexByID(shelf_id); 1073 int app_index = model_->ItemIndexByID(shelf_id);
1047 DCHECK_GE(app_index, 0); 1074 DCHECK_GE(app_index, 0);
1048 ash::ShelfItemType type = model_->items()[app_index].type; 1075 ash::ShelfItemType type = model_->items()[app_index].type;
1049 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) { 1076 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) {
1050 if (running_index != app_index) 1077 if (running_index != app_index)
1051 model_->Move(running_index, app_index); 1078 model_->Move(running_index, app_index);
1052 running_index++; 1079 running_index++;
1053 } 1080 }
1054 } 1081 }
1055 } 1082 }
1056 } 1083 }
1057 1084
1058 ash::ShelfID 1085 ash::ShelfID
1059 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( 1086 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType(
1060 const std::string& app_id, 1087 const std::string& app_id,
1061 int index, 1088 int index,
1062 ash::ShelfItemType shelf_item_type) { 1089 ash::ShelfItemType shelf_item_type) {
1063 AppShortcutLauncherItemController* controller = 1090 AppShortcutLauncherItemController* controller =
1064 AppShortcutLauncherItemController::Create(app_id, this); 1091 AppShortcutLauncherItemController::Create(app_id, app_id, this);
1065 ash::ShelfID shelf_id = InsertAppLauncherItem( 1092 ash::ShelfID shelf_id = InsertAppLauncherItem(
1066 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); 1093 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type);
1067 return shelf_id; 1094 return shelf_id;
1068 } 1095 }
1069 1096
1070 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1097 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1071 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1098 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1072 CHECK(iter != id_to_item_controller_map_.end()); 1099 CHECK(iter != id_to_item_controller_map_.end());
1073 CHECK(iter->second); 1100 CHECK(iter->second);
1074 const std::string& app_id = iter->second->app_id(); 1101 const std::string& app_id = iter->second->app_id();
1075 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1102 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1076 if (app_icon_loader) 1103 if (app_icon_loader)
1077 app_icon_loader->ClearImage(app_id); 1104 app_icon_loader->ClearImage(app_id);
1078 id_to_item_controller_map_.erase(iter); 1105 id_to_item_controller_map_.erase(iter);
1079 int index = model_->ItemIndexByID(id); 1106 int index = model_->ItemIndexByID(id);
1080 // A "browser proxy" is not known to the model and this removal does 1107 // A "browser proxy" is not known to the model and this removal does
1081 // therefore not need to be propagated to the model. 1108 // therefore not need to be propagated to the model.
1082 if (index != -1) 1109 if (index != -1)
1083 model_->RemoveItemAt(index); 1110 model_->RemoveItemAt(index);
1084 } 1111 }
1085 1112
1086 void ChromeLauncherControllerImpl::DoPinAppWithID(const std::string& app_id) { 1113 void ChromeLauncherControllerImpl::DoPinAppWithID(const std::string& app_id) {
1087 // If there is an item, do nothing and return. 1114 // If there is an item, do nothing and return.
1088 if (IsAppPinned(app_id)) 1115 if (IsAppPinned(app_id))
1089 return; 1116 return;
1090 1117
1091 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1118 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id, app_id);
1092 if (shelf_id) { 1119 if (shelf_id) {
1093 // App item exists, pin it 1120 // App item exists, pin it
1094 Pin(shelf_id); 1121 Pin(shelf_id);
1095 } else { 1122 } else {
1096 // Otherwise, create a shortcut item for it. 1123 // Otherwise, create a shortcut item for it.
1097 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count()); 1124 shelf_id = CreateAppShortcutLauncherItem(app_id, model_->item_count());
1098 SyncPinPosition(shelf_id); 1125 SyncPinPosition(shelf_id);
1099 } 1126 }
1100 } 1127 }
1101 1128
1102 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id) { 1129 void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id) {
1103 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); 1130 ash::ShelfID shelf_id = GetShelfIDForAppID(app_id, app_id);
1104 if (shelf_id && IsPinned(shelf_id)) 1131 if (shelf_id && IsPinned(shelf_id))
1105 Unpin(shelf_id); 1132 Unpin(shelf_id);
1106 } 1133 }
1107 1134
1108 int ChromeLauncherControllerImpl::PinRunningAppInternal(int index, 1135 int ChromeLauncherControllerImpl::PinRunningAppInternal(int index,
1109 ash::ShelfID shelf_id) { 1136 ash::ShelfID shelf_id) {
1110 int running_index = model_->ItemIndexByID(shelf_id); 1137 int running_index = model_->ItemIndexByID(shelf_id);
1111 ash::ShelfItem item = model_->items()[running_index]; 1138 ash::ShelfItem item = model_->items()[running_index];
1112 DCHECK(item.type == ash::TYPE_WINDOWED_APP || 1139 DCHECK(item.type == ash::TYPE_WINDOWED_APP ||
1113 item.type == ash::TYPE_PLATFORM_APP); 1140 item.type == ash::TYPE_PLATFORM_APP);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 --max_index; 1278 --max_index;
1252 } 1279 }
1253 --index; 1280 --index;
1254 } 1281 }
1255 } 1282 }
1256 // If the item wasn't found, that means id_to_item_controller_map_ 1283 // If the item wasn't found, that means id_to_item_controller_map_
1257 // is out of sync. 1284 // is out of sync.
1258 DCHECK(index <= max_index); 1285 DCHECK(index <= max_index);
1259 } else { 1286 } else {
1260 // Check if the item was already running but not yet pinned. 1287 // Check if the item was already running but not yet pinned.
1261 ash::ShelfID shelf_id = GetShelfIDForAppID(*pref_app_id); 1288 ash::ShelfID shelf_id = GetShelfIDForAppID(*pref_app_id, *pref_app_id);
1262 if (shelf_id) { 1289 if (shelf_id) {
1263 // This app is running but not yet pinned. So pin and move it. 1290 // This app is running but not yet pinned. So pin and move it.
1264 index = PinRunningAppInternal(index, shelf_id); 1291 index = PinRunningAppInternal(index, shelf_id);
1265 } else { 1292 } else {
1266 // This app wasn't pinned before, insert a new entry. 1293 // This app wasn't pinned before, insert a new entry.
1267 shelf_id = CreateAppShortcutLauncherItem(*pref_app_id, index); 1294 shelf_id = CreateAppShortcutLauncherItem(*pref_app_id, index);
1268 ++max_index; 1295 ++max_index;
1269 index = model_->ItemIndexByID(shelf_id); 1296 index = model_->ItemIndexByID(shelf_id);
1270 } 1297 }
1271 ++pref_app_id; 1298 ++pref_app_id;
(...skipping 22 matching lines...) Expand all
1294 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { 1321 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) {
1295 // Update apps icon if applicable. 1322 // Update apps icon if applicable.
1296 OnAppUpdated(profile_, *pref_app_id); 1323 OnAppUpdated(profile_, *pref_app_id);
1297 if (*pref_app_id == extension_misc::kChromeAppId) { 1324 if (*pref_app_id == extension_misc::kChromeAppId) {
1298 int target_index = FindInsertionPoint(); 1325 int target_index = FindInsertionPoint();
1299 DCHECK(seen_chrome_index >= 0 && seen_chrome_index < target_index); 1326 DCHECK(seen_chrome_index >= 0 && seen_chrome_index < target_index);
1300 model_->Move(seen_chrome_index, target_index); 1327 model_->Move(seen_chrome_index, target_index);
1301 } else { 1328 } else {
1302 DoPinAppWithID(*pref_app_id); 1329 DoPinAppWithID(*pref_app_id);
1303 int target_index = FindInsertionPoint(); 1330 int target_index = FindInsertionPoint();
1304 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); 1331 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id, *pref_app_id);
1305 int source_index = model_->ItemIndexByID(id); 1332 int source_index = model_->ItemIndexByID(id);
1306 if (source_index != target_index) 1333 if (source_index != target_index)
1307 model_->Move(source_index, target_index); 1334 model_->Move(source_index, target_index);
1308 } 1335 }
1309 } 1336 }
1310 } 1337 }
1311 1338
1312 void ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs() { 1339 void ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs() {
1313 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) { 1340 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) {
1314 ash::Shelf* shelf = ash::Shelf::ForWindow(window); 1341 ash::Shelf* shelf = ash::Shelf::ForWindow(window);
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 if (index == -1) 1707 if (index == -1)
1681 continue; 1708 continue;
1682 ash::ShelfItem item = model_->items()[index]; 1709 ash::ShelfItem item = model_->items()[index];
1683 item.image = image; 1710 item.image = image;
1684 if (arc_deferred_launcher_) 1711 if (arc_deferred_launcher_)
1685 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1712 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1686 model_->Set(index, item); 1713 model_->Set(index, item);
1687 // It's possible we're waiting on more than one item, so don't break. 1714 // It's possible we're waiting on more than one item, so don't break.
1688 } 1715 }
1689 } 1716 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698