| 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/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Unowned pointer, represents host Arc window. | 239 // Unowned pointer, represents host Arc window. |
| 240 views::Widget* widget_ = nullptr; | 240 views::Widget* widget_ = nullptr; |
| 241 | 241 |
| 242 arc::mojom::OrientationLock requested_orientation_lock_ = | 242 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 243 arc::mojom::OrientationLock::NONE; | 243 arc::mojom::OrientationLock::NONE; |
| 244 bool has_requested_orientation_lock_ = false; | 244 bool has_requested_orientation_lock_ = false; |
| 245 | 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 246 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 struct ArcAppWindowLauncherController::TaskInfo { | |
| 250 TaskInfo(const std::string& package_name, const std::string& activity_name) | |
| 251 : package_name(package_name), activity_name(activity_name) {} | |
| 252 ~TaskInfo() {} | |
| 253 | |
| 254 std::string package_name; | |
| 255 std::string activity_name; | |
| 256 }; | |
| 257 | |
| 258 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 249 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 259 ChromeLauncherController* owner, | 250 ChromeLauncherController* owner, |
| 260 ash::ShelfDelegate* shelf_delegate) | 251 ash::ShelfDelegate* shelf_delegate) |
| 261 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { | 252 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { |
| 262 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { | 253 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { |
| 263 observed_profile_ = owner->GetProfile(); | 254 observed_profile_ = owner->GetProfile(); |
| 264 StartObserving(observed_profile_); | 255 StartObserving(observed_profile_); |
| 265 } | 256 } |
| 266 } | 257 } |
| 267 | 258 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return; | 304 return; |
| 314 observed_windows_.push_back(window); | 305 observed_windows_.push_back(window); |
| 315 window->AddObserver(this); | 306 window->AddObserver(this); |
| 316 } | 307 } |
| 317 | 308 |
| 318 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( | 309 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( |
| 319 aura::Window* window, | 310 aura::Window* window, |
| 320 bool visible) { | 311 bool visible) { |
| 321 // The application id property should be set at this time. | 312 // The application id property should be set at this time. |
| 322 if (visible) | 313 if (visible) |
| 323 MayAttachContollerToWindow(window); | 314 CheckForAppWindowWidget(window); |
| 324 } | 315 } |
| 325 | 316 |
| 326 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 317 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| 327 auto it = | 318 auto it = |
| 328 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 319 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
| 329 DCHECK(it != observed_windows_.end()); | 320 DCHECK(it != observed_windows_.end()); |
| 330 observed_windows_.erase(it); | 321 observed_windows_.erase(it); |
| 331 window->RemoveObserver(this); | 322 window->RemoveObserver(this); |
| 332 | 323 |
| 333 for (auto& it : task_id_to_app_window_) { | 324 for (auto& it : task_id_to_app_window_) { |
| 334 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) | 325 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) |
| 335 it.second->set_widget(nullptr); | 326 it.second->set_widget(nullptr); |
| 336 } | 327 } |
| 337 } | 328 } |
| 338 | 329 |
| 339 ArcAppWindowLauncherController::AppWindow* | 330 ArcAppWindowLauncherController::AppWindow* |
| 340 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | 331 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| 341 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 332 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
| 342 if (it == task_id_to_app_window_.end()) | 333 if (it == task_id_to_app_window_.end()) |
| 343 return nullptr; | 334 return nullptr; |
| 344 return it->second.get(); | 335 return it->second.get(); |
| 345 } | 336 } |
| 346 | 337 |
| 347 void ArcAppWindowLauncherController::MayAttachContollerToWindow( | 338 void ArcAppWindowLauncherController::CheckForAppWindowWidget( |
| 348 aura::Window* window) { | 339 aura::Window* window) { |
| 349 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); | 340 const std::string app_id = exo::ShellSurface::GetApplicationId(window); |
| 350 if (window_app_id.empty()) | 341 if (app_id.empty()) |
| 351 return; | 342 return; |
| 352 | 343 |
| 353 int task_id = -1; | 344 int task_id = -1; |
| 354 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 345 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 355 return; | 346 return; |
| 356 | 347 |
| 357 if (!task_id) | 348 if (task_id) { |
| 358 return; | 349 // We need to add the observer after exo started observing shell |
| 350 // because we want to update the orientation after exo send |
| 351 // the layout switch information. |
| 352 if (!observing_shell_) { |
| 353 observing_shell_ = true; |
| 354 ash::WmShell::Get()->AddShellObserver(this); |
| 355 } |
| 359 | 356 |
| 360 // We need to add the observer after exo started observing shell | 357 AppWindow* app_window = GetAppWindowForTask(task_id); |
| 361 // because we want to update the orientation after exo send | 358 if (app_window) { |
| 362 // the layout switch information. | 359 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); |
| 363 if (!observing_shell_) { | 360 ash::SetShelfIDForWindow(app_window->shelf_id(), window); |
| 364 observing_shell_ = true; | 361 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| 365 ash::WmShell::Get()->AddShellObserver(this); | 362 window, |
| 363 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| 364 if (ash::Shell::GetInstance() |
| 365 ->maximize_mode_controller() |
| 366 ->IsMaximizeModeWindowManagerEnabled()) { |
| 367 SetOrientationLockForAppWindow(app_window); |
| 368 } |
| 369 } |
| 366 } | 370 } |
| 367 | |
| 368 // Check if we have controller for this task. | |
| 369 if (GetAppWindowForTask(task_id)) | |
| 370 return; | |
| 371 | |
| 372 // Create controller if we have task info. | |
| 373 TaskIdToTaskInfoMap::iterator it = task_id_to_task_info_.find(task_id); | |
| 374 if (it == task_id_to_task_info_.end()) | |
| 375 return; | |
| 376 | |
| 377 const TaskInfo& task_info = *it->second; | |
| 378 const std::string app_id = | |
| 379 GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId( | |
| 380 task_info.package_name, task_info.activity_name)); | |
| 381 | |
| 382 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); | |
| 383 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | |
| 384 RegisterApp(app_window.get()); | |
| 385 DCHECK(app_window->controller()); | |
| 386 ash::SetShelfIDForWindow(app_window->shelf_id(), window); | |
| 387 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( | |
| 388 window, | |
| 389 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); | |
| 390 if (ash::WmShell::Get() | |
| 391 ->maximize_mode_controller() | |
| 392 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 393 SetOrientationLockForAppWindow(app_window.get()); | |
| 394 } | |
| 395 task_id_to_app_window_[task_id] = std::move(app_window); | |
| 396 | |
| 397 // TaskInfo is no longer needed. Discard it. | |
| 398 task_id_to_task_info_.erase(task_id); | |
| 399 } | 371 } |
| 400 | 372 |
| 401 void ArcAppWindowLauncherController::OnAppReadyChanged( | 373 void ArcAppWindowLauncherController::OnAppReadyChanged( |
| 402 const std::string& app_id, | 374 const std::string& app_id, |
| 403 bool ready) { | 375 bool ready) { |
| 404 if (!ready) | 376 if (!ready) |
| 405 OnAppRemoved(app_id); | 377 OnAppRemoved(app_id); |
| 406 } | 378 } |
| 407 | 379 |
| 408 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { | 380 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 424 OnTaskDestroyed(task_id); | 396 OnTaskDestroyed(task_id); |
| 425 | 397 |
| 426 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); | 398 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); |
| 427 } | 399 } |
| 428 | 400 |
| 429 void ArcAppWindowLauncherController::OnTaskCreated( | 401 void ArcAppWindowLauncherController::OnTaskCreated( |
| 430 int task_id, | 402 int task_id, |
| 431 const std::string& package_name, | 403 const std::string& package_name, |
| 432 const std::string& activity_name) { | 404 const std::string& activity_name) { |
| 433 DCHECK(!GetAppWindowForTask(task_id)); | 405 DCHECK(!GetAppWindowForTask(task_id)); |
| 434 std::unique_ptr<TaskInfo> task_info( | |
| 435 new TaskInfo(package_name, activity_name)); | |
| 436 task_id_to_task_info_[task_id] = std::move(task_info); | |
| 437 | 406 |
| 438 for (auto* window : observed_windows_) | 407 const std::string app_id = GetShelfAppIdFromArcAppId( |
| 439 MayAttachContollerToWindow(window); | 408 ArcAppListPrefs::GetAppId(package_name, activity_name)); |
| 409 |
| 410 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); |
| 411 RegisterApp(app_window.get()); |
| 412 |
| 413 task_id_to_app_window_[task_id] = std::move(app_window); |
| 414 |
| 415 for (auto window : observed_windows_) |
| 416 CheckForAppWindowWidget(window); |
| 440 } | 417 } |
| 441 | 418 |
| 442 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 419 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 443 task_id_to_task_info_.erase(task_id); | |
| 444 | |
| 445 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 420 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
| 446 if (it == task_id_to_app_window_.end()) | 421 if (it == task_id_to_app_window_.end()) |
| 447 return; | 422 return; |
| 448 | 423 |
| 449 AppWindow* app_window = it->second.get(); | 424 AppWindow* app_window = it->second.get(); |
| 450 UnregisterApp(app_window); | 425 UnregisterApp(app_window); |
| 451 | 426 |
| 452 task_id_to_app_window_.erase(it); | 427 task_id_to_app_window_.erase(it); |
| 453 } | 428 } |
| 454 | 429 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 600 |
| 626 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 601 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 627 // Resolve the orientation when it first resolved. | 602 // Resolve the orientation when it first resolved. |
| 628 orientation_lock = GetCurrentOrientation(); | 603 orientation_lock = GetCurrentOrientation(); |
| 629 app_window->set_requested_orientation_lock(orientation_lock); | 604 app_window->set_requested_orientation_lock(orientation_lock); |
| 630 } | 605 } |
| 631 | 606 |
| 632 shell->screen_orientation_controller()->LockOrientationForWindow( | 607 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 633 window, BlinkOrientationLockFromMojom(orientation_lock)); | 608 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 634 } | 609 } |
| OLD | NEW |