summaryrefslogtreecommitdiff
path: root/forms
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2023-05-05 10:18:52 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-05-05 15:51:53 +0200
commit9e745192f19dda1328231c680ee17275c3c89932 (patch)
treed4c304583c15e77e3bbc881980f9a4119927feac /forms
parent87cefcdce6a02044e61c3173777b4546f3ad39f6 (diff)
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>
Diffstat (limited to 'forms')
-rw-r--r--forms/inc/strings.hrc1
-rw-r--r--forms/source/xforms/submission.cxx32
-rw-r--r--forms/source/xforms/submission/submission.hxx6
3 files changed, 32 insertions, 7 deletions
diff --git a/forms/inc/strings.hrc b/forms/inc/strings.hrc
index 07d39970c403..bc822b96ef55 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 368673a88318..e0d312aa63f0 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 65631b9a21c1..26a2514c829d 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() {}