| 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/public/cpp/shelf_types.h" | 7 #include "ash/public/cpp/shelf_types.h" |
| 8 #include "ash/public/cpp/window_properties.h" | 8 #include "ash/public/cpp/window_properties.h" |
| 9 #include "ash/shelf/shelf_model.h" | 9 #include "ash/shelf/shelf_model.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // are valid here. | 114 // are valid here. |
| 115 void ExtensionAppWindowLauncherController::OnWindowDestroying( | 115 void ExtensionAppWindowLauncherController::OnWindowDestroying( |
| 116 aura::Window* window) { | 116 aura::Window* window) { |
| 117 UnregisterApp(window); | 117 UnregisterApp(window); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | 120 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| 121 const ash::ShelfID shelf_id = GetShelfId(app_window); | 121 const ash::ShelfID shelf_id = GetShelfId(app_window); |
| 122 DCHECK(!shelf_id.IsNull()); | 122 DCHECK(!shelf_id.IsNull()); |
| 123 aura::Window* window = app_window->GetNativeWindow(); | 123 aura::Window* window = app_window->GetNativeWindow(); |
| 124 window->SetProperty(ash::kShelfIDKey, new ash::ShelfID(shelf_id)); | 124 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); |
| 125 | 125 |
| 126 // Windows created by IME extension should be treated the same way as the | 126 // Windows created by IME extension should be treated the same way as the |
| 127 // virtual keyboard window, which does not register itself in launcher. | 127 // virtual keyboard window, which does not register itself in launcher. |
| 128 // Ash's ShelfWindowWatcher handles app panel windows separately. | 128 // Ash's ShelfWindowWatcher handles app panel windows separately. |
| 129 if (app_window->is_ime_window() || app_window->window_type_is_panel()) | 129 if (app_window->is_ime_window() || app_window->window_type_is_panel()) |
| 130 return; | 130 return; |
| 131 | 131 |
| 132 // Get the app's shelf identifier and add an entry to the map. | 132 // Get the app's shelf identifier and add an entry to the map. |
| 133 DCHECK_EQ(window_to_shelf_id_map_.count(window), 0u); | 133 DCHECK_EQ(window_to_shelf_id_map_.count(window), 0u); |
| 134 window_to_shelf_id_map_[window] = shelf_id; | 134 window_to_shelf_id_map_[window] = shelf_id; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 app_controller_iter->second; | 146 app_controller_iter->second; |
| 147 DCHECK_EQ(controller->app_id(), shelf_id.app_id); | 147 DCHECK_EQ(controller->app_id(), shelf_id.app_id); |
| 148 controller->AddAppWindow(app_window); | 148 controller->AddAppWindow(app_window); |
| 149 } else { | 149 } else { |
| 150 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = | 150 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = |
| 151 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id); | 151 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id); |
| 152 app_controller_map_[shelf_id] = controller.get(); | 152 app_controller_map_[shelf_id] = controller.get(); |
| 153 controller->AddAppWindow(app_window); | 153 controller->AddAppWindow(app_window); |
| 154 | 154 |
| 155 // Check for any existing pinned shelf item with a matching |shelf_id|. | 155 // Check for any existing pinned shelf item with a matching |shelf_id|. |
| 156 if (owner()->GetItem(shelf_id) == nullptr) { | 156 if (!owner()->GetItem(shelf_id)) { |
| 157 owner()->CreateAppLauncherItem(std::move(controller), status); | 157 owner()->CreateAppLauncherItem(std::move(controller), status); |
| 158 // Restore any existing app icon and flag as set. | 158 // Restore any existing app icon and flag as set. |
| 159 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { | 159 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { |
| 160 owner()->SetLauncherItemImage(shelf_id, | 160 owner()->SetLauncherItemImage(shelf_id, |
| 161 app_window->app_icon().AsImageSkia()); | 161 app_window->app_icon().AsImageSkia()); |
| 162 app_controller_map_[shelf_id]->set_image_set_by_controller(true); | 162 app_controller_map_[shelf_id]->set_image_set_by_controller(true); |
| 163 } | 163 } |
| 164 } else { | 164 } else { |
| 165 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, | 165 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, |
| 166 std::move(controller)); | 166 std::move(controller)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 ExtensionAppWindowLauncherController::ControllerForWindow( | 203 ExtensionAppWindowLauncherController::ControllerForWindow( |
| 204 aura::Window* window) { | 204 aura::Window* window) { |
| 205 const auto window_iter = window_to_shelf_id_map_.find(window); | 205 const auto window_iter = window_to_shelf_id_map_.find(window); |
| 206 if (window_iter == window_to_shelf_id_map_.end()) | 206 if (window_iter == window_to_shelf_id_map_.end()) |
| 207 return nullptr; | 207 return nullptr; |
| 208 const auto controller_iter = app_controller_map_.find(window_iter->second); | 208 const auto controller_iter = app_controller_map_.find(window_iter->second); |
| 209 if (controller_iter == app_controller_map_.end()) | 209 if (controller_iter == app_controller_map_.end()) |
| 210 return nullptr; | 210 return nullptr; |
| 211 return controller_iter->second; | 211 return controller_iter->second; |
| 212 } | 212 } |
| OLD | NEW |