Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/appl/appopen.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
#include <com/sun/star/uno/Reference.h>
21
#include <com/sun/star/beans/PropertyValue.hpp>
22
#include <com/sun/star/beans/NamedValue.hpp>
23
#include <com/sun/star/frame/FrameSearchFlag.hpp>
24
#include <com/sun/star/frame/XDispatchProvider.hpp>
25
#include <com/sun/star/frame/XFrame.hpp>
26
#include <com/sun/star/frame/Desktop.hpp>
27
#include <com/sun/star/frame/XModel3.hpp>
28
#include <com/sun/star/util/URL.hpp>
29
#include <com/sun/star/util/URLTransformer.hpp>
30
#include <com/sun/star/util/XURLTransformer.hpp>
31
#include <com/sun/star/system/SystemShellExecuteException.hpp>
32
#include <com/sun/star/document/XTypeDetection.hpp>
33
#include <com/sun/star/document/MacroExecMode.hpp>
34
#include <com/sun/star/document/UpdateDocMode.hpp>
35
#include <com/sun/star/task/ErrorCodeRequest.hpp>
36
#include <com/sun/star/task/InteractionHandler.hpp>
37
#include <com/sun/star/beans/XPropertySet.hpp>
38
#include <com/sun/star/embed/ElementModes.hpp>
39
#include <com/sun/star/embed/XStorage.hpp>
40
#include <com/sun/star/container/XNameAccess.hpp>
41
#include <com/sun/star/packages/WrongPasswordException.hpp>
42
#include <com/sun/star/uno/Sequence.h>
43
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
44
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
45
#include <rtl/ustring.hxx>
46
47
#include <comphelper/processfactory.hxx>
48
#include <comphelper/sequence.hxx>
49
#include <comphelper/sequenceashashmap.hxx>
50
#include <comphelper/SetFlagContextHelper.hxx>
51
#include <comphelper/storagehelper.hxx>
52
#include <comphelper/string.hxx>
53
#include <comphelper/synchronousdispatch.hxx>
54
55
#include <svl/intitem.hxx>
56
#include <svl/stritem.hxx>
57
#include <svl/eitem.hxx>
58
#include <sfx2/doctempl.hxx>
59
#include <svtools/sfxecode.hxx>
60
#include <preventduplicateinteraction.hxx>
61
#include <svtools/ehdl.hxx>
62
#include <tools/debug.hxx>
63
#include <tools/stream.hxx>
64
#include <tools/urlobj.hxx>
65
#include <unotools/pathoptions.hxx>
66
#include <unotools/securityoptions.hxx>
67
#include <unotools/moduleoptions.hxx>
68
#include <unotools/extendedsecurityoptions.hxx>
69
#include <comphelper/docpasswordhelper.hxx>
70
#include <comphelper/docpasswordrequest.hxx>
71
#include <vcl/svapp.hxx>
72
#include <vcl/weld/MessageDialog.hxx>
73
74
#include <sfx2/app.hxx>
75
#include <sfx2/bindings.hxx>
76
#include <sfx2/dispatch.hxx>
77
#include <sfx2/docfile.hxx>
78
#include <sfx2/docfilt.hxx>
79
#include <sfx2/fcontnr.hxx>
80
#include <sfx2/objitem.hxx>
81
#include <sfx2/objsh.hxx>
82
#include <svl/slstitm.hxx>
83
#include <appopen.hxx>
84
#include <sfx2/request.hxx>
85
#include <sfx2/sfxresid.hxx>
86
#include <sfx2/viewsh.hxx>
87
#include <sfx2/strings.hrc>
88
#include <sfx2/viewfrm.hxx>
89
#include <sfx2/sfxuno.hxx>
90
#include <sfx2/objface.hxx>
91
#include <sfx2/filedlghelper.hxx>
92
#include <sfx2/templatedlg.hxx>
93
#include <sfx2/sfxsids.hrc>
94
#include <o3tl/string_view.hxx>
95
#include <openuriexternally.hxx>
96
97
#include <officecfg/Office/ProtocolHandler.hxx>
98
#include <officecfg/Office/Security.hxx>
99
100
using namespace ::com::sun::star;
101
using namespace ::com::sun::star::beans;
102
using namespace ::com::sun::star::frame;
103
using namespace ::com::sun::star::lang;
104
using namespace ::com::sun::star::uno;
105
using namespace ::com::sun::star::util;
106
using namespace ::com::sun::star::task;
107
using namespace ::com::sun::star::container;
108
using namespace ::cppu;
109
using namespace ::sfx2;
110
111
void SetTemplate_Impl( std::u16string_view rFileName,
112
                        const OUString &rLongName,
113
                        SfxObjectShell *pDoc)
