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