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