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

Unified Diff: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc

Issue 1811523002: Enhance chrome.app.window API with better shelf integration Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [WIP] Rebase + browser tests. Added a new map that holds all the showInShelf windows. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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;
}

Powered by Google App Engine
This is Rietveld 408576698