1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _DESKTOP_DISPATCHWATCHER_HXX 29*cdf0e10cSrcweir #define _DESKTOP_DISPATCHWATCHER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchResultListener.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "officeipcthread.hxx" 36*cdf0e10cSrcweir #include <hash_map> 37*cdf0e10cSrcweir #include <vector> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace desktop 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /* 43*cdf0e10cSrcweir Class for controlls dispatching of command URL through office command line. There 44*cdf0e10cSrcweir are "dangerous" command URLs, that can result in a running office without UI. To prevent 45*cdf0e10cSrcweir this situation the implementation surveile all dispatches and looks for an open task if 46*cdf0e10cSrcweir there is arose a problem. If there is none the office will be shutdown to prevent a 47*cdf0e10cSrcweir running office without UI. 48*cdf0e10cSrcweir */ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir struct OUStringHashCode 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir size_t operator()( const ::rtl::OUString& sString ) const 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir return sString.hashCode(); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir }; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir class DispatchWatcherHashMap : public ::std::hash_map< ::rtl::OUString, sal_Int32, OUStringHashCode, ::std::equal_to< ::rtl::OUString > > 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir public: 61*cdf0e10cSrcweir inline void free() 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir DispatchWatcherHashMap().swap( *this ); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir }; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class DispatchWatcher : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XDispatchResultListener > 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir public: 70*cdf0e10cSrcweir enum RequestType 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir REQUEST_OPEN, 73*cdf0e10cSrcweir REQUEST_VIEW, 74*cdf0e10cSrcweir REQUEST_START, 75*cdf0e10cSrcweir REQUEST_PRINT, 76*cdf0e10cSrcweir REQUEST_PRINTTO, 77*cdf0e10cSrcweir REQUEST_FORCEOPEN, 78*cdf0e10cSrcweir REQUEST_FORCENEW 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir struct DispatchRequest 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir DispatchRequest( RequestType aType, const ::rtl::OUString& aFile, boost::optional< rtl::OUString > const & cwdUrl, const ::rtl::OUString& aPrinter, const ::rtl::OUString& aFact ) : 84*cdf0e10cSrcweir aRequestType( aType ), aURL( aFile ), aCwdUrl( cwdUrl ), aPrinterName( aPrinter ), aPreselectedFactory( aFact ) {} 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir RequestType aRequestType; 87*cdf0e10cSrcweir rtl::OUString aURL; 88*cdf0e10cSrcweir boost::optional< rtl::OUString > aCwdUrl; 89*cdf0e10cSrcweir rtl::OUString aPrinterName; 90*cdf0e10cSrcweir rtl::OUString aPreselectedFactory; 91*cdf0e10cSrcweir }; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir typedef std::vector< DispatchRequest > DispatchList; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir virtual ~DispatchWatcher(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // XEventListener 98*cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) 99*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // XDispachResultListener 102*cdf0e10cSrcweir virtual void SAL_CALL dispatchFinished( const com::sun::star::frame::DispatchResultEvent& aEvent ) throw( com::sun::star::uno::RuntimeException ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // Access function to get a dispatcher watcher reference. There must be a global reference holder 105*cdf0e10cSrcweir static DispatchWatcher* GetDispatchWatcher(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // execute new dispatch request 108*cdf0e10cSrcweir sal_Bool executeDispatchRequests( const DispatchList& aDispatches, bool bNoTerminate = false ); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir private: 111*cdf0e10cSrcweir DispatchWatcher(); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir static ::osl::Mutex& GetMutex(); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir DispatchWatcherHashMap m_aRequestContainer; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir static ::osl::Mutex* pWatcherMutex; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir sal_Int16 m_nRequestCount; 120*cdf0e10cSrcweir }; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir #endif // _DESKTOP_DISPATCHWATCHER_HXX 125