summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-03-16 11:16:14 +0100
committerStephan Bergmann <sbergman@redhat.com>2012-03-16 15:01:26 +0100
commitd4b67611c421ebe9b75284106fe389b434419961 (patch)
tree9aebc058ae712e5bb1953267261c28c5a929f306 /shell
parent1a6b52a1bfc184524fc63d4a9d0b51055bf9af23 (diff)
Introduced SystemShellExecuteFlags::URIS_ONLY
Diffstat (limited to 'shell')
-rw-r--r--shell/source/unix/exec/shellexec.cxx44
-rw-r--r--shell/source/win32/SysShExec.cxx26
-rw-r--r--shell/source/win32/SysShExec.hxx6
-rw-r--r--shell/source/win32/SysShentry.cxx13
4 files changed, 73 insertions, 16 deletions
diff --git a/shell/source/unix/exec/shellexec.cxx b/shell/source/unix/exec/shellexec.cxx
index 912132103cdd..3b41f5b7e1c1 100644
--- a/shell/source/unix/exec/shellexec.cxx
+++ b/shell/source/unix/exec/shellexec.cxx
@@ -39,6 +39,7 @@
#include <com/sun/star/util/XMacroExpander.hpp>
#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
#include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
#include "uno/current_context.hxx"
@@ -76,6 +77,8 @@ using namespace cppu;
namespace // private
{
+ namespace css = com::sun::star;
+
Sequence< OUString > SAL_CALL ShellExec_getSupportedServiceNames()
{
Sequence< OUString > aRet(1);
@@ -132,10 +135,10 @@ void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aPar
// DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html
static const char *pDesktopLaunch = getenv( "DESKTOP_LAUNCH" );
- // Check whether aCommand contains a document url or not
- sal_Int32 nIndex = aCommand.indexOf( OUString( RTL_CONSTASCII_USTRINGPARAM(":/") ) );
-
- if( nIndex > 0 || 0 == aCommand.compareToAscii("mailto:", 7) )
+ // Check whether aCommand contains an absolute URI reference:
+ css::uno::Reference< css::uri::XUriReference > uri(
+ css::uri::UriReferenceFactory::create(m_xContext)->parse(aCommand));
+ if (uri.is() && uri->isAbsolute())
{
// It seems to be a url ..
// We need to re-encode file urls because osl_getFileURLFromSystemPath converts
@@ -155,7 +158,29 @@ void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aPar
}
#ifdef MACOSX
- aBuffer.append("open");
+ //TODO: Using open(1) with an argument that syntactically is an absolute
+ // URI reference does not necessarily give expected results:
+ // 1 If the given URI reference matches a supported scheme (e.g.,
+ // "mailto:foo"):
+ // 1.1 If it matches an existing pathname (relative to CWD): Results
+ // in "mailto:foo?\n[0]\tcancel\n[1]\tOpen the file\tmailto:foo\n[2]\t
+ // Open the URL\tmailto:foo\n\nWhich did you mean? Cancelled." on
+ // stderr and SystemShellExecuteException.
+ // 1.2 If it does not match an exitsting pathname (relative to CWD):
+ // Results in the corresponding application being opened with the given
+ // document (e.g., Mail with a New Message).
+ // 2 If the given URI reference does not match a supported scheme
+ // (e.g., "foo:bar"):
+ // 2.1 If it matches an existing pathname (relative to CWD) pointing to
+ // an executable: Results in execution of that executable.
+ // 2.2 If it matches an existing pathname (relative to CWD) pointing to
+ // a non-executable regular file: Results in opening it in TextEdit.
+ // 2.3 If it matches an existing pathname (relative to CWD) pointing to
+ // a directory: Results in opening it in Finder.
+ // 2.4 If it does not match an exitsting pathname (relative to CWD):
+ // Results in "The file /.../foo:bar does not exits." (where "/..." is
+ // the CWD) on stderr and SystemShellExecuteException.
+ aBuffer.append("open --");
#else
// The url launchers are expected to be in the $BRAND_BASE_DIR/program
// directory:
@@ -233,6 +258,15 @@ void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aPar
aLaunchBuffer.append(" ");
escapeForShell(aLaunchBuffer, OUStringToOString(aURL, osl_getThreadTextEncoding()));
}
+ } else if ((nFlags & css::system::SystemShellExecuteFlags::URIS_ONLY) != 0)
+ {
+ throw css::lang::IllegalArgumentException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "XSystemShellExecute.execute URIS_ONLY with non-absolute"
+ " URI reference "))
+ + aCommand),
+ static_cast< cppu::OWeakObject * >(this), 0);
} else {
escapeForShell(aBuffer, OUStringToOString(aCommand, osl_getThreadTextEncoding()));
aBuffer.append(" ");
diff --git a/shell/source/win32/SysShExec.cxx b/shell/source/win32/SysShExec.cxx
index b4c656c1f9fa..d0c7a90b1e10 100644
--- a/shell/source/win32/SysShExec.cxx
+++ b/shell/source/win32/SysShExec.cxx
@@ -36,6 +36,7 @@
#include <sal/macros.h>
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
#define WIN32_LEAN_AND_MEAN
#if defined _MSC_VER
@@ -79,6 +80,8 @@ using namespace cppu;
namespace // private
{
+ namespace css = com::sun::star;
+
Sequence< OUString > SAL_CALL SysShExec_getSupportedServiceNames()
{
Sequence< OUString > aRet(1);
@@ -258,8 +261,9 @@ namespace // private
//-----------------------------------------------------------------------------------------
-CSysShExec::CSysShExec( ) :
- WeakComponentImplHelper2< XSystemShellExecute, XServiceInfo >( m_aMutex )
+CSysShExec::CSysShExec( const Reference< css::uno::XComponentContext >& xContext ) :
+ WeakComponentImplHelper2< XSystemShellExecute, XServiceInfo >( m_aMutex ),
+ m_xContext(xContext)
{
/*
* As this service is declared thread-affine, it is ensured to be called from a
@@ -284,12 +288,28 @@ void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aPa
static_cast< XSystemShellExecute* >( this ),
1 );
- if (!(nFlags >= DEFAULTS && nFlags <= NO_SYSTEM_ERROR_MESSAGE))
+ if ((nFlags & ~(NO_SYSTEM_ERROR_MESSAGE | URIS_ONLY)) != 0)
throw IllegalArgumentException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid Flags specified")),
static_cast< XSystemShellExecute* >( this ),
3 );
+ if ((nFlags & URIS_ONLY) != 0)
+ {
+ css::uno::Reference< css::uri::XUriReference > uri(
+ css::uri::UriReferenceFactory::create(m_xContext)->parse(aCommand));
+ if (!(uri.is() && uri->isAbsolute()))
+ {
+ throw css::lang::IllegalArgumentException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "XSystemShellExecute.execute URIS_ONLY with"
+ " non-absolute URI reference "))
+ + aCommand),
+ static_cast< cppu::OWeakObject * >(this), 0);
+ }
+ }
+
/* #i4789#; jump mark detection on system paths
if the given command is a system path (not http or
other uri schemes) and seems to have a jump mark
diff --git a/shell/source/win32/SysShExec.hxx b/shell/source/win32/SysShExec.hxx
index 84b9a746d076..3ba357f2ff1b 100644
--- a/shell/source/win32/SysShExec.hxx
+++ b/shell/source/win32/SysShExec.hxx
@@ -36,6 +36,7 @@
#include <cppuhelper/compbase2.hxx>
#include <osl/mutex.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/system/XSystemShellExecute.hpp>
@@ -55,8 +56,11 @@ class CSysShExec :
com::sun::star::system::XSystemShellExecute,
com::sun::star::lang::XServiceInfo >
{
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
+ m_xContext;
+
public:
- CSysShExec( );
+ CSysShExec(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext);
//------------------------------------------------
// XSystemShellExecute
diff --git a/shell/source/win32/SysShentry.cxx b/shell/source/win32/SysShentry.cxx
index 874be551aa59..37a93672249e 100644
--- a/shell/source/win32/SysShentry.cxx
+++ b/shell/source/win32/SysShentry.cxx
@@ -59,9 +59,9 @@ using com::sun::star::system::XSystemShellExecute;
namespace
{
- Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiServiceFactory >& )
+ Reference< XInterface > SAL_CALL createInstance( const Reference< XComponentContext >& xContext )
{
- return Reference< XInterface >( static_cast< XSystemShellExecute* >( new CSysShExec( ) ) );
+ return Reference< XInterface >( static_cast< XSystemShellExecute* >( new CSysShExec(xContext) ) );
}
}
@@ -72,19 +72,18 @@ extern "C"
// returns a factory to create XFilePicker-Services
//----------------------------------------------------------------------
-SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface* pSrvManager, uno_Interface* /*pRegistryKey*/ )
+SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface*, uno_Interface* /*pRegistryKey*/ )
{
void* pRet = 0;
- if ( pSrvManager && ( 0 == rtl_str_compare( pImplName, SYSSHEXEC_IMPL_NAME ) ) )
+ if ( 0 == rtl_str_compare( pImplName, SYSSHEXEC_IMPL_NAME ) )
{
Sequence< OUString > aSNS( 1 );
aSNS.getArray( )[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( SYSSHEXEC_SERVICE_NAME ));
- Reference< XSingleServiceFactory > xFactory ( createOneInstanceFactory(
- reinterpret_cast< XMultiServiceFactory* > ( pSrvManager ),
- OUString::createFromAscii( pImplName ),
+ Reference< XSingleComponentFactory > xFactory ( createSingleComponentFactory(
createInstance,
+ OUString::createFromAscii( pImplName ),
aSNS ) );
if ( xFactory.is() )
{