LCOV - code coverage report
Current view: top level - sfx2/source/doc - plugin.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 121 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 26 0.0 %
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 <sal/config.h>
      21             : 
      22             : #include <com/sun/star/plugin/PluginManager.hpp>
      23             : #include <com/sun/star/plugin/XPlugin.hpp>
      24             : #include <com/sun/star/plugin/XPluginManager.hpp>
      25             : #include <com/sun/star/plugin/PluginMode.hpp>
      26             : #include <com/sun/star/awt/XControl.hpp>
      27             : #include <com/sun/star/awt/PosSize.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
      30             : #include <com/sun/star/lang/XEventListener.hpp>
      31             : #include <com/sun/star/lang/XServiceInfo.hpp>
      32             : #include <com/sun/star/util/XCloseable.hpp>
      33             : 
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <cppuhelper/implbase5.hxx>
      36             : #include <cppuhelper/supportsservice.hxx>
      37             : #include <rtl/ref.hxx>
      38             : #include <rtl/ustring.hxx>
      39             : #include <svl/itemprop.hxx>
      40             : #include <svl/ownlist.hxx>
      41             : #include <svtools/miscopt.hxx>
      42             : #include <toolkit/helper/vclunohelper.hxx>
      43             : #include <vcl/window.hxx>
      44             : 
      45             : using namespace ::com::sun::star;
      46             : 
      47             : namespace {
      48             : 
      49           0 : class PluginWindow_Impl : public vcl::Window
      50             : {
      51             : public:
      52             :     uno::Reference < awt::XWindow > xWindow;
      53           0 :     explicit PluginWindow_Impl(vcl::Window* pParent)
      54           0 :      : Window( pParent, WB_CLIPCHILDREN )
      55           0 :      {}
      56             : 
      57             :      virtual void Resize() SAL_OVERRIDE;
      58             : };
      59             : 
      60           0 : void PluginWindow_Impl::Resize()
      61             : {
      62           0 :     Size aSize( GetOutputSizePixel() );
      63           0 :     if ( xWindow.is() )
      64           0 :         xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), css::awt::PosSize::SIZE );
      65           0 : }
      66             : 
      67             : #define PROPERTY_UNBOUND 0
      68             : 
      69             : #define WID_COMMANDS    1
      70             : #define WID_MIMETYPE    2
      71             : #define WID_URL         3
      72           0 : const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
      73             : {
      74             :     static const SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
      75             :     {
      76           0 :         { OUString("PluginCommands"), WID_COMMANDS, cppu::UnoType<css::uno::Sequence< ::com::sun::star::beans::PropertyValue >>::get(), PROPERTY_UNBOUND, 0},
      77           0 :         { OUString("PluginMimeType"), WID_MIMETYPE, cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
      78           0 :         { OUString("PluginURL"),      WID_URL     , cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
      79             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      80           0 :     };
      81           0 :     return aPluginPropertyMap_Impl;
      82             : }
      83             : 
      84             : class PluginObject : public ::cppu::WeakImplHelper5 <
      85             :         css::util::XCloseable,
      86             :         css::lang::XEventListener,
      87             :         css::frame::XSynchronousFrameLoader,
      88             :         css::beans::XPropertySet,
      89             :         css::lang::XServiceInfo >
      90             : {
      91             :     css::uno::Reference< css::plugin::XPlugin > mxPlugin;
      92             :     SfxItemPropertyMap  maPropMap;
      93             :     SvCommandList       maCmdList;
      94             :     OUString     maURL;
      95             :     OUString     maMimeType;
      96             : 
      97             : public:
      98             :     PluginObject();
      99             :     virtual ~PluginObject();
     100             : 
     101             :     virtual sal_Bool SAL_CALL load( const css::uno::Sequence < css::beans::PropertyValue >& lDescriptor,
     102             :             const css::uno::Reference < css::frame::XFrame >& xFrame ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     103             :     virtual void SAL_CALL cancel() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     104             :     virtual void SAL_CALL close( sal_Bool bDeliverOwnership ) throw( css::util::CloseVetoException, css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     105             :     virtual void SAL_CALL addCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     106             :     virtual void SAL_CALL removeCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     107             :     virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
     108             :     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     109             :     virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     110             :     virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     111             :     virtual void SAL_CALL addVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     112             :     virtual void SAL_CALL removeVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     113             :     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     114             :     virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             : 
     116           0 :     virtual OUString SAL_CALL getImplementationName()
     117             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     118             :     {
     119           0 :         return OUString("com.sun.star.comp.sfx2.PluginObject");
     120             :     }
     121             : 
     122           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
     123             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     124             :     {
     125           0 :         return cppu::supportsService(this, ServiceName);
     126             :     }
     127             : 
     128           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
     129             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     130             :     {
     131           0 :         css::uno::Sequence< OUString > aSeq(1);
     132           0 :         aSeq[0] = "com.sun.star.frame.SpecialEmbeddedObject";
     133           0 :         return aSeq;
     134             :     }
     135             : };
     136             : 
     137           0 : PluginObject::PluginObject()
     138           0 :     : maPropMap( lcl_GetPluginPropertyMap_Impl() )
     139             : {
     140           0 : }
     141             : 
     142           0 : PluginObject::~PluginObject()
     143             : {
     144           0 : }
     145             : 
     146           0 : sal_Bool SAL_CALL PluginObject::load(
     147             :     const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
     148             :     const uno::Reference < frame::XFrame >& xFrame )
     149             : throw( uno::RuntimeException, std::exception )
     150             : {
     151           0 :     uno::Reference< plugin::XPluginManager > xPMgr( plugin::PluginManager::create(comphelper::getProcessComponentContext()) );
     152             : 
     153           0 :     if ( SvtMiscOptions().IsPluginsEnabled() )
     154             :     {
     155           0 :         vcl::Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     156           0 :         VclPtr<PluginWindow_Impl> pWin = VclPtr<PluginWindow_Impl>::Create( pParent );
     157           0 :         pWin->SetSizePixel( pParent->GetOutputSizePixel() );
     158           0 :         pWin->SetBackground();
     159           0 :         pWin->Show();
     160             : 
     161           0 :         size_t nCount = maCmdList.size();
     162           0 :         uno::Sequence < OUString > aCmds( nCount ), aArgs( nCount );
     163           0 :         OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
     164           0 :         for( size_t i = 0; i < nCount; i++ )
     165             :         {
     166           0 :             pCmds[i] = maCmdList[ i ].GetCommand();
     167           0 :             pArgs[i] = maCmdList[ i ].GetArgument();
     168             :         }
     169             : 
     170           0 :         mxPlugin = xPMgr->createPluginFromURL(
     171           0 :             xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
     172           0 :             uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
     173             : 
     174           0 :         if ( mxPlugin.is() )
     175             :         {
     176           0 :             uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
     177           0 :             if ( xWindow.is() )
     178             :             {
     179           0 :                 pWin->xWindow = xWindow;
     180           0 :                 pWin->Resize();
     181           0 :                 xWindow->setVisible( sal_True );
     182             :             }
     183             : 
     184             :             try
     185             :             {
     186           0 :                 uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
     187           0 :                 if( xControl.is() )
     188             :                 {
     189           0 :                     uno::Reference< awt::XControlModel > xModel = xControl->getModel();
     190           0 :                     uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
     191           0 :                     if( xProp.is() )
     192             :                     {
     193           0 :                         uno::Any aValue = xProp->getPropertyValue("URL");
     194           0 :                         aValue >>= maURL;
     195           0 :                         aValue = xProp->getPropertyValue("TYPE");
     196           0 :                         aValue >>= maMimeType;
     197           0 :                     }
     198           0 :                 }
     199             :             }
     200           0 :             catch( const uno::Exception& )
     201             :             {
     202           0 :             }
     203             :         }
     204             : 
     205           0 :         uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
     206             : 
     207             :         // we must destroy the plugin before the parent is destroyed
     208           0 :         xWindow->addEventListener( this );
     209           0 :         xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
     210           0 :         return mxPlugin.is() ? sal_True : sal_False;
     211             :     }
     212             : 
     213           0 :     return sal_False;
     214             : }
     215             : 
     216           0 : void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException, std::exception )
     217             : {
     218           0 :     uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
     219           0 :     if (xComp.is())
     220           0 :         xComp->dispose();
     221           0 :     mxPlugin = 0;
     222           0 : }
     223             : 
     224           0 : void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException, std::exception )
     225             : {
     226           0 : }
     227             : 
     228           0 : void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException, std::exception )
     229             : {
     230           0 : }
     231             : 
     232           0 : void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException, std::exception )
     233             : {
     234           0 : }
     235             : 
     236           0 : void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException, std::exception)
     237             : {
     238           0 :     cancel();
     239           0 : }
     240             : 
     241           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException, std::exception )
     242             : {
     243           0 :     static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
     244           0 :     return xInfo;
     245             : }
     246             : 
     247           0 : void SAL_CALL PluginObject::setPropertyValue(const OUString& aPropertyName, const uno::Any& aAny)
     248             :     throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     249             : {
     250           0 :     if ( aPropertyName == "PluginURL" )
     251             :     {
     252           0 :         aAny >>= maURL;
     253             :     }
     254           0 :     else if ( aPropertyName == "PluginMimeType" )
     255             :     {
     256           0 :         aAny >>= maMimeType;
     257             :     }
     258           0 :     else if ( aPropertyName == "PluginCommands" )
     259             :     {
     260           0 :         maCmdList.clear();
     261           0 :         uno::Sequence < beans::PropertyValue > aCommandSequence;
     262           0 :         if( aAny >>= aCommandSequence )
     263           0 :             maCmdList.FillFromSequence( aCommandSequence );
     264             :     }
     265             :     else
     266           0 :          throw beans::UnknownPropertyException();
     267           0 : }
     268             : 
     269           0 : uno::Any SAL_CALL PluginObject::getPropertyValue(const OUString& aPropertyName)
     270             :         throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     271             : {
     272           0 :     uno::Any aAny;
     273           0 :     if ( aPropertyName == "PluginURL" )
     274             :     {
     275           0 :         aAny <<= maURL;
     276             :     }
     277           0 :     else if ( aPropertyName == "PluginMimeType" )
     278             :     {
     279           0 :         aAny <<= maMimeType;
     280             :     }
     281           0 :     else if ( aPropertyName == "PluginCommands" )
     282             :     {
     283           0 :         uno::Sequence< beans::PropertyValue > aCommandSequence;
     284           0 :         maCmdList.FillSequence( aCommandSequence );
     285           0 :         aAny <<= aCommandSequence;
     286             :     }
     287             :     else
     288           0 :          throw beans::UnknownPropertyException();
     289           0 :     return aAny;
     290             : }
     291             : 
     292           0 : void SAL_CALL PluginObject::addPropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     293             : {
     294           0 : }
     295             : 
     296           0 : void SAL_CALL PluginObject::removePropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     297             : {
     298           0 : }
     299             : 
     300           0 : void SAL_CALL PluginObject::addVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     301             : {
     302           0 : }
     303             : 
     304           0 : void SAL_CALL PluginObject::removeVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     305             : {
     306           0 : }
     307             : 
     308             : }
     309             : 
     310             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     311           0 : com_sun_star_comp_sfx2_PluginObject_get_implementation(
     312             :     css::uno::XComponentContext *,
     313             :     css::uno::Sequence<css::uno::Any> const &)
     314             : {
     315           0 :     return cppu::acquire(new PluginObject());
     316             : }
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11