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

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: Rebase v1 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;
162 } else if (app_window->show_in_shelf()) {
163 secondary_window_controller_map_[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 shelf_id_iter =
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(shelf_id_iter != window_to_app_shelf_id_map_.end());
165 std::string app_shelf_id = iter1->second; 174 std::string app_shelf_id = shelf_id_iter->second;
166 window_to_app_shelf_id_map_.erase(iter1); 175 window_to_app_shelf_id_map_.erase(shelf_id_iter);
167 window->RemoveObserver(this); 176 window->RemoveObserver(this);
168 177
169 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); 178 AppControllerMap::iterator app_controller_iter =
170 DCHECK(iter2 != app_controller_map_.end()); 179 app_controller_map_.find(app_shelf_id);
171 ExtensionAppWindowLauncherItemController* controller = iter2->second; 180 WindowControllerMap::iterator secondary_window_iter =
181 secondary_window_controller_map_.find(window);
182 DCHECK(app_controller_iter != app_controller_map_.end() ||
183 secondary_window_iter != secondary_window_controller_map_.end());
184 ExtensionAppWindowLauncherItemController* controller;
185 if (secondary_window_iter != secondary_window_controller_map_.end())
186 controller = secondary_window_iter->second;
187 else
188 controller = app_controller_iter->second;
189
172 controller->RemoveWindow(controller->GetAppWindow(window)); 190 controller->RemoveWindow(controller->GetAppWindow(window));
173 if (controller->window_count() == 0) { 191 if (controller->window_count() == 0) {
174 // If this is the last window associated with the app shelf id, close the 192 // If this is the last window associated with the app shelf id, close the
175 // shelf item. 193 // shelf item.
176 ash::ShelfID shelf_id = controller->shelf_id(); 194 ash::ShelfID shelf_id = controller->shelf_id();
177 owner()->CloseLauncherItem(shelf_id); 195 owner()->CloseLauncherItem(shelf_id);
178 app_controller_map_.erase(iter2); 196 if (secondary_window_iter != secondary_window_controller_map_.end())
197 secondary_window_controller_map_.erase(secondary_window_iter);
198 else
199 app_controller_map_.erase(app_controller_iter);
179 } 200 }
180 } 201 }
181 202
182 bool ExtensionAppWindowLauncherController::IsRegisteredApp( 203 bool ExtensionAppWindowLauncherController::IsRegisteredApp(
183 aura::Window* window) { 204 aura::Window* window) {
184 return window_to_app_shelf_id_map_.find(window) != 205 return window_to_app_shelf_id_map_.find(window) !=
185 window_to_app_shelf_id_map_.end(); 206 window_to_app_shelf_id_map_.end();
186 } 207 }
187 208
188 // Private Methods 209 // Private Methods
189 210
190 AppWindowLauncherItemController* 211 AppWindowLauncherItemController*
191 ExtensionAppWindowLauncherController::ControllerForWindow( 212 ExtensionAppWindowLauncherController::ControllerForWindow(
192 aura::Window* window) { 213 aura::Window* window) {
193 WindowToAppShelfIdMap::iterator iter1 = 214 WindowToAppShelfIdMap::iterator shelf_id_iter =
194 window_to_app_shelf_id_map_.find(window); 215 window_to_app_shelf_id_map_.find(window);
195 if (iter1 == window_to_app_shelf_id_map_.end()) 216 if (shelf_id_iter == window_to_app_shelf_id_map_.end())
196 return nullptr; 217 return nullptr;
197 std::string app_shelf_id = iter1->second; 218 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.
198 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); 219 WindowControllerMap::iterator secondary_window_iter =
199 if (iter2 == app_controller_map_.end()) 220 secondary_window_controller_map_.find(window);
200 return nullptr; 221 if (secondary_window_iter != secondary_window_controller_map_.end())
201 return iter2->second; 222 return secondary_window_iter->second;
223 AppControllerMap::iterator app_controller_iter =
224 app_controller_map_.find(app_shelf_id);
225 if (app_controller_iter != app_controller_map_.end())
226 return app_controller_iter->second;
227 return nullptr;
202 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698