Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
| diff --git a/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
| index 425caa8329826c15495861bea758c5bceffca420..97bf157ea17a8a2789ae8357959c82b34c45370c 100644 |
| --- a/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
| +++ b/chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc |
| @@ -122,7 +122,8 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| : ash::STATUS_RUNNING; |
| AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); |
| ash::ShelfID shelf_id = 0; |
| - if (iter != app_controller_map_.end()) { |
| + |
| + if (!app_window->show_in_shelf() && iter != app_controller_map_.end()) { |
| ExtensionAppWindowLauncherItemController* controller = iter->second; |
| DCHECK(controller->app_id() == app_id); |
| shelf_id = controller->shelf_id(); |
| @@ -137,10 +138,11 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| owner()); |
| controller->AddAppWindow(app_window); |
| // If the app shelf id is not unique, and there is already a shelf |
| - // item for this app id (e.g. pinned), use that shelf item. |
| + // item for this app id (e.g. pinned), use that shelf item, except for the |
| + // case when the showInShelf parameter is true. |
| if (app_shelf_id == app_id) |
| shelf_id = owner()->GetShelfIDForAppID(app_id); |
| - if (shelf_id == 0) { |
| + if (shelf_id == 0 || app_window->show_in_shelf()) { |
| shelf_id = owner()->CreateAppLauncherItem(controller, app_id, status); |
| // Restore any existing app icon and flag as set. |
| const gfx::Image& app_icon = app_window->app_icon(); |
| @@ -151,31 +153,50 @@ void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| } else { |
| owner()->SetItemController(shelf_id, controller); |
| } |
| + |
| const std::string app_shelf_id = GetAppShelfId(app_window); |
| - app_controller_map_[app_shelf_id] = controller; |
| + // We need to change the controller associated with the app if there is no |
| + // controller currently tied to the app shelf id (first window). |
| + if (!app_controller_map_[app_shelf_id]) { |
| + app_controller_map_[app_shelf_id] = controller; |
| + } else if (app_window->show_in_shelf()) { |
| + secondary_window_controller_map_[window] = controller; |
| + } |
| } |
| owner()->SetItemStatus(shelf_id, status); |
| ash::SetShelfIDForWindow(shelf_id, window); |
| } |
| void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
| - WindowToAppShelfIdMap::iterator iter1 = |
| + WindowToAppShelfIdMap::iterator shelf_id_iter = |
| window_to_app_shelf_id_map_.find(window); |
| - DCHECK(iter1 != window_to_app_shelf_id_map_.end()); |
| - std::string app_shelf_id = iter1->second; |
| - window_to_app_shelf_id_map_.erase(iter1); |
| + DCHECK(shelf_id_iter != window_to_app_shelf_id_map_.end()); |
| + std::string app_shelf_id = shelf_id_iter->second; |
| + window_to_app_shelf_id_map_.erase(shelf_id_iter); |
| window->RemoveObserver(this); |
| - AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
| - DCHECK(iter2 != app_controller_map_.end()); |
| - ExtensionAppWindowLauncherItemController* controller = iter2->second; |
| + AppControllerMap::iterator app_controller_iter = |
| + app_controller_map_.find(app_shelf_id); |
| + WindowControllerMap::iterator secondary_window_iter = |
| + secondary_window_controller_map_.find(window); |
| + DCHECK(app_controller_iter != app_controller_map_.end() || |
| + secondary_window_iter != secondary_window_controller_map_.end()); |
| + ExtensionAppWindowLauncherItemController* controller; |
| + if (secondary_window_iter != secondary_window_controller_map_.end()) |
| + controller = secondary_window_iter->second; |
| + else |
| + controller = app_controller_iter->second; |
| + |
| controller->RemoveWindow(controller->GetAppWindow(window)); |
| if (controller->window_count() == 0) { |
| // If this is the last window associated with the app shelf id, close the |
| // shelf item. |
| ash::ShelfID shelf_id = controller->shelf_id(); |
| owner()->CloseLauncherItem(shelf_id); |
| - app_controller_map_.erase(iter2); |
| + if (secondary_window_iter != secondary_window_controller_map_.end()) |
| + secondary_window_controller_map_.erase(secondary_window_iter); |
| + else |
| + app_controller_map_.erase(app_controller_iter); |
| } |
| } |
| @@ -190,13 +211,18 @@ bool ExtensionAppWindowLauncherController::IsRegisteredApp( |
| AppWindowLauncherItemController* |
| ExtensionAppWindowLauncherController::ControllerForWindow( |
| aura::Window* window) { |
| - WindowToAppShelfIdMap::iterator iter1 = |
| + WindowToAppShelfIdMap::iterator shelf_id_iter = |
| window_to_app_shelf_id_map_.find(window); |
| - if (iter1 == window_to_app_shelf_id_map_.end()) |
| - return nullptr; |
| - std::string app_shelf_id = iter1->second; |
| - AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
| - if (iter2 == app_controller_map_.end()) |
| + if (shelf_id_iter == window_to_app_shelf_id_map_.end()) |
| return nullptr; |
| - return iter2->second; |
| + std::string app_shelf_id = shelf_id_iter->second; |
|
stevenjb
2016/05/03 20:39:49
No need for this temp, just use shelf_id_iter->sec
Andra Paraschiv
2016/05/04 11:59:09
Done.
|
| + WindowControllerMap::iterator secondary_window_iter = |
| + secondary_window_controller_map_.find(window); |
| + if (secondary_window_iter != secondary_window_controller_map_.end()) |
| + return secondary_window_iter->second; |
| + AppControllerMap::iterator app_controller_iter = |
| + app_controller_map_.find(app_shelf_id); |
| + if (app_controller_iter != app_controller_map_.end()) |
| + return app_controller_iter->second; |
| + return nullptr; |
| } |