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