Chromium Code Reviews| 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 |
| 11 #include "ash/common/multi_profile_uma.h" | 11 #include "ash/common/multi_profile_uma.h" |
| 12 #include "ash/common/shelf/shelf_model.h" | 12 #include "ash/common/shelf/shelf_model.h" |
| 13 #include "ash/common/shelf/wm_shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 15 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 16 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
| 17 #include "ash/public/cpp/app_launch_id.h" | 17 #include "ash/public/cpp/app_launch_id.h" |
| 18 #include "ash/public/cpp/shelf_item_delegate.h" | |
| 18 #include "ash/resources/grit/ash_resources.h" | 19 #include "ash/resources/grit/ash_resources.h" |
| 19 #include "ash/root_window_controller.h" | 20 #include "ash/root_window_controller.h" |
| 20 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 21 #include "ash/strings/grit/ash_strings.h" | 22 #include "ash/strings/grit/ash_strings.h" |
| 22 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
| 23 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 24 #include "base/macros.h" | 25 #include "base/macros.h" |
| 25 #include "base/strings/pattern.h" | 26 #include "base/strings/pattern.h" |
| 26 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 47 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 48 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
| 48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 49 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" | 50 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h" |
| 50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 51 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 52 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 52 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" | 53 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" |
| 53 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 54 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 54 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" | 55 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| 55 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | |
| 56 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr oller.h" | 56 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr oller.h" |
| 57 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" | 57 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" |
| 58 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 58 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 59 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 59 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 60 #include "chrome/browser/ui/browser.h" | 60 #include "chrome/browser/ui/browser.h" |
| 61 #include "chrome/browser/ui/browser_finder.h" | 61 #include "chrome/browser/ui/browser_finder.h" |
| 62 #include "chrome/browser/ui/browser_list.h" | 62 #include "chrome/browser/ui/browser_list.h" |
| 63 #include "chrome/browser/ui/browser_tabstrip.h" | 63 #include "chrome/browser/ui/browser_tabstrip.h" |
| 64 #include "chrome/browser/ui/browser_window.h" | 64 #include "chrome/browser/ui/browser_window.h" |
| 65 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 65 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 96 namespace { | 96 namespace { |
| 97 | 97 |
| 98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { | 98 int64_t GetDisplayIDForShelf(ash::WmShelf* shelf) { |
| 99 display::Display display = | 99 display::Display display = |
| 100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); | 100 shelf->GetWindow()->GetRootWindow()->GetDisplayNearestWindow(); |
| 101 DCHECK(display.is_valid()); | 101 DCHECK(display.is_valid()); |
| 102 return display.id(); | 102 return display.id(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // A callback that does nothing after shelf item selection handling. | 105 // A callback that does nothing after shelf item selection handling. |
| 106 void NoopCallback(ash::ShelfAction, base::Optional<MenuItemList>) {} | 106 void NoopCallback(ash::ShelfAction, base::Optional<ash::MenuItemList>) {} |
| 107 | 107 |
| 108 // Calls ItemSelected with |source|, default arguments, and no callback. | 108 // Calls ItemSelected with |source|, default arguments, and no callback. |
| 109 void SelectItemWithSource(ash::mojom::ShelfItemDelegate* delegate, | 109 void SelectItemWithSource(ash::ShelfItemDelegate* delegate, |
| 110 ash::ShelfLaunchSource source) { | 110 ash::ShelfLaunchSource source) { |
| 111 delegate->ItemSelected(nullptr, display::kInvalidDisplayId, source, | 111 delegate->ItemSelected(nullptr, display::kInvalidDisplayId, source, |
| 112 base::Bind(&NoopCallback)); | 112 base::Bind(&NoopCallback)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Returns true if the given |item| has a pinned shelf item type. | 115 // Returns true if the given |item| has a pinned shelf item type. |
| 116 bool ItemTypeIsPinned(const ash::ShelfItem& item) { | 116 bool ItemTypeIsPinned(const ash::ShelfItem& item) { |
| 117 return item.type == ash::TYPE_PINNED_APP || | 117 return item.type == ash::TYPE_PINNED_APP || |
| 118 item.type == ash::TYPE_BROWSER_SHORTCUT; | 118 item.type == ash::TYPE_BROWSER_SHORTCUT; |
| 119 } | 119 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 } | 284 } |
| 285 | 285 |
| 286 // Release all profile dependent resources. | 286 // Release all profile dependent resources. |
| 287 ReleaseProfile(); | 287 ReleaseProfile(); |
| 288 | 288 |
| 289 // Get rid of the multi user window manager instance. | 289 // Get rid of the multi user window manager instance. |
| 290 chrome::MultiUserWindowManager::DeleteInstance(); | 290 chrome::MultiUserWindowManager::DeleteInstance(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
| 294 LauncherItemController* controller, | 294 ash::ShelfItemDelegate* controller, |
| 295 ash::ShelfItemStatus status) { | 295 ash::ShelfItemStatus status) { |
| 296 return InsertAppLauncherItem(controller, status, model_->item_count(), | 296 return InsertAppLauncherItem(controller, status, model_->item_count(), |
| 297 ash::TYPE_APP); | 297 ash::TYPE_APP); |
| 298 } | 298 } |
| 299 | 299 |
| 300 const ash::ShelfItem* ChromeLauncherControllerImpl::GetItem( | 300 const ash::ShelfItem* ChromeLauncherControllerImpl::GetItem( |
| 301 ash::ShelfID id) const { | 301 ash::ShelfID id) const { |
| 302 const int index = model_->ItemIndexByID(id); | 302 const int index = model_->ItemIndexByID(id); |
| 303 if (index >= 0 && index < model_->item_count()) | 303 if (index >= 0 && index < model_->item_count()) |
| 304 return &model_->items()[index]; | 304 return &model_->items()[index]; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 320 const ash::ShelfItem* item = GetItem(id); | 320 const ash::ShelfItem* item = GetItem(id); |
| 321 if (item && item->status != status) { | 321 if (item && item->status != status) { |
| 322 ash::ShelfItem new_item = *item; | 322 ash::ShelfItem new_item = *item; |
| 323 new_item.status = status; | 323 new_item.status = status; |
| 324 model_->Set(model_->ItemIndexByID(id), new_item); | 324 model_->Set(model_->ItemIndexByID(id), new_item); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 void ChromeLauncherControllerImpl::SetItemController( | 328 void ChromeLauncherControllerImpl::SetItemController( |
| 329 ash::ShelfID id, | 329 ash::ShelfID id, |
| 330 LauncherItemController* controller) { | 330 ash::ShelfItemDelegate* controller) { |
|
James Cook
2017/04/04 15:34:45
ditto on all these locals named "controller"
msw
2017/04/04 18:53:09
Done.
| |
| 331 CHECK(controller); | 331 CHECK(controller); |
| 332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 332 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 333 CHECK(iter != id_to_item_controller_map_.end()); | 333 CHECK(iter != id_to_item_controller_map_.end()); |
| 334 controller->set_shelf_id(id); | 334 controller->set_shelf_id(id); |
| 335 iter->second = controller; | 335 iter->second = controller; |
| 336 // Existing controller is destroyed and replaced by registering again. | 336 // Existing controller is destroyed and replaced by registering again. |
| 337 SetShelfItemDelegate(id, controller); | 337 SetShelfItemDelegate(id, controller); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { | 340 void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { |
| 341 CHECK(id); | 341 CHECK(id); |
| 342 if (IsPinned(id)) { | 342 if (IsPinned(id)) { |
| 343 // Create a new shortcut controller. | 343 // Create a new shortcut controller. |
| 344 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 344 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 345 CHECK(iter != id_to_item_controller_map_.end()); | 345 CHECK(iter != id_to_item_controller_map_.end()); |
| 346 LauncherItemController* controller = iter->second; | 346 ash::ShelfItemDelegate* controller = iter->second; |
| 347 SetItemStatus(id, ash::STATUS_CLOSED); | 347 SetItemStatus(id, ash::STATUS_CLOSED); |
| 348 const ash::AppLaunchId& app_launch_id = controller->app_launch_id(); | 348 const ash::AppLaunchId& app_launch_id = controller->app_launch_id(); |
| 349 controller = AppShortcutLauncherItemController::Create(app_launch_id, this); | 349 controller = AppShortcutLauncherItemController::Create(app_launch_id); |
| 350 controller->set_shelf_id(id); | 350 controller->set_shelf_id(id); |
| 351 // Existing controller is destroyed and replaced by registering again. | 351 // Existing controller is destroyed and replaced by registering again. |
|
James Cook
2017/04/04 23:57:27
Nice to see junk like this going away.
| |
| 352 iter->second = controller; | 352 iter->second = controller; |
| 353 SetShelfItemDelegate(id, controller); | 353 SetShelfItemDelegate(id, controller); |
| 354 } else { | 354 } else { |
| 355 LauncherItemClosed(id); | 355 LauncherItemClosed(id); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { | 359 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { |
| 360 const ash::ShelfItem* item = GetItem(id); | 360 const ash::ShelfItem* item = GetItem(id); |
| 361 if (item && item->status != ash::STATUS_CLOSED) | 361 if (item && item->status != ash::STATUS_CLOSED) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 372 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, | 372 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, |
| 373 ash::ShelfItemStatus status) { | 373 ash::ShelfItemStatus status) { |
| 374 ash::ShelfID id = GetShelfIDForAppID(app_id); | 374 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 375 const ash::ShelfItem* item = GetItem(id); | 375 const ash::ShelfItem* item = GetItem(id); |
| 376 if (item) { | 376 if (item) { |
| 377 if (!IsPinned(id) && status == ash::STATUS_CLOSED) | 377 if (!IsPinned(id) && status == ash::STATUS_CLOSED) |
| 378 LauncherItemClosed(id); | 378 LauncherItemClosed(id); |
| 379 else | 379 else |
| 380 SetItemStatus(id, status); | 380 SetItemStatus(id, status); |
| 381 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { | 381 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { |
| 382 InsertAppLauncherItem(AppShortcutLauncherItemController::Create( | 382 InsertAppLauncherItem( |
| 383 ash::AppLaunchId(app_id), this), | 383 AppShortcutLauncherItemController::Create(ash::AppLaunchId(app_id)), |
| 384 status, model_->item_count(), ash::TYPE_APP); | 384 status, model_->item_count(), ash::TYPE_APP); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { | 388 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { |
| 389 LauncherItemController* controller = GetLauncherItemController(id); | 389 ash::ShelfItemDelegate* controller = GetLauncherItemController(id); |
| 390 if (!controller) | 390 if (!controller) |
| 391 return; // In case invoked from menu and item closed while menu up. | 391 return; // In case invoked from menu and item closed while menu up. |
| 392 | 392 |
| 393 // Launching some items replaces the associated item controller instance, | 393 // Launching some items replaces the associated item controller instance, |
| 394 // which destroys the app and launch id strings; making copies avoid crashes. | 394 // which destroys the app and launch id strings; making copies avoid crashes. |
| 395 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()), | 395 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()), |
| 396 ash::LAUNCH_FROM_UNKNOWN, event_flags); | 396 ash::LAUNCH_FROM_UNKNOWN, event_flags); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { | 399 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { |
| 400 ash::mojom::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); | 400 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id); |
| 401 if (!delegate) | 401 if (!delegate) |
| 402 return; // May happen if menu closed. | 402 return; // May happen if menu closed. |
| 403 delegate->Close(); | 403 delegate->Close(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { | 406 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { |
| 407 const ash::ShelfItem* item = GetItem(id); | 407 const ash::ShelfItem* item = GetItem(id); |
| 408 return item && item->status != ash::STATUS_CLOSED; | 408 return item && item->status != ash::STATUS_CLOSED; |
| 409 } | 409 } |
| 410 | 410 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 423 ash::ShelfID id = GetShelfIDForAppID(app_id); | 423 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 424 if (id) { | 424 if (id) { |
| 425 SelectItemWithSource(model_->GetShelfItemDelegate(id), source); | 425 SelectItemWithSource(model_->GetShelfItemDelegate(id), source); |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Create a temporary application launcher item and use it to see if there are | 429 // Create a temporary application launcher item and use it to see if there are |
| 430 // running instances. | 430 // running instances. |
| 431 ash::AppLaunchId app_launch_id(app_id); | 431 ash::AppLaunchId app_launch_id(app_id); |
| 432 std::unique_ptr<AppShortcutLauncherItemController> controller( | 432 std::unique_ptr<AppShortcutLauncherItemController> controller( |
| 433 AppShortcutLauncherItemController::Create(app_launch_id, this)); | 433 AppShortcutLauncherItemController::Create(app_launch_id)); |
| 434 if (!controller->GetRunningApplications().empty()) | 434 if (!controller->GetRunningApplications().empty()) |
| 435 SelectItemWithSource(controller.get(), source); | 435 SelectItemWithSource(controller.get(), source); |
| 436 else | 436 else |
| 437 LaunchApp(app_launch_id, source, event_flags); | 437 LaunchApp(app_launch_id, source, event_flags); |
| 438 } | 438 } |
| 439 | 439 |
| 440 void ChromeLauncherControllerImpl::SetLauncherItemImage( | 440 void ChromeLauncherControllerImpl::SetLauncherItemImage( |
| 441 ash::ShelfID shelf_id, | 441 ash::ShelfID shelf_id, |
| 442 const gfx::ImageSkia& image) { | 442 const gfx::ImageSkia& image) { |
| 443 const ash::ShelfItem* item = GetItem(shelf_id); | 443 const ash::ShelfItem* item = GetItem(shelf_id); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 505 |
| 506 return id; | 506 return id; |
| 507 } | 507 } |
| 508 | 508 |
| 509 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( | 509 void ChromeLauncherControllerImpl::SetRefocusURLPatternForTest( |
| 510 ash::ShelfID id, | 510 ash::ShelfID id, |
| 511 const GURL& url) { | 511 const GURL& url) { |
| 512 const ash::ShelfItem* item = GetItem(id); | 512 const ash::ShelfItem* item = GetItem(id); |
| 513 if (item && !IsPlatformApp(id) && | 513 if (item && !IsPlatformApp(id) && |
| 514 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { | 514 (item->type == ash::TYPE_PINNED_APP || item->type == ash::TYPE_APP)) { |
| 515 LauncherItemController* controller = GetLauncherItemController(id); | 515 ash::ShelfItemDelegate* controller = GetLauncherItemController(id); |
| 516 DCHECK(controller); | 516 DCHECK(controller); |
| 517 AppShortcutLauncherItemController* app_controller = | 517 AppShortcutLauncherItemController* app_controller = |
| 518 static_cast<AppShortcutLauncherItemController*>(controller); | 518 static_cast<AppShortcutLauncherItemController*>(controller); |
| 519 app_controller->set_refocus_url(url); | 519 app_controller->set_refocus_url(url); |
| 520 } else { | 520 } else { |
| 521 NOTREACHED() << "Invalid launcher item or type"; | 521 NOTREACHED() << "Invalid launcher item or type"; |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 525 ash::ShelfAction ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 ash::Shell::GetInstance()->CreateKeyboard(); | 583 ash::Shell::GetInstance()->CreateKeyboard(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( | 586 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
| 587 Profile* profile) { | 587 Profile* profile) { |
| 588 // Switch the running applications to the new user. | 588 // Switch the running applications to the new user. |
| 589 for (auto& controller : app_window_controllers_) | 589 for (auto& controller : app_window_controllers_) |
| 590 controller->AdditionalUserAddedToSession(profile); | 590 controller->AdditionalUserAddedToSession(profile); |
| 591 } | 591 } |
| 592 | 592 |
| 593 MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( | 593 ash::MenuItemList ChromeLauncherControllerImpl::GetAppMenuItemsForTesting( |
| 594 const ash::ShelfItem& item) { | 594 const ash::ShelfItem& item) { |
| 595 LauncherItemController* controller = GetLauncherItemController(item.id); | 595 ash::ShelfItemDelegate* controller = GetLauncherItemController(item.id); |
| 596 return controller ? controller->GetAppMenuItems(ui::EF_NONE) : MenuItemList(); | 596 return controller ? controller->GetAppMenuItems(ui::EF_NONE) |
| 597 : ash::MenuItemList(); | |
| 597 } | 598 } |
| 598 | 599 |
| 599 std::vector<content::WebContents*> | 600 std::vector<content::WebContents*> |
| 600 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 601 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| 601 const std::string& app_id) { | 602 const std::string& app_id) { |
| 602 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 603 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 603 // If there is no such item pinned to the launcher, no menu gets created. | 604 // If there is no such item pinned to the launcher, no menu gets created. |
| 604 if (!item || item->type != ash::TYPE_PINNED_APP) | 605 if (!item || item->type != ash::TYPE_PINNED_APP) |
| 605 return std::vector<content::WebContents*>(); | 606 return std::vector<content::WebContents*>(); |
| 606 LauncherItemController* controller = GetLauncherItemController(item->id); | 607 ash::ShelfItemDelegate* controller = GetLauncherItemController(item->id); |
| 607 AppShortcutLauncherItemController* app_controller = | 608 AppShortcutLauncherItemController* app_controller = |
| 608 static_cast<AppShortcutLauncherItemController*>(controller); | 609 static_cast<AppShortcutLauncherItemController*>(controller); |
| 609 return app_controller->GetRunningApplications(); | 610 return app_controller->GetRunningApplications(); |
| 610 } | 611 } |
| 611 | 612 |
| 612 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, | 613 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
| 613 int window_index) { | 614 int window_index) { |
| 614 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); | 615 const ash::ShelfItem* item = GetItem(GetShelfIDForAppID(app_id)); |
| 615 if (item && | 616 if (item && |
| 616 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { | 617 (item->type == ash::TYPE_APP || item->type == ash::TYPE_PINNED_APP)) { |
| 617 LauncherItemController* controller = GetLauncherItemController(item->id); | 618 ash::ShelfItemDelegate* controller = GetLauncherItemController(item->id); |
| 618 AppWindowLauncherItemController* app_window_controller = | 619 AppWindowLauncherItemController* app_window_controller = |
| 619 controller->AsAppWindowLauncherItemController(); | 620 controller->AsAppWindowLauncherItemController(); |
| 620 DCHECK(app_window_controller); | 621 DCHECK(app_window_controller); |
| 621 app_window_controller->ActivateIndexedApp(window_index); | 622 app_window_controller->ActivateIndexedApp(window_index); |
| 622 } | 623 } |
| 623 } | 624 } |
| 624 | 625 |
| 625 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( | 626 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
| 626 content::WebContents* web_contents, | 627 content::WebContents* web_contents, |
| 627 const std::string& app_id) { | 628 const std::string& app_id) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 for (const auto& pair : id_to_item_controller_map_) { | 685 for (const auto& pair : id_to_item_controller_map_) { |
| 685 const ash::ShelfItem* item = GetItem(pair.first); | 686 const ash::ShelfItem* item = GetItem(pair.first); |
| 686 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT) | 687 if (item && item->type == ash::TYPE_BROWSER_SHORTCUT) |
| 687 return static_cast<BrowserShortcutLauncherItemController*>(pair.second); | 688 return static_cast<BrowserShortcutLauncherItemController*>(pair.second); |
| 688 } | 689 } |
| 689 NOTREACHED() | 690 NOTREACHED() |
| 690 << "There should be always be a BrowserShortcutLauncherItemController."; | 691 << "There should be always be a BrowserShortcutLauncherItemController."; |
| 691 return nullptr; | 692 return nullptr; |
| 692 } | 693 } |
| 693 | 694 |
| 694 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 695 ash::ShelfItemDelegate* ChromeLauncherControllerImpl::GetLauncherItemController( |
| 695 const ash::ShelfID id) { | 696 const ash::ShelfID id) { |
| 696 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 697 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 697 return iter == id_to_item_controller_map_.end() ? nullptr : iter->second; | 698 return iter == id_to_item_controller_map_.end() ? nullptr : iter->second; |
| 698 } | 699 } |
| 699 | 700 |
| 700 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( | 701 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
| 701 ash::WmShelf* shelf, | 702 ash::WmShelf* shelf, |
| 702 const AccountId& account_id) const { | 703 const AccountId& account_id) const { |
| 703 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); | 704 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); |
| 704 if (!other_profile || other_profile == profile()) | 705 if (!other_profile || other_profile == profile()) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 728 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 729 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| 729 } | 730 } |
| 730 | 731 |
| 731 ArcAppDeferredLauncherController* | 732 ArcAppDeferredLauncherController* |
| 732 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { | 733 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { |
| 733 return arc_deferred_launcher_.get(); | 734 return arc_deferred_launcher_.get(); |
| 734 } | 735 } |
| 735 | 736 |
| 736 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( | 737 const std::string& ChromeLauncherControllerImpl::GetLaunchIDForShelfID( |
| 737 ash::ShelfID id) { | 738 ash::ShelfID id) { |
| 738 LauncherItemController* controller = GetLauncherItemController(id); | 739 ash::ShelfItemDelegate* controller = GetLauncherItemController(id); |
| 739 return controller ? controller->launch_id() : base::EmptyString(); | 740 return controller ? controller->launch_id() : base::EmptyString(); |
| 740 } | 741 } |
| 741 | 742 |
| 742 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { | 743 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { |
| 743 // The base class implementation updates the helper and app icon loaders. | 744 // The base class implementation updates the helper and app icon loaders. |
| 744 ChromeLauncherController::AttachProfile(profile_to_attach); | 745 ChromeLauncherController::AttachProfile(profile_to_attach); |
| 745 | 746 |
| 746 pref_change_registrar_.Init(profile()->GetPrefs()); | 747 pref_change_registrar_.Init(profile()->GetPrefs()); |
| 747 pref_change_registrar_.Add( | 748 pref_change_registrar_.Add( |
| 748 prefs::kPolicyPinnedLauncherApps, | 749 prefs::kPolicyPinnedLauncherApps, |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 SetVirtualKeyboardBehaviorFromPrefs(); | 935 SetVirtualKeyboardBehaviorFromPrefs(); |
| 935 | 936 |
| 936 prefs_observer_ = | 937 prefs_observer_ = |
| 937 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); | 938 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); |
| 938 } | 939 } |
| 939 | 940 |
| 940 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 941 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
| 941 const ash::AppLaunchId& app_launch_id, | 942 const ash::AppLaunchId& app_launch_id, |
| 942 int index) { | 943 int index) { |
| 943 AppShortcutLauncherItemController* controller = | 944 AppShortcutLauncherItemController* controller = |
| 944 AppShortcutLauncherItemController::Create(app_launch_id, this); | 945 AppShortcutLauncherItemController::Create(app_launch_id); |
| 945 return InsertAppLauncherItem(controller, ash::STATUS_CLOSED, index, | 946 return InsertAppLauncherItem(controller, ash::STATUS_CLOSED, index, |
| 946 ash::TYPE_PINNED_APP); | 947 ash::TYPE_PINNED_APP); |
| 947 } | 948 } |
| 948 | 949 |
| 949 /////////////////////////////////////////////////////////////////////////////// | 950 /////////////////////////////////////////////////////////////////////////////// |
| 950 // ChromeLauncherControllerImpl private: | 951 // ChromeLauncherControllerImpl private: |
| 951 | 952 |
| 952 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { | 953 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
| 953 RunningAppListIds list; | 954 RunningAppListIds list; |
| 954 for (int i = 0; i < model_->item_count(); i++) { | 955 for (int i = 0; i < model_->item_count(); i++) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 : ash::STATUS_RUNNING; | 1200 : ash::STATUS_RUNNING; |
| 1200 } else { | 1201 } else { |
| 1201 status = ash::STATUS_RUNNING; | 1202 status = ash::STATUS_RUNNING; |
| 1202 } | 1203 } |
| 1203 } | 1204 } |
| 1204 } | 1205 } |
| 1205 return status; | 1206 return status; |
| 1206 } | 1207 } |
| 1207 | 1208 |
| 1208 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( | 1209 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( |
| 1209 LauncherItemController* controller, | 1210 ash::ShelfItemDelegate* controller, |
| 1210 ash::ShelfItemStatus status, | 1211 ash::ShelfItemStatus status, |
| 1211 int index, | 1212 int index, |
| 1212 ash::ShelfItemType shelf_item_type) { | 1213 ash::ShelfItemType shelf_item_type) { |
| 1213 ash::ShelfID id = model_->next_id(); | 1214 ash::ShelfID id = model_->next_id(); |
| 1214 CHECK(!GetItem(id)); | 1215 CHECK(!GetItem(id)); |
| 1215 CHECK(controller); | 1216 CHECK(controller); |
| 1216 // Ash's ShelfWindowWatcher handles app panel windows separately. | 1217 // Ash's ShelfWindowWatcher handles app panel windows separately. |
| 1217 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); | 1218 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); |
| 1218 id_to_item_controller_map_[id] = controller; | 1219 id_to_item_controller_map_[id] = controller; |
| 1219 controller->set_shelf_id(id); | 1220 controller->set_shelf_id(id); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1252 ash::ShelfItem browser_shortcut; | 1253 ash::ShelfItem browser_shortcut; |
| 1253 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1254 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
| 1254 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1255 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1255 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1256 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
| 1256 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 1257 browser_shortcut.title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 1257 browser_shortcut.app_launch_id = | 1258 browser_shortcut.app_launch_id = |
| 1258 ash::AppLaunchId(extension_misc::kChromeAppId); | 1259 ash::AppLaunchId(extension_misc::kChromeAppId); |
| 1259 ash::ShelfID id = model_->next_id(); | 1260 ash::ShelfID id = model_->next_id(); |
| 1260 model_->AddAt(0, browser_shortcut); | 1261 model_->AddAt(0, browser_shortcut); |
| 1261 BrowserShortcutLauncherItemController* controller = | 1262 BrowserShortcutLauncherItemController* controller = |
| 1262 new BrowserShortcutLauncherItemController(this, model_); | 1263 new BrowserShortcutLauncherItemController(model_); |
| 1263 controller->set_shelf_id(id); | 1264 controller->set_shelf_id(id); |
| 1264 id_to_item_controller_map_[id] = controller; | 1265 id_to_item_controller_map_[id] = controller; |
| 1265 // ShelfModel owns BrowserShortcutLauncherItemController. | 1266 // ShelfModel owns BrowserShortcutLauncherItemController. |
| 1266 SetShelfItemDelegate(id, controller); | 1267 SetShelfItemDelegate(id, controller); |
| 1267 controller->UpdateBrowserItemState(); | 1268 controller->UpdateBrowserItemState(); |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 bool ChromeLauncherControllerImpl::IsIncognito( | 1271 bool ChromeLauncherControllerImpl::IsIncognito( |
| 1271 const content::WebContents* web_contents) const { | 1272 const content::WebContents* web_contents) const { |
| 1272 const Profile* profile = | 1273 const Profile* profile = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1308 while (!browser_to_close.empty()) { | 1309 while (!browser_to_close.empty()) { |
| 1309 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); | 1310 TabStripModel* tab_strip = browser_to_close.back()->tab_strip_model(); |
| 1310 if (!tab_strip->empty()) | 1311 if (!tab_strip->empty()) |
| 1311 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 1312 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 1312 browser_to_close.pop_back(); | 1313 browser_to_close.pop_back(); |
| 1313 } | 1314 } |
| 1314 } | 1315 } |
| 1315 | 1316 |
| 1316 void ChromeLauncherControllerImpl::SetShelfItemDelegate( | 1317 void ChromeLauncherControllerImpl::SetShelfItemDelegate( |
| 1317 ash::ShelfID id, | 1318 ash::ShelfID id, |
| 1318 ash::mojom::ShelfItemDelegate* item_delegate) { | 1319 ash::ShelfItemDelegate* item_delegate) { |
| 1319 DCHECK_NE(id, ash::kInvalidShelfID); | 1320 DCHECK_NE(id, ash::kInvalidShelfID); |
| 1320 DCHECK(item_delegate); | 1321 DCHECK(item_delegate); |
| 1321 model_->SetShelfItemDelegate( | 1322 model_->SetShelfItemDelegate( |
| 1322 id, base::WrapUnique<ash::mojom::ShelfItemDelegate>(item_delegate)); | 1323 id, base::WrapUnique<ash::ShelfItemDelegate>(item_delegate)); |
| 1323 } | 1324 } |
| 1324 | 1325 |
| 1325 void ChromeLauncherControllerImpl::ReleaseProfile() { | 1326 void ChromeLauncherControllerImpl::ReleaseProfile() { |
| 1326 if (app_sync_ui_state_) | 1327 if (app_sync_ui_state_) |
| 1327 app_sync_ui_state_->RemoveObserver(this); | 1328 app_sync_ui_state_->RemoveObserver(this); |
| 1328 | 1329 |
| 1329 app_updaters_.clear(); | 1330 app_updaters_.clear(); |
| 1330 | 1331 |
| 1331 prefs_observer_.reset(); | 1332 prefs_observer_.reset(); |
| 1332 | 1333 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 old_item.app_launch_id.app_id()); | 1397 old_item.app_launch_id.app_id()); |
| 1397 | 1398 |
| 1398 ash::AppLaunchId app_launch_id(shelf_app_id, | 1399 ash::AppLaunchId app_launch_id(shelf_app_id, |
| 1399 old_item.app_launch_id.launch_id()); | 1400 old_item.app_launch_id.launch_id()); |
| 1400 ash::launcher::RemovePinPosition(profile(), app_launch_id); | 1401 ash::launcher::RemovePinPosition(profile(), app_launch_id); |
| 1401 } | 1402 } |
| 1402 } | 1403 } |
| 1403 | 1404 |
| 1404 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( | 1405 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
| 1405 ash::ShelfID id, | 1406 ash::ShelfID id, |
| 1406 ash::mojom::ShelfItemDelegate* item_delegate) { | 1407 ash::ShelfItemDelegate* item_delegate) { |
| 1407 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1408 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| 1408 // get into this state in the first place. | 1409 // get into this state in the first place. |
| 1409 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 1410 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| 1410 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) | 1411 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
| 1411 return; | 1412 return; |
| 1412 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; | 1413 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id; |
| 1413 id_to_item_controller_map_.erase(iter); | 1414 id_to_item_controller_map_.erase(iter); |
| 1414 } | 1415 } |
| 1415 | 1416 |
| 1416 /////////////////////////////////////////////////////////////////////////////// | 1417 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1449 // AppIconLoaderDelegate: | 1450 // AppIconLoaderDelegate: |
| 1450 | 1451 |
| 1451 void ChromeLauncherControllerImpl::OnAppImageUpdated( | 1452 void ChromeLauncherControllerImpl::OnAppImageUpdated( |
| 1452 const std::string& id, | 1453 const std::string& id, |
| 1453 const gfx::ImageSkia& image) { | 1454 const gfx::ImageSkia& image) { |
| 1454 // TODO: need to get this working for shortcuts. | 1455 // TODO: need to get this working for shortcuts. |
| 1455 for (int index = 0; index < model_->item_count(); ++index) { | 1456 for (int index = 0; index < model_->item_count(); ++index) { |
| 1456 ash::ShelfItem item = model_->items()[index]; | 1457 ash::ShelfItem item = model_->items()[index]; |
| 1457 if (GetAppIDForShelfID(item.id) != id) | 1458 if (GetAppIDForShelfID(item.id) != id) |
| 1458 continue; | 1459 continue; |
| 1459 LauncherItemController* controller = GetLauncherItemController(item.id); | 1460 ash::ShelfItemDelegate* controller = GetLauncherItemController(item.id); |
| 1460 if (!controller || controller->image_set_by_controller()) | 1461 if (!controller || controller->image_set_by_controller()) |
| 1461 continue; | 1462 continue; |
| 1462 item.image = image; | 1463 item.image = image; |
| 1463 if (arc_deferred_launcher_) | 1464 if (arc_deferred_launcher_) |
| 1464 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1465 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1465 model_->Set(index, item); | 1466 model_->Set(index, item); |
| 1466 // It's possible we're waiting on more than one item, so don't break. | 1467 // It's possible we're waiting on more than one item, so don't break. |
| 1467 } | 1468 } |
| 1468 } | 1469 } |
| OLD | NEW |