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