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

Generated by: LCOV version 1.10