xref: /trunk/main/desktop/source/deployment/registry/inc/dp_backend.h (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_REGISTRY_H
25 #define INCLUDED_DP_REGISTRY_H
26 
27 #include "dp_misc.h"
28 #include "dp_resource.h"
29 #include "dp_interact.h"
30 #include "rtl/ref.hxx"
31 #include "cppuhelper/weakref.hxx"
32 #include "cppuhelper/implbase1.hxx"
33 #include "cppuhelper/compbase1.hxx"
34 #include "cppuhelper/compbase2.hxx"
35 #include "tools/inetmime.hxx"
36 #include "com/sun/star/lang/XEventListener.hpp"
37 #include "com/sun/star/deployment/XPackageRegistry.hpp"
38 #include "com/sun/star/deployment/XPackageManager.hpp"
39 #include "com/sun/star/deployment/InvalidRemovedParameterException.hpp"
40 #include <memory>
41 #include <hash_map>
42 #include <list>
43 #include "dp_registry.hrc"
44 
45 namespace dp_registry
46 {
47 namespace backend
48 {
49 
50 namespace css = ::com::sun::star;
51 
52 class PackageRegistryBackend;
53 
54 char const* const BACKEND_SERVICE_NAME =
55 "com.sun.star.deployment.PackageRegistryBackend";
56 
57 typedef ::cppu::WeakComponentImplHelper1<
58     css::deployment::XPackage > t_PackageBase;
59 
60 //==============================================================================
61 class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
62 {
63     PackageRegistryBackend * getMyBackend() const;
64     void processPackage_impl(
65         bool registerPackage,
66         bool startup,
67         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
68         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
69 
70 protected:
71     ::rtl::Reference<PackageRegistryBackend> m_myBackend;
72     const ::rtl::OUString m_url;
73     ::rtl::OUString m_name;
74     ::rtl::OUString m_displayName;
75     const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
76     const bool m_bRemoved;
77     //Only set if m_bRemoved = true;
78     const ::rtl::OUString m_identifier;
79 
80     void check() const;
81     void fireModified();
82     virtual void SAL_CALL disposing();
83 
84     void checkAborted(
85         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
86 
87     // @@@ to be implemented by specific backend:
88     virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
89     isRegistered_(
90         ::osl::ResettableMutexGuard & guard,
91         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
92         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
93         = 0;
94     virtual void processPackage_(
95         ::osl::ResettableMutexGuard & guard,
96         bool registerPackage,
97         bool startup,
98         ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
99         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
100         = 0;
101 
102     virtual ~Package();
103     Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
104              ::rtl::OUString const & url,
105              ::rtl::OUString const & name,
106              ::rtl::OUString const & displayName,
107              css::uno::Reference<css::deployment::XPackageTypeInfo> const &
108              xPackageType,
109              bool bRemoved,
110              ::rtl::OUString const & identifier);
111 
112 public:
113 
114     class TypeInfo :
115         public ::cppu::WeakImplHelper1<css::deployment::XPackageTypeInfo>
116     {
117         const ::rtl::OUString m_mediaType;
118         const ::rtl::OUString m_fileFilter;
119         const ::rtl::OUString m_shortDescr;
120         const sal_uInt16 m_smallIcon, m_smallIcon_HC;
121     public:
122         virtual ~TypeInfo();
TypeInfo(::rtl::OUString const & mediaType,::rtl::OUString const & fileFilter,::rtl::OUString const & shortDescr,sal_uInt16 smallIcon,sal_uInt16 smallIcon_HC)123         TypeInfo( ::rtl::OUString const & mediaType,
124                   ::rtl::OUString const & fileFilter,
125                   ::rtl::OUString const & shortDescr,
126                   sal_uInt16 smallIcon, sal_uInt16 smallIcon_HC )
127             : m_mediaType(mediaType), m_fileFilter(fileFilter),
128               m_shortDescr(shortDescr),
129               m_smallIcon(smallIcon), m_smallIcon_HC(smallIcon_HC)
130             {}
131         // XPackageTypeInfo
132         virtual ::rtl::OUString SAL_CALL getMediaType();
133         virtual ::rtl::OUString SAL_CALL getDescription();
134         virtual ::rtl::OUString SAL_CALL getShortDescription();
135         virtual ::rtl::OUString SAL_CALL getFileFilter();
136         virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
137                                                 sal_Bool smallIcon );
138     };
139 
140     // XComponent
141     virtual void SAL_CALL dispose();
142     virtual void SAL_CALL addEventListener(
143         css::uno::Reference<css::lang::XEventListener> const & xListener );
144     virtual void SAL_CALL removeEventListener(
145         css::uno::Reference<css::lang::XEventListener> const & xListener );
146 
147     // XModifyBroadcaster
148     virtual void SAL_CALL addModifyListener(
149         css::uno::Reference<css::util::XModifyListener> const & xListener );
150     virtual void SAL_CALL removeModifyListener(
151         css::uno::Reference<css::util::XModifyListener> const & xListener );
152 
153     // XPackage
154     virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
155     createAbortChannel();
156     virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
157     SAL_CALL isRegistered(
158         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
159         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
160 
161     virtual ::sal_Int32 SAL_CALL checkPrerequisites(
162         const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
163         const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
164         sal_Bool noLicenseChecking);
165 
166     virtual ::sal_Bool SAL_CALL checkDependencies(
167         const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv );
168 
169     virtual void SAL_CALL registerPackage(
170         sal_Bool startup,
171         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
172         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
173     virtual void SAL_CALL revokePackage(
174         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
175         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
176     virtual sal_Bool SAL_CALL isBundle();
177     virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
178     SAL_CALL getBundle(
179         css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
180         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
181     virtual ::rtl::OUString SAL_CALL getName();
182     virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getIdentifier();
183     virtual ::rtl::OUString SAL_CALL getVersion();
184     virtual ::rtl::OUString SAL_CALL getURL();
185     virtual ::rtl::OUString SAL_CALL getDisplayName();
186     virtual ::rtl::OUString SAL_CALL getDescription();
187     virtual ::rtl::OUString SAL_CALL getLicenseText();
188     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
189     getUpdateInformationURLs();
190     virtual css::beans::StringPair SAL_CALL getPublisherInfo();
191     virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
192     getIcon( sal_Bool bHighContrast );
193     virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
194     getPackageType();
195     virtual void SAL_CALL exportTo(
196         ::rtl::OUString const & destFolderURL,
197         ::rtl::OUString const & newTitle,
198         sal_Int32 nameClashAction,
199         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
200     virtual ::rtl::OUString SAL_CALL getRepositoryName();
201     virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getRegistrationDataURL();
202     virtual sal_Bool SAL_CALL isRemoved();
203 
204 };
205 
206 typedef ::cppu::WeakComponentImplHelper2<
207     css::lang::XEventListener,
208     css::deployment::XPackageRegistry > t_BackendBase;
209 
210 //==============================================================================
211 class PackageRegistryBackend
212     : protected ::dp_misc::MutexHolder, public t_BackendBase
213 {
214     //The map held originally WeakReferences. The map entries are removed in the disposing
215     //function, which is called when the XPackages are destructed or they are
216     //explicitly disposed. The latter happens, for example, when a extension is
217     //removed (see dp_manager.cxx). However, because of how the help systems work, now
218     // XPackageManager::getDeployedPackages is called often. This results in a lot
219     //of bindPackage calls which are costly. Therefore we keep hard references in
220     //the map now.
221     typedef ::std::hash_map<
222         ::rtl::OUString, css::uno::Reference<css::deployment::XPackage>,
223         ::rtl::OUStringHash > t_string2ref;
224     t_string2ref m_bound;
225 
226 protected:
227     ::rtl::OUString m_cachePath;
228     css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
229 
230     ::rtl::OUString m_context;
231     // currently only for library containers:
232     enum {
233         CONTEXT_UNKNOWN,
234         CONTEXT_USER, CONTEXT_SHARED,CONTEXT_BUNDLED, CONTEXT_TMP, CONTEXT_BUNDLED_PREREG,
235         CONTEXT_DOCUMENT
236     } m_eContext;
237     bool m_readOnly;
238 
239     struct StrCannotDetectMediaType : public ::dp_misc::StaticResourceString<
240         StrCannotDetectMediaType, RID_STR_CANNOT_DETECT_MEDIA_TYPE> {};
241     struct StrUnsupportedMediaType : public ::dp_misc::StaticResourceString<
242         StrUnsupportedMediaType, RID_STR_UNSUPPORTED_MEDIA_TYPE> {};
243 
244     // @@@ to be implemented by specific backend:
245     virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
246         ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
247         sal_Bool bRemoved, ::rtl::OUString const & identifier,
248         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
249         = 0;
250 
251     void check();
252     virtual void SAL_CALL disposing();
253 
254     virtual ~PackageRegistryBackend();
255     PackageRegistryBackend(
256         css::uno::Sequence<css::uno::Any> const & args,
257         css::uno::Reference<css::uno::XComponentContext> const & xContext );
258 
259     /* creates a folder with a unique name.
260        If url is empty then it is created in the backend folder, otherwise
261        at a location relative to that folder specified by url.
262     */
263     ::rtl::OUString createFolder(
264         ::rtl::OUString const & relUrl,
265         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
266     /* deletes folders and files.
267 
268        All folder all files which end with ".tmp" or ".tmp_" and which are
269        not used are deleted.
270      */
271     void deleteUnusedFolders(
272         ::rtl::OUString const & relUrl,
273         ::std::list< ::rtl::OUString> const & usedFolders);
274     /* deletes one folder with a "temporary" name and the corresponding
275        tmp file, which was used to derive the folder name.
276     */
277     static void deleteTempFolder(
278         ::rtl::OUString const & folderUrl);
279 
280     ::rtl::OUString getSharedRegistrationDataURL(
281         css::uno::Reference<css::deployment::XPackage> const & extension,
282         css::uno::Reference<css::deployment::XPackage> const & item);
283 
284     /* The backends must implement this function, which is called
285        from XPackageRegistry::packageRemoved (also implemented here).
286        This ensure that the backends clean up their registration data
287        when an extension was removed.
288     */
289 //    virtual void deleteDbEntry( ::rtl::OUString const & url) = 0;
290 
291 
292 
293 public:
294     struct StrRegisteringPackage : public ::dp_misc::StaticResourceString<
295         StrRegisteringPackage, RID_STR_REGISTERING_PACKAGE> {};
296     struct StrRevokingPackage : public ::dp_misc::StaticResourceString<
297         StrRevokingPackage, RID_STR_REVOKING_PACKAGE> {};
298 
299     inline css::uno::Reference<css::uno::XComponentContext> const &
getComponentContext()300     getComponentContext() const { return m_xComponentContext; }
301 
getCachePath()302     inline ::rtl::OUString const & getCachePath() const { return m_cachePath; }
transientMode()303     inline bool transientMode() const { return m_cachePath.getLength() == 0; }
304 
getContext()305     inline ::rtl::OUString getContext() const {return m_context; }
306 
307     // XEventListener
308     virtual void SAL_CALL disposing( css::lang::EventObject const & evt );
309 
310     // XPackageRegistry
311     virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
312         ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
313         sal_Bool bRemoved, ::rtl::OUString const & identifier,
314         css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
315 
316 //     virtual void SAL_CALL packageRemoved(
317 //         ::rtl::OUString const & url, ::rtl::OUString const & mediaType)
318 //         throw (css::deployment::DeploymentException,
319 //                css::uno::RuntimeException);
320 
321 };
322 
323 }
324 }
325 
326 #endif
327