114
0
{
115
    // write TemplateName to DocumentProperties of document
116
    // TemplateDate stays as default (=current date)
117
0
    pDoc->ResetFromTemplate( rLongName, rFileName );
118
0
}
119
120
namespace {
121
122
class SfxDocPasswordVerifier : public ::comphelper::IDocPasswordVerifier
123
{
124
public:
125
    explicit SfxDocPasswordVerifier(SfxMedium& rMedium)
126
0
        : m_rMedium(rMedium)
127
0
        , mxStorage(rMedium.GetStorage())
128
0
    {
129
0
    }
130
131
    virtual ::comphelper::DocPasswordVerifierResult
132
                        verifyPassword( const OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) override;
133
    virtual ::comphelper::DocPasswordVerifierResult
134
                        verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) override;
135
136
private:
137
    SfxMedium & m_rMedium;
138
    Reference< embed::XStorage > mxStorage;
139
};
140
141
}
142
143
::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData )
144
0
{
145
0
    o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( rPassword );
146
0
    return verifyEncryptionData( o_rEncryptionData );
147
0
}
148
149
150
::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData )
151
0
{
152
0
    ::comphelper::DocPasswordVerifierResult eResult = ::comphelper::DocPasswordVerifierResult::WrongPassword;
153
0
    try
154
0
    {
155
        // check the encryption data
156
        // if the data correct is the stream will be opened successfully
157
        // and immediately closed
158
0
        ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( mxStorage, rEncryptionData );
159
160
        // for new ODF encryption, try to extract the encrypted inner package
161
        // (it will become the SfxObjectShell storage)
162
0
        if (!m_rMedium.TryEncryptedInnerPackage(mxStorage))
163
0
        {   // ... old ODF encryption:
164
0
            mxStorage->openStreamElement(
165
0
                u"content.xml"_ustr,
166
0
                embed::ElementModes::READ | embed::ElementModes::NOCREATE );
167
0
        }
168
169
        // no exception -> success
170
0
        eResult = ::comphelper::DocPasswordVerifierResult::OK;
171
0
    }
172
0
    catch( const packages::WrongPasswordException& )
173
0
    {
174
0
        eResult = ::comphelper::DocPasswordVerifierResult::WrongPassword;
175
0
    }
176
0
    catch( const uno::Exception& )
177
0
    {
178
        // unknown error, report it as wrong password
179
        // TODO/LATER: we need an additional way to report unknown problems in this case
180
0
        eResult = ::comphelper::DocPasswordVerifierResult::WrongPassword;
181
0
    }
182
0
    return eResult;
183
0
}
184
185
186
ErrCode CheckPasswd_Impl
187
(
188
    SfxObjectShell*  pDoc,
189
    SfxMedium*       pFile      // the Medium and its Password should be obtained
190
)
191
192
/*  [Description]
193
194
    Ask for the password for a medium, only works if it concerns storage.
195
    If the password flag is set in the Document Info, then the password is
196
    requested through a user dialogue and the set at the Set of the medium.
197
    If the set does not exist the it is created.
198
*/
199
0
{
200
0
    ErrCode nRet = ERRCODE_NONE;
201
202
0
    if( !pFile->GetFilter() || pFile->IsStorage() )
203
0
    {
204
0
        uno::Reference< embed::XStorage > xStorage = pFile->GetStorage();
205
0
        if( xStorage.is() )
206
0
        {
207
0
            uno::Reference< beans::XPropertySet > xStorageProps( xStorage, uno::UNO_QUERY );
208
0
            if ( xStorageProps.is() )
209
0
            {
210
0
                bool bIsEncrypted = false;
211
0
                uno::Sequence< uno::Sequence< beans::NamedValue > > aGpgProperties;
212
0
                try {
213
0
                    xStorageProps->getPropertyValue(u"HasEncryptedEntries"_ustr)
214
0
                        >>= bIsEncrypted;
215
0
                    xStorageProps->getPropertyValue(u"EncryptionGpGProperties"_ustr)
216
0
                        >>= aGpgProperties;
217
0
                } catch( uno::Exception& )
218
0
                {
219
                    // TODO/LATER:
220
                    // the storage either has no encrypted elements or it's just
221
                    // does not allow to detect it, probably it should be implemented later
222
0
                }
223
224
0
                if ( bIsEncrypted )
225
0
                {
226
0
                    css::uno::Reference<css::awt::XWindow> xWin(pDoc ? pDoc->GetDialogParent(pFile) : nullptr);
227
0
                    if (xWin)
228
0
                        xWin->setVisible(true);
229
230
0
                    nRet = ERRCODE_SFX_CANTGETPASSWD;
231
232
0
                    SfxItemSet& rSet = pFile->GetItemSet();
233
0
                    Reference< css::task::XInteractionHandler > xInteractionHandler = pFile->GetInteractionHandler();
234
0
                    if( xInteractionHandler.is() )
235
0
                    {
236
                        // use the comphelper password helper to request a password
237
0
                        OUString aPassword;
238
0
                        const SfxStringItem* pPasswordItem = rSet.GetItem(SID_PASSWORD, false);
239
0
                        if ( pPasswordItem )
240
0
                            aPassword = pPasswordItem->GetValue();
241
242
0
                        uno::Sequence< beans::NamedValue > aEncryptionData;
243
0
                        const SfxUnoAnyItem* pEncryptionDataItem = rSet.GetItem(SID_ENCRYPTIONDATA, false);
244
0
                        if ( pEncryptionDataItem )
245
0
                            pEncryptionDataItem->GetValue() >>= aEncryptionData;
246
247
                        // try if one of the public key entries is
248
                        // decryptable, then extract session key
249
                        // from it
250
0
                        if ( !aEncryptionData.hasElements() && aGpgProperties.hasElements() )
251
0
                            aEncryptionData = ::comphelper::DocPasswordHelper::decryptGpgSession(aGpgProperties);
252
253
                        // tdf#93389: if recovering a document, encryption data should contain
254
                        // entries for the real filter, not only for recovery ODF, to keep it
255
                        // encrypted. Pass this in encryption data.
256
                        // TODO: pass here the real filter (from AutoRecovery::implts_openDocs)
257
                        // to marshal this to requestAndVerifyDocPassword
258
0
                        if (rSet.GetItemState(SID_DOC_SALVAGE, false) == SfxItemState::SET)
259
0
                        {
260
0
                            aEncryptionData = comphelper::concatSequences(
261
0
                                aEncryptionData, std::initializer_list<beans::NamedValue>{
262
0
                                                     { u"ForSalvage"_ustr, css::uno::Any(true) } });
263
0
                        }
264
265
0
                        SfxDocPasswordVerifier aVerifier(*pFile);
266
0
                        aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword(
267
0
                            aVerifier, aEncryptionData, aPassword, xInteractionHandler, pFile->GetOrigURL(), comphelper::DocPasswordRequestType::Standard );
268
269
0
                        rSet.ClearItem( SID_PASSWORD );
270
0
                        rSet.ClearItem( SID_ENCRYPTIONDATA );
271
272
0
                        if ( aEncryptionData.hasElements() )
273
0
                        {
274
0
                            rSet.Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::Any( aEncryptionData ) ) );
275
276
0
                            try
277
0
                            {
278
                                // update the version list of the medium using the new password
279
0
                                pFile->GetVersionList();
280
0
                            }
281
0
                            catch( uno::Exception& )
282
0
                            {
283
                                // TODO/LATER: set the error code
284
0
                            }
285
286
0
                            nRet = ERRCODE_NONE;
287
0
                        }
288
0
                        else
289
0
                            nRet = ERRCODE_IO_ABORT;
290
0
                    }
291
0
                }
292
0
            }
293
0
            else
294
0
            {
295
0
                OSL_FAIL( "A storage must implement XPropertySet interface!" );
296
0
                nRet = ERRCODE_SFX_CANTGETPASSWD;
297
0
            }
298
0
        }
299
0
    }
300
301
0
    return nRet;
