| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 int task_id() const { return task_id_; } | 127 int task_id() const { return task_id_; } |
| 128 | 128 |
| 129 ash::ShelfID shelf_id() const { return shelf_id_; } | 129 ash::ShelfID shelf_id() const { return shelf_id_; } |
| 130 | 130 |
| 131 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } | 131 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } |
| 132 | 132 |
| 133 views::Widget* widget() const { return widget_; } | 133 views::Widget* widget() const { return widget_; } |
| 134 | 134 |
| 135 ArcAppWindowLauncherItemController* controller() { return controller_; } | 135 ArcAppWindowLauncherItemController* controller() { return controller_; } |
| 136 | 136 |
| 137 const std::string app_id() { return app_id_; } | 137 const std::string& app_id() { return app_id_; } |
| 138 | 138 |
| 139 // ui::BaseWindow: | 139 // ui::BaseWindow: |
| 140 bool IsActive() const override { | 140 bool IsActive() const override { |
| 141 return widget_->IsActive() && owner_->active_task_id_ == task_id_; | 141 return widget_->IsActive() && owner_->active_task_id_ == task_id_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool IsMaximized() const override { | 144 bool IsMaximized() const override { |
| 145 NOTREACHED(); | 145 NOTREACHED(); |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 void ArcAppWindowLauncherController::ActiveUserChanged( | 269 void ArcAppWindowLauncherController::ActiveUserChanged( |
| 270 const std::string& user_email) { | 270 const std::string& user_email) { |
| 271 const std::string& primary_user_email = user_manager::UserManager::Get() | 271 const std::string& primary_user_email = user_manager::UserManager::Get() |
| 272 ->GetPrimaryUser() | 272 ->GetPrimaryUser() |
| 273 ->GetAccountId() | 273 ->GetAccountId() |
| 274 .GetUserEmail(); | 274 .GetUserEmail(); |
| 275 if (user_email == primary_user_email) { | 275 if (user_email == primary_user_email) { |
| 276 // Restore existing Arc window and create controllers for them. | 276 // Restore existing Arc window and create controllers for them. |
| 277 AttachControllerToWindowsIfNeeded(); | 277 AttachControllerToWindowsIfNeeded(); |
| 278 |
| 279 // Make sure that we created items for all apps, not only which have a |
| 280 // window. |
| 281 for (const auto& it : task_id_to_shelf_app_id_) |
| 282 AttachControllerToTask(it.second, it.first); |
| 283 |
| 278 // Update active status. | 284 // Update active status. |
| 279 OnTaskSetActive(active_task_id_); | 285 OnTaskSetActive(active_task_id_); |
| 280 } else { | 286 } else { |
| 281 // Remove all Arc apps and destroy its controllers. There is no mapping | 287 // Remove all Arc apps and destroy its controllers. There is no mapping |
| 282 // task id to app window because it is not safe when controller is missing. | 288 // task id to app window because it is not safe when controller is missing. |
| 283 for (auto& it : task_id_to_app_window_) { | 289 for (auto& it : task_id_to_app_window_) { |
| 284 AppWindow* app_window = it.second.get(); | 290 AppWindow* app_window = it.second.get(); |
| 285 UnregisterApp(app_window, true); | 291 UnregisterApp(app_window, true); |
| 286 } | 292 } |
| 287 task_id_to_app_window_.clear(); | 293 task_id_to_app_window_.clear(); |
| 294 |
| 295 // Some controllers might have no windows attached, for example background |
| 296 // task when foreground tasks is in full screen. |
| 297 for (const auto& it : app_controller_map_) |
| 298 owner()->CloseLauncherItem(it.second->shelf_id()); |
| 299 app_controller_map_.clear(); |
| 288 } | 300 } |
| 289 } | 301 } |
| 290 | 302 |
| 291 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( | 303 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( |
| 292 Profile* profile) { | 304 Profile* profile) { |
| 293 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); | 305 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); |
| 294 } | 306 } |
| 295 | 307 |
| 296 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { | 308 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { |
| 297 // Arc windows has type WINDOW_TYPE_NORMAL. | 309 // Arc windows has type WINDOW_TYPE_NORMAL. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 OnTaskDestroyed(task_id); | 434 OnTaskDestroyed(task_id); |
| 423 | 435 |
| 424 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); | 436 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); |
| 425 } | 437 } |
| 426 | 438 |
| 427 void ArcAppWindowLauncherController::OnTaskCreated( | 439 void ArcAppWindowLauncherController::OnTaskCreated( |
| 428 int task_id, | 440 int task_id, |
| 429 const std::string& package_name, | 441 const std::string& package_name, |
| 430 const std::string& activity_name) { | 442 const std::string& activity_name) { |
| 431 DCHECK(!GetAppWindowForTask(task_id)); | 443 DCHECK(!GetAppWindowForTask(task_id)); |
| 432 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId( | 444 const std::string shelf_app_id = GetShelfAppIdFromArcAppId( |
| 433 ArcAppListPrefs::GetAppId(package_name, activity_name)); | 445 ArcAppListPrefs::GetAppId(package_name, activity_name)); |
| 446 task_id_to_shelf_app_id_[task_id] = shelf_app_id; |
| 434 | 447 |
| 435 // Don't create shelf icon for non-primary user. | 448 // Don't create shelf icon for non-primary user. |
| 436 if (observed_profile_ != owner()->GetProfile()) | 449 if (observed_profile_ != owner()->GetProfile()) |
| 437 return; | 450 return; |
| 438 | 451 |
| 439 AttachControllerToWindowsIfNeeded(); | 452 AttachControllerToWindowsIfNeeded(); |
| 453 |
| 454 // 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 |
| 456 // control over it. |
| 457 AttachControllerToTask(shelf_app_id, task_id); |
| 440 } | 458 } |
| 441 | 459 |
| 442 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 460 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 443 auto it = task_id_to_app_window_.find(task_id); | 461 auto it = task_id_to_app_window_.find(task_id); |
| 444 if (it != task_id_to_app_window_.end()) { | 462 if (it != task_id_to_app_window_.end()) { |
| 445 AppWindow* app_window = it->second.get(); | 463 AppWindow* app_window = it->second.get(); |
| 446 UnregisterApp(app_window, true); | 464 UnregisterApp(app_window, true); |
| 447 task_id_to_app_window_.erase(it); | 465 task_id_to_app_window_.erase(it); |
| 448 } | 466 } |
| 449 | 467 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { | 588 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { |
| 571 for (auto* window : observed_windows_) | 589 for (auto* window : observed_windows_) |
| 572 window->RemoveObserver(this); | 590 window->RemoveObserver(this); |
| 573 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); | 591 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); |
| 574 prefs->RemoveObserver(this); | 592 prefs->RemoveObserver(this); |
| 575 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 593 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
| 576 if (env) | 594 if (env) |
| 577 env->RemoveObserver(this); | 595 env->RemoveObserver(this); |
| 578 } | 596 } |
| 579 | 597 |
| 598 ArcAppWindowLauncherItemController* |
| 599 ArcAppWindowLauncherController::AttachControllerToTask( |
| 600 const std::string& shelf_app_id, |
| 601 int task_id) { |
| 602 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); |
| 603 if (it != app_controller_map_.end()) { |
| 604 DCHECK_EQ(it->second->app_id(), shelf_app_id); |
| 605 it->second->AddTaskId(task_id); |
| 606 return it->second; |
| 607 } |
| 608 |
| 609 ArcAppWindowLauncherItemController* controller = |
| 610 new ArcAppWindowLauncherItemController(shelf_app_id, owner()); |
| 611 const ash::ShelfID shelf_id = |
| 612 shelf_delegate_->GetShelfIDForAppID(shelf_app_id); |
| 613 if (!shelf_id) { |
| 614 owner()->CreateAppLauncherItem(controller, shelf_app_id, |
| 615 ash::STATUS_RUNNING); |
| 616 } else { |
| 617 owner()->SetItemController(shelf_id, controller); |
| 618 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 619 } |
| 620 controller->AddTaskId(task_id); |
| 621 app_controller_map_[shelf_app_id] = controller; |
| 622 return controller; |
| 623 } |
| 624 |
| 580 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | 625 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| 581 const std::string app_id = app_window->app_id(); | 626 const std::string app_id = app_window->app_id(); |
| 582 DCHECK(!app_id.empty()); | 627 DCHECK(!app_id.empty()); |
| 583 | 628 |
| 584 ArcAppWindowLauncherItemController* controller; | 629 ArcAppWindowLauncherItemController* controller = |
| 585 AppControllerMap::iterator it = app_controller_map_.find(app_id); | 630 AttachControllerToTask(app_id, app_window->task_id()); |
| 586 ash::ShelfID shelf_id = 0; | 631 DCHECK(controller); |
| 587 if (it != app_controller_map_.end()) { | 632 |
| 588 controller = it->second; | 633 const ash::ShelfID shelf_id = shelf_delegate_->GetShelfIDForAppID(app_id); |
| 589 DCHECK_EQ(controller->app_id(), app_id); | 634 DCHECK(shelf_id); |
| 590 shelf_id = controller->shelf_id(); | 635 |
| 591 } else { | |
| 592 controller = new ArcAppWindowLauncherItemController(app_id, owner()); | |
| 593 shelf_id = shelf_delegate_->GetShelfIDForAppID(app_id); | |
| 594 if (shelf_id == 0) { | |
| 595 // Map Play Store shelf icon to Arc Support host, to share one entry. | |
| 596 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, | |
| 597 ash::STATUS_RUNNING); | |
| 598 } else { | |
| 599 owner()->SetItemController(shelf_id, controller); | |
| 600 } | |
| 601 app_controller_map_[app_id] = controller; | |
| 602 } | |
| 603 controller->AddWindow(app_window); | 636 controller->AddWindow(app_window); |
| 604 controller->AddTaskId(app_window->task_id()); | |
| 605 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 637 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 606 app_window->SetController(controller); | 638 app_window->SetController(controller); |
| 607 app_window->set_shelf_id(shelf_id); | 639 app_window->set_shelf_id(shelf_id); |
| 608 } | 640 } |
| 609 | 641 |
| 610 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, | 642 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, |
| 611 bool close_controller) { | 643 bool close_controller) { |
| 612 const std::string app_id = app_window->app_id(); | 644 const std::string app_id = app_window->app_id(); |
| 613 | 645 |
| 614 DCHECK(!app_id.empty()); | 646 DCHECK(!app_id.empty()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 678 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 647 // Resolve the orientation when it first resolved. | 679 // Resolve the orientation when it first resolved. |
| 648 orientation_lock = GetCurrentOrientation(); | 680 orientation_lock = GetCurrentOrientation(); |
| 649 app_window->set_requested_orientation_lock(orientation_lock); | 681 app_window->set_requested_orientation_lock(orientation_lock); |
| 650 } | 682 } |
| 651 | 683 |
| 652 ash::Shell* shell = ash::Shell::GetInstance(); | 684 ash::Shell* shell = ash::Shell::GetInstance(); |
| 653 shell->screen_orientation_controller()->LockOrientationForWindow( | 685 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 654 window, BlinkOrientationLockFromMojom(orientation_lock)); | 686 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 655 } | 687 } |
| OLD | NEW |