feat: Add Secure Keyboard Entry APIs in macOS (#20678)
* feat: Add Secure Keyboard Entry APIs in macOS Add methods: - app.isSecureInputEnabled() - app.setSecureInputEnabled(enabled) These enable to prevent other process listens keyboard input events. * fix: lint error in app.md for #20678 * fix: crash app.setSecureInputEnabled() in password textfield * fix: export Secure keyboard Entry API to only macOS * fix: lint error in browser_mac.mm for #20678 * test: add test for app.setSecureKeyboardEntryEnabled in macOS
This commit is contained in:
parent
5bdf97e7ae
commit
7b55a70a36
5 changed files with 64 additions and 0 deletions
|
@ -1525,6 +1525,14 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
|||
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
||||
.SetMethod("showAboutPanel",
|
||||
base::BindRepeating(&Browser::ShowAboutPanel, browser))
|
||||
#if defined(OS_MACOSX)
|
||||
.SetMethod(
|
||||
"isSecureKeyboardEntryEnabled",
|
||||
base::BindRepeating(&Browser::IsSecureKeyboardEntryEnabled, browser))
|
||||
.SetMethod(
|
||||
"setSecureKeyboardEntryEnabled",
|
||||
base::BindRepeating(&Browser::SetSecureKeyboardEntryEnabled, browser))
|
||||
#endif
|
||||
#if defined(OS_MACOSX) || defined(OS_WIN)
|
||||
.SetMethod("showEmojiPanel",
|
||||
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#include "base/files/file_path.h"
|
||||
#endif
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "ui/base/cocoa/secure_password_input.h"
|
||||
#endif
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
@ -261,6 +265,12 @@ class Browser : public WindowListObserver {
|
|||
|
||||
void RemoveObserver(BrowserObserver* obs) { observers_.RemoveObserver(obs); }
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
// Returns whether secure input is enabled
|
||||
bool IsSecureKeyboardEntryEnabled();
|
||||
void SetSecureKeyboardEntryEnabled(bool enabled);
|
||||
#endif
|
||||
|
||||
bool is_shutting_down() const { return is_shutdown_; }
|
||||
bool is_quiting() const { return is_quiting_; }
|
||||
bool is_ready() const { return is_ready_; }
|
||||
|
@ -305,6 +315,10 @@ class Browser : public WindowListObserver {
|
|||
|
||||
std::unique_ptr<gin_helper::Promise<void>> ready_promise_;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
std::unique_ptr<ui::ScopedPasswordInputEnabler> password_input_enabler_;
|
||||
#endif
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_WIN)
|
||||
base::Value about_panel_options_;
|
||||
#elif defined(OS_MACOSX)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "shell/browser/browser.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
@ -430,4 +431,17 @@ bool Browser::IsEmojiPanelSupported() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Browser::IsSecureKeyboardEntryEnabled() {
|
||||
return password_input_enabler_.get() != nullptr;
|
||||
}
|
||||
|
||||
void Browser::SetSecureKeyboardEntryEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
password_input_enabler_ =
|
||||
std::make_unique<ui::ScopedPasswordInputEnabler>();
|
||||
} else {
|
||||
password_input_enabler_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue