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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_desktop.hxx" 26 27 #include "com/sun/star/deployment/VersionException.hpp" 28 #include "com/sun/star/deployment/LicenseException.hpp" 29 #include "com/sun/star/deployment/InstallException.hpp" 30 #include "com/sun/star/deployment/DependencyException.hpp" 31 #include "com/sun/star/deployment/PlatformException.hpp" 32 #include "com/sun/star/task/XInteractionApprove.hpp" 33 #include "com/sun/star/task/XInteractionAbort.hpp" 34 #include "com/sun/star/task/XInteractionHandler.hpp" 35 #include "com/sun/star/ucb/XCommandEnvironment.hpp" 36 #include "com/sun/star/uno/XComponentContext.hpp" 37 #include "dp_commandenvironments.hxx" 38 39 namespace deployment = com::sun::star::deployment; 40 namespace lang = com::sun::star::lang; 41 namespace task = com::sun::star::task; 42 namespace ucb = com::sun::star::ucb; 43 namespace uno = com::sun::star::uno; 44 namespace css = com::sun::star; 45 46 #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 47 48 using ::com::sun::star::uno::Reference; 49 using ::rtl::OUString; 50 51 namespace dp_manager { 52 53 BaseCommandEnv::BaseCommandEnv() 54 { 55 } 56 57 BaseCommandEnv::BaseCommandEnv( 58 Reference< task::XInteractionHandler> const & handler) 59 : m_forwardHandler(handler) 60 { 61 } 62 63 BaseCommandEnv::~BaseCommandEnv() 64 { 65 } 66 // XCommandEnvironment 67 //______________________________________________________________________________ 68 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler() 69 { 70 return this; 71 } 72 73 //______________________________________________________________________________ 74 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler() 75 { 76 return this; 77 } 78 79 void BaseCommandEnv::handle( 80 Reference< task::XInteractionRequest> const & /*xRequest*/ ) 81 { 82 } 83 84 void BaseCommandEnv::handle_(bool approve, bool abort, 85 Reference< task::XInteractionRequest> const & xRequest ) 86 { 87 if (approve == false && abort == false) 88 { 89 //not handled so far -> forwarding 90 if (m_forwardHandler.is()) 91 m_forwardHandler->handle(xRequest); 92 else 93 return; //cannot handle 94 } 95 else 96 { 97 // select: 98 uno::Sequence< Reference< task::XInteractionContinuation > > conts( 99 xRequest->getContinuations() ); 100 Reference< task::XInteractionContinuation > const * pConts = 101 conts.getConstArray(); 102 sal_Int32 len = conts.getLength(); 103 for ( sal_Int32 pos = 0; pos < len; ++pos ) 104 { 105 if (approve) { 106 Reference< task::XInteractionApprove > xInteractionApprove( 107 pConts[ pos ], uno::UNO_QUERY ); 108 if (xInteractionApprove.is()) { 109 xInteractionApprove->select(); 110 // don't query again for ongoing continuations: 111 approve = false; 112 } 113 } 114 else if (abort) { 115 Reference< task::XInteractionAbort > xInteractionAbort( 116 pConts[ pos ], uno::UNO_QUERY ); 117 if (xInteractionAbort.is()) { 118 xInteractionAbort->select(); 119 // don't query again for ongoing continuations: 120 abort = false; 121 } 122 } 123 } 124 } 125 126 } 127 128 // XProgressHandler 129 void BaseCommandEnv::push( uno::Any const & /*Status*/ ) 130 { 131 } 132 133 134 void BaseCommandEnv::update( uno::Any const & /*Status */) 135 { 136 } 137 138 void BaseCommandEnv::pop() 139 { 140 } 141 //============================================================================== 142 143 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() 144 { 145 } 146 147 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv( 148 css::uno::Reference< css::task::XInteractionHandler> const & handler): 149 BaseCommandEnv(handler) 150 { 151 } 152 // XInteractionHandler 153 void TmpRepositoryCommandEnv::handle( 154 Reference< task::XInteractionRequest> const & xRequest ) 155 { 156 uno::Any request( xRequest->getRequest() ); 157 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 158 159 deployment::VersionException verExc; 160 deployment::LicenseException licExc; 161 deployment::InstallException instExc; 162 163 bool approve = false; 164 bool abort = false; 165 166 if ((request >>= verExc) 167 || (request >>= licExc) 168 || (request >>= instExc)) 169 { 170 approve = true; 171 } 172 173 handle_(approve, abort, xRequest); 174 } 175 //================================================================================ 176 177 LicenseCommandEnv::LicenseCommandEnv( 178 css::uno::Reference< css::task::XInteractionHandler> const & handler, 179 bool bSuppressLicense, 180 OUString const & repository): 181 BaseCommandEnv(handler), m_repository(repository), 182 m_bSuppressLicense(bSuppressLicense) 183 { 184 } 185 // XInteractionHandler 186 void LicenseCommandEnv::handle( 187 Reference< task::XInteractionRequest> const & xRequest ) 188 { 189 uno::Any request( xRequest->getRequest() ); 190 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 191 192 193 deployment::LicenseException licExc; 194 195 bool approve = false; 196 bool abort = false; 197 198 if (request >>= licExc) 199 { 200 if (m_bSuppressLicense 201 || m_repository.equals(OUSTR("bundled")) 202 || licExc.AcceptBy.equals(OUSTR("admin"))) 203 { 204 //always approve in bundled case, because we do not support 205 //showing licenses anyway. 206 //The "admin" already accepted the license when installing the 207 // shared extension 208 approve = true; 209 } 210 } 211 212 handle_(approve, abort, xRequest); 213 } 214 215 //================================================================================ 216 //================================================================================ 217 218 NoLicenseCommandEnv::NoLicenseCommandEnv( 219 css::uno::Reference< css::task::XInteractionHandler> const & handler): 220 BaseCommandEnv(handler) 221 { 222 } 223 // XInteractionHandler 224 void NoLicenseCommandEnv::handle( 225 Reference< task::XInteractionRequest> const & xRequest ) 226 { 227 uno::Any request( xRequest->getRequest() ); 228 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 229 230 231 deployment::LicenseException licExc; 232 233 bool approve = false; 234 bool abort = false; 235 236 if (request >>= licExc) 237 { 238 approve = true; 239 } 240 handle_(approve, abort, xRequest); 241 } 242 243 // SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv( 244 // css::uno::Reference< css::task::XInteractionHandler> const & handler): 245 // BaseCommandEnv(handler) 246 // { 247 // } 248 SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv() 249 { 250 } 251 252 void SilentCheckPrerequisitesCommandEnv::handle( 253 Reference< task::XInteractionRequest> const & xRequest ) 254 { 255 uno::Any request( xRequest->getRequest() ); 256 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 257 258 deployment::LicenseException licExc; 259 deployment::PlatformException platformExc; 260 deployment::DependencyException depExc; 261 bool approve = false; 262 bool abort = false; 263 264 if (request >>= licExc) 265 { 266 approve = true; 267 handle_(approve, abort, xRequest); 268 } 269 else if ((request >>= platformExc) 270 || (request >>= depExc)) 271 { 272 m_Exception = request; 273 } 274 else 275 { 276 m_UnknownException = request; 277 } 278 } 279 // NoExceptionCommandEnv::NoExceptionCommandEnv( 280 // css::uno::Reference< css::task::XInteractionHandler> const & handler, 281 // css::uno::Type const & type): 282 // BaseCommandEnv(handler), 283 // m_type(type) 284 // { 285 // } 286 // // XInteractionHandler 287 // void NoExceptionCommandEnv::handle( 288 // Reference< task::XInteractionRequest> const & xRequest ) 289 // throw (uno::RuntimeException) 290 // { 291 // uno::Any request( xRequest->getRequest() ); 292 // OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION ); 293 294 295 // deployment::LicenseException licExc; 296 297 // bool approve = false; 298 // bool abort = false; 299 300 // if (request.getValueType() == m_type) 301 // { 302 // approve = true; 303 // } 304 // handle_(approve, abort, xRequest); 305 // } 306 307 308 309 } // namespace dp_manager 310