OLD | NEW |
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_delegate.h" | |
8 #include "ash/shelf/shelf_model.h" | 7 #include "ash/shelf/shelf_model.h" |
9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
10 #include "ash/wm/window_properties.h" | 9 #include "ash/wm/window_properties.h" |
11 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
12 #include "ash/wm_window.h" | 11 #include "ash/wm_window.h" |
13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
17 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" | 16 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // which destroys AppWindow, so both |window| and the associated AppWindow | 123 // which destroys AppWindow, so both |window| and the associated AppWindow |
125 // are valid here. | 124 // are valid here. |
126 void ExtensionAppWindowLauncherController::OnWindowDestroying( | 125 void ExtensionAppWindowLauncherController::OnWindowDestroying( |
127 aura::Window* window) { | 126 aura::Window* window) { |
128 UnregisterApp(window); | 127 UnregisterApp(window); |
129 } | 128 } |
130 | 129 |
131 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | 130 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
132 // Windows created by IME extension should be treated the same way as the | 131 // Windows created by IME extension should be treated the same way as the |
133 // virtual keyboard window, which does not register itself in launcher. | 132 // virtual keyboard window, which does not register itself in launcher. |
134 if (app_window->is_ime_window()) | 133 // Ash's ShelfWindowWatcher handles app panel windows separately. |
| 134 if (app_window->is_ime_window() || app_window->window_type_is_panel()) |
135 return; | 135 return; |
136 | 136 |
137 // Ash's ShelfWindowWatcher handles app panel windows separately. | |
138 if (app_window->window_type_is_panel()) { | |
139 // Load panel app icons now. ShelfWindowWatcher cannot easily trigger this, | |
140 // and ShelfModel::Set cannot be called in ShelfItemAdded, since ShelfView | |
141 // may not have added a view for the new shelf item at that point. | |
142 const std::string& app_id = app_window->extension_id(); | |
143 AppIconLoader* app_icon_loader = owner()->GetAppIconLoaderForApp(app_id); | |
144 if (app_icon_loader) { | |
145 app_icon_loader->FetchImage(app_id); | |
146 app_icon_loader->UpdateImage(app_id); | |
147 } | |
148 return; | |
149 } | |
150 | |
151 aura::Window* window = app_window->GetNativeWindow(); | 137 aura::Window* window = app_window->GetNativeWindow(); |
152 // Get the app's shelf identifier and add an entry to the map. | 138 // Get the app's shelf identifier and add an entry to the map. |
153 DCHECK(window_to_app_shelf_id_map_.find(window) == | 139 DCHECK(window_to_app_shelf_id_map_.find(window) == |
154 window_to_app_shelf_id_map_.end()); | 140 window_to_app_shelf_id_map_.end()); |
155 const std::string app_shelf_id = GetAppShelfId(app_window); | 141 const std::string app_shelf_id = GetAppShelfId(app_window); |
156 window_to_app_shelf_id_map_[window] = app_shelf_id; | 142 window_to_app_shelf_id_map_[window] = app_shelf_id; |
157 window->AddObserver(this); | 143 window->AddObserver(this); |
158 | 144 |
159 // Find or create an item controller and launcher item. | 145 // Find or create an item controller and launcher item. |
160 std::string app_id = app_window->extension_id(); | 146 std::string app_id = app_window->extension_id(); |
(...skipping 14 matching lines...) Expand all Loading... |
175 std::string launch_id = GetLaunchId(app_window); | 161 std::string launch_id = GetLaunchId(app_window); |
176 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = | 162 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = |
177 base::MakeUnique<ExtensionAppWindowLauncherItemController>( | 163 base::MakeUnique<ExtensionAppWindowLauncherItemController>( |
178 ash::AppLaunchId(app_id, launch_id)); | 164 ash::AppLaunchId(app_id, launch_id)); |
179 ExtensionAppWindowLauncherItemController* item_controller = | 165 ExtensionAppWindowLauncherItemController* item_controller = |
180 controller.get(); | 166 controller.get(); |
181 | 167 |
182 controller->AddAppWindow(app_window); | 168 controller->AddAppWindow(app_window); |
183 // If there is already a shelf id mapped to this AppLaunchId (e.g. pinned), | 169 // If there is already a shelf id mapped to this AppLaunchId (e.g. pinned), |
184 // use that shelf item. | 170 // use that shelf item. |
185 shelf_id = | 171 shelf_id = ash::Shell::Get()->shelf_model()->GetShelfIDForAppIDAndLaunchID( |
186 ash::Shell::Get()->shelf_delegate()->GetShelfIDForAppIDAndLaunchID( | 172 app_id, launch_id); |
187 app_id, launch_id); | |
188 | 173 |
189 if (shelf_id == 0) { | 174 if (shelf_id == 0) { |
190 shelf_id = owner()->CreateAppLauncherItem(std::move(controller), status); | 175 shelf_id = owner()->CreateAppLauncherItem(std::move(controller), status); |
191 // Restore any existing app icon and flag as set. | 176 // Restore any existing app icon and flag as set. |
192 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { | 177 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { |
193 owner()->SetLauncherItemImage(shelf_id, | 178 owner()->SetLauncherItemImage(shelf_id, |
194 app_window->app_icon().AsImageSkia()); | 179 app_window->app_icon().AsImageSkia()); |
195 item_controller->set_image_set_by_controller(true); | 180 item_controller->set_image_set_by_controller(true); |
196 } | 181 } |
197 } else { | 182 } else { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 WindowToAppShelfIdMap::iterator window_iter = | 230 WindowToAppShelfIdMap::iterator window_iter = |
246 window_to_app_shelf_id_map_.find(window); | 231 window_to_app_shelf_id_map_.find(window); |
247 if (window_iter == window_to_app_shelf_id_map_.end()) | 232 if (window_iter == window_to_app_shelf_id_map_.end()) |
248 return nullptr; | 233 return nullptr; |
249 AppControllerMap::iterator app_controller_iter = | 234 AppControllerMap::iterator app_controller_iter = |
250 app_controller_map_.find(window_iter->second); | 235 app_controller_map_.find(window_iter->second); |
251 if (app_controller_iter == app_controller_map_.end()) | 236 if (app_controller_iter == app_controller_map_.end()) |
252 return nullptr; | 237 return nullptr; |
253 return app_controller_iter->second; | 238 return app_controller_iter->second; |
254 } | 239 } |
OLD | NEW |