Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

Issue 2345043002: arc: Prevent showing Arc app window for secondary user profile. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 282 }
283 283
284 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { 284 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
285 // Arc windows has type WINDOW_TYPE_NORMAL. 285 // Arc windows has type WINDOW_TYPE_NORMAL.
286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) 286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL)
287 return; 287 return;
288 observed_windows_.push_back(window); 288 observed_windows_.push_back(window);
289 window->AddObserver(this); 289 window->AddObserver(this);
290 } 290 }
291 291
292 void ArcAppWindowLauncherController::OnWindowVisibilityChanged( 292 void ArcAppWindowLauncherController::OnWindowPropertyChanged(
293 aura::Window* window, 293 aura::Window* window,
294 bool visible) { 294 const void* key,
295 // The application id property should be set at this time. It is important to 295 intptr_t old) {
296 // have window->IsVisible set to true before attaching to a controller because 296 if (!exo::ShellSurface::IsApplicationWindowReadyPropertyKey(key))
297 // the window is registered in multi-user manager and this manager may 297 return;
298 // consider this new window as hidden for current profile. Multi-user manager 298
299 // uses OnWindowVisibilityChanging event to update window state. 299 DCHECK(exo::ShellSurface::IsApplicationWindowReadyToShow(window));
300 if (visible && observed_profile_ == owner()->GetProfile()) 300 if (observed_profile_ == owner()->GetProfile()) {
301 AttachControllerToWindowIfNeeded(window); 301 if (AttachControllerToWindowIfNeeded(window))
302 window->Show();
303 } else {
304 chrome::MultiUserWindowManager* multi_user_manager =
305 chrome::MultiUserWindowManager::GetInstance();
306 if (multi_user_manager->GetWindowOwner(window).empty()) {
307 multi_user_manager->SetWindowOwner(
308 window,
309 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
310 // Now the window is registered for primary user however it is marked as
311 // hidden. Manually mark it as visible in order to get it automatically
312 // restored when user switches back to primary profile.
313 multi_user_manager->MarkWindowAsVisible(window);
314 }
315 }
302 } 316 }
303 317
304 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 318 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
305 auto it = 319 auto it =
306 std::find(observed_windows_.begin(), observed_windows_.end(), window); 320 std::find(observed_windows_.begin(), observed_windows_.end(), window);
307 DCHECK(it != observed_windows_.end()); 321 DCHECK(it != observed_windows_.end());
308 observed_windows_.erase(it); 322 observed_windows_.erase(it);
309 window->RemoveObserver(this); 323 window->RemoveObserver(this);
310 324
311 auto it_app_window = 325 auto it_app_window =
(...skipping 16 matching lines...) Expand all
328 if (it == task_id_to_app_window_.end()) 342 if (it == task_id_to_app_window_.end())
329 return nullptr; 343 return nullptr;
330 return it->second.get(); 344 return it->second.get();
331 } 345 }
332 346
333 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { 347 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() {
334 for (auto* window : observed_windows_) 348 for (auto* window : observed_windows_)
335 AttachControllerToWindowIfNeeded(window); 349 AttachControllerToWindowIfNeeded(window);
336 } 350 }
337 351
338 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( 352 bool ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
339 aura::Window* window) { 353 aura::Window* window) {
354 if (!exo::ShellSurface::IsApplicationWindowReadyToShow(window))
355 return false;
356
340 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); 357 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window);
341 if (window_app_id.empty()) 358 if (window_app_id.empty())
342 return; 359 return false;
343 360
344 int task_id = -1; 361 int task_id = -1;
345 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 362 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
346 return; 363 return false;
347 364
348 if (!task_id) 365 if (!task_id)
349 return; 366 return false;
350 367
351 // We need to add the observer after exo started observing shell 368 // We need to add the observer after exo started observing shell
352 // because we want to update the orientation after exo send 369 // because we want to update the orientation after exo send
353 // the layout switch information. 370 // the layout switch information.
354 if (!observing_shell_) { 371 if (!observing_shell_) {
355 observing_shell_ = true; 372 observing_shell_ = true;
356 ash::WmShell::Get()->AddShellObserver(this); 373 ash::WmShell::Get()->AddShellObserver(this);
357 } 374 }
358 375
359 // Check if we have controller for this task. 376 // Check if we have controller for this task.
360 if (GetAppWindowForTask(task_id)) 377 if (GetAppWindowForTask(task_id))
361 return; 378 return false;
362 379
363 // Create controller if we have task info. 380 // Create controller if we have task info.
364 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); 381 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
365 if (it == task_id_to_shelf_app_id_.end()) 382 if (it == task_id_to_shelf_app_id_.end())
366 return; 383 return false;
367 384
368 const std::string& app_id = it->second; 385 const std::string& app_id = it->second;
369 386
370 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 387 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
371 DCHECK(widget); 388 DCHECK(widget);
372 std::unique_ptr<AppWindow> app_window( 389 std::unique_ptr<AppWindow> app_window(
373 new AppWindow(task_id, app_id, widget, this)); 390 new AppWindow(task_id, app_id, widget, this));
374 RegisterApp(app_window.get()); 391 RegisterApp(app_window.get());
375 DCHECK(app_window->controller()); 392 DCHECK(app_window->controller());
376 ash::WmWindowAura::Get(window)->SetIntProperty( 393 ash::WmWindowAura::Get(window)->SetIntProperty(
377 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); 394 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id());
378 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 395 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
379 window, 396 window,
380 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); 397 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
381 if (ash::WmShell::Get() 398 if (ash::WmShell::Get()
382 ->maximize_mode_controller() 399 ->maximize_mode_controller()
383 ->IsMaximizeModeWindowManagerEnabled()) { 400 ->IsMaximizeModeWindowManagerEnabled()) {
384 SetOrientationLockForAppWindow(app_window.get()); 401 SetOrientationLockForAppWindow(app_window.get());
385 } 402 }
386 task_id_to_app_window_[task_id] = std::move(app_window); 403 task_id_to_app_window_[task_id] = std::move(app_window);
404 return true;
387 } 405 }
388 406
389 void ArcAppWindowLauncherController::OnAppReadyChanged( 407 void ArcAppWindowLauncherController::OnAppReadyChanged(
390 const std::string& app_id, 408 const std::string& app_id,
391 bool ready) { 409 bool ready) {
392 if (!ready) 410 if (!ready)
393 OnAppRemoved(app_id); 411 OnAppRemoved(app_id);
394 } 412 }
395 413
396 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { 414 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 654 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
637 // Resolve the orientation when it first resolved. 655 // Resolve the orientation when it first resolved.
638 orientation_lock = GetCurrentOrientation(); 656 orientation_lock = GetCurrentOrientation();
639 app_window->set_requested_orientation_lock(orientation_lock); 657 app_window->set_requested_orientation_lock(orientation_lock);
640 } 658 }
641 659
642 ash::Shell* shell = ash::Shell::GetInstance(); 660 ash::Shell* shell = ash::Shell::GetInstance();
643 shell->screen_orientation_controller()->LockOrientationForWindow( 661 shell->screen_orientation_controller()->LockOrientationForWindow(
644 window, BlinkOrientationLockFromMojom(orientation_lock)); 662 window, BlinkOrientationLockFromMojom(orientation_lock));
645 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698