302
0
}
303
304
305
ErrCodeMsg SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &rFileName, std::unique_ptr<SfxItemSet> pSet )
306
0
{
307
0
    std::shared_ptr<const SfxFilter> pFilter;
308
0
    SfxMedium aMedium( rFileName,  ( StreamMode::READ | StreamMode::SHARE_DENYNONE ) );
309
310
0
    if ( !aMedium.GetStorage( false ).is() )
311
0
        aMedium.GetInStream();
312
313
0
    if ( aMedium.GetErrorIgnoreWarning() )
314
0
    {
315
0
        return aMedium.GetErrorCode();
316
0
    }
317
318
0
    aMedium.UseInteractionHandler( true );
319
0
    ErrCode nErr = GetFilterMatcher().GuessFilter( aMedium, pFilter, SfxFilterFlags::TEMPLATE, SfxFilterFlags::NONE );
320
0
    if ( ERRCODE_NONE != nErr)
321
0
    {
322
0
        return ERRCODE_SFX_NOTATEMPLATE;
323
0
    }
324
325
0
    if( !pFilter || !pFilter->IsAllowedAsTemplate() )
326
0
    {
327
0
        return ERRCODE_SFX_NOTATEMPLATE;
328
0
    }
329
330
0
    if ( pFilter->GetFilterFlags() & SfxFilterFlags::STARONEFILTER )
331
0
    {
332
0
        DBG_ASSERT( !xDoc.Is(), "Sorry, not implemented!" );
333
0
        SfxStringItem aName( SID_FILE_NAME, rFileName );
334
0
        SfxStringItem aReferer( SID_REFERER, u"private:user"_ustr );
335
0
        SfxStringItem aFlags( SID_OPTIONS, u"T"_ustr );
336
0
        SfxBoolItem aHidden( SID_HIDDEN, true );
337
0
        const SfxPoolItemHolder aRet(GetDispatcher_Impl()->ExecuteList(
338
0
            SID_OPENDOC, SfxCallMode::SYNCHRON,
339
0
            { &aName, &aHidden, &aReferer, &aFlags } ));
340
0
        const SfxObjectItem* pObj(dynamic_cast<const SfxObjectItem*>(aRet.getItem()));
341
0
        if ( pObj )
342
0
            xDoc = dynamic_cast<SfxObjectShell*>( pObj->GetShell()  );
343
0
        else
344
0
        {
345
0
            const SfxViewFrameItem* pView(dynamic_cast<const SfxViewFrameItem*>(aRet.getItem()));
346
0
            if ( pView )
347
0
            {
348
0
                SfxViewFrame *pFrame = pView->GetFrame();
349
0
                if ( pFrame )
350
0
                    xDoc = pFrame->GetObjectShell();
351
0
            }
352
0
        }
353
354
0
        if ( !xDoc.Is() )
355
0
            return ERRCODE_SFX_DOLOADFAILED;
356
0
    }
357
0
    else
358
0
    {
359
0
        if ( !xDoc.Is() )
360
0
            xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() );
361
362
        //pMedium takes ownership of pSet
363
0
        SfxMedium *pMedium = new SfxMedium(rFileName, StreamMode::STD_READ, std::move(pFilter), std::move(pSet));
364
0
        if(!xDoc->DoLoad(pMedium))
365
0
        {
366
0
            ErrCodeMsg nErrCode = xDoc->GetErrorCode();
367
0
            xDoc->DoClose();
368
0
            xDoc.Clear();
369
0
            return nErrCode;
370
0
        }
371
0
    }
372
373
0
    try
374
0
    {
375
        // TODO: introduce error handling
376
377
0
        uno::Reference< embed::XStorage > xTempStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
378
0
        if( !xTempStorage.is() )
379
0
            throw uno::RuntimeException();
380
381
0
        xDoc->GetStorage()->copyToStorage( xTempStorage );
382
383
0
        if ( !xDoc->DoSaveCompleted( new SfxMedium( xTempStorage, OUString() ) ) )
384
0
            throw uno::RuntimeException();
385
0
    }
386
0
    catch( uno::Exception& )
387
0
    {
388
0
        xDoc->DoClose();
389
0
        xDoc.Clear();
390
391
        // TODO: transfer correct error outside
392
0
        return ERRCODE_SFX_GENERAL;
393
0
    }
394
395
0
    SetTemplate_Impl( rFileName, OUString(), xDoc );
396
397
0
    xDoc->SetNoName();
398
0
    xDoc->InvalidateName();
399
0
    xDoc->SetModified(false);
400
0
    xDoc->ResetError();
401
402
0
    css::uno::Reference< css::frame::XModel >  xModel = xDoc->GetModel();
403
0
    if ( xModel.is() )
404
0
    {
405
0
        std::unique_ptr<SfxItemSet> pNew = xDoc->GetMedium()->GetItemSet().Clone();
406
0
        pNew->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL );
407
0
        pNew->ClearItem( SID_FILTER_NAME );
408
0
        comphelper::SequenceAsHashMap aArgs = TransformItems(SID_OPENDOC, *pNew);
409
0
        aArgs[u"Title"_ustr] <<= xDoc->GetTitle(SFX_TITLE_DETECT);
410
0
        xModel->attachResource(OUString(), aArgs.getAsConstPropertyValueList());
411
0
    }
412
413
0
    return xDoc->GetErrorCode();
414
0
}
415
416
417
void SfxApplication::NewDocDirectExec_Impl( SfxRequest& rReq )
418
0
{
419
0
    const SfxStringItem* pFactoryItem = rReq.GetArg(SID_NEWDOCDIRECT);
420
0
    OUString aFactName;
421
0
    if ( pFactoryItem )
422
0
        aFactName = pFactoryItem->GetValue();
423
0
    else
424
0
        aFactName = SvtModuleOptions().GetDefaultModuleName();
425
426
0
    SfxRequest aReq( SID_OPENDOC, SfxCallMode::SYNCHRON, GetPool() );
427
0
    aReq.AppendItem( SfxStringItem( SID_FILE_NAME, "private:factory/" + aFactName ) );
428
0
    aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, GetFrame() ) );
429
0
    aReq.AppendItem( SfxStringItem( SID_TARGETNAME, u"_default"_ustr ) );
430
431
    // TODO/LATER: Should the other arguments be transferred as well?
432
0
    const SfxStringItem* pDefaultPathItem = rReq.GetArg<SfxStringItem>(SID_DEFAULTFILEPATH);
433
0
    if ( pDefaultPathItem )
434
0
        aReq.AppendItem( *pDefaultPathItem );
435
0
    const SfxStringItem* pDefaultNameItem = rReq.GetArg<SfxStringItem>(SID_DEFAULTFILENAME);
436
0
    if ( pDefaultNameItem )
437
0
        aReq.AppendItem( *pDefaultNameItem );
438
439
0
    SfxGetpApp()->ExecuteSlot( aReq );
440
0
    const SfxViewFrameItem* pItem(dynamic_cast<const SfxViewFrameItem*>(aReq.GetReturnValue().getItem()));
441
0
    if (nullptr != pItem)
442
0
        rReq.SetReturnValue(SfxFrameItem(0, pItem->GetFrame()));
443
0
}
444
445
void SfxApplication::NewDocDirectState_Impl( SfxItemSet &rSet )
446
0
{
447
0
    rSet.Put(SfxStringItem(SID_NEWDOCDIRECT, "private:factory/" + SvtModuleOptions().GetDefaultModuleName()));
448
0
}
449
450
void SfxApplication::NewDocExec_Impl( SfxRequest& rReq )
451
0
{
452
    // No Parameter from BASIC only Factory given?
453
0
    const SfxStringItem* pTemplNameItem = rReq.GetArg(SID_TEMPLATE_NAME);
454
0
    const SfxStringItem* pTemplFileNameItem = rReq.GetArg(SID_FILE_NAME);
455
0
    const SfxStringItem* pTemplRegionNameItem = rReq.GetArg(SID_TEMPLATE_REGIONNAME);
456
457
0
    SfxObjectShellLock xDoc;
458
459
0
    OUString  aTemplateRegion, aTemplateName, aTemplateFileName;
460
0
    bool    bDirect = false; // through FileName instead of Region/Template
461
0
    SfxErrorContext aEc(ERRCTX_SFX_NEWDOC);
462
0
    if ( !pTemplNameItem && !pTemplFileNameItem )
463
0
    {
464
0
        bool bNewWin = false;
465
0
        weld::Window* pTopWin = GetTopWindow();
466
467
0
        SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
468
0
        Reference<XModel> xModel;
469
0
        if(pCurrentShell)
470
0
            xModel = pCurrentShell->GetModel();
471
472
0
        SfxTemplateManagerDlg aTemplDlg(rReq.GetFrameWeld());
473
474
0
        if (xModel.is())
475
0
            aTemplDlg.setDocumentModel(xModel);
476
477
0
        int nRet = aTemplDlg.run();
478
0
        if ( nRet == RET_OK )
479
0
        {
480
0
            rReq.Done();
481
0
            if ( pTopWin != GetTopWindow() )
482
0
            {
483
                // the dialogue opens a document -> a new TopWindow appears
484
0
                pTopWin = GetTopWindow();
485
0
                bNewWin = true;
486
0
            }
487
0
        }
488
489
0
        if (bNewWin && pTopWin)
490
0
        {
491
            // after the destruction of the dialogue its parent comes to top,
492
            // but we want that the new document is on top
493
0
            pTopWin->present();
494
0
        }
495
496
0
        return;
497
0
    }
498
0
    else
499
0
    {
500
        // Template-Name
501
0
        if ( pTemplNameItem )
502
0
            aTemplateName = pTemplNameItem->GetValue();
503
504
        // Template-Region
505
0
        if ( pTemplRegionNameItem )
506
0
            aTemplateRegion = pTemplRegionNameItem->GetValue();
507
508
        // Template-File-Name
509
0
        if ( pTemplFileNameItem )
510
0
        {
511
0
            aTemplateFileName = pTemplFileNameItem->GetValue();
512
0
            bDirect = true;
513
0
        }
514
0
    }
515
516
0
    ErrCode lErr = ERRCODE_NONE;
517
0
    if ( !bDirect )
518
0
    {
519
0
        SfxDocumentTemplates aTmpFac;
520
0
        if( aTemplateFileName.isEmpty() )
521
0
            aTmpFac.GetFull( aTemplateRegion, aTemplateName, aTemplateFileName );
522
523
0
        if( aTemplateFileName.isEmpty() )
524
0
            lErr = ERRCODE_SFX_TEMPLATENOTFOUND;
525
0
    }
526
527
0
    INetURLObject aObj( aTemplateFileName );
528
0
    SfxErrorContext aEC( ERRCTX_SFX_LOADTEMPLATE, aObj.PathToFileName() );
529
530
0
    if ( lErr != ERRCODE_NONE )
531
0
    {
532
0
        ErrCode lFatalErr = lErr.IgnoreWarning();
533
0
        if ( lFatalErr )
534
0
            ErrorHandler::HandleError(lErr);
535
0
    }
536
0
    else
537
0
    {
538
0
        SfxCallMode eMode = SfxCallMode::SYNCHRON;
539
0
        SfxPoolItemHolder aResult;
540
0
        SfxStringItem aReferer( SID_REFERER, u"private:user"_ustr );
541
0
        SfxStringItem aTarget( SID_TARGETNAME, u"_default"_ustr );
542
0
        if ( !aTemplateFileName.isEmpty() )
543
0
        {
544
0
            DBG_ASSERT( aObj.GetProtocol() != INetProtocol::NotValid, "Illegal URL!" );
545
546
0
            SfxStringItem aName( SID_FILE_NAME, aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
547
0
            SfxStringItem aTemplName( SID_TEMPLATE_NAME, aTemplateName );
548
0
            SfxStringItem aTemplRegionName( SID_TEMPLATE_REGIONNAME, aTemplateRegion );
549
0
            aResult = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode,
550
0
                {&aName, &aTarget, &aReferer, &aTemplName, &aTemplRegionName});
551
0
        }
552
0
        else
553
0
        {
554
0
            SfxStringItem aName( SID_FILE_NAME, u"private:factory"_ustr );
555
0
            aResult = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode,
556
0
                    { &aName, &aTarget, &aReferer } );
557
0
        }
558
559
0
        if (aResult)
560
0
            rReq.SetReturnValue( *aResult.getItem() );
561
0
    }
