Resolves: tdf#154337 allow submitting to file: if user agrees
continue to allow submitting to http[s]: without further interaction.
Don't allow for other protocols, except for file: where the user has to
agree via dialog prompt.
Change-Id: Ia915f4f33d5dba621971ce69a156c339da933b55
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151418
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/forms/inc/strings.hrc b/forms/inc/strings.hrc
index 07d3997..bc822b9 100644
--- a/forms/inc/strings.hrc
+++ b/forms/inc/strings.hrc
@@ -82,5 +82,6 @@
#define RID_STR_XFORMS_PATTERN_DOESNT_MATCH NC_("RID_STR_XFORMS_PATTERN_DOESNT_MATCH", "The string '$1' does not match the required regular expression '$2'.")
#define RID_STR_XFORMS_BINDING_UI_NAME NC_("RID_STR_XFORMS_BINDING_UI_NAME", "Binding" )
#define RID_STR_XFORMS_CANT_REMOVE_TYPE NC_("RID_STR_XFORMS_CANT_REMOVE_TYPE", "This is a built-in type and cannot be removed." )
#define RID_STR_XFORMS_WARN_TARGET_IS_FILE NC_("RID_STR_XFORMS_WARN_TARGET_IS_FILE", "Are you sure you want to write to local file \"$\"?" )
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/forms/source/xforms/submission.cxx b/forms/source/xforms/submission.cxx
index 368673a..e0d312a 100644
--- a/forms/source/xforms/submission.cxx
+++ b/forms/source/xforms/submission.cxx
@@ -42,11 +42,16 @@
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <com/sun/star/task/XInteractionContinuation.hpp>
#include <com/sun/star/xforms/InvalidDataOnSubmitException.hpp>
#include <com/sun/star/form/runtime/XFormController.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/interaction.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <frm_resource.hxx>
#include <strings.hrc>
#include <memory>
#include <string_view>
@@ -238,8 +243,31 @@ bool Submission::doSubmit( const Reference< XInteractionHandler >& xHandler )
return false;
}
if (!xSubmission->IsWebProtocol())
return false;
const INetURLObject& rURLObject = xSubmission->GetURLObject();
INetProtocol eProtocol = rURLObject.GetProtocol();
// tdf#154337 continue to allow submitting to http[s]: without further
// interaction. Don't allow for other protocols, except for file:
// where the user has to agree first.
if (eProtocol != INetProtocol::Http && eProtocol != INetProtocol::Https)
{
if (eProtocol != INetProtocol::File)
return false;
else
{
Reference<css::form::runtime::XFormController> xFormController(xHandler, UNO_QUERY);
Reference<css::awt::XControl> xContainerControl(xFormController ? xFormController->getContainer() : nullptr, UNO_QUERY);
Reference<css::awt::XWindow> xParent(xContainerControl ? xContainerControl->getPeer() : nullptr, UNO_QUERY);
OUString aFileName(rURLObject.getFSysPath(FSysStyle::Detect));
std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(Application::GetFrameWeld(xParent),
VclMessageType::Question, VclButtonsType::YesNo,
frm::ResourceManager::loadString(RID_STR_XFORMS_WARN_TARGET_IS_FILE).replaceFirst("$", aFileName)));
xQueryBox->set_default_response(RET_NO);
if (xQueryBox->run() != RET_YES)
return false;
}
}
CSubmission::SubmissionResult aResult = xSubmission->submit( xHandler );
diff --git a/forms/source/xforms/submission/submission.hxx b/forms/source/xforms/submission/submission.hxx
index 65631b9a..26a2514 100644
--- a/forms/source/xforms/submission/submission.hxx
+++ b/forms/source/xforms/submission/submission.hxx
@@ -119,11 +119,7 @@ public:
, m_xContext(::comphelper::getProcessComponentContext())
{}
bool IsWebProtocol() const
{
INetProtocol eProtocol = m_aURLObj.GetProtocol();
return eProtocol == INetProtocol::Http || eProtocol == INetProtocol::Https;
}
const INetURLObject& GetURLObject() const { return m_aURLObj; }
virtual ~CSubmission() {}