summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorRodrigo Tobar <rtobar@icrar.org>2022-12-20 14:15:56 +0800
committerAndreas Kling <kling@serenityos.org>2022-12-20 10:28:58 +0100
commit89061883f28e36d397ac915c144c765834f6e20b (patch)
tree9046275cc0757348e1674f1b4c00298c6faff5e3 /Userland
parentbb48a67f84e2151bd27ba0b0f87dcf0e46605e61 (diff)
downloadserenity-89061883f28e36d397ac915c144c765834f6e20b.zip
PDFViewer: Prompt password for encrypted documents
This tackles a FIXME, but also makes sense to implement only now that the SecurityHandler logic has been fixed. When a Document is created an automatic attempt is made to provide the empty string as the password; even if this attempt failed the SecurityHandler still reported it had a user password, hence we never arrived to the VERIFY_NOT_REQUIRED line this commit is changing.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PDFViewer/PDFViewerWidget.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
index 4747b277ee..3008527613 100644
--- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
+++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp
@@ -19,6 +19,7 @@
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/FilePicker.h>
+#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
@@ -366,8 +367,15 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(Core::File& file)
auto document = TRY(PDF::Document::create(m_buffer));
if (auto sh = document->security_handler(); sh && !sh->has_user_password()) {
- // FIXME: Prompt the user for a password
- VERIFY_NOT_REACHED();
+ DeprecatedString password;
+ while (true) {
+ auto result = GUI::InputBox::show(window(), password, "Password"sv, "Password required"sv, {}, GUI::InputType::Password);
+ if (result == GUI::Dialog::ExecResult::OK
+ && document->security_handler()->try_provide_user_password(password))
+ break;
+ if (result == GUI::Dialog::ExecResult::Cancel)
+ return {};
+ }
}
TRY(document->initialize());