From 32534b76eaa95fde79435ff0c325f24234cbe84d Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Sun, 18 May 2025 02:27:25 +0100 Subject: [PATCH] tdf#162826: Move pdf pwdinteract Move sdext's pwdinteract that provides getPassword() into vcl/source/pdf so it can also be used for the PDFium based import. Change-Id: Iab0f6fd0814986622624cdb2c523f1c60caddcc2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185470 Reviewed-by: David Gilbert Tested-by: Jenkins --- include/vcl/pdf/pwdinteract.hxx | 24 +++++++++++++++++++ sdext/Library_pdfimport.mk | 1 - sdext/source/pdfimport/filterdet.cxx | 6 ++--- sdext/source/pdfimport/inc/pdfihelper.hxx | 9 ------- sdext/source/pdfimport/wrapper/wrapper.cxx | 4 ++-- solenv/clang-format/excludelist | 2 +- vcl/Library_vcl.mk | 1 + .../misc => vcl/source/pdf}/pwdinteract.cxx | 4 ++-- 8 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 include/vcl/pdf/pwdinteract.hxx rename {sdext/source/pdfimport/misc => vcl/source/pdf}/pwdinteract.cxx (98%) diff --git a/include/vcl/pdf/pwdinteract.hxx b/include/vcl/pdf/pwdinteract.hxx new file mode 100644 index 000000000000..6a13a62b0b7b --- /dev/null +++ b/include/vcl/pdf/pwdinteract.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include +#include + +namespace vcl::pdf +{ +/** retrieve password from user + */ +bool VCL_DLLPUBLIC getPassword(const css::uno::Reference& xHandler, + OUString& rOutPwd, bool bFirstTry, const OUString& rDocName); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/Library_pdfimport.mk b/sdext/Library_pdfimport.mk index a1d4d0b5aceb..0843bd867977 100644 --- a/sdext/Library_pdfimport.mk +++ b/sdext/Library_pdfimport.mk @@ -55,7 +55,6 @@ $(eval $(call gb_Library_add_defs,pdfimport, \ $(eval $(call gb_Library_add_exception_objects,pdfimport,\ sdext/source/pdfimport/filterdet \ sdext/source/pdfimport/misc/pdfihelper \ - sdext/source/pdfimport/misc/pwdinteract \ sdext/source/pdfimport/odf/odfemitter \ sdext/source/pdfimport/pdfiadaptor \ sdext/source/pdfimport/pdfparse/pdfentries \ diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx index 65a4c6a15a83..95face19665d 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -19,7 +19,6 @@ #include "filterdet.hxx" -#include "inc/pdfihelper.hxx" #include "inc/pdfparse.hxx" #include @@ -38,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -366,7 +366,7 @@ uno::Reference getEmbeddedFile(const OUString& rInPDFFileURL, if (bMayUseUI && xIntHdl.is()) { OUString aDocName(rInPDFFileURL.copy(rInPDFFileURL.lastIndexOf('/') + 1)); - bAgain = getPassword(xIntHdl, io_rPwd, !bAgain, aDocName); + bAgain = vcl::pdf::getPassword(xIntHdl, io_rPwd, !bAgain, aDocName); SAL_INFO("sdext.pdfimport", "getEmbeddedFile pdfium Pass result: " << bAgain); continue; } @@ -812,7 +812,7 @@ uno::Reference< io::XStream > getAdditionalStream( const OUString& bool bEntered = false; do { - bEntered = getPassword( xIntHdl, io_rPwd, ! bEntered, aDocName ); + bEntered = vcl::pdf::getPassword( xIntHdl, io_rPwd, ! bEntered, aDocName ); OString aIsoPwd = OUStringToOString( io_rPwd, RTL_TEXTENCODING_ISO_8859_1 ); bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd ); diff --git a/sdext/source/pdfimport/inc/pdfihelper.hxx b/sdext/source/pdfimport/inc/pdfihelper.hxx index bc8e04a70253..9cb8760bc12a 100644 --- a/sdext/source/pdfimport/inc/pdfihelper.hxx +++ b/sdext/source/pdfimport/inc/pdfihelper.hxx @@ -214,15 +214,6 @@ namespace pdfi return seed; } }; - - /** retrieve password from user - */ - bool getPassword( const css::uno::Reference< - css::task::XInteractionHandler >& xHandler, - OUString& rOutPwd, - bool bFirstTry, - const OUString& rDocName - ); } #endif diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index fcac1cdacfa2..5c9ec116dec7 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -54,6 +53,7 @@ #include #include +#include #include #include @@ -1137,7 +1137,7 @@ bool xpdf_ImportFromFile(const OUString& rURL, // already got one (e.g. if the hybrid detect prompted for one) if (!bPasswordOnEntry) { - bEntered = getPassword(xIHdl, aPwd, !bEntered, aDocName); + bEntered = vcl::pdf::getPassword(xIHdl, aPwd, !bEntered, aDocName); if (!bEntered) { // User cancelled password input diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 178e885130fc..83e205857453 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -9977,7 +9977,6 @@ sdext/source/pdfimport/inc/treevisitorfactory.hxx sdext/source/pdfimport/inc/wrapper.hxx sdext/source/pdfimport/inc/xmlemitter.hxx sdext/source/pdfimport/misc/pdfihelper.cxx -sdext/source/pdfimport/misc/pwdinteract.cxx sdext/source/pdfimport/odf/odfemitter.cxx sdext/source/pdfimport/pdfiadaptor.cxx sdext/source/pdfimport/pdfiadaptor.hxx @@ -14768,6 +14767,7 @@ vcl/source/outdev/textline.cxx vcl/source/outdev/transparent.cxx vcl/source/outdev/vclreferencebase.cxx vcl/source/outdev/wallpaper.cxx +vcl/source/pdf/pwdinteract.cxx vcl/source/text/ImplLayoutRuns.cxx vcl/source/text/textlayout.cxx vcl/source/toolkit/group.cxx diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 07537ccdfc71..dc0a081fc5b9 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -566,6 +566,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/pdf/PDFEncryptor \ vcl/source/pdf/PDFEncryptorR6 \ vcl/source/pdf/PdfConfig \ + vcl/source/pdf/pwdinteract \ vcl/source/pdf/ResourceDict \ vcl/source/pdf/Matrix3 \ vcl/source/pdf/XmpMetadata \ diff --git a/sdext/source/pdfimport/misc/pwdinteract.cxx b/vcl/source/pdf/pwdinteract.cxx similarity index 98% rename from sdext/source/pdfimport/misc/pwdinteract.cxx rename to vcl/source/pdf/pwdinteract.cxx index 44214ac70ac3..65a7664754c7 100644 --- a/sdext/source/pdfimport/misc/pwdinteract.cxx +++ b/vcl/source/pdf/pwdinteract.cxx @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -117,7 +117,7 @@ void PDFPasswordRequest::select() } // namespace -namespace pdfi +namespace vcl::pdf { bool getPassword( const uno::Reference< task::XInteractionHandler >& xHandler,