Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_DP_REGISTRY_H
21 : #define INCLUDED_DP_REGISTRY_H
22 :
23 : #include "dp_misc.h"
24 : #include "dp_resource.h"
25 : #include "dp_interact.h"
26 : #include "rtl/ref.hxx"
27 : #include "cppuhelper/weakref.hxx"
28 : #include "cppuhelper/implbase1.hxx"
29 : #include "cppuhelper/compbase1.hxx"
30 : #include "cppuhelper/compbase2.hxx"
31 : #include "tools/inetmime.hxx"
32 : #include "com/sun/star/lang/XEventListener.hpp"
33 : #include "com/sun/star/deployment/XPackageRegistry.hpp"
34 : #include "com/sun/star/deployment/XPackageManager.hpp"
35 : #include "com/sun/star/deployment/InvalidRemovedParameterException.hpp"
36 : #include <memory>
37 : #include <boost/unordered_map.hpp>
38 : #include <list>
39 : #include "dp_registry.hrc"
40 :
41 : namespace dp_registry
42 : {
43 : namespace backend
44 : {
45 :
46 : class PackageRegistryBackend;
47 :
48 : #define BACKEND_SERVICE_NAME "com.sun.star.deployment.PackageRegistryBackend"
49 :
50 : typedef ::cppu::WeakComponentImplHelper1<
51 : css::deployment::XPackage > t_PackageBase;
52 :
53 : //==============================================================================
54 : class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
55 : {
56 : PackageRegistryBackend * getMyBackend() const;
57 : void processPackage_impl(
58 : bool registerPackage,
59 : bool startup,
60 : css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
61 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
62 :
63 : protected:
64 : ::rtl::Reference<PackageRegistryBackend> m_myBackend;
65 : const ::rtl::OUString m_url;
66 : ::rtl::OUString m_name;
67 : ::rtl::OUString m_displayName;
68 : const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
69 : const bool m_bRemoved;
70 : //Only set if m_bRemoved = true;
71 : const ::rtl::OUString m_identifier;
72 :
73 : void check() const;
74 : void fireModified();
75 : virtual void SAL_CALL disposing();
76 :
77 : void checkAborted(
78 : ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
79 :
80 : // @@@ to be implemented by specific backend:
81 : virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
82 : isRegistered_(
83 : ::osl::ResettableMutexGuard & guard,
84 : ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
85 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
86 : = 0;
87 : virtual void processPackage_(
88 : ::osl::ResettableMutexGuard & guard,
89 : bool registerPackage,
90 : bool startup,
91 : ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
92 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
93 : = 0;
94 :
95 : virtual ~Package();
96 : Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
97 : ::rtl::OUString const & url,
98 : ::rtl::OUString const & name,
99 : ::rtl::OUString const & displayName,
100 : css::uno::Reference<css::deployment::XPackageTypeInfo> const &
101 : xPackageType,
102 : bool bRemoved,
103 : ::rtl::OUString const & identifier);
104 :
105 : public:
106 :
107 : class TypeInfo :
108 : public ::cppu::WeakImplHelper1<css::deployment::XPackageTypeInfo>
109 : {
110 : const ::rtl::OUString m_mediaType;
111 : const ::rtl::OUString m_fileFilter;
112 : const ::rtl::OUString m_shortDescr;
113 : const sal_uInt16 m_smallIcon;
114 : public:
115 : virtual ~TypeInfo();
116 0 : TypeInfo( ::rtl::OUString const & mediaType,
117 : ::rtl::OUString const & fileFilter,
118 : ::rtl::OUString const & shortDescr,
119 : sal_uInt16 smallIcon)
120 : : m_mediaType(mediaType), m_fileFilter(fileFilter),
121 : m_shortDescr(shortDescr),
122 0 : m_smallIcon(smallIcon)
123 0 : {}
124 : // XPackageTypeInfo
125 : virtual ::rtl::OUString SAL_CALL getMediaType()
126 : throw (css::uno::RuntimeException);
127 : virtual ::rtl::OUString SAL_CALL getDescription()
128 : throw (css::deployment::ExtensionRemovedException,
129 : css::uno::RuntimeException);
130 : virtual ::rtl::OUString SAL_CALL getShortDescription()
131 : throw (css::deployment::ExtensionRemovedException,
132 : css::uno::RuntimeException);
133 : virtual ::rtl::OUString SAL_CALL getFileFilter()
134 : throw (css::uno::RuntimeException);
135 : virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
136 : sal_Bool smallIcon )
137 : throw (css::uno::RuntimeException);
138 : };
139 :
140 : // XComponent
141 : virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
142 : virtual void SAL_CALL addEventListener(
143 : css::uno::Reference<css::lang::XEventListener> const & xListener )
144 : throw (css::uno::RuntimeException);
145 : virtual void SAL_CALL removeEventListener(
146 : css::uno::Reference<css::lang::XEventListener> const & xListener )
147 : throw (css::uno::RuntimeException);
148 :
149 : // XModifyBroadcaster
150 : virtual void SAL_CALL addModifyListener(
151 : css::uno::Reference<css::util::XModifyListener> const & xListener )
152 : throw (css::uno::RuntimeException);
153 : virtual void SAL_CALL removeModifyListener(
154 : css::uno::Reference<css::util::XModifyListener> const & xListener )
155 : throw (css::uno::RuntimeException);
156 :
157 : // XPackage
158 : virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
159 : createAbortChannel() throw (css::uno::RuntimeException);
160 : virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
161 : SAL_CALL isRegistered(
162 : css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
164 : throw (css::deployment::DeploymentException,
165 : css::ucb::CommandFailedException,
166 : css::ucb::CommandAbortedException,
167 : css::uno::RuntimeException);
168 :
169 : virtual ::sal_Int32 SAL_CALL checkPrerequisites(
170 : const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
171 : const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
172 : sal_Bool noLicenseChecking)
173 : throw (css::deployment::DeploymentException,
174 : css::deployment::ExtensionRemovedException,
175 : css::ucb::CommandFailedException,
176 : css::ucb::CommandAbortedException,
177 : css::uno::RuntimeException);
178 :
179 : virtual ::sal_Bool SAL_CALL checkDependencies(
180 : const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv )
181 : throw (css::deployment::DeploymentException,
182 : css::deployment::ExtensionRemovedException,
183 : css::ucb::CommandFailedException,
184 : css::uno::RuntimeException);
185 :
186 : virtual void SAL_CALL registerPackage(
187 : sal_Bool startup,
188 : css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
189 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
190 : throw (css::deployment::DeploymentException,
191 : css::deployment::ExtensionRemovedException,
192 : css::ucb::CommandFailedException,
193 : css::ucb::CommandAbortedException,
194 : css::lang::IllegalArgumentException, css::uno::RuntimeException);
195 : virtual void SAL_CALL revokePackage(
196 : sal_Bool startup,
197 : css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
198 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
199 : throw (css::deployment::DeploymentException,
200 : css::ucb::CommandFailedException,
201 : css::ucb::CommandAbortedException,
202 : css::lang::IllegalArgumentException,
203 : css::uno::RuntimeException);
204 : virtual sal_Bool SAL_CALL isBundle()
205 : throw (css::uno::RuntimeException);
206 : virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
207 : SAL_CALL getBundle(
208 : css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
209 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
210 : throw (css::deployment::DeploymentException,
211 : css::ucb::CommandFailedException,
212 : css::ucb::CommandAbortedException,
213 : css::lang::IllegalArgumentException,
214 : css::uno::RuntimeException);
215 : virtual ::rtl::OUString SAL_CALL getName()
216 : throw (css::uno::RuntimeException);
217 : virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getIdentifier()
218 : throw (css::uno::RuntimeException);
219 : virtual ::rtl::OUString SAL_CALL getVersion()
220 : throw (css::deployment::ExtensionRemovedException,
221 : css::uno::RuntimeException);
222 : virtual ::rtl::OUString SAL_CALL getURL()
223 : throw (css::uno::RuntimeException);
224 : virtual ::rtl::OUString SAL_CALL getDisplayName()
225 : throw (css::deployment::ExtensionRemovedException,
226 : css::uno::RuntimeException);
227 : virtual ::rtl::OUString SAL_CALL getDescription()
228 : throw (css::deployment::ExtensionRemovedException,
229 : css::uno::RuntimeException);
230 : virtual ::rtl::OUString SAL_CALL getLicenseText()
231 : throw (css::deployment::ExtensionRemovedException,
232 : css::uno::RuntimeException);
233 : virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL
234 : getUpdateInformationURLs()
235 : throw (css::deployment::ExtensionRemovedException,
236 : css::uno::RuntimeException);
237 : virtual css::beans::StringPair SAL_CALL getPublisherInfo()
238 : throw (css::deployment::ExtensionRemovedException,
239 : css::uno::RuntimeException);
240 : virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
241 : getIcon( sal_Bool bHighContrast )
242 : throw (css::deployment::ExtensionRemovedException,
243 : css::uno::RuntimeException);
244 : virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
245 : getPackageType() throw (css::uno::RuntimeException);
246 : virtual void SAL_CALL exportTo(
247 : ::rtl::OUString const & destFolderURL,
248 : ::rtl::OUString const & newTitle,
249 : sal_Int32 nameClashAction,
250 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
251 : throw (css::deployment::ExtensionRemovedException,
252 : css::ucb::CommandFailedException,
253 : css::ucb::CommandAbortedException, css::uno::RuntimeException);
254 : virtual ::rtl::OUString SAL_CALL getRepositoryName()
255 : throw (css::uno::RuntimeException);
256 : virtual css::beans::Optional< ::rtl::OUString > SAL_CALL getRegistrationDataURL()
257 : throw (css::deployment::ExtensionRemovedException,
258 : css::uno::RuntimeException);
259 : virtual sal_Bool SAL_CALL isRemoved()
260 : throw (css::uno::RuntimeException);
261 :
262 : };
263 :
264 : typedef ::cppu::WeakComponentImplHelper2<
265 : css::lang::XEventListener,
266 : css::deployment::XPackageRegistry > t_BackendBase;
267 :
268 : //==============================================================================
269 : class PackageRegistryBackend
270 : : protected ::dp_misc::MutexHolder, public t_BackendBase
271 : {
272 : //The map held originally WeakReferences. The map entries are removed in the disposing
273 : //function, which is called when the XPackages are destructed or they are
274 : //explicitly disposed. The latter happens, for example, when a extension is
275 : //removed (see dp_manager.cxx). However, because of how the help systems work, now
276 : // XPackageManager::getDeployedPackages is called often. This results in a lot
277 : //of bindPackage calls which are costly. Therefore we keep hard references in
278 : //the map now.
279 : typedef ::boost::unordered_map<
280 : ::rtl::OUString, css::uno::Reference<css::deployment::XPackage>,
281 : ::rtl::OUStringHash > t_string2ref;
282 : t_string2ref m_bound;
283 :
284 : protected:
285 : ::rtl::OUString m_cachePath;
286 : css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
287 :
288 : ::rtl::OUString m_context;
289 : // currently only for library containers:
290 : enum {
291 : CONTEXT_UNKNOWN,
292 : CONTEXT_USER, CONTEXT_SHARED,CONTEXT_BUNDLED, CONTEXT_TMP,
293 : CONTEXT_DOCUMENT
294 : } m_eContext;
295 : bool m_readOnly;
296 :
297 : struct StrCannotDetectMediaType : public ::dp_misc::StaticResourceString<
298 : StrCannotDetectMediaType, RID_STR_CANNOT_DETECT_MEDIA_TYPE> {};
299 : struct StrUnsupportedMediaType : public ::dp_misc::StaticResourceString<
300 : StrUnsupportedMediaType, RID_STR_UNSUPPORTED_MEDIA_TYPE> {};
301 :
302 : // @@@ to be implemented by specific backend:
303 : virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
304 : ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
305 : sal_Bool bRemoved, ::rtl::OUString const & identifier,
306 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
307 : = 0;
308 :
309 : void check();
310 : virtual void SAL_CALL disposing();
311 :
312 : virtual ~PackageRegistryBackend();
313 : PackageRegistryBackend(
314 : css::uno::Sequence<css::uno::Any> const & args,
315 : css::uno::Reference<css::uno::XComponentContext> const & xContext );
316 :
317 : /* creates a folder with a unique name.
318 : If url is empty then it is created in the the backend folder, otherwise
319 : at a location relative to that folder specified by url.
320 : */
321 : ::rtl::OUString createFolder(
322 : ::rtl::OUString const & relUrl,
323 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
324 : /* deletes folders and files.
325 :
326 : All folder all files which end with ".tmp" or ".tmp_" and which are
327 : not used are deleted.
328 : */
329 : void deleteUnusedFolders(
330 : ::rtl::OUString const & relUrl,
331 : ::std::list< ::rtl::OUString> const & usedFolders);
332 : /* deletes one folder with a "temporary" name and the corresponding
333 : tmp file, which was used to derive the folder name.
334 : */
335 : static void deleteTempFolder(
336 : ::rtl::OUString const & folderUrl);
337 :
338 : ::rtl::OUString getSharedRegistrationDataURL(
339 : css::uno::Reference<css::deployment::XPackage> const & extension,
340 : css::uno::Reference<css::deployment::XPackage> const & item);
341 :
342 : /* The backends must implement this function, which is called
343 : from XPackageRegistry::packageRemoved (also implemented here).
344 : This ensure that the backends clean up their registration data
345 : when an extension was removed.
346 : */
347 : // virtual void deleteDbEntry( ::rtl::OUString const & url) = 0;
348 :
349 :
350 :
351 : public:
352 : struct StrRegisteringPackage : public ::dp_misc::StaticResourceString<
353 : StrRegisteringPackage, RID_STR_REGISTERING_PACKAGE> {};
354 : struct StrRevokingPackage : public ::dp_misc::StaticResourceString<
355 : StrRevokingPackage, RID_STR_REVOKING_PACKAGE> {};
356 :
357 : inline css::uno::Reference<css::uno::XComponentContext> const &
358 0 : getComponentContext() const { return m_xComponentContext; }
359 :
360 0 : inline ::rtl::OUString const & getCachePath() const { return m_cachePath; }
361 0 : inline bool transientMode() const { return m_cachePath.isEmpty(); }
362 :
363 0 : inline ::rtl::OUString getContext() const {return m_context; }
364 :
365 : // XEventListener
366 : virtual void SAL_CALL disposing( css::lang::EventObject const & evt )
367 : throw (css::uno::RuntimeException);
368 :
369 : // XPackageRegistry
370 : virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
371 : ::rtl::OUString const & url, ::rtl::OUString const & mediaType,
372 : sal_Bool bRemoved, ::rtl::OUString const & identifier,
373 : css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
374 : throw (css::deployment::DeploymentException,
375 : css::deployment::InvalidRemovedParameterException,
376 : css::ucb::CommandFailedException,
377 : css::lang::IllegalArgumentException, css::uno::RuntimeException);
378 :
379 : // virtual void SAL_CALL packageRemoved(
380 : // ::rtl::OUString const & url, ::rtl::OUString const & mediaType)
381 : // throw (css::deployment::DeploymentException,
382 : // css::uno::RuntimeException);
383 :
384 : };
385 :
386 : }
387 : }
388 :
389 : #endif
390 :
391 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|