Introduced SystemShellExecuteFlags::URIS_ONLY

This commit is contained in:
Stephan Bergmann
2012-03-16 15:01:26 +01:00
parent 1a6b52a1bf
commit d4b67611c4
35 changed files with 357 additions and 208 deletions
+1 -1
View File
@@ -2146,7 +2146,7 @@ IMPL_LINK( SpellDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch ( uno::Exception& )
{
+1 -1
View File
@@ -311,7 +311,7 @@ IMPL_LINK( AboutDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch ( uno::Exception& )
{
+1 -1
View File
@@ -158,7 +158,7 @@ static void lcl_OpenURL( ::rtl::OUString sURL )
RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
uno::UNO_QUERY_THROW );
if ( xSystemShell.is() )
xSystemShell->execute( sURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShell->execute( sURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch( const uno::Exception& e )
{
@@ -634,7 +634,7 @@ void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle
uno::Reference< XSystemShellExecute > xSystemShellExecute(
m_xContext->getServiceManager()->createInstanceWithContext( OUSTR( "com.sun.star.system.SystemShellExecute" ), m_xContext), uno::UNO_QUERY_THROW);
//throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
xSystemShellExecute->execute( sURL, OUString(), SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( sURL, OUString(), SystemShellExecuteFlags::URIS_ONLY );
}
catch ( const uno::Exception& )
{
@@ -1419,7 +1419,7 @@ IMPL_LINK( UpdateDialog, hyperlink_clicked, svt::FixedHyperlink*, pHyperlink )
m_context), uno::UNO_QUERY_THROW);
//throws lang::IllegalArgumentException, system::SystemShellExecuteException
xSystemShellExecute->execute(
sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY);
}
catch ( const uno::Exception& )
{
+1 -1
View File
@@ -879,7 +879,7 @@ void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID )
uno::Reference< ::com::sun::star::system::XSystemShellExecute > xSystemShellExecute( m_xFactory->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))),
uno::UNO_QUERY_THROW);
xSystemShellExecute->execute(m_aTempDumpURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
xSystemShellExecute->execute(m_aTempDumpURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY);
}
else
throw embed::UnreachableStateException();
@@ -1495,7 +1495,7 @@ UpdateCheck::showReleaseNote(const rtl::OUString& rURL) const
try {
if( xShellExecute.is() )
xShellExecute->execute(rURL, rtl::OUString(), c3s::SystemShellExecuteFlags::DEFAULTS);
xShellExecute->execute(rURL, rtl::OUString(), c3s::SystemShellExecuteFlags::URIS_ONLY);
} catch(const c3s::SystemShellExecuteException&) {
}
}
@@ -568,7 +568,7 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
void XMLFilterTestDialog::displayXMLFile( const OUString& rURL )
{
::com::sun::star::uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(comphelper::getProcessServiceFactory()->createInstance(DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), com::sun::star::uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( rURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( rURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
void XMLFilterTestDialog::onImportBrowse()
@@ -283,7 +283,7 @@ sal_Bool MailToDispatcher::implts_dispatch( const css::util::URL&
// start mail client
// Because there is no notofocation about success - we use case of
// no detected exception as SUCCESS - FAILED otherwhise.
xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY );
bSuccess = sal_True;
}
catch (const css::lang::IllegalArgumentException&)
+1 -1
View File
@@ -192,7 +192,7 @@ void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL&
xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE),
css::uno::UNO_QUERY_THROW);
xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS);
xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
}
catch(const css::uno::Exception&)
+1 -1
View File
@@ -858,7 +858,7 @@ IMPL_LINK_NOARG(BackingWindow, ToolboxHdl)
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
UNO_QUERY_THROW);
//throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS);
xSystemShellExecute->execute( sURL, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY);
}
}
}
@@ -277,7 +277,7 @@ void SAL_CALL BaseDispatch::dispatch( const URL& aURL, const Sequence < Property
try
{
xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY );
}
catch( Exception& rEx )
{
@@ -48,6 +48,12 @@ published constants SystemShellExecuteFlags
method <member scope="com::sun::star::system">XSystemShellExecute::execute()</member> fails.
*/
const long NO_SYSTEM_ERROR_MESSAGE = 1;
/** Only allows opening of absolute URI references.
@since LibreOffice 3.6
*/
const long URIS_ONLY = 2;
};
//=============================================================================
@@ -65,8 +65,10 @@ published interface XSystemShellExecute: com::sun::star::uno::XInterface
avoid showing system error messages, in case of failures, etc.
@throws com::sun::star::lang::IllegalArgumentException
when the specified flags are wrong or exclude each other.
.
when the specified flags are wrong or exclude each other; also thrown,
with an ArgumentPosition of 0, when nFlags contains URIS_ONLY and
aCommand is not an absolute URI reference
@throws com::sun::star::sys::SystemExecuteException
in the case of errors when trying to executed the specified command.
+1
View File
@@ -114,6 +114,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/appl/module \
sfx2/source/appl/newhelp \
sfx2/source/appl/opengrf \
sfx2/source/appl/openuriexternally \
sfx2/source/appl/sfxhelp \
sfx2/source/appl/sfxpicklist \
sfx2/source/appl/shutdownicon \
+1 -1
View File
@@ -33,7 +33,7 @@
#define ACC_IBM (RID_SFX_APP_START+2)
#define MSG_ERR_NO_WEBBROWSER_FOUND (RID_SFX_APP_START+7)
#define MSG_ERR_NO_ABS_URI_REF (RID_SFX_APP_START+8)
#define MSG_ISPRINTING_QUERYABORT (RID_SFX_APP_START+9)
#define MSG_CANT_QUIT (RID_SFX_APP_START+10)
#define STR_ISMODIFIED (RID_SFX_APP_START+11)
+7
View File
@@ -82,6 +82,13 @@ ErrorBox MSG_ERR_NO_WEBBROWSER_FOUND
Message[ en-US ] = "%PRODUCTNAME could not find a web browser on your system. Please check your Desktop Preferences or install a web browser (for example, Mozilla) in the default location requested during the browser installation." ;
};
ErrorBox MSG_ERR_NO_ABS_URI_REF
{
BUTTONS = WB_OK ;
DEFBUTTON = WB_DEF_OK ;
Message[ en-US ] = "\"$(ARG1)\" is not an absolute URL that can be passed to an external application to open it." ;
};
Resource SID_UNKNOWN
{
String 1 "-" ;
+83 -124
View File
@@ -39,9 +39,8 @@
#include <com/sun/star/frame/XDispatchResultListener.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/system/XSystemShellExecute.hpp>
#include <com/sun/star/system/SystemShellExecuteException.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/document/UpdateDocMode.hpp>
#include <com/sun/star/task/ErrorCodeRequest.hpp>
@@ -108,6 +107,7 @@
#include <sfx2/docfac.hxx>
#include <sfx2/event.hxx>
#include <svl/svstdarr.hxx>
#include "openuriexternally.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
@@ -115,7 +115,6 @@ using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::system;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::container;
using namespace ::cppu;
@@ -952,140 +951,100 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
if (!pFilter || !lcl_isFilterNativelySupported(*pFilter))
{
// hyperlink does not link to own type => special handling (http, ftp) browser and (other external protocols) OS
Reference< XSystemShellExecute > xSystemShellExecute( ::comphelper::getProcessServiceFactory()->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))), UNO_QUERY );
if ( xSystemShellExecute.is() )
if ( aINetProtocol == INET_PROT_MAILTO )
{
if ( aINetProtocol == INET_PROT_MAILTO )
// don't dispatch mailto hyperlink to desktop dispatcher
rReq.RemoveItem( SID_TARGETNAME );
rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_self") ) );
}
else if ( aINetProtocol == INET_PROT_FTP ||
aINetProtocol == INET_PROT_HTTP ||
aINetProtocol == INET_PROT_HTTPS )
{
sfx2::openUriExternally(aURL.Complete, true);
return;
}
else
{
// check for "internal" protocols that should not be forwarded to the system
Sequence < ::rtl::OUString > aProtocols(2);
// add special protocols that always should be treated as internal
aProtocols[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:*"));
aProtocols[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.*"));
try
{
// don't dispatch mailto hyperlink to desktop dispatcher
rReq.RemoveItem( SID_TARGETNAME );
rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_self") ) );
// get registered protocol handlers from configuration
Reference < XNameAccess > xAccess( ::comphelper::ConfigurationHelper::openConfig( ::comphelper::getProcessServiceFactory(),
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.ProtocolHandler/HandlerSet")), ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
if ( xAccess.is() )
{
Sequence < ::rtl::OUString > aNames = xAccess->getElementNames();
for ( sal_Int32 nName = 0; nName < aNames.getLength(); nName ++)
{
Reference < XPropertySet > xSet;
Any aRet = xAccess->getByName( aNames[nName] );
aRet >>= xSet;
if ( xSet.is() )
{
// copy protocols
aRet = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Protocols")) );
Sequence < ::rtl::OUString > aTmp;
aRet >>= aTmp;
// todo: add operator+= to SequenceAsVector class and use SequenceAsVector for aProtocols
sal_Int32 nLength = aProtocols.getLength();
aProtocols.realloc( nLength+aTmp.getLength() );
for ( sal_Int32 n=0; n<aTmp.getLength(); n++ )
aProtocols[(++nLength)-1] = aTmp[n];
}
}
}
}
else if ( aINetProtocol == INET_PROT_FTP ||
aINetProtocol == INET_PROT_HTTP ||
aINetProtocol == INET_PROT_HTTPS )
catch ( Exception& )
{
try
{
// start browser
::rtl::OUString aURLString( aURL.Complete );
xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
}
catch ( ::com::sun::star::lang::IllegalArgumentException& )
{
SolarMutexGuard aGuard;
Window *pWindow = SFX_APP()->GetTopWindow();
ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
}
catch ( ::com::sun::star::system::SystemShellExecuteException& )
{
SolarMutexGuard aGuard;
Window *pWindow = SFX_APP()->GetTopWindow();
ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
}
return;
// registered protocols could not be read
}
else
sal_Bool bFound = sal_False;
for ( sal_Int32 nProt=0; nProt<aProtocols.getLength(); nProt++ )
{
// check for "internal" protocols that should not be forwarded to the system
Sequence < ::rtl::OUString > aProtocols(2);
// add special protocols that always should be treated as internal
aProtocols[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:*"));
aProtocols[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.*"));
try
WildCard aPattern(aProtocols[nProt]);
if ( aPattern.Matches( aURL.Complete ) )
{
// get registered protocol handlers from configuration
Reference < XNameAccess > xAccess( ::comphelper::ConfigurationHelper::openConfig( ::comphelper::getProcessServiceFactory(),
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.ProtocolHandler/HandlerSet")), ::comphelper::ConfigurationHelper::E_READONLY ), UNO_QUERY );
if ( xAccess.is() )
{
Sequence < ::rtl::OUString > aNames = xAccess->getElementNames();
for ( sal_Int32 nName = 0; nName < aNames.getLength(); nName ++)
{
Reference < XPropertySet > xSet;
Any aRet = xAccess->getByName( aNames[nName] );
aRet >>= xSet;
if ( xSet.is() )
{
// copy protocols
aRet = xSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Protocols")) );
Sequence < ::rtl::OUString > aTmp;
aRet >>= aTmp;
bFound = sal_True;
break;
}
}
// todo: add operator+= to SequenceAsVector class and use SequenceAsVector for aProtocols
sal_Int32 nLength = aProtocols.getLength();
aProtocols.realloc( nLength+aTmp.getLength() );
for ( sal_Int32 n=0; n<aTmp.getLength(); n++ )
aProtocols[(++nLength)-1] = aTmp[n];
}
}
if ( !bFound )
{
sal_Bool bLoadInternal = sal_False;
// security reservation: => we have to check the referer before executing
if (SFX_APP()->IsSecureURL(rtl::OUString(), &aReferer))
{
try
{
sfx2::openUriExternally(
aURL.Complete, pFilter == 0);
}
catch ( ::com::sun::star::system::SystemShellExecuteException& )
{
rReq.RemoveItem( SID_TARGETNAME );
rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) );
bLoadInternal = sal_True;
}
}
catch ( Exception& )
else
{
// registered protocols could not be read
SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aURL.Complete );
ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
}
sal_Bool bFound = sal_False;
for ( sal_Int32 nProt=0; nProt<aProtocols.getLength(); nProt++ )
{
WildCard aPattern(aProtocols[nProt]);
if ( aPattern.Matches( aURL.Complete ) )
{
bFound = sal_True;
break;
}
}
if ( !bFound )
{
sal_Bool bLoadInternal = sal_False;
// security reservation: => we have to check the referer before executing
if (SFX_APP()->IsSecureURL(rtl::OUString(), &aReferer))
{
::rtl::OUString aURLString( aURL.Complete );
try
{
// give os this file
xSystemShellExecute->execute( aURLString, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
}
catch ( ::com::sun::star::lang::IllegalArgumentException& )
{
SolarMutexGuard aGuard;
Window *pWindow = SFX_APP()->GetTopWindow();
ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
}
catch ( ::com::sun::star::system::SystemShellExecuteException& )
{
if ( !pFilter )
{
SolarMutexGuard aGuard;
Window *pWindow = SFX_APP()->GetTopWindow();
ErrorBox( pWindow, SfxResId( MSG_ERR_NO_WEBBROWSER_FOUND )).Execute();
}
else
{
rReq.RemoveItem( SID_TARGETNAME );
rReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii("_default") ) );
bLoadInternal = sal_True;
}
}
}
else
{
SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aURL.Complete );
ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
}
if ( !bLoadInternal )
return;
}
if ( !bLoadInternal )
return;
}
}
}
+2 -2
View File
@@ -439,7 +439,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch ( uno::Exception& )
{
@@ -1013,7 +1013,7 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
xSystemShell->execute(
aURLBuf.makeStringAndClear(),
::rtl::OUString(),
css::system::SystemShellExecuteFlags::DEFAULTS );
css::system::SystemShellExecuteFlags::URIS_ONLY );
}
}
catch( const ::com::sun::star::uno::Exception& )
+101
View File
@@ -0,0 +1,101 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
* (initial developer) ]
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include "sal/config.h"
#include "com/sun/star/lang/IllegalArgumentException.hpp"
#include "com/sun/star/system/XSystemShellExecute.hpp"
#include "com/sun/star/system/SystemShellExecuteException.hpp"
#include "com/sun/star/system/SystemShellExecuteFlags.hpp"
#include "com/sun/star/uno/Reference.hxx"
#include "com/sun/star/uno/RuntimeException.hpp"
#include "com/sun/star/uno/XInterface.hpp"
#include "comphelper/processfactory.hxx"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sfx2/app.hxx"
#include "sfx2/sfxresid.hxx"
#include "tools/string.hxx"
#include "vcl/msgbox.hxx"
#include "vcl/svapp.hxx"
#include "openuriexternally.hxx"
#include "app.hrc"
namespace {
namespace css = com::sun::star;
}
bool sfx2::openUriExternally(
rtl::OUString const & uri, bool handleSystemShellExecuteException)
{
css::uno::Reference< css::system::XSystemShellExecute > exec(
comphelper::getProcessServiceFactory()->createInstance(
rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.system.SystemShellExecute"))),
css::uno::UNO_QUERY_THROW);
try {
exec->execute(
uri, rtl::OUString(),
css::system::SystemShellExecuteFlags::URIS_ONLY);
return true;
} catch (css::lang::IllegalArgumentException & e) {
if (e.ArgumentPosition != 0) {
throw css::uno::RuntimeException(
(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
"unexpected IllegalArgumentException: "))
+ e.Message),
css::uno::Reference< css::uno::XInterface >());
}
SolarMutexGuard g;
ErrorBox eb(
SfxGetpApp()->GetTopWindow(), SfxResId(MSG_ERR_NO_ABS_URI_REF));
String msg(eb.GetMessText());
msg.SearchAndReplaceAscii("$(ARG1)", uri);
eb.SetMessText(msg);
eb.Execute();
} catch (css::system::SystemShellExecuteException &) {
if (!handleSystemShellExecuteException) {
throw;
}
SolarMutexGuard g;
ErrorBox(
SfxGetpApp()->GetTopWindow(),
SfxResId(MSG_ERR_NO_WEBBROWSER_FOUND)).
Execute();
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+1 -1
View File
@@ -690,7 +690,7 @@ static bool impl_showOnlineHelp( const String& rURL )
if ( xSystemShell.is() )
{
xSystemShell->execute( aHelpLink, rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
xSystemShell->execute( aHelpLink, rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY );
return true;
}
}
+57
View File
@@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
* (initial developer) ]
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#ifndef INCLUDED_SFX2_SOURCE_INC_OPENURIEXTERNALLY_HXX
#define INCLUDED_SFX2_SOURCE_INC_OPENURIEXTERNALLY_HXX
#include "sal/config.h"
namespace rtl { class OUString; }
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(
rtl::OUString const & uri, bool handleSystemShellExecuteException);
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+1 -1
View File
@@ -63,7 +63,7 @@
#define MSG_QUERY_OPENASTEMPLATE (RID_SFX_VIEW_START+41)
#define MSG_CANT_CLOSE (RID_SFX_VIEW_START+42)
#define MSG_ERROR_NO_WEBBROWSER_FOUND (RID_SFX_VIEW_START+43)
#define TP_FRAMEPROPERTIES (RID_SFX_VIEW_START+44)
#define FT_FRAMENAME 3
-18
View File
@@ -170,21 +170,3 @@ String STR_REPAIREDDOCUMENT
{
Text [ en-US ] = " (repaired document)" ;
};
ErrorBox MSG_ERROR_NO_WEBBROWSER_FOUND
{
BUTTONS = WB_OK ;
DEFBUTTON = WB_DEF_OK ;
Message[ en-US ] = "%PRODUCTNAME could not find a web browser on your system. Please check your Desktop Preferences or install a web browser (for example, Mozilla) in the default location requested during the browser installation." ;
};
+2 -25
View File
@@ -39,8 +39,6 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/system/XSystemShellExecute.hpp>
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
#include <com/sun/star/container/XContainerQuery.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
@@ -86,6 +84,7 @@
#include "workwin.hxx"
#include <sfx2/objface.hxx>
#include <sfx2/docfilt.hxx>
#include "openuriexternally.hxx"
#include <comphelper/processfactory.hxx>
@@ -94,7 +93,6 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::system;
using namespace ::cppu;
namespace css = ::com::sun::star;
@@ -728,28 +726,7 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
return;
}
::com::sun::star::uno::Reference< XSystemShellExecute > xSystemShellExecute( xSMGR->createInstance(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))),
css::uno::UNO_QUERY );
sal_Bool bRet( sal_True );
if ( xSystemShellExecute.is() )
{
try
{
xSystemShellExecute->execute(
aFileURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
}
catch (const uno::Exception&)
{
SolarMutexGuard aGuard;
Window *pParent = SFX_APP()->GetTopWindow();
ErrorBox( pParent, SfxResId( MSG_ERROR_NO_WEBBROWSER_FOUND )).Execute();
bRet = sal_False;
}
}
rReq.Done(bRet);
rReq.Done(sfx2::openUriExternally(aFileURL, true));
break;
}
else
+39 -5
View File
@@ -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(" ");
+23 -3
View File
@@ -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
+5 -1
View File
@@ -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
+6 -7
View File
@@ -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() )
{
+1 -1
View File
@@ -1696,7 +1696,7 @@ IMPL_LINK_NOARG(SvtDocumentTemplateDialog, OpenLinkHdl_Impl)
RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
uno::UNO_QUERY_THROW );
if ( xSystemShell.is() )
xSystemShell->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShell->execute( sURL, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
EndDialog( RET_CANCEL );
}
catch( const uno::Exception& e )
+1 -1
View File
@@ -96,7 +96,7 @@ void pWorker(void *pThreadData)
uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( pData->fileName, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
xSystemShellExecute->execute( pData->fileName, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
void EditWithExternalTool(GraphicObject *pGraphicObject, SwWrtShell *rSh)
+1 -1
View File
@@ -844,7 +844,7 @@ void SwSpellPopup::Execute( sal_uInt16 nId )
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
xSystemShellExecute->execute( sExplanationLink, rtl::OUString(),
com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch (const uno::Exception&)
{
@@ -708,7 +708,7 @@ public class Helper
Object oSystemShell = xContext.getServiceManager().createInstanceWithContext( "com.sun.star.system.SystemShellExecute", xContext );
XSystemShellExecute xSystemShell = (XSystemShellExecute)UnoRuntime.queryInterface( XSystemShellExecute.class, oSystemShell );
if ( xSystemShell != null )
xSystemShell.execute( sURL, "", SystemShellExecuteFlags.DEFAULTS );
xSystemShell.execute( sURL, "", SystemShellExecuteFlags.URIS_ONLY );
}
catch( Exception e )
{
+1 -1
View File
@@ -2979,7 +2979,7 @@ void VCLXFixedHyperlink::ProcessWindowEvent( const VclWindowEvent& rVclWindowEve
{
// start browser
xSystemShellExecute->execute(
sURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::DEFAULTS );
sURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
catch( uno::Exception& )
{
+1 -1
View File
@@ -113,7 +113,7 @@ IMPL_LINK_NOARG(NewerVersionWarningDialog, UpdateHdl)
if ( xSystemShell.is() && !sNotifyURL.isEmpty() )
{
xSystemShell->execute(
sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
sNotifyURL, ::rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY );
}
}
else