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 #if ! defined INCLUDED_DP_MANAGER_H
25 #define INCLUDED_DP_MANAGER_H
26 
27 #include "dp_manager.hrc"
28 #include "dp_misc.h"
29 #include "dp_interact.h"
30 #include "dp_activepackages.hxx"
31 #include "rtl/ref.hxx"
32 #include "cppuhelper/compbase1.hxx"
33 #include "cppuhelper/implbase2.hxx"
34 #include "ucbhelper/content.hxx"
35 #include "com/sun/star/deployment/XPackageRegistry.hpp"
36 #include "com/sun/star/deployment/XPackageManager.hpp"
37 #include <memory>
38 
39 
40 namespace css = ::com::sun::star;
41 
42 namespace dp_manager {
43 
44 typedef ::cppu::WeakComponentImplHelper1<
45     css::deployment::XPackageManager > t_pm_helper;
46 
47 //==============================================================================
48 class PackageManagerImpl : private ::dp_misc::MutexHolder, public t_pm_helper
49 {
50     css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
51     ::rtl::OUString m_context;
52     ::rtl::OUString m_registrationData;
53     ::rtl::OUString m_registrationData_expanded;
54     ::rtl::OUString m_registryCache;
55     bool m_readOnly;
56 
57     ::rtl::OUString m_activePackages;
58     ::rtl::OUString m_activePackages_expanded;
59     ::std::auto_ptr< ActivePackages > m_activePackagesDB;
60     //This mutex is only used for synchronization in addPackage
61     ::osl::Mutex m_addMutex;
62     css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
63     inline void logIntern( css::uno::Any const & status );
64     void fireModified();
65 
66     css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry;
67 
68     void initRegistryBackends();
69     void initActivationLayer(
70         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
71     ::rtl::OUString detectMediaType(
72         ::ucbhelper::Content const & ucbContent, bool throw_exc = true );
73     ::rtl::OUString insertToActivationLayer(
74         css::uno::Sequence<css::beans::NamedValue> const & properties,
75         ::rtl::OUString const & mediaType,
76         ::ucbhelper::Content const & sourceContent,
77         ::rtl::OUString const & title, ActivePackages::Data * dbData );
78     void insertToActivationLayerDB(
79         ::rtl::OUString const & id, ActivePackages::Data const & dbData );
80 
81 	void deletePackageFromCache(
82 		css::uno::Reference<css::deployment::XPackage> const & xPackage,
83         ::rtl::OUString const & destFolder );
84 
85     bool isInstalled(
86         css::uno::Reference<css::deployment::XPackage> const & package);
87 
88     bool synchronizeRemovedExtensions(
89         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
90         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
91 
92     bool synchronizeAddedExtensions(
93         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
94         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
95 
96     class CmdEnvWrapperImpl
97         : public ::cppu::WeakImplHelper2< css::ucb::XCommandEnvironment,
98                                           css::ucb::XProgressHandler >
99     {
100         css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
101         css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress;
102         css::uno::Reference<css::task::XInteractionHandler>
103         m_xUserInteractionHandler;
104 
105     public:
106         virtual ~CmdEnvWrapperImpl();
107         CmdEnvWrapperImpl(
108             css::uno::Reference<css::ucb::XCommandEnvironment>
109             const & xUserCmdEnv,
110             css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile );
111 
112         // XCommandEnvironment
113         virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL
114         getInteractionHandler() throw (css::uno::RuntimeException);
115         virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL
116         getProgressHandler() throw (css::uno::RuntimeException);
117 
118         // XProgressHandler
119         virtual void SAL_CALL push( css::uno::Any const & Status )
120             throw (css::uno::RuntimeException);
121         virtual void SAL_CALL update( css::uno::Any const & Status )
122             throw (css::uno::RuntimeException);
123         virtual void SAL_CALL pop() throw (css::uno::RuntimeException);
124     };
125 
126 protected:
127     inline void check();
128     virtual void SAL_CALL disposing();
129 
130     virtual ~PackageManagerImpl();
PackageManagerImpl(css::uno::Reference<css::uno::XComponentContext> const & xComponentContext,::rtl::OUString const & context)131     inline PackageManagerImpl(
132         css::uno::Reference<css::uno::XComponentContext>
133         const & xComponentContext, ::rtl::OUString const & context )
134         : t_pm_helper( getMutex() ),
135           m_xComponentContext( xComponentContext ),
136           m_context( context ),
137           m_readOnly( true )
138         {}
139 
140 public:
141     static css::uno::Reference<css::deployment::XPackageManager> create(
142         css::uno::Reference<css::uno::XComponentContext>
143         const & xComponentContext, ::rtl::OUString const & context );
144 
145     // XComponent
146     virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
147     virtual void SAL_CALL addEventListener(
148         css::uno::Reference<css::lang::XEventListener> const & xListener )
149         throw (css::uno::RuntimeException);
150     virtual void SAL_CALL removeEventListener(
151         css::uno::Reference<css::lang::XEventListener> const & xListener )
152         throw (css::uno::RuntimeException);
153 
154     // XModifyBroadcaster
155     virtual void SAL_CALL addModifyListener(
156         css::uno::Reference<css::util::XModifyListener> const & xListener )
157         throw (css::uno::RuntimeException);
158     virtual void SAL_CALL removeModifyListener(
159         css::uno::Reference<css::util::XModifyListener> const & xListener )
160         throw (css::uno::RuntimeException);
161 
162     // XPackageManager
163     virtual ::rtl::OUString SAL_CALL getContext()
164         throw (css::uno::RuntimeException);
165     virtual css::uno::Sequence<
166         css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
167     getSupportedPackageTypes() throw (css::uno::RuntimeException);
168 
169     virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
170     createAbortChannel() throw (css::uno::RuntimeException);
171 
172     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage(
173         ::rtl::OUString const & url,
174         css::uno::Sequence<css::beans::NamedValue> const & properties,
175         ::rtl::OUString const & mediaType,
176         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
177         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
178         throw (css::deployment::DeploymentException,
179                css::ucb::CommandFailedException,
180                css::ucb::CommandAbortedException,
181                css::lang::IllegalArgumentException,
182                css::uno::RuntimeException);
183 
184     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension(
185         css::uno::Reference<css::deployment::XPackage> const & extension,
186         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
187         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
188         throw (css::deployment::DeploymentException,
189             css::ucb::CommandFailedException,
190             css::ucb::CommandAbortedException,
191             css::lang::IllegalArgumentException,
192             css::uno::RuntimeException);
193 
194     virtual void SAL_CALL removePackage(
195         ::rtl::OUString const & id, ::rtl::OUString const & fileName,
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     ::rtl::OUString getDeployPath( ActivePackages::Data const & data );
205     css::uno::Reference<css::deployment::XPackage> SAL_CALL getDeployedPackage_(
206         ::rtl::OUString const & id, ::rtl::OUString const & fileName,
207         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
208     css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
209         ::rtl::OUString const & id, ActivePackages::Data const & data,
210         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
211         bool ignoreAlienPlatforms = false );
212     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL
213     getDeployedPackage(
214         ::rtl::OUString const & id, ::rtl::OUString const & fileName,
215         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
216         throw (css::deployment::DeploymentException,
217                css::ucb::CommandFailedException,
218                css::lang::IllegalArgumentException, css::uno::RuntimeException);
219 
220     css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
221     getDeployedPackages_(
222         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
223     virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
224     SAL_CALL getDeployedPackages(
225         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
226         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
227         throw (css::deployment::DeploymentException,
228                css::ucb::CommandFailedException,
229                css::ucb::CommandAbortedException,
230                css::lang::IllegalArgumentException,
231                css::uno::RuntimeException);
232 
233     virtual void SAL_CALL reinstallDeployedPackages(
234         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
235         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
236         throw (css::deployment::DeploymentException,
237                css::ucb::CommandFailedException,
238                css::ucb::CommandAbortedException,
239                css::lang::IllegalArgumentException,
240                css::uno::RuntimeException);
241 
242     virtual ::sal_Bool SAL_CALL isReadOnly(  )
243         throw (::com::sun::star::uno::RuntimeException);
244 
245     virtual ::sal_Bool SAL_CALL synchronize(
246         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
247         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
248         throw (css::deployment::DeploymentException,
249                css::ucb::CommandFailedException,
250                css::ucb::CommandAbortedException,
251                css::uno::RuntimeException);
252 
253     virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
254     getExtensionsWithUnacceptedLicenses(
255         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv)
256         throw (css::deployment::DeploymentException,
257                css::uno::RuntimeException);
258 
259     virtual sal_Int32 SAL_CALL checkPrerequisites(
260         css::uno::Reference<css::deployment::XPackage> const & extension,
261         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
262         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
263         throw (css::deployment::DeploymentException,
264                css::ucb::CommandFailedException,
265                css::ucb::CommandAbortedException,
266                css::lang::IllegalArgumentException,
267                css::uno::RuntimeException);
268         };
269 
270 //______________________________________________________________________________
check()271 inline void PackageManagerImpl::check()
272 {
273     ::osl::MutexGuard guard( getMutex() );
274     if (rBHelper.bInDispose || rBHelper.bDisposed)
275         throw css::lang::DisposedException(
276             OUSTR("PackageManager instance has already been disposed!"),
277             static_cast< ::cppu::OWeakObject * >(this) );
278 }
279 
280 //______________________________________________________________________________
logIntern(css::uno::Any const & status)281 inline void PackageManagerImpl::logIntern( css::uno::Any const & status )
282 {
283     if (m_xLogFile.is())
284         m_xLogFile->update( status );
285 }
286 
287 }
288 
289 #endif
290 
291