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

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: use one point to add window to multi user manager 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return blink::WebScreenOrientationLockLandscapePrimary; 80 return blink::WebScreenOrientationLockLandscapePrimary;
81 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: 81 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY:
82 return blink::WebScreenOrientationLockPortraitSecondary; 82 return blink::WebScreenOrientationLockPortraitSecondary;
83 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: 83 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY:
84 return blink::WebScreenOrientationLockLandscapeSecondary; 84 return blink::WebScreenOrientationLockLandscapeSecondary;
85 default: 85 default:
86 return blink::WebScreenOrientationLockAny; 86 return blink::WebScreenOrientationLockAny;
87 } 87 }
88 } 88 }
89 89
90 int GetWindowTaskId(aura::Window* window) {
91 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window);
92 if (window_app_id.empty())
93 return -1;
94
95 int task_id = -1;
96 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
97 return -1;
98
99 return task_id;
100 }
101
90 } // namespace 102 } // namespace
91 103
92 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { 104 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
93 public: 105 public:
94 AppWindow(int task_id, 106 AppWindow(int task_id,
95 const std::string app_id, 107 const std::string app_id,
96 views::Widget* widget, 108 views::Widget* widget,
97 ArcAppWindowLauncherController* owner) 109 ArcAppWindowLauncherController* owner)
98 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {} 110 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {}
99 ~AppWindow() {} 111 ~AppWindow() {}
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Arc windows has type WINDOW_TYPE_NORMAL. 297 // Arc windows has type WINDOW_TYPE_NORMAL.
286 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) 298 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL)
287 return; 299 return;
288 observed_windows_.push_back(window); 300 observed_windows_.push_back(window);
289 window->AddObserver(this); 301 window->AddObserver(this);
290 } 302 }
291 303
292 void ArcAppWindowLauncherController::OnWindowVisibilityChanged( 304 void ArcAppWindowLauncherController::OnWindowVisibilityChanged(
293 aura::Window* window, 305 aura::Window* window,
294 bool visible) { 306 bool visible) {
307 // Attach window to multi-user manager now to let it manage visibility state
308 // of the Arc window correctly.
309 if (GetWindowTaskId(window) > 0) {
310 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
311 window,
312 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
313 }
314
295 // The application id property should be set at this time. It is important to 315 // The application id property should be set at this time. It is important to
296 // have window->IsVisible set to true before attaching to a controller because 316 // have window->IsVisible set to true before attaching to a controller because
297 // the window is registered in multi-user manager and this manager may 317 // the window is registered in multi-user manager and this manager may
298 // consider this new window as hidden for current profile. Multi-user manager 318 // consider this new window as hidden for current profile. Multi-user manager
299 // uses OnWindowVisibilityChanging event to update window state. 319 // uses OnWindowVisibilityChanging event to update window state.
300 if (visible && observed_profile_ == owner()->GetProfile()) 320 if (visible && observed_profile_ == owner()->GetProfile())
301 AttachControllerToWindowIfNeeded(window); 321 AttachControllerToWindowIfNeeded(window);
302 } 322 }
303 323
304 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 324 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
(...skipping 25 matching lines...) Expand all
330 return it->second.get(); 350 return it->second.get();
331 } 351 }
332 352
333 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { 353 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() {
334 for (auto* window : observed_windows_) 354 for (auto* window : observed_windows_)
335 AttachControllerToWindowIfNeeded(window); 355 AttachControllerToWindowIfNeeded(window);
336 } 356 }
337 357
338 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( 358 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
339 aura::Window* window) { 359 aura::Window* window) {
340 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); 360 const int task_id = GetWindowTaskId(window);
341 if (window_app_id.empty()) 361 if (task_id <= 0)
342 return;
343
344 int task_id = -1;
345 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
346 return;
347
348 if (!task_id)
349 return; 362 return;
350 363
351 // We need to add the observer after exo started observing shell 364 // We need to add the observer after exo started observing shell
352 // because we want to update the orientation after exo send 365 // because we want to update the orientation after exo send
353 // the layout switch information. 366 // the layout switch information.
354 if (!observing_shell_) { 367 if (!observing_shell_) {
355 observing_shell_ = true; 368 observing_shell_ = true;
356 ash::WmShell::Get()->AddShellObserver(this); 369 ash::WmShell::Get()->AddShellObserver(this);
357 } 370 }
358 371
359 // Check if we have controller for this task. 372 // Check if we have controller for this task.
360 if (GetAppWindowForTask(task_id)) 373 if (GetAppWindowForTask(task_id))
361 return; 374 return;
362 375
363 // Create controller if we have task info. 376 // Create controller if we have task info.
364 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); 377 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
365 if (it == task_id_to_shelf_app_id_.end()) 378 if (it == task_id_to_shelf_app_id_.end())
366 return; 379 return;
367 380
368 const std::string& app_id = it->second; 381 const std::string& app_id = it->second;
369 382
370 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 383 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
371 DCHECK(widget); 384 DCHECK(widget);
372 std::unique_ptr<AppWindow> app_window( 385 std::unique_ptr<AppWindow> app_window(
373 new AppWindow(task_id, app_id, widget, this)); 386 new AppWindow(task_id, app_id, widget, this));
374 RegisterApp(app_window.get()); 387 RegisterApp(app_window.get());
375 DCHECK(app_window->controller()); 388 DCHECK(app_window->controller());
376 ash::WmWindowAura::Get(window)->SetIntProperty( 389 ash::WmWindowAura::Get(window)->SetIntProperty(
377 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); 390 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id());
378 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
379 window,
380 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
381 if (ash::WmShell::Get() 391 if (ash::WmShell::Get()
382 ->maximize_mode_controller() 392 ->maximize_mode_controller()
383 ->IsMaximizeModeWindowManagerEnabled()) { 393 ->IsMaximizeModeWindowManagerEnabled()) {
384 SetOrientationLockForAppWindow(app_window.get()); 394 SetOrientationLockForAppWindow(app_window.get());
385 } 395 }
386 task_id_to_app_window_[task_id] = std::move(app_window); 396 task_id_to_app_window_[task_id] = std::move(app_window);
387 } 397 }
388 398
389 void ArcAppWindowLauncherController::OnAppReadyChanged( 399 void ArcAppWindowLauncherController::OnAppReadyChanged(
390 const std::string& app_id, 400 const std::string& app_id,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 646 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
637 // Resolve the orientation when it first resolved. 647 // Resolve the orientation when it first resolved.
638 orientation_lock = GetCurrentOrientation(); 648 orientation_lock = GetCurrentOrientation();
639 app_window->set_requested_orientation_lock(orientation_lock); 649 app_window->set_requested_orientation_lock(orientation_lock);
640 } 650 }
641 651
642 ash::Shell* shell = ash::Shell::GetInstance(); 652 ash::Shell* shell = ash::Shell::GetInstance();
643 shell->screen_orientation_controller()->LockOrientationForWindow( 653 shell->screen_orientation_controller()->LockOrientationForWindow(
644 window, BlinkOrientationLockFromMojom(orientation_lock)); 654 window, BlinkOrientationLockFromMojom(orientation_lock));
645 } 655 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698