| 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_model.h" | 7 #include "ash/shelf/shelf_model.h" |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/wm/window_properties.h" | 8 #include "ash/wm/window_properties.h" |
| 10 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 11 #include "ash/wm_window.h" | 10 #include "ash/wm_window.h" |
| 12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 16 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" | 15 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 16 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 18 #include "extensions/browser/app_window/app_window.h" | 17 #include "extensions/browser/app_window/app_window.h" |
| 19 #include "extensions/browser/app_window/native_app_window.h" | 18 #include "extensions/browser/app_window/native_app_window.h" |
| 20 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 21 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 23 | 22 |
| 24 using extensions::AppWindow; | 23 using extensions::AppWindow; |
| 25 using extensions::AppWindowRegistry; | 24 using extensions::AppWindowRegistry; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 std::string GetAppShelfId(AppWindow* app_window) { | 43 std::string GetAppShelfId(AppWindow* app_window) { |
| 45 // Set app_shelf_id value to app_id and then append launch_id. | 44 // Set app_shelf_id value to app_id and then append launch_id. |
| 46 std::string app_id = app_window->extension_id(); | 45 std::string app_id = app_window->extension_id(); |
| 47 std::string launch_id = GetLaunchId(app_window); | 46 std::string launch_id = GetLaunchId(app_window); |
| 48 return app_id + launch_id; | 47 return app_id + launch_id; |
| 49 } | 48 } |
| 50 | 49 |
| 51 } // namespace | 50 } // namespace |
| 52 | 51 |
| 53 ExtensionAppWindowLauncherController::ExtensionAppWindowLauncherController( | 52 ExtensionAppWindowLauncherController::ExtensionAppWindowLauncherController( |
| 54 ChromeLauncherController* owner) | 53 ChromeLauncherControllerImpl* owner) |
| 55 : AppWindowLauncherController(owner) { | 54 : AppWindowLauncherController(owner) { |
| 56 AppWindowRegistry* registry = AppWindowRegistry::Get(owner->profile()); | 55 AppWindowRegistry* registry = AppWindowRegistry::Get(owner->profile()); |
| 57 registry_.insert(registry); | 56 registry_.insert(registry); |
| 58 registry->AddObserver(this); | 57 registry->AddObserver(this); |
| 59 } | 58 } |
| 60 | 59 |
| 61 ExtensionAppWindowLauncherController::~ExtensionAppWindowLauncherController() { | 60 ExtensionAppWindowLauncherController::~ExtensionAppWindowLauncherController() { |
| 62 for (std::set<AppWindowRegistry*>::iterator it = registry_.begin(); | 61 for (std::set<AppWindowRegistry*>::iterator it = registry_.begin(); |
| 63 it != registry_.end(); ++it) | 62 it != registry_.end(); ++it) |
| 64 (*it)->RemoveObserver(this); | 63 (*it)->RemoveObserver(this); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 std::string launch_id = GetLaunchId(app_window); | 160 std::string launch_id = GetLaunchId(app_window); |
| 162 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = | 161 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = |
| 163 base::MakeUnique<ExtensionAppWindowLauncherItemController>( | 162 base::MakeUnique<ExtensionAppWindowLauncherItemController>( |
| 164 ash::AppLaunchId(app_id, launch_id)); | 163 ash::AppLaunchId(app_id, launch_id)); |
| 165 ExtensionAppWindowLauncherItemController* item_controller = | 164 ExtensionAppWindowLauncherItemController* item_controller = |
| 166 controller.get(); | 165 controller.get(); |
| 167 | 166 |
| 168 controller->AddAppWindow(app_window); | 167 controller->AddAppWindow(app_window); |
| 169 // If there is already a shelf id mapped to this AppLaunchId (e.g. pinned), | 168 // If there is already a shelf id mapped to this AppLaunchId (e.g. pinned), |
| 170 // use that shelf item. | 169 // use that shelf item. |
| 171 shelf_id = ash::Shell::Get()->shelf_model()->GetShelfIDForAppIDAndLaunchID( | 170 shelf_id = owner()->GetShelfIDForAppIDAndLaunchID(app_id, launch_id); |
| 172 app_id, launch_id); | |
| 173 | 171 |
| 174 if (shelf_id == 0) { | 172 if (shelf_id == 0) { |
| 175 shelf_id = owner()->CreateAppLauncherItem(std::move(controller), status); | 173 shelf_id = owner()->CreateAppLauncherItem(std::move(controller), status); |
| 176 // Restore any existing app icon and flag as set. | 174 // Restore any existing app icon and flag as set. |
| 177 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { | 175 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { |
| 178 owner()->SetLauncherItemImage(shelf_id, | 176 owner()->SetLauncherItemImage(shelf_id, |
| 179 app_window->app_icon().AsImageSkia()); | 177 app_window->app_icon().AsImageSkia()); |
| 180 item_controller->set_image_set_by_controller(true); | 178 item_controller->set_image_set_by_controller(true); |
| 181 } | 179 } |
| 182 } else { | 180 } else { |
| 183 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 181 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, |
| 184 shelf_model->SetShelfItemDelegate(shelf_id, std::move(controller)); | 182 std::move(controller)); |
| 185 } | 183 } |
| 186 | 184 |
| 187 // We need to change the controller associated with app_shelf_id. | 185 // We need to change the controller associated with app_shelf_id. |
| 188 app_controller_map_[app_shelf_id] = item_controller; | 186 app_controller_map_[app_shelf_id] = item_controller; |
| 189 } | 187 } |
| 190 owner()->SetItemStatus(shelf_id, status); | 188 owner()->SetItemStatus(shelf_id, status); |
| 191 ash::WmWindow::Get(window)->aura_window()->SetProperty(ash::kShelfIDKey, | 189 ash::WmWindow::Get(window)->aura_window()->SetProperty(ash::kShelfIDKey, |
| 192 shelf_id); | 190 shelf_id); |
| 193 } | 191 } |
| 194 | 192 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 WindowToAppShelfIdMap::iterator window_iter = | 228 WindowToAppShelfIdMap::iterator window_iter = |
| 231 window_to_app_shelf_id_map_.find(window); | 229 window_to_app_shelf_id_map_.find(window); |
| 232 if (window_iter == window_to_app_shelf_id_map_.end()) | 230 if (window_iter == window_to_app_shelf_id_map_.end()) |
| 233 return nullptr; | 231 return nullptr; |
| 234 AppControllerMap::iterator app_controller_iter = | 232 AppControllerMap::iterator app_controller_iter = |
| 235 app_controller_map_.find(window_iter->second); | 233 app_controller_map_.find(window_iter->second); |
| 236 if (app_controller_iter == app_controller_map_.end()) | 234 if (app_controller_iter == app_controller_map_.end()) |
| 237 return nullptr; | 235 return nullptr; |
| 238 return app_controller_iter->second; | 236 return app_controller_iter->second; |
| 239 } | 237 } |
| OLD | NEW |