LibreOffice Module desktop (master)  1
dp_extensionmanager.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <strings.hrc>
23 #include <dp_misc.h>
24 #include <dp_shared.hxx>
25 #include <cppuhelper/compbase.hxx>
26 #include <com/sun/star/deployment/XExtensionManager.hpp>
27 #include <com/sun/star/deployment/XPackageManager.hpp>
28 #include <com/sun/star/deployment/XPackageManagerFactory.hpp>
29 #include <osl/mutex.hxx>
30 #include <vector>
31 #include <unordered_map>
32 
33 namespace dp_manager {
34 
35 typedef std::unordered_map<
36  OUString,
37  std::vector<css::uno::Reference<css::deployment::XPackage> > > id2extensions;
38 
40  public ::cppu::WeakComponentImplHelper< css::deployment::XExtensionManager, css::lang::XServiceInfo >
41 {
42 public:
43  explicit ExtensionManager( css::uno::Reference< css::uno::XComponentContext >const& xContext);
44  virtual ~ExtensionManager() override;
45 
46  void check();
47  void fireModified();
48 
49 public:
50 
51  // XServiceInfo
52  virtual OUString SAL_CALL getImplementationName() override;
53  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
54  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
55 
56 // XModifyBroadcaster
57  virtual void SAL_CALL addModifyListener(
58  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
59  virtual void SAL_CALL removeModifyListener(
60  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
61 
62 //XExtensionManager
63  virtual css::uno::Sequence<
64  css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
65  getSupportedPackageTypes() override;
66 
67  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
68  createAbortChannel() override;
69 
70  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addExtension(
71  OUString const & url,
72  css::uno::Sequence<css::beans::NamedValue> const & properties,
73  OUString const & repository,
74  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
75  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
76 
77  virtual void SAL_CALL removeExtension(
78  OUString const & identifier,
79  OUString const & filename,
80  OUString const & repository,
81  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
82  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
83 
84  virtual void SAL_CALL enableExtension(
85  css::uno::Reference<css::deployment::XPackage> const & extension,
86  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
87  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
88 
89  virtual void SAL_CALL disableExtension(
90  css::uno::Reference<css::deployment::XPackage> const & extension,
91  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
92  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
93 
94  virtual sal_Int32 SAL_CALL checkPrerequisitesAndEnable(
95  css::uno::Reference<css::deployment::XPackage> const & extension,
96  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
97  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
98 
99  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
100  SAL_CALL getDeployedExtensions(
101  OUString const & repository,
102  css::uno::Reference<css::task::XAbortChannel> const &,
103  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
104 
105  virtual css::uno::Reference< css::deployment::XPackage>
106  SAL_CALL getDeployedExtension(
107  OUString const & repository,
108  OUString const & identifier,
109  OUString const & filename,
110  css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
111 
112  virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> >
114  OUString const & identifier,
115  OUString const & filename,
116  css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
117 
118  virtual css::uno::Sequence< css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > >
119  SAL_CALL getAllExtensions(
120  css::uno::Reference<css::task::XAbortChannel> const &,
121  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
122 
123  virtual void SAL_CALL reinstallDeployedExtensions(
124  sal_Bool force, OUString const & repository,
125  css::uno::Reference< css::task::XAbortChannel> const & xAbortChannel,
126  css::uno::Reference< css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
127 
128  virtual sal_Bool SAL_CALL synchronize(
129  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
130  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
131 
132  virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
134  OUString const & repository,
135  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) override;
136 
137  virtual sal_Bool SAL_CALL isReadOnlyRepository(OUString const & repository) override;
138 
139 private:
140 
141  static OUString StrSyncRepository() { return DpResId(RID_STR_SYNCHRONIZING_REPOSITORY); }
142 
143  css::uno::Reference< css::uno::XComponentContext> m_xContext;
144  css::uno::Reference<css::deployment::XPackageManagerFactory> m_xPackageManagerFactory;
145 
146  //only to be used within addExtension
147  ::osl::Mutex m_addMutex;
148  /* contains the names of all repositories (except tmp) in order of there
149  priority. That is, the first element is "user" followed by "shared" and
150  then "bundled"
151  */
152  std::vector< OUString > m_repositoryNames;
153 
154  css::uno::Reference<css::deployment::XPackageManager> getUserRepository();
155  css::uno::Reference<css::deployment::XPackageManager> getSharedRepository();
156  css::uno::Reference<css::deployment::XPackageManager> getBundledRepository();
157  css::uno::Reference<css::deployment::XPackageManager> getTmpRepository();
158  css::uno::Reference<css::deployment::XPackageManager> getBakRepository();
159 
160  bool isUserDisabled(OUString const & identifier,
161  OUString const & filename);
162 
163  static bool isUserDisabled(
164  css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExtSameId);
165 
166  void activateExtension(
167  OUString const & identifier,
168  OUString const & fileName,
169  bool bUserDisabled, bool bStartup,
170  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
171  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
172 
173  static void activateExtension(
174  css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExt,
175  bool bUserDisabled, bool bStartup,
176  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
177  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
178 
179  std::vector<css::uno::Reference<css::deployment::XPackage> >
180  getExtensionsWithSameId(OUString const & identifier,
181  OUString const & fileName);
182 
183  css::uno::Reference<css::deployment::XPackage> backupExtension(
184  OUString const & identifier, OUString const & fileName,
185  css::uno::Reference<css::deployment::XPackageManager> const & xPackageManager,
186  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
187 
188  void checkInstall(
189  OUString const & displayName,
190  css::uno::Reference<css::ucb::XCommandEnvironment> const & cmdEnv);
191 
192  void checkUpdate(
193  OUString const & newVersion,
194  OUString const & newDisplayName,
195  css::uno::Reference<css::deployment::XPackage> const & oldExtension,
196  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
197 
198  void addExtensionsToMap(
199  id2extensions & mapExt,
200  css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > const & seqExt,
201  OUString const & repository);
202 
205  css::uno::Reference<css::deployment::XPackageManager>
206  getPackageManager(OUString const & repository);
207 
214  css::uno::Reference<css::deployment::XPackageManager> const & xPackageMgr,
215  css::uno::Sequence<css::beans::NamedValue> const & properties,
216  css::uno::Reference<css::deployment::XPackage> const & xTmpExtension,
217  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
218  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
219  css::uno::Reference<css::deployment::XPackage> & out_existingExtension );
220 
221 };
222 
223 }
224 
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< OUString, std::vector< css::uno::Reference< css::deployment::XPackage > > > id2extensions
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getExtensionsWithUnacceptedLicenses(OUString const &repository, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual void SAL_CALL reinstallDeployedExtensions(sal_Bool force, OUString const &repository, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual sal_Int32 SAL_CALL checkPrerequisitesAndEnable(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::deployment::XPackageManager > getPackageManager(OUString const &repository)
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
css::uno::Reference< css::deployment::XPackageManager > getBakRepository()
virtual css::uno::Sequence< css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > > SAL_CALL getAllExtensions(css::uno::Reference< css::task::XAbortChannel > const &, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL addExtension(OUString const &url, css::uno::Sequence< css::beans::NamedValue > const &properties, OUString const &repository, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeExtension(OUString const &identifier, OUString const &filename, OUString const &repository, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::deployment::XPackageManager > getTmpRepository()
ExtensionManager(css::uno::Reference< css::uno::XComponentContext >const &xContext)
void activateExtension(OUString const &identifier, OUString const &fileName, bool bUserDisabled, bool bStartup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
std::vector< OUString > m_repositoryNames
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getDeployedExtensions(OUString const &repository, css::uno::Reference< css::task::XAbortChannel > const &, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getExtensionsWithSameIdentifier(OUString const &identifier, OUString const &filename, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
bool doChecksForAddExtension(css::uno::Reference< css::deployment::XPackageManager > const &xPackageMgr, css::uno::Sequence< css::beans::NamedValue > const &properties, css::uno::Reference< css::deployment::XPackage > const &xTmpExtension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, css::uno::Reference< css::deployment::XPackage > &out_existingExtension)
virtual sal_Bool SAL_CALL isReadOnlyRepository(OUString const &repository) override
css::uno::Reference< css::deployment::XPackageManager > getUserRepository()
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL getDeployedExtension(OUString const &repository, OUString const &identifier, OUString const &filename, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::deployment::XPackageManagerFactory > m_xPackageManagerFactory
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::deployment::XPackage > backupExtension(OUString const &identifier, OUString const &fileName, css::uno::Reference< css::deployment::XPackageManager > const &xPackageManager, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
unsigned char sal_Bool
virtual sal_Bool SAL_CALL synchronize(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual void SAL_CALL disableExtension(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::deployment::XPackageManager > getSharedRepository()
void addExtensionsToMap(id2extensions &mapExt, css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > const &seqExt, OUString const &repository)
::boost::spirit::classic::rule< ScannerT > identifier
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2178
std::vector< css::uno::Reference< css::deployment::XPackage > > getExtensionsWithSameId(OUString const &identifier, OUString const &fileName)
css::uno::Reference< css::deployment::XPackageManager > getBundledRepository()
bool isUserDisabled(OUString const &identifier, OUString const &filename)
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
void checkUpdate(OUString const &newVersion, OUString const &newDisplayName, css::uno::Reference< css::deployment::XPackage > const &oldExtension, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackageTypeInfo > > SAL_CALL getSupportedPackageTypes() override
virtual void SAL_CALL enableExtension(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
void checkInstall(OUString const &displayName, css::uno::Reference< css::ucb::XCommandEnvironment > const &cmdEnv)
virtual OUString SAL_CALL getImplementationName() override
OUString DpResId(const char *pId)
Definition: dp_shared.hxx:36
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override