1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #if ! defined INCLUDED_DP_MANAGER_H 29 #define INCLUDED_DP_MANAGER_H 30 31 #include "dp_manager.hrc" 32 #include "dp_misc.h" 33 #include "dp_interact.h" 34 #include "dp_activepackages.hxx" 35 #include "rtl/ref.hxx" 36 #include "cppuhelper/compbase1.hxx" 37 #include "cppuhelper/implbase2.hxx" 38 #include "ucbhelper/content.hxx" 39 #include "com/sun/star/deployment/XPackageRegistry.hpp" 40 #include "com/sun/star/deployment/XPackageManager.hpp" 41 #include <memory> 42 43 44 namespace css = ::com::sun::star; 45 46 namespace dp_manager { 47 48 typedef ::cppu::WeakComponentImplHelper1< 49 css::deployment::XPackageManager > t_pm_helper; 50 51 //============================================================================== 52 class PackageManagerImpl : private ::dp_misc::MutexHolder, public t_pm_helper 53 { 54 css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; 55 ::rtl::OUString m_context; 56 ::rtl::OUString m_registrationData; 57 ::rtl::OUString m_registrationData_expanded; 58 ::rtl::OUString m_registryCache; 59 bool m_readOnly; 60 61 ::rtl::OUString m_activePackages; 62 ::rtl::OUString m_activePackages_expanded; 63 ::std::auto_ptr< ActivePackages > m_activePackagesDB; 64 //This mutex is only used for synchronization in addPackage 65 ::osl::Mutex m_addMutex; 66 css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile; 67 inline void logIntern( css::uno::Any const & status ); 68 void fireModified(); 69 70 css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry; 71 72 void initRegistryBackends(); 73 void initActivationLayer( 74 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); 75 ::rtl::OUString detectMediaType( 76 ::ucbhelper::Content const & ucbContent, bool throw_exc = true ); 77 ::rtl::OUString insertToActivationLayer( 78 css::uno::Sequence<css::beans::NamedValue> const & properties, 79 ::rtl::OUString const & mediaType, 80 ::ucbhelper::Content const & sourceContent, 81 ::rtl::OUString const & title, ActivePackages::Data * dbData ); 82 void insertToActivationLayerDB( 83 ::rtl::OUString const & id, ActivePackages::Data const & dbData ); 84 85 void deletePackageFromCache( 86 css::uno::Reference<css::deployment::XPackage> const & xPackage, 87 ::rtl::OUString const & destFolder ); 88 89 bool isInstalled( 90 css::uno::Reference<css::deployment::XPackage> const & package); 91 92 bool synchronizeRemovedExtensions( 93 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 94 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv); 95 96 bool synchronizeAddedExtensions( 97 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 98 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv); 99 100 class CmdEnvWrapperImpl 101 : public ::cppu::WeakImplHelper2< css::ucb::XCommandEnvironment, 102 css::ucb::XProgressHandler > 103 { 104 css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile; 105 css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress; 106 css::uno::Reference<css::task::XInteractionHandler> 107 m_xUserInteractionHandler; 108 109 public: 110 virtual ~CmdEnvWrapperImpl(); 111 CmdEnvWrapperImpl( 112 css::uno::Reference<css::ucb::XCommandEnvironment> 113 const & xUserCmdEnv, 114 css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile ); 115 116 // XCommandEnvironment 117 virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL 118 getInteractionHandler() throw (css::uno::RuntimeException); 119 virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL 120 getProgressHandler() throw (css::uno::RuntimeException); 121 122 // XProgressHandler 123 virtual void SAL_CALL push( css::uno::Any const & Status ) 124 throw (css::uno::RuntimeException); 125 virtual void SAL_CALL update( css::uno::Any const & Status ) 126 throw (css::uno::RuntimeException); 127 virtual void SAL_CALL pop() throw (css::uno::RuntimeException); 128 }; 129 130 protected: 131 inline void check(); 132 virtual void SAL_CALL disposing(); 133 134 virtual ~PackageManagerImpl(); 135 inline PackageManagerImpl( 136 css::uno::Reference<css::uno::XComponentContext> 137 const & xComponentContext, ::rtl::OUString const & context ) 138 : t_pm_helper( getMutex() ), 139 m_xComponentContext( xComponentContext ), 140 m_context( context ), 141 m_readOnly( true ) 142 {} 143 144 public: 145 static css::uno::Reference<css::deployment::XPackageManager> create( 146 css::uno::Reference<css::uno::XComponentContext> 147 const & xComponentContext, ::rtl::OUString const & context ); 148 149 // XComponent 150 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException); 151 virtual void SAL_CALL addEventListener( 152 css::uno::Reference<css::lang::XEventListener> const & xListener ) 153 throw (css::uno::RuntimeException); 154 virtual void SAL_CALL removeEventListener( 155 css::uno::Reference<css::lang::XEventListener> const & xListener ) 156 throw (css::uno::RuntimeException); 157 158 // XModifyBroadcaster 159 virtual void SAL_CALL addModifyListener( 160 css::uno::Reference<css::util::XModifyListener> const & xListener ) 161 throw (css::uno::RuntimeException); 162 virtual void SAL_CALL removeModifyListener( 163 css::uno::Reference<css::util::XModifyListener> const & xListener ) 164 throw (css::uno::RuntimeException); 165 166 // XPackageManager 167 virtual ::rtl::OUString SAL_CALL getContext() 168 throw (css::uno::RuntimeException); 169 virtual css::uno::Sequence< 170 css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL 171 getSupportedPackageTypes() throw (css::uno::RuntimeException); 172 173 virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL 174 createAbortChannel() throw (css::uno::RuntimeException); 175 176 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage( 177 ::rtl::OUString const & url, 178 css::uno::Sequence<css::beans::NamedValue> const & properties, 179 ::rtl::OUString const & mediaType, 180 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 181 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 182 throw (css::deployment::DeploymentException, 183 css::ucb::CommandFailedException, 184 css::ucb::CommandAbortedException, 185 css::lang::IllegalArgumentException, 186 css::uno::RuntimeException); 187 188 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension( 189 css::uno::Reference<css::deployment::XPackage> const & extension, 190 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 191 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 192 throw (css::deployment::DeploymentException, 193 css::ucb::CommandFailedException, 194 css::ucb::CommandAbortedException, 195 css::lang::IllegalArgumentException, 196 css::uno::RuntimeException); 197 198 virtual void SAL_CALL removePackage( 199 ::rtl::OUString const & id, ::rtl::OUString const & fileName, 200 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 201 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 202 throw (css::deployment::DeploymentException, 203 css::ucb::CommandFailedException, 204 css::ucb::CommandAbortedException, 205 css::lang::IllegalArgumentException, 206 css::uno::RuntimeException); 207 208 ::rtl::OUString getDeployPath( ActivePackages::Data const & data ); 209 css::uno::Reference<css::deployment::XPackage> SAL_CALL getDeployedPackage_( 210 ::rtl::OUString const & id, ::rtl::OUString const & fileName, 211 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); 212 css::uno::Reference<css::deployment::XPackage> getDeployedPackage_( 213 ::rtl::OUString const & id, ActivePackages::Data const & data, 214 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, 215 bool ignoreAlienPlatforms = false ); 216 virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL 217 getDeployedPackage( 218 ::rtl::OUString const & id, ::rtl::OUString const & fileName, 219 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 220 throw (css::deployment::DeploymentException, 221 css::ucb::CommandFailedException, 222 css::lang::IllegalArgumentException, css::uno::RuntimeException); 223 224 css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> > 225 getDeployedPackages_( 226 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ); 227 virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> > 228 SAL_CALL getDeployedPackages( 229 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 230 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 231 throw (css::deployment::DeploymentException, 232 css::ucb::CommandFailedException, 233 css::ucb::CommandAbortedException, 234 css::lang::IllegalArgumentException, 235 css::uno::RuntimeException); 236 237 virtual void SAL_CALL reinstallDeployedPackages( 238 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 239 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 240 throw (css::deployment::DeploymentException, 241 css::ucb::CommandFailedException, 242 css::ucb::CommandAbortedException, 243 css::lang::IllegalArgumentException, 244 css::uno::RuntimeException); 245 246 virtual ::sal_Bool SAL_CALL isReadOnly( ) 247 throw (::com::sun::star::uno::RuntimeException); 248 249 virtual ::sal_Bool SAL_CALL synchronize( 250 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 251 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 252 throw (css::deployment::DeploymentException, 253 css::ucb::CommandFailedException, 254 css::ucb::CommandAbortedException, 255 css::uno::RuntimeException); 256 257 virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL 258 getExtensionsWithUnacceptedLicenses( 259 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) 260 throw (css::deployment::DeploymentException, 261 css::uno::RuntimeException); 262 263 virtual sal_Int32 SAL_CALL checkPrerequisites( 264 css::uno::Reference<css::deployment::XPackage> const & extension, 265 css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel, 266 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) 267 throw (css::deployment::DeploymentException, 268 css::ucb::CommandFailedException, 269 css::ucb::CommandAbortedException, 270 css::lang::IllegalArgumentException, 271 css::uno::RuntimeException); 272 }; 273 274 //______________________________________________________________________________ 275 inline void PackageManagerImpl::check() 276 { 277 ::osl::MutexGuard guard( getMutex() ); 278 if (rBHelper.bInDispose || rBHelper.bDisposed) 279 throw css::lang::DisposedException( 280 OUSTR("PackageManager instance has already been disposed!"), 281 static_cast< ::cppu::OWeakObject * >(this) ); 282 } 283 284 //______________________________________________________________________________ 285 inline void PackageManagerImpl::logIntern( css::uno::Any const & status ) 286 { 287 if (m_xLogFile.is()) 288 m_xLogFile->update( status ); 289 } 290 291 } 292 293 #endif 294 295