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