warning dialog gets launched when adding binding to script in doc
workaround issue: no functionProvider created on doc open
This commit is contained in:
Duncan Foster
2003-02-28 12:43:04 +00:00
parent f9ece96fd3
commit cce9740dc0
4 changed files with 93 additions and 52 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ScriptSecurityManager.cxx,v $
*
* $Revision: 1.12 $
* $Revision: 1.13 $
*
* last change: $Author: dfoster $ $Date: 2003-02-25 16:08:37 $
* last change: $Author: dfoster $ $Date: 2003-02-28 13:43:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -113,12 +113,20 @@ ScriptSecurityManager::ScriptSecurityManager(
readConfiguration();
}
void ScriptSecurityManager::addScriptStorage( rtl::OUString url,
void ScriptSecurityManager::addScriptStorage( rtl::OUString scriptStorageURL,
sal_Int32 storageID)
{
Permission_Hash::const_iterator ph_it = m_permissionSettings.find( scriptStorageURL );
if ( ph_it != m_permissionSettings.end() )
{
OSL_TRACE( "ScriptSecurityManager::addScriptStorage: already called for %s",
::rtl::OUStringToOString( scriptStorageURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer);
return;
}
readConfiguration();
StoragePerm newPerm;
newPerm.url=url;
newPerm.scriptStorageURL=scriptStorageURL;
newPerm.storageID=storageID;
// we err on the side of caution!!
@@ -163,7 +171,7 @@ void ScriptSecurityManager::addScriptStorage( rtl::OUString url,
{
OSL_TRACE("according to path");
// check path
rtl::OUString path = url.copy( 0, url.lastIndexOf( '/' ) );
rtl::OUString path = scriptStorageURL.copy( 0, scriptStorageURL.lastIndexOf( '/' ) );
OSL_TRACE( "no of elts in path list = %d",
(int)m_secureURL.getLength() );
bool match = false;
@@ -251,28 +259,17 @@ void ScriptSecurityManager::addScriptStorage( rtl::OUString url,
if ( newPerm.execPermission == sal_True )
{
OSL_TRACE("setting exec permission to true for %s",
::rtl::OUStringToOString( url,
RTL_TEXTENCODING_ASCII_US ).pData->buffer);
::rtl::OUStringToOString( scriptStorageURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
else
{
OSL_TRACE("setting exec permission to false for %s",
::rtl::OUStringToOString( url,
RTL_TEXTENCODING_ASCII_US ).pData->buffer);
::rtl::OUStringToOString( scriptStorageURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
/* need to clear out vector in case we've seen this doc before */
::std::vector< StoragePerm >::iterator iter;
::std::vector< StoragePerm >::iterator iterEnd =
m_permissionSettings.end();
for ( iter = m_permissionSettings.begin() ; iter != iterEnd; ++iter )
{
if ( iter->url.equals( url ) )
{
m_permissionSettings.erase(iter);
}
}
m_permissionSettings.push_back(newPerm);
m_permissionSettings[ scriptStorageURL ] = newPerm;
}
short ScriptSecurityManager::executeDialog( const OUString & path )
@@ -296,7 +293,7 @@ short ScriptSecurityManager::executeDialog( const OUString & path )
}
/**
* checks to see whether the requested ScriptPeremission is allowed.
* checks to see whether the requested ScriptPermission is allowed.
* This was modelled after the Java AccessController, but at this time
* we can't see a good reason not to return a bool, rather than throw
* an exception if the request is not granted (as is the case in Java).
@@ -311,22 +308,35 @@ sal_Bool ScriptSecurityManager::checkPermission( const OUString & scriptStorageU
"ScriptSecurityManager::checkPermission: execute permission request for %s",
::rtl::OUStringToOString( scriptStorageURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer);
::std::vector< StoragePerm >::const_iterator iter;
::std::vector< StoragePerm >::const_iterator iterEnd =
Permission_Hash::const_iterator ph_it = m_permissionSettings.find( scriptStorageURL );
Permission_Hash::const_iterator ph_itend =
m_permissionSettings.end();
for ( iter = m_permissionSettings.begin() ; iter != iterEnd; ++iter )
if ( ph_it != ph_itend )
{
if ( iter->url.equals( scriptStorageURL ) )
{
// warning dialog if necessary
return iter->execPermission;
}
return ph_it->second.execPermission;
}
// we should never get here!!
throw RuntimeException( OUString::createFromAscii( "ScriptSecurityManager::checkPermission: storageURL not found" ), Reference< XInterface > () );
}
else
return sal_True;
return sal_True;
}
void ScriptSecurityManager::removePermissionSettings ( ::rtl::OUString & scriptStorageURL )
{
Permission_Hash::const_iterator ph_it =
m_permissionSettings.find( scriptStorageURL );
if ( ph_it == m_permissionSettings.end() )
{
OSL_TRACE( "Entry for storage url %s doesn't exist in map",
::rtl::OUStringToOString( scriptStorageURL,
RTL_TEXTENCODING_ASCII_US ).pData->buffer);
return;
}
// erase the entry from the hash
m_permissionSettings.erase( scriptStorageURL );
}
void ScriptSecurityManager::readConfiguration()

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ScriptSecurityManager.hxx,v $
*
* $Revision: 1.6 $
* $Revision: 1.7 $
*
* last change: $Author: dfoster $ $Date: 2003-02-13 17:29:39 $
* last change: $Author: dfoster $ $Date: 2003-02-28 13:43:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,7 +63,7 @@
#ifndef _FRAMEWORK_SCRIPT_SCRIPTSECURITYMANAGER_HXX_
#define _FRAMEWORK_SCRIPT_SCRIPTSECURITYMANAGER_HXX_
#include <vector>
#include <hash_map>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
@@ -76,11 +76,13 @@ namespace scripting_securitymgr
#define dcsssf ::drafts::com::sun::star::script::framework
struct StoragePerm {
rtl::OUString url;
rtl::OUString scriptStorageURL;
sal_Int32 storageID;
sal_Bool execPermission;
};
typedef ::std::hash_map< ::rtl::OUString, StoragePerm, ::rtl::OUStringHash,
::std::equal_to< ::rtl::OUString > > Permission_Hash;
/**
* Class responsible for managing the ScriptSecurity.
*/
@@ -91,7 +93,7 @@ public:
const css::uno::Reference< css::uno::XComponentContext > & xContext )
throw ( css::uno::RuntimeException );
~ScriptSecurityManager();
void addScriptStorage( rtl::OUString url, sal_Int32 storageID);
void addScriptStorage( rtl::OUString scriptStorageURL, sal_Int32 storageID);
/**
* checks to see if the requested permission can be granted
* checks to see whether the requested ScriptPeremission is allowed.
@@ -102,6 +104,7 @@ public:
sal_Bool checkPermission( const rtl::OUString & scriptStorageURL,
const rtl::OUString & permissionRequest )
throw (css::uno::RuntimeException);
void removePermissionSettings ( ::rtl::OUString & scriptStorageURL );
private:
void readConfiguration() throw (css::uno::RuntimeException);
short executeDialog ( const rtl::OUString & path );
@@ -111,7 +114,7 @@ private:
sal_Bool m_warning;
sal_Int32 m_officeBasic;
css::uno::Sequence< rtl::OUString > m_secureURL;
::std::vector< StoragePerm > m_permissionSettings;
Permission_Hash m_permissionSettings;
};
} // scripting_securitymgr

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ScriptStorageManager.cxx,v $
*
* $Revision: 1.21 $
* $Revision: 1.22 $
*
* last change: $Author: npower $ $Date: 2003-02-13 13:52:06 $
* last change: $Author: dfoster $ $Date: 2003-02-28 13:43:04 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -253,20 +253,27 @@ throw ( RuntimeException )
//*************************************************************************
sal_Int32 SAL_CALL
ScriptStorageManager::createScriptStorageWithURI(
const Reference< ucb::XSimpleFileAccess >& xSFA, const OUString & stringURI )
const Reference< ucb::XSimpleFileAccess >& xSFA, const OUString & cStringURI )
throw ( RuntimeException )
{
OSL_TRACE( "** ==> ScriptStorageManager in createScriptingStorageWithURI\n" );
validateXRef( xSFA, "ScriptStorageManager::createScriptStorage: XSimpleFileAccess is not valid" );
sal_Int32 returnedID = getScriptStorageID(stringURI);
if (returnedID != -1)
{
OSL_TRACE("Using existing storage for %s",
::rtl::OUStringToOString( stringURI,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
return returnedID;
}
// related to issue 11866
// warning dialog gets launched when adding binding to script in doc
// workaround issue: no functionProvider created on doc open
// if NODIALOG tag, strip from stringURI, set boolean=true
bool displayDialog = true;
::rtl::OUString dialogTag = ::rtl::OUString::createFromAscii( "NoDialog::" );
::rtl::OUString stringURI = cStringURI;
if( stringURI.indexOf( dialogTag ) == 0 )
{
OSL_TRACE( "ScriptStorageManager::createScriptStorage: will not display security dialogs" );
stringURI = stringURI.copy( dialogTag.getLength() );
displayDialog = false;
}
sal_Int32 returnedID = getScriptStorageID(stringURI);
// convert file:///... url to vnd... syntax
::rtl::OUString canonicalURI(
@@ -275,8 +282,24 @@ throw ( RuntimeException )
rtl_UriCharClassUricNoSlash, rtl_UriEncodeCheckEscapes,
RTL_TEXTENCODING_ASCII_US ) );
returnedID = setupAnyStorage( xSFA, canonicalURI, stringURI );
m_securityMgr.addScriptStorage( stringURI, returnedID );
if (returnedID == -1)
{
OSL_TRACE("Creating new storage for %s",
::rtl::OUStringToOString( stringURI,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
returnedID = setupAnyStorage( xSFA, canonicalURI, stringURI );
}
else
{
OSL_TRACE("Using existing storage for %s",
::rtl::OUStringToOString( stringURI,
RTL_TEXTENCODING_ASCII_US ).pData->buffer );
}
if( displayDialog )
{
m_securityMgr.addScriptStorage( stringURI, returnedID );
}
return returnedID;
}
@@ -480,6 +503,7 @@ throw ( ::com::sun::star::uno::RuntimeException )
// erase the entry from the hash
m_ScriptStorageMap.erase( scriptStorageID );
m_securityMgr.removePermissionSettings ( docURI );
removeScriptDocURIHashEntry( docURI );
}