562
0
}
563
564
565
namespace {
566
567
/**
568
 * Check if a given filter type should open the hyperlinked document
569
 * natively.
570
 *
571
 * @param rFilter filter object
572
 */
573
bool lcl_isFilterNativelySupported(const SfxFilter& rFilter)
574
0
{
575
0
    if (rFilter.IsOwnFormat())
576
0
        return true;
577
578
0
    const OUString& aName = rFilter.GetFilterName();
579
    // We can handle all Excel variants natively.
580
0
    return aName.startsWith("MS Excel") || aName.startsWith("Calc Office Open XML");
581
0
}
582
583
}
584
585
void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
586
0
{
587
0
    OUString aDocService;
588
0
    const SfxStringItem* pDocSrvItem = rReq.GetArg(SID_DOC_SERVICE);
589
0
    if (pDocSrvItem)
590
0
        aDocService = pDocSrvItem->GetValue();
591
592
0
    sal_uInt16 nSID = rReq.GetSlot();
593
0
    const SfxStringItem* pFileNameItem = rReq.GetArg(SID_FILE_NAME);
594
0
    if ( pFileNameItem )
595
0
    {
596
0
        OUString aCommand( pFileNameItem->GetValue() );
597
0
        const SfxSlot* pSlot = GetInterface()->GetSlot( aCommand );
598
0
        if ( pSlot )
599
0
        {
600
0
            pFileNameItem = nullptr;
601
0
        }
602
0
        else
603
0
        {
604
0
            if ( aCommand.startsWith("slot:") )
605
0
            {
606
0
                sal_uInt16 nSlotId = static_cast<sal_uInt16>(o3tl::toInt32(aCommand.subView(5)));
607
0
                if ( nSlotId == SID_OPENDOC )
608
0
                    pFileNameItem = nullptr;
609
0
            }
610
0
        }
611
0
    }
612
613
0
    if ( !pFileNameItem )
614
0
    {
615
        // get FileName from dialog
616
0
        css::uno::Sequence<OUString> aURLList;
617
0
        OUString aFilter;
618
0
        std::optional<SfxAllItemSet> pSet;
619
0
        OUString aPath;
620
0
        const SfxStringItem* pFolderNameItem = rReq.GetArg(SID_PATH);
621
0
        if ( pFolderNameItem )
622
0
            aPath = pFolderNameItem->GetValue();
623
0
        else if ( nSID == SID_OPENTEMPLATE )
624
0
        {
625
0
            aPath = SvtPathOptions().GetTemplatePath();
626
0
            if (!aPath.isEmpty())                             // if not empty then get last token
627
0
                aPath = aPath.copy(aPath.lastIndexOf(';')+1); // lastIndexOf+copy works whether separator (';') is there or not
628
0
        }
629
630
0
        sal_Int16 nDialog = SFX2_IMPL_DIALOG_CONFIG;
631
0
        const SfxBoolItem* pSystemDialogItem = rReq.GetArg(SID_FILE_DIALOG);
632
0
        if ( pSystemDialogItem )
633
0
            nDialog = pSystemDialogItem->GetValue() ? SFX2_IMPL_DIALOG_SYSTEM : SFX2_IMPL_DIALOG_OOO;
634
635
0
        const SfxBoolItem* pRemoteDialogItem = rReq.GetArg(SID_REMOTE_DIALOG);
636
0
        if ( pRemoteDialogItem && pRemoteDialogItem->GetValue())
637
0
            nDialog = SFX2_IMPL_DIALOG_REMOTE;
638
639
0
        sal_Int16 nDialogType = ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION_FILTEROPTIONS;
640
0
        FileDialogFlags eDialogFlags = FileDialogFlags::MultiSelection;
641
0
        const SfxBoolItem* pSignPDFItem = rReq.GetArg(SID_SIGNPDF);
642
0
        if (pSignPDFItem && pSignPDFItem->GetValue())
643
0
        {
644
0
            eDialogFlags |= FileDialogFlags::SignPDF;
645
0
            nDialogType = ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
646
0
        }
647
648
0
        css::uno::Sequence< OUString >  aDenyList;
649
650
0
        const SfxStringListItem* pDenyListItem = rReq.GetArg(SID_DENY_LIST);
651
0
        if ( pDenyListItem )
652
0
            pDenyListItem->GetStringList( aDenyList );
653
654
0
        std::optional<bool> bShowFilterDialog;
655
0
        weld::Window* pTopWindow = GetTopWindow();
656
0
        ErrCode nErr = sfx2::FileOpenDialog_Impl(pTopWindow,
657
0
                nDialogType,
658
0
                eDialogFlags, aURLList,
659
0
                aFilter, pSet, &aPath, nDialog, aDenyList, bShowFilterDialog);
660
661
0
        if ( nErr == ERRCODE_ABORT )
662
0
        {
663
0
            return;
664
0
        }
665
666
0
        rReq.SetArgs( *pSet );
667
0
        if ( !aFilter.isEmpty() )
668
0
            rReq.AppendItem( SfxStringItem( SID_FILTER_NAME, aFilter ) );
669
0
        rReq.AppendItem( SfxStringItem( SID_TARGETNAME, u"_default"_ustr ) );
670
0
        rReq.AppendItem( SfxStringItem( SID_REFERER, u"private:user"_ustr ) );
671
0
        pSet.reset();
672
673
0
        if (aURLList.hasElements())
674
0
        {
675
0
            if ( nSID == SID_OPENTEMPLATE )
676
0
                rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, false ) );
677
678
            // This helper wraps an existing (or may new created InteractionHandler)
679
            // intercept all incoming interactions and provide useful information
680
            // later if the following transaction was finished.
681
682
0
            rtl::Reference<sfx2::PreventDuplicateInteraction> pHandler = new sfx2::PreventDuplicateInteraction(comphelper::getProcessComponentContext());
683
0
            uno::Reference<task::XInteractionHandler> xWrappedHandler;
684
685
            // wrap existing handler or create new UUI handler
686
0
            const SfxUnoAnyItem* pInteractionItem = rReq.GetArg(SID_INTERACTIONHANDLER);
687
0
            if (pInteractionItem)
688
0
            {
689
0
                pInteractionItem->GetValue() >>= xWrappedHandler;
690
0
                rReq.RemoveItem( SID_INTERACTIONHANDLER );
691
0
            }
692
0
            if (xWrappedHandler.is())
693
0
                pHandler->setHandler(xWrappedHandler);
694
0
            else
695
0
                pHandler->useDefaultUUIHandler();
696
0
            rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,css::uno::Any(uno::Reference<task::XInteractionHandler>(pHandler))) );
697
698
            // define rules for this handler
699
0
            css::uno::Type aInteraction = ::cppu::UnoType<css::task::ErrorCodeRequest>::get();
700
0
            ::sfx2::PreventDuplicateInteraction::InteractionInfo aRule(aInteraction);
701
0
            pHandler->addInteractionRule(aRule);
702
703
0
            if (!aDocService.isEmpty())
704
0
            {
705
0
                rReq.RemoveItem(SID_DOC_SERVICE);
706
0
                rReq.AppendItem(SfxStringItem(SID_DOC_SERVICE, aDocService));
707
0
            }
708
709
            // Passes the checkbox state of "Edit Filter Settings" to filter dialogs through multiple layers of code.
710
            // Since some layers use a published API and cannot be modified directly, we use a context layer instead.
711
            // This is a one-time flag and is not stored in any configuration.
712
            // For an example of how it's used, see ScFilterOptionsObj::execute.
713
0
            std::optional<css::uno::ContextLayer> oLayer;
714
0
            if (bShowFilterDialog.has_value())
715
0
            {
716
0
                oLayer.emplace(comphelper::NewFlagContext(u"ShowFilterDialog"_ustr,
717
0
                                                          bShowFilterDialog.value()));
718
0
            }
719
720
0
            for (auto const& url : aURLList)
721
0
            {
722
0
                rReq.RemoveItem( SID_FILE_NAME );
723
0
                rReq.AppendItem( SfxStringItem( SID_FILE_NAME, url ) );
724
725
                // Run synchronous, so that not the next document is loaded
726
                // when rescheduling
727
                // TODO/LATER: use URLList argument and always remove one document after another, each step in asynchronous execution, until finished
728
                // but only if reschedule is a problem
729
0
                GetDispatcher_Impl()->Execute( SID_OPENDOC, SfxCallMode::SYNCHRON, *rReq.GetArgs() );
730
731
                // check for special interaction "NO MORE DOCUMENTS ALLOWED" and
732
                // break loop then. Otherwise we risk showing the same interaction more than once.
733
0
                if ( pHandler->getInteractionInfo(aInteraction, &aRule) )
734
0
                {
735
0
                    if (aRule.m_nCallCount > 0)
736
0
                    {
737
0
                        if (aRule.m_xRequest.is())
738
0
                        {
739
0
                            css::task::ErrorCodeRequest aRequest;
740
0
                            if (aRule.m_xRequest->getRequest() >>= aRequest)
741
0
                            {
742
0
                                if (aRequest.ErrCode == sal_Int32(sal_uInt32(ERRCODE_SFX_NOMOREDOCUMENTSALLOWED)))
743
0
                                    break;
744
0
                            }
745
0
                        }
746
0
                    }
747
0
                }
748
0
            }
