| 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/display/screen_orientation_controller_chromeos.h" | 8 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 9 #include "ash/shared/app_types.h" | 9 #include "ash/shared/app_types.h" |
| 10 #include "ash/shelf/shelf_delegate.h" | |
| 11 #include "ash/shelf/shelf_model.h" | 10 #include "ash/shelf/shelf_model.h" |
| 12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 14 #include "ash/wm/window_properties.h" | 13 #include "ash/wm/window_properties.h" |
| 15 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 16 #include "ash/wm/window_state_aura.h" | 15 #include "ash/wm/window_state_aura.h" |
| 17 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 18 #include "ash/wm_window.h" | 17 #include "ash/wm_window.h" |
| 19 #include "base/bind.h" | 18 #include "base/bind.h" |
| 20 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Unowned pointers | 241 // Unowned pointers |
| 243 views::Widget* const widget_; | 242 views::Widget* const widget_; |
| 244 ArcAppWindowLauncherController* owner_; | 243 ArcAppWindowLauncherController* owner_; |
| 245 ArcAppWindowLauncherItemController* controller_ = nullptr; | 244 ArcAppWindowLauncherItemController* controller_ = nullptr; |
| 246 // Unowned pointer, represents host ARC window. | 245 // Unowned pointer, represents host ARC window. |
| 247 | 246 |
| 248 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 247 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 249 }; | 248 }; |
| 250 | 249 |
| 251 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 250 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 252 ChromeLauncherController* owner, | 251 ChromeLauncherController* owner) |
| 253 ash::ShelfDelegate* shelf_delegate) | 252 : AppWindowLauncherController(owner) { |
| 254 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { | |
| 255 if (arc::IsArcAllowedForProfile(owner->profile())) { | 253 if (arc::IsArcAllowedForProfile(owner->profile())) { |
| 256 observed_profile_ = owner->profile(); | 254 observed_profile_ = owner->profile(); |
| 257 StartObserving(observed_profile_); | 255 StartObserving(observed_profile_); |
| 258 } | 256 } |
| 259 } | 257 } |
| 260 | 258 |
| 261 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { | 259 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
| 262 if (observed_profile_) | 260 if (observed_profile_) |
| 263 StopObserving(observed_profile_); | 261 StopObserving(observed_profile_); |
| 264 if (observing_shell_) | 262 if (observing_shell_) |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 if (it != app_shelf_group_to_controller_map_.end()) { | 646 if (it != app_shelf_group_to_controller_map_.end()) { |
| 649 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); | 647 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); |
| 650 it->second->AddTaskId(task_id); | 648 it->second->AddTaskId(task_id); |
| 651 return it->second; | 649 return it->second; |
| 652 } | 650 } |
| 653 | 651 |
| 654 std::unique_ptr<ArcAppWindowLauncherItemController> controller = | 652 std::unique_ptr<ArcAppWindowLauncherItemController> controller = |
| 655 base::MakeUnique<ArcAppWindowLauncherItemController>( | 653 base::MakeUnique<ArcAppWindowLauncherItemController>( |
| 656 app_shelf_id.ToString()); | 654 app_shelf_id.ToString()); |
| 657 ArcAppWindowLauncherItemController* item_controller = controller.get(); | 655 ArcAppWindowLauncherItemController* item_controller = controller.get(); |
| 656 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); |
| 658 const ash::ShelfID shelf_id = | 657 const ash::ShelfID shelf_id = |
| 659 shelf_delegate_->GetShelfIDForAppID(app_shelf_id.ToString()); | 658 shelf_model->GetShelfIDForAppID(app_shelf_id.ToString()); |
| 660 if (!shelf_id) { | 659 if (shelf_id == ash::kInvalidShelfID) { |
| 661 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); | 660 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); |
| 662 } else { | 661 } else { |
| 663 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | |
| 664 shelf_model->SetShelfItemDelegate(shelf_id, std::move(controller)); | 662 shelf_model->SetShelfItemDelegate(shelf_id, std::move(controller)); |
| 665 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 663 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 666 } | 664 } |
| 667 item_controller->AddTaskId(task_id); | 665 item_controller->AddTaskId(task_id); |
| 668 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; | 666 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; |
| 669 return item_controller; | 667 return item_controller; |
| 670 } | 668 } |
| 671 | 669 |
| 672 void ArcAppWindowLauncherController::RegisterApp( | 670 void ArcAppWindowLauncherController::RegisterApp( |
| 673 AppWindowInfo* app_window_info) { | 671 AppWindowInfo* app_window_info) { |
| 674 AppWindow* app_window = app_window_info->app_window(); | 672 AppWindow* app_window = app_window_info->app_window(); |
| 675 ArcAppWindowLauncherItemController* controller = | 673 ArcAppWindowLauncherItemController* controller = |
| 676 AttachControllerToTask(app_window->task_id(), *app_window_info); | 674 AttachControllerToTask(app_window->task_id(), *app_window_info); |
| 677 DCHECK(controller); | 675 DCHECK(controller); |
| 678 | 676 |
| 679 const ash::ShelfID shelf_id = | 677 const ash::ShelfID shelf_id = |
| 680 shelf_delegate_->GetShelfIDForAppID(controller->app_id()); | 678 ash::Shell::Get()->shelf_model()->GetShelfIDForAppID( |
| 681 DCHECK(shelf_id); | 679 controller->app_id()); |
| 680 DCHECK_NE(shelf_id, ash::kInvalidShelfID); |
| 682 | 681 |
| 683 controller->AddWindow(app_window); | 682 controller->AddWindow(app_window); |
| 684 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 683 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 685 app_window->SetController(controller); | 684 app_window->SetController(controller); |
| 686 app_window->set_shelf_id(shelf_id); | 685 app_window->set_shelf_id(shelf_id); |
| 687 } | 686 } |
| 688 | 687 |
| 689 void ArcAppWindowLauncherController::UnregisterApp( | 688 void ArcAppWindowLauncherController::UnregisterApp( |
| 690 AppWindowInfo* app_window_info) { | 689 AppWindowInfo* app_window_info) { |
| 691 AppWindow* app_window = app_window_info->app_window(); | 690 AppWindow* app_window = app_window_info->app_window(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); | 736 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); |
| 738 if (arc_app_id.empty()) | 737 if (arc_app_id.empty()) |
| 739 return -1; | 738 return -1; |
| 740 | 739 |
| 741 int task_id = -1; | 740 int task_id = -1; |
| 742 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 741 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 743 return -1; | 742 return -1; |
| 744 | 743 |
| 745 return task_id; | 744 return task_id; |
| 746 } | 745 } |
| OLD | NEW |