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 05cd17360af12941b2e28fad9ac4ba5c77d18ba7..54b6bc4052d0c03b8c2582f6fe330de48b518709 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,8 +153,15 @@ 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()) { |
+ window_controller_map_[window] = controller; |
+ } |
} |
owner()->SetItemStatus(shelf_id, status); |
ash::SetShelfIDForWindow(shelf_id, window); |
@@ -167,15 +176,25 @@ void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
window->RemoveObserver(this); |
AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
- DCHECK(iter2 != app_controller_map_.end()); |
- ExtensionAppWindowLauncherItemController* controller = iter2->second; |
+ WindowControllerMap::iterator iter3 = window_controller_map_.find(window); |
+ DCHECK(iter2 != app_controller_map_.end() || |
+ iter3 != window_controller_map_.end()); |
+ ExtensionAppWindowLauncherItemController* controller; |
+ if (iter2 != app_controller_map_.end()) |
+ controller = iter2->second; |
+ else |
+ controller = iter3->second; |
+ |
controller->RemoveWindowForNativeWindow(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 (iter2 != app_controller_map_.end()) |
+ app_controller_map_.erase(iter2); |
+ else |
+ window_controller_map_.erase(iter3); |
} |
} |
@@ -196,7 +215,10 @@ ExtensionAppWindowLauncherController::ControllerForWindow( |
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()) |
- return nullptr; |
- return iter2->second; |
+ WindowControllerMap::iterator iter3 = window_controller_map_.find(window); |
+ if (iter2 != app_controller_map_.end()) |
+ return iter2->second; |
+ if (iter3 != window_controller_map_.end()) |
+ return iter3->second; |
+ return nullptr; |
} |