Chromium Code Reviews| 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 | |
| 249 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 258 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 250 ChromeLauncherController* owner, | 259 ChromeLauncherController* owner, |
| 251 ash::ShelfDelegate* shelf_delegate) | 260 ash::ShelfDelegate* shelf_delegate) |
| 252 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { | 261 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { |
| 253 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { | 262 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { |
| 254 observed_profile_ = owner->GetProfile(); | 263 observed_profile_ = owner->GetProfile(); |
| 255 StartObserving(observed_profile_); | 264 StartObserving(observed_profile_); |
| 256 } | 265 } |
| 257 } | 266 } |
| 258 | 267 |
| 259 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { | 268 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
| 260 if (observed_profile_) | 269 if (observed_profile_) |
| 261 StopObserving(observed_profile_); | 270 StopObserving(observed_profile_); |
| 262 if (observing_shell_) | 271 if (observing_shell_) |
| 263 ash::WmShell::Get()->RemoveShellObserver(this); | 272 ash::WmShell::Get()->RemoveShellObserver(this); |
| 273 | |
| 274 // Special for M53 branch. Due different deletion order of the shell | |
|
khmel
2016/08/19 21:00:12
patch for M53
| |
| 275 // and shelf launcher controllers we have to care about pending Arc | |
| 276 // items because we cannot observe window detroying events anymore. | |
| 277 // This is the reason of crashing unit_tests: ArcOrientationLock | |
| 278 for (auto& it : task_id_to_app_window_) | |
| 279 UnregisterApp(it.second.get()); | |
| 264 } | 280 } |
| 265 | 281 |
| 266 // static | 282 // static |
| 267 std::string ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( | 283 std::string ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId( |
| 268 const std::string& arc_app_id) { | 284 const std::string& arc_app_id) { |
| 269 return arc_app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId | 285 return arc_app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId |
| 270 : arc_app_id; | 286 : arc_app_id; |
| 271 } | 287 } |
| 272 | 288 |
| 273 // static | 289 // static |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 304 return; | 320 return; |
| 305 observed_windows_.push_back(window); | 321 observed_windows_.push_back(window); |
| 306 window->AddObserver(this); | 322 window->AddObserver(this); |
| 307 } | 323 } |
| 308 | 324 |
| 309 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( | 325 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( |
| 310 aura::Window* window, | 326 aura::Window* window, |
| 311 bool visible) { | 327 bool visible) { |
| 312 // The application id property should be set at this time. | 328 // The application id property should be set at this time. |
| 313 if (visible) | 329 if (visible) |
| 314 CheckForAppWindowWidget(window); | 330 MayAttachContollerToWindow(window); |
| 315 } | 331 } |
| 316 | 332 |
| 317 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 333 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
| 318 auto it = | 334 auto it = |
| 319 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 335 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
| 320 DCHECK(it != observed_windows_.end()); | 336 DCHECK(it != observed_windows_.end()); |
| 321 observed_windows_.erase(it); | 337 observed_windows_.erase(it); |
| 322 window->RemoveObserver(this); | 338 window->RemoveObserver(this); |
| 323 | 339 |
| 324 for (auto& it : task_id_to_app_window_) { | 340 for (auto& it : task_id_to_app_window_) { |
| 325 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) | 341 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) |
| 326 it.second->set_widget(nullptr); | 342 it.second->set_widget(nullptr); |
| 327 } | 343 } |
| 328 } | 344 } |
| 329 | 345 |
| 330 ArcAppWindowLauncherController::AppWindow* | 346 ArcAppWindowLauncherController::AppWindow* |
| 331 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | 347 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| 332 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 348 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
| 333 if (it == task_id_to_app_window_.end()) | 349 if (it == task_id_to_app_window_.end()) |
| 334 return nullptr; | 350 return nullptr; |
| 335 return it->second.get(); | 351 return it->second.get(); |
| 336 } | 352 } |
| 337 | 353 |
| 338 void ArcAppWindowLauncherController::CheckForAppWindowWidget( | 354 void ArcAppWindowLauncherController::MayAttachContollerToWindow( |
| 339 aura::Window* window) { | 355 aura::Window* window) { |
| 340 const std::string app_id = exo::ShellSurface::GetApplicationId(window); | 356 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); |
| 341 if (app_id.empty()) | 357 if (window_app_id.empty()) |
| 342 return; | 358 return; |
| 343 | 359 |
| 344 int task_id = -1; | 360 int task_id = -1; |
| 345 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 361 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 346 return; | 362 return; |
| 347 | 363 |
| 348 if (task_id) { | 364 if (!task_id) |
| 349 // We need to add the observer after exo started observing shell | 365 return; |
| 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 } | |
| 356 | 366 |
| 357 AppWindow* app_window = GetAppWindowForTask(task_id); | 367 // We need to add the observer after exo started observing shell |
| 358 if (app_window) { | 368 // because we want to update the orientation after exo send |
| 359 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | 369 // the layout switch information. |
| 360 ash::SetShelfIDForWindow(app_window->shelf_id(), window); | 370 if (!observing_shell_) { |
| 361 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( | 371 observing_shell_ = true; |
| 362 window, | 372 ash::WmShell::Get()->AddShellObserver(this); |
| 363 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); | |
| 364 if (ash::Shell::GetInstance() | |
| 365 ->maximize_mode_controller() | |
| 366 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 367 SetOrientationLockForAppWindow(app_window); | |
| 368 } | |
| 369 } | |
| 370 } | 373 } |
| 374 | |
| 375 // Check if we have controller for this task. | |
| 376 if (GetAppWindowForTask(task_id)) | |
| 377 return; | |
| 378 | |
| 379 // Create controller if we have task info. | |
| 380 TaskIdToTaskInfoMap::iterator it = task_id_to_task_info_.find(task_id); | |
| 381 if (it == task_id_to_task_info_.end()) | |
| 382 return; | |
| 383 | |
| 384 const TaskInfo& task_info = *it->second; | |
| 385 const std::string app_id = | |
| 386 GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId( | |
| 387 task_info.package_name, task_info.activity_name)); | |
| 388 | |
| 389 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); | |
| 390 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | |
| 391 RegisterApp(app_window.get()); | |
| 392 DCHECK(app_window->controller()); | |
| 393 ash::SetShelfIDForWindow(app_window->shelf_id(), window); | |
| 394 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( | |
| 395 window, | |
| 396 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); | |
| 397 if (ash::Shell::GetInstance() | |
| 398 ->maximize_mode_controller() | |
| 399 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 400 SetOrientationLockForAppWindow(app_window.get()); | |
| 401 } | |
| 402 task_id_to_app_window_[task_id] = std::move(app_window); | |
| 403 | |
| 404 // TaskInfo is no longer needed. Discard it. | |
| 405 task_id_to_task_info_.erase(task_id); | |
| 371 } | 406 } |
| 372 | 407 |
| 373 void ArcAppWindowLauncherController::OnAppReadyChanged( | 408 void ArcAppWindowLauncherController::OnAppReadyChanged( |
| 374 const std::string& app_id, | 409 const std::string& app_id, |
| 375 bool ready) { | 410 bool ready) { |
| 376 if (!ready) | 411 if (!ready) |
| 377 OnAppRemoved(app_id); | 412 OnAppRemoved(app_id); |
| 378 } | 413 } |
| 379 | 414 |
| 380 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { | 415 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 396 OnTaskDestroyed(task_id); | 431 OnTaskDestroyed(task_id); |
| 397 | 432 |
| 398 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); | 433 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); |
| 399 } | 434 } |
| 400 | 435 |
| 401 void ArcAppWindowLauncherController::OnTaskCreated( | 436 void ArcAppWindowLauncherController::OnTaskCreated( |
| 402 int task_id, | 437 int task_id, |
| 403 const std::string& package_name, | 438 const std::string& package_name, |
| 404 const std::string& activity_name) { | 439 const std::string& activity_name) { |
| 405 DCHECK(!GetAppWindowForTask(task_id)); | 440 DCHECK(!GetAppWindowForTask(task_id)); |
| 441 std::unique_ptr<TaskInfo> task_info( | |
| 442 new TaskInfo(package_name, activity_name)); | |
| 443 task_id_to_task_info_[task_id] = std::move(task_info); | |
| 406 | 444 |
| 407 const std::string app_id = GetShelfAppIdFromArcAppId( | 445 for (auto* window : observed_windows_) |
| 408 ArcAppListPrefs::GetAppId(package_name, activity_name)); | 446 MayAttachContollerToWindow(window); |
| 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); | |
| 417 } | 447 } |
| 418 | 448 |
| 419 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 449 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 450 task_id_to_task_info_.erase(task_id); | |
| 451 | |
| 420 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 452 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
| 421 if (it == task_id_to_app_window_.end()) | 453 if (it == task_id_to_app_window_.end()) |
| 422 return; | 454 return; |
| 423 | 455 |
| 424 AppWindow* app_window = it->second.get(); | 456 AppWindow* app_window = it->second.get(); |
| 425 UnregisterApp(app_window); | 457 UnregisterApp(app_window); |
| 426 | 458 |
| 427 task_id_to_app_window_.erase(it); | 459 task_id_to_app_window_.erase(it); |
| 428 } | 460 } |
| 429 | 461 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 | 632 |
| 601 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 633 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 602 // Resolve the orientation when it first resolved. | 634 // Resolve the orientation when it first resolved. |
| 603 orientation_lock = GetCurrentOrientation(); | 635 orientation_lock = GetCurrentOrientation(); |
| 604 app_window->set_requested_orientation_lock(orientation_lock); | 636 app_window->set_requested_orientation_lock(orientation_lock); |
| 605 } | 637 } |
| 606 | 638 |
| 607 shell->screen_orientation_controller()->LockOrientationForWindow( | 639 shell->screen_orientation_controller()->LockOrientationForWindow( |
| 608 window, BlinkOrientationLockFromMojom(orientation_lock)); | 640 window, BlinkOrientationLockFromMojom(orientation_lock)); |
| 609 } | 641 } |
| OLD | NEW |