include/sfx2/strings.hrc               |    1 
 sfx2/source/appl/openuriexternally.cxx |   73 +++++++++++++++++++--------------
 2 files changed, 44 insertions(+), 30 deletions(-)

New commits:
commit 70009098fd70df021048c540d1796c928554b494
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Fri Oct 29 11:17:09 2021 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Fri Oct 29 13:26:36 2021 +0200

    tdf#128969: Let the user explicitly decide to execute an external program
    
    ...bringing up a warning dialog now in cases where it would have before only
    brought up a failure message
    
    Change-Id: I850badf5927517f16f965950df699979887dbdc0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124422
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 4b95c8505d87..82bd1c2168a1 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -103,6 +103,7 @@
 #define STR_GB                                  NC_("STR_GB", "GB")
 #define STR_QUERY_LASTVERSION                   NC_("STR_QUERY_LASTVERSION", 
"Cancel all changes?")
 #define STR_NO_WEBBROWSER_FOUND                 NC_("STR_NO_WEBBROWSER_FOUND", 
"Opening \"$(ARG1)\" failed with error code $(ARG2) and message: 
\"$(ARG3)\"\nMaybe no web browser could be found on your system. In that case, 
please check your Desktop Preferences or install a web browser (for example, 
Firefox) in the default location requested during the browser installation.")
+#define STR_DANGEROUS_TO_OPEN                   NC_("STR_DANGEROUS_TO_OPEN", 
"It might be dangerous to open \"$(ARG1)\".\nDo you really want to open it?")
 #define STR_NO_ABS_URI_REF                      NC_("STR_NO_ABS_URI_REF", 
"\"$(ARG1)\" cannot be passed to an external application to open it (e.g., it 
might not be an absolute URL, or might denote no existing file).")
 #define STR_GID_INTERN                          NC_("STR_GID_INTERN", 
"Internal")
 #define STR_GID_APPLICATION                     NC_("STR_GID_APPLICATION", 
"Application")
diff --git a/sfx2/source/appl/openuriexternally.cxx 
b/sfx2/source/appl/openuriexternally.cxx
index d149f63d257d..0425da7208be 100644
--- a/sfx2/source/appl/openuriexternally.cxx
+++ b/sfx2/source/appl/openuriexternally.cxx
@@ -80,37 +80,50 @@ IMPL_LINK_NOARG(URITools, onOpenURI, Timer*, void)
     std::unique_ptr<URITools> guard(this);
     css::uno::Reference< css::system::XSystemShellExecute > exec(
         
css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
-    try {
-        exec->execute(
-            msURI, OUString(),
-            css::system::SystemShellExecuteFlags::URIS_ONLY);
-    } catch (css::lang::IllegalArgumentException & e) {
-        if (e.ArgumentPosition != 0) {
-            throw css::uno::RuntimeException(
-                "unexpected IllegalArgumentException: " + e.Message);
+    for (sal_Int32 flags = css::system::SystemShellExecuteFlags::URIS_ONLY;;) {
+        try {
+            exec->execute(msURI, OUString(), flags);
+        } catch (css::lang::IllegalArgumentException & e) {
+            if (e.ArgumentPosition != 0) {
+                throw css::uno::RuntimeException(
+                    "unexpected IllegalArgumentException: " + e.Message);
+            }
+            SolarMutexGuard g;
+            weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
+            if (flags == css::system::SystemShellExecuteFlags::URIS_ONLY) {
+                std::unique_ptr<weld::MessageDialog> eb(
+                    Application::CreateMessageDialog(
+                        pWindow, VclMessageType::Warning, 
VclButtonsType::OkCancel,
+                        SfxResId(STR_DANGEROUS_TO_OPEN)));
+                
eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
+                if (eb->run() == RET_OK) {
+                    flags = 0;
+                    continue;
+                }
+            } else {
+                std::unique_ptr<weld::MessageDialog> 
eb(Application::CreateMessageDialog(pWindow,
+                                                                         
VclMessageType::Warning, VclButtonsType::Ok,
+                                                                         
SfxResId(STR_NO_ABS_URI_REF)));
+                
eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
+                eb->run();
+            }
+        } catch (css::system::SystemShellExecuteException & e) {
+            if (!mbHandleSystemShellExecuteException) {
+                throw;
+            }
+            SolarMutexGuard g;
+            weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
+            std::unique_ptr<weld::MessageDialog> 
eb(Application::CreateMessageDialog(pWindow,
+                                                                     
VclMessageType::Warning, VclButtonsType::Ok,
+                                                                     
SfxResId(STR_NO_WEBBROWSER_FOUND)));
+            eb->set_primary_text(
+                eb->get_primary_text().replaceFirst("$(ARG1)", msURI)
+                .replaceFirst("$(ARG2)", OUString::number(e.PosixError))
+                .replaceFirst("$(ARG3)", e.Message));
+                //TODO: avoid subsequent replaceFirst acting on previous 
replacement
+            eb->run();
         }
-        SolarMutexGuard g;
-        weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
-        std::unique_ptr<weld::MessageDialog> 
eb(Application::CreateMessageDialog(pWindow,
-                                                                 
VclMessageType::Warning, VclButtonsType::Ok,
-                                                                 
SfxResId(STR_NO_ABS_URI_REF)));
-        eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", 
msURI));
-        eb->run();
-    } catch (css::system::SystemShellExecuteException & e) {
-        if (!mbHandleSystemShellExecuteException) {
-            throw;
-        }
-        SolarMutexGuard g;
-        weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
-        std::unique_ptr<weld::MessageDialog> 
eb(Application::CreateMessageDialog(pWindow,
-                                                                 
VclMessageType::Warning, VclButtonsType::Ok,
-                                                                 
SfxResId(STR_NO_WEBBROWSER_FOUND)));
-        eb->set_primary_text(
-            eb->get_primary_text().replaceFirst("$(ARG1)", msURI)
-            .replaceFirst("$(ARG2)", OUString::number(e.PosixError))
-            .replaceFirst("$(ARG3)", e.Message));
-            //TODO: avoid subsequent replaceFirst acting on previous 
replacement
-        eb->run();
+        break;
     }
 }
 

Reply via email to