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