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