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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 255 |
256 // static | 256 // static |
257 std::string ArcAppWindowLauncherController::GetArcAppIdFromShelfAppId( | 257 std::string ArcAppWindowLauncherController::GetArcAppIdFromShelfAppId( |
258 const std::string& shelf_app_id) { | 258 const std::string& shelf_app_id) { |
259 return shelf_app_id == ArcSupportHost::kHostAppId ? arc::kPlayStoreAppId | 259 return shelf_app_id == ArcSupportHost::kHostAppId ? arc::kPlayStoreAppId |
260 : shelf_app_id; | 260 : shelf_app_id; |
261 } | 261 } |
262 | 262 |
263 void ArcAppWindowLauncherController::ActiveUserChanged( | 263 void ArcAppWindowLauncherController::ActiveUserChanged( |
264 const std::string& user_email) { | 264 const std::string& user_email) { |
265 for (auto& it : task_id_to_app_window_) { | 265 const std::string& primary_user_email = user_manager::UserManager::Get() |
266 AppWindow* app_window = it.second.get(); | 266 ->GetPrimaryUser() |
267 if (user_email == | 267 ->GetAccountId() |
268 user_manager::UserManager::Get() | 268 .GetUserEmail(); |
269 ->GetPrimaryUser() | 269 if (user_email == primary_user_email) { |
270 ->GetAccountId() | 270 MaybeAttachContollerToWindows(); |
271 .GetUserEmail()) { | 271 OnTaskSetActive(active_task_id_); |
272 RegisterApp(app_window); | 272 } else { |
273 } else { | 273 for (auto& it : task_id_to_app_window_) { |
274 AppWindow* app_window = it.second.get(); | |
274 UnregisterApp(app_window, true); | 275 UnregisterApp(app_window, true); |
275 } | 276 } |
277 task_id_to_app_window_.clear(); | |
khmel
2016/09/06 20:46:13
It is not safe to keep mapping to AppWindow when c
Mr4D (OOO till 08-26)
2016/09/07 20:17:34
Can you please add a comment here to state this?
khmel
2016/09/07 21:01:47
Done.
| |
276 } | 278 } |
277 } | 279 } |
278 | 280 |
279 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( | 281 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( |
280 Profile* profile) { | 282 Profile* profile) { |
281 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); | 283 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); |
282 } | 284 } |
283 | 285 |
284 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { | 286 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { |
285 // Arc windows has type WINDOW_TYPE_NORMAL. | 287 // Arc windows has type WINDOW_TYPE_NORMAL. |
286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) | 288 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) |
287 return; | 289 return; |
288 observed_windows_.push_back(window); | 290 observed_windows_.push_back(window); |
289 window->AddObserver(this); | 291 window->AddObserver(this); |
290 } | 292 } |
291 | 293 |
292 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( | 294 void ArcAppWindowLauncherController::OnWindowVisibilityChanging( |
293 aura::Window* window, | 295 aura::Window* window, |
294 bool visible) { | 296 bool visible) { |
295 // The application id property should be set at this time. | 297 // The application id property should be set at this time. |
296 if (visible) | 298 if (visible) |
297 MayAttachContollerToWindow(window); | 299 MaybeAttachContollerToWindow(window); |
298 } | 300 } |
299 | 301 |
300 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { | 302 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { |
301 auto it = | 303 auto it = |
302 std::find(observed_windows_.begin(), observed_windows_.end(), window); | 304 std::find(observed_windows_.begin(), observed_windows_.end(), window); |
303 DCHECK(it != observed_windows_.end()); | 305 DCHECK(it != observed_windows_.end()); |
304 observed_windows_.erase(it); | 306 observed_windows_.erase(it); |
305 window->RemoveObserver(this); | 307 window->RemoveObserver(this); |
306 | 308 |
307 auto it_app_window = | 309 auto it_app_window = |
(...skipping 11 matching lines...) Expand all Loading... | |
319 } | 321 } |
320 | 322 |
321 ArcAppWindowLauncherController::AppWindow* | 323 ArcAppWindowLauncherController::AppWindow* |
322 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | 324 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
323 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 325 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
324 if (it == task_id_to_app_window_.end()) | 326 if (it == task_id_to_app_window_.end()) |
325 return nullptr; | 327 return nullptr; |
326 return it->second.get(); | 328 return it->second.get(); |
327 } | 329 } |
328 | 330 |
329 void ArcAppWindowLauncherController::MayAttachContollerToWindow( | 331 void ArcAppWindowLauncherController::MaybeAttachContollerToWindows() { |
332 for (auto* window : observed_windows_) | |
333 MaybeAttachContollerToWindow(window); | |
334 } | |
335 | |
336 void ArcAppWindowLauncherController::MaybeAttachContollerToWindow( | |
330 aura::Window* window) { | 337 aura::Window* window) { |
331 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); | 338 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); |
332 if (window_app_id.empty()) | 339 if (window_app_id.empty()) |
333 return; | 340 return; |
334 | 341 |
335 int task_id = -1; | 342 int task_id = -1; |
336 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 343 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
337 return; | 344 return; |
338 | 345 |
339 if (!task_id) | 346 if (!task_id) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 } | 410 } |
404 | 411 |
405 void ArcAppWindowLauncherController::OnTaskCreated( | 412 void ArcAppWindowLauncherController::OnTaskCreated( |
406 int task_id, | 413 int task_id, |
407 const std::string& package_name, | 414 const std::string& package_name, |
408 const std::string& activity_name) { | 415 const std::string& activity_name) { |
409 DCHECK(!GetAppWindowForTask(task_id)); | 416 DCHECK(!GetAppWindowForTask(task_id)); |
410 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId( | 417 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId( |
411 ArcAppListPrefs::GetAppId(package_name, activity_name)); | 418 ArcAppListPrefs::GetAppId(package_name, activity_name)); |
412 | 419 |
413 for (auto* window : observed_windows_) | 420 MaybeAttachContollerToWindows(); |
414 MayAttachContollerToWindow(window); | |
415 } | 421 } |
416 | 422 |
417 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 423 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
418 auto it = task_id_to_app_window_.find(task_id); | 424 auto it = task_id_to_app_window_.find(task_id); |
419 if (it != task_id_to_app_window_.end()) { | 425 if (it != task_id_to_app_window_.end()) { |
420 AppWindow* app_window = it->second.get(); | 426 AppWindow* app_window = it->second.get(); |
421 UnregisterApp(app_window, true); | 427 UnregisterApp(app_window, true); |
422 task_id_to_app_window_.erase(it); | 428 task_id_to_app_window_.erase(it); |
423 } | 429 } |
424 | 430 |
(...skipping 11 matching lines...) Expand all Loading... | |
436 if (!controller->window_count()) { | 442 if (!controller->window_count()) { |
437 owner()->CloseLauncherItem(controller->shelf_id()); | 443 owner()->CloseLauncherItem(controller->shelf_id()); |
438 app_controller_map_.erase(it_controller); | 444 app_controller_map_.erase(it_controller); |
439 } | 445 } |
440 } | 446 } |
441 | 447 |
442 task_id_to_shelf_app_id_.erase(it_app_id); | 448 task_id_to_shelf_app_id_.erase(it_app_id); |
443 } | 449 } |
444 | 450 |
445 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | 451 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { |
446 if (observed_profile_ != owner()->GetProfile()) | 452 if (observed_profile_ != owner()->GetProfile()) { |
453 active_task_id_ = task_id; | |
447 return; | 454 return; |
455 } | |
448 | 456 |
449 TaskIdToAppWindow::iterator previous_active_app_it = | 457 TaskIdToAppWindow::iterator previous_active_app_it = |
450 task_id_to_app_window_.find(active_task_id_); | 458 task_id_to_app_window_.find(active_task_id_); |
451 if (previous_active_app_it != task_id_to_app_window_.end()) { | 459 if (previous_active_app_it != task_id_to_app_window_.end()) { |
452 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), | 460 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), |
453 ash::STATUS_RUNNING); | 461 ash::STATUS_RUNNING); |
454 previous_active_app_it->second->SetFullscreenMode( | 462 previous_active_app_it->second->SetFullscreenMode( |
455 previous_active_app_it->second->widget() && | 463 previous_active_app_it->second->widget() && |
456 previous_active_app_it->second->widget()->IsFullscreen() | 464 previous_active_app_it->second->widget()->IsFullscreen() |
457 ? FullScreenMode::ACTIVE | 465 ? FullScreenMode::ACTIVE |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 controller->AddWindow(app_window); | 584 controller->AddWindow(app_window); |
577 controller->AddTaskId(app_window->task_id()); | 585 controller->AddTaskId(app_window->task_id()); |
578 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 586 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
579 app_window->SetController(controller); | 587 app_window->SetController(controller); |
580 app_window->set_shelf_id(shelf_id); | 588 app_window->set_shelf_id(shelf_id); |
581 } | 589 } |
582 | 590 |
583 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, | 591 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, |
584 bool close_controller) { | 592 bool close_controller) { |
585 const std::string app_id = app_window->app_id(); | 593 const std::string app_id = app_window->app_id(); |
594 | |
586 DCHECK(!app_id.empty()); | 595 DCHECK(!app_id.empty()); |
587 AppControllerMap::iterator it = app_controller_map_.find(app_id); | 596 AppControllerMap::iterator it = app_controller_map_.find(app_id); |
588 DCHECK(it != app_controller_map_.end()); | 597 CHECK(it != app_controller_map_.end()); |
589 | 598 |
590 ArcAppWindowLauncherItemController* controller = it->second; | 599 ArcAppWindowLauncherItemController* controller = it->second; |
591 controller->RemoveWindow(app_window); | 600 controller->RemoveWindow(app_window); |
592 if (close_controller && !controller->window_count()) { | 601 if (close_controller && !controller->window_count()) { |
593 ash::ShelfID shelf_id = app_window->shelf_id(); | 602 ash::ShelfID shelf_id = app_window->shelf_id(); |
594 owner()->CloseLauncherItem(shelf_id); | 603 owner()->CloseLauncherItem(shelf_id); |
595 app_controller_map_.erase(it); | 604 app_controller_map_.erase(it); |
596 } | 605 } |
597 app_window->ResetController(); | 606 app_window->ResetController(); |
598 } | 607 } |
(...skipping 19 matching lines...) Expand all Loading... | |
618 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 627 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
619 // Resolve the orientation when it first resolved. | 628 // Resolve the orientation when it first resolved. |
620 orientation_lock = GetCurrentOrientation(); | 629 orientation_lock = GetCurrentOrientation(); |
621 app_window->set_requested_orientation_lock(orientation_lock); | 630 app_window->set_requested_orientation_lock(orientation_lock); |
622 } | 631 } |
623 | 632 |
624 ash::Shell* shell = ash::Shell::GetInstance(); | 633 ash::Shell* shell = ash::Shell::GetInstance(); |
625 shell->screen_orientation_controller()->LockOrientationForWindow( | 634 shell->screen_orientation_controller()->LockOrientationForWindow( |
626 window, BlinkOrientationLockFromMojom(orientation_lock)); | 635 window, BlinkOrientationLockFromMojom(orientation_lock)); |
627 } | 636 } |
OLD | NEW |