| 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.h" |
| 7 #include "ash/shelf/shelf_delegate.h" | 8 #include "ash/shelf/shelf_delegate.h" |
| 8 #include "ash/shelf/shelf_util.h" | 9 #include "ash/shelf/shelf_util.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/system/status_area_widget.h" |
| 12 #include "ash/wm/window_state_aura.h" |
| 10 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 11 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 14 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" | 17 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont
roller.h" |
| 15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "extensions/browser/app_window/app_window.h" | 20 #include "extensions/browser/app_window/app_window.h" |
| 17 #include "extensions/browser/app_window/native_app_window.h" | 21 #include "extensions/browser/app_window/native_app_window.h" |
| 18 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
| 20 | 24 |
| 25 #if defined(OS_CHROMEOS) |
| 26 #include "ash/system/chromeos/ime_menu/ime_menu_tray.h" |
| 27 #endif // defined(OS_CHROMEOS) |
| 28 |
| 21 using extensions::AppWindow; | 29 using extensions::AppWindow; |
| 22 using extensions::AppWindowRegistry; | 30 using extensions::AppWindowRegistry; |
| 23 | 31 |
| 24 namespace { | 32 namespace { |
| 25 | 33 |
| 26 std::string GetAppShelfId(AppWindow* app_window) { | 34 std::string GetAppShelfId(AppWindow* app_window) { |
| 27 if (app_window->window_type_is_panel()) | 35 if (app_window->window_type_is_panel()) |
| 28 return base::StringPrintf("panel:%d", app_window->session_id().id()); | 36 return base::StringPrintf("panel:%d", app_window->session_id().id()); |
| 29 return app_window->extension_id(); | 37 return app_window->extension_id(); |
| 30 } | 38 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 UnregisterApp(window); | 110 UnregisterApp(window); |
| 103 } | 111 } |
| 104 | 112 |
| 105 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | 113 void ExtensionAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| 106 // Windows created by IME extension should be treated the same way as the | 114 // Windows created by IME extension should be treated the same way as the |
| 107 // virtual keyboard window, which does not register itself in launcher. | 115 // virtual keyboard window, which does not register itself in launcher. |
| 108 if (app_window->is_ime_window()) | 116 if (app_window->is_ime_window()) |
| 109 return; | 117 return; |
| 110 | 118 |
| 111 aura::Window* window = app_window->GetNativeWindow(); | 119 aura::Window* window = app_window->GetNativeWindow(); |
| 120 |
| 121 #if defined(OS_CHROMEOS) |
| 122 // IME window created by IME extension should also not register itself in the |
| 123 // lanucher. Instead, is should show ImeMenuTray in the status tray. |
| 124 if (extension_misc::IsImeMenuExtensionId(app_window->extension_id())) { |
| 125 ash::Shelf* shelf = ash::Shelf::ForWindow(app_window->GetNativeWindow()); |
| 126 if (shelf) { |
| 127 ash::ImeMenuTray* ime_menu_tray = |
| 128 shelf->shelf_widget()->status_area_widget()->ime_menu_tray(); |
| 129 if (ime_menu_tray) { |
| 130 ime_menu_tray->SetWindowState(ash::wm::GetWindowState(window)); |
| 131 // Sets the property of the window to indicate that the icon should be |
| 132 // shown on the status area tray. |
| 133 window->SetProperty(ash::kShelfItemOnTrayForImeMenu, true); |
| 134 ash::SetShelfIDForWindow(ash::kInvalidShelfID, window); |
| 135 } |
| 136 } |
| 137 return; |
| 138 } |
| 139 #endif // defined(OS_CHROMEOS) |
| 112 // Get the app's shelf identifier and add an entry to the map. | 140 // Get the app's shelf identifier and add an entry to the map. |
| 113 DCHECK(window_to_app_shelf_id_map_.find(window) == | 141 DCHECK(window_to_app_shelf_id_map_.find(window) == |
| 114 window_to_app_shelf_id_map_.end()); | 142 window_to_app_shelf_id_map_.end()); |
| 115 const std::string app_shelf_id = GetAppShelfId(app_window); | 143 const std::string app_shelf_id = GetAppShelfId(app_window); |
| 116 window_to_app_shelf_id_map_[window] = app_shelf_id; | 144 window_to_app_shelf_id_map_[window] = app_shelf_id; |
| 117 window->AddObserver(this); | 145 window->AddObserver(this); |
| 118 | 146 |
| 119 // Find or create an item controller and launcher item. | 147 // Find or create an item controller and launcher item. |
| 120 std::string app_id = app_window->extension_id(); | 148 std::string app_id = app_window->extension_id(); |
| 121 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) | 149 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 owner()->SetItemController(shelf_id, controller); | 184 owner()->SetItemController(shelf_id, controller); |
| 157 } | 185 } |
| 158 const std::string app_shelf_id = GetAppShelfId(app_window); | 186 const std::string app_shelf_id = GetAppShelfId(app_window); |
| 159 app_controller_map_[app_shelf_id] = controller; | 187 app_controller_map_[app_shelf_id] = controller; |
| 160 } | 188 } |
| 161 owner()->SetItemStatus(shelf_id, status); | 189 owner()->SetItemStatus(shelf_id, status); |
| 162 ash::SetShelfIDForWindow(shelf_id, window); | 190 ash::SetShelfIDForWindow(shelf_id, window); |
| 163 } | 191 } |
| 164 | 192 |
| 165 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { | 193 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
| 194 #if defined(OS_CHROMEOS) |
| 195 if (window->GetProperty(ash::kShelfItemOnTrayForImeMenu)) { |
| 196 ash::Shelf* shelf = ash::Shelf::ForWindow(window); |
| 197 if (shelf) { |
| 198 ash::ImeMenuTray* ime_menu_tray = |
| 199 shelf->shelf_widget()->status_area_widget()->ime_menu_tray(); |
| 200 if (ime_menu_tray) |
| 201 ime_menu_tray->SetWindowState(nullptr); |
| 202 } |
| 203 } |
| 204 #endif // defined(OS_CHROMEOS) |
| 205 if (window->GetProperty(ash::kShelfItemOnTrayForImeMenu)) |
| 206 return; |
| 207 |
| 166 WindowToAppShelfIdMap::iterator iter1 = | 208 WindowToAppShelfIdMap::iterator iter1 = |
| 167 window_to_app_shelf_id_map_.find(window); | 209 window_to_app_shelf_id_map_.find(window); |
| 168 DCHECK(iter1 != window_to_app_shelf_id_map_.end()); | 210 DCHECK(iter1 != window_to_app_shelf_id_map_.end()); |
| 169 std::string app_shelf_id = iter1->second; | 211 std::string app_shelf_id = iter1->second; |
| 170 window_to_app_shelf_id_map_.erase(iter1); | 212 window_to_app_shelf_id_map_.erase(iter1); |
| 171 window->RemoveObserver(this); | 213 window->RemoveObserver(this); |
| 172 | 214 |
| 173 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); | 215 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
| 174 DCHECK(iter2 != app_controller_map_.end()); | 216 DCHECK(iter2 != app_controller_map_.end()); |
| 175 ExtensionAppWindowLauncherItemController* controller = iter2->second; | 217 ExtensionAppWindowLauncherItemController* controller = iter2->second; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 197 WindowToAppShelfIdMap::iterator iter1 = | 239 WindowToAppShelfIdMap::iterator iter1 = |
| 198 window_to_app_shelf_id_map_.find(window); | 240 window_to_app_shelf_id_map_.find(window); |
| 199 if (iter1 == window_to_app_shelf_id_map_.end()) | 241 if (iter1 == window_to_app_shelf_id_map_.end()) |
| 200 return nullptr; | 242 return nullptr; |
| 201 std::string app_shelf_id = iter1->second; | 243 std::string app_shelf_id = iter1->second; |
| 202 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); | 244 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
| 203 if (iter2 == app_controller_map_.end()) | 245 if (iter2 == app_controller_map_.end()) |
| 204 return nullptr; | 246 return nullptr; |
| 205 return iter2->second; | 247 return iter2->second; |
| 206 } | 248 } |
| OLD | NEW |