749
750
0
            return;
751
0
        }
752
0
    }
753
754
0
    bool bHyperlinkUsed = false;
755
756
0
    if ( SID_OPENURL == nSID )
757
0
    {
758
        // SID_OPENURL does the same as SID_OPENDOC!
759
0
        rReq.SetSlot( SID_OPENDOC );
760
0
    }
761
0
    else if ( nSID == SID_OPENTEMPLATE )
762
0
    {
763
0
        rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, false ) );
764
0
    }
765
    // pass URL to OS by using ShellExecuter or open it internal
766
    // if it seems to be an own format.
767
    /* Attention!
768
            There exist two possibilities to open hyperlinks:
769
            a) using SID_OPENHYPERLINK (new)
770
            b) using SID_BROWSE        (old)
771
     */
772
0
    else if ( nSID == SID_OPENHYPERLINK )
773
0
    {
774
0
        rReq.SetSlot( SID_OPENDOC );
775
0
        bHyperlinkUsed = true;
776
0
    }
777
778
    // no else here! It's optional ...
779
0
    if (!bHyperlinkUsed)
780
0
    {
781
0
        const SfxBoolItem* pHyperLinkUsedItem = rReq.GetArg<SfxBoolItem>(SID_BROWSE);
782
0
        if ( pHyperLinkUsedItem )
783
0
            bHyperlinkUsed = pHyperLinkUsedItem->GetValue();
784
        // no "official" item, so remove it from ItemSet before using UNO-API
785
0
        rReq.RemoveItem( SID_BROWSE );
786
0
    }
787
788
0
    const SfxStringItem* pFileName = rReq.GetArg(SID_FILE_NAME);
789
0
    assert(pFileName && "SID_FILE_NAME is required");
790
0
    OUString aFileName = pFileName->GetValue();
791
792
0
    OUString aReferer;
793
0
    const SfxStringItem* pRefererItem = rReq.GetArg(SID_REFERER);
794
0
    if ( pRefererItem )
795
0
        aReferer = pRefererItem->GetValue();
796
797
0
    const SfxStringItem* pFileFlagsItem = rReq.GetArg(SID_OPTIONS);
798
0
    if ( pFileFlagsItem )
799
0
    {
800
0
        const OUString aFileFlags = pFileFlagsItem->GetValue().toAsciiUpperCase();
801
0
        if ( aFileFlags.indexOf('T') >= 0 )
802
0
        {
803
0
            rReq.RemoveItem( SID_TEMPLATE );
804
0
            rReq.AppendItem( SfxBoolItem( SID_TEMPLATE, true ) );
805
0
        }
806
807
0
        if ( aFileFlags.indexOf('H') >= 0 )
808
0
        {
809
0
            rReq.RemoveItem( SID_HIDDEN );
810
0
            rReq.AppendItem( SfxBoolItem( SID_HIDDEN, true ) );
811
0
        }
812
813
0
        if ( aFileFlags.indexOf('R') >= 0 )
814
0
        {
815
0
            rReq.RemoveItem( SID_DOC_READONLY );
816
0
            rReq.AppendItem( SfxBoolItem( SID_DOC_READONLY, true ) );
817
0
        }
818
819
0
        if ( aFileFlags.indexOf('B') >= 0 )
820
0
        {
821
0
            rReq.RemoveItem( SID_PREVIEW );
822
0
            rReq.AppendItem( SfxBoolItem( SID_PREVIEW, true ) );
823
0
        }
824
825
0
        rReq.RemoveItem( SID_OPTIONS );
826
0
    }
827
828
    // Mark without URL cannot be handled by hyperlink code
829
0
    if ( bHyperlinkUsed && !aFileName.isEmpty() && aFileName[0] != '#' )
