LCOV - code coverage report
Current view: top level - sfx2/source/appl - appopen.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 521 0.2 %
Date: 2014-04-14 Functions: 2 14 14.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10