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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 #include "ui/aura/window_event_dispatcher.h" | 83 #include "ui/aura/window_event_dispatcher.h" |
84 #include "ui/base/l10n/l10n_util.h" | 84 #include "ui/base/l10n/l10n_util.h" |
85 #include "ui/base/resource/resource_bundle.h" | 85 #include "ui/base/resource/resource_bundle.h" |
86 #include "ui/base/window_open_disposition.h" | 86 #include "ui/base/window_open_disposition.h" |
87 #include "ui/display/types/display_constants.h" | 87 #include "ui/display/types/display_constants.h" |
88 #include "ui/keyboard/keyboard_util.h" | 88 #include "ui/keyboard/keyboard_util.h" |
89 #include "ui/resources/grit/ui_resources.h" | 89 #include "ui/resources/grit/ui_resources.h" |
90 #include "ui/wm/core/window_animations.h" | 90 #include "ui/wm/core/window_animations.h" |
91 | 91 |
92 using extensions::Extension; | 92 using extensions::Extension; |
93 using extension_misc::kChromeAppId; | |
93 using extension_misc::kGmailAppId; | 94 using extension_misc::kGmailAppId; |
94 using content::WebContents; | 95 using content::WebContents; |
95 | 96 |
96 namespace { | 97 namespace { |
97 | 98 |
98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { | 99 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { |
99 display::Display display = | 100 display::Display display = |
100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); | 101 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); |
101 DCHECK(display.is_valid()); | 102 DCHECK(display.is_valid()); |
102 return display.id(); | 103 return display.id(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() { | 268 ChromeLauncherControllerImpl::~ChromeLauncherControllerImpl() { |
268 // Reset the BrowserStatusMonitor as it has a weak pointer to this. | 269 // Reset the BrowserStatusMonitor as it has a weak pointer to this. |
269 browser_status_monitor_.reset(); | 270 browser_status_monitor_.reset(); |
270 | 271 |
271 // Reset the app window controllers here since it has a weak pointer to this. | 272 // Reset the app window controllers here since it has a weak pointer to this. |
272 app_window_controllers_.clear(); | 273 app_window_controllers_.clear(); |
273 | 274 |
274 model_->RemoveObserver(this); | 275 model_->RemoveObserver(this); |
275 if (ash::Shell::HasInstance()) | 276 if (ash::Shell::HasInstance()) |
276 ash::Shell::Get()->window_tree_host_manager()->RemoveObserver(this); | 277 ash::Shell::Get()->window_tree_host_manager()->RemoveObserver(this); |
277 for (const auto& pair : id_to_item_controller_map_) { | |
278 int index = model_->ItemIndexByID(pair.first); | |
279 // A "browser proxy" is not known to the model and this removal does | |
280 // therefore not need to be propagated to the model. | |
281 if (index != -1 && | |
282 model_->items()[index].type != ash::TYPE_BROWSER_SHORTCUT) | |
283 model_->RemoveItemAt(index); | |
284 } | |
285 | 278 |
286 // Release all profile dependent resources. | 279 // Release all profile dependent resources. |
287 ReleaseProfile(); | 280 ReleaseProfile(); |
288 | 281 |
289 // Get rid of the multi user window manager instance. | 282 // Get rid of the multi user window manager instance. |
290 chrome::MultiUserWindowManager::DeleteInstance(); | 283 chrome::MultiUserWindowManager::DeleteInstance(); |
291 } | 284 } |
292 | 285 |
293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 286 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
294 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, | 287 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, |
(...skipping 23 matching lines...) Expand all Loading... | |
318 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, | 311 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, |
319 ash::ShelfItemStatus status) { | 312 ash::ShelfItemStatus status) { |
320 const ash::ShelfItem* item = GetItem(id); | 313 const ash::ShelfItem* item = GetItem(id); |
321 if (item && item->status != status) { | 314 if (item && item->status != status) { |
322 ash::ShelfItem new_item = *item; | 315 ash::ShelfItem new_item = *item; |
323 new_item.status = status; | 316 new_item.status = status; |
324 model_->Set(model_->ItemIndexByID(id), new_item); | 317 model_->Set(model_->ItemIndexByID(id), new_item); |
325 } | 318 } |
326 } | 319 } |
327 | 320 |
328 void ChromeLauncherControllerImpl::SetShelfItemDelegate( | |
329 ash::ShelfID id, | |
330 std::unique_ptr<ash::ShelfItemDelegate> item_delegate) { | |
331 CHECK(item_delegate); | |
332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | |
333 CHECK(iter != id_to_item_controller_map_.end()); | |
334 item_delegate->set_shelf_id(id); | |
335 iter->second = item_delegate.get(); | |
336 model_->SetShelfItemDelegate(id, std::move(item_delegate)); | |
337 } | |
338 | |
339 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { | 321 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { |
340 CHECK(id); | 322 CHECK(id); |
341 if (IsPinned(id)) { | 323 if (IsPinned(id)) { |
342 // Create a new shortcut delegate. | 324 // Create a new shortcut delegate. |
343 SetItemStatus(id, ash::STATUS_CLOSED); | 325 SetItemStatus(id, ash::STATUS_CLOSED); |
344 SetShelfItemDelegate(id, AppShortcutLauncherItemController::Create( | 326 model_->SetShelfItemDelegate(id, AppShortcutLauncherItemController::Create( |
345 GetItem(id)->app_launch_id)); | 327 GetItem(id)->app_launch_id)); |
346 } else { | 328 } else { |
347 LauncherItemClosed(id); | 329 RemoveShelfItem(id); |
348 } | 330 } |
349 } | 331 } |
350 | 332 |
351 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { | 333 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { |
352 const ash::ShelfItem* item = GetItem(id); | 334 const ash::ShelfItem* item = GetItem(id); |
353 if (item && item->status != ash::STATUS_CLOSED) | 335 if (item && item->status != ash::STATUS_CLOSED) |
354 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 336 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
355 else | 337 else |
356 LauncherItemClosed(id); | 338 RemoveShelfItem(id); |
357 } | 339 } |
358 | 340 |
359 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 341 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
360 const ash::ShelfItem* item = GetItem(id); | 342 const ash::ShelfItem* item = GetItem(id); |
361 return item && ItemTypeIsPinned(*item); | 343 return item && ItemTypeIsPinned(*item); |
362 } | 344 } |
363 | 345 |
364 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, | 346 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, |
365 ash::ShelfItemStatus status) { | 347 ash::ShelfItemStatus status) { |
366 ash::ShelfID id = GetShelfIDForAppID(app_id); | 348 ash::ShelfID id = GetShelfIDForAppID(app_id); |
367 const ash::ShelfItem* item = GetItem(id); | 349 const ash::ShelfItem* item = GetItem(id); |
368 if (item) { | 350 if (item) { |
369 if (!IsPinned(id) && status == ash::STATUS_CLOSED) | 351 if (!IsPinned(id) && status == ash::STATUS_CLOSED) |
370 LauncherItemClosed(id); | 352 RemoveShelfItem(id); |
371 else | 353 else |
372 SetItemStatus(id, status); | 354 SetItemStatus(id, status); |
373 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { | 355 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { |
374 InsertAppLauncherItem( | 356 InsertAppLauncherItem( |
375 AppShortcutLauncherItemController::Create(ash::AppLaunchId(app_id)), | 357 AppShortcutLauncherItemController::Create(ash::AppLaunchId(app_id)), |
376 status, model_->item_count(), ash::TYPE_APP); | 358 status, model_->item_count(), ash::TYPE_APP); |
377 } | 359 } |
378 } | 360 } |
379 | 361 |
380 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { | 362 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { |
381 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(id); | 363 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
382 if (!delegate) | 364 if (!delegate) |
383 return; // In case invoked from menu and item closed while menu up. | 365 return; // In case invoked from menu and item closed while menu up. |
384 | 366 |
385 // Launching some items replaces the associated item delegate instance, | 367 // Launching some items replaces the associated item delegate instance, |
386 // which destroys the app and launch id strings; making copies avoid crashes. | 368 // which destroys the app and launch id strings; making copies avoid crashes. |
387 LaunchApp(ash::AppLaunchId(delegate->app_id(), delegate->launch_id()), | 369 LaunchApp(ash::AppLaunchId(delegate->app_id(), delegate->launch_id()), |
388 ash::LAUNCH_FROM_UNKNOWN, event_flags); | 370 ash::LAUNCH_FROM_UNKNOWN, event_flags); |
389 } | 371 } |
390 | 372 |
391 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { | 373 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 if (id) { | 456 if (id) { |
475 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || | 457 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || |
476 app_state == APP_STATE_ACTIVE) | 458 app_state == APP_STATE_ACTIVE) |
477 ? ash::STATUS_ACTIVE | 459 ? ash::STATUS_ACTIVE |
478 : GetAppState(app_id)); | 460 : GetAppState(app_id)); |
479 } | 461 } |
480 } | 462 } |
481 | 463 |
482 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( | 464 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( |
483 content::WebContents* contents) { | 465 content::WebContents* contents) { |
484 DCHECK(contents); | |
485 | |
486 std::string app_id = launcher_controller_helper()->GetAppID(contents); | 466 std::string app_id = launcher_controller_helper()->GetAppID(contents); |
487 | |
488 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 467 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
489 app_id = kGmailAppId; | 468 app_id = kGmailAppId; |
490 | 469 |
491 ash::ShelfID id = GetShelfIDForAppID(app_id); | 470 ash::ShelfID id = GetShelfIDForAppID(app_id); |
492 | 471 return id == ash::kInvalidShelfID ? GetShelfIDForAppID(kChromeAppId) : id; |
James Cook
2017/04/07 20:42:22
nit: maybe a comment here about why invalid id mea
msw
2017/04/07 22:02:16
Done.
| |
493 if (app_id.empty() || !id) { | |
494 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | |
495 return model_->items()[browser_index].id; | |
496 } | |
497 | |
498 return id; | |
499 } | 472 } |
500 | 473 |
501 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( | 474 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( |
502 ash::ShelfID id, | 475 ash::ShelfID id, |
503 const GURL& url) { | 476 const GURL& url) { |
504 const ash::ShelfItem* item = GetItem(id); | 477 const ash::ShelfItem* item = GetItem(id); |
505 if (item && !IsPlatformApp(id) && | 478 if (item && !IsPlatformApp(id) && |
506 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { | 479 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { |
507 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(id); | 480 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
508 AppShortcutLauncherItemController* item_controller = | 481 AppShortcutLauncherItemController* item_controller = |
509 static_cast<AppShortcutLauncherItemController*>(item_delegate); | 482 static_cast<AppShortcutLauncherItemController*>(delegate); |
510 item_controller->set_refocus_url(url); | 483 item_controller->set_refocus_url(url); |
511 } else { | 484 } else { |
512 NOTREACHED() << "Invalid launcher item or type"; | 485 NOTREACHED() << "Invalid launcher item or type"; |
513 } | 486 } |
514 } | 487 } |
515 | 488 |
516 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 489 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
517 ui::BaseWindow* window, | 490 ui::BaseWindow* window, |
518 bool allow_minimize) { | 491 bool allow_minimize) { |
519 // In separated desktop mode we might have to teleport a window back to the | 492 // In separated desktop mode we might have to teleport a window back to the |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 | 549 |
577 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( | 550 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
578 Profile* profile) { | 551 Profile* profile) { |
579 // Switch the running applications to the new user. | 552 // Switch the running applications to the new user. |
580 for (auto& controller : app_window_controllers_) | 553 for (auto& controller : app_window_controllers_) |
581 controller->AdditionalUserAddedToSession(profile); | 554 controller->AdditionalUserAddedToSession(profile); |
582 } | 555 } |
583 | 556 |
584 ash::MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( | 557 ash::MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( |
585 const ash::ShelfItem& item) { | 558 const ash::ShelfItem& item) { |
586 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item.id); | 559 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id); |
587 return item_delegate ? item_delegate->GetAppMenuItems(ui::EF_NONE) | 560 return delegate ? delegate->GetAppMenuItems(ui::EF_NONE) |
588 : ash::MenuItemList(); | 561 : ash::MenuItemList(); |
589 } | 562 } |
590 | 563 |
591 std::vector<content::WebContents*> | 564 std::vector<content::WebContents*> |
592 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 565 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
593 const std::string& app_id) { | 566 const std::string& app_id) { |
594 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 567 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
595 // If there is no such item pinned to the launcher, no menu gets created. | 568 // If there is no such item pinned to the launcher, no menu gets created. |
596 if (!item || item->type != ash::TYPE_PINNED_APP) | 569 if (!item || item->type != ash::TYPE_PINNED_APP) |
597 return std::vector<content::WebContents*>(); | 570 return std::vector<content::WebContents*>(); |
598 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item->id); | 571 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); |
599 AppShortcutLauncherItemController* item_controller = | 572 AppShortcutLauncherItemController* item_controller = |
600 static_cast<AppShortcutLauncherItemController*>(item_delegate); | 573 static_cast<AppShortcutLauncherItemController*>(delegate); |
601 return item_controller->GetRunningApplications(); | 574 return item_controller->GetRunningApplications(); |
602 } | 575 } |
603 | 576 |
604 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, | 577 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
605 int window_index) { | 578 int window_index) { |
606 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 579 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
607 if (item && | 580 if (item && |
608 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { | 581 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { |
609 ash::ShelfItemDelegate* item_delegate = GetShelfItemDelegate(item->id); | 582 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item->id); |
610 AppWindowLauncherItemController* item_controller = | 583 AppWindowLauncherItemController* item_controller = |
611 item_delegate->AsAppWindowLauncherItemController(); | 584 delegate->AsAppWindowLauncherItemController(); |
612 item_controller->ActivateIndexedApp(window_index); | 585 item_controller->ActivateIndexedApp(window_index); |
613 } | 586 } |
614 } | 587 } |
615 | 588 |
616 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( | 589 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
617 content::WebContents* web_contents, | 590 content::WebContents* web_contents, |
618 const std::string& app_id) { | 591 const std::string& app_id) { |
619 if ((web_contents_to_app_id_.find(web_contents) != | 592 if ((web_contents_to_app_id_.find(web_contents) != |
620 web_contents_to_app_id_.end()) && | 593 web_contents_to_app_id_.end()) && |
621 (web_contents_to_app_id_[web_contents] == app_id)) | 594 (web_contents_to_app_id_[web_contents] == app_id)) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 const extensions::Extension* extension = | 638 const extensions::Extension* extension = |
666 GetExtensionForAppID(app_id, profile()); | 639 GetExtensionForAppID(app_id, profile()); |
667 if (extension) | 640 if (extension) |
668 return base::UTF8ToUTF16(extension->name()); | 641 return base::UTF8ToUTF16(extension->name()); |
669 } | 642 } |
670 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 643 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
671 } | 644 } |
672 | 645 |
673 BrowserShortcutLauncherItemController* | 646 BrowserShortcutLauncherItemController* |
674 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { | 647 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
675 for (const auto& pair : id_to_item_controller_map_) { | 648 ash::ShelfID id = GetShelfIDForAppID(kChromeAppId); |
676 const ash::ShelfItem* item = GetItem(pair.first); | 649 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
677 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT) | 650 DCHECK(delegate) << "There should be always be a browser shortcut item."; |
678 return static_cast<BrowserShortcutLauncherItemController*>(pair.second); | 651 return static_cast<BrowserShortcutLauncherItemController*>(delegate); |
679 } | |
680 NOTREACHED() | |
681 << "There should be always be a BrowserShortcutLauncherItemController."; | |
682 return nullptr; | |
683 } | |
684 | |
685 ash::ShelfItemDelegate* ChromeLauncherControllerImpl::GetShelfItemDelegate( | |
686 const ash::ShelfID id) { | |
687 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | |
688 return iter == id_to_item_controller_map_.end() ? nullptr : iter->second; | |
689 } | 652 } |
690 | 653 |
691 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( | 654 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
692 ash::WmShelf* shelf, | 655 ash::WmShelf* shelf, |
693 const AccountId& account_id) const { | 656 const AccountId& account_id) const { |
694 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); | 657 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); |
695 if (!other_profile || other_profile == profile()) | 658 if (!other_profile || other_profile == profile()) |
696 return false; | 659 return false; |
697 | 660 |
698 // Note: The Auto hide state from preferences is not the same as the actual | 661 // Note: The Auto hide state from preferences is not the same as the actual |
(...skipping 20 matching lines...) Expand all Loading... | |
719 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 682 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
720 } | 683 } |
721 | 684 |
722 ArcAppDeferredLauncherController* | 685 ArcAppDeferredLauncherController* |
723 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { | 686 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { |
724 return arc_deferred_launcher_.get(); | 687 return arc_deferred_launcher_.get(); |
725 } | 688 } |
726 | 689 |
727 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( | 690 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( |
728 ash::ShelfID id) { | 691 ash::ShelfID id) { |
729 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(id); | 692 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
730 return delegate ? delegate->launch_id() : base::EmptyString(); | 693 return delegate ? delegate->launch_id() : base::EmptyString(); |
731 } | 694 } |
732 | 695 |
733 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { | 696 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { |
734 // The base class implementation updates the helper and app icon loaders. | 697 // The base class implementation updates the helper and app icon loaders. |
735 ChromeLauncherController::AttachProfile(profile_to_attach); | 698 ChromeLauncherController::AttachProfile(profile_to_attach); |
736 | 699 |
737 pref_change_registrar_.Init(profile()->GetPrefs()); | 700 pref_change_registrar_.Init(profile()->GetPrefs()); |
738 pref_change_registrar_.Add( | 701 pref_change_registrar_.Add( |
739 prefs::kPolicyPinnedLauncherApps, | 702 prefs::kPolicyPinnedLauncherApps, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 if (item && item->type == ash::TYPE_APP) { | 927 if (item && item->type == ash::TYPE_APP) { |
965 int app_index = model_->ItemIndexByID(item->id); | 928 int app_index = model_->ItemIndexByID(item->id); |
966 DCHECK_GE(app_index, 0); | 929 DCHECK_GE(app_index, 0); |
967 if (running_index != app_index) | 930 if (running_index != app_index) |
968 model_->Move(running_index, app_index); | 931 model_->Move(running_index, app_index); |
969 running_index++; | 932 running_index++; |
970 } | 933 } |
971 } | 934 } |
972 } | 935 } |
973 | 936 |
974 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { | 937 void ChromeLauncherControllerImpl::RemoveShelfItem(ash::ShelfID id) { |
975 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 938 const std::string& app_id = GetAppIDForShelfID(id); |
976 CHECK(iter != id_to_item_controller_map_.end()); | |
977 CHECK(iter->second); | |
978 const std::string& app_id = iter->second->app_id(); | |
979 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 939 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
980 if (app_icon_loader) | 940 if (app_icon_loader) |
981 app_icon_loader->ClearImage(app_id); | 941 app_icon_loader->ClearImage(app_id); |
982 id_to_item_controller_map_.erase(iter); | 942 const int index = model_->ItemIndexByID(id); |
983 int index = model_->ItemIndexByID(id); | |
984 // A "browser proxy" is not known to the model and this removal does | 943 // A "browser proxy" is not known to the model and this removal does |
985 // therefore not need to be propagated to the model. | 944 // therefore not need to be propagated to the model. |
986 if (index != -1) | 945 if (index != -1) |
987 model_->RemoveItemAt(index); | 946 model_->RemoveItemAt(index); |
988 } | 947 } |
989 | 948 |
990 void ChromeLauncherControllerImpl::PinRunningAppInternal( | 949 void ChromeLauncherControllerImpl::PinRunningAppInternal( |
991 int index, | 950 int index, |
992 ash::ShelfID shelf_id) { | 951 ash::ShelfID shelf_id) { |
993 DCHECK_EQ(GetItem(shelf_id)->type, ash::TYPE_APP); | 952 DCHECK_EQ(GetItem(shelf_id)->type, ash::TYPE_APP); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 if (shelf_app_id != app_id) | 1052 if (shelf_app_id != app_id) |
1094 continue; | 1053 continue; |
1095 | 1054 |
1096 // Update apps icon if applicable. | 1055 // Update apps icon if applicable. |
1097 OnAppUpdated(profile(), app_id); | 1056 OnAppUpdated(profile(), app_id); |
1098 | 1057 |
1099 // Find existing pin or app from the right of current |index|. | 1058 // Find existing pin or app from the right of current |index|. |
1100 int app_index = index; | 1059 int app_index = index; |
1101 for (; app_index < model_->item_count(); ++app_index) { | 1060 for (; app_index < model_->item_count(); ++app_index) { |
1102 const ash::ShelfItem& item = model_->items()[app_index]; | 1061 const ash::ShelfItem& item = model_->items()[app_index]; |
1103 const IDToItemControllerMap::iterator it = | 1062 if (item.app_launch_id.app_id() == app_id && |
1104 id_to_item_controller_map_.find(item.id); | 1063 item.app_launch_id.launch_id() == pref_app_launch_id.launch_id()) { |
1105 if (it != id_to_item_controller_map_.end() && | |
1106 it->second->app_id() == app_id && | |
1107 it->second->launch_id() == pref_app_launch_id.launch_id()) { | |
1108 break; | 1064 break; |
1109 } | 1065 } |
1110 } | 1066 } |
1111 if (app_index < model_->item_count()) { | 1067 if (app_index < model_->item_count()) { |
1112 // Found existing pin or running app. | 1068 // Found existing pin or running app. |
1113 const ash::ShelfItem item = model_->items()[app_index]; | 1069 const ash::ShelfItem item = model_->items()[app_index]; |
1114 if (item.type == ash::TYPE_PINNED_APP || | 1070 if (ItemTypeIsPinned(item)) { |
1115 item.type == ash::TYPE_BROWSER_SHORTCUT) { | |
1116 // Just move to required position or keep it inplace. | 1071 // Just move to required position or keep it inplace. |
1117 model_->Move(app_index, index); | 1072 model_->Move(app_index, index); |
1118 } else { | 1073 } else { |
1119 PinRunningAppInternal(index, item.id); | 1074 PinRunningAppInternal(index, item.id); |
1120 } | 1075 } |
1121 DCHECK_EQ(model_->ItemIndexByID(item.id), index); | 1076 DCHECK_EQ(model_->ItemIndexByID(item.id), index); |
1122 } else { | 1077 } else { |
1123 // This is fresh pin. Create new one. | 1078 // This is fresh pin. Create new one. |
1124 DCHECK_NE(app_id, extension_misc::kChromeAppId); | 1079 DCHECK_NE(app_id, kChromeAppId); |
1125 CreateAppShortcutLauncherItem(pref_app_launch_id, index); | 1080 CreateAppShortcutLauncherItem(pref_app_launch_id, index); |
1126 } | 1081 } |
1127 ++index; | 1082 ++index; |
1128 } | 1083 } |
1129 | 1084 |
1130 // At second step remove any pin to the right from the current index. | 1085 // At second step remove any pin to the right from the current index. |
1131 while (index < model_->item_count()) { | 1086 while (index < model_->item_count()) { |
1132 const ash::ShelfItem item = model_->items()[index]; | 1087 const ash::ShelfItem item = model_->items()[index]; |
1133 if (item.type == ash::TYPE_PINNED_APP) | 1088 if (item.type == ash::TYPE_PINNED_APP) |
1134 UnpinShelfItemInternal(item.id); | 1089 UnpinShelfItemInternal(item.id); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( | 1153 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( |
1199 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, | 1154 std::unique_ptr<ash::ShelfItemDelegate> item_delegate, |
1200 ash::ShelfItemStatus status, | 1155 ash::ShelfItemStatus status, |
1201 int index, | 1156 int index, |
1202 ash::ShelfItemType shelf_item_type) { | 1157 ash::ShelfItemType shelf_item_type) { |
1203 ash::ShelfID id = model_->next_id(); | 1158 ash::ShelfID id = model_->next_id(); |
1204 CHECK(!GetItem(id)); | 1159 CHECK(!GetItem(id)); |
1205 CHECK(item_delegate); | 1160 CHECK(item_delegate); |
1206 // Ash's ShelfWindowWatcher handles app panel windows separately. | 1161 // Ash's ShelfWindowWatcher handles app panel windows separately. |
1207 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); | 1162 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); |
1208 id_to_item_controller_map_[id] = item_delegate.get(); | |
1209 item_delegate->set_shelf_id(id); | |
1210 | 1163 |
1211 ash::ShelfItem item; | 1164 ash::ShelfItem item; |
1212 item.type = shelf_item_type; | 1165 item.type = shelf_item_type; |
1213 item.app_launch_id = item_delegate->app_launch_id(); | 1166 item.app_launch_id = item_delegate->app_launch_id(); |
1214 item.image = extensions::util::GetDefaultAppIcon(); | 1167 item.image = extensions::util::GetDefaultAppIcon(); |
1215 | 1168 |
1216 const std::string& app_id = item_delegate->app_id(); | 1169 const std::string& app_id = item_delegate->app_id(); |
1217 item.title = LauncherControllerHelper::GetAppTitle(profile(), app_id); | 1170 item.title = LauncherControllerHelper::GetAppTitle(profile(), app_id); |
1218 | 1171 |
1219 ash::ShelfItemStatus new_state = GetAppState(app_id); | 1172 ash::ShelfItemStatus new_state = GetAppState(app_id); |
(...skipping 17 matching lines...) Expand all Loading... | |
1237 // Do not sync the pin position of the browser shortcut item when it is added; | 1190 // Do not sync the pin position of the browser shortcut item when it is added; |
1238 // its initial position before prefs have loaded is unimportant and the sync | 1191 // its initial position before prefs have loaded is unimportant and the sync |
1239 // service may not yet be initialized. | 1192 // service may not yet be initialized. |
1240 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler(); | 1193 ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler(); |
1241 | 1194 |
1242 ash::ShelfItem browser_shortcut; | 1195 ash::ShelfItem browser_shortcut; |
1243 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1196 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
1244 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1197 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1245 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1198 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
1246 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 1199 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
1247 browser_shortcut.app_launch_id = | 1200 browser_shortcut.app_launch_id = ash::AppLaunchId(kChromeAppId); |
1248 ash::AppLaunchId(extension_misc::kChromeAppId); | |
1249 ash::ShelfID id = model_->next_id(); | 1201 ash::ShelfID id = model_->next_id(); |
1250 model_->AddAt(0, browser_shortcut); | 1202 model_->AddAt(0, browser_shortcut); |
1251 std::unique_ptr<BrowserShortcutLauncherItemController> item_delegate = | 1203 std::unique_ptr<BrowserShortcutLauncherItemController> item_delegate = |
1252 base::MakeUnique<BrowserShortcutLauncherItemController>(model_); | 1204 base::MakeUnique<BrowserShortcutLauncherItemController>(model_); |
1253 BrowserShortcutLauncherItemController* item_controller = item_delegate.get(); | 1205 BrowserShortcutLauncherItemController* item_controller = item_delegate.get(); |
1254 item_controller->set_shelf_id(id); | |
1255 id_to_item_controller_map_[id] = item_controller; | |
1256 model_->SetShelfItemDelegate(id, std::move(item_delegate)); | 1206 model_->SetShelfItemDelegate(id, std::move(item_delegate)); |
1257 item_controller->UpdateBrowserItemState(); | 1207 item_controller->UpdateBrowserItemState(); |
1258 } | 1208 } |
1259 | 1209 |
1260 bool ChromeLauncherControllerImpl::IsIncognito( | 1210 bool ChromeLauncherControllerImpl::IsIncognito( |
1261 const content::WebContents* web_contents) const { | 1211 const content::WebContents* web_contents) const { |
1262 const Profile* profile = | 1212 const Profile* profile = |
1263 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1213 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
1264 return profile->IsOffTheRecord() && !profile->IsGuestSession() && | 1214 return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
1265 !profile->IsSystemProfile(); | 1215 !profile->IsSystemProfile(); |
1266 } | 1216 } |
1267 | 1217 |
1268 int ChromeLauncherControllerImpl::FindInsertionPoint() { | 1218 int ChromeLauncherControllerImpl::FindInsertionPoint() { |
1269 DCHECK_GT(model_->item_count(), 0); | |
1270 for (int i = model_->item_count() - 1; i > 0; --i) { | 1219 for (int i = model_->item_count() - 1; i > 0; --i) { |
1271 ash::ShelfItemType type = model_->items()[i].type; | 1220 if (ItemTypeIsPinned(model_->items()[i])) |
1272 DCHECK_NE(ash::TYPE_APP_LIST, type); | |
1273 if (type == ash::TYPE_PINNED_APP || type == ash::TYPE_BROWSER_SHORTCUT) | |
1274 return i; | 1221 return i; |
1275 } | 1222 } |
1276 return 0; | 1223 return 0; |
1277 } | 1224 } |
1278 | 1225 |
1279 void ChromeLauncherControllerImpl::CloseWindowedAppsFromRemovedExtension( | 1226 void ChromeLauncherControllerImpl::CloseWindowedAppsFromRemovedExtension( |
1280 const std::string& app_id, | 1227 const std::string& app_id, |
1281 const Profile* profile) { | 1228 const Profile* profile) { |
1282 // This function cannot rely on the controller's enumeration functionality | 1229 // This function cannot rely on the controller's enumeration functionality |
1283 // since the extension has already been unloaded. | 1230 // since the extension has already been unloaded. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 // Remove the pin position from preferences as needed. | 1284 // Remove the pin position from preferences as needed. |
1338 if (ItemTypeIsPinned(old_item) && should_sync_pin_changes()) { | 1285 if (ItemTypeIsPinned(old_item) && should_sync_pin_changes()) { |
1339 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859 | 1286 // TODO(khmel): Fix this Arc application id mapping. See http://b/31703859 |
1340 const std::string shelf_app_id = | 1287 const std::string shelf_app_id = |
1341 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( | 1288 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( |
1342 old_item.app_launch_id.app_id()); | 1289 old_item.app_launch_id.app_id()); |
1343 ash::AppLaunchId app_launch_id(shelf_app_id, | 1290 ash::AppLaunchId app_launch_id(shelf_app_id, |
1344 old_item.app_launch_id.launch_id()); | 1291 old_item.app_launch_id.launch_id()); |
1345 ash::launcher::RemovePinPosition(profile(), app_launch_id); | 1292 ash::launcher::RemovePinPosition(profile(), app_launch_id); |
1346 } | 1293 } |
1347 | |
1348 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | |
1349 // get into this state in the first place. | |
1350 if (id_to_item_controller_map_.count(old_item.id) > 0) | |
1351 id_to_item_controller_map_.erase(old_item.id); | |
1352 } | 1294 } |
1353 | 1295 |
1354 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, | 1296 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, |
1355 int target_index) { | 1297 int target_index) { |
1356 // Update the pin position preference as needed. | 1298 // Update the pin position preference as needed. |
1357 const ash::ShelfItem& item = model_->items()[target_index]; | 1299 const ash::ShelfItem& item = model_->items()[target_index]; |
1358 DCHECK_NE(ash::TYPE_APP_LIST, item.type); | 1300 DCHECK_NE(ash::TYPE_APP_LIST, item.type); |
1359 if (ItemTypeIsPinned(item) && should_sync_pin_changes()) | 1301 if (ItemTypeIsPinned(item) && should_sync_pin_changes()) |
1360 SyncPinPosition(item.id); | 1302 SyncPinPosition(item.id); |
1361 } | 1303 } |
(...skipping 13 matching lines...) Expand all Loading... | |
1375 const std::string shelf_app_id = | 1317 const std::string shelf_app_id = |
1376 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( | 1318 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( |
1377 old_item.app_launch_id.app_id()); | 1319 old_item.app_launch_id.app_id()); |
1378 | 1320 |
1379 ash::AppLaunchId app_launch_id(shelf_app_id, | 1321 ash::AppLaunchId app_launch_id(shelf_app_id, |
1380 old_item.app_launch_id.launch_id()); | 1322 old_item.app_launch_id.launch_id()); |
1381 ash::launcher::RemovePinPosition(profile(), app_launch_id); | 1323 ash::launcher::RemovePinPosition(profile(), app_launch_id); |
1382 } | 1324 } |
1383 } | 1325 } |
1384 | 1326 |
1385 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | |
1386 ash::ShelfID id, | |
1387 ash::ShelfItemDelegate* item_delegate) { | |
1388 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | |
1389 // get into this state in the first place. | |
1390 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | |
1391 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | |
1392 return; | |
1393 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; | |
1394 id_to_item_controller_map_.erase(iter); | |
1395 } | |
1396 | |
1397 /////////////////////////////////////////////////////////////////////////////// | 1327 /////////////////////////////////////////////////////////////////////////////// |
1398 // ash::WindowTreeHostManager::Observer: | 1328 // ash::WindowTreeHostManager::Observer: |
1399 | 1329 |
1400 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { | 1330 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { |
1401 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. | 1331 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. |
1402 // Because it might be called by some operations, like crbug.com/627040 | 1332 // Because it might be called by some operations, like crbug.com/627040 |
1403 // rotating screen. | 1333 // rotating screen. |
1404 ash::WmShelf* shelf = | 1334 ash::WmShelf* shelf = |
1405 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow()); | 1335 ash::WmShelf::ForWindow(ash::WmShell::Get()->GetPrimaryRootWindow()); |
1406 if (shelf->alignment() != ash::SHELF_ALIGNMENT_BOTTOM_LOCKED) | 1336 if (shelf->alignment() != ash::SHELF_ALIGNMENT_BOTTOM_LOCKED) |
(...skipping 16 matching lines...) Expand all Loading... | |
1423 if (item.title != title) { | 1353 if (item.title != title) { |
1424 item.title = title; | 1354 item.title = title; |
1425 model_->Set(app_list_index, item); | 1355 model_->Set(app_list_index, item); |
1426 } | 1356 } |
1427 } | 1357 } |
1428 | 1358 |
1429 /////////////////////////////////////////////////////////////////////////////// | 1359 /////////////////////////////////////////////////////////////////////////////// |
1430 // AppIconLoaderDelegate: | 1360 // AppIconLoaderDelegate: |
1431 | 1361 |
1432 void ChromeLauncherControllerImpl::OnAppImageUpdated( | 1362 void ChromeLauncherControllerImpl::OnAppImageUpdated( |
1433 const std::string& id, | 1363 const std::string& app_id, |
1434 const gfx::ImageSkia& image) { | 1364 const gfx::ImageSkia& image) { |
1435 // TODO: need to get this working for shortcuts. | 1365 // TODO: need to get this working for shortcuts. |
1436 for (int index = 0; index < model_->item_count(); ++index) { | 1366 for (int index = 0; index < model_->item_count(); ++index) { |
1437 ash::ShelfItem item = model_->items()[index]; | 1367 ash::ShelfItem item = model_->items()[index]; |
1438 if (GetAppIDForShelfID(item.id) != id) | 1368 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(item.id); |
1369 if (item.type == ash::TYPE_APP_PANEL || !delegate || | |
1370 delegate->image_set_by_controller() || | |
1371 item.app_launch_id.app_id() != app_id) { | |
1439 continue; | 1372 continue; |
1440 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(item.id); | 1373 } |
1441 if (!delegate || delegate->image_set_by_controller()) | |
1442 continue; | |
1443 item.image = image; | 1374 item.image = image; |
1444 if (arc_deferred_launcher_) | 1375 if (arc_deferred_launcher_) |
1445 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1376 arc_deferred_launcher_->MaybeApplySpinningEffect(app_id, &item.image); |
1446 model_->Set(index, item); | 1377 model_->Set(index, item); |
1447 // It's possible we're waiting on more than one item, so don't break. | 1378 // It's possible we're waiting on more than one item, so don't break. |
1448 } | 1379 } |
1449 } | 1380 } |
OLD | NEW |