830
0
    {
831
0
        uno::Reference<document::XTypeDetection> xTypeDetection(
832
0
            comphelper::getProcessServiceFactory()->createInstance(u"com.sun.star.document.TypeDetection"_ustr), UNO_QUERY);
833
834
0
        if ( xTypeDetection.is() )
835
0
        {
836
0
            URL             aURL;
837
838
0
            aURL.Complete = aFileName;
839
0
            Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
840
0
            xTrans->parseStrict( aURL );
841
842
0
            INetProtocol aINetProtocol = INetURLObject( aURL.Complete ).GetProtocol();
843
0
            auto eMode = officecfg::Office::Security::Hyperlinks::Open::get();
844
845
0
            if ( eMode == SvtExtendedSecurityOptions::OPEN_NEVER && aINetProtocol != INetProtocol::VndSunStarHelp )
846
0
            {
847
0
                SolarMutexGuard aGuard;
848
0
                weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
849
850
0
                std::unique_ptr<weld::MessageDialog> xSecurityWarningBox(Application::CreateMessageDialog(pWindow,
851
0
                                                                         VclMessageType::Warning, VclButtonsType::Ok, SfxResId(STR_SECURITY_WARNING_NO_HYPERLINKS)));
852
0
                xSecurityWarningBox->set_title(SfxResId(RID_SECURITY_WARNING_TITLE));
853
0
                xSecurityWarningBox->run();
854
0
                return;
855
0
            }
856
857
0
            std::shared_ptr<const SfxFilter> pFilter{};
858
859
            // attempt loading native documents only if they are from a known protocol
860
            // it might be sensible to limit the set of protocols even further, but that
861
            // may cause regressions, needs further testing
862
            // see tdf#136427 for details
863
0
            if (aINetProtocol != INetProtocol::NotValid) {
864
0
                const OUString aTypeName { xTypeDetection->queryTypeByURL( aURL.Main ) };
865
0
                SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher();
866
0
                pFilter = rMatcher.GetFilter4EA( aTypeName );
867
0
            }
868
869
0
            bool bStartPresentation = false;
870
0
            if (pFilter)
871
0
            {
872
0
                const SfxUInt16Item* pSlide = rReq.GetArg(SID_DOC_STARTPRESENTATION);
873
0
                if (pSlide
874
0
                    && (pFilter->GetWildcard().Matches(u".pptx")
875
0
                        || pFilter->GetWildcard().Matches(u".ppt")
876
0
                        || pFilter->GetWildcard().Matches(u".ppsx")
877
0
                        || pFilter->GetWildcard().Matches(u".pps")))
878
0
                {
879
0
                    bStartPresentation = true;
880
0
                }
881
0
            }
882
883
0
            if (!pFilter || (!lcl_isFilterNativelySupported(*pFilter) && !bStartPresentation))
884
0
            {
885
                // hyperlink does not link to own type => special handling (http, ftp) browser and (other external protocols) OS
886
0
                if ( aINetProtocol == INetProtocol::Mailto )
887
0
                {
888
                    // don't dispatch mailto hyperlink to desktop dispatcher
889
0
                    rReq.RemoveItem( SID_TARGETNAME );
890
0
                    rReq.AppendItem( SfxStringItem( SID_TARGETNAME, u"_self"_ustr ) );
891
0
                }
892
0
                else if ( aINetProtocol == INetProtocol::Ftp ||
893
0
                     aINetProtocol == INetProtocol::Http ||
894
0
                     aINetProtocol == INetProtocol::Https )
895
0
                {
896
0
                    sfx2::openUriExternally(aURL.Complete, true, rReq.GetFrameWeld());
897
0
                    return;
898
0
                }
899
0
                else
900
0
                {
901
                    // check for "internal" protocols that should not be forwarded to the system
902
                    // add special protocols that always should be treated as internal
903
0
                    std::vector < OUString > aProtocols { u"private:*"_ustr, u"vnd.sun.star.*"_ustr };
904
905
                    // get registered protocol handlers from configuration
906
0
                    Reference < XNameAccess > xAccess(officecfg::Office::ProtocolHandler::HandlerSet::get());
907
0
                    const Sequence < OUString > aNames = xAccess->getElementNames();
908
0
                    for ( const auto& rName : aNames )
909
0
                    {
910
0
                        Reference < XPropertySet > xSet;
911
0
                        Any aRet = xAccess->getByName( rName );
912
0
                        aRet >>= xSet;
913
0
                        if ( xSet.is() )
914
0
                        {
915
                            // copy protocols
916
0
                            aRet = xSet->getPropertyValue(u"Protocols"_ustr);
917
0
                            Sequence < OUString > aTmp;
918
0
                            aRet >>= aTmp;
919
920
0
                            aProtocols.insert(aProtocols.end(),std::cbegin(aTmp),std::cend(aTmp));
921
0
                        }
922
0
                    }
923
924
0
                    bool bFound = false;
925
0
                    for (const OUString & rProtocol : aProtocols)
926
0
                    {
927
0
                        WildCard aPattern(rProtocol);
928
0
                        if ( aPattern.Matches( aURL.Complete ) )
929
0
                        {
930
0
                            bFound = true;
931
0
                            break;
932
0
                        }
933
0
                    }
934
935
0
                    if ( !bFound )
936
0
                    {
937
0
                        bool bLoadInternal = false;
938
0
                        try
939
0
                        {
940
0
                            sfx2::openUriExternally(
941
0
                                aURL.Complete, pFilter == nullptr, rReq.GetFrameWeld());
942
0
                        }
943
0
                        catch ( css::system::SystemShellExecuteException& )
944
0
                        {
945
0
                            rReq.RemoveItem( SID_TARGETNAME );
946
0
                            rReq.AppendItem( SfxStringItem( SID_TARGETNAME, u"_default"_ustr ) );
947
0
                            bLoadInternal = true;
948
0
                        }
949
0
                        if ( !bLoadInternal )
950
0
                            return;
951
0
                    }
952
0
                }
953
0
            }
954
0
            else
955
0
            {
956
                // hyperlink document must be loaded into a new frame
957
0
                rReq.RemoveItem( SID_TARGETNAME );
958
0
                rReq.AppendItem( SfxStringItem( SID_TARGETNAME, u"_default"_ustr ) );
959
0
            }
960
0
        }
961
0
    }
962
963
0
    if (!SvtSecurityOptions::isSecureMacroUri(aFileName, aReferer))
964
0
    {
965
0
        SfxErrorContext aCtx( ERRCTX_SFX_OPENDOC, aFileName );
966
0
        ErrorHandler::HandleError( ERRCODE_IO_ACCESSDENIED );
967
0
        return;
968
0
    }
969
970
0
    SfxFrame* pTargetFrame = nullptr;
971
0
    Reference< XFrame > xTargetFrame;
972
973
0
    const SfxFrameItem* pFrameItem = rReq.GetArg<SfxFrameItem>(SID_DOCFRAME);
974
0
    if ( pFrameItem )
975
0
        pTargetFrame = pFrameItem->GetFrame();
976
977
0
    if ( !pTargetFrame )
978
0
    {
979
0
        const SfxUnoFrameItem* pUnoFrameItem = rReq.GetArg(SID_FILLFRAME);
980
0
        if ( pUnoFrameItem )
981
0
            xTargetFrame = pUnoFrameItem->GetFrame();
982
0
    }
983
984
0
    if (!pTargetFrame && !xTargetFrame.is())
985
0
    {
986
0
        if (const SfxViewFrame* pViewFrame = SfxViewFrame::Current())
987
0
            pTargetFrame = &pViewFrame->GetFrame();
988
0
    }
989
990
    // check if caller has set a callback
991
0
    std::unique_ptr<SfxLinkItem> pLinkItem;
992
993
    // remove from Itemset, because it confuses the parameter transformation
994
0
    if (auto pParamLinkItem = rReq.GetArg<SfxLinkItem>(SID_DONELINK))
995
0
        pLinkItem.reset(pParamLinkItem->Clone());
996
997
0
    rReq.RemoveItem( SID_DONELINK );
998
999
    // check if the view must be hidden
1000
0
    bool bHidden = false;
1001
0
    const SfxBoolItem* pHidItem = rReq.GetArg(SID_HIDDEN);
1002
0
    if ( pHidItem )
1003
0
        bHidden = pHidItem->GetValue();
1004
1005
    // This request is a UI call. We have to set the right values inside the MediaDescriptor
1006
    // for: InteractionHandler, StatusIndicator, MacroExecutionMode and DocTemplate.
1007
    // But we have to look for already existing values or for real hidden requests.
1008
0
    const SfxBoolItem* pPreviewItem = rReq.GetArg(SID_PREVIEW);
1009
0
    if (!bHidden && ( !pPreviewItem || !pPreviewItem->GetValue() ) )
1010
0
    {
1011
0
        const SfxUnoAnyItem* pInteractionItem = rReq.GetArg(SID_INTERACTIONHANDLER);
1012
0
        const SfxUInt16Item* pMacroExecItem = rReq.GetArg(SID_MACROEXECMODE);
1013
0
        const SfxUInt16Item* pDocTemplateItem = rReq.GetArg(SID_UPDATEDOCMODE);
1014
1015
0
        if (!pInteractionItem)
1016
0
        {
1017
0
            Reference < task::XInteractionHandler2 > xHdl = task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), nullptr );
1018
0
            rReq.AppendItem( SfxUnoAnyItem(SID_INTERACTIONHANDLER,css::uno::Any(xHdl)) );
1019
0
        }
1020
0
        if (!pMacroExecItem)
1021
0
            rReq.AppendItem( SfxUInt16Item(SID_MACROEXECMODE,css::document::MacroExecMode::USE_CONFIG) );
