Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/desktop/source/deployment/manager/dp_commandenvironments.cxx
Line
Count
Source
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
21
#include <com/sun/star/deployment/VersionException.hpp>
22
#include <com/sun/star/deployment/LicenseException.hpp>
23
#include <com/sun/star/deployment/InstallException.hpp>
24
#include <com/sun/star/deployment/DependencyException.hpp>
25
#include <com/sun/star/deployment/PlatformException.hpp>
26
#include <com/sun/star/task/XInteractionApprove.hpp>
27
#include <utility>
28
#include "dp_commandenvironments.hxx"
29
#include <osl/diagnose.h>
30
31
namespace deployment = css::deployment;
32
namespace task = css::task;
33
namespace ucb = css::ucb;
34
namespace uno = css::uno;
35
36
using css::uno::Reference;
37
38
namespace dp_manager {
39
40
BaseCommandEnv::BaseCommandEnv()
41
0
{
42
0
}
43
44
BaseCommandEnv::BaseCommandEnv(
45
    Reference< task::XInteractionHandler> const & handler)
46
0
    : m_forwardHandler(handler)
47
0
{
48
0
}
49
50
BaseCommandEnv::~BaseCommandEnv()
51
0
{
52
0
}
53
// XCommandEnvironment
54
55
Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
56
0
{
57
0
    return this;
58
0
}
59
60
61
Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
62
0
{
63
0
    return this;
64
0
}
65
66
void BaseCommandEnv::handle(
67
    Reference< task::XInteractionRequest> const & /*xRequest*/ )
68
0
{
69
0
}
70
71
void BaseCommandEnv::handle_(bool approve,
72
                             Reference< task::XInteractionRequest> const & xRequest )
73
0
{
74
0
    if (!approve)
75
0
    {
76
        //not handled so far -> forwarding
77
0
        if (m_forwardHandler.is())
78
0
            m_forwardHandler->handle(xRequest);
79
0
        else
80
0
            return; //cannot handle
81
0
    }
82
0
    else
83
0
    {
84
        // select:
85
0
        for (auto& xContinuation : xRequest->getContinuations())
86
0
        {
87
0
            Reference<task::XInteractionApprove> xInteractionApprove(xContinuation, uno::UNO_QUERY);
88
0
            if (xInteractionApprove.is())
89
0
            {
90
0
                xInteractionApprove->select();
91
                // don't query again for ongoing continuations:
92
0
                break;
93
0
            }
94
0
        }
95
0
    }
96
97
0
}
98
99
// XProgressHandler
100
void BaseCommandEnv::push( uno::Any const & /*Status*/ )
101
0
{
102
0
}
103
104
void BaseCommandEnv::update( uno::Any const & /*Status */)
105
0
{
106
0
}
107
108
void BaseCommandEnv::pop()
109
0
{
110
0
}
111
112
113
TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
114
0
{
115
0
}
116
117
TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
118
    css::uno::Reference< css::task::XInteractionHandler> const & handler):
119
0
    BaseCommandEnv(handler)
120
0
{
121
0
}
122
// XInteractionHandler
123
void TmpRepositoryCommandEnv::handle(
124
    Reference< task::XInteractionRequest> const & xRequest )
125
0
{
126
0
    uno::Any request( xRequest->getRequest() );
127
0
    OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
128
129
0
    deployment::VersionException verExc;
130
0
    deployment::LicenseException licExc;
131
0
    deployment::InstallException instExc;
132
133
0
    bool approve = false;
134
135
0
    if ((request >>= verExc)
136
0
        || (request >>= licExc)
137
0
        || (request >>= instExc))
138
0
    {
139
0
        approve = true;
140
0
    }
141
142
0
    handle_(approve, xRequest);
143
0
}
144
145
146
LicenseCommandEnv::LicenseCommandEnv(
147
    css::uno::Reference< css::task::XInteractionHandler> const & handler,
148
    bool bSuppressLicense,
149
    OUString repository):
150
0
    BaseCommandEnv(handler), m_repository(std::move(repository)),
151
0
    m_bSuppressLicense(bSuppressLicense)
152
0
{
153
0
}
154
// XInteractionHandler
155
void LicenseCommandEnv::handle(
156
    Reference< task::XInteractionRequest> const & xRequest )
157
0
{
158
0
    uno::Any request( xRequest->getRequest() );
159
0
    OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
160
161
0
    deployment::LicenseException licExc;
162
163
0
    bool approve = false;
164
165
0
    if (request >>= licExc)
166
0
    {
167
0
        if (m_bSuppressLicense
168
0
            || m_repository == "bundled"
169
0
            || licExc.AcceptBy == "admin")
170
0
        {
171
            //always approve in bundled case, because we do not support
172
            //showing licenses anyway.
173
            //The "admin" already accepted the license when installing the
174
            // shared extension
175
0
            approve = true;
176
0
        }
177
0
    }
178
179
0
    handle_(approve, xRequest);
180
0
}
181
182
183
NoLicenseCommandEnv::NoLicenseCommandEnv(
184
    css::uno::Reference< css::task::XInteractionHandler> const & handler):
185
0
    BaseCommandEnv(handler)
186
0
{
187
0
}
188
// XInteractionHandler
189
void NoLicenseCommandEnv::handle(
190
    Reference< task::XInteractionRequest> const & xRequest )
191
0
{
192
0
    uno::Any request( xRequest->getRequest() );
193
0
    OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
194
195
0
    deployment::LicenseException licExc;
196
197
0
    bool approve = false;
198
199
0
    if (request >>= licExc)
200
0
    {
201
0
        approve = true;
202
0
    }
203
0
    handle_(approve, xRequest);
204
0
}
205
206
SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
207
0
{
208
0
}
209
210
void SilentCheckPrerequisitesCommandEnv::handle(
211
       Reference< task::XInteractionRequest> const & xRequest )
212
0
{
213
0
    uno::Any request( xRequest->getRequest() );
214
0
    OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
215
216
0
    deployment::LicenseException licExc;
217
0
    deployment::PlatformException platformExc;
218
0
    deployment::DependencyException depExc;
219
220
0
    if (request >>= licExc)
221
0
    {
222
0
        handle_(true, xRequest); // approve = true
223
0
    }
224
0
    else if ((request >>= platformExc)
225
0
             || (request >>= depExc))
226
0
    {
227
0
        m_Exception = std::move(request);
228
0
    }
229
0
    else
230
0
    {
231
0
        m_UnknownException = std::move(request);
232
0
    }
233
0
}
234
235
}
236
237
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */