Commit 5fd57903 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Add/remove for PIN dialog impl in PinDialogManager

Extend interface of the PinDialogManager class to allow dynamically
adding and removing custom PIN dialog host implementations.

This will be used in follow-up CLs for supporting showing the PIN
request on Chrome OS Login/Lock screens.

Bug: 964069
Change-Id: I238a3af5b110bf434d9af7bbbfa109d6575721cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730896
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarIgor <igorcov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683430}
parent 788e0c7d
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/stl_util.h"
namespace chromeos { namespace chromeos {
...@@ -58,7 +59,7 @@ PinDialogManager::RequestPinResult PinDialogManager::RequestPin( ...@@ -58,7 +59,7 @@ PinDialogManager::RequestPinResult PinDialogManager::RequestPin(
return RequestPinResult::kInvalidId; return RequestPinResult::kInvalidId;
// A new dialog will be opened, so initialize the related internal state. // A new dialog will be opened, so initialize the related internal state.
active_dialog_state_.emplace(&default_dialog_host_, extension_id, active_dialog_state_.emplace(GetHostForNewDialog(), extension_id,
extension_name, code_type); extension_name, code_type);
} }
...@@ -145,6 +146,22 @@ void PinDialogManager::ExtensionUnloaded(const std::string& extension_id) { ...@@ -145,6 +146,22 @@ void PinDialogManager::ExtensionUnloaded(const std::string& extension_id) {
} }
} }
void PinDialogManager::AddPinDialogHost(
SecurityTokenPinDialogHost* pin_dialog_host) {
DCHECK(!base::Contains(added_dialog_hosts_, pin_dialog_host));
added_dialog_hosts_.push_back(pin_dialog_host);
}
void PinDialogManager::RemovePinDialogHost(
SecurityTokenPinDialogHost* pin_dialog_host) {
if (active_dialog_state_ && active_dialog_state_->host == pin_dialog_host) {
pin_dialog_host->CloseSecurityTokenPinDialog();
DCHECK(!active_dialog_state_);
}
DCHECK(base::Contains(added_dialog_hosts_, pin_dialog_host));
base::Erase(added_dialog_hosts_, pin_dialog_host);
}
PinDialogManager::ActiveDialogState::ActiveDialogState( PinDialogManager::ActiveDialogState::ActiveDialogState(
SecurityTokenPinDialogHost* host, SecurityTokenPinDialogHost* host,
const std::string& extension_id, const std::string& extension_id,
...@@ -178,4 +195,10 @@ void PinDialogManager::OnPinDialogClosed() { ...@@ -178,4 +195,10 @@ void PinDialogManager::OnPinDialogClosed() {
active_dialog_state_.reset(); active_dialog_state_.reset();
} }
SecurityTokenPinDialogHost* PinDialogManager::GetHostForNewDialog() {
if (added_dialog_hosts_.empty())
return &default_dialog_host_;
return added_dialog_hosts_.back();
}
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -99,6 +100,15 @@ class PinDialogManager final { ...@@ -99,6 +100,15 @@ class PinDialogManager final {
// Resets the manager data related to the extension. // Resets the manager data related to the extension.
void ExtensionUnloaded(const std::string& extension_id); void ExtensionUnloaded(const std::string& extension_id);
// Dynamically adds the dialog host that can be used by this instance for
// showing new dialogs. There may be multiple hosts added, in which case the
// most recently added is used. Before any hosts have been added, the default
// (popup-based) host is used.
void AddPinDialogHost(SecurityTokenPinDialogHost* pin_dialog_host);
// Removes the previously added dialog host. If a dialog is still opened in
// this host, closes it beforehand.
void RemovePinDialogHost(SecurityTokenPinDialogHost* pin_dialog_host);
SecurityTokenPinDialogHostPopupImpl* default_dialog_host_for_testing() { SecurityTokenPinDialogHostPopupImpl* default_dialog_host_for_testing() {
return &default_dialog_host_; return &default_dialog_host_;
} }
...@@ -132,6 +142,11 @@ class PinDialogManager final { ...@@ -132,6 +142,11 @@ class PinDialogManager final {
// The callback that gets invoked once the PIN dialog gets closed. // The callback that gets invoked once the PIN dialog gets closed.
void OnPinDialogClosed(); void OnPinDialogClosed();
// Returns the dialog host that should own the new dialog. Currently returns
// the most recently added dialog host (falling back to the default one when
// no host has been added).
SecurityTokenPinDialogHost* GetHostForNewDialog();
// Tells whether user closed the last request PIN dialog issued by an // Tells whether user closed the last request PIN dialog issued by an
// extension. The extension_id is the key and value is true if user closed the // extension. The extension_id is the key and value is true if user closed the
// dialog. Used to determine if the limit of dialogs rejected by the user has // dialog. Used to determine if the limit of dialogs rejected by the user has
...@@ -143,6 +158,9 @@ class PinDialogManager final { ...@@ -143,6 +158,9 @@ class PinDialogManager final {
std::map<ExtensionNameRequestIdPair, base::Time> sign_request_times_; std::map<ExtensionNameRequestIdPair, base::Time> sign_request_times_;
SecurityTokenPinDialogHostPopupImpl default_dialog_host_; SecurityTokenPinDialogHostPopupImpl default_dialog_host_;
// The list of dynamically added dialog hosts, in the same order as they were
// added.
std::vector<SecurityTokenPinDialogHost*> added_dialog_hosts_;
// There can be only one active dialog to request the PIN at any point of // There can be only one active dialog to request the PIN at any point of
// time. // time.
......
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