| 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 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "ash/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: | 81 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: |
| 82 return blink::WebScreenOrientationLockPortraitSecondary; | 82 return blink::WebScreenOrientationLockPortraitSecondary; |
| 83 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: | 83 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: |
| 84 return blink::WebScreenOrientationLockLandscapeSecondary; | 84 return blink::WebScreenOrientationLockLandscapeSecondary; |
| 85 default: | 85 default: |
| 86 return blink::WebScreenOrientationLockAny; | 86 return blink::WebScreenOrientationLockAny; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 int GetWindowTaskId(aura::Window* window) { | 90 int GetWindowTaskId(aura::Window* window) { |
| 91 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); | 91 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); |
| 92 if (window_app_id.empty()) | 92 if (arc_app_id.empty()) |
| 93 return -1; | 93 return -1; |
| 94 | 94 |
| 95 int task_id = -1; | 95 int task_id = -1; |
| 96 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 96 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 97 return -1; | 97 return -1; |
| 98 | 98 |
| 99 return task_id; | 99 return task_id; |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 // The information about the arc application window which has to be kept |
| 105 // even when its AppWindow is not present. |
| 106 class ArcAppWindowLauncherController::AppWindowInfo { |
| 107 public: |
| 108 explicit AppWindowInfo(const std::string& shelf_app_id) |
| 109 : shelf_app_id_(shelf_app_id) {} |
| 110 ~AppWindowInfo() {} |
| 111 |
| 112 const std::string& shelf_app_id() const { return shelf_app_id_; } |
| 113 |
| 114 bool has_requested_orientation_lock() const { |
| 115 return has_requested_orientation_lock_; |
| 116 } |
| 117 |
| 118 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { |
| 119 has_requested_orientation_lock_ = true; |
| 120 requested_orientation_lock_ = lock; |
| 121 } |
| 122 |
| 123 arc::mojom::OrientationLock requested_orientation_lock() const { |
| 124 return requested_orientation_lock_; |
| 125 } |
| 126 |
| 127 void set_app_window(std::unique_ptr<AppWindow> window) { |
| 128 app_window_ = std::move(window); |
| 129 } |
| 130 |
| 131 AppWindow* app_window() { return app_window_.get(); } |
| 132 |
| 133 private: |
| 134 std::string shelf_app_id_; |
| 135 bool has_requested_orientation_lock_ = false; |
| 136 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 137 arc::mojom::OrientationLock::NONE; |
| 138 std::unique_ptr<AppWindow> app_window_; |
| 139 |
| 140 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); |
| 141 }; |
| 142 |
| 143 // A ui::BaseWindow for a chromeos launcher to control ARC applications. |
| 104 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | 144 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
| 105 public: | 145 public: |
| 106 AppWindow(int task_id, | 146 AppWindow(int task_id, |
| 107 const std::string app_id, | |
| 108 views::Widget* widget, | 147 views::Widget* widget, |
| 109 ArcAppWindowLauncherController* owner) | 148 ArcAppWindowLauncherController* owner) |
| 110 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {} | 149 : task_id_(task_id), widget_(widget), owner_(owner) {} |
| 111 ~AppWindow() {} | 150 ~AppWindow() {} |
| 112 | 151 |
| 113 void SetController(ArcAppWindowLauncherItemController* controller) { | 152 void SetController(ArcAppWindowLauncherItemController* controller) { |
| 114 DCHECK(!controller_ && controller); | 153 DCHECK(!controller_ && controller); |
| 115 controller_ = controller; | 154 controller_ = controller; |
| 116 } | 155 } |
| 117 | 156 |
| 118 void ResetController() { controller_ = nullptr; } | 157 void ResetController() { controller_ = nullptr; } |
| 119 | 158 |
| 120 void SetFullscreenMode(FullScreenMode mode) { | 159 void SetFullscreenMode(FullScreenMode mode) { |
| 121 DCHECK(mode != FullScreenMode::NOT_DEFINED); | 160 DCHECK(mode != FullScreenMode::NOT_DEFINED); |
| 122 fullscreen_mode_ = mode; | 161 fullscreen_mode_ = mode; |
| 123 } | 162 } |
| 124 | 163 |
| 125 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } | 164 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } |
| 126 | 165 |
| 127 int task_id() const { return task_id_; } | 166 int task_id() const { return task_id_; } |
| 128 | 167 |
| 129 ash::ShelfID shelf_id() const { return shelf_id_; } | 168 ash::ShelfID shelf_id() const { return shelf_id_; } |
| 130 | 169 |
| 131 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } | 170 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } |
| 132 | 171 |
| 133 views::Widget* widget() const { return widget_; } | 172 views::Widget* widget() const { return widget_; } |
| 134 | 173 |
| 135 ArcAppWindowLauncherItemController* controller() { return controller_; } | 174 ArcAppWindowLauncherItemController* controller() { return controller_; } |
| 136 | 175 |
| 137 const std::string& app_id() { return app_id_; } | |
| 138 | |
| 139 // ui::BaseWindow: | 176 // ui::BaseWindow: |
| 140 bool IsActive() const override { | 177 bool IsActive() const override { |
| 141 return widget_->IsActive() && owner_->active_task_id_ == task_id_; | 178 return widget_->IsActive() && owner_->active_task_id_ == task_id_; |
| 142 } | 179 } |
| 143 | 180 |
| 144 bool IsMaximized() const override { | 181 bool IsMaximized() const override { |
| 145 NOTREACHED(); | 182 NOTREACHED(); |
| 146 return false; | 183 return false; |
| 147 } | 184 } |
| 148 | 185 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 234 |
| 198 void FlashFrame(bool flash) override { NOTREACHED(); } | 235 void FlashFrame(bool flash) override { NOTREACHED(); } |
| 199 | 236 |
| 200 bool IsAlwaysOnTop() const override { | 237 bool IsAlwaysOnTop() const override { |
| 201 NOTREACHED(); | 238 NOTREACHED(); |
| 202 return false; | 239 return false; |
| 203 } | 240 } |
| 204 | 241 |
| 205 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); } | 242 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); } |
| 206 | 243 |
| 207 arc::mojom::OrientationLock requested_orientation_lock() const { | |
| 208 return requested_orientation_lock_; | |
| 209 } | |
| 210 | |
| 211 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { | |
| 212 has_requested_orientation_lock_ = true; | |
| 213 requested_orientation_lock_ = lock; | |
| 214 } | |
| 215 | |
| 216 bool has_requested_orientation_lock() const { | |
| 217 return has_requested_orientation_lock_; | |
| 218 } | |
| 219 | |
| 220 private: | 244 private: |
| 221 int task_id_; | 245 int task_id_; |
| 222 ash::ShelfID shelf_id_ = 0; | 246 ash::ShelfID shelf_id_ = 0; |
| 223 std::string app_id_; | |
| 224 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; | 247 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; |
| 225 // Unowned pointers | 248 // Unowned pointers |
| 226 views::Widget* const widget_; | 249 views::Widget* const widget_; |
| 227 ArcAppWindowLauncherController* owner_; | 250 ArcAppWindowLauncherController* owner_; |
| 228 ArcAppWindowLauncherItemController* controller_ = nullptr; | 251 ArcAppWindowLauncherItemController* controller_ = nullptr; |
| 229 // Unowned pointer, represents host Arc window. | 252 // Unowned pointer, represents host Arc window. |
| 230 | 253 |
| 231 arc::mojom::OrientationLock requested_orientation_lock_ = | |
| 232 arc::mojom::OrientationLock::NONE; | |
| 233 bool has_requested_orientation_lock_ = false; | |
| 234 | |
| 235 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 254 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 236 }; | 255 }; |
| 237 | 256 |
| 238 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 257 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 239 ChromeLauncherController* owner, | 258 ChromeLauncherController* owner, |
| 240 ash::ShelfDelegate* shelf_delegate) | 259 ash::ShelfDelegate* shelf_delegate) |
| 241 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { | 260 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { |
| 242 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { | 261 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { |
| 243 observed_profile_ = owner->GetProfile(); | 262 observed_profile_ = owner->GetProfile(); |
| 244 StartObserving(observed_profile_); | 263 StartObserving(observed_profile_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 271 const std::string& primary_user_email = user_manager::UserManager::Get() | 290 const std::string& primary_user_email = user_manager::UserManager::Get() |
| 272 ->GetPrimaryUser() | 291 ->GetPrimaryUser() |
| 273 ->GetAccountId() | 292 ->GetAccountId() |
| 274 .GetUserEmail(); | 293 .GetUserEmail(); |
| 275 if (user_email == primary_user_email) { | 294 if (user_email == primary_user_email) { |
| 276 // Restore existing Arc window and create controllers for them. | 295 // Restore existing Arc window and create controllers for them. |
| 277 AttachControllerToWindowsIfNeeded(); | 296 AttachControllerToWindowsIfNeeded(); |
| 278 | 297 |
| 279 // Make sure that we created items for all apps, not only which have a | 298 // Make sure that we created items for all apps, not only which have a |
| 280 // window. | 299 // window. |
| 281 for (const auto& it : task_id_to_shelf_app_id_) | 300 for (const auto& info : task_id_to_app_window_info_) |
| 282 AttachControllerToTask(it.second, it.first); | 301 AttachControllerToTask(info.second->shelf_app_id(), info.first); |
| 283 | 302 |
| 284 // Update active status. | 303 // Update active status. |
| 285 OnTaskSetActive(active_task_id_); | 304 OnTaskSetActive(active_task_id_); |
| 286 } else { | 305 } else { |
| 287 // Remove all Arc apps and destroy its controllers. There is no mapping | 306 // Remove all Arc apps and destroy its controllers. There is no mapping |
| 288 // task id to app window because it is not safe when controller is missing. | 307 // task id to app window because it is not safe when controller is missing. |
| 289 for (auto& it : task_id_to_app_window_) { | 308 for (auto& it : task_id_to_app_window_info_) |
| 290 AppWindow* app_window = it.second.get(); | 309 UnregisterApp(it.second.get(), true); |
| 291 UnregisterApp(app_window, true); | |
| 292 } | |
| 293 task_id_to_app_window_.clear(); | |
| 294 | 310 |
| 295 // Some controllers might have no windows attached, for example background | 311 // Some controllers might have no windows attached, for example background |
| 296 // task when foreground tasks is in full screen. | 312 // task when foreground tasks is in full screen. |
| 297 for (const auto& it : app_controller_map_) | 313 for (const auto& it : app_controller_map_) |
| 298 owner()->CloseLauncherItem(it.second->shelf_id()); | 314 owner()->CloseLauncherItem(it.second->shelf_id()); |
| 299 app_controller_map_.clear(); | 315 app_controller_map_.clear(); |
| 300 } | 316 } |
| 301 } | 317 } |
| 302 | 318 |
| 303 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( | 319 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 333 AttachControllerToWindowIfNeeded(window); | 349 AttachControllerToWindowIfNeeded(window); |
| 334 } | 350 } |
| 335 | 351 |
| 336 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 352 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| 337 auto it = | 353 auto it = |
| 338 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 354 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
| 339 DCHECK(it != observed_windows_.end()); | 355 DCHECK(it != observed_windows_.end()); |
| 340 observed_windows_.erase(it); | 356 observed_windows_.erase(it); |
| 341 window->RemoveObserver(this); | 357 window->RemoveObserver(this); |
| 342 | 358 |
| 343 auto it_app_window = | 359 auto info_it = std::find_if( |
| 344 std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(), | 360 task_id_to_app_window_info_.begin(), task_id_to_app_window_info_.end(), |
| 345 [window](const TaskIdToAppWindow::value_type& pair) { | 361 [window](TaskIdToAppWindowInfo::value_type& pair) { |
| 346 return pair.second->GetNativeWindow() == window; | 362 return pair.second->app_window() && |
| 347 }); | 363 pair.second->app_window()->GetNativeWindow() == window; |
| 348 if (it_app_window != task_id_to_app_window_.end()) { | 364 }); |
| 365 if (info_it != task_id_to_app_window_info_.end()) { |
| 349 // Note, window may be recreated in some cases, so do not close controller | 366 // Note, window may be recreated in some cases, so do not close controller |
| 350 // on window destroying. Controller will be closed onTaskDestroyed event | 367 // on window destroying. Controller will be closed onTaskDestroyed event |
| 351 // which is generated when actual task is destroyed. | 368 // which is generated when actual task is destroyed. |
| 352 UnregisterApp(it_app_window->second.get(), false); | 369 UnregisterApp(info_it->second.get(), false); |
| 353 task_id_to_app_window_.erase(it_app_window); | |
| 354 } | 370 } |
| 355 } | 371 } |
| 356 | 372 |
| 373 ArcAppWindowLauncherController::AppWindowInfo* |
| 374 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { |
| 375 const auto it = task_id_to_app_window_info_.find(task_id); |
| 376 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get(); |
| 377 } |
| 378 |
| 357 ArcAppWindowLauncherController::AppWindow* | 379 ArcAppWindowLauncherController::AppWindow* |
| 358 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | 380 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| 359 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 381 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 360 if (it == task_id_to_app_window_.end()) | 382 return info ? info->app_window() : nullptr; |
| 361 return nullptr; | |
| 362 return it->second.get(); | |
| 363 } | 383 } |
| 364 | 384 |
| 365 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { | 385 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { |
| 366 for (auto* window : observed_windows_) | 386 for (auto* window : observed_windows_) |
| 367 AttachControllerToWindowIfNeeded(window); | 387 AttachControllerToWindowIfNeeded(window); |
| 368 } | 388 } |
| 369 | 389 |
| 370 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( | 390 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( |
| 371 aura::Window* window) { | 391 aura::Window* window) { |
| 372 const int task_id = GetWindowTaskId(window); | 392 const int task_id = GetWindowTaskId(window); |
| 373 if (task_id <= 0) | 393 if (task_id <= 0) |
| 374 return; | 394 return; |
| 375 | 395 |
| 376 // We need to add the observer after exo started observing shell | 396 // We need to add the observer after exo started observing shell |
| 377 // because we want to update the orientation after exo send | 397 // because we want to update the orientation after exo send |
| 378 // the layout switch information. | 398 // the layout switch information. |
| 379 if (!observing_shell_) { | 399 if (!observing_shell_) { |
| 380 observing_shell_ = true; | 400 observing_shell_ = true; |
| 381 ash::WmShell::Get()->AddShellObserver(this); | 401 ash::WmShell::Get()->AddShellObserver(this); |
| 382 } | 402 } |
| 383 | 403 |
| 384 // Check if we have controller for this task. | 404 // Check if we have controller for this task. |
| 385 if (GetAppWindowForTask(task_id)) | 405 if (GetAppWindowForTask(task_id)) |
| 386 return; | 406 return; |
| 387 | 407 |
| 388 // Create controller if we have task info. | 408 // Create controller if we have task info. |
| 389 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); | 409 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 390 if (it == task_id_to_shelf_app_id_.end()) | 410 if (!info) { |
| 411 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; |
| 391 return; | 412 return; |
| 392 | 413 } |
| 393 const std::string& app_id = it->second; | |
| 394 | 414 |
| 395 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 415 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 396 DCHECK(widget); | 416 DCHECK(widget); |
| 397 std::unique_ptr<AppWindow> app_window( | 417 DCHECK(!info->app_window()); |
| 398 new AppWindow(task_id, app_id, widget, this)); | 418 info->set_app_window(base::MakeUnique<AppWindow>(task_id, widget, this)); |
| 399 RegisterApp(app_window.get()); | 419 RegisterApp(info); |
| 400 DCHECK(app_window->controller()); | 420 DCHECK(info->app_window()->controller()); |
| 401 ash::WmWindowAura::Get(window)->SetIntProperty( | 421 ash::WmWindowAura::Get(window)->SetIntProperty( |
| 402 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); | 422 ash::WmWindowProperty::SHELF_ID, info->app_window()->shelf_id()); |
| 403 if (ash::WmShell::Get() | 423 if (ash::WmShell::Get() |
| 404 ->maximize_mode_controller() | 424 ->maximize_mode_controller() |
| 405 ->IsMaximizeModeWindowManagerEnabled()) { | 425 ->IsMaximizeModeWindowManagerEnabled()) { |
| 406 SetOrientationLockForAppWindow(app_window.get()); | 426 SetOrientationLockForAppWindow(info->app_window()); |
| 407 } | 427 } |
| 408 task_id_to_app_window_[task_id] = std::move(app_window); | |
| 409 } | 428 } |
| 410 | 429 |
| 411 void ArcAppWindowLauncherController::OnAppReadyChanged( | 430 void ArcAppWindowLauncherController::OnAppReadyChanged( |
| 412 const std::string& app_id, | 431 const std::string& arc_app_id, |
| 413 bool ready) { | 432 bool ready) { |
| 414 if (!ready) | 433 if (!ready) |
| 415 OnAppRemoved(app_id); | 434 OnAppRemoved(arc_app_id); |
| 416 } | 435 } |
| 417 | 436 |
| 418 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { | 437 void ArcAppWindowLauncherController::OnAppRemoved( |
| 419 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(app_id); | 438 const std::string& arc_app_id) { |
| 439 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(arc_app_id); |
| 420 | 440 |
| 421 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); | 441 const auto it = app_controller_map_.find(shelf_app_id); |
| 422 if (it == app_controller_map_.end()) | 442 if (it == app_controller_map_.end()) |
| 423 return; | 443 return; |
| 424 | 444 |
| 425 const ArcAppWindowLauncherItemController* controller = it->second; | 445 const ArcAppWindowLauncherItemController* controller = it->second; |
| 426 | 446 |
| 427 std::vector<int> task_ids_to_remove; | 447 std::vector<int> task_ids_to_remove; |
| 428 for (auto* window : controller->windows()) { | 448 for (auto* window : controller->windows()) { |
| 429 AppWindow* app_window = static_cast<AppWindow*>(window); | 449 AppWindow* app_window = static_cast<AppWindow*>(window); |
| 430 task_ids_to_remove.push_back(app_window->task_id()); | 450 task_ids_to_remove.push_back(app_window->task_id()); |
| 431 } | 451 } |
| 432 | 452 |
| 433 for (const auto task_id : task_ids_to_remove) | 453 for (const auto task_id : task_ids_to_remove) |
| 434 OnTaskDestroyed(task_id); | 454 OnTaskDestroyed(task_id); |
| 435 | 455 |
| 436 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); | 456 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); |
| 437 } | 457 } |
| 438 | 458 |
| 439 void ArcAppWindowLauncherController::OnTaskCreated( | 459 void ArcAppWindowLauncherController::OnTaskCreated( |
| 440 int task_id, | 460 int task_id, |
| 441 const std::string& package_name, | 461 const std::string& package_name, |
| 442 const std::string& activity_name) { | 462 const std::string& activity_name) { |
| 443 DCHECK(!GetAppWindowForTask(task_id)); | 463 DCHECK(!GetAppWindowForTask(task_id)); |
| 444 const std::string shelf_app_id = GetShelfAppIdFromArcAppId( | 464 const std::string arc_app_id = |
| 445 ArcAppListPrefs::GetAppId(package_name, activity_name)); | 465 ArcAppListPrefs::GetAppId(package_name, activity_name); |
| 446 task_id_to_shelf_app_id_[task_id] = shelf_app_id; | 466 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(arc_app_id); |
| 447 | 467 task_id_to_app_window_info_[task_id] = |
| 468 base::MakeUnique<AppWindowInfo>(shelf_app_id); |
| 448 // Don't create shelf icon for non-primary user. | 469 // Don't create shelf icon for non-primary user. |
| 449 if (observed_profile_ != owner()->GetProfile()) | 470 if (observed_profile_ != owner()->GetProfile()) |
| 450 return; | 471 return; |
| 451 | 472 |
| 452 AttachControllerToWindowsIfNeeded(); | 473 AttachControllerToWindowsIfNeeded(); |
| 453 | 474 |
| 454 // Some tasks can be started in background and might have no window until | 475 // Some tasks can be started in background and might have no window until |
| 455 // pushed to the front. We need its representation on the shelf to give a user | 476 // pushed to the front. We need its representation on the shelf to give a user |
| 456 // control over it. | 477 // control over it. |
| 457 AttachControllerToTask(shelf_app_id, task_id); | 478 AttachControllerToTask(shelf_app_id, task_id); |
| 458 } | 479 } |
| 459 | 480 |
| 460 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 481 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 461 auto it = task_id_to_app_window_.find(task_id); | 482 auto it = task_id_to_app_window_info_.find(task_id); |
| 462 if (it != task_id_to_app_window_.end()) { | 483 if (it == task_id_to_app_window_info_.end()) |
| 463 AppWindow* app_window = it->second.get(); | 484 return; |
| 464 UnregisterApp(app_window, true); | 485 UnregisterApp(it->second.get(), true); |
| 465 task_id_to_app_window_.erase(it); | |
| 466 } | |
| 467 | 486 |
| 468 // Check if we may close controller now, at this point we can safely remove | 487 // Check if we may close controller now, at this point we can safely remove |
| 469 // controllers without window. | 488 // controllers without window. |
| 470 auto it_app_id = task_id_to_shelf_app_id_.find(task_id); | 489 const std::string& shelf_app_id = it->second->shelf_app_id(); |
| 471 if (it_app_id == task_id_to_shelf_app_id_.end()) | |
| 472 return; | |
| 473 | 490 |
| 474 const std::string& app_id = it_app_id->second; | 491 const auto it_controller = app_controller_map_.find(shelf_app_id); |
| 475 AppControllerMap::iterator it_controller = app_controller_map_.find(app_id); | |
| 476 if (it_controller != app_controller_map_.end()) { | 492 if (it_controller != app_controller_map_.end()) { |
| 477 ArcAppWindowLauncherItemController* controller = it_controller->second; | 493 ArcAppWindowLauncherItemController* controller = it_controller->second; |
| 478 controller->RemoveTaskId(task_id); | 494 controller->RemoveTaskId(task_id); |
| 479 if (!controller->window_count()) { | 495 if (!controller->window_count()) { |
| 480 owner()->CloseLauncherItem(controller->shelf_id()); | 496 owner()->CloseLauncherItem(controller->shelf_id()); |
| 481 app_controller_map_.erase(it_controller); | 497 app_controller_map_.erase(it_controller); |
| 482 } | 498 } |
| 483 } | 499 } |
| 484 | 500 |
| 485 task_id_to_shelf_app_id_.erase(it_app_id); | 501 task_id_to_app_window_info_.erase(it); |
| 486 } | 502 } |
| 487 | 503 |
| 488 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | 504 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { |
| 489 if (observed_profile_ != owner()->GetProfile()) { | 505 if (observed_profile_ != owner()->GetProfile()) { |
| 490 active_task_id_ = task_id; | 506 active_task_id_ = task_id; |
| 491 return; | 507 return; |
| 492 } | 508 } |
| 493 | 509 |
| 494 TaskIdToAppWindow::iterator previous_active_app_it = | 510 AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); |
| 495 task_id_to_app_window_.find(active_task_id_); | 511 if (previous_app_window) { |
| 496 if (previous_active_app_it != task_id_to_app_window_.end()) { | 512 owner()->SetItemStatus(previous_app_window->shelf_id(), |
| 497 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), | |
| 498 ash::STATUS_RUNNING); | 513 ash::STATUS_RUNNING); |
| 499 previous_active_app_it->second->SetFullscreenMode( | 514 previous_app_window->SetFullscreenMode( |
| 500 previous_active_app_it->second->widget() && | 515 previous_app_window->widget() && |
| 501 previous_active_app_it->second->widget()->IsFullscreen() | 516 previous_app_window->widget()->IsFullscreen() |
| 502 ? FullScreenMode::ACTIVE | 517 ? FullScreenMode::ACTIVE |
| 503 : FullScreenMode::NON_ACTIVE); | 518 : FullScreenMode::NON_ACTIVE); |
| 504 } | 519 } |
| 505 | 520 |
| 506 active_task_id_ = task_id; | 521 active_task_id_ = task_id; |
| 507 | 522 |
| 508 TaskIdToAppWindow::iterator new_active_app_it = | 523 AppWindow* current_app_window = GetAppWindowForTask(task_id); |
| 509 task_id_to_app_window_.find(active_task_id_); | 524 if (current_app_window) { |
| 510 if (new_active_app_it != task_id_to_app_window_.end()) { | |
| 511 owner()->SetItemStatus( | 525 owner()->SetItemStatus( |
| 512 new_active_app_it->second->shelf_id(), | 526 current_app_window->shelf_id(), |
| 513 new_active_app_it->second->widget() && | 527 current_app_window->widget() && current_app_window->IsActive() |
| 514 new_active_app_it->second->widget()->IsActive() | |
| 515 ? ash::STATUS_ACTIVE | 528 ? ash::STATUS_ACTIVE |
| 516 : ash::STATUS_RUNNING); | 529 : ash::STATUS_RUNNING); |
| 517 // TODO(reveman): Figure out how to support fullscreen in interleaved | 530 // TODO(reveman): Figure out how to support fullscreen in interleaved |
| 518 // window mode. | 531 // window mode. |
| 519 // if (new_active_app_it->second->widget()) { | 532 // if (new_active_app_it->second->widget()) { |
| 520 // new_active_app_it->second->widget()->SetFullscreen( | 533 // new_active_app_it->second->widget()->SetFullscreen( |
| 521 // new_active_app_it->second->fullscreen_mode() == | 534 // new_active_app_it->second->fullscreen_mode() == |
| 522 // FullScreenMode::ACTIVE); | 535 // FullScreenMode::ACTIVE); |
| 523 // } | 536 // } |
| 524 } | 537 } |
| 525 } | 538 } |
| 526 | 539 |
| 527 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( | 540 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( |
| 528 int32_t task_id, | 541 int32_t task_id, |
| 529 const arc::mojom::OrientationLock orientation_lock) { | 542 const arc::mojom::OrientationLock orientation_lock) { |
| 530 // Don't save to AppInfo because this is requested in runtime. | 543 // Don't save to AppInfo in prefs because this is requested in runtime. |
| 531 TaskIdToAppWindow::iterator app_it = task_id_to_app_window_.find(task_id); | 544 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 532 if (app_it == task_id_to_app_window_.end()) | 545 DCHECK(info); |
| 546 if (!info) |
| 533 return; | 547 return; |
| 534 AppWindow* app_window = app_it->second.get(); | 548 info->set_requested_orientation_lock(orientation_lock); |
| 535 app_window->set_requested_orientation_lock(orientation_lock); | |
| 536 | 549 |
| 537 if (ash::WmShell::Get() | 550 if (ash::WmShell::Get() |
| 538 ->maximize_mode_controller() | 551 ->maximize_mode_controller() |
| 539 ->IsMaximizeModeWindowManagerEnabled()) { | 552 ->IsMaximizeModeWindowManagerEnabled()) { |
| 540 SetOrientationLockForAppWindow(app_window); | 553 AppWindow* app_window = info->app_window(); |
| 554 if (app_window) |
| 555 SetOrientationLockForAppWindow(app_window); |
| 541 } | 556 } |
| 542 } | 557 } |
| 543 | 558 |
| 544 AppWindowLauncherItemController* | 559 AppWindowLauncherItemController* |
| 545 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { | 560 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { |
| 546 AppWindow* app_window = GetAppWindowForTask(active_task_id_); | 561 AppWindow* app_window = GetAppWindowForTask(active_task_id_); |
| 547 if (app_window && | 562 if (app_window && |
| 548 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { | 563 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { |
| 549 return app_window->controller(); | 564 return app_window->controller(); |
| 550 } | 565 } |
| 551 | 566 |
| 552 for (auto& it : task_id_to_app_window_) { | 567 for (auto& it : task_id_to_app_window_info_) { |
| 553 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) | 568 AppWindow* app_window = it.second->app_window(); |
| 554 return it.second->controller(); | 569 if (app_window && |
| 570 app_window->widget() == |
| 571 views::Widget::GetWidgetForNativeWindow(window)) { |
| 572 return it.second->app_window()->controller(); |
| 573 } |
| 555 } | 574 } |
| 556 | 575 |
| 557 return nullptr; | 576 return nullptr; |
| 558 } | 577 } |
| 559 | 578 |
| 560 void ArcAppWindowLauncherController::OnWindowActivated( | 579 void ArcAppWindowLauncherController::OnWindowActivated( |
| 561 aura::client::ActivationChangeObserver::ActivationReason reason, | 580 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 562 aura::Window* gained_active, | 581 aura::Window* gained_active, |
| 563 aura::Window* lost_active) { | 582 aura::Window* lost_active) { |
| 564 OnTaskSetActive(active_task_id_); | 583 OnTaskSetActive(active_task_id_); |
| 565 } | 584 } |
| 566 | 585 |
| 567 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { | 586 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { |
| 568 for (auto& it : task_id_to_app_window_) | 587 for (auto& it : task_id_to_app_window_info_) { |
| 569 SetOrientationLockForAppWindow(it.second.get()); | 588 AppWindow* app_window = it.second->app_window(); |
| 589 if (app_window) |
| 590 SetOrientationLockForAppWindow(app_window); |
| 591 } |
| 570 } | 592 } |
| 571 | 593 |
| 572 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { | 594 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { |
| 573 ash::ScreenOrientationController* orientation_controller = | 595 ash::ScreenOrientationController* orientation_controller = |
| 574 ash::Shell::GetInstance()->screen_orientation_controller(); | 596 ash::Shell::GetInstance()->screen_orientation_controller(); |
| 575 // Don't unlock one by one because it'll switch to next rotation. | 597 // Don't unlock one by one because it'll switch to next rotation. |
| 576 orientation_controller->UnlockAll(); | 598 orientation_controller->UnlockAll(); |
| 577 } | 599 } |
| 578 | 600 |
| 579 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { | 601 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 592 prefs->RemoveObserver(this); | 614 prefs->RemoveObserver(this); |
| 593 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 615 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
| 594 if (env) | 616 if (env) |
| 595 env->RemoveObserver(this); | 617 env->RemoveObserver(this); |
| 596 } | 618 } |
| 597 | 619 |
| 598 ArcAppWindowLauncherItemController* | 620 ArcAppWindowLauncherItemController* |
| 599 ArcAppWindowLauncherController::AttachControllerToTask( | 621 ArcAppWindowLauncherController::AttachControllerToTask( |
| 600 const std::string& shelf_app_id, | 622 const std::string& shelf_app_id, |
| 601 int task_id) { | 623 int task_id) { |
| 602 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); | 624 const auto it = app_controller_map_.find(shelf_app_id); |
| 603 if (it != app_controller_map_.end()) { | 625 if (it != app_controller_map_.end()) { |
| 604 DCHECK_EQ(it->second->app_id(), shelf_app_id); | 626 DCHECK_EQ(it->second->app_id(), shelf_app_id); |
| 605 it->second->AddTaskId(task_id); | 627 it->second->AddTaskId(task_id); |
| 606 return it->second; | 628 return it->second; |
| 607 } | 629 } |
| 608 | 630 |
| 609 ArcAppWindowLauncherItemController* controller = | 631 ArcAppWindowLauncherItemController* controller = |
| 610 new ArcAppWindowLauncherItemController(shelf_app_id, owner()); | 632 new ArcAppWindowLauncherItemController(shelf_app_id, owner()); |
| 611 const ash::ShelfID shelf_id = | 633 const ash::ShelfID shelf_id = |
| 612 shelf_delegate_->GetShelfIDForAppID(shelf_app_id); | 634 shelf_delegate_->GetShelfIDForAppID(shelf_app_id); |
| 613 if (!shelf_id) { | 635 if (!shelf_id) { |
| 614 owner()->CreateAppLauncherItem(controller, shelf_app_id, | 636 owner()->CreateAppLauncherItem(controller, shelf_app_id, |
| 615 ash::STATUS_RUNNING); | 637 ash::STATUS_RUNNING); |
| 616 } else { | 638 } else { |
| 617 owner()->SetItemController(shelf_id, controller); | 639 owner()->SetItemController(shelf_id, controller); |
| 618 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 640 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 619 } | 641 } |
| 620 controller->AddTaskId(task_id); | 642 controller->AddTaskId(task_id); |
| 621 app_controller_map_[shelf_app_id] = controller; | 643 app_controller_map_[shelf_app_id] = controller; |
| 622 return controller; | 644 return controller; |
| 623 } | 645 } |
| 624 | 646 |
| 625 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | 647 void ArcAppWindowLauncherController::RegisterApp( |
| 626 const std::string app_id = app_window->app_id(); | 648 AppWindowInfo* app_window_info) { |
| 627 DCHECK(!app_id.empty()); | 649 const std::string shelf_app_id = app_window_info->shelf_app_id(); |
| 628 | 650 DCHECK(!shelf_app_id.empty()); |
| 651 AppWindow* app_window = app_window_info->app_window(); |
| 629 ArcAppWindowLauncherItemController* controller = | 652 ArcAppWindowLauncherItemController* controller = |
| 630 AttachControllerToTask(app_id, app_window->task_id()); | 653 AttachControllerToTask(shelf_app_id, app_window->task_id()); |
| 631 DCHECK(controller); | 654 DCHECK(controller); |
| 632 | 655 |
| 633 const ash::ShelfID shelf_id = shelf_delegate_->GetShelfIDForAppID(app_id); | 656 const ash::ShelfID shelf_id = |
| 657 shelf_delegate_->GetShelfIDForAppID(shelf_app_id); |
| 634 DCHECK(shelf_id); | 658 DCHECK(shelf_id); |
| 635 | 659 |
| 636 controller->AddWindow(app_window); | 660 controller->AddWindow(app_window); |
| 637 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 661 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 638 app_window->SetController(controller); | 662 app_window->SetController(controller); |
| 639 app_window->set_shelf_id(shelf_id); | 663 app_window->set_shelf_id(shelf_id); |
| 640 } | 664 } |
| 641 | 665 |
| 642 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, | 666 void ArcAppWindowLauncherController::UnregisterApp( |
| 643 bool close_controller) { | 667 AppWindowInfo* app_window_info, |
| 644 const std::string app_id = app_window->app_id(); | 668 bool close_controller) { |
| 645 | 669 AppWindow* app_window = app_window_info->app_window(); |
| 646 DCHECK(!app_id.empty()); | 670 if (!app_window) |
| 647 AppControllerMap::iterator it = app_controller_map_.find(app_id); | 671 return; |
| 672 const std::string& shelf_app_id = app_window_info->shelf_app_id(); |
| 673 DCHECK(app_window); |
| 674 DCHECK(!shelf_app_id.empty()); |
| 675 const auto it = app_controller_map_.find(shelf_app_id); |
| 648 CHECK(it != app_controller_map_.end()); | 676 CHECK(it != app_controller_map_.end()); |
| 649 | 677 |
| 650 ArcAppWindowLauncherItemController* controller = it->second; | 678 ArcAppWindowLauncherItemController* controller = it->second; |
| 651 controller->RemoveWindow(app_window); | 679 controller->RemoveWindow(app_window); |
| 652 if (close_controller && !controller->window_count()) { | 680 if (close_controller && !controller->window_count()) { |
| 653 ash::ShelfID shelf_id = app_window->shelf_id(); | 681 ash::ShelfID shelf_id = app_window->shelf_id(); |
| 654 owner()->CloseLauncherItem(shelf_id); | 682 owner()->CloseLauncherItem(shelf_id); |
| 655 app_controller_map_.erase(it); | 683 app_controller_map_.erase(it); |
| 656 } | 684 } |
| 657 app_window->ResetController(); | 685 app_window->ResetController(); |
| 686 app_window_info->set_app_window(nullptr); |
| 658 } | 687 } |
| 659 | 688 |
| 660 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( | 689 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( |
| 661 AppWindow* app_window) { | 690 AppWindow* app_window) { |
| 662 ash::WmWindow* window = | 691 ash::WmWindow* window = |
| 663 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget()); | 692 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget()); |
| 664 if (!window) | 693 if (!window) |
| 665 return; | 694 return; |
| 695 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); |
| 666 arc::mojom::OrientationLock orientation_lock; | 696 arc::mojom::OrientationLock orientation_lock; |
| 667 if (app_window->has_requested_orientation_lock()) { | 697 |
| 668 orientation_lock = app_window->requested_orientation_lock(); | 698 if (info->has_requested_orientation_lock()) { |
| 699 orientation_lock = info->requested_orientation_lock(); |
| 669 } else { | 700 } else { |
| 670 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); | 701 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); |
| 671 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 702 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 672 prefs->GetApp(app_window->app_id()); | 703 prefs->GetApp(info->shelf_app_id()); |
| 673 if (!app_info) | 704 if (!app_info) |
| 674 return; | 705 return; |
| 675 orientation_lock = app_info->orientation_lock; | 706 orientation_lock = app_info->orientation_lock; |
| 676 } | 707 } |
| 677 | 708 |
| 678 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 709 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 679 // Resolve the orientation when it first resolved. | 710 // Resolve the orientation when it first resolved. |
| 680 orientation_lock = GetCurrentOrientation(); | 711 orientation_lock = GetCurrentOrientation(); |
| 681 app_window->set_requested_orientation_lock(orientation_lock); | 712 info->set_requested_orientation_lock(orientation_lock); |
| 682 } | 713 } |
| 683 | |
| 684 ash::Shell* shell = ash::Shell::GetInstance(); | 714 ash::Shell* shell = ash::Shell::GetInstance(); |
| 685 shell->screen_orientation_controller()->LockOrientationForWindow( | 715 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 686 window, BlinkOrientationLockFromMojom(orientation_lock)); | 716 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 687 } | 717 } |
| OLD | NEW |