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

Side by Side Diff: chrome/browser/ui/ash/launcher/extension_app_window_launcher_controller.cc

Issue 1914993002: Enhance chrome.app.window API with better shelf integration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browsertest: Close windows in other order Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/extension_app_window_launcher_controlle r.h" 5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_controlle r.h"
6 6
7 #include "ash/shelf/shelf_util.h" 7 #include "ash/shelf/shelf_util.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 window_to_app_shelf_id_map_[window] = app_shelf_id; 115 window_to_app_shelf_id_map_[window] = app_shelf_id;
116 window->AddObserver(this); 116 window->AddObserver(this);
117 117
118 // Find or create an item controller and launcher item. 118 // Find or create an item controller and launcher item.
119 std::string app_id = app_window->extension_id(); 119 std::string app_id = app_window->extension_id();
120 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) 120 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window)
121 ? ash::STATUS_ACTIVE 121 ? ash::STATUS_ACTIVE
122 : ash::STATUS_RUNNING; 122 : ash::STATUS_RUNNING;
123 AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); 123 AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id);
124 ash::ShelfID shelf_id = 0; 124 ash::ShelfID shelf_id = 0;
125 if (iter != app_controller_map_.end()) { 125
126 if (!app_window->show_in_shelf() && iter != app_controller_map_.end()) {
126 ExtensionAppWindowLauncherItemController* controller = iter->second; 127 ExtensionAppWindowLauncherItemController* controller = iter->second;
127 DCHECK(controller->app_id() == app_id); 128 DCHECK(controller->app_id() == app_id);
128 shelf_id = controller->shelf_id(); 129 shelf_id = controller->shelf_id();
129 controller->AddAppWindow(app_window); 130 controller->AddAppWindow(app_window);
130 } else { 131 } else {
131 LauncherItemController::Type type = 132 LauncherItemController::Type type =
132 app_window->window_type_is_panel() 133 app_window->window_type_is_panel()
133 ? LauncherItemController::TYPE_APP_PANEL 134 ? LauncherItemController::TYPE_APP_PANEL
134 : LauncherItemController::TYPE_APP; 135 : LauncherItemController::TYPE_APP;
135 ExtensionAppWindowLauncherItemController* controller = 136 ExtensionAppWindowLauncherItemController* controller =
136 new ExtensionAppWindowLauncherItemController(type, app_shelf_id, app_id, 137 new ExtensionAppWindowLauncherItemController(type, app_shelf_id, app_id,
137 owner()); 138 owner());
138 controller->AddAppWindow(app_window); 139 controller->AddAppWindow(app_window);
139 // If the app shelf id is not unique, and there is already a shelf 140 // If the app shelf id is not unique, and there is already a shelf
140 // item for this app id (e.g. pinned), use that shelf item. 141 // item for this app id (e.g. pinned), use that shelf item, except for the
142 // case when the showInShelf parameter is true.
141 if (app_shelf_id == app_id) 143 if (app_shelf_id == app_id)
142 shelf_id = owner()->GetShelfIDForAppID(app_id); 144 shelf_id = owner()->GetShelfIDForAppID(app_id);
143 if (shelf_id == 0) { 145 if (shelf_id == 0 || app_window->show_in_shelf()) {
144 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, status); 146 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, status);
145 // Restore any existing app icon and flag as set. 147 // Restore any existing app icon and flag as set.
146 const gfx::Image& app_icon = app_window->app_icon(); 148 const gfx::Image& app_icon = app_window->app_icon();
147 if (!app_icon.IsEmpty()) { 149 if (!app_icon.IsEmpty()) {
148 owner()->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia()); 150 owner()->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia());
149 controller->set_image_set_by_controller(true); 151 controller->set_image_set_by_controller(true);
150 } 152 }
151 } else { 153 } else {
152 owner()->SetItemController(shelf_id, controller); 154 owner()->SetItemController(shelf_id, controller);
153 } 155 }
156
154 const std::string app_shelf_id = GetAppShelfId(app_window); 157 const std::string app_shelf_id = GetAppShelfId(app_window);
155 app_controller_map_[app_shelf_id] = controller; 158 // We need to change the controller associated with the app if there is no
159 // controller currently tied to the app shelf id (first window).
160 if (!app_controller_map_[app_shelf_id]) {
161 app_controller_map_[app_shelf_id] = controller;
stevenjb 2016/04/26 16:30:00 Use an iterator instead of doing the map lookup tw
Andra Paraschiv 2016/04/28 09:49:03 The code remained the same. When using an iterator
stevenjb 2016/05/03 20:39:48 Actually, [] will insert a new element (so this ef
Andra Paraschiv 2016/05/04 11:59:09 Done.
162 } else if (app_window->show_in_shelf()) {
163 window_controller_map_[window] = controller;
stevenjb 2016/04/26 16:30:00 This will only contain entries for secondary windo
Andra Paraschiv 2016/04/28 09:49:03 Renamed the member to secondary_window_controller_
164 }
156 } 165 }
157 owner()->SetItemStatus(shelf_id, status); 166 owner()->SetItemStatus(shelf_id, status);
158 ash::SetShelfIDForWindow(shelf_id, window); 167 ash::SetShelfIDForWindow(shelf_id, window);
159 } 168 }
160 169
161 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { 170 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) {
162 WindowToAppShelfIdMap::iterator iter1 = 171 WindowToAppShelfIdMap::iterator iter1 =
163 window_to_app_shelf_id_map_.find(window); 172 window_to_app_shelf_id_map_.find(window);
164 DCHECK(iter1 != window_to_app_shelf_id_map_.end()); 173 DCHECK(iter1 != window_to_app_shelf_id_map_.end());
165 std::string app_shelf_id = iter1->second; 174 std::string app_shelf_id = iter1->second;
166 window_to_app_shelf_id_map_.erase(iter1); 175 window_to_app_shelf_id_map_.erase(iter1);
167 window->RemoveObserver(this); 176 window->RemoveObserver(this);
168 177
169 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); 178 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id);
170 DCHECK(iter2 != app_controller_map_.end()); 179 WindowControllerMap::iterator iter3 = window_controller_map_.find(window);
stevenjb 2016/04/26 16:30:00 'iter2' wasn't a good name and adding 'iter3' make
Andra Paraschiv 2016/04/28 09:49:03 Done.
171 ExtensionAppWindowLauncherItemController* controller = iter2->second; 180 DCHECK(iter2 != app_controller_map_.end() ||
181 iter3 != window_controller_map_.end());
182 ExtensionAppWindowLauncherItemController* controller;
183 if (iter3 != window_controller_map_.end())
184 controller = iter3->second;
185 else
186 controller = iter2->second;
187
172 controller->RemoveWindowForNativeWindow(window); 188 controller->RemoveWindowForNativeWindow(window);
173 if (controller->window_count() == 0) { 189 if (controller->window_count() == 0) {
174 // If this is the last window associated with the app shelf id, close the 190 // If this is the last window associated with the app shelf id, close the
175 // shelf item. 191 // shelf item.
176 ash::ShelfID shelf_id = controller->shelf_id(); 192 ash::ShelfID shelf_id = controller->shelf_id();
177 owner()->CloseLauncherItem(shelf_id); 193 owner()->CloseLauncherItem(shelf_id);
178 app_controller_map_.erase(iter2); 194 if (iter3 != window_controller_map_.end())
195 window_controller_map_.erase(iter3);
196 else
197 app_controller_map_.erase(iter2);
179 } 198 }
180 } 199 }
181 200
182 bool ExtensionAppWindowLauncherController::IsRegisteredApp( 201 bool ExtensionAppWindowLauncherController::IsRegisteredApp(
183 aura::Window* window) { 202 aura::Window* window) {
184 return window_to_app_shelf_id_map_.find(window) != 203 return window_to_app_shelf_id_map_.find(window) !=
185 window_to_app_shelf_id_map_.end(); 204 window_to_app_shelf_id_map_.end();
186 } 205 }
187 206
188 // Private Methods 207 // Private Methods
189 208
190 AppWindowLauncherItemController* 209 AppWindowLauncherItemController*
191 ExtensionAppWindowLauncherController::ControllerForWindow( 210 ExtensionAppWindowLauncherController::ControllerForWindow(
192 aura::Window* window) { 211 aura::Window* window) {
193 WindowToAppShelfIdMap::iterator iter1 = 212 WindowToAppShelfIdMap::iterator iter1 =
194 window_to_app_shelf_id_map_.find(window); 213 window_to_app_shelf_id_map_.find(window);
195 if (iter1 == window_to_app_shelf_id_map_.end()) 214 if (iter1 == window_to_app_shelf_id_map_.end())
196 return nullptr; 215 return nullptr;
197 std::string app_shelf_id = iter1->second; 216 std::string app_shelf_id = iter1->second;
198 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); 217 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id);
stevenjb 2016/04/26 16:30:00 In this case we don't need iter2 unless iter3 == e
Andra Paraschiv 2016/04/28 09:49:03 Done.
199 if (iter2 == app_controller_map_.end()) 218 WindowControllerMap::iterator iter3 = window_controller_map_.find(window);
200 return nullptr; 219 if (iter3 != window_controller_map_.end())
201 return iter2->second; 220 return iter3->second;
221 if (iter2 != app_controller_map_.end())
222 return iter2->second;
223 return nullptr;
202 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698