xref: /trunk/main/framework/inc/services/pluginframe.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_SERVICES_PLUGINFRAME_HXX_
25 #define __FRAMEWORK_SERVICES_PLUGINFRAME_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <services/frame.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //  interface includes
35 //_________________________________________________________________________________________________________________
36 #include <com/sun/star/mozilla/XPluginInstance.hpp>
37 #include <com/sun/star/mozilla/XPluginInstancePeer.hpp>
38 #include <com/sun/star/mozilla/XPluginWindowPeer.hpp>
39 #include <com/sun/star/io/XInputStream.hpp>
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <com/sun/star/awt/XWindow.hpp>
42 #include <com/sun/star/frame/XDispatchResultListener.hpp>
43 #include <com/sun/star/frame/FeatureStateEvent.hpp>
44 #include <com/sun/star/lang/EventObject.hpp>
45 
46 //_________________________________________________________________________________________________________________
47 //  other includes
48 //_________________________________________________________________________________________________________________
49 
50 #ifndef _VCL_ATOM_HXX
51 #include <vcl/threadex.hxx>
52 #endif
53 #include <unotools/cmdoptions.hxx>
54 
55 
56 //_________________________________________________________________________________________________________________
57 //  namespace
58 //_________________________________________________________________________________________________________________
59 
60 namespace framework{
61 
62 //_________________________________________________________________________________________________________________
63 //  exported const
64 //_________________________________________________________________________________________________________________
65 
66 //_________________________________________________________________________________________________________________
67 //  exported definitions
68 //_________________________________________________________________________________________________________________
69 
70 /*-************************************************************************************************************//**
71     @short      implements an special frame - a plugin frame
72     @descr      -
73 
74     @implements XInitialization
75                 XPluginInstance
76                 XDispatchResultListener
77     @base       Frame
78 *//*-*************************************************************************************************************/
79 
80 class PlugInFrame   :   public css::lang::XInitialization           ,
81                         public css::mozilla::XPluginInstance        ,
82                         public css::frame::XDispatchResultListener  ,   // => XEVENTLISTENER
83                         public Frame                                    // Order of baseclasses is necessary for right initialization!
84 {
85     //-------------------------------------------------------------------------------------------------------------
86     //  public methods
87     //-------------------------------------------------------------------------------------------------------------
88 
89     public:
90 
91         //---------------------------------------------------------------------------------------------------------
92         //  constructor / destructor
93         //---------------------------------------------------------------------------------------------------------
94 
95         /*-****************************************************************************************************//**
96             @short      standard constructor to create instance
97             @descr      This constructor initialize a new instance of this class,
98                         and will be set valid values on his member and baseclasses.
99 
100             @seealso    -
101 
102             @param      -
103             @return     -
104 
105             @onerror    -
106         *//*-*****************************************************************************************************/
107 
108         PlugInFrame( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
109 
110         /*-****************************************************************************************************//**
111             @short      standard destructor
112             @descr      This method destruct an instance of this class and clear some member.
113 
114             @seealso    -
115 
116             @param      -
117             @return     -
118 
119             @onerror    -
120         *//*-*****************************************************************************************************/
121 
122         virtual ~PlugInFrame();
123 
124         //---------------------------------------------------------------------------------------------------------
125         //  XInterface, XTypeProvider, XServiceInfo
126         //---------------------------------------------------------------------------------------------------------
127 
128         DECLARE_XINTERFACE
129         DECLARE_XTYPEPROVIDER
130         DECLARE_XSERVICEINFO
131 
132         //---------------------------------------------------------------------------------------------------------
133         //  XInitialization
134         //---------------------------------------------------------------------------------------------------------
135 
136         void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& seqArguments );
137 
138         //---------------------------------------------------------------------------------------------------------
139         //  XPluginInstance
140         //---------------------------------------------------------------------------------------------------------
141 
142         void SAL_CALL start         ();
143         void SAL_CALL implcb_start  ();
144         void SAL_CALL stop          ();
145         void SAL_CALL implcb_stop   ();
146         void SAL_CALL destroy       ();
147         void SAL_CALL implcb_destroy();
148         void SAL_CALL createWindow          (   const   css::uno::Any&      aPlatformWindowHandle   ,
149                                                         sal_Bool            bEmbedded               );
150         void SAL_CALL implcb_createWindow   (   const   css::uno::Any&      aPlatformWindowHandle   ,
151                                                         sal_Bool            bEmbedded               );
152         void SAL_CALL newStream     (   const   ::rtl::OUString&                                sMIMEDescription,
153                                         const   ::rtl::OUString&                                sURL            ,
154                                         const   ::rtl::OUString&                                sFilter         ,
155                                         const   css::uno::Reference< css::io::XInputStream >&   xStream         ,
156                                         const   css::uno::Any&                                  aSessionId      );
157         void SAL_CALL implcb_newStream
158                                     (   const   ::rtl::OUString&                                sMIMEDescription,
159                                         const   ::rtl::OUString&                                sURL            ,
160                                         const   ::rtl::OUString&                                sFilter         ,
161                                         const   css::uno::Reference< css::io::XInputStream >&   xStream         ,
162                                         const   css::uno::Any&                                  aSessionId      );
163         void SAL_CALL newURL        (   const   ::rtl::OUString&    sMIMEDescription,
164                                         const   ::rtl::OUString&    sURL            ,
165                                         const   ::rtl::OUString&    sFilter         ,
166                                         const   css::uno::Any&      aSessionId      );
167         void SAL_CALL implcb_newURL (   const   ::rtl::OUString&    sMIMEDescription,
168                                         const   ::rtl::OUString&    sURL            ,
169                                         const   ::rtl::OUString&    sFilter         ,
170                                         const   css::uno::Any&      aSessionId      );
171         virtual void SAL_CALL getHttpServerURL( ::rtl::OUString&    sHost   ,
172                                                 sal_uInt16&         nPort   ,
173                                                 ::rtl::OUString&    sPrefix );
174 
175         //---------------------------------------------------------------------------------------------------------
176         //   XDispatchProvider
177         //---------------------------------------------------------------------------------------------------------
178 
179         virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(    const   css::util::URL&     aURL            ,
180                                                                                         const   ::rtl::OUString&    sTargetFrameName,
181                                                                                                 sal_Int32           nSearchFlags    );
182         virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& seqDescripts );
183 
184         //---------------------------------------------------------------------------------------------------------
185         //   XDispatchResultListener
186         //---------------------------------------------------------------------------------------------------------
187 
188         virtual void SAL_CALL dispatchFinished      ( const css::frame::DispatchResultEvent&                    aEvent     );
189 
190         //---------------------------------------------------------------------------------------------------------
191         //   XEventListener
192         //---------------------------------------------------------------------------------------------------------
193 
194         void SAL_CALL disposing( const css::lang::EventObject& aEvent );
195 
196     //-------------------------------------------------------------------------------------------------------------
197     //  protected methods
198     //-------------------------------------------------------------------------------------------------------------
199 
200     protected:
201 
202     //-------------------------------------------------------------------------------------------------------------
203     //  private methods
204     //-------------------------------------------------------------------------------------------------------------
205 
206     private:
207 
208         void impl_tryToLoadDocument();
209         sal_Bool impl_registerRemoteFactories( const css::uno::Reference< css::lang::XMultiServiceFactory >& xRemoteServiceManager );
210 
211     //-------------------------------------------------------------------------------------------------------------
212     //  debug methods
213     //  (should be private everyway!)
214     //-------------------------------------------------------------------------------------------------------------
215 
216         /*-****************************************************************************************************//**
217             @short      debug-method to check incoming parameter of some other methods of this class
218             @descr      The following methods are used to check parameters for other methods
219                         of this class. The return value is used directly for an ASSERT(...).
220 
221             @seealso    ASSERTs in implementation!
222 
223             @param      references to checking variables
224             @return     sal_False on invalid parameter<BR>
225                         sal_True  otherway
226 
227             @onerror    -
228         *//*-*****************************************************************************************************/
229 
230     #ifdef ENABLE_ASSERTIONS
231 
232     private:
233 
234         static sal_Bool impldbg_checkParameter_initialize           (   const   css::uno::Sequence< css::uno::Any >&                    seqArguments            );
235         static sal_Bool impldbg_checkParameter_createWindow         (   const   css::uno::Any&                                          aPlatformWindowHandle   ,
236                                                                                 sal_Bool                                                bEmbedded               );
237         static sal_Bool impldbg_checkParameter_newStream            (   const   ::rtl::OUString&                                        sMIMEDescription        ,
238                                                                         const   ::rtl::OUString&                                        sURL                    ,
239                                                                         const   ::rtl::OUString&                                        sFilter                 ,
240                                                                         const   css::uno::Reference< css::io::XInputStream >&           xStream                 );
241         static sal_Bool impldbg_checkParameter_newURL               (   const   ::rtl::OUString&                                        sMIMEDescription        ,
242                                                                         const   ::rtl::OUString&                                        sURL                    ,
243                                                                         const   ::rtl::OUString&                                        sFilter                 );
244         static sal_Bool impldbg_checkParameter_getHttpServerURL     (           ::rtl::OUString&                                        sHost                   ,
245                                                                                 sal_uInt16&                                             nPort                   ,
246                                                                                 ::rtl::OUString&                                        sPrefix                 );
247         static sal_Bool impldbg_checkParameter_queryDispatch        (   const   css::util::URL&                                         aURL                    ,
248                                                                         const   ::rtl::OUString&                                        sTargetFrameName        ,
249                                                                                 sal_Int32                                               nSearchFlags            );
250         static sal_Bool impldbg_checkParameter_queryDispatches      (   const   css::uno::Sequence< css::frame::DispatchDescriptor >&   seqDescripts            );
251         static sal_Bool impldbg_checkParameter_statusChanged        (   const   css::frame::FeatureStateEvent&                          aEvent                  );
252         static sal_Bool impldbg_checkParameter_disposing            (   const   css::lang::EventObject&                                 aEvent                  );
253 
254     #endif  // #ifdef ENABLE_ASSERTIONS
255 
256     //-------------------------------------------------------------------------------------------------------------
257     //  variables
258     //  (should be private everyway!)
259     //-------------------------------------------------------------------------------------------------------------
260 
261     private:
262 
263         css::uno::Reference< css::mozilla::XPluginInstancePeer >            m_xPlugInInstancePeer   ;   /// Reference to UNO interface of PlugIn dll for communication with browser
264         css::uno::Reference< css::mozilla::XPluginWindowPeer >              m_xPlugInWindowPeer     ;   /// Reference to set child window at plugin window
265         css::uno::Sequence< css::beans::PropertyValue >                     m_seqProperties         ;   /// Sequence of properties as arguments for load document
266         css::util::URL                                                      m_aURL                  ;   /// URL for document to load
267         sal_Bool                                                            m_bILoad                ;   /// PlugInFrame has a valid loader which load the document and wait for finished/cancelled
268         sal_Bool                                                            m_bIHaveDocument        ;   /// We have a document loaded successful.
269         css::uno::Reference< css::frame::XDispatchProvider >                m_xPlugInDispatcher     ;   /// Dispatcher to forward dispatches to browser
270         static sal_Bool                                                     m_bRemoteFactoriesExist ;   /// indicates, if remote factories was already registered (necessary one times only!)
271         SvtCommandOptions                                                   m_aCommandOptions       ;   /// ref counted class to support disabling commands defined by configuration file
272 
273 };      //  class PlugInFrame
274 
275 /*-************************************************************************************************************//**
276     @short      used to forward all asynchronous calls which use VCL internal to the main thread
277     @descr      We need this asynchronous mechanism to prevent us against dead locks. Sometimes our main thread
278                 can call us for event handling like FOCUS, ACTIVATE and something else. But at the same time we will call
279                 the main thread to CREATE A WINDOW, SET IT VISIBLE ... Then we have a problem. We must send us himself a event
280                 to run our code synchronized with our main thread!
281 
282     @implements
283     @base       -
284 *//*-*************************************************************************************************************/
285 
286 enum eIMPL_PluginCommand
287 {
288     START           ,
289     STOP            ,
290     CREATEWINDOW    ,
291     DESTROY         ,
292     NEWSTREAM       ,
293     NEWURL
294 };
295 
296 class cIMPL_MainThreadExecutorRequest
297 {
298     public:
299         cIMPL_MainThreadExecutorRequest(    eIMPL_PluginCommand                             eCommand                ,
300                                             PlugInFrame*                                    pPluginInstance         );
301 
302         cIMPL_MainThreadExecutorRequest(    eIMPL_PluginCommand                             eCommand                ,
303                                             PlugInFrame*                                    pPluginInstance         ,
304                                     const   css::uno::Any&                                  aPlatformWindowHandle   ,
305                                             sal_Bool                                        bEmbedded               );
306 
307         cIMPL_MainThreadExecutorRequest(    eIMPL_PluginCommand                             eCommand                ,
308                                             PlugInFrame*                                    pPluginInstance         ,
309                                     const   ::rtl::OUString&                                sMIMEDescription        ,
310                                     const   ::rtl::OUString&                                sURL                    ,
311                                     const   ::rtl::OUString&                                sFilter                 ,
312                                     const   css::uno::Reference< css::io::XInputStream >&   xStream                 ,
313                                     const   css::uno::Any&                                  aSessionId              );
314 
315         /*-****************************************************************************************************//**
316             @short      -
317             @descr      -
318 
319             @seealso    -
320 
321             @param      -
322             @return     -
323 
324             @onerror    -
325         *//*-*****************************************************************************************************/
326 
327         virtual long doIt();
328 
329     //-------------------------------------------------------------------------------------------------------------
330     //  private variables
331     //-------------------------------------------------------------------------------------------------------------
332     private:
333 
334         eIMPL_PluginCommand                             m_eCommand              ;   /// switch to specify forward function
335         PlugInFrame*                                    m_pPluginInstance       ;   /// instance which has started this swicth mechanism and wish to called back from us
336         css::uno::Reference< css::uno::XInterface >     m_xPluginInstance       ;   /// reference to our plugin frame to prevent that plugin frame dies before we call back
337         css::uno::Any                                   m_aPlatformWindowHandle ;   /// parameter for XPluginInstance->createWindow()
338         sal_Bool                                        m_bEmbedded             ;   /// parameter for XPluginInstance->createWindow()
339         ::rtl::OUString                                 m_sMIMEDescription      ;   /// parameter for XPluginInstance->newStream()/newURL()
340         ::rtl::OUString                                 m_sURL                  ;   /// parameter for XPluginInstance->newStream()/newURL()
341         ::rtl::OUString                                 m_sFilter               ;   /// parameter for XPluginInstance->newStream()/newURL()
342         css::uno::Reference< css::io::XInputStream >    m_xStream               ;   /// parameter for XPluginInstance->newStream()/newURL()
343         css::uno::Any                                   m_aSessionId            ;   /// parameter for XPluginInstance->newStream()/newURL()
344 };
345 
346 class cIMPL_MainThreadExecutor
347 {
348     //-------------------------------------------------------------------------------------------------------------
349     //  public methods
350     //-------------------------------------------------------------------------------------------------------------
351     public:
352         static void execute( cIMPL_MainThreadExecutorRequest* pRequest );
353 
354         /*-****************************************************************************************************//**
355             @short      -
356             @descr      -
357 
358             @seealso    -
359 
360             @param      -
361             @return     -
362 
363             @onerror    -
364         *//*-*****************************************************************************************************/
365         DECL_STATIC_LINK( cIMPL_MainThreadExecutor, worker, cIMPL_MainThreadExecutorRequest* );
366 };
367 
368 }       //  namespace framework
369 
370 #endif  //  #ifndef __FRAMEWORK_SERVICES_PLUGINFRAME_HXX_
371