1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #if ! defined INCLUDED_DP_EXTENSIONMANAGER_H
30 #define INCLUDED_DP_EXTENSIONMANAGER_H
31 
32 #include "dp_manager.hrc"
33 #include "dp_misc.h"
34 #include "dp_interact.h"
35 #include "dp_activepackages.hxx"
36 #include "rtl/ref.hxx"
37 #include "cppuhelper/compbase1.hxx"
38 #include "ucbhelper/content.hxx"
39 #include "com/sun/star/deployment/XPackageRegistry.hpp"
40 #include "com/sun/star/deployment/XPackageManager.hpp"
41 #include "osl/mutex.hxx"
42 #include <list>
43 
44 
45 namespace css = ::com::sun::star;
46 
47 namespace dp_manager {
48 
49 typedef ::std::hash_map<
50     ::rtl::OUString,
51     ::std::vector<css::uno::Reference<css::deployment::XPackage> >,
52     ::rtl::OUStringHash > id2extensions;
53 
54 
55 class ExtensionManager : private ::dp_misc::MutexHolder,
56         public ::cppu::WeakComponentImplHelper1< css::deployment::XExtensionManager >
57 {
58 public:
59     ExtensionManager( css::uno::Reference< css::uno::XComponentContext >const& xContext);
60     virtual     ~ExtensionManager();
61 
62     static css::uno::Sequence< ::rtl::OUString > getServiceNames();
63     static ::rtl::OUString getImplName();
64 
65     void check();
66     void fireModified();
67 
68 public:
69 
70 //    XModifyBroadcaster
71     virtual void SAL_CALL addModifyListener(
72        css::uno::Reference<css::util::XModifyListener> const & xListener )
73        throw (css::uno::RuntimeException);
74     virtual void SAL_CALL removeModifyListener(
75        css::uno::Reference<css::util::XModifyListener> const & xListener )
76        throw (css::uno::RuntimeException);
77 
78 //XExtensionManager
79     virtual css::uno::Sequence<
80         css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
81         getSupportedPackageTypes()
82             throw (css::uno::RuntimeException);
83 
84     virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
85     createAbortChannel() throw (css::uno::RuntimeException);
86 
87     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addExtension(
88         ::rtl::OUString const & url,
89         css::uno::Sequence<css::beans::NamedValue> const & properties,
90         ::rtl::OUString const & repository,
91         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
92         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
93         throw (css::deployment::DeploymentException,
94                css::ucb::CommandFailedException,
95                css::ucb::CommandAbortedException,
96                css::lang::IllegalArgumentException,
97                css::uno::RuntimeException);
98 
99     virtual void SAL_CALL removeExtension(
100         ::rtl::OUString const & identifier,
101         ::rtl::OUString const & filename,
102         ::rtl::OUString const & repository,
103         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
104         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
105         throw (css::deployment::DeploymentException,
106             css::ucb::CommandFailedException,
107             css::ucb::CommandAbortedException,
108             css::lang::IllegalArgumentException,
109             css::uno::RuntimeException);
110 
111     virtual void SAL_CALL enableExtension(
112         css::uno::Reference<css::deployment::XPackage> const & extension,
113         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
114         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
115         throw (css::deployment::DeploymentException,
116             css::ucb::CommandFailedException,
117             css::ucb::CommandAbortedException,
118             css::lang::IllegalArgumentException,
119             css::uno::RuntimeException);
120 
121     virtual void SAL_CALL disableExtension(
122         css::uno::Reference<css::deployment::XPackage> const & extension,
123         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
124         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
125         throw (css::deployment::DeploymentException,
126             css::ucb::CommandFailedException,
127             css::ucb::CommandAbortedException,
128             css::lang::IllegalArgumentException,
129             css::uno::RuntimeException);
130 
131 
132     virtual sal_Int32 SAL_CALL checkPrerequisitesAndEnable(
133         css::uno::Reference<css::deployment::XPackage> const & extension,
134         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
135         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
136         throw (css::deployment::DeploymentException,
137             css::ucb::CommandFailedException,
138             css::ucb::CommandAbortedException,
139             css::lang::IllegalArgumentException,
140             css::uno::RuntimeException);
141 
142 
143     virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
144         SAL_CALL getDeployedExtensions(
145         ::rtl::OUString const & repository,
146         css::uno::Reference<css::task::XAbortChannel> const &,
147         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
148         throw (css::deployment::DeploymentException,
149             css::ucb::CommandFailedException,
150             css::ucb::CommandAbortedException,
151             css::lang::IllegalArgumentException,
152             css::uno::RuntimeException);
153 
154     virtual css::uno::Reference< css::deployment::XPackage>
155         SAL_CALL getDeployedExtension(
156         ::rtl::OUString const & repository,
157         ::rtl::OUString const & identifier,
158         ::rtl::OUString const & filename,
159         css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv )
160         throw (
161             css::deployment::DeploymentException,
162             css::ucb::CommandFailedException,
163             css::lang::IllegalArgumentException,
164             css::uno::RuntimeException);
165 
166     virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> >
167     SAL_CALL getExtensionsWithSameIdentifier(
168         ::rtl::OUString const & identifier,
169         ::rtl::OUString const & filename,
170         css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv )
171         throw (
172             css::deployment::DeploymentException,
173             css::ucb::CommandFailedException,
174             css::lang::IllegalArgumentException,
175             css::uno::RuntimeException);
176 
177     virtual css::uno::Sequence< css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > >
178         SAL_CALL getAllExtensions(
179         css::uno::Reference<css::task::XAbortChannel> const &,
180         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
181         throw (css::deployment::DeploymentException,
182             css::ucb::CommandFailedException,
183             css::ucb::CommandAbortedException,
184             css::lang::IllegalArgumentException,
185             css::uno::RuntimeException);
186 
187 
188     virtual void SAL_CALL reinstallDeployedExtensions(
189         ::rtl::OUString const & repository,
190         css::uno::Reference< css::task::XAbortChannel> const & xAbortChannel,
191         css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv )
192         throw (
193             css::deployment::DeploymentException,
194             css::ucb::CommandFailedException,
195             css::ucb::CommandAbortedException,
196             css::lang::IllegalArgumentException,
197             css::uno::RuntimeException);
198 
199     virtual sal_Bool SAL_CALL synchronize(
200         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
201         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
202         throw (css::deployment::DeploymentException,
203                css::ucb::CommandFailedException,
204                css::ucb::CommandAbortedException,
205                css::lang::IllegalArgumentException,
206                css::uno::RuntimeException);
207 
208     virtual void SAL_CALL synchronizeBundledPrereg(
209         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
210         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
211         throw (css::deployment::DeploymentException,
212                css::uno::RuntimeException);
213 
214     virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
215     getExtensionsWithUnacceptedLicenses(
216         ::rtl::OUString const & repository,
217         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv)
218         throw (css::deployment::DeploymentException,
219                css::uno::RuntimeException);
220 
221     virtual sal_Bool SAL_CALL isReadOnlyRepository(::rtl::OUString const & repository)
222         throw (css::uno::RuntimeException);
223 
224 private:
225 
226     struct StrSyncRepository : public ::dp_misc::StaticResourceString<
227         StrSyncRepository, RID_STR_SYNCHRONIZING_REPOSITORY> {};
228 
229     struct ExtensionInfos
230     {
231         ::rtl::OUString identifier;
232         ::rtl::OUString fileName;
233         ::rtl::OUString displayName;
234         ::rtl::OUString version;
235     };
236 
237     css::uno::Reference< css::uno::XComponentContext> m_xContext;
238     css::uno::Reference<css::deployment::XPackageManagerFactory> m_xPackageManagerFactory;
239 
240     //only to be used within addExtension
241     ::osl::Mutex m_addMutex;
242     /* contains the names of all repositories (except tmp) in order of there
243        priority. That is, the first element is "user" follod by "shared" and
244        then "bundled"
245      */
246     ::std::list< ::rtl::OUString > m_repositoryNames;
247 
248     css::uno::Reference<css::deployment::XPackageManager> getUserRepository();
249     css::uno::Reference<css::deployment::XPackageManager> getSharedRepository();
250     css::uno::Reference<css::deployment::XPackageManager> getBundledRepository();
251     css::uno::Reference<css::deployment::XPackageManager> getTmpRepository();
252 
253     bool isUserDisabled(::rtl::OUString const & identifier,
254                         ::rtl::OUString const & filename);
255 
256     bool isUserDisabled(
257         css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExtSameId);
258 
259     void activateExtension(
260         ::rtl::OUString const & identifier,
261         ::rtl::OUString const & fileName,
262         bool bUserDisabled, bool bStartup,
263         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
264         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
265 
266     void activateExtension(
267         css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExt,
268         bool bUserDisabled, bool bStartup,
269         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
270         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
271 
272 
273     ::std::list<css::uno::Reference<css::deployment::XPackage> >
274     getExtensionsWithSameId(::rtl::OUString  const & identifier,
275                             ::rtl::OUString const & fileName,
276                             css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv =
277                             css::uno::Reference< css::ucb::XCommandEnvironment>());
278 
279     css::uno::Reference<css::deployment::XPackage> backupExtension(
280         ::rtl::OUString const & identifier, ::rtl::OUString const & fileName,
281         css::uno::Reference<css::deployment::XPackageManager> const & xPackageManager,
282         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
283 
284     void checkInstall(
285         ::rtl::OUString const & displayName,
286         css::uno::Reference<css::ucb::XCommandEnvironment> const & cmdEnv);
287 
288     void checkUpdate(
289         ::rtl::OUString const & newVersion,
290         ::rtl::OUString const & newDisplayName,
291         css::uno::Reference<css::deployment::XPackage> const & oldExtension,
292         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
293 
294     css::uno::Reference<css::deployment::XPackage> getTempExtension(
295         ::rtl::OUString const & url,
296         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
297         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
298 
299 
300     void addExtensionsToMap(
301         id2extensions & mapExt,
302         css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExt,
303         ::rtl::OUString const & repository);
304 
305     css::uno::Reference<css::deployment::XPackageManager>
306     getPackageManager(::rtl::OUString const & repository)
307         throw (css::lang::IllegalArgumentException);
308 
309     bool doChecksForAddExtension(
310         css::uno::Reference<css::deployment::XPackageManager> const & xPackageMgr,
311         css::uno::Sequence<css::beans::NamedValue> const & properties,
312         css::uno::Reference<css::deployment::XPackage> const & xTmpExtension,
313         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
314         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
315         css::uno::Reference<css::deployment::XPackage> & out_existingExtension )
316         throw (css::deployment::DeploymentException,
317                css::ucb::CommandFailedException,
318                css::ucb::CommandAbortedException,
319                css::lang::IllegalArgumentException,
320                css::uno::RuntimeException);
321 
322 
323 };
324 
325 }
326 
327 
328 
329 
330 #endif
331 
332