1022
0
        if (!pDocTemplateItem)
1023
0
            rReq.AppendItem( SfxUInt16Item(SID_UPDATEDOCMODE,css::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
1024
0
    }
1025
1026
    // extract target name
1027
0
    OUString aTarget;
1028
0
    const SfxStringItem* pTargetItem = rReq.GetArg(SID_TARGETNAME);
1029
0
    if ( pTargetItem )
1030
0
        aTarget = pTargetItem->GetValue();
1031
0
    else
1032
0
    {
1033
0
        const SfxBoolItem* pNewViewItem = rReq.GetArg(SID_OPEN_NEW_VIEW);
1034
0
        if ( pNewViewItem && pNewViewItem->GetValue() )
1035
0
            aTarget = "_blank" ;
1036
0
    }
1037
1038
0
    if ( bHidden )
1039
0
    {
1040
0
        aTarget = "_blank";
1041
0
        DBG_ASSERT( rReq.IsSynchronCall() || pLinkItem, "Hidden load process must be done synchronously!" );
1042
0
    }
1043
1044
0
    Reference < XController > xController;
1045
    // if a frame is given, it must be used for the starting point of the targeting mechanism
1046
    // this code is also used if asynchronous loading is possible, because loadComponent always is synchron
1047
0
    if ( !xTargetFrame.is() )
1048
0
    {
1049
0
        if ( pTargetFrame )
1050
0
        {
1051
0
            xTargetFrame = pTargetFrame->GetFrameInterface();
1052
0
        }
1053
0
        else
1054
0
        {
1055
0
            xTargetFrame = Desktop::create(::comphelper::getProcessComponentContext());
1056
0
        }
1057
0
    }
1058
1059
    // make URL ready
1060
0
    const SfxStringItem* pURLItem = rReq.GetArg(SID_FILE_NAME);
1061
0
    aFileName = pURLItem->GetValue();
1062
0
    if( aFileName.startsWith("#") ) // Mark without URL
1063
0
    {
1064
0
        SfxViewFrame *pView = pTargetFrame ? pTargetFrame->GetCurrentViewFrame() : nullptr;
1065
0
        if (!pView)
1066
0
            pView = SfxViewFrame::Current();
1067
0
        if (pView)
1068
0
            pView->GetViewShell()->JumpToMark( aFileName.copy(1) );
1069
0
        rReq.SetReturnValue( SfxViewFrameItem( pView ) );
1070
0
        return;
1071
0
    }
1072
1073
    // convert items to properties for framework API calls
1074
0
    comphelper::SequenceAsHashMap aArgs = TransformItems(SID_OPENDOC, *rReq.GetArgs());
1075
    // Any Referer (that was relevant in the above call to
1076
    // SvtSecurityOptions::isSecureMacroUri) is no longer relevant, assuming
1077
    // this "open" request is initiated directly by the user:
1078
0
    aArgs.erase(u"Referer"_ustr);
1079
1080
    // TODO/LATER: either remove LinkItem or create an asynchronous process for it
1081
0
    if( bHidden || pLinkItem || rReq.IsSynchronCall() )
1082
0
    {
1083
        // if loading must be done synchron, we must wait for completion to get a return value
1084
        // find frame by myself; I must know the exact frame to get the controller for the return value from it
1085
0
        Reference < XComponent > xComp;
1086
1087
0
        try
1088
0
        {
1089
0
            xComp = comphelper::SynchronousDispatch::dispatch(xTargetFrame, aFileName, aTarget, aArgs.getAsConstPropertyValueList());
1090
0
        }
1091
0
        catch(const RuntimeException&)
1092
0
        {
1093
0
            throw;
1094
0
        }
1095
0
        catch(const css::uno::Exception&)
1096
0
        {
1097
0
        }
1098
1099
0
        Reference < XModel > xModel( xComp, UNO_QUERY );
1100
0
        if ( xModel.is() )
1101
0
            xController = xModel->getCurrentController();
1102
0
        else
1103
0
            xController.set( xComp, UNO_QUERY );
1104
1105
0
    }
1106
0
    else
1107
0
    {
1108
0
        URL aURL;
1109
0
        aURL.Complete = aFileName;
1110
0
        Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
1111
0
        xTrans->parseStrict( aURL );
1112
1113
0
        Reference < XDispatchProvider > xProv( xTargetFrame, UNO_QUERY );
1114
0
        Reference < XDispatch > xDisp = xProv.is() ? xProv->queryDispatch( aURL, aTarget, FrameSearchFlag::ALL ) : Reference < XDispatch >();
1115
0
        if ( xDisp.is() )
1116
0
            xDisp->dispatch(aURL, aArgs.getAsConstPropertyValueList());
1117
0
    }
1118
1119
0
    if ( xController.is() )
1120
0
    {
1121
        // try to find the SfxFrame for the controller
1122
0
        SfxFrame* pCntrFrame = nullptr;
1123
0
        for ( SfxViewShell* pShell = SfxViewShell::GetFirst( false ); pShell; pShell = SfxViewShell::GetNext( *pShell, false ) )
1124
0
        {
1125
0
            if ( pShell->GetController() == xController )
1126
0
            {
1127
0
                pCntrFrame = &pShell->GetViewFrame().GetFrame();
1128
0
                break;
1129
0
            }
1130
0
        }
1131
1132
0
        if ( pCntrFrame )
1133
0
        {
1134
0
            SfxObjectShell* pSh = pCntrFrame->GetCurrentDocument();
1135
0
            DBG_ASSERT( pSh, "Controller without ObjectShell ?!" );
1136
1137
0
            rReq.SetReturnValue( SfxViewFrameItem( pCntrFrame->GetCurrentViewFrame() ) );
1138
0
        }
1139
0
    }
1140
1141
0
    if (pLinkItem)
1142
0
    {
1143
0
        const SfxPoolItem* pRetValue(rReq.GetReturnValue().getItem());
1144
0
        if (pRetValue)
1145
0
        {
1146
0
            pLinkItem->GetValue().Call(pRetValue);
1147
0
        }
1148
0
    }
1149
0
}
1150
1151
void SfxApplication::OpenRemoteExec_Impl( SfxRequest& rReq )
1152
0
{
1153
0
    rReq.AppendItem( SfxBoolItem( SID_REMOTE_DIALOG, true ) );
1154
0
    GetDispatcher_Impl()->Execute( SID_OPENDOC, SfxCallMode::SYNCHRON, *rReq.GetArgs() );
1155
0
}
1156
1157
void SfxApplication::SignPDFExec_Impl(SfxRequest& rReq)
1158
0
{
1159
0
    rReq.AppendItem(SfxBoolItem(SID_SIGNPDF, true));
1160
0
    GetDispatcher_Impl()->Execute(SID_OPENDOC, SfxCallMode::SYNCHRON, *rReq.GetArgs());
1161
0
}
1162
1163
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */