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 neccessary 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 ) throw(	css::uno::Exception			,
137 					 																				css::uno::RuntimeException	);
138 
139 		//---------------------------------------------------------------------------------------------------------
140 		//	XPluginInstance
141 		//---------------------------------------------------------------------------------------------------------
142 
143 		void SAL_CALL start			() throw( css::uno::RuntimeException );
144 		void SAL_CALL implcb_start	() throw( css::uno::RuntimeException );
145 		void SAL_CALL stop			() throw( css::uno::RuntimeException );
146 		void SAL_CALL implcb_stop	() throw( css::uno::RuntimeException );
147 		void SAL_CALL destroy		() throw( css::uno::RuntimeException );
148 		void SAL_CALL implcb_destroy() throw( css::uno::RuntimeException );
149 		void SAL_CALL createWindow			(	const	css::uno::Any&		aPlatformWindowHandle	,
150 														sal_Bool			bEmbedded				) throw( css::uno::RuntimeException );
151 		void SAL_CALL implcb_createWindow	(	const	css::uno::Any&		aPlatformWindowHandle	,
152 														sal_Bool			bEmbedded				) throw( css::uno::RuntimeException );
153 		void SAL_CALL newStream		(	const	::rtl::OUString&								sMIMEDescription,
154 										const	::rtl::OUString&								sURL			,
155 										const	::rtl::OUString&								sFilter			,
156 										const	css::uno::Reference< css::io::XInputStream >&	xStream			,
157 										const	css::uno::Any&									aSessionId		) throw( css::uno::RuntimeException );
158 	    void SAL_CALL implcb_newStream
159 		                            (	const	::rtl::OUString&								sMIMEDescription,
160 										const	::rtl::OUString&								sURL			,
161 										const	::rtl::OUString&								sFilter			,
162 										const	css::uno::Reference< css::io::XInputStream >&	xStream			,
163 										const	css::uno::Any&									aSessionId		) throw( css::uno::RuntimeException );
164 		void SAL_CALL newURL		(	const	::rtl::OUString&	sMIMEDescription,
165 										const	::rtl::OUString&	sURL			,
166 										const	::rtl::OUString&	sFilter			,
167 										const	css::uno::Any&		aSessionId		) throw( css::uno::RuntimeException );
168 		void SAL_CALL implcb_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     	virtual void SAL_CALL getHttpServerURL(	::rtl::OUString&	sHost	,
173 												sal_uInt16&			nPort	,
174 												::rtl::OUString&	sPrefix	) throw( css::uno::RuntimeException );
175 
176 		//---------------------------------------------------------------------------------------------------------
177 		//	 XDispatchProvider
178 		//---------------------------------------------------------------------------------------------------------
179 
180 		virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(	const	css::util::URL&	 	aURL			,
181 																						const	::rtl::OUString&	sTargetFrameName,
182 																								sal_Int32			nSearchFlags	) throw( css::uno::RuntimeException );
183 		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 );
184 
185 		//---------------------------------------------------------------------------------------------------------
186         //   XDispatchResultListener
187 		//---------------------------------------------------------------------------------------------------------
188 
189         virtual void SAL_CALL dispatchFinished      ( const css::frame::DispatchResultEvent&                    aEvent     ) throw( css::uno::RuntimeException );
190 
191 		//---------------------------------------------------------------------------------------------------------
192 		//	 XEventListener
193 		//---------------------------------------------------------------------------------------------------------
194 
195 		void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
196 
197 	//-------------------------------------------------------------------------------------------------------------
198 	//	protected methods
199 	//-------------------------------------------------------------------------------------------------------------
200 
201 	protected:
202 
203 	//-------------------------------------------------------------------------------------------------------------
204 	//	private methods
205 	//-------------------------------------------------------------------------------------------------------------
206 
207 	private:
208 
209 		void impl_tryToLoadDocument();
210         sal_Bool impl_registerRemoteFactories( const css::uno::Reference< css::lang::XMultiServiceFactory >& xRemoteServiceManager );
211 
212 	//-------------------------------------------------------------------------------------------------------------
213 	//	debug methods
214 	//	(should be private everyway!)
215 	//-------------------------------------------------------------------------------------------------------------
216 
217 		/*-****************************************************************************************************//**
218 			@short		debug-method to check incoming parameter of some other mehods of this class
219 			@descr		The following methods are used to check parameters for other methods
220 						of this class. The return value is used directly for an ASSERT(...).
221 
222 			@seealso	ASSERTs in implementation!
223 
224 			@param		references to checking variables
225 			@return		sal_False on invalid parameter<BR>
226 						sal_True  otherway
227 
228 			@onerror	-
229 		*//*-*****************************************************************************************************/
230 
231 	#ifdef ENABLE_ASSERTIONS
232 
233 	private:
234 
235 		static sal_Bool impldbg_checkParameter_initialize			(	const	css::uno::Sequence< css::uno::Any >&					seqArguments			);
236 		static sal_Bool impldbg_checkParameter_createWindow			(	const	css::uno::Any&											aPlatformWindowHandle	,
237 																				sal_Bool												bEmbedded				);
238 		static sal_Bool impldbg_checkParameter_newStream			(	const	::rtl::OUString&										sMIMEDescription		,
239 																		const	::rtl::OUString&										sURL					,
240 																		const	::rtl::OUString&										sFilter					,
241 																		const	css::uno::Reference< css::io::XInputStream >&			xStream					);
242 		static sal_Bool impldbg_checkParameter_newURL				(	const	::rtl::OUString&										sMIMEDescription		,
243 																		const	::rtl::OUString&										sURL					,
244 																		const	::rtl::OUString&										sFilter					);
245     	static sal_Bool impldbg_checkParameter_getHttpServerURL		(			::rtl::OUString&										sHost					,
246 																				sal_uInt16&												nPort					,
247 																				::rtl::OUString&										sPrefix					);
248 		static sal_Bool impldbg_checkParameter_queryDispatch		(	const	css::util::URL&	 										aURL					,
249 																		const	::rtl::OUString&										sTargetFrameName		,
250 																				sal_Int32												nSearchFlags			);
251 		static sal_Bool impldbg_checkParameter_queryDispatches		(	const	css::uno::Sequence< css::frame::DispatchDescriptor >&	seqDescripts			);
252 		static sal_Bool impldbg_checkParameter_statusChanged		(	const	css::frame::FeatureStateEvent&							aEvent					);
253 		static sal_Bool impldbg_checkParameter_disposing			(	const	css::lang::EventObject&									aEvent					);
254 
255 	#endif	// #ifdef ENABLE_ASSERTIONS
256 
257 	//-------------------------------------------------------------------------------------------------------------
258 	//	variables
259 	//	(should be private everyway!)
260 	//-------------------------------------------------------------------------------------------------------------
261 
262 	private:
263 
264 		css::uno::Reference< css::mozilla::XPluginInstancePeer >			m_xPlugInInstancePeer	;	/// Reference to UNO interface of PlugIn dll for communication with browser
265 		css::uno::Reference< css::mozilla::XPluginWindowPeer >				m_xPlugInWindowPeer		;	/// Reference to set child window at plugin window
266 		css::uno::Sequence< css::beans::PropertyValue >						m_seqProperties			;	/// Sequence of properties as arguments for load document
267 		css::util::URL														m_aURL					;	/// URL for document to load
268 		sal_Bool															m_bILoad				;	/// PlugInFrame has a valid loader which load the document and wait for finished/cancelled
269 		sal_Bool															m_bIHaveDocument		;	/// We have a document loaded successful.
270 		css::uno::Reference< css::frame::XDispatchProvider >				m_xPlugInDispatcher		;	/// Dispatcher to forward dispatches to browser
271         static sal_Bool                                                     m_bRemoteFactoriesExist ;   /// indicates, if remote factories was already registered (neccessary one times only!)
272 		SvtCommandOptions													m_aCommandOptions		;	/// ref counted class to support disabling commands defined by configuration file
273 
274 };		//	class PlugInFrame
275 
276 /*-************************************************************************************************************//**
277 	@short		used to forward all asynchronous calls which use VCL internal to the main thread
278 	@descr		We need this asynchronous mechanism to prevent us against dead locks. Sometimes our main thread
279 				can call us for event handling like FOCUS, ACTIVATE and something else. But at the same time we will call
280 				the main thread to CREATE A WINDOW, SET IT VISIBLE ... Then we have a problem. We must send us himself a event
281 				to run our code synchronized with our main thread!
282 
283 	@implements
284 	@base		-
285 *//*-*************************************************************************************************************/
286 
287 enum eIMPL_PluginCommand
288 {
289 	START			,
290 	STOP			,
291 	CREATEWINDOW	,
292 	DESTROY         ,
293 	NEWSTREAM       ,
294 	NEWURL
295 };
296 
297 class cIMPL_MainThreadExecutorRequest
298 {
299 	public:
300 		cIMPL_MainThreadExecutorRequest(	eIMPL_PluginCommand								eCommand				,
301 											PlugInFrame*									pPluginInstance			);
302 
303 		cIMPL_MainThreadExecutorRequest(	eIMPL_PluginCommand								eCommand				,
304 											PlugInFrame*									pPluginInstance			,
305 									const	css::uno::Any&									aPlatformWindowHandle	,
306 											sal_Bool										bEmbedded				);
307 
308 	    cIMPL_MainThreadExecutorRequest(	eIMPL_PluginCommand								eCommand				,
309 											PlugInFrame*									pPluginInstance			,
310 									const   ::rtl::OUString&								sMIMEDescription		,
311 									const	::rtl::OUString&								sURL		    		,
312 									const	::rtl::OUString&								sFilter		    		,
313 									const	css::uno::Reference< css::io::XInputStream >&	xStream     			,
314 									const	css::uno::Any&									aSessionId				);
315 
316 		/*-****************************************************************************************************//**
317 			@short		-
318 			@descr		-
319 
320 			@seealso	-
321 
322 			@param		-
323 			@return		-
324 
325 			@onerror	-
326 		*//*-*****************************************************************************************************/
327 
328 		virtual long doIt();
329 
330 	//-------------------------------------------------------------------------------------------------------------
331 	//	private variables
332 	//-------------------------------------------------------------------------------------------------------------
333 	private:
334 
335 		eIMPL_PluginCommand								m_eCommand				;	/// switch to specify forward function
336 		PlugInFrame*									m_pPluginInstance		;	/// instance wich has started this swicth mechanism and wish to called back from us
337 		css::uno::Reference< css::uno::XInterface >		m_xPluginInstance		;	/// reference to our plugin frame to prevent that plugin frame dies before we call back
338 		css::uno::Any									m_aPlatformWindowHandle	;	///	parameter for XPluginInstance->createWindow()
339 		sal_Bool										m_bEmbedded				;	///	parameter for XPluginInstance->createWindow()
340 	    ::rtl::OUString				    				m_sMIMEDescription		;	/// parameter for XPluginInstance->newStream()/newURL()
341 		::rtl::OUString			        				m_sURL					;	/// parameter for XPluginInstance->newStream()/newURL()
342 		::rtl::OUString									m_sFilter				;	/// parameter for XPluginInstance->newStream()/newURL()
343 		css::uno::Reference< css::io::XInputStream >	m_xStream				;	/// parameter for XPluginInstance->newStream()/newURL()
344 		css::uno::Any      								m_aSessionId			;	/// parameter for XPluginInstance->newStream()/newURL()
345 };
346 
347 class cIMPL_MainThreadExecutor
348 {
349 	//-------------------------------------------------------------------------------------------------------------
350 	//	public methods
351 	//-------------------------------------------------------------------------------------------------------------
352 	public:
353 		static void execute( cIMPL_MainThreadExecutorRequest* pRequest );
354 
355 		/*-****************************************************************************************************//**
356 			@short		-
357 			@descr		-
358 
359 			@seealso	-
360 
361 			@param		-
362 			@return		-
363 
364 			@onerror	-
365 		*//*-*****************************************************************************************************/
366 		DECL_STATIC_LINK( cIMPL_MainThreadExecutor, worker, cIMPL_MainThreadExecutorRequest* );
367 };
368 
369 }		//	namespace framework
370 
371 #endif	//	#ifndef __FRAMEWORK_SERVICES_PLUGINFRAME_HXX_
372