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

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

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