Commit 88a6a719 authored by Henrique Grandinetti's avatar Henrique Grandinetti Committed by Commit Bot

Create Parent Access Widget

This widget is being create to facilitate the usage of the Parent
Access views in WebUI pages. With the widget it is possible to
instantiate the view without a pre-existing view hierarchy. We will
start using this in a follow up cl.

Bug: 921145, 921142
Change-Id: If57a14aac63a45c0da46766ce191ef392c322aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610818Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Commit-Queue: Henrique Grandinetti <hgrandinetti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661063}
parent 8f84163c
...@@ -429,6 +429,8 @@ component("ash") { ...@@ -429,6 +429,8 @@ component("ash") {
"login/ui/note_action_launch_button.h", "login/ui/note_action_launch_button.h",
"login/ui/parent_access_view.cc", "login/ui/parent_access_view.cc",
"login/ui/parent_access_view.h", "login/ui/parent_access_view.h",
"login/ui/parent_access_widget.cc",
"login/ui/parent_access_widget.h",
"login/ui/pin_keyboard_animation.cc", "login/ui/pin_keyboard_animation.cc",
"login/ui/pin_keyboard_animation.h", "login/ui/pin_keyboard_animation.h",
"login/ui/public_account_warning_dialog.cc", "login/ui/public_account_warning_dialog.cc",
......
...@@ -180,7 +180,7 @@ void LoginScreenController::AuthenticateUserWithEasyUnlock( ...@@ -180,7 +180,7 @@ void LoginScreenController::AuthenticateUserWithEasyUnlock(
} }
void LoginScreenController::ValidateParentAccessCode( void LoginScreenController::ValidateParentAccessCode(
const AccountId& account_id, const base::Optional<AccountId>& account_id,
const std::string& code, const std::string& code,
OnParentAccessValidation callback) { OnParentAccessValidation callback) {
if (!login_screen_client_) { if (!login_screen_client_) {
......
...@@ -74,7 +74,7 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen, ...@@ -74,7 +74,7 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
OnAuthenticateCallback callback); OnAuthenticateCallback callback);
void EnrollUserWithExternalBinary(OnAuthenticateCallback callback); void EnrollUserWithExternalBinary(OnAuthenticateCallback callback);
void AuthenticateUserWithEasyUnlock(const AccountId& account_id); void AuthenticateUserWithEasyUnlock(const AccountId& account_id);
void ValidateParentAccessCode(const AccountId& account_id, void ValidateParentAccessCode(const base::Optional<AccountId>& account_id,
const std::string& code, const std::string& code,
OnParentAccessValidation callback); OnParentAccessValidation callback);
void HardlockPod(const AccountId& account_id); void HardlockPod(const AccountId& account_id);
...@@ -218,4 +218,4 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen, ...@@ -218,4 +218,4 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
} // namespace ash } // namespace ash
#endif // ASH_LOGIN_LOCK_SCREEN_CONTROLLER_H_ #endif // ASH_LOGIN_LOGIN_SCREEN_CONTROLLER_H_
...@@ -60,7 +60,7 @@ void MockLoginScreenClient::EnrollUserWithExternalBinary( ...@@ -60,7 +60,7 @@ void MockLoginScreenClient::EnrollUserWithExternalBinary(
} }
void MockLoginScreenClient::ValidateParentAccessCode( void MockLoginScreenClient::ValidateParentAccessCode(
const AccountId& account_id, const base::Optional<AccountId>& account_id,
const std::string& code, const std::string& code,
ValidateParentAccessCodeCallback callback) { ValidateParentAccessCodeCallback callback) {
ValidateParentAccessCode_(account_id, code, callback); ValidateParentAccessCode_(account_id, code, callback);
......
...@@ -30,7 +30,7 @@ class MockLoginScreenClient : public mojom::LoginScreenClient { ...@@ -30,7 +30,7 @@ class MockLoginScreenClient : public mojom::LoginScreenClient {
MOCK_METHOD1(EnrollUserWithExternalBinary_, MOCK_METHOD1(EnrollUserWithExternalBinary_,
void(EnrollUserWithExternalBinaryCallback& callback)); void(EnrollUserWithExternalBinaryCallback& callback));
MOCK_METHOD3(ValidateParentAccessCode_, MOCK_METHOD3(ValidateParentAccessCode_,
void(const AccountId& account_id, void(const base::Optional<AccountId>& account_id,
const std::string& access_code, const std::string& access_code,
ValidateParentAccessCodeCallback& callback)); ValidateParentAccessCodeCallback& callback));
...@@ -74,7 +74,7 @@ class MockLoginScreenClient : public mojom::LoginScreenClient { ...@@ -74,7 +74,7 @@ class MockLoginScreenClient : public mojom::LoginScreenClient {
void EnrollUserWithExternalBinary( void EnrollUserWithExternalBinary(
EnrollUserWithExternalBinaryCallback callback) override; EnrollUserWithExternalBinaryCallback callback) override;
void ValidateParentAccessCode( void ValidateParentAccessCode(
const AccountId& account_id, const base::Optional<AccountId>& account_id,
const std::string& code, const std::string& code,
ValidateParentAccessCodeCallback callback) override; ValidateParentAccessCodeCallback callback) override;
MOCK_METHOD1(AuthenticateUserWithEasyUnlock, MOCK_METHOD1(AuthenticateUserWithEasyUnlock,
......
...@@ -391,7 +391,7 @@ ParentAccessView::Callbacks::Callbacks(const Callbacks& other) = default; ...@@ -391,7 +391,7 @@ ParentAccessView::Callbacks::Callbacks(const Callbacks& other) = default;
ParentAccessView::Callbacks::~Callbacks() = default; ParentAccessView::Callbacks::~Callbacks() = default;
ParentAccessView::ParentAccessView(const AccountId& account_id, ParentAccessView::ParentAccessView(const base::Optional<AccountId>& account_id,
const Callbacks& callbacks) const Callbacks& callbacks)
: NonAccessibleView(kParentAccessViewClassName), : NonAccessibleView(kParentAccessViewClassName),
callbacks_(callbacks), callbacks_(callbacks),
......
...@@ -76,9 +76,12 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView, ...@@ -76,9 +76,12 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView,
OnFinished on_finished; OnFinished on_finished;
}; };
// Creates parent access view for the user identified by |account_id|. // Creates parent access view that will validate the parent access code for a
// |callbacks| will be called when user performs certain actions. // specific child, when |account_id| is set, or to any child signed in the
ParentAccessView(const AccountId& account_id, const Callbacks& callbacks); // device, when it is empty. |callbacks| will be called when user performs
// certain actions.
ParentAccessView(const base::Optional<AccountId>& account_id,
const Callbacks& callbacks);
~ParentAccessView() override; ~ParentAccessView() override;
// views::View: // views::View:
...@@ -118,8 +121,9 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView, ...@@ -118,8 +121,9 @@ class ASH_EXPORT ParentAccessView : public NonAccessibleView,
// Callbacks to be called when user performs certain actions. // Callbacks to be called when user performs certain actions.
const Callbacks callbacks_; const Callbacks callbacks_;
// Account id of the user that parent access code is processed for. // Account id of the user that parent access code is processed for. When
const AccountId account_id_; // empty, the code is processed for all the children signed in the device.
const base::Optional<AccountId> account_id_;
State state_ = State::kNormal; State state_ = State::kNormal;
......
...@@ -69,7 +69,7 @@ class ParentAccessViewTest : public LoginTestBase { ...@@ -69,7 +69,7 @@ class ParentAccessViewTest : public LoginTestBase {
access_granted ? ++successful_validation_ : ++back_action_; access_granted ? ++successful_validation_ : ++back_action_;
} }
const AccountId account_id_; const base::Optional<AccountId> account_id_;
std::unique_ptr<MockLoginScreenClient> login_client_; std::unique_ptr<MockLoginScreenClient> login_client_;
// Number of times the view was dismissed with back button. // Number of times the view was dismissed with back button.
......
// Copyright 2019 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/login/ui/parent_access_widget.h"
#include <utility>
#include "ash/login/ui/parent_access_view.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "components/session_manager/session_manager_types.h"
#include "ui/views/widget/widget.h"
namespace ash {
ParentAccessWidget::ParentAccessWidget(
const base::Optional<AccountId>& account_id,
const OnExitCallback& callback) {
views::Widget::InitParams widget_params;
// Using window frameless to be able to get focus on the view input fields,
// which does not work with popup type.
widget_params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
widget_params.ownership =
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget_params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
widget_params.accept_events = true;
ShellWindowId parent_window_id =
Shell::Get()->session_controller()->GetSessionState() ==
session_manager::SessionState::ACTIVE
? ash::kShellWindowId_SystemModalContainer
: ash::kShellWindowId_LockSystemModalContainer;
widget_params.parent =
ash::Shell::GetPrimaryRootWindow()->GetChildById(parent_window_id);
widget_ = std::make_unique<views::Widget>();
widget_->set_focus_on_creation(true);
widget_->Init(widget_params);
ParentAccessView::Callbacks callbacks;
callbacks.on_finished = callback;
widget_->SetContentsView(new ParentAccessView(account_id, callbacks));
widget_->CenterWindow(widget_->GetContentsView()->GetPreferredSize());
widget_->Show();
widget_->GetContentsView()->RequestFocus();
}
ParentAccessWidget::~ParentAccessWidget() = default;
} // namespace ash
// Copyright 2019 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_LOGIN_UI_PARENT_ACCESS_WIDGET_H_
#define ASH_LOGIN_UI_PARENT_ACCESS_WIDGET_H_
#include <memory>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/optional.h"
class AccountId;
namespace views {
class Widget;
}
namespace ash {
// Widget to display the Parent Access View in a standalone container.
class ParentAccessWidget {
public:
using OnExitCallback = base::RepeatingCallback<void(bool success)>;
// Creates and shows the widget. When |account_id| is set, the parent
// access code is validated using the configuration for the provided account,
// when it is empty it tries to validate the access code to any child signed
// in the device. The |callback| is called when (a) the validation is
// successful or (b) the back button is pressed.
ParentAccessWidget(const base::Optional<AccountId>& account_id,
const OnExitCallback& callback);
~ParentAccessWidget();
private:
std::unique_ptr<views::Widget> widget_;
DISALLOW_COPY_AND_ASSIGN(ParentAccessWidget);
};
} // namespace ash
#endif // ASH_LOGIN_UI_PARENT_ACCESS_WIDGET_H_
...@@ -285,11 +285,13 @@ interface LoginScreenClient { ...@@ -285,11 +285,13 @@ interface LoginScreenClient {
// the other auth methods above. // the other auth methods above.
AuthenticateUserWithEasyUnlock(signin.mojom.AccountId account_id); AuthenticateUserWithEasyUnlock(signin.mojom.AccountId account_id);
// Validates parent access code for the user identified by |account_id|. // Validates parent access code for the user identified by |account_id|. When
// Passes validation result in the callback. // |account_id| is empty it tries to validate the access code for any child
// Note: This should only be used for child user. // that is signed in the device. Passes validation result in the callback.
// Note: This should only be used for child user, it will always return false
// when a non-child id is used.
ValidateParentAccessCode( ValidateParentAccessCode(
signin.mojom.AccountId account_id, signin.mojom.AccountId? account_id,
string access_code) => (bool access_code_valid); string access_code) => (bool access_code_valid);
// Request to hard lock the user pod. // Request to hard lock the user pod.
......
...@@ -138,7 +138,7 @@ void LoginScreenClient::AuthenticateUserWithEasyUnlock( ...@@ -138,7 +138,7 @@ void LoginScreenClient::AuthenticateUserWithEasyUnlock(
} }
void LoginScreenClient::ValidateParentAccessCode( void LoginScreenClient::ValidateParentAccessCode(
const AccountId& account_id, const base::Optional<AccountId>& account_id,
const std::string& access_code, const std::string& access_code,
ValidateParentAccessCodeCallback callback) { ValidateParentAccessCodeCallback callback) {
bool result = chromeos::parent_access::ParentAccessService::Get() bool result = chromeos::parent_access::ParentAccessService::Get()
......
...@@ -101,7 +101,7 @@ class LoginScreenClient : public ash::mojom::LoginScreenClient { ...@@ -101,7 +101,7 @@ class LoginScreenClient : public ash::mojom::LoginScreenClient {
EnrollUserWithExternalBinaryCallback callback) override; EnrollUserWithExternalBinaryCallback callback) override;
void AuthenticateUserWithEasyUnlock(const AccountId& account_id) override; void AuthenticateUserWithEasyUnlock(const AccountId& account_id) override;
void ValidateParentAccessCode( void ValidateParentAccessCode(
const AccountId& account_id, const base::Optional<AccountId>& account_id,
const std::string& access_code, const std::string& access_code,
ValidateParentAccessCodeCallback callback) override; ValidateParentAccessCodeCallback callback) override;
void HardlockPod(const AccountId& account_id) override; void HardlockPod(const AccountId& account_id) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment