sfx2/source/appl/openuriexternally.cxx | 50 +++++++++++++++++++++++++++------ sfx2/source/inc/openuriexternally.hxx | 32 +++++++++------------ sfx2/source/view/viewsh.cxx | 3 + 3 files changed, 58 insertions(+), 27 deletions(-)
New commits: commit b527fd0b6a8163d213529b386b80a8088136d1e4 Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Date: Mon Mar 12 09:50:17 2018 +0100 tdf#116305 Add timeout to help Windows bring browsers to the front Adding a timeout seems to help Windows a lot to actually bring the browser into the front, especially when it was closed before. Still no 100% success rate, but much improved now. Reviewed-on: https://gerrit.libreoffice.org/51132 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> (cherry picked from commit 5d5da77e82b6498dd73123ec0dc36d2315e279a1) Change-Id: I62affee4b837e0a60b1aac2a20be6fe7c3f9d2e0 diff --git a/sfx2/source/appl/openuriexternally.cxx b/sfx2/source/appl/openuriexternally.cxx index ed702340fb11..630c2c8391c5 100644 --- a/sfx2/source/appl/openuriexternally.cxx +++ b/sfx2/source/appl/openuriexternally.cxx @@ -28,16 +28,44 @@ #include "app.hrc" -bool sfx2::openUriExternally( - OUString const & uri, bool handleSystemShellExecuteException) +class URITools +{ +private: + Timer aOpenURITimer; + OUString msURI; + bool mbHandleSystemShellExecuteException; + DECL_LINK_TYPED(onOpenURI, Timer*, void); + +public: + void openURI(const OUString& sURI, bool bHandleSystemShellExecuteException); +}; + +void URITools::openURI(const OUString& sURI, bool bHandleSystemShellExecuteException) +{ + mbHandleSystemShellExecuteException = bHandleSystemShellExecuteException; + msURI = sURI; + + // tdf#116305 Workaround: Use timer to bring browsers to the front + aOpenURITimer.SetInvokeHandler(LINK(this, URITools, onOpenURI)); +#ifdef WNT + // 200ms seems to be the the best compromise between responsiveness and success rate + aOpenURITimer.SetTimeout(200); +#else + aOpenURITimer.SetTimeout(0); +#endif + aOpenURITimer.SetDebugName("sfx2::openUriExternallyTimer"); + aOpenURITimer.Start(); +} + +IMPL_LINK_NOARG_TYPED(URITools, onOpenURI, Timer*, void) { css::uno::Reference< css::system::XSystemShellExecute > exec( css::system::SystemShellExecute::create(comphelper::getProcessComponentContext())); try { exec->execute( - uri, OUString(), + msURI, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY); - return true; + return; } catch (css::lang::IllegalArgumentException & e) { if (e.ArgumentPosition != 0) { throw css::uno::RuntimeException( @@ -46,10 +74,10 @@ bool sfx2::openUriExternally( SolarMutexGuard g; ScopedVclPtrInstance<MessageDialog> eb( SfxGetpApp()->GetTopWindow(), SfxResId(STR_NO_ABS_URI_REF)); - eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", uri)); + eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI)); eb->Execute(); } catch (css::system::SystemShellExecuteException & e) { - if (!handleSystemShellExecuteException) { + if (!mbHandleSystemShellExecuteException) { throw; } SolarMutexGuard g; @@ -57,13 +85,19 @@ bool sfx2::openUriExternally( SfxGetpApp()->GetTopWindow(), SfxResId(STR_NO_WEBBROWSER_FOUND)); eb->set_primary_text( - eb->get_primary_text().replaceFirst("$(ARG1)", uri) + 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->Execute(); } - return false; + delete this; +} + +void sfx2::openUriExternally(const OUString& sURI, bool bHandleSystemShellExecuteException) +{ + URITools* uriTools = new URITools; + uriTools->openURI(sURI, bHandleSystemShellExecuteException); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/inc/openuriexternally.hxx b/sfx2/source/inc/openuriexternally.hxx index 42013cd70609..b45b2b7a931d 100644 --- a/sfx2/source/inc/openuriexternally.hxx +++ b/sfx2/source/inc/openuriexternally.hxx @@ -12,24 +12,20 @@ #include <sal/config.h> - -namespace sfx2 { - -/// Open a URI via com.sun.star.system.SystemShellExecute -/// -/// Handles XSystemShellExecute.execute's IllegalArgumentException (throwing a -/// RuntimeException if it is unexpected, i.e., not caused by the given uri not -/// being an absolute URI reference). -/// -/// Handles XSystemShellExecute.execute's SystemShellExecuteException unless the -/// given handleSystemShellExecuteException is false (in which case the -/// exception is re-thrown). -/// -/// @return true iff execution was successful -bool openUriExternally( - OUString const & uri, bool handleSystemShellExecuteException); - -} +namespace sfx2 +{ +/** Open a URI via com.sun.star.system.SystemShellExecute + + Handles XSystemShellExecute.execute's IllegalArgumentException (throwing a + RuntimeException if it is unexpected, i.e., not caused by the given uri not + being an absolute URI reference). + + Handles XSystemShellExecute.execute's SystemShellExecuteException unless the + given handleSystemShellExecuteException is false (in which case the + exception is re-thrown). +*/ +void openUriExternally(const OUString& sURI, bool bHandleSystemShellExecuteException); +}; #endif diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 0852c1d255e6..4aaff2c6c8d5 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -670,7 +670,8 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq ) return; } - rReq.Done(sfx2::openUriExternally(aFileURL, true)); + sfx2::openUriExternally(aFileURL, true); + rReq.Done(true); break; } else _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits