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

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: refactored 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_window_launcher_controller.h ('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 if (!visible)
308 return;
295 // The application id property should be set at this time. It is important to 309 // 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 310 // 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 311 // 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 312 // consider this new window as hidden for current profile. Multi-user manager
299 // uses OnWindowVisibilityChanging event to update window state. 313 // uses OnWindowVisibilityChanging event to update window state.
300 if (visible && observed_profile_ == owner()->GetProfile()) 314 if (observed_profile_ == owner()->GetProfile()) {
301 AttachControllerToWindowIfNeeded(window); 315 AttachControllerToWindowIfNeeded(window);
316 } else {
317 // Attach window to multi-user manager now to let it manage visibility state
318 // of the Arc window correctly.
319 if (GetWindowTaskId(window) > 0)
320 AttachWindowToMultiUserManager(window);
Mr4D (OOO till 08-26) 2016/09/16 19:08:55 Hmm.. This should only be needed in one place. Why
khmel 2016/09/16 19:19:30 Let me summarize: 1. AttachControllerToWindowIfNe
Mr4D (OOO till 08-26) 2016/09/16 22:07:28 Okay. I understand that the icon would be shown si
khmel 2016/09/16 22:38:44 Done as we discussed off-line
321 }
302 } 322 }
303 323
304 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 324 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
305 auto it = 325 auto it =
306 std::find(observed_windows_.begin(), observed_windows_.end(), window); 326 std::find(observed_windows_.begin(), observed_windows_.end(), window);
307 DCHECK(it != observed_windows_.end()); 327 DCHECK(it != observed_windows_.end());
308 observed_windows_.erase(it); 328 observed_windows_.erase(it);
309 window->RemoveObserver(this); 329 window->RemoveObserver(this);
310 330
311 auto it_app_window = 331 auto it_app_window =
(...skipping 16 matching lines...) Expand all
328 if (it == task_id_to_app_window_.end()) 348 if (it == task_id_to_app_window_.end())
329 return nullptr; 349 return nullptr;
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
358 void ArcAppWindowLauncherController::AttachWindowToMultiUserManager(
359 aura::Window* window) {
360 DCHECK(window);
361 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
362 window,
363 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
364 }
365
338 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( 366 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
339 aura::Window* window) { 367 aura::Window* window) {
340 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); 368 const int task_id = GetWindowTaskId(window);
341 if (window_app_id.empty()) 369 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; 370 return;
350 371
351 // We need to add the observer after exo started observing shell 372 // We need to add the observer after exo started observing shell
352 // because we want to update the orientation after exo send 373 // because we want to update the orientation after exo send
353 // the layout switch information. 374 // the layout switch information.
354 if (!observing_shell_) { 375 if (!observing_shell_) {
355 observing_shell_ = true; 376 observing_shell_ = true;
356 ash::WmShell::Get()->AddShellObserver(this); 377 ash::WmShell::Get()->AddShellObserver(this);
357 } 378 }
358 379
359 // Check if we have controller for this task. 380 // Check if we have controller for this task.
360 if (GetAppWindowForTask(task_id)) 381 if (GetAppWindowForTask(task_id))
361 return; 382 return;
362 383
363 // Create controller if we have task info. 384 // Create controller if we have task info.
364 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); 385 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
365 if (it == task_id_to_shelf_app_id_.end()) 386 if (it == task_id_to_shelf_app_id_.end())
366 return; 387 return;
367 388
368 const std::string& app_id = it->second; 389 const std::string& app_id = it->second;
369 390
370 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 391 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
371 DCHECK(widget); 392 DCHECK(widget);
372 std::unique_ptr<AppWindow> app_window( 393 std::unique_ptr<AppWindow> app_window(
373 new AppWindow(task_id, app_id, widget, this)); 394 new AppWindow(task_id, app_id, widget, this));
374 RegisterApp(app_window.get()); 395 RegisterApp(app_window.get());
375 DCHECK(app_window->controller()); 396 DCHECK(app_window->controller());
376 ash::WmWindowAura::Get(window)->SetIntProperty( 397 ash::WmWindowAura::Get(window)->SetIntProperty(
377 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id()); 398 ash::WmWindowProperty::SHELF_ID, app_window->shelf_id());
378 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 399 AttachWindowToMultiUserManager(window);
379 window,
380 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
381 if (ash::WmShell::Get() 400 if (ash::WmShell::Get()
382 ->maximize_mode_controller() 401 ->maximize_mode_controller()
383 ->IsMaximizeModeWindowManagerEnabled()) { 402 ->IsMaximizeModeWindowManagerEnabled()) {
384 SetOrientationLockForAppWindow(app_window.get()); 403 SetOrientationLockForAppWindow(app_window.get());
385 } 404 }
386 task_id_to_app_window_[task_id] = std::move(app_window); 405 task_id_to_app_window_[task_id] = std::move(app_window);
387 } 406 }
388 407
389 void ArcAppWindowLauncherController::OnAppReadyChanged( 408 void ArcAppWindowLauncherController::OnAppReadyChanged(
390 const std::string& app_id, 409 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) { 655 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
637 // Resolve the orientation when it first resolved. 656 // Resolve the orientation when it first resolved.
638 orientation_lock = GetCurrentOrientation(); 657 orientation_lock = GetCurrentOrientation();
639 app_window->set_requested_orientation_lock(orientation_lock); 658 app_window->set_requested_orientation_lock(orientation_lock);
640 } 659 }
641 660
642 ash::Shell* shell = ash::Shell::GetInstance(); 661 ash::Shell* shell = ash::Shell::GetInstance();
643 shell->screen_orientation_controller()->LockOrientationForWindow( 662 shell->screen_orientation_controller()->LockOrientationForWindow(
644 window, BlinkOrientationLockFromMojom(orientation_lock)); 663 window, BlinkOrientationLockFromMojom(orientation_lock));
645 } 664 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698