LCOV - code coverage report
Current view: top level - extensions/source/plugin/base - context.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 117 0.0 %
Date: 2014-04-14 Functions: 0 18 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             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      12             :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13             :  * it under the terms of the GNU Lesser General Public License version 3
      14             :  * only, as published by the Free Software Foundation.
      15             :  *
      16             :  * OpenOffice.org is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU Lesser General Public License version 3 for more details
      20             :  * (a copy is included in the LICENSE file that accompanied this code).
      21             :  *
      22             :  * You should have received a copy of the GNU Lesser General Public License
      23             :  * version 3 along with OpenOffice.org.  If not, see
      24             :  * <http://www.openoffice.org/license.html>
      25             :  * for a copy of the LGPLv3 License.
      26             :  *
      27             :  ************************************************************************/
      28             : 
      29             : #ifdef AIX
      30             : #define _LINUX_SOURCE_COMPAT
      31             : #include <sys/timer.h>
      32             : #undef _LINUX_SOURCE_COMPAT
      33             : #endif
      34             : 
      35             : #ifdef WNT
      36             : #include <prewin.h>
      37             : #include <postwin.h>
      38             : #undef OPTIONAL
      39             : #endif
      40             : 
      41             : #include <cstdarg>
      42             : #include <cstdio>
      43             : 
      44             : #include <plugin/impl.hxx>
      45             : 
      46             : #include <sal/log.hxx>
      47             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      48             : #include <com/sun/star/frame/XComponentLoader.hpp>
      49             : #include <com/sun/star/uno/XComponentContext.hpp>
      50             : #include <com/sun/star/frame/Desktop.hpp>
      51             : #include <tools/urlobj.hxx>
      52             : #include <osl/file.hxx>
      53             : 
      54             : #include <cppuhelper/implbase1.hxx>
      55             : 
      56             : using namespace com::sun::star::io;
      57             : using namespace com::sun::star::frame;
      58             : 
      59             : namespace ext_plug {
      60             : 
      61             : class FileSink : public ::cppu::WeakAggImplHelper1< ::com::sun::star::io::XOutputStream >
      62             : {
      63             : private:
      64             :     Reference< ::com::sun::star::uno::XComponentContext >   m_xContext;
      65             :     FILE*                   fp;
      66             :     Reference< ::com::sun::star::plugin::XPlugin >          m_xPlugin;
      67             :     OUString                 m_aMIMEType;
      68             :     OUString                 m_aTarget;
      69             :     OUString                 m_aFileName;
      70             : 
      71             : public:
      72             :     FileSink( const Reference< ::com::sun::star::uno::XComponentContext > &,
      73             :               const Reference< ::com::sun::star::plugin::XPlugin > & plugin,
      74             :               const OUString& mimetype,
      75             :               const OUString& target,
      76             :               const Reference< ::com::sun::star::io::XActiveDataSource > & source );
      77             :     virtual ~FileSink();
      78             : 
      79             :     // ::com::sun::star::io::XOutputStream
      80             :     virtual void SAL_CALL writeBytes( const Sequence<sal_Int8>& ) throw(std::exception) SAL_OVERRIDE;
      81             :     virtual void SAL_CALL flush() throw(std::exception) SAL_OVERRIDE;
      82             :     virtual void SAL_CALL closeOutput() throw(std::exception) SAL_OVERRIDE;
      83             : };
      84             : 
      85             : }
      86             : using namespace ext_plug;
      87             : 
      88             : class XPluginContext_Impl : public ::cppu::WeakAggImplHelper1< ::com::sun::star::plugin::XPluginContext >
      89             : {
      90             :     Reference< ::com::sun::star::uno::XComponentContext >   m_xContext;
      91             :     rtl_TextEncoding                                        m_aEncoding;
      92             : public:
      93             : 
      94             :     XPluginContext_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & );
      95             :     virtual ~XPluginContext_Impl();
      96             : 
      97             : 
      98             :     virtual OUString SAL_CALL getValue(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, ::com::sun::star::plugin::PluginVariable variable) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
      99             :     virtual void SAL_CALL getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     100             :     virtual void SAL_CALL getURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     101             :     virtual void SAL_CALL postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     102             :     virtual void SAL_CALL postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     103             :     virtual void SAL_CALL newStream(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& mimetype, const OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     104             :     virtual void SAL_CALL displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& message) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     105             :     virtual OUString SAL_CALL getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & plugin) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception ) SAL_OVERRIDE;
     106             : };
     107             : 
     108           0 : Reference< ::com::sun::star::plugin::XPluginContext >  XPluginManager_Impl::createPluginContext() throw(std::exception)
     109             : {
     110           0 :     return new XPluginContext_Impl( m_xContext );
     111             : }
     112             : 
     113           0 : XPluginContext_Impl::XPluginContext_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext )
     114             :     : m_xContext( rxContext ),
     115           0 :       m_aEncoding( osl_getThreadTextEncoding() )
     116             : {
     117           0 : }
     118             : 
     119           0 : XPluginContext_Impl::~XPluginContext_Impl()
     120             : {
     121           0 : }
     122             : 
     123           0 : OUString XPluginContext_Impl::getValue( const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/, ::com::sun::star::plugin::PluginVariable /*variable*/ )
     124             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     125             : {
     126           0 :     return OUString();
     127             : }
     128             : 
     129             : 
     130           0 : void XPluginContext_Impl::getURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target) throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     131             : {
     132           0 :     Reference< XDesktop2 > xDesktop = Desktop::create(m_xContext);
     133             : 
     134           0 :     if(  target.isEmpty() )
     135             :     {
     136           0 :         INetURLObject aURL;
     137           0 :         aURL.SetSmartProtocol( INET_PROT_FILE );
     138           0 :         aURL.SetSmartURL( url );
     139             : 
     140           0 :         OUString aUrl = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
     141             :         // the mimetype cannot be specified
     142           0 :         plugin->provideNewStream( OUString(),
     143             :                                   Reference< XActiveDataSource >(),
     144             :                                   aUrl,
     145           0 :                                   0, 0, aUrl.startsWith("file:") );
     146           0 :         return;
     147             :     }
     148             : 
     149           0 :     XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin );
     150             : 
     151           0 :     if( pPlugin )
     152             :     {
     153             :         try
     154             :         {
     155           0 :             ::com::sun::star::beans::PropertyValue aValue;
     156           0 :             aValue.Name     = "Referer";
     157           0 :             aValue.Value <<= pPlugin->getRefererURL();
     158             : 
     159           0 :             Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 );
     160             :             Reference< ::com::sun::star::lang::XComponent >  xComp =
     161           0 :                 xDesktop->loadComponentFromURL(
     162             :                                               url,
     163             :                                               target,
     164             :                                               ::com::sun::star::frame::FrameSearchFlag::PARENT          |
     165             :                                               ::com::sun::star::frame::FrameSearchFlag::SELF            |
     166             :                                               ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
     167             :                                               ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
     168             :                                               ::com::sun::star::frame::FrameSearchFlag::TASKS           |
     169             :                                               ::com::sun::star::frame::FrameSearchFlag::CREATE,
     170             :                                               aArgs
     171           0 :                                               );
     172             :         }
     173           0 :         catch(...)
     174             :         {
     175           0 :             throw ::com::sun::star::plugin::PluginException();
     176             :         }
     177           0 :     }
     178             : }
     179             : 
     180           0 : void XPluginContext_Impl::getURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Reference< ::com::sun::star::lang::XEventListener > & listener )
     181             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     182             : {
     183           0 :     getURL( plugin, url, target );
     184           0 :     if( listener.is() )
     185           0 :         listener->disposing( ::com::sun::star::lang::EventObject() );
     186           0 : }
     187             : 
     188           0 : OUString XPluginContext_Impl::getUserAgent(const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/)
     189             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     190             : {
     191           0 :     return OUString("Mozilla 3.0");
     192             : }
     193             : 
     194           0 : void XPluginContext_Impl::displayStatusText(const Reference< ::com::sun::star::plugin::XPlugin > & /*plugin*/, const OUString& /*message*/)
     195             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     196             : {
     197           0 : }
     198             : 
     199           0 : void XPluginContext_Impl::postURL(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file)
     200             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     201             : {
     202           0 :     Sequence< sal_Int8 > aBuf;
     203             : 
     204           0 :     if( file )
     205             :     {
     206           0 :         OUString aFileName( (char*)buf.getConstArray(), strlen((char*)buf.getConstArray()), m_aEncoding );
     207           0 :         INetURLObject aFilePath( aFileName );
     208           0 :         aFileName = aFilePath.PathToFileName();
     209           0 :         SvFileStream aStream( aFileName, STREAM_READ );
     210           0 :         if( aStream.IsOpen() )
     211             :         {
     212           0 :             int nBytes = 0;
     213           0 :             aStream.Seek( STREAM_SEEK_TO_END );
     214           0 :             aBuf = Sequence<sal_Int8>( nBytes = aStream.Tell() );
     215           0 :             aStream.Seek( STREAM_SEEK_TO_BEGIN );
     216           0 :             aStream.Read( aBuf.getArray(), nBytes );
     217           0 :             aStream.Close();
     218           0 :             osl::FileBase::getFileURLFromSystemPath( aFileName, aFileName );
     219           0 :             osl::File::remove( aFileName );
     220           0 :         }
     221             :     }
     222             : 
     223           0 :     Reference< XDesktop2 > xDesktop = Desktop::create(m_xContext);
     224             : 
     225           0 :     XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( plugin );
     226           0 :     if( pPlugin )
     227             :     {
     228             :         try
     229             :         {
     230           0 :             ::com::sun::star::beans::PropertyValue aValues[2];
     231           0 :             aValues[0].Name = "Referer";
     232           0 :             aValues[0].Value <<= pPlugin->getRefererURL();
     233             : 
     234           0 :             aValues[1].Name = "PostString";
     235           0 :             aValues[1].Value <<= OStringToOUString( (char*)( file ? aBuf : buf ).getConstArray(), m_aEncoding );
     236           0 :             Sequence< ::com::sun::star::beans::PropertyValue > aArgs( aValues, 2 );
     237             :             Reference< ::com::sun::star::lang::XComponent >  xComp =
     238           0 :                 xDesktop->loadComponentFromURL(
     239             :                                               url,
     240             :                                               target,
     241             :                                               ::com::sun::star::frame::FrameSearchFlag::PARENT          |
     242             :                                               ::com::sun::star::frame::FrameSearchFlag::SELF            |
     243             :                                               ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
     244             :                                               ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
     245             :                                               ::com::sun::star::frame::FrameSearchFlag::TASKS           |
     246             :                                               ::com::sun::star::frame::FrameSearchFlag::CREATE,
     247             :                                               aArgs
     248           0 :                                               );
     249             :         }
     250           0 :         catch( ... )
     251             :         {
     252           0 :             throw ::com::sun::star::plugin::PluginException();
     253             :         }
     254           0 :     }
     255           0 : }
     256             : 
     257           0 : void XPluginContext_Impl::postURLNotify(const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& url, const OUString& target, const Sequence< sal_Int8 >& buf, sal_Bool file, const Reference< ::com::sun::star::lang::XEventListener > & listener )
     258             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     259             : {
     260           0 :     postURL( plugin, url, target, buf, file );
     261           0 :     if( listener.is() )
     262           0 :         listener->disposing( ::com::sun::star::lang::EventObject() );
     263           0 : }
     264             : 
     265           0 : void XPluginContext_Impl::newStream( const Reference< ::com::sun::star::plugin::XPlugin > & plugin, const OUString& mimetype, const OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source )
     266             :     throw( ::com::sun::star::plugin::PluginException, RuntimeException, std::exception )
     267             : {
     268           0 :     FileSink*  pNewSink = new FileSink( m_xContext, plugin, mimetype, target, source );
     269           0 :     pNewSink->acquire();
     270           0 : }
     271             : 
     272             : 
     273             : 
     274           0 : FileSink::FileSink( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext, const Reference< ::com::sun::star::plugin::XPlugin > & plugin,
     275             :                     const OUString& mimetype,
     276             :                     const OUString& target, const Reference< ::com::sun::star::io::XActiveDataSource > & source ) :
     277             :         m_xContext( rxContext ),
     278             :         m_xPlugin( plugin ),
     279             :         m_aMIMEType( mimetype ),
     280           0 :         m_aTarget( target )
     281             : {
     282           0 :     osl::FileBase::createTempFile( 0, 0, &m_aFileName );
     283           0 :     OString aFile = OUStringToOString( m_aFileName, osl_getThreadTextEncoding() );
     284           0 :     fp = fopen( aFile.getStr() , "wb" );
     285             : 
     286           0 :     Reference< ::com::sun::star::io::XActiveDataControl >  xControl( source, UNO_QUERY );
     287             : 
     288           0 :     source->setOutputStream( Reference< ::com::sun::star::io::XOutputStream > ( this ) );
     289           0 :     if( xControl.is() )
     290           0 :         xControl->start();
     291           0 : }
     292             : 
     293           0 : FileSink::~FileSink()
     294             : {
     295           0 :     osl::File::remove( m_aFileName );
     296           0 : }
     297             : 
     298           0 : void FileSink::closeOutput() throw(std::exception)
     299             : {
     300           0 :     if( fp )
     301           0 :         fclose( fp );
     302             : 
     303           0 :     Reference< XDesktop2 > xDesktop = Desktop::create(m_xContext);
     304           0 :     XPlugin_Impl* pPlugin = XPluginManager_Impl::getPluginImplementation( m_xPlugin );
     305             : 
     306           0 :     if( pPlugin )
     307             :     {
     308             :         try
     309             :         {
     310           0 :             ::com::sun::star::beans::PropertyValue aValue;
     311           0 :             aValue.Name = "Referer";
     312           0 :             aValue.Value <<= pPlugin->getRefererURL();
     313             : 
     314           0 :             Sequence< ::com::sun::star::beans::PropertyValue > aArgs( &aValue, 1 );
     315             :             Reference< ::com::sun::star::lang::XComponent >  xComp =
     316           0 :                 xDesktop->loadComponentFromURL(
     317             :                                               m_aFileName,
     318             :                                               m_aTarget,
     319             :                                               ::com::sun::star::frame::FrameSearchFlag::PARENT          |
     320             :                                               ::com::sun::star::frame::FrameSearchFlag::SELF            |
     321             :                                               ::com::sun::star::frame::FrameSearchFlag::CHILDREN        |
     322             :                                               ::com::sun::star::frame::FrameSearchFlag::SIBLINGS        |
     323             :                                               ::com::sun::star::frame::FrameSearchFlag::TASKS           |
     324             :                                               ::com::sun::star::frame::FrameSearchFlag::CREATE,
     325             :                                               aArgs
     326           0 :                                               );
     327             :         }
     328           0 :         catch( ... )
     329             :         {
     330             :         }
     331             :     }
     332           0 :     release();
     333           0 : }
     334             : 
     335           0 : void FileSink::writeBytes( const Sequence<sal_Int8>& Buffer ) throw(std::exception)
     336             : {
     337           0 :     if( fp )
     338             :     {
     339           0 :         size_t nItems = Buffer.getLength();
     340           0 :         bool bSuccess = (fwrite(Buffer.getConstArray(), 1, nItems, fp) == nItems);
     341             :         SAL_WARN_IF( !bSuccess, "extensions.plugin", "short write");
     342             :     }
     343           0 : }
     344             : 
     345           0 : void FileSink::flush() throw(std::exception)
     346             : {
     347           0 :     if( fp )
     348           0 :         fflush( fp );
     349           0 : }
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10