forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate user switching check from SystemTray.
On active user switching, a dialog is shown to confirm the user wants to stop screen sharing sessions. It was implemented in SystemTray, but the logic is not directly related to SystemTray. Also, it doesn't work with UnifiedSystemTray (--enable-features=SystemTrayUnified) which will replace old SystemTray class. This CL splits the dialog management to ScreenSwitchCheckController which will be owned by ash::Shell. Previously it was in chrome/browser/. https://crrev.com/c/665938 TEST=CanSwitchUserTest BUG=837507 Change-Id: I50d27f079e627a212209e1a10a6c23590623624b Reviewed-on: https://chromium-review.googlesource.com/1032453 Reviewed-by: James Cook <jamescook@chromium.org> Reviewed-by: Evan Stade <estade@chromium.org> Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org> Cr-Commit-Position: refs/heads/master@{#557418}
- Loading branch information
Tetsui Ohkubo
authored and
Commit Bot
committed
May 10, 2018
1 parent
b7dcce4
commit 54d5022
Showing
9 changed files
with
191 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
ash/system/screen_security/screen_switch_check_controller.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/system/screen_security/screen_switch_check_controller.h" | ||
|
||
#include "ash/shell.h" | ||
#include "ash/strings/grit/ash_strings.h" | ||
#include "ash/system/tray/system_tray_notifier.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/views/controls/message_box_view.h" | ||
#include "ui/views/layout/fill_layout.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
// Dialog that confirms the user wants to stop screen share/cast. Calls a | ||
// callback with the result. | ||
class CancelCastingDialog : public views::DialogDelegateView { | ||
public: | ||
CancelCastingDialog(base::OnceCallback<void(bool)> callback) | ||
: callback_(std::move(callback)) { | ||
AddChildView(new views::MessageBoxView(views::MessageBoxView::InitParams( | ||
l10n_util::GetStringUTF16(IDS_DESKTOP_CASTING_ACTIVE_MESSAGE)))); | ||
SetLayoutManager(std::make_unique<views::FillLayout>()); | ||
} | ||
~CancelCastingDialog() override = default; | ||
|
||
base::string16 GetWindowTitle() const override { | ||
return l10n_util::GetStringUTF16(IDS_DESKTOP_CASTING_ACTIVE_TITLE); | ||
} | ||
|
||
int GetDialogButtons() const override { | ||
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | ||
} | ||
|
||
bool Cancel() override { | ||
std::move(callback_).Run(false); | ||
return true; | ||
} | ||
|
||
bool Accept() override { | ||
// Stop screen sharing and capturing. When notified, all capture sessions or | ||
// all share sessions will be stopped. | ||
// Currently, the logic is in ScreenSecurityNotificationController. | ||
Shell::Get()->system_tray_notifier()->NotifyScreenCaptureStop(); | ||
Shell::Get()->system_tray_notifier()->NotifyScreenShareStop(); | ||
|
||
std::move(callback_).Run(true); | ||
return true; | ||
} | ||
|
||
private: | ||
base::OnceCallback<void(bool)> callback_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CancelCastingDialog); | ||
}; | ||
|
||
} // namespace | ||
|
||
ScreenSwitchCheckController::ScreenSwitchCheckController() { | ||
Shell::Get()->system_tray_notifier()->AddScreenCaptureObserver(this); | ||
Shell::Get()->system_tray_notifier()->AddScreenShareObserver(this); | ||
} | ||
|
||
ScreenSwitchCheckController::~ScreenSwitchCheckController() { | ||
Shell::Get()->system_tray_notifier()->RemoveScreenShareObserver(this); | ||
Shell::Get()->system_tray_notifier()->RemoveScreenCaptureObserver(this); | ||
} | ||
|
||
void ScreenSwitchCheckController::CanSwitchAwayFromActiveUser( | ||
base::OnceCallback<void(bool)> callback) { | ||
// If neither screen sharing nor capturing is going on we can immediately | ||
// switch users. | ||
if (!has_capture_ && !has_share_) { | ||
std::move(callback).Run(true); | ||
return; | ||
} | ||
|
||
views::DialogDelegate::CreateDialogWidget( | ||
new CancelCastingDialog(std::move(callback)), | ||
Shell::GetPrimaryRootWindow(), nullptr) | ||
->Show(); | ||
} | ||
|
||
void ScreenSwitchCheckController::OnScreenCaptureStart( | ||
const base::Closure& stop_callback, | ||
const base::string16& screen_capture_status) { | ||
has_capture_ = true; | ||
} | ||
|
||
void ScreenSwitchCheckController::OnScreenCaptureStop() { | ||
// Multiple screen capture sessions can exist, but they are stopped at once | ||
// for simplicity. | ||
has_capture_ = false; | ||
} | ||
|
||
void ScreenSwitchCheckController::OnScreenShareStart( | ||
const base::Closure& stop_callback, | ||
const base::string16& helper_name) { | ||
has_share_ = true; | ||
} | ||
|
||
void ScreenSwitchCheckController::OnScreenShareStop() { | ||
// Multiple screen share sessions can exist, but they are stopped at once for | ||
// simplicity. | ||
has_share_ = false; | ||
} | ||
|
||
} // namespace ash |
46 changes: 46 additions & 0 deletions
46
ash/system/screen_security/screen_switch_check_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_SYSTEM_SCREEN_SECURITY_SCREEN_SWITCH_CHECK_CONTROLLER_H_ | ||
#define ASH_SYSTEM_SCREEN_SECURITY_SCREEN_SWITCH_CHECK_CONTROLLER_H_ | ||
|
||
#include "ash/system/screen_security/screen_capture_observer.h" | ||
#include "ash/system/screen_security/screen_share_observer.h" | ||
|
||
namespace ash { | ||
|
||
// Controller of a dialog that confirms the user wants to stop screen share/cast | ||
// on user profile switching. | ||
class ScreenSwitchCheckController : public ScreenCaptureObserver, | ||
public ScreenShareObserver { | ||
public: | ||
ScreenSwitchCheckController(); | ||
~ScreenSwitchCheckController() override; | ||
|
||
// Determines if it's ok to switch away from the currently active user. Screen | ||
// casting may block this (or at least throw up a confirmation dialog). Calls | ||
// |callback| with the result. | ||
void CanSwitchAwayFromActiveUser(base::OnceCallback<void(bool)> callback); | ||
|
||
private: | ||
// ScreenCaptureObserver: | ||
void OnScreenCaptureStart( | ||
const base::Closure& stop_callback, | ||
const base::string16& screen_capture_status) override; | ||
void OnScreenCaptureStop() override; | ||
|
||
// ScreenShareObserver: | ||
void OnScreenShareStart(const base::Closure& stop_callback, | ||
const base::string16& helper_name) override; | ||
void OnScreenShareStop() override; | ||
|
||
bool has_capture_ = false; | ||
bool has_share_ = false; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ScreenSwitchCheckController); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_SYSTEM_SCREEN_SECURITY_SCREEN_SWITCH_CHECK_CONTROLLER_H_ |
Oops, something went wrong.