1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_desktop.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 34cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx" 35cdf0e10cSrcweir #include "rtl/bootstrap.hxx" 36cdf0e10cSrcweir #include "com/sun/star/deployment/ExtensionManager.hpp" 37cdf0e10cSrcweir #include "com/sun/star/deployment/XExtensionManager.hpp" 38cdf0e10cSrcweir #include "com/sun/star/deployment/thePackageManagerFactory.hpp" 39cdf0e10cSrcweir #include "com/sun/star/deployment/XPackageManager.hpp" 40cdf0e10cSrcweir #include "com/sun/star/deployment/XPackageManagerFactory.hpp" 41cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp" 42cdf0e10cSrcweir #include "com/sun/star/deployment/InstallException.hpp" 43cdf0e10cSrcweir #include "com/sun/star/deployment/VersionException.hpp" 44cdf0e10cSrcweir #include "com/sun/star/deployment/LicenseException.hpp" 45cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 46cdf0e10cSrcweir #include "com/sun/star/registry/XRegistryKey.hpp" 47cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp" 48cdf0e10cSrcweir #include "com/sun/star/task/XInteractionApprove.hpp" 49cdf0e10cSrcweir #include "com/sun/star/beans/Ambiguous.hpp" 50cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 51cdf0e10cSrcweir #include "com/sun/star/io/XInputStream.hpp" 52cdf0e10cSrcweir #include "com/sun/star/util/XModifyBroadcaster.hpp" 53cdf0e10cSrcweir #include "comphelper/sequence.hxx" 54cdf0e10cSrcweir #include "xmlscript/xml_helper.hxx" 55cdf0e10cSrcweir #include "osl/diagnose.h" 56cdf0e10cSrcweir #include "dp_interact.h" 57cdf0e10cSrcweir #include "dp_resource.h" 58cdf0e10cSrcweir #include "dp_ucb.h" 59cdf0e10cSrcweir #include "dp_identifier.hxx" 60cdf0e10cSrcweir #include "dp_descriptioninfoset.hxx" 61cdf0e10cSrcweir #include "dp_extensionmanager.hxx" 62cdf0e10cSrcweir #include "dp_commandenvironments.hxx" 63cdf0e10cSrcweir #include "dp_properties.hxx" 64cdf0e10cSrcweir #include "boost/bind.hpp" 65cdf0e10cSrcweir 66cdf0e10cSrcweir #include <list> 67cdf0e10cSrcweir #include <hash_map> 68cdf0e10cSrcweir #include <algorithm> 69cdf0e10cSrcweir 70cdf0e10cSrcweir namespace deploy = com::sun::star::deployment; 71cdf0e10cSrcweir namespace lang = com::sun::star::lang; 72cdf0e10cSrcweir namespace registry = com::sun::star::registry; 73cdf0e10cSrcweir namespace task = com::sun::star::task; 74cdf0e10cSrcweir namespace ucb = com::sun::star::ucb; 75cdf0e10cSrcweir namespace uno = com::sun::star::uno; 76cdf0e10cSrcweir namespace beans = com::sun::star::beans; 77cdf0e10cSrcweir namespace util = com::sun::star::util; 78cdf0e10cSrcweir namespace css = com::sun::star; 79cdf0e10cSrcweir 80cdf0e10cSrcweir 81cdf0e10cSrcweir //#define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 82cdf0e10cSrcweir 83cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 84cdf0e10cSrcweir using ::rtl::OUString; 85cdf0e10cSrcweir 86cdf0e10cSrcweir namespace { 87cdf0e10cSrcweir 88cdf0e10cSrcweir struct CompIdentifiers 89cdf0e10cSrcweir { 90cdf0e10cSrcweir bool operator() (::std::vector<Reference<deploy::XPackage> > const & a, 91cdf0e10cSrcweir ::std::vector<Reference<deploy::XPackage> > const & b) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir 94cdf0e10cSrcweir if (getName(a).compareTo(getName(b)) < 0) 95cdf0e10cSrcweir return true; 96cdf0e10cSrcweir return false; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir OUString getName(::std::vector<Reference<deploy::XPackage> > const & a); 100cdf0e10cSrcweir }; 101cdf0e10cSrcweir 102cdf0e10cSrcweir OUString CompIdentifiers::getName(::std::vector<Reference<deploy::XPackage> > const & a) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir OSL_ASSERT(a.size() == 3); 105cdf0e10cSrcweir //get the first non-null reference 106cdf0e10cSrcweir Reference<deploy::XPackage> extension; 107cdf0e10cSrcweir ::std::vector<Reference<deploy::XPackage> >::const_iterator it = a.begin(); 108cdf0e10cSrcweir for (; it != a.end(); it++) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if (it->is()) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir extension = *it; 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir OSL_ASSERT(extension.is()); 117cdf0e10cSrcweir return extension->getDisplayName(); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir void writeLastModified(OUString & url, Reference<ucb::XCommandEnvironment> const & xCmdEnv) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir //Write the lastmodified file 123cdf0e10cSrcweir try { 124cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros(url); 125cdf0e10cSrcweir ::ucbhelper::Content ucbStamp(url, xCmdEnv ); 126cdf0e10cSrcweir dp_misc::erase_path( url, xCmdEnv ); 127cdf0e10cSrcweir ::rtl::OString stamp("1" ); 128cdf0e10cSrcweir Reference<css::io::XInputStream> xData( 129cdf0e10cSrcweir ::xmlscript::createInputStream( 130cdf0e10cSrcweir ::rtl::ByteSequence( 131cdf0e10cSrcweir reinterpret_cast<sal_Int8 const *>(stamp.getStr()), 132cdf0e10cSrcweir stamp.getLength() ) ) ); 133cdf0e10cSrcweir ucbStamp.writeStream( xData, true /* replace existing */ ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir catch(...) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir uno::Any exc(::cppu::getCaughtException()); 138cdf0e10cSrcweir throw deploy::DeploymentException( 139cdf0e10cSrcweir OUSTR("Failed to update") + url, 0, exc); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir class ExtensionRemoveGuard 144cdf0e10cSrcweir { 145cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackage> m_extension; 146cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackageManager> m_xPackageManager; 147cdf0e10cSrcweir 148cdf0e10cSrcweir public: 149*7bc7b19fSMichael Stahl ExtensionRemoveGuard(){}; 150cdf0e10cSrcweir ExtensionRemoveGuard( 151cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackage> const & extension, 152cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackageManager> const & xPackageManager): 153cdf0e10cSrcweir m_extension(extension), m_xPackageManager(xPackageManager) {} 154cdf0e10cSrcweir ~ExtensionRemoveGuard(); 155cdf0e10cSrcweir 156*7bc7b19fSMichael Stahl void set(css::uno::Reference<css::deployment::XPackage> const & extension, 157*7bc7b19fSMichael Stahl css::uno::Reference<css::deployment::XPackageManager> const & xPackageManager) { 158cdf0e10cSrcweir m_extension = extension; 159*7bc7b19fSMichael Stahl m_xPackageManager = xPackageManager; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir }; 162cdf0e10cSrcweir 163cdf0e10cSrcweir ExtensionRemoveGuard::~ExtensionRemoveGuard() 164cdf0e10cSrcweir { 165cdf0e10cSrcweir try { 166*7bc7b19fSMichael Stahl OSL_ASSERT(!(m_extension.is() && !m_xPackageManager.is())); 167cdf0e10cSrcweir if (m_xPackageManager.is() && m_extension.is()) 168cdf0e10cSrcweir m_xPackageManager->removePackage( 169cdf0e10cSrcweir dp_misc::getIdentifier(m_extension), ::rtl::OUString(), 170cdf0e10cSrcweir css::uno::Reference<css::task::XAbortChannel>(), 171cdf0e10cSrcweir css::uno::Reference<css::ucb::XCommandEnvironment>()); 172cdf0e10cSrcweir } catch (...) { 173cdf0e10cSrcweir OSL_ASSERT(0); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir } //end namespace 178cdf0e10cSrcweir 179cdf0e10cSrcweir namespace dp_manager { 180cdf0e10cSrcweir 181cdf0e10cSrcweir 182cdf0e10cSrcweir 183cdf0e10cSrcweir //------------------------------------------------------------------------------ 184cdf0e10cSrcweir 185cdf0e10cSrcweir //ToDo: bundled extension 186cdf0e10cSrcweir ExtensionManager::ExtensionManager( Reference< uno::XComponentContext > const& xContext) : 187cdf0e10cSrcweir ::cppu::WeakComponentImplHelper1< css::deployment::XExtensionManager >(getMutex()), 188cdf0e10cSrcweir m_xContext( xContext ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir m_xPackageManagerFactory = deploy::thePackageManagerFactory::get(m_xContext); 191cdf0e10cSrcweir OSL_ASSERT(m_xPackageManagerFactory.is()); 192cdf0e10cSrcweir 193cdf0e10cSrcweir m_repositoryNames.push_back(OUSTR("user")); 194cdf0e10cSrcweir m_repositoryNames.push_back(OUSTR("shared")); 195cdf0e10cSrcweir m_repositoryNames.push_back(OUSTR("bundled")); 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir //------------------------------------------------------------------------------ 199cdf0e10cSrcweir 200cdf0e10cSrcweir ExtensionManager::~ExtensionManager() 201cdf0e10cSrcweir { 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir Reference<deploy::XPackageManager> ExtensionManager::getUserRepository() 205cdf0e10cSrcweir { 206cdf0e10cSrcweir return m_xPackageManagerFactory->getPackageManager(OUSTR("user")); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir Reference<deploy::XPackageManager> ExtensionManager::getSharedRepository() 209cdf0e10cSrcweir { 210cdf0e10cSrcweir return m_xPackageManagerFactory->getPackageManager(OUSTR("shared")); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir Reference<deploy::XPackageManager> ExtensionManager::getBundledRepository() 213cdf0e10cSrcweir { 214cdf0e10cSrcweir return m_xPackageManagerFactory->getPackageManager(OUSTR("bundled")); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir Reference<deploy::XPackageManager> ExtensionManager::getTmpRepository() 217cdf0e10cSrcweir { 218cdf0e10cSrcweir return m_xPackageManagerFactory->getPackageManager(OUSTR("tmp")); 219cdf0e10cSrcweir } 220*7bc7b19fSMichael Stahl Reference<deploy::XPackageManager> ExtensionManager::getBakRepository() 221*7bc7b19fSMichael Stahl { 222*7bc7b19fSMichael Stahl return m_xPackageManagerFactory->getPackageManager(OUSTR("bak")); 223*7bc7b19fSMichael Stahl } 224cdf0e10cSrcweir 225cdf0e10cSrcweir Reference<task::XAbortChannel> ExtensionManager::createAbortChannel() 226cdf0e10cSrcweir throw (uno::RuntimeException) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir return new dp_misc::AbortChannel; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackageManager> 232cdf0e10cSrcweir ExtensionManager::getPackageManager(::rtl::OUString const & repository) 233cdf0e10cSrcweir throw (css::lang::IllegalArgumentException) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir Reference<deploy::XPackageManager> xPackageManager; 236cdf0e10cSrcweir if (repository.equals(OUSTR("user"))) 237cdf0e10cSrcweir xPackageManager = getUserRepository(); 238cdf0e10cSrcweir else if (repository.equals(OUSTR("shared"))) 239cdf0e10cSrcweir xPackageManager = getSharedRepository(); 240cdf0e10cSrcweir else if (repository.equals(OUSTR("bundled"))) 241cdf0e10cSrcweir xPackageManager = getBundledRepository(); 242cdf0e10cSrcweir else 243cdf0e10cSrcweir throw lang::IllegalArgumentException( 244cdf0e10cSrcweir OUSTR("No valid repository name provided."), 245cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 0); 246cdf0e10cSrcweir return xPackageManager; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250cdf0e10cSrcweir /* 251cdf0e10cSrcweir Enters the XPackage objects into a map. They must be all from the 252cdf0e10cSrcweir same repository. The value type of the map is a vector, where each vector 253cdf0e10cSrcweir represents an extension with a particular identifier. The first member 254cdf0e10cSrcweir is represents the user extension, the second the shared extension and the 255cdf0e10cSrcweir third the bundled extension. 256cdf0e10cSrcweir */ 257cdf0e10cSrcweir void ExtensionManager::addExtensionsToMap( 258cdf0e10cSrcweir id2extensions & mapExt, 259cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > const & seqExt, 260cdf0e10cSrcweir OUString const & repository) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir //Determine the index in the vector where these extensions are to be 263cdf0e10cSrcweir //added. 264cdf0e10cSrcweir ::std::list<OUString>::const_iterator citNames = 265cdf0e10cSrcweir m_repositoryNames.begin(); 266cdf0e10cSrcweir int index = 0; 267cdf0e10cSrcweir for (;citNames != m_repositoryNames.end(); citNames++, index++) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir if (citNames->equals(repository)) 270cdf0e10cSrcweir break; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir for (int i = 0; i < seqExt.getLength(); i++) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir Reference<deploy::XPackage> const & xExtension = seqExt[i]; 276cdf0e10cSrcweir OUString id = dp_misc::getIdentifier(xExtension); 277cdf0e10cSrcweir id2extensions::iterator ivec = mapExt.find(id); 278cdf0e10cSrcweir if (ivec == mapExt.end()) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir ::std::vector<Reference<deploy::XPackage> > vec(3); 281cdf0e10cSrcweir vec[index] = xExtension; 282cdf0e10cSrcweir mapExt[id] = vec; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir else 285cdf0e10cSrcweir { 286cdf0e10cSrcweir ivec->second[index] = xExtension; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir /* 292cdf0e10cSrcweir returns a list containing extensions with the same identifier from 293cdf0e10cSrcweir all repositories (user, shared, bundled) If one repository does not 294cdf0e10cSrcweir have this extension, then the list contains an empty Referenc. The list 295cdf0e10cSrcweir is ordered according to the priority of the repostories: 296cdf0e10cSrcweir 1. user 297cdf0e10cSrcweir 2. shared 298cdf0e10cSrcweir 3. bundled 299cdf0e10cSrcweir 300cdf0e10cSrcweir The number of elements is always three, unless the number of repository 301cdf0e10cSrcweir changes. 302cdf0e10cSrcweir */ 303cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > 304cdf0e10cSrcweir ExtensionManager::getExtensionsWithSameId( 305cdf0e10cSrcweir OUString const & identifier, OUString const & fileName, 306cdf0e10cSrcweir Reference< ucb::XCommandEnvironment> const & /*xCmdEnv*/) 307cdf0e10cSrcweir 308cdf0e10cSrcweir { 309cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > extensionList; 310cdf0e10cSrcweir try 311cdf0e10cSrcweir { //will throw an exception if the extension does not exist 312cdf0e10cSrcweir extensionList.push_back(getUserRepository()->getDeployedPackage( 313cdf0e10cSrcweir identifier, fileName, Reference<ucb::XCommandEnvironment>())); 314cdf0e10cSrcweir } catch(lang::IllegalArgumentException &) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir extensionList.push_back(Reference<deploy::XPackage>()); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir try 319cdf0e10cSrcweir { 320cdf0e10cSrcweir extensionList.push_back(getSharedRepository()->getDeployedPackage( 321cdf0e10cSrcweir identifier, fileName, Reference<ucb::XCommandEnvironment>())); 322cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir extensionList.push_back(Reference<deploy::XPackage>()); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir try 327cdf0e10cSrcweir { 328cdf0e10cSrcweir extensionList.push_back(getBundledRepository()->getDeployedPackage( 329cdf0e10cSrcweir identifier, fileName, Reference<ucb::XCommandEnvironment>())); 330cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir extensionList.push_back(Reference<deploy::XPackage>()); 333cdf0e10cSrcweir } 334cdf0e10cSrcweir OSL_ASSERT(extensionList.size() == 3); 335cdf0e10cSrcweir return extensionList; 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > 339cdf0e10cSrcweir ExtensionManager::getExtensionsWithSameIdentifier( 340cdf0e10cSrcweir OUString const & identifier, 341cdf0e10cSrcweir OUString const & fileName, 342cdf0e10cSrcweir Reference< ucb::XCommandEnvironment> const & xCmdEnv ) 343cdf0e10cSrcweir throw ( 344cdf0e10cSrcweir deploy::DeploymentException, 345cdf0e10cSrcweir ucb::CommandFailedException, 346cdf0e10cSrcweir lang::IllegalArgumentException, 347cdf0e10cSrcweir uno::RuntimeException) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir try 350cdf0e10cSrcweir { 351cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > listExtensions = 352cdf0e10cSrcweir getExtensionsWithSameId( 353cdf0e10cSrcweir identifier, fileName, xCmdEnv); 354cdf0e10cSrcweir sal_Bool bHasExtension = false; 355cdf0e10cSrcweir 356cdf0e10cSrcweir //throw an IllegalArgumentException if there is no extension at all. 357cdf0e10cSrcweir typedef ::std::list<Reference<deploy::XPackage> >::const_iterator CIT; 358cdf0e10cSrcweir for (CIT i = listExtensions.begin(); i != listExtensions.end(); i++) 359cdf0e10cSrcweir bHasExtension |= i->is(); 360cdf0e10cSrcweir if (!bHasExtension) 361cdf0e10cSrcweir throw lang::IllegalArgumentException( 362cdf0e10cSrcweir OUSTR("Could not find extension: ") + identifier + OUSTR(", ") + fileName, 363cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), -1); 364cdf0e10cSrcweir 365cdf0e10cSrcweir return comphelper::containerToSequence< 366cdf0e10cSrcweir Reference<deploy::XPackage>, 367cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > 368cdf0e10cSrcweir > (listExtensions); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir catch (deploy::DeploymentException & ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir throw; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir catch ( ucb::CommandFailedException & ) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir throw; 377cdf0e10cSrcweir } 378cdf0e10cSrcweir catch (lang::IllegalArgumentException &) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir throw; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir catch (...) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir uno::Any exc = ::cppu::getCaughtException(); 385cdf0e10cSrcweir throw deploy::DeploymentException( 386cdf0e10cSrcweir OUSTR("Extension Manager: exception during getExtensionsWithSameIdentifier"), 387cdf0e10cSrcweir static_cast<OWeakObject*>(this), exc); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir 392cdf0e10cSrcweir 393cdf0e10cSrcweir bool ExtensionManager::isUserDisabled( 394cdf0e10cSrcweir OUString const & identifier, OUString const & fileName) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > listExtensions; 397cdf0e10cSrcweir 398cdf0e10cSrcweir try { 399cdf0e10cSrcweir listExtensions = getExtensionsWithSameId(identifier, fileName); 400cdf0e10cSrcweir } catch (lang::IllegalArgumentException & ) { 401cdf0e10cSrcweir } 402cdf0e10cSrcweir OSL_ASSERT(listExtensions.size() == 3); 403cdf0e10cSrcweir 404cdf0e10cSrcweir return isUserDisabled( ::comphelper::containerToSequence< 405cdf0e10cSrcweir Reference<deploy::XPackage>, 406cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > 407cdf0e10cSrcweir > (listExtensions)); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir bool ExtensionManager::isUserDisabled( 411cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > const & seqExtSameId) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir OSL_ASSERT(seqExtSameId.getLength() == 3); 414cdf0e10cSrcweir Reference<deploy::XPackage> const & userExtension = seqExtSameId[0]; 415cdf0e10cSrcweir if (userExtension.is()) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir beans::Optional<beans::Ambiguous<sal_Bool> > reg = 418cdf0e10cSrcweir userExtension->isRegistered(Reference<task::XAbortChannel>(), 419cdf0e10cSrcweir Reference<ucb::XCommandEnvironment>()); 420cdf0e10cSrcweir //If the value is ambiguous is than we assume that the extension 421cdf0e10cSrcweir //is enabled, but something went wrong during enabling. We do not 422cdf0e10cSrcweir //automatically disable user extensions. 423cdf0e10cSrcweir if (reg.IsPresent && 424cdf0e10cSrcweir ! reg.Value.IsAmbiguous && ! reg.Value.Value) 425cdf0e10cSrcweir return true; 426cdf0e10cSrcweir } 427cdf0e10cSrcweir return false; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir /* 431cdf0e10cSrcweir This method determines the active extension (XPackage.registerPackage) with a 432cdf0e10cSrcweir particular identifier. 433cdf0e10cSrcweir 434cdf0e10cSrcweir The parameter bUserDisabled determines if the user extension is disabled. 435cdf0e10cSrcweir 436cdf0e10cSrcweir When the user repository contains an extension with the given identifier and 437cdf0e10cSrcweir it is not disabled by the user, then it is always registered. Otherwise an 438cdf0e10cSrcweir extension is only registered when there is no registered extension in one of 439cdf0e10cSrcweir the repositories with a higher priority. That is, if the extension is from 440cdf0e10cSrcweir the shared repository and an active extension with the same identifer is in 441cdf0e10cSrcweir the user repository, then the extension is not registered. Similarly a 442cdf0e10cSrcweir bundled extension is not registered if there is an active extension with the 443cdf0e10cSrcweir same identifier in the shared or user repository. 444cdf0e10cSrcweir */ 445cdf0e10cSrcweir void ExtensionManager::activateExtension( 446cdf0e10cSrcweir OUString const & identifier, OUString const & fileName, 447cdf0e10cSrcweir bool bUserDisabled, 448cdf0e10cSrcweir bool bStartup, 449cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 450cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > listExtensions; 453cdf0e10cSrcweir try { 454cdf0e10cSrcweir listExtensions = getExtensionsWithSameId(identifier, fileName); 455cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 456cdf0e10cSrcweir } 457cdf0e10cSrcweir OSL_ASSERT(listExtensions.size() == 3); 458cdf0e10cSrcweir 459cdf0e10cSrcweir activateExtension( 460cdf0e10cSrcweir ::comphelper::containerToSequence< 461cdf0e10cSrcweir Reference<deploy::XPackage>, 462cdf0e10cSrcweir ::std::list<Reference<deploy::XPackage> > 463cdf0e10cSrcweir > (listExtensions), 464cdf0e10cSrcweir bUserDisabled, bStartup, xAbortChannel, xCmdEnv); 465cdf0e10cSrcweir 466cdf0e10cSrcweir fireModified(); 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir void ExtensionManager::activateExtension( 470cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > const & seqExt, 471cdf0e10cSrcweir bool bUserDisabled, 472cdf0e10cSrcweir bool bStartup, 473cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 474cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir bool bActive = false; 477cdf0e10cSrcweir sal_Int32 len = seqExt.getLength(); 478cdf0e10cSrcweir for (sal_Int32 i = 0; i < len; i++) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir Reference<deploy::XPackage> const & aExt = seqExt[i]; 481cdf0e10cSrcweir if (aExt.is()) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir //get the registration value of the current iteration 484cdf0e10cSrcweir beans::Optional<beans::Ambiguous<sal_Bool> > optReg = 485cdf0e10cSrcweir aExt->isRegistered(xAbortChannel, xCmdEnv); 486cdf0e10cSrcweir //If nothing can be registered then break 487cdf0e10cSrcweir if (!optReg.IsPresent) 488cdf0e10cSrcweir break; 489cdf0e10cSrcweir 490cdf0e10cSrcweir //Check if this is a disabled user extension, 491cdf0e10cSrcweir if (i == 0 && bUserDisabled) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir aExt->revokePackage(xAbortChannel, xCmdEnv); 494cdf0e10cSrcweir continue; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir 497cdf0e10cSrcweir //If we have already determined an active extension then we must 498cdf0e10cSrcweir //make sure to unregister all extensions with the same id in 499cdf0e10cSrcweir //repositories with a lower priority 500cdf0e10cSrcweir if (bActive) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir aExt->revokePackage(xAbortChannel, xCmdEnv); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir else 505cdf0e10cSrcweir { 506cdf0e10cSrcweir //This is the first extension in the ordered list, which becomes 507cdf0e10cSrcweir //the active extension 508cdf0e10cSrcweir bActive = true; 509cdf0e10cSrcweir //Register if not already done. 510cdf0e10cSrcweir //reregister if the value is ambiguous, which indicates that 511cdf0e10cSrcweir //something went wrong during last registration. 512cdf0e10cSrcweir aExt->registerPackage(bStartup, xAbortChannel, xCmdEnv); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir } 515cdf0e10cSrcweir } 516cdf0e10cSrcweir } 517cdf0e10cSrcweir 518cdf0e10cSrcweir Reference<deploy::XPackage> ExtensionManager::backupExtension( 519cdf0e10cSrcweir OUString const & identifier, OUString const & fileName, 520cdf0e10cSrcweir Reference<deploy::XPackageManager> const & xPackageManager, 521cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir Reference<deploy::XPackage> xBackup; 524cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> tmpCmdEnv( 525cdf0e10cSrcweir new TmpRepositoryCommandEnv(xCmdEnv->getInteractionHandler())); 526cdf0e10cSrcweir Reference<deploy::XPackage> xOldExtension; 527cdf0e10cSrcweir xOldExtension = xPackageManager->getDeployedPackage( 528cdf0e10cSrcweir identifier, fileName, tmpCmdEnv); 529cdf0e10cSrcweir 530cdf0e10cSrcweir if (xOldExtension.is()) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir xBackup = getTmpRepository()->addPackage( 533cdf0e10cSrcweir xOldExtension->getURL(), uno::Sequence<beans::NamedValue>(), 534cdf0e10cSrcweir OUString(), Reference<task::XAbortChannel>(), tmpCmdEnv); 535cdf0e10cSrcweir 536cdf0e10cSrcweir OSL_ENSURE(xBackup.is(), "Failed to backup extension"); 537cdf0e10cSrcweir } 538cdf0e10cSrcweir return xBackup; 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir //The supported package types are actually determined by the registry. However 542cdf0e10cSrcweir //creating a registry 543cdf0e10cSrcweir //(desktop/source/deployment/registry/dp_registry.cxx:PackageRegistryImpl) will 544cdf0e10cSrcweir //create all the backends, so that the registry can obtain from them the package 545cdf0e10cSrcweir //types. Creating the registry will also set up the registry folder containing 546cdf0e10cSrcweir //all the subfolders for the respective backends. 547cdf0e10cSrcweir //Because all repositories support the same backends, we can just delegate this 548cdf0e10cSrcweir //call to one of the repositories. 549cdf0e10cSrcweir uno::Sequence< Reference<deploy::XPackageTypeInfo> > 550cdf0e10cSrcweir ExtensionManager::getSupportedPackageTypes() 551cdf0e10cSrcweir throw (uno::RuntimeException) 552cdf0e10cSrcweir { 553cdf0e10cSrcweir return getUserRepository()->getSupportedPackageTypes(); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir //Do some necessary checks and user interaction. This function does not 556cdf0e10cSrcweir //aquire the extension manager mutex and that mutex must not be aquired 557cdf0e10cSrcweir //when this function is called. doChecksForAddExtension does synchronous 558cdf0e10cSrcweir //user interactions which may require aquiring the solar mutex. 559cdf0e10cSrcweir //Returns true if the extension can be installed. 560cdf0e10cSrcweir bool ExtensionManager::doChecksForAddExtension( 561cdf0e10cSrcweir Reference<deploy::XPackageManager> const & xPackageMgr, 562cdf0e10cSrcweir uno::Sequence<beans::NamedValue> const & properties, 563cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackage> const & xTmpExtension, 564cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 565cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv, 566cdf0e10cSrcweir Reference<deploy::XPackage> & out_existingExtension ) 567cdf0e10cSrcweir throw (deploy::DeploymentException, 568cdf0e10cSrcweir ucb::CommandFailedException, 569cdf0e10cSrcweir ucb::CommandAbortedException, 570cdf0e10cSrcweir lang::IllegalArgumentException, 571cdf0e10cSrcweir uno::RuntimeException) 572cdf0e10cSrcweir { 573cdf0e10cSrcweir try 574cdf0e10cSrcweir { 575cdf0e10cSrcweir Reference<deploy::XPackage> xOldExtension; 576cdf0e10cSrcweir const OUString sIdentifier = dp_misc::getIdentifier(xTmpExtension); 577cdf0e10cSrcweir const OUString sFileName = xTmpExtension->getName(); 578cdf0e10cSrcweir const OUString sDisplayName = xTmpExtension->getDisplayName(); 579cdf0e10cSrcweir const OUString sVersion = xTmpExtension->getVersion(); 580cdf0e10cSrcweir 581cdf0e10cSrcweir try 582cdf0e10cSrcweir { 583cdf0e10cSrcweir xOldExtension = xPackageMgr->getDeployedPackage( 584cdf0e10cSrcweir sIdentifier, sFileName, xCmdEnv); 585cdf0e10cSrcweir out_existingExtension = xOldExtension; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir catch (lang::IllegalArgumentException &) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir } 590cdf0e10cSrcweir bool bCanInstall = false; 591cdf0e10cSrcweir 592cdf0e10cSrcweir //This part is not guarded against other threads removing, adding, disabling ... 593cdf0e10cSrcweir //etc. the same extension. 594cdf0e10cSrcweir //checkInstall is safe because it notifies the user if the extension is not yet 595cdf0e10cSrcweir //installed in the same repository. Because addExtension has its own guard 596cdf0e10cSrcweir //(m_addMutex), another thread cannot add the extension in the meantime. 597cdf0e10cSrcweir //checkUpdate is called if the same extension exists in the same 598cdf0e10cSrcweir //repository. The user is asked if they want to replace it. Another 599cdf0e10cSrcweir //thread 600cdf0e10cSrcweir //could already remove the extension. So asking the user was not 601cdf0e10cSrcweir //necessary. No harm is done. The other thread may also ask the user 602cdf0e10cSrcweir //if he wants to remove the extension. This depends on the 603cdf0e10cSrcweir //XCommandEnvironment which it passes to removeExtension. 604cdf0e10cSrcweir if (xOldExtension.is()) 605cdf0e10cSrcweir { 606cdf0e10cSrcweir //throws a CommandFailedException if the user cancels 607cdf0e10cSrcweir //the action. 608cdf0e10cSrcweir checkUpdate(sVersion, sDisplayName,xOldExtension, xCmdEnv); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir else 611cdf0e10cSrcweir { 612cdf0e10cSrcweir //throws a CommandFailedException if the user cancels 613cdf0e10cSrcweir //the action. 614cdf0e10cSrcweir checkInstall(sDisplayName, xCmdEnv); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir //Prevent showing the license if requested. 617cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> _xCmdEnv(xCmdEnv); 618cdf0e10cSrcweir ExtensionProperties props(OUString(), properties, Reference<ucb::XCommandEnvironment>()); 619cdf0e10cSrcweir 620cdf0e10cSrcweir dp_misc::DescriptionInfoset info(dp_misc::getDescriptionInfoset(xTmpExtension->getURL())); 621cdf0e10cSrcweir const ::boost::optional<dp_misc::SimpleLicenseAttributes> licenseAttributes = 622cdf0e10cSrcweir info.getSimpleLicenseAttributes(); 623cdf0e10cSrcweir 624cdf0e10cSrcweir if (licenseAttributes && licenseAttributes->suppressIfRequired 625cdf0e10cSrcweir && props.isSuppressedLicense()) 626cdf0e10cSrcweir _xCmdEnv = Reference<ucb::XCommandEnvironment>( 627cdf0e10cSrcweir new NoLicenseCommandEnv(xCmdEnv->getInteractionHandler())); 628cdf0e10cSrcweir 629cdf0e10cSrcweir bCanInstall = xTmpExtension->checkPrerequisites( 630cdf0e10cSrcweir xAbortChannel, _xCmdEnv, xOldExtension.is() || props.isExtensionUpdate()) == 0 ? true : false; 631cdf0e10cSrcweir 632cdf0e10cSrcweir return bCanInstall; 633cdf0e10cSrcweir } 634cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 635cdf0e10cSrcweir throw; 636cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 637cdf0e10cSrcweir throw; 638cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 639cdf0e10cSrcweir throw; 640cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 641cdf0e10cSrcweir throw; 642cdf0e10cSrcweir } catch (uno::RuntimeException &) { 643cdf0e10cSrcweir throw; 644cdf0e10cSrcweir } catch (uno::Exception &) { 645cdf0e10cSrcweir uno::Any excOccurred = ::cppu::getCaughtException(); 646cdf0e10cSrcweir deploy::DeploymentException exc( 647cdf0e10cSrcweir OUSTR("Extension Manager: exception in doChecksForAddExtension"), 648cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred); 649cdf0e10cSrcweir throw exc; 650cdf0e10cSrcweir } catch (...) { 651cdf0e10cSrcweir throw uno::RuntimeException( 652cdf0e10cSrcweir OUSTR("Extension Manager: unexpected exception in doChecksForAddExtension"), 653cdf0e10cSrcweir static_cast<OWeakObject*>(this)); 654cdf0e10cSrcweir } 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir // Only add to shared and user repository 658cdf0e10cSrcweir Reference<deploy::XPackage> ExtensionManager::addExtension( 659cdf0e10cSrcweir OUString const & url, uno::Sequence<beans::NamedValue> const & properties, 660cdf0e10cSrcweir OUString const & repository, 661cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 662cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 663cdf0e10cSrcweir throw (deploy::DeploymentException, 664cdf0e10cSrcweir ucb::CommandFailedException, 665cdf0e10cSrcweir ucb::CommandAbortedException, 666cdf0e10cSrcweir lang::IllegalArgumentException, 667cdf0e10cSrcweir uno::RuntimeException) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir Reference<deploy::XPackage> xNewExtension; 670cdf0e10cSrcweir //Determine the repository to use 671cdf0e10cSrcweir Reference<deploy::XPackageManager> xPackageManager; 672cdf0e10cSrcweir if (repository.equals(OUSTR("user"))) 673cdf0e10cSrcweir xPackageManager = getUserRepository(); 674cdf0e10cSrcweir else if (repository.equals(OUSTR("shared"))) 675cdf0e10cSrcweir xPackageManager = getSharedRepository(); 676cdf0e10cSrcweir else 677cdf0e10cSrcweir throw lang::IllegalArgumentException( 678cdf0e10cSrcweir OUSTR("No valid repository name provided."), 679cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 0); 680cdf0e10cSrcweir //We must make sure that the xTmpExtension is not create twice, because this 681cdf0e10cSrcweir //would remove the first one. 682cdf0e10cSrcweir ::osl::MutexGuard addGuard(m_addMutex); 683cdf0e10cSrcweir 684cdf0e10cSrcweir Reference<deploy::XPackage> xTmpExtension = 685cdf0e10cSrcweir getTempExtension(url, xAbortChannel, xCmdEnv); 686cdf0e10cSrcweir //Make sure the extension is removed from the tmp repository in case 687cdf0e10cSrcweir //of an exception 688cdf0e10cSrcweir ExtensionRemoveGuard tmpExtensionRemoveGuard(xTmpExtension, getTmpRepository()); 689*7bc7b19fSMichael Stahl ExtensionRemoveGuard bakExtensionRemoveGuard; 690cdf0e10cSrcweir const OUString sIdentifier = dp_misc::getIdentifier(xTmpExtension); 691cdf0e10cSrcweir const OUString sFileName = xTmpExtension->getName(); 692cdf0e10cSrcweir Reference<deploy::XPackage> xOldExtension; 693cdf0e10cSrcweir Reference<deploy::XPackage> xExtensionBackup; 694cdf0e10cSrcweir 695cdf0e10cSrcweir uno::Any excOccurred2; 696cdf0e10cSrcweir bool bUserDisabled = false; 697cdf0e10cSrcweir bool bCanInstall = doChecksForAddExtension( 698cdf0e10cSrcweir xPackageManager, 699cdf0e10cSrcweir properties, 700cdf0e10cSrcweir xTmpExtension, 701cdf0e10cSrcweir xAbortChannel, 702cdf0e10cSrcweir xCmdEnv, 703cdf0e10cSrcweir xOldExtension ); 704cdf0e10cSrcweir 705cdf0e10cSrcweir { 706cdf0e10cSrcweir // In this garded section (getMutex) we must not use the argument xCmdEnv 707cdf0e10cSrcweir // because it may bring up dialogs (XInteractionHandler::handle) this 708cdf0e10cSrcweir //may potententially deadlock. See issue 709cdf0e10cSrcweir //http://qa.openoffice.org/issues/show_bug.cgi?id=114933 710cdf0e10cSrcweir //By not providing xCmdEnv the underlying APIs will throw an exception if 711cdf0e10cSrcweir //the XInteractionRequest cannot be handled 712cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 713cdf0e10cSrcweir 714cdf0e10cSrcweir if (bCanInstall) 715cdf0e10cSrcweir { 716cdf0e10cSrcweir try 717cdf0e10cSrcweir { 718cdf0e10cSrcweir bUserDisabled = isUserDisabled(sIdentifier, sFileName); 719cdf0e10cSrcweir if (xOldExtension.is()) 720cdf0e10cSrcweir { 721cdf0e10cSrcweir try 722cdf0e10cSrcweir { 723cdf0e10cSrcweir xOldExtension->revokePackage( 724cdf0e10cSrcweir xAbortChannel, Reference<ucb::XCommandEnvironment>()); 725cdf0e10cSrcweir //save the old user extension in case the user aborts 726*7bc7b19fSMichael Stahl xExtensionBackup = getBakRepository()->importExtension( 727cdf0e10cSrcweir xOldExtension, Reference<task::XAbortChannel>(), 728cdf0e10cSrcweir Reference<ucb::XCommandEnvironment>()); 729*7bc7b19fSMichael Stahl bakExtensionRemoveGuard.set(xExtensionBackup, getBakRepository()); 730cdf0e10cSrcweir } 731cdf0e10cSrcweir catch (lang::DisposedException &) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir //Another thread might have removed the extension meanwhile 734cdf0e10cSrcweir } 735cdf0e10cSrcweir } 736cdf0e10cSrcweir //check again dependencies but prevent user interaction, 737cdf0e10cSrcweir //We can disregard the license, because the user must have already 738cdf0e10cSrcweir //accepted it, whe we called checkPrerequisites the first time 739cdf0e10cSrcweir SilentCheckPrerequisitesCommandEnv * pSilentCommandEnv = 740cdf0e10cSrcweir new SilentCheckPrerequisitesCommandEnv(); 741cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> silentCommandEnv(pSilentCommandEnv); 742cdf0e10cSrcweir 743cdf0e10cSrcweir sal_Int32 failedPrereq = xTmpExtension->checkPrerequisites( 744cdf0e10cSrcweir xAbortChannel, silentCommandEnv, true); 745cdf0e10cSrcweir if (failedPrereq == 0) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir xNewExtension = xPackageManager->addPackage( 748cdf0e10cSrcweir url, properties, OUString(), xAbortChannel, 749cdf0e10cSrcweir Reference<ucb::XCommandEnvironment>()); 750cdf0e10cSrcweir //If we add a user extension and there is already one which was 751cdf0e10cSrcweir //disabled by a user, then the newly installed one is enabled. If we 752cdf0e10cSrcweir //add to another repository then the user extension remains 753cdf0e10cSrcweir //disabled. 754cdf0e10cSrcweir bool bUserDisabled2 = bUserDisabled; 755cdf0e10cSrcweir if (repository.equals(OUSTR("user"))) 756cdf0e10cSrcweir bUserDisabled2 = false; 757cdf0e10cSrcweir 758cdf0e10cSrcweir ::rtl::OUString const name(xNewExtension->getName()); 759cdf0e10cSrcweir activateExtension( 760cdf0e10cSrcweir dp_misc::getIdentifier(xNewExtension), 761cdf0e10cSrcweir name, bUserDisabled2, false, xAbortChannel, 762cdf0e10cSrcweir Reference<ucb::XCommandEnvironment>()); 763cdf0e10cSrcweir } 764cdf0e10cSrcweir else 765cdf0e10cSrcweir { 766cdf0e10cSrcweir if (pSilentCommandEnv->m_Exception.hasValue()) 767cdf0e10cSrcweir ::cppu::throwException(pSilentCommandEnv->m_Exception); 768cdf0e10cSrcweir else if ( pSilentCommandEnv->m_UnknownException.hasValue()) 769cdf0e10cSrcweir ::cppu::throwException(pSilentCommandEnv->m_UnknownException); 770cdf0e10cSrcweir else 771cdf0e10cSrcweir throw deploy::DeploymentException ( 772cdf0e10cSrcweir OUSTR("Extension Manager: exception during addExtension, ckeckPrerequisites failed"), 773cdf0e10cSrcweir static_cast<OWeakObject*>(this), uno::Any()); 774cdf0e10cSrcweir } 775cdf0e10cSrcweir } 776cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 777cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 778cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 779cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 780cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 781cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 782cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 783cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 784cdf0e10cSrcweir } catch (uno::RuntimeException &) { 785cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 786cdf0e10cSrcweir } catch (...) { 787cdf0e10cSrcweir excOccurred2 = ::cppu::getCaughtException(); 788cdf0e10cSrcweir deploy::DeploymentException exc( 789cdf0e10cSrcweir OUSTR("Extension Manager: exception during addExtension, url: ") 790cdf0e10cSrcweir + url, static_cast<OWeakObject*>(this), excOccurred2); 791cdf0e10cSrcweir excOccurred2 <<= exc; 792cdf0e10cSrcweir } 793cdf0e10cSrcweir } 794cdf0e10cSrcweir 795cdf0e10cSrcweir if (excOccurred2.hasValue()) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir //It does not matter what exception is thrown. We try to 798cdf0e10cSrcweir //recover the original status. 799cdf0e10cSrcweir //If the user aborted installation then a ucb::CommandAbortedException 800cdf0e10cSrcweir //is thrown. 801cdf0e10cSrcweir //Use a private AbortChannel so the user cannot interrupt. 802cdf0e10cSrcweir try 803cdf0e10cSrcweir { 804cdf0e10cSrcweir if (xExtensionBackup.is()) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir Reference<deploy::XPackage> xRestored = 807cdf0e10cSrcweir xPackageManager->importExtension( 808cdf0e10cSrcweir xExtensionBackup, Reference<task::XAbortChannel>(), 809cdf0e10cSrcweir Reference<ucb::XCommandEnvironment>()); 810cdf0e10cSrcweir } 811cdf0e10cSrcweir activateExtension( 812cdf0e10cSrcweir sIdentifier, sFileName, bUserDisabled, false, 813cdf0e10cSrcweir Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>()); 814cdf0e10cSrcweir } 815cdf0e10cSrcweir catch (...) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir } 818cdf0e10cSrcweir ::cppu::throwException(excOccurred2); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } // leaving the garded section (getMutex()) 821cdf0e10cSrcweir 822cdf0e10cSrcweir try 823cdf0e10cSrcweir { 824cdf0e10cSrcweir fireModified(); 825cdf0e10cSrcweir 826cdf0e10cSrcweir }catch (deploy::DeploymentException& ) { 827cdf0e10cSrcweir throw; 828cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 829cdf0e10cSrcweir throw; 830cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 831cdf0e10cSrcweir throw; 832cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 833cdf0e10cSrcweir throw; 834cdf0e10cSrcweir } catch (uno::RuntimeException &) { 835cdf0e10cSrcweir throw; 836cdf0e10cSrcweir } catch (uno::Exception &) { 837cdf0e10cSrcweir uno::Any excOccurred = ::cppu::getCaughtException(); 838cdf0e10cSrcweir deploy::DeploymentException exc( 839cdf0e10cSrcweir OUSTR("Extension Manager: exception in doChecksForAddExtension"), 840cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred); 841cdf0e10cSrcweir throw exc; 842cdf0e10cSrcweir } catch (...) { 843cdf0e10cSrcweir throw uno::RuntimeException( 844cdf0e10cSrcweir OUSTR("Extension Manager: unexpected exception in doChecksForAddExtension"), 845cdf0e10cSrcweir static_cast<OWeakObject*>(this)); 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir return xNewExtension; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir 851cdf0e10cSrcweir void ExtensionManager::removeExtension( 852cdf0e10cSrcweir OUString const & identifier, OUString const & fileName, 853cdf0e10cSrcweir OUString const & repository, 854cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 855cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 856cdf0e10cSrcweir throw (deploy::DeploymentException, 857cdf0e10cSrcweir ucb::CommandFailedException, 858cdf0e10cSrcweir ucb::CommandAbortedException, 859cdf0e10cSrcweir lang::IllegalArgumentException, 860cdf0e10cSrcweir uno::RuntimeException) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir uno::Any excOccurred1; 863cdf0e10cSrcweir Reference<deploy::XPackage> xExtensionBackup; 864cdf0e10cSrcweir Reference<deploy::XPackageManager> xPackageManager; 865cdf0e10cSrcweir bool bUserDisabled = false; 866cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 867cdf0e10cSrcweir try 868cdf0e10cSrcweir { 869cdf0e10cSrcweir //Determine the repository to use 870cdf0e10cSrcweir if (repository.equals(OUSTR("user"))) 871cdf0e10cSrcweir xPackageManager = getUserRepository(); 872cdf0e10cSrcweir else if (repository.equals(OUSTR("shared"))) 873cdf0e10cSrcweir xPackageManager = getSharedRepository(); 874cdf0e10cSrcweir else 875cdf0e10cSrcweir throw lang::IllegalArgumentException( 876cdf0e10cSrcweir OUSTR("No valid repository name provided."), 877cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 0); 878cdf0e10cSrcweir 879cdf0e10cSrcweir bUserDisabled = isUserDisabled(identifier, fileName); 880cdf0e10cSrcweir //Backup the extension, in case the user cancels the action 881cdf0e10cSrcweir xExtensionBackup = backupExtension( 882cdf0e10cSrcweir identifier, fileName, xPackageManager, xCmdEnv); 883cdf0e10cSrcweir 884cdf0e10cSrcweir //revoke the extension if it is active 885cdf0e10cSrcweir Reference<deploy::XPackage> xOldExtension = 886cdf0e10cSrcweir xPackageManager->getDeployedPackage( 887cdf0e10cSrcweir identifier, fileName, xCmdEnv); 888cdf0e10cSrcweir xOldExtension->revokePackage(xAbortChannel, xCmdEnv); 889cdf0e10cSrcweir 890cdf0e10cSrcweir xPackageManager->removePackage( 891cdf0e10cSrcweir identifier, fileName, xAbortChannel, xCmdEnv); 892cdf0e10cSrcweir activateExtension(identifier, fileName, bUserDisabled, false, 893cdf0e10cSrcweir xAbortChannel, xCmdEnv); 894cdf0e10cSrcweir fireModified(); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 897cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 898cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 899cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 900cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 901cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 902cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 903cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 904cdf0e10cSrcweir } catch (uno::RuntimeException &) { 905cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 906cdf0e10cSrcweir } catch (...) { 907cdf0e10cSrcweir excOccurred1 = ::cppu::getCaughtException(); 908cdf0e10cSrcweir deploy::DeploymentException exc( 909cdf0e10cSrcweir OUSTR("Extension Manager: exception during removeEtension"), 910cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred1); 911cdf0e10cSrcweir excOccurred1 <<= exc; 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir if (excOccurred1.hasValue()) 915cdf0e10cSrcweir { 916cdf0e10cSrcweir //User aborted installation, restore the previous situation. 917cdf0e10cSrcweir //Use a private AbortChannel so the user cannot interrupt. 918cdf0e10cSrcweir try 919cdf0e10cSrcweir { 920cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> tmpCmdEnv( 921cdf0e10cSrcweir new TmpRepositoryCommandEnv(xCmdEnv->getInteractionHandler())); 922cdf0e10cSrcweir if (xExtensionBackup.is()) 923cdf0e10cSrcweir { 924cdf0e10cSrcweir Reference<deploy::XPackage> xRestored = 925cdf0e10cSrcweir xPackageManager->importExtension( 926cdf0e10cSrcweir xExtensionBackup, Reference<task::XAbortChannel>(), 927cdf0e10cSrcweir tmpCmdEnv); 928cdf0e10cSrcweir activateExtension( 929cdf0e10cSrcweir identifier, fileName, bUserDisabled, false, 930cdf0e10cSrcweir Reference<task::XAbortChannel>(), 931cdf0e10cSrcweir tmpCmdEnv); 932cdf0e10cSrcweir 933cdf0e10cSrcweir getTmpRepository()->removePackage( 934cdf0e10cSrcweir dp_misc::getIdentifier(xExtensionBackup), 935cdf0e10cSrcweir xExtensionBackup->getName(), xAbortChannel, xCmdEnv); 936cdf0e10cSrcweir fireModified(); 937cdf0e10cSrcweir } 938cdf0e10cSrcweir } 939cdf0e10cSrcweir catch (...) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir } 942cdf0e10cSrcweir ::cppu::throwException(excOccurred1); 943cdf0e10cSrcweir } 944cdf0e10cSrcweir 945cdf0e10cSrcweir if (xExtensionBackup.is()) 946cdf0e10cSrcweir getTmpRepository()->removePackage( 947cdf0e10cSrcweir dp_misc::getIdentifier(xExtensionBackup), 948cdf0e10cSrcweir xExtensionBackup->getName(), xAbortChannel, xCmdEnv); 949cdf0e10cSrcweir } 950cdf0e10cSrcweir 951cdf0e10cSrcweir // Only enable extensions from shared and user repository 952cdf0e10cSrcweir void ExtensionManager::enableExtension( 953cdf0e10cSrcweir Reference<deploy::XPackage> const & extension, 954cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 955cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv) 956cdf0e10cSrcweir throw (deploy::DeploymentException, 957cdf0e10cSrcweir ucb::CommandFailedException, 958cdf0e10cSrcweir ucb::CommandAbortedException, 959cdf0e10cSrcweir lang::IllegalArgumentException, 960cdf0e10cSrcweir uno::RuntimeException) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 963cdf0e10cSrcweir bool bUserDisabled = false; 964cdf0e10cSrcweir uno::Any excOccurred; 965cdf0e10cSrcweir try 966cdf0e10cSrcweir { 967cdf0e10cSrcweir if (!extension.is()) 968cdf0e10cSrcweir return; 969cdf0e10cSrcweir OUString repository = extension->getRepositoryName(); 970cdf0e10cSrcweir if (!repository.equals(OUSTR("user"))) 971cdf0e10cSrcweir throw lang::IllegalArgumentException( 972cdf0e10cSrcweir OUSTR("No valid repository name provided."), 973cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 0); 974cdf0e10cSrcweir 975cdf0e10cSrcweir bUserDisabled = isUserDisabled(dp_misc::getIdentifier(extension), 976cdf0e10cSrcweir extension->getName()); 977cdf0e10cSrcweir 978cdf0e10cSrcweir activateExtension(dp_misc::getIdentifier(extension), 979cdf0e10cSrcweir extension->getName(), false, false, 980cdf0e10cSrcweir xAbortChannel, xCmdEnv); 981cdf0e10cSrcweir } 982cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 983cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 984cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 985cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 986cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 987cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 988cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 989cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 990cdf0e10cSrcweir } catch (uno::RuntimeException &) { 991cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 992cdf0e10cSrcweir } catch (...) { 993cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 994cdf0e10cSrcweir deploy::DeploymentException exc( 995cdf0e10cSrcweir OUSTR("Extension Manager: exception during enableExtension"), 996cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred); 997cdf0e10cSrcweir excOccurred <<= exc; 998cdf0e10cSrcweir } 999cdf0e10cSrcweir 1000cdf0e10cSrcweir if (excOccurred.hasValue()) 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir try 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir activateExtension(dp_misc::getIdentifier(extension), 1005cdf0e10cSrcweir extension->getName(), bUserDisabled, false, 1006cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1007cdf0e10cSrcweir } 1008cdf0e10cSrcweir catch (...) 1009cdf0e10cSrcweir { 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir ::cppu::throwException(excOccurred); 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir } 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir /** 1016cdf0e10cSrcweir */ 1017cdf0e10cSrcweir sal_Int32 ExtensionManager::checkPrerequisitesAndEnable( 1018cdf0e10cSrcweir Reference<deploy::XPackage> const & extension, 1019cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1020cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv) 1021cdf0e10cSrcweir throw (deploy::DeploymentException, 1022cdf0e10cSrcweir ucb::CommandFailedException, 1023cdf0e10cSrcweir ucb::CommandAbortedException, 1024cdf0e10cSrcweir lang::IllegalArgumentException, 1025cdf0e10cSrcweir uno::RuntimeException) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir try 1028cdf0e10cSrcweir { 1029cdf0e10cSrcweir if (!extension.is()) 1030cdf0e10cSrcweir return 0; 1031cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 1032cdf0e10cSrcweir sal_Int32 ret = 0; 1033cdf0e10cSrcweir Reference<deploy::XPackageManager> mgr = 1034cdf0e10cSrcweir getPackageManager(extension->getRepositoryName()); 1035cdf0e10cSrcweir ret = mgr->checkPrerequisites(extension, xAbortChannel, xCmdEnv); 1036cdf0e10cSrcweir if (ret) 1037cdf0e10cSrcweir { 1038cdf0e10cSrcweir //There are some unfulfilled prerequisites, try to revoke 1039cdf0e10cSrcweir extension->revokePackage(xAbortChannel, xCmdEnv); 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir const OUString id(dp_misc::getIdentifier(extension)); 1042cdf0e10cSrcweir activateExtension(id, extension->getName(), 1043cdf0e10cSrcweir isUserDisabled(id, extension->getName()), false, 1044cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1045cdf0e10cSrcweir return ret; 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 1048cdf0e10cSrcweir throw; 1049cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1050cdf0e10cSrcweir throw; 1051cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1052cdf0e10cSrcweir throw; 1053cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1054cdf0e10cSrcweir throw; 1055cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1056cdf0e10cSrcweir throw; 1057cdf0e10cSrcweir } catch (...) { 1058cdf0e10cSrcweir uno::Any excOccurred = ::cppu::getCaughtException(); 1059cdf0e10cSrcweir deploy::DeploymentException exc( 1060cdf0e10cSrcweir OUSTR("Extension Manager: exception during disableExtension"), 1061cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred); 1062cdf0e10cSrcweir throw exc; 1063cdf0e10cSrcweir } 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir void ExtensionManager::disableExtension( 1068cdf0e10cSrcweir Reference<deploy::XPackage> const & extension, 1069cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1070cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1071cdf0e10cSrcweir throw (deploy::DeploymentException, 1072cdf0e10cSrcweir ucb::CommandFailedException, 1073cdf0e10cSrcweir ucb::CommandAbortedException, 1074cdf0e10cSrcweir lang::IllegalArgumentException, 1075cdf0e10cSrcweir uno::RuntimeException) 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 1078cdf0e10cSrcweir uno::Any excOccurred; 1079cdf0e10cSrcweir bool bUserDisabled = false; 1080cdf0e10cSrcweir try 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir if (!extension.is()) 1083cdf0e10cSrcweir return; 1084cdf0e10cSrcweir const OUString repository( extension->getRepositoryName()); 1085cdf0e10cSrcweir if (!repository.equals(OUSTR("user"))) 1086cdf0e10cSrcweir throw lang::IllegalArgumentException( 1087cdf0e10cSrcweir OUSTR("No valid repository name provided."), 1088cdf0e10cSrcweir static_cast<cppu::OWeakObject*>(this), 0); 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir const OUString id(dp_misc::getIdentifier(extension)); 1091cdf0e10cSrcweir bUserDisabled = isUserDisabled(id, extension->getName()); 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir activateExtension(id, extension->getName(), true, false, 1094cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir catch (deploy::DeploymentException& ) { 1097cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1098cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1099cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1100cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1101cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1102cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1103cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1104cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1105cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1106cdf0e10cSrcweir } catch (...) { 1107cdf0e10cSrcweir excOccurred = ::cppu::getCaughtException(); 1108cdf0e10cSrcweir deploy::DeploymentException exc( 1109cdf0e10cSrcweir OUSTR("Extension Manager: exception during disableExtension"), 1110cdf0e10cSrcweir static_cast<OWeakObject*>(this), excOccurred); 1111cdf0e10cSrcweir excOccurred <<= exc; 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir if (excOccurred.hasValue()) 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir try 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir activateExtension(dp_misc::getIdentifier(extension), 1119cdf0e10cSrcweir extension->getName(), bUserDisabled, false, 1120cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1121cdf0e10cSrcweir } 1122cdf0e10cSrcweir catch (...) 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir ::cppu::throwException(excOccurred); 1126cdf0e10cSrcweir } 1127cdf0e10cSrcweir } 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir uno::Sequence< Reference<deploy::XPackage> > 1130cdf0e10cSrcweir ExtensionManager::getDeployedExtensions( 1131cdf0e10cSrcweir OUString const & repository, 1132cdf0e10cSrcweir Reference<task::XAbortChannel> const &xAbort, 1133cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1134cdf0e10cSrcweir throw (deploy::DeploymentException, 1135cdf0e10cSrcweir ucb::CommandFailedException, 1136cdf0e10cSrcweir ucb::CommandAbortedException, 1137cdf0e10cSrcweir lang::IllegalArgumentException, 1138cdf0e10cSrcweir uno::RuntimeException) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir return getPackageManager(repository)->getDeployedPackages( 1141cdf0e10cSrcweir xAbort, xCmdEnv); 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir Reference<deploy::XPackage> 1145cdf0e10cSrcweir ExtensionManager::getDeployedExtension( 1146cdf0e10cSrcweir OUString const & repository, 1147cdf0e10cSrcweir OUString const & identifier, 1148cdf0e10cSrcweir OUString const & filename, 1149cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1150cdf0e10cSrcweir throw (deploy::DeploymentException, 1151cdf0e10cSrcweir ucb::CommandFailedException, 1152cdf0e10cSrcweir lang::IllegalArgumentException, 1153cdf0e10cSrcweir uno::RuntimeException) 1154cdf0e10cSrcweir { 1155cdf0e10cSrcweir return getPackageManager(repository)->getDeployedPackage( 1156cdf0e10cSrcweir identifier, filename, xCmdEnv); 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir uno::Sequence< uno::Sequence<Reference<deploy::XPackage> > > 1160cdf0e10cSrcweir ExtensionManager::getAllExtensions( 1161cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbort, 1162cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1163cdf0e10cSrcweir throw (deploy::DeploymentException, 1164cdf0e10cSrcweir ucb::CommandFailedException, 1165cdf0e10cSrcweir ucb::CommandAbortedException, 1166cdf0e10cSrcweir lang::IllegalArgumentException, 1167cdf0e10cSrcweir uno::RuntimeException) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir try 1170cdf0e10cSrcweir { 1171cdf0e10cSrcweir id2extensions mapExt; 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > userExt = 1174cdf0e10cSrcweir getUserRepository()->getDeployedPackages(xAbort, xCmdEnv); 1175cdf0e10cSrcweir addExtensionsToMap(mapExt, userExt, OUSTR("user")); 1176cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > sharedExt = 1177cdf0e10cSrcweir getSharedRepository()->getDeployedPackages(xAbort, xCmdEnv); 1178cdf0e10cSrcweir addExtensionsToMap(mapExt, sharedExt, OUSTR("shared")); 1179cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > bundledExt = 1180cdf0e10cSrcweir getBundledRepository()->getDeployedPackages(xAbort, xCmdEnv); 1181cdf0e10cSrcweir addExtensionsToMap(mapExt, bundledExt, OUSTR("bundled")); 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir //copy the values of the map to a vector for sorting 1184cdf0e10cSrcweir ::std::vector< ::std::vector<Reference<deploy::XPackage> > > 1185cdf0e10cSrcweir vecExtensions; 1186cdf0e10cSrcweir id2extensions::const_iterator mapIt = mapExt.begin(); 1187cdf0e10cSrcweir for (;mapIt != mapExt.end(); mapIt++) 1188cdf0e10cSrcweir vecExtensions.push_back(mapIt->second); 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir //sort the element according to the identifier 1191cdf0e10cSrcweir ::std::sort(vecExtensions.begin(), vecExtensions.end(), CompIdentifiers()); 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir ::std::vector< ::std::vector<Reference<deploy::XPackage> > >::const_iterator 1194cdf0e10cSrcweir citVecVec = vecExtensions.begin(); 1195cdf0e10cSrcweir sal_Int32 j = 0; 1196cdf0e10cSrcweir uno::Sequence< uno::Sequence<Reference<deploy::XPackage> > > seqSeq(vecExtensions.size()); 1197cdf0e10cSrcweir for (;citVecVec != vecExtensions.end(); citVecVec++, j++) 1198cdf0e10cSrcweir { 1199cdf0e10cSrcweir seqSeq[j] = comphelper::containerToSequence(*citVecVec); 1200cdf0e10cSrcweir } 1201cdf0e10cSrcweir return seqSeq; 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir } catch (deploy::DeploymentException& ) { 1204cdf0e10cSrcweir throw; 1205cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1206cdf0e10cSrcweir throw; 1207cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1208cdf0e10cSrcweir throw; 1209cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1210cdf0e10cSrcweir throw; 1211cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1212cdf0e10cSrcweir throw; 1213cdf0e10cSrcweir } catch (...) { 1214cdf0e10cSrcweir uno::Any exc = ::cppu::getCaughtException(); 1215cdf0e10cSrcweir throw deploy::DeploymentException( 1216cdf0e10cSrcweir OUSTR("Extension Manager: exception during enableExtension"), 1217cdf0e10cSrcweir static_cast<OWeakObject*>(this), exc); 1218cdf0e10cSrcweir } 1219cdf0e10cSrcweir } 1220cdf0e10cSrcweir 1221cdf0e10cSrcweir //only to be called from unopkg!!! 1222cdf0e10cSrcweir void ExtensionManager::reinstallDeployedExtensions( 1223cdf0e10cSrcweir OUString const & repository, 1224cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1225cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1226cdf0e10cSrcweir throw (deploy::DeploymentException, 1227cdf0e10cSrcweir ucb::CommandFailedException, ucb::CommandAbortedException, 1228cdf0e10cSrcweir lang::IllegalArgumentException, uno::RuntimeException) 1229cdf0e10cSrcweir { 1230cdf0e10cSrcweir try 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir Reference<deploy::XPackageManager> 1233cdf0e10cSrcweir xPackageManager = getPackageManager(repository); 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 1236cdf0e10cSrcweir xPackageManager->reinstallDeployedPackages(xAbortChannel, xCmdEnv); 1237cdf0e10cSrcweir //We must sync here, otherwise we will get exceptions when extensions 1238cdf0e10cSrcweir //are removed. 1239cdf0e10cSrcweir dp_misc::syncRepositories(xCmdEnv); 1240cdf0e10cSrcweir const uno::Sequence< Reference<deploy::XPackage> > extensions( 1241cdf0e10cSrcweir xPackageManager->getDeployedPackages(xAbortChannel, xCmdEnv)); 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir for ( sal_Int32 pos = 0; pos < extensions.getLength(); ++pos ) 1244cdf0e10cSrcweir { 1245cdf0e10cSrcweir try 1246cdf0e10cSrcweir { 1247cdf0e10cSrcweir const OUString id = dp_misc::getIdentifier(extensions[ pos ]); 1248cdf0e10cSrcweir const OUString fileName = extensions[ pos ]->getName(); 1249cdf0e10cSrcweir OSL_ASSERT(id.getLength()); 1250cdf0e10cSrcweir activateExtension(id, fileName, false, true, xAbortChannel, xCmdEnv ); 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir catch (lang::DisposedException &) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir } 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir } catch (deploy::DeploymentException& ) { 1257cdf0e10cSrcweir throw; 1258cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1259cdf0e10cSrcweir throw; 1260cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1261cdf0e10cSrcweir throw; 1262cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1263cdf0e10cSrcweir throw; 1264cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1265cdf0e10cSrcweir throw; 1266cdf0e10cSrcweir } catch (...) { 1267cdf0e10cSrcweir uno::Any exc = ::cppu::getCaughtException(); 1268cdf0e10cSrcweir throw deploy::DeploymentException( 1269cdf0e10cSrcweir OUSTR("Extension Manager: exception during enableExtension"), 1270cdf0e10cSrcweir static_cast<OWeakObject*>(this), exc); 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir } 1273cdf0e10cSrcweir 1274cdf0e10cSrcweir /** Works on the bundled repository. That is using the variables 1275cdf0e10cSrcweir BUNDLED_EXTENSIONS and BUNDLED_EXTENSIONS_USER. 1276cdf0e10cSrcweir */ 1277cdf0e10cSrcweir void ExtensionManager::synchronizeBundledPrereg( 1278cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1279cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1280cdf0e10cSrcweir throw (deploy::DeploymentException, 1281cdf0e10cSrcweir uno::RuntimeException) 1282cdf0e10cSrcweir { 1283cdf0e10cSrcweir try 1284cdf0e10cSrcweir { 1285cdf0e10cSrcweir String sSynchronizingBundled(StrSyncRepository::get()); 1286cdf0e10cSrcweir sSynchronizingBundled.SearchAndReplaceAllAscii( "%NAME", OUSTR("bundled")); 1287cdf0e10cSrcweir dp_misc::ProgressLevel progressBundled(xCmdEnv, sSynchronizingBundled); 1288cdf0e10cSrcweir 1289cdf0e10cSrcweir Reference<deploy::XPackageManagerFactory> xPackageManagerFactory( 1290cdf0e10cSrcweir deploy::thePackageManagerFactory::get(m_xContext)); 1291cdf0e10cSrcweir 1292cdf0e10cSrcweir Reference<deploy::XPackageManager> xMgr = 1293cdf0e10cSrcweir xPackageManagerFactory->getPackageManager(OUSTR("bundled_prereg")); 1294cdf0e10cSrcweir xMgr->synchronize(xAbortChannel, xCmdEnv); 1295cdf0e10cSrcweir progressBundled.update(OUSTR("\n\n")); 1296cdf0e10cSrcweir 1297cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > extensions = xMgr->getDeployedPackages( 1298cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1299cdf0e10cSrcweir try 1300cdf0e10cSrcweir { 1301cdf0e10cSrcweir for (sal_Int32 i = 0; i < extensions.getLength(); i++) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir extensions[i]->registerPackage(true, xAbortChannel, xCmdEnv); 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir } 1306cdf0e10cSrcweir catch (...) 1307cdf0e10cSrcweir { 1308cdf0e10cSrcweir OSL_ASSERT(0); 1309cdf0e10cSrcweir } 1310cdf0e10cSrcweir OUString lastSyncBundled(RTL_CONSTASCII_USTRINGPARAM( 1311cdf0e10cSrcweir "$BUNDLED_EXTENSIONS_PREREG/lastsynchronized")); 1312cdf0e10cSrcweir writeLastModified(lastSyncBundled, xCmdEnv); 1313cdf0e10cSrcweir 1314cdf0e10cSrcweir } catch (deploy::DeploymentException& ) { 1315cdf0e10cSrcweir throw; 1316cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1317cdf0e10cSrcweir throw; 1318cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1319cdf0e10cSrcweir throw; 1320cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1321cdf0e10cSrcweir throw; 1322cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1323cdf0e10cSrcweir throw; 1324cdf0e10cSrcweir } catch (...) { 1325cdf0e10cSrcweir uno::Any exc = ::cppu::getCaughtException(); 1326cdf0e10cSrcweir throw deploy::DeploymentException( 1327cdf0e10cSrcweir OUSTR("Extension Manager: exception in synchronize"), 1328cdf0e10cSrcweir static_cast<OWeakObject*>(this), exc); 1329cdf0e10cSrcweir } 1330cdf0e10cSrcweir } 1331cdf0e10cSrcweir 1332cdf0e10cSrcweir sal_Bool ExtensionManager::synchronize( 1333cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1334cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1335cdf0e10cSrcweir throw (deploy::DeploymentException, 1336cdf0e10cSrcweir ucb::CommandFailedException, 1337cdf0e10cSrcweir ucb::CommandAbortedException, 1338cdf0e10cSrcweir lang::IllegalArgumentException, 1339cdf0e10cSrcweir uno::RuntimeException) 1340cdf0e10cSrcweir { 1341cdf0e10cSrcweir try 1342cdf0e10cSrcweir { 1343cdf0e10cSrcweir sal_Bool bModified = sal_False; 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 1346cdf0e10cSrcweir String sSynchronizingShared(StrSyncRepository::get()); 1347cdf0e10cSrcweir sSynchronizingShared.SearchAndReplaceAllAscii( "%NAME", OUSTR("shared")); 1348cdf0e10cSrcweir dp_misc::ProgressLevel progressShared(xCmdEnv, sSynchronizingShared); 1349cdf0e10cSrcweir bModified = getSharedRepository()->synchronize(xAbortChannel, xCmdEnv); 1350cdf0e10cSrcweir progressShared.update(OUSTR("\n\n")); 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir String sSynchronizingBundled(StrSyncRepository::get()); 1353cdf0e10cSrcweir sSynchronizingBundled.SearchAndReplaceAllAscii( "%NAME", OUSTR("bundled")); 1354cdf0e10cSrcweir dp_misc::ProgressLevel progressBundled(xCmdEnv, sSynchronizingBundled); 1355cdf0e10cSrcweir bModified |= getBundledRepository()->synchronize(xAbortChannel, xCmdEnv); 1356cdf0e10cSrcweir progressBundled.update(OUSTR("\n\n")); 1357cdf0e10cSrcweir 1358cdf0e10cSrcweir //Always determine the active extension. This is necessary for the 1359cdf0e10cSrcweir //first-start optimization. The setup creates the registration data for the 1360cdf0e10cSrcweir //bundled extensions (brand_layer/share/prereg/bundled), which is copied to the user 1361cdf0e10cSrcweir //installation (user_installation/extension/bundled) when a user starts OOo 1362cdf0e10cSrcweir //for the first time after running setup. All bundled extensions are registered 1363cdf0e10cSrcweir //at that moment. However, extensions with the same identifier can be in the 1364cdf0e10cSrcweir //shared or user repository, in which case the respective bundled extensions must 1365cdf0e10cSrcweir //be revoked. 1366cdf0e10cSrcweir try 1367cdf0e10cSrcweir { 1368cdf0e10cSrcweir const uno::Sequence<uno::Sequence<Reference<deploy::XPackage> > > 1369cdf0e10cSrcweir seqSeqExt = getAllExtensions(xAbortChannel, xCmdEnv); 1370cdf0e10cSrcweir for (sal_Int32 i = 0; i < seqSeqExt.getLength(); i++) 1371cdf0e10cSrcweir { 1372cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > const & seqExt = 1373cdf0e10cSrcweir seqSeqExt[i]; 1374cdf0e10cSrcweir activateExtension(seqExt, isUserDisabled(seqExt), true, 1375cdf0e10cSrcweir xAbortChannel, xCmdEnv); 1376cdf0e10cSrcweir } 1377cdf0e10cSrcweir } 1378cdf0e10cSrcweir catch (...) 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir //We catch the exception, so we can write the lastmodified file 1381cdf0e10cSrcweir //so we will no repeat this everytime OOo starts. 1382cdf0e10cSrcweir OSL_ENSURE(0, "Extensions Manager: synchronize"); 1383cdf0e10cSrcweir } 1384cdf0e10cSrcweir OUString lastSyncBundled(RTL_CONSTASCII_USTRINGPARAM( 1385cdf0e10cSrcweir "$BUNDLED_EXTENSIONS_USER/lastsynchronized")); 1386cdf0e10cSrcweir writeLastModified(lastSyncBundled, xCmdEnv); 1387cdf0e10cSrcweir OUString lastSyncShared(RTL_CONSTASCII_USTRINGPARAM( 1388cdf0e10cSrcweir "$SHARED_EXTENSIONS_USER/lastsynchronized")); 1389cdf0e10cSrcweir writeLastModified(lastSyncShared, xCmdEnv); 1390cdf0e10cSrcweir return bModified; 1391cdf0e10cSrcweir } catch (deploy::DeploymentException& ) { 1392cdf0e10cSrcweir throw; 1393cdf0e10cSrcweir } catch (ucb::CommandFailedException & ) { 1394cdf0e10cSrcweir throw; 1395cdf0e10cSrcweir } catch (ucb::CommandAbortedException & ) { 1396cdf0e10cSrcweir throw; 1397cdf0e10cSrcweir } catch (lang::IllegalArgumentException &) { 1398cdf0e10cSrcweir throw; 1399cdf0e10cSrcweir } catch (uno::RuntimeException &) { 1400cdf0e10cSrcweir throw; 1401cdf0e10cSrcweir } catch (...) { 1402cdf0e10cSrcweir uno::Any exc = ::cppu::getCaughtException(); 1403cdf0e10cSrcweir throw deploy::DeploymentException( 1404cdf0e10cSrcweir OUSTR("Extension Manager: exception in synchronize"), 1405cdf0e10cSrcweir static_cast<OWeakObject*>(this), exc); 1406cdf0e10cSrcweir } 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir 1409cdf0e10cSrcweir // Notify the user when a new extension is to be installed. This is only the 1410cdf0e10cSrcweir // case when one uses the system integration to install an extension (double 1411cdf0e10cSrcweir // clicking on .oxt file etc.)). The function must only be called if there is no 1412cdf0e10cSrcweir // extension with the same identifier already deployed. Then the checkUpdate 1413cdf0e10cSrcweir // function will inform the user that the extension is about to be installed In 1414cdf0e10cSrcweir // case the user cancels the installation a CommandFailed exception is 1415cdf0e10cSrcweir // thrown. 1416cdf0e10cSrcweir void ExtensionManager::checkInstall( 1417cdf0e10cSrcweir OUString const & displayName, 1418cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & cmdEnv) 1419cdf0e10cSrcweir { 1420cdf0e10cSrcweir uno::Any request( 1421cdf0e10cSrcweir deploy::InstallException( 1422cdf0e10cSrcweir OUSTR("Extension ") + displayName + 1423cdf0e10cSrcweir OUSTR(" is about to be installed."), 1424cdf0e10cSrcweir static_cast<OWeakObject *>(this), displayName)); 1425cdf0e10cSrcweir bool approve = false, abort = false; 1426cdf0e10cSrcweir if (! dp_misc::interactContinuation( 1427cdf0e10cSrcweir request, task::XInteractionApprove::static_type(), 1428cdf0e10cSrcweir cmdEnv, &approve, &abort )) 1429cdf0e10cSrcweir { 1430cdf0e10cSrcweir OSL_ASSERT( !approve && !abort ); 1431cdf0e10cSrcweir throw deploy::DeploymentException( 1432cdf0e10cSrcweir dp_misc::getResourceString(RID_STR_ERROR_WHILE_ADDING) + displayName, 1433cdf0e10cSrcweir static_cast<OWeakObject *>(this), request ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir if (abort || !approve) 1436cdf0e10cSrcweir throw ucb::CommandFailedException( 1437cdf0e10cSrcweir dp_misc::getResourceString(RID_STR_ERROR_WHILE_ADDING) + displayName, 1438cdf0e10cSrcweir static_cast<OWeakObject *>(this), request ); 1439cdf0e10cSrcweir } 1440cdf0e10cSrcweir 1441cdf0e10cSrcweir /* The function will make the user interaction in case there is an extension 1442cdf0e10cSrcweir installed with the same id. This function may only be called if there is already 1443cdf0e10cSrcweir an extension. 1444cdf0e10cSrcweir */ 1445cdf0e10cSrcweir void ExtensionManager::checkUpdate( 1446cdf0e10cSrcweir OUString const & newVersion, 1447cdf0e10cSrcweir OUString const & newDisplayName, 1448cdf0e10cSrcweir Reference<deploy::XPackage> const & oldExtension, 1449cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv ) 1450cdf0e10cSrcweir { 1451cdf0e10cSrcweir // package already deployed, interact --force: 1452cdf0e10cSrcweir uno::Any request( 1453cdf0e10cSrcweir (deploy::VersionException( 1454cdf0e10cSrcweir dp_misc::getResourceString( 1455cdf0e10cSrcweir RID_STR_PACKAGE_ALREADY_ADDED ) + newDisplayName, 1456cdf0e10cSrcweir static_cast<OWeakObject *>(this), newVersion, newDisplayName, 1457cdf0e10cSrcweir oldExtension ) ) ); 1458cdf0e10cSrcweir bool replace = false, abort = false; 1459cdf0e10cSrcweir if (! dp_misc::interactContinuation( 1460cdf0e10cSrcweir request, task::XInteractionApprove::static_type(), 1461cdf0e10cSrcweir xCmdEnv, &replace, &abort )) { 1462cdf0e10cSrcweir OSL_ASSERT( !replace && !abort ); 1463cdf0e10cSrcweir throw deploy::DeploymentException( 1464cdf0e10cSrcweir dp_misc::getResourceString( 1465cdf0e10cSrcweir RID_STR_ERROR_WHILE_ADDING) + newDisplayName, 1466cdf0e10cSrcweir static_cast<OWeakObject *>(this), request ); 1467cdf0e10cSrcweir } 1468cdf0e10cSrcweir if (abort || !replace) 1469cdf0e10cSrcweir throw ucb::CommandFailedException( 1470cdf0e10cSrcweir dp_misc::getResourceString( 1471cdf0e10cSrcweir RID_STR_PACKAGE_ALREADY_ADDED) + newDisplayName, 1472cdf0e10cSrcweir static_cast<OWeakObject *>(this), request ); 1473cdf0e10cSrcweir } 1474cdf0e10cSrcweir 1475cdf0e10cSrcweir Reference<deploy::XPackage> ExtensionManager::getTempExtension( 1476cdf0e10cSrcweir OUString const & url, 1477cdf0e10cSrcweir Reference<task::XAbortChannel> const & xAbortChannel, 1478cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & /*xCmdEnv*/) 1479cdf0e10cSrcweir 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> tmpCmdEnvA(new TmpRepositoryCommandEnv()); 1482cdf0e10cSrcweir Reference<deploy::XPackage> xTmpPackage = getTmpRepository()->addPackage( 1483cdf0e10cSrcweir url, uno::Sequence<beans::NamedValue>(),OUString(), xAbortChannel, tmpCmdEnvA); 1484cdf0e10cSrcweir if (!xTmpPackage.is()) 1485cdf0e10cSrcweir { 1486cdf0e10cSrcweir throw deploy::DeploymentException( 1487cdf0e10cSrcweir OUSTR("Extension Manager: Failed to create temporary XPackage for url: ") + url, 1488cdf0e10cSrcweir static_cast<OWeakObject*>(this), uno::Any()); 1489cdf0e10cSrcweir 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir return xTmpPackage; 1492cdf0e10cSrcweir } 1493cdf0e10cSrcweir 1494cdf0e10cSrcweir uno::Sequence<Reference<deploy::XPackage> > SAL_CALL 1495cdf0e10cSrcweir ExtensionManager::getExtensionsWithUnacceptedLicenses( 1496cdf0e10cSrcweir OUString const & repository, 1497cdf0e10cSrcweir Reference<ucb::XCommandEnvironment> const & xCmdEnv) 1498cdf0e10cSrcweir throw (deploy::DeploymentException, 1499cdf0e10cSrcweir uno::RuntimeException) 1500cdf0e10cSrcweir { 1501cdf0e10cSrcweir Reference<deploy::XPackageManager> 1502cdf0e10cSrcweir xPackageManager = getPackageManager(repository); 1503cdf0e10cSrcweir ::osl::MutexGuard guard(getMutex()); 1504cdf0e10cSrcweir return xPackageManager->getExtensionsWithUnacceptedLicenses(xCmdEnv); 1505cdf0e10cSrcweir } 1506cdf0e10cSrcweir 1507cdf0e10cSrcweir sal_Bool ExtensionManager::isReadOnlyRepository(::rtl::OUString const & repository) 1508cdf0e10cSrcweir throw (uno::RuntimeException) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir return getPackageManager(repository)->isReadOnly(); 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir //------------------------------------------------------------------------------ 1513cdf0e10cSrcweir //------------------------------------------------------------------------------ 1514cdf0e10cSrcweir //------------------------------------------------------------------------------ 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir namespace sdecl = comphelper::service_decl; 1517cdf0e10cSrcweir sdecl::class_<ExtensionManager> servicePIP; 1518cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl( 1519cdf0e10cSrcweir servicePIP, 1520cdf0e10cSrcweir // a private one: 1521cdf0e10cSrcweir "com.sun.star.comp.deployment.ExtensionManager", 1522cdf0e10cSrcweir "com.sun.star.comp.deployment.ExtensionManager"); 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir //------------------------------------------------------------------------------ 1525cdf0e10cSrcweir bool singleton_entries( 1526cdf0e10cSrcweir uno::Reference< registry::XRegistryKey > const & xRegistryKey ) 1527cdf0e10cSrcweir { 1528cdf0e10cSrcweir try { 1529cdf0e10cSrcweir uno::Reference< registry::XRegistryKey > xKey( 1530cdf0e10cSrcweir xRegistryKey->createKey( 1531cdf0e10cSrcweir serviceDecl.getImplementationName() + 1532cdf0e10cSrcweir // xxx todo: use future generated function to get singleton name 1533cdf0e10cSrcweir OUSTR("/UNO/SINGLETONS/" 1534cdf0e10cSrcweir "com.sun.star.deployment.ExtensionManager") ) ); 1535cdf0e10cSrcweir xKey->setStringValue( serviceDecl.getSupportedServiceNames()[0] ); 1536cdf0e10cSrcweir return true; 1537cdf0e10cSrcweir } 1538cdf0e10cSrcweir catch (registry::InvalidRegistryException & exc) { 1539cdf0e10cSrcweir (void) exc; // avoid warnings 1540cdf0e10cSrcweir OSL_ENSURE( 0, ::rtl::OUStringToOString( 1541cdf0e10cSrcweir exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 1542cdf0e10cSrcweir return false; 1543cdf0e10cSrcweir } 1544cdf0e10cSrcweir } 1545cdf0e10cSrcweir 1546cdf0e10cSrcweir // XModifyBroadcaster 1547cdf0e10cSrcweir //______________________________________________________________________________ 1548cdf0e10cSrcweir void ExtensionManager::addModifyListener( 1549cdf0e10cSrcweir Reference<util::XModifyListener> const & xListener ) 1550cdf0e10cSrcweir throw (uno::RuntimeException) 1551cdf0e10cSrcweir { 1552cdf0e10cSrcweir check(); 1553cdf0e10cSrcweir rBHelper.addListener( ::getCppuType( &xListener ), xListener ); 1554cdf0e10cSrcweir } 1555cdf0e10cSrcweir 1556cdf0e10cSrcweir //______________________________________________________________________________ 1557cdf0e10cSrcweir void ExtensionManager::removeModifyListener( 1558cdf0e10cSrcweir Reference<util::XModifyListener> const & xListener ) 1559cdf0e10cSrcweir throw (uno::RuntimeException) 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir check(); 1562cdf0e10cSrcweir rBHelper.removeListener( ::getCppuType( &xListener ), xListener ); 1563cdf0e10cSrcweir } 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir void ExtensionManager::check() 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir ::osl::MutexGuard guard( getMutex() ); 1568cdf0e10cSrcweir if (rBHelper.bInDispose || rBHelper.bDisposed) { 1569cdf0e10cSrcweir throw lang::DisposedException( 1570cdf0e10cSrcweir OUSTR("ExtensionManager instance has already been disposed!"), 1571cdf0e10cSrcweir static_cast<OWeakObject *>(this) ); 1572cdf0e10cSrcweir } 1573cdf0e10cSrcweir } 1574cdf0e10cSrcweir 1575cdf0e10cSrcweir void ExtensionManager::fireModified() 1576cdf0e10cSrcweir { 1577cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper * pContainer = rBHelper.getContainer( 1578cdf0e10cSrcweir util::XModifyListener::static_type() ); 1579cdf0e10cSrcweir if (pContainer != 0) { 1580cdf0e10cSrcweir pContainer->forEach<util::XModifyListener>( 1581cdf0e10cSrcweir boost::bind(&util::XModifyListener::modified, _1, 1582cdf0e10cSrcweir lang::EventObject(static_cast<OWeakObject *>(this))) ); 1583cdf0e10cSrcweir } 1584cdf0e10cSrcweir } 1585cdf0e10cSrcweir 1586cdf0e10cSrcweir } // namespace dp_manager 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir 1589