2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2001-07-03 06:58:21 +00:00
/*************************************************************************
*
2008-04-11 07:24:03 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2001-07-03 06:58:21 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2001-07-03 06:58:21 +00:00
*
2008-04-11 07:24:03 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2001-07-03 06:58:21 +00:00
*
2008-04-11 07:24:03 +00:00
* This file is part of OpenOffice . org .
2001-07-03 06:58:21 +00:00
*
2008-04-11 07:24:03 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2001-07-03 06:58:21 +00:00
*
2008-04-11 07:24:03 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2001-07-03 06:58:21 +00:00
*
2008-04-11 07:24:03 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2001-07-03 06:58:21 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-06-13 07:43:11 +00:00
# include <stdio.h>
2001-07-03 06:58:21 +00:00
# include <dispatch/dispatchprovider.hxx>
2004-01-28 13:28:57 +00:00
# include <loadenv/loadenv.hxx>
# include <dispatch/loaddispatcher.hxx>
2003-03-25 17:22:13 +00:00
# include <dispatch/closedispatcher.hxx>
2001-07-03 06:58:21 +00:00
# include <dispatch/menudispatcher.hxx>
2009-01-02 15:26:18 +00:00
# include <dispatch/startmoduledispatcher.hxx>
2001-07-03 06:58:21 +00:00
2007-08-02 13:43:58 +00:00
# include <pattern/window.hxx>
2001-07-03 06:58:21 +00:00
# include <threadhelp/transactionguard.hxx>
# include <threadhelp/readguard.hxx>
2009-09-18 10:15:03 +00:00
# include <threadhelp/writeguard.hxx>
2009-01-02 15:26:18 +00:00
# include <dispatchcommands.h>
2002-08-22 09:07:00 +00:00
# include <protocols.h>
2001-07-03 06:58:21 +00:00
# include <services.h>
2008-10-14 05:23:43 +00:00
# include <targets.h>
2001-07-03 06:58:21 +00:00
# include <general.h>
# include <com/sun/star/frame/FrameSearchFlag.hpp>
2001-07-31 09:07:00 +00:00
# include <com/sun/star/uno/Exception.hpp>
2001-08-02 12:34:32 +00:00
# include <com/sun/star/ucb/XContentProviderManager.hpp>
2001-08-08 08:52:46 +00:00
# include <com/sun/star/document/XTypeDetection.hpp>
2002-09-05 11:13:03 +00:00
# include <com/sun/star/lang/XInitialization.hpp>
2001-07-31 09:07:00 +00:00
# include <osl/diagnose.h>
# include <rtl/string.h>
# include <rtl/ustring.hxx>
2001-07-03 06:58:21 +00:00
# include <vcl/svapp.hxx>
2001-08-02 12:34:32 +00:00
# include <rtl/ustrbuf.hxx>
2001-07-03 06:58:21 +00:00
namespace framework {
//*****************************************************************************************************************
// XInterface, XTypeProvider
//*****************************************************************************************************************
2002-05-23 11:54:59 +00:00
DEFINE_XINTERFACE_2 ( DispatchProvider ,
OWeakObject ,
DIRECT_INTERFACE ( css : : lang : : XTypeProvider ) ,
DIRECT_INTERFACE ( css : : frame : : XDispatchProvider )
)
DEFINE_XTYPEPROVIDER_2 ( DispatchProvider ,
css : : lang : : XTypeProvider ,
css : : frame : : XDispatchProvider
)
/**
2001-07-03 06:58:21 +00:00
@ short standard ctor / dtor
@ descr These initialize a new instance of tihs class with needed informations for work .
We hold a weakreference to our owner frame which start dispatches at us .
We can ' t use a normal reference because he hold a reference of us too . . .
nobody can die so . . . !
@ seealso using at owner
2002-05-23 11:54:59 +00:00
@ param xFactory
reference to servicemanager to create new services .
@ param xFrame
reference to our owner frame .
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
@ modified 17.05 .2002 10 : 07 , as96863
*/
2001-07-03 06:58:21 +00:00
DispatchProvider : : DispatchProvider ( const css : : uno : : Reference < css : : lang : : XMultiServiceFactory > & xFactory ,
const css : : uno : : Reference < css : : frame : : XFrame > & xFrame )
// Init baseclasses first
2002-05-23 11:54:59 +00:00
: ThreadHelpBase ( & Application : : GetSolarMutex ( ) )
, OWeakObject ( )
2001-07-03 06:58:21 +00:00
// Init member
2002-05-23 11:54:59 +00:00
, m_xFactory ( xFactory )
2006-06-19 10:15:33 +00:00
, m_xFrame ( xFrame )
2001-07-03 06:58:21 +00:00
{
}
2002-05-23 11:54:59 +00:00
/**
@ short protected ( ! ) dtor for deinitializing
@ descr We made it protected to prevent using of us as base class instead as a member .
@ modified 17.05 .2002 10 : 05 , as96863
*/
2001-07-03 06:58:21 +00:00
DispatchProvider : : ~ DispatchProvider ( )
{
}
2002-05-23 11:54:59 +00:00
/**
2001-07-03 06:58:21 +00:00
@ interface XDispatchProvider
@ short search a dispatcher for given URL
@ descr If no interceptor is set on owner , we search for right frame and dispatch URL to it .
If no frame was found , we do nothing .
2002-05-23 11:54:59 +00:00
But we doesn ' t do it directly here . We detect the type of our owner frame and calls
specialized queryDispatch ( ) helper dependen from that . Because a Desktop handle some
2004-01-28 13:28:57 +00:00
requests in another way then a normal frame .
2002-05-23 11:54:59 +00:00
@ param aURL
URL to dispatch .
@ param sTargetFrameName
name of searched frame .
@ param nSearchFlags
flags for searching .
@ return A reference to a dispatch object for this URL ( if someone was found ! ) .
2001-07-03 06:58:21 +00:00
@ threadsafe yes
2002-05-23 11:54:59 +00:00
@ modified 17.05 .2002 10 : 59 , as96863
*/
2001-07-03 06:58:21 +00:00
css : : uno : : Reference < css : : frame : : XDispatch > SAL_CALL DispatchProvider : : queryDispatch ( const css : : util : : URL & aURL ,
const : : rtl : : OUString & sTargetFrameName ,
sal_Int32 nSearchFlags ) throw ( css : : uno : : RuntimeException )
{
2002-05-23 11:54:59 +00:00
css : : uno : : Reference < css : : frame : : XDispatch > xDispatcher ;
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
/* SAFE { */
2001-07-03 06:58:21 +00:00
ReadGuard aReadLock ( m_aLock ) ;
2002-05-23 11:54:59 +00:00
css : : uno : : Reference < css : : frame : : XFrame > xOwner ( m_xFrame . get ( ) , css : : uno : : UNO_QUERY ) ;
2001-07-03 06:58:21 +00:00
aReadLock . unlock ( ) ;
2002-05-23 11:54:59 +00:00
/* } SAFE */
2001-07-03 06:58:21 +00:00
2004-01-28 13:28:57 +00:00
css : : uno : : Reference < css : : frame : : XDesktop > xDesktopCheck ( xOwner , css : : uno : : UNO_QUERY ) ;
2002-05-23 11:54:59 +00:00
if ( xDesktopCheck . is ( ) )
xDispatcher = implts_queryDesktopDispatch ( xOwner , aURL , sTargetFrameName , nSearchFlags ) ;
else
xDispatcher = implts_queryFrameDispatch ( xOwner , aURL , sTargetFrameName , nSearchFlags ) ;
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
return xDispatcher ;
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
/**
2001-07-03 06:58:21 +00:00
@ interface XDispatchProvider
@ short do the same like queryDispatch ( ) . . . but handle multiple dispatches at the same time
@ descr It ' s an optimism . User give us a list of queries . . . and we return a list of dispatcher .
If one of given queries couldn ' t be solved to a real existing dispatcher . . .
we return a list with empty references in it ! Order of both lists will be retained !
@ seealso method queryDispatch ( )
2002-05-23 11:54:59 +00:00
@ param lDescriptions
a list of all dispatch parameters for multiple requests
@ return A reference a list of dispatch objects for these URLs - may with some < NULL / > values inside .
2001-07-03 06:58:21 +00:00
@ threadsafe yes
2002-05-23 11:54:59 +00:00
@ modified 17.05 .2002 09 : 55 , as96863
*/
2001-07-03 06:58:21 +00:00
css : : uno : : Sequence < css : : uno : : Reference < css : : frame : : XDispatch > > SAL_CALL DispatchProvider : : queryDispatches ( const css : : uno : : Sequence < css : : frame : : DispatchDescriptor > & lDescriptions ) throw ( css : : uno : : RuntimeException )
{
2002-05-23 11:54:59 +00:00
// Create return list - which must have same size then the given descriptor
// It's not allowed to pack it!
sal_Int32 nCount = lDescriptions . getLength ( ) ;
css : : uno : : Sequence < css : : uno : : Reference < css : : frame : : XDispatch > > lDispatcher ( nCount ) ;
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
// Step over all descriptors and try to get any dispatcher for it.
for ( sal_Int32 i = 0 ; i < nCount ; + + i )
{
lDispatcher [ i ] = queryDispatch ( lDescriptions [ i ] . FeatureURL ,
lDescriptions [ i ] . FrameName ,
lDescriptions [ i ] . SearchFlags ) ;
}
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
return lDispatcher ;
}
2001-07-03 06:58:21 +00:00
2009-09-18 10:15:03 +00:00
: : sal_Bool lcl_isStartModuleDispatch ( const css : : util : : URL & aURL )
{
2011-01-16 15:48:11 +00:00
return ( aURL . Complete . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( CMD_UNO_SHOWSTARTMODULE ) ) ) ;
2009-09-18 10:15:03 +00:00
}
2002-05-23 11:54:59 +00:00
/**
@ short helper for queryDispatch ( )
2004-01-28 13:28:57 +00:00
@ descr Every member of the frame tree ( frame , desktop ) must handle such request
2002-05-23 11:54:59 +00:00
in another way . So we implement different specialized metods for every one .
@ threadsafe yes
2004-01-28 13:28:57 +00:00
@ modified 20.08 .2003 08 : 32 , as96863
2002-05-23 11:54:59 +00:00
*/
css : : uno : : Reference < css : : frame : : XDispatch > DispatchProvider : : implts_queryDesktopDispatch ( const css : : uno : : Reference < css : : frame : : XFrame > xDesktop ,
const css : : util : : URL & aURL ,
const : : rtl : : OUString & sTargetFrameName ,
sal_Int32 nSearchFlags )
{
css : : uno : : Reference < css : : frame : : XDispatch > xDispatcher ;
// ignore wrong requests which are not supported
if (
( sTargetFrameName = = SPECIALTARGET_MENUBAR ) | | // valid for frame dispatches - not for desktop
( sTargetFrameName = = SPECIALTARGET_PARENT ) | | // we have no parent by definition
( sTargetFrameName = = SPECIALTARGET_BEAMER ) // beamer frames are allowed as child of tasks only -
// and they exist more then ones. We have no idea which our sub tasks is the right one
)
2001-07-03 06:58:21 +00:00
{
2002-05-23 11:54:59 +00:00
return NULL ;
}
//-----------------------------------------------------------------------------------------------------
// I) handle special cases which not right for using findFrame() first
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
// I.I) "_blank"
// It's not the right place to create a new task here - because we are queried for a dispatch object
// only, which can handle such request. Such dispatcher should create the required task on demand.
// Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
// here. Thats why we must "intercept" here.
//-----------------------------------------------------------------------------------------------------
if ( sTargetFrameName = = SPECIALTARGET_BLANK )
{
2002-05-30 11:51:28 +00:00
if ( implts_isLoadableContent ( aURL ) )
2004-01-28 13:28:57 +00:00
xDispatcher = implts_getOrCreateDispatchHelper ( E_BLANKDISPATCHER , xDesktop ) ;
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
//-----------------------------------------------------------------------------------------------------
// I.II) "_default"
// This is a combination of search an empty task for recycling - or create a new one.
//-----------------------------------------------------------------------------------------------------
else
if ( sTargetFrameName = = SPECIALTARGET_DEFAULT )
{
2002-05-30 11:51:28 +00:00
if ( implts_isLoadableContent ( aURL ) )
2009-09-18 10:15:03 +00:00
xDispatcher = implts_getOrCreateDispatchHelper ( E_DEFAULTDISPATCHER , xDesktop ) ;
if ( lcl_isStartModuleDispatch ( aURL ) )
xDispatcher = implts_getOrCreateDispatchHelper ( E_STARTMODULEDISPATCHER , xDesktop ) ;
2002-05-23 11:54:59 +00:00
}
//-----------------------------------------------------------------------------------------------------
// I.III) "_self", "", "_top"
// The desktop can't load any document - but he can handle some special protocols like "uno", "slot" ...
// Why is "top" here handled too? Because the desktop is the topest frame. Normaly it's superflous
// to use this target - but we can handle it in the same manner then "_self".
//-----------------------------------------------------------------------------------------------------
else
if (
( sTargetFrameName = = SPECIALTARGET_SELF ) | |
( sTargetFrameName = = SPECIALTARGET_TOP ) | |
2011-12-26 14:20:50 -02:00
( sTargetFrameName . isEmpty ( ) )
2002-05-23 11:54:59 +00:00
)
{
2002-05-30 11:51:28 +00:00
xDispatcher = implts_searchProtocolHandler ( aURL ) ;
2002-05-23 11:54:59 +00:00
}
//-----------------------------------------------------------------------------------------------------
// I.IV) no further special targets exist
// Now we have to search for the right target frame by calling findFrame() - but should provide our code
// against creation of a new task if no frame could be found.
// I said it b efore - it's allowed for dispatch() only.
//-----------------------------------------------------------------------------------------------------
else
{
sal_Int32 nRightFlags = nSearchFlags ;
nRightFlags & = ~ css : : frame : : FrameSearchFlag : : CREATE ;
// try to find any existing target and ask him for his dispatcher
css : : uno : : Reference < css : : frame : : XFrame > xFoundFrame = xDesktop - > findFrame ( sTargetFrameName , nRightFlags ) ;
if ( xFoundFrame . is ( ) )
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xProvider ( xFoundFrame , css : : uno : : UNO_QUERY ) ;
xDispatcher = xProvider - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
}
else
// if it couldn't be found - but creation was allowed
// use special dispatcher for creatio or froward it to the browser
if ( nSearchFlags & css : : frame : : FrameSearchFlag : : CREATE )
2004-01-28 13:28:57 +00:00
xDispatcher = implts_getOrCreateDispatchHelper ( E_CREATEDISPATCHER , xDesktop , sTargetFrameName , nSearchFlags ) ;
2002-05-23 11:54:59 +00:00
}
return xDispatcher ;
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
//_________________________________________________________________________________________________________________
css : : uno : : Reference < css : : frame : : XDispatch > DispatchProvider : : implts_queryFrameDispatch ( const css : : uno : : Reference < css : : frame : : XFrame > xFrame ,
const css : : util : : URL & aURL ,
const : : rtl : : OUString & sTargetFrameName ,
sal_Int32 nSearchFlags )
{
css : : uno : : Reference < css : : frame : : XDispatch > xDispatcher ;
2003-03-25 17:22:13 +00:00
//-----------------------------------------------------------------------------------------------------
// 0) Some URLs are dispatched in a generic way (e.g. by the menu) using the default target "".
// But they are specified to use her own fix target. Detect such URLs here and use the correct target.
//-----------------------------------------------------------------------------------------------------
: : rtl : : OUString sTargetName = sTargetFrameName ;
2002-05-23 11:54:59 +00:00
//-----------------------------------------------------------------------------------------------------
// I) handle special cases which not right for using findFrame() first
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
// I.I) "_blank", "_default"
// It's not the right place to create a new task here. Only the desktop can do that.
// Normaly the functionality for "_blank" is provided by findFrame() - but that would create it directly
// here. Thats why we must "intercept" here.
//-----------------------------------------------------------------------------------------------------
if (
2003-03-25 17:22:13 +00:00
( sTargetName = = SPECIALTARGET_BLANK ) | |
( sTargetName = = SPECIALTARGET_DEFAULT )
2002-05-23 11:54:59 +00:00
)
{
2004-01-28 13:28:57 +00:00
css : : uno : : Reference < css : : frame : : XDispatchProvider > xParent ( xFrame - > getCreator ( ) , css : : uno : : UNO_QUERY ) ;
if ( xParent . is ( ) )
xDispatcher = xParent - > queryDispatch ( aURL , sTargetName , 0 ) ; // its a special target - ignore search flags
2002-05-23 11:54:59 +00:00
}
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
//-----------------------------------------------------------------------------------------------------
// I.II) "_menubar"
// Special mode on frame or task to receive the local menu. Not supported by findFrame()
//-----------------------------------------------------------------------------------------------------
else
2003-03-25 17:22:13 +00:00
if ( sTargetName = = SPECIALTARGET_MENUBAR )
2002-05-23 11:54:59 +00:00
{
xDispatcher = implts_getOrCreateDispatchHelper ( E_MENUDISPATCHER , xFrame ) ;
}
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
//-----------------------------------------------------------------------------------------------------
// I.IV) "_helpagent"
// Special sub frame of a top frame only. Search or create it. ... OK it's currently a little bit HACKI.
// Only the sfx (means the controller) can create it it.
//-----------------------------------------------------------------------------------------------------
else
2003-03-25 17:22:13 +00:00
if ( sTargetName = = SPECIALTARGET_BEAMER )
2002-05-23 11:54:59 +00:00
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xBeamer ( xFrame - > findFrame ( SPECIALTARGET_BEAMER , css : : frame : : FrameSearchFlag : : CHILDREN | css : : frame : : FrameSearchFlag : : SELF ) , css : : uno : : UNO_QUERY ) ;
if ( xBeamer . is ( ) )
{
xDispatcher = xBeamer - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
}
else
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xController ( xFrame - > getController ( ) , css : : uno : : UNO_QUERY ) ;
if ( xController . is ( ) )
// force using of special target - but use original search flags
// May the caller used the CREATE flag or not!
xDispatcher = xController - > queryDispatch ( aURL , SPECIALTARGET_BEAMER , nSearchFlags ) ;
}
}
2001-07-03 06:58:21 +00:00
2002-05-23 11:54:59 +00:00
//-----------------------------------------------------------------------------------------------------
2003-03-25 17:22:13 +00:00
// I.V) "_parent"
// Our parent frame (if it exist) should handle this URL.
//-----------------------------------------------------------------------------------------------------
else
if ( sTargetName = = SPECIALTARGET_PARENT )
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xParent ( xFrame - > getCreator ( ) , css : : uno : : UNO_QUERY ) ;
if ( xParent . is ( ) )
// SELF => we must adress the parent directly... and not his parent or any other parent!
xDispatcher = xParent - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
}
//-----------------------------------------------------------------------------------------------------
// I.VI) "_top"
// This request must be forwarded to any parent frame, till we reach a top frame.
// If no parent exist, we can handle itself.
//-----------------------------------------------------------------------------------------------------
else
if ( sTargetName = = SPECIALTARGET_TOP )
{
if ( xFrame - > isTop ( ) )
{
2007-04-16 15:38:44 +00:00
// If we are this top frame itself (means our owner frame)
// we should call ourself recursiv with a better target "_self".
// So we can share the same code! (see reaction for "_self" inside this method too.)
xDispatcher = this - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
2003-03-25 17:22:13 +00:00
}
else
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xParent ( xFrame - > getCreator ( ) , css : : uno : : UNO_QUERY ) ;
2010-11-05 10:31:15 +08:00
// Normaly if isTop() returned sal_False ... the parent frame MUST(!) exist ...
2003-03-25 17:22:13 +00:00
// But it seams to be better to check that here to prevent us against an access violation.
if ( xParent . is ( ) )
xDispatcher = xParent - > queryDispatch ( aURL , SPECIALTARGET_TOP , 0 ) ;
}
}
//-----------------------------------------------------------------------------------------------------
// I.VII) "_self", ""
2002-05-23 11:54:59 +00:00
// Our owner frame should handle this URL. But we can't do it for all of them.
// So we ask the internal setted controller first. If he disagree we try to find a registered
// protocol handler. If this failed too - we check for a loadable content and in case of true
// we load it into the frame by returning specilized dispatch object.
//-----------------------------------------------------------------------------------------------------
else
if (
2003-03-25 17:22:13 +00:00
( sTargetName = = SPECIALTARGET_SELF ) | |
2011-12-26 14:20:50 -02:00
( sTargetName . isEmpty ( ) )
2002-05-23 11:54:59 +00:00
)
{
2007-04-16 15:38:44 +00:00
// There exist a hard coded interception for special URLs.
2009-02-12 10:27:21 +00:00
if (
2011-01-16 14:12:57 +00:00
( aURL . Complete . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " .uno:CloseDoc " ) ) ) | |
( aURL . Complete . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " .uno:CloseWin " ) ) )
2009-02-12 10:27:21 +00:00
)
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xParent ( xFrame - > getCreator ( ) , css : : uno : : UNO_QUERY ) ;
// In case the frame is not a top one, is not based on system window and has a parent,
// the parent frame should to be queried for the correct dispatcher.
// See i93473
if (
! WindowHelper : : isTopWindow ( xFrame - > getContainerWindow ( ) ) & &
! VCLUnoHelper : : GetWindow ( xFrame - > getContainerWindow ( ) ) - > IsSystemWindow ( ) & &
xParent . is ( )
)
xDispatcher = xParent - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
else
xDispatcher = implts_getOrCreateDispatchHelper ( E_CLOSEDISPATCHER , xFrame ) ;
}
2011-01-16 14:12:57 +00:00
else if ( aURL . Complete . equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( " .uno:CloseFrame " ) ) )
2007-04-16 15:38:44 +00:00
xDispatcher = implts_getOrCreateDispatchHelper ( E_CLOSEDISPATCHER , xFrame ) ;
if ( ! xDispatcher . is ( ) )
{
// Ask our controller for his agreement for these dispatched URL ...
// because some URLs are internal and can be handled faster by SFX - which most is the current controller!
// But in case of e.g. the bibliography not all queries will be handled successfully here.
css : : uno : : Reference < css : : frame : : XDispatchProvider > xController ( xFrame - > getController ( ) , css : : uno : : UNO_QUERY ) ;
if ( xController . is ( ) )
xDispatcher = xController - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
}
2003-03-25 17:22:13 +00:00
// If controller has no fun to dispatch these URL - we must search another right dispatcher.
// Search for any registered protocol handler first.
if ( ! xDispatcher . is ( ) )
xDispatcher = implts_searchProtocolHandler ( aURL ) ;
// Not for controller - not for protocol handler
// It should be a loadable content - may be a file. Check it ...
// This check is neccessary to found out, that
// support for some protocols isn't installed by user. May be
// "ftp" isn't available. So we suppress creation of our self dispatcher.
// The result will be clear. He can't handle it - but he would try it.
if (
( ! xDispatcher . is ( ) ) & &
( implts_isLoadableContent ( aURL ) )
)
2002-05-23 11:54:59 +00:00
{
xDispatcher = implts_getOrCreateDispatchHelper ( E_SELFDISPATCHER , xFrame ) ;
}
}
//-----------------------------------------------------------------------------------------------------
// I.VI) no further special handlings exist
// Now we have to search for the right target frame by calling findFrame() - but should provide our code
// against creation of a new task if no frame could be found.
// I said it before - it's allowed for dispatch() only.
//-----------------------------------------------------------------------------------------------------
else
{
sal_Int32 nRightFlags = nSearchFlags ;
nRightFlags & = ~ css : : frame : : FrameSearchFlag : : CREATE ;
// try to find any existing target and ask him for his dispatcher
2003-03-25 17:22:13 +00:00
css : : uno : : Reference < css : : frame : : XFrame > xFoundFrame = xFrame - > findFrame ( sTargetName , nRightFlags ) ;
2002-05-23 11:54:59 +00:00
if ( xFoundFrame . is ( ) )
{
// Attention: Found target is our own owner frame!
// Don't ask him for his dispatcher. We know it already - it's our self dispatch helper.
// Otherwhise we can start a never ending recursiv call. Why?
// Somewere called our owner frame - he called some interceptor objects - and may by this dispatch provider
// is called. If wa use queryDispatch() on our owner frame again - we start this call stack again ... and again.
if ( xFoundFrame = = xFrame )
xDispatcher = implts_getOrCreateDispatchHelper ( E_SELFDISPATCHER , xFrame ) ;
else
{
css : : uno : : Reference < css : : frame : : XDispatchProvider > xProvider ( xFoundFrame , css : : uno : : UNO_QUERY ) ;
xDispatcher = xProvider - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
}
}
else
// if it couldn't be found - but creation was allowed
2004-01-28 13:28:57 +00:00
// forward request to the desktop.
2002-05-23 11:54:59 +00:00
// Note: The given target name must be used to set the name on new created task!
// Don't forward request by changing it to a special one e.g _blank.
// Use the CREATE flag only to prevent call against further searches.
// We already know it - the target must be created new.
if ( nSearchFlags & css : : frame : : FrameSearchFlag : : CREATE )
{
2004-01-28 13:28:57 +00:00
css : : uno : : Reference < css : : frame : : XDispatchProvider > xParent ( xFrame - > getCreator ( ) , css : : uno : : UNO_QUERY ) ;
if ( xParent . is ( ) )
xDispatcher = xParent - > queryDispatch ( aURL , sTargetName , css : : frame : : FrameSearchFlag : : CREATE ) ;
2002-05-23 11:54:59 +00:00
}
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
return xDispatcher ;
}
//_________________________________________________________________________________________________________________
/**
@ short search for a registered protocol handler and ask him for a dispatch object
2002-09-05 11:13:03 +00:00
@ descr Wes earch a suitable handler inside our cfg package org . openoffice . Office . ProtocolHandler .
If we found anyone , we create and initialize it . Initialize means : we set our owner frame on it
as context information . He can use it or leave it . Of course - we are aware of handler implementations ,
which doesn ' t support initialization . It ' s an optional feature .
2002-05-23 11:54:59 +00:00
@ param aURL
the dispatch URL for which may a handler is registered
2002-09-05 11:13:03 +00:00
@ return A dispatch object if a handler was found and agree with the given URL or < NULL / > otherwhise .
2002-05-23 11:54:59 +00:00
@ threadsafe yes
2002-09-05 11:13:03 +00:00
@ modified 05.09 .2002 13 : 43 , as96863
2002-05-23 11:54:59 +00:00
*/
css : : uno : : Reference < css : : frame : : XDispatch > DispatchProvider : : implts_searchProtocolHandler ( const css : : util : : URL & aURL )
{
css : : uno : : Reference < css : : frame : : XDispatch > xDispatcher ;
ProtocolHandler aHandler ;
2002-09-05 11:13:03 +00:00
// This member is threadsafe by himself and lives if we live - we doesn't need any mutex here.
if ( m_aProtocolHandlerCache . search ( aURL , & aHandler ) )
2001-07-03 06:58:21 +00:00
{
2002-05-23 11:54:59 +00:00
/* SAFE { */
2002-09-05 11:13:03 +00:00
ReadGuard aReadLock ( m_aLock ) ;
// create it
css : : uno : : Reference < css : : frame : : XDispatchProvider > xHandler ;
try
{
xHandler = css : : uno : : Reference < css : : frame : : XDispatchProvider > (
m_xFactory - > createInstance ( aHandler . m_sUNOName ) ,
css : : uno : : UNO_QUERY ) ;
}
2011-12-14 00:03:52 +09:00
catch ( const css : : uno : : Exception & ) { }
2002-09-05 11:13:03 +00:00
// look if initialization is neccessary
css : : uno : : Reference < css : : lang : : XInitialization > xInit ( xHandler , css : : uno : : UNO_QUERY ) ;
if ( xInit . is ( ) )
{
css : : uno : : Reference < css : : frame : : XFrame > xOwner ( m_xFrame . get ( ) , css : : uno : : UNO_QUERY ) ;
LOG_ASSERT ( xOwner . is ( ) , " DispatchProvider::implts_searchProtocolHandler() \n Couldn't get reference to my owner frame. So I can't set may needed context information for this protocol handler. " )
if ( xOwner . is ( ) )
{
try
{
// but do it only, if all context informations are OK
css : : uno : : Sequence < css : : uno : : Any > lContext ( 1 ) ;
lContext [ 0 ] < < = xOwner ;
xInit - > initialize ( lContext ) ;
}
2011-12-14 00:03:52 +09:00
catch ( const css : : uno : : Exception & ) { }
2002-09-05 11:13:03 +00:00
}
}
aReadLock . unlock ( ) ;
2002-05-23 11:54:59 +00:00
/* } SAFE */
2002-09-05 11:13:03 +00:00
// ask for his (sub)dispatcher for the given URL
2002-05-23 11:54:59 +00:00
if ( xHandler . is ( ) )
xDispatcher = xHandler - > queryDispatch ( aURL , SPECIALTARGET_SELF , 0 ) ;
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
return xDispatcher ;
2001-07-03 06:58:21 +00:00
}
2002-05-23 11:54:59 +00:00
//_________________________________________________________________________________________________________________
/**
2001-07-03 06:58:21 +00:00
@ short get or create new dispatch helper
@ descr Sometimes we need some helper implementations to support dispatching of special URLs or commands .
But it ' s not a good idea to hold these services for the whole life time of this provider instance .
We should create it on demand . . .
2002-05-23 11:54:59 +00:00
Thats why we implement this method . It return an already existing helper or create a new one otherwise .
2004-01-28 13:28:57 +00:00
@ attention The parameter sTarget and nSearchFlags are defaulted to " " and 0 !
Please use it only , if you can be shure , that the realy given by the outside calli !
Mostly it depends from the parameter eHelper is they are required or not .
2002-05-23 11:54:59 +00:00
@ param eHelper
specify the requested dispatch helper
@ param xOwner
the target of possible dispatch ( ) call on created dispatch helper
2004-01-28 13:28:57 +00:00
@ param sTarget
the target parameter of the original queryDispatch ( ) request
@ param nSearchFlags
the flags parameter of the original queryDispatch ( ) request
2001-07-03 06:58:21 +00:00
@ return A reference to a dispatch helper .
@ threadsafe yes
2004-01-28 13:28:57 +00:00
@ modified 20.08 .2003 10 : 22 , as96863
2002-05-23 11:54:59 +00:00
*/
css : : uno : : Reference < css : : frame : : XDispatch > DispatchProvider : : implts_getOrCreateDispatchHelper ( EDispatchHelper eHelper ,
const css : : uno : : Reference < css : : frame : : XFrame > & xOwner ,
2004-01-28 13:28:57 +00:00
const : : rtl : : OUString & sTarget ,
sal_Int32 nSearchFlags )
2001-07-03 06:58:21 +00:00
{
css : : uno : : Reference < css : : frame : : XDispatch > xDispatchHelper ;
2002-05-23 11:54:59 +00:00
/* SAFE { */
ReadGuard aReadLock ( m_aLock ) ;
css : : uno : : Reference < css : : lang : : XMultiServiceFactory > xFactory = m_xFactory ;
aReadLock . unlock ( ) ;
/* } SAFE */
switch ( eHelper )
2001-07-03 06:58:21 +00:00
{
2002-05-23 11:54:59 +00:00
case E_MENUDISPATCHER :
{
// Attention: Such menue dispatcher must be a singleton for this frame - means our owner frame.
// Otherwhise he can make some trouble.
/* SAFE { */
WriteGuard aWriteLock ( m_aLock ) ;
if ( ! m_xMenuDispatcher . is ( ) )
{
MenuDispatcher * pDispatcher = new MenuDispatcher ( xFactory , xOwner ) ;
m_xMenuDispatcher = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
xDispatchHelper = m_xMenuDispatcher ;
aWriteLock . unlock ( ) ;
/* } SAFE */
}
break ;
case E_CREATEDISPATCHER :
{
2004-01-28 13:28:57 +00:00
LoadDispatcher * pDispatcher = new LoadDispatcher ( xFactory , xOwner , sTarget , nSearchFlags ) ;
2002-05-23 11:54:59 +00:00
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
break ;
case E_BLANKDISPATCHER :
{
css : : uno : : Reference < css : : frame : : XFrame > xDesktop ( xOwner , css : : uno : : UNO_QUERY ) ;
if ( xDesktop . is ( ) )
{
2004-01-28 13:28:57 +00:00
LoadDispatcher * pDispatcher = new LoadDispatcher ( xFactory , xOwner , SPECIALTARGET_BLANK , 0 ) ;
2002-05-23 11:54:59 +00:00
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
}
break ;
case E_DEFAULTDISPATCHER :
{
css : : uno : : Reference < css : : frame : : XFrame > xDesktop ( xOwner , css : : uno : : UNO_QUERY ) ;
if ( xDesktop . is ( ) )
{
2004-01-28 13:28:57 +00:00
LoadDispatcher * pDispatcher = new LoadDispatcher ( xFactory , xOwner , SPECIALTARGET_DEFAULT , 0 ) ;
2002-05-23 11:54:59 +00:00
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
}
break ;
case E_SELFDISPATCHER :
{
2004-01-28 13:28:57 +00:00
LoadDispatcher * pDispatcher = new LoadDispatcher ( xFactory , xOwner , SPECIALTARGET_SELF , 0 ) ;
2002-05-23 11:54:59 +00:00
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
break ;
2003-03-25 17:22:13 +00:00
case E_CLOSEDISPATCHER :
{
2007-04-16 15:38:44 +00:00
CloseDispatcher * pDispatcher = new CloseDispatcher ( xFactory , xOwner , sTarget ) ;
2003-03-25 17:22:13 +00:00
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
2009-09-18 10:15:03 +00:00
break ;
2009-01-02 15:26:18 +00:00
case E_STARTMODULEDISPATCHER :
{
StartModuleDispatcher * pDispatcher = new StartModuleDispatcher ( xFactory , xOwner , sTarget ) ;
xDispatchHelper = css : : uno : : Reference < css : : frame : : XDispatch > ( static_cast < : : cppu : : OWeakObject * > ( pDispatcher ) , css : : uno : : UNO_QUERY ) ;
}
2003-03-25 17:22:13 +00:00
break ;
2001-07-03 06:58:21 +00:00
}
2001-08-02 12:34:32 +00:00
2001-07-03 06:58:21 +00:00
return xDispatchHelper ;
}
2002-05-23 11:54:59 +00:00
//_________________________________________________________________________________________________________________
/**
2001-08-08 08:52:46 +00:00
@ short check URL for support by our used loader or handler
2001-08-02 12:34:32 +00:00
@ descr If we must return our own dispatch helper implementations ( self , blank , create dispatcher ! )
2001-08-08 08:52:46 +00:00
we should be shure , that URL describe any loadable content . Otherwise slot / uno URLs
2002-05-23 11:54:59 +00:00
will be detected . . . but there exist nothing for ral loading into a target frame !
2001-08-02 12:34:32 +00:00
2002-05-23 11:54:59 +00:00
@ param aURL
URL which should be " detected "
@ return < TRUE / > if somewhere could handle that - < FALSE / > otherwise .
2001-08-02 12:34:32 +00:00
@ threadsafe yes
2002-05-23 11:54:59 +00:00
@ modified 17.05 .2002 09 : 47 , as96863
*/
2001-08-02 12:34:32 +00:00
sal_Bool DispatchProvider : : implts_isLoadableContent ( const css : : util : : URL & aURL )
{
2004-01-28 13:28:57 +00:00
LoadEnv : : EContentType eType = LoadEnv : : classifyContent ( aURL . Complete , css : : uno : : Sequence < css : : beans : : PropertyValue > ( ) ) ;
2004-07-06 15:57:07 +00:00
return ( eType = = LoadEnv : : E_CAN_BE_LOADED ) ;
2001-08-02 12:34:32 +00:00
}
2002-05-23 11:54:59 +00:00
} // namespace framework
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */