summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-10-06 17:08:57 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-10-08 16:12:20 +0200
commitf3ce30ec75a4d7116b9cd4d7b21d9aaa0e237eeb (patch)
tree63796907e0ec423d41d06fc15e9ceba0da567624 /scripting
parent078a81d5ba9f44b642e3e8b838fc4fe48a91810a (diff)
tdf#120363: try to avoid asking user to enable JVM when looking ...
... for a provider for an operation. When another provider actually handles an operation, it's useless to ask user to enable disabled JVM just to learn that it doesn't handle the request. So, this patch does the MasterScriptProvider operations in two steps: first with "Enable JVM" interaction disabled, and if failed, again with the interaction enabled to try disabled providers. This shouldn't typically give performance penalties in case when JVM is enabled, and when it's disabled and the operation is addressed to another provider. A context class designed to disable "Enable JVM" interaction is moved from cui/source/customize/cfgutil.cxx to a new comphelper header, which is supposed to hold similar helper context classes in needed. Change-Id: I21be922bfd80a276d9c8f1215d62a47bb3c225f5 Reviewed-on: https://gerrit.libreoffice.org/61468 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/provider/MasterScriptProvider.cxx126
1 files changed, 60 insertions, 66 deletions
diff --git a/scripting/source/provider/MasterScriptProvider.cxx b/scripting/source/provider/MasterScriptProvider.cxx
index 56082753e864..7f91fb83da12 100644
--- a/scripting/source/provider/MasterScriptProvider.cxx
+++ b/scripting/source/provider/MasterScriptProvider.cxx
@@ -18,6 +18,7 @@
*/
+#include <comphelper/DisableInteractionHelper.hxx>
#include <comphelper/documentinfo.hxx>
#include <cppuhelper/implementationentry.hxx>
@@ -450,6 +451,49 @@ MasterScriptProvider::parseLocationName( const OUString& location )
return temp;
}
+namespace
+{
+template <typename Proc> bool FindProviderAndApply(ProviderCache& rCache, Proc p)
+{
+ auto pass = [&rCache, &p]() -> bool
+ {
+ bool bResult = false;
+ for (auto& rProv : rCache.getAllProviders())
+ {
+ Reference<container::XNameContainer> xCont(rProv, UNO_QUERY);
+ if (!xCont.is())
+ {
+ continue;
+ }
+ try
+ {
+ bResult = p(xCont);
+ break;
+ }
+ catch (Exception& e)
+ {
+ SAL_INFO("scripting.provider", "ignoring " << e);
+ }
+ }
+ return bResult;
+ };
+ bool bSuccess = false;
+ // 1. Try to perform the operation without trying to enable JVM (if disabled)
+ // This allows us to avoid useless user interaction in case when other provider
+ // (not JVM) actually handles the operation.
+ {
+ css::uno::ContextLayer layer(
+ new comphelper::NoEnableJavaInteractionContext(css::uno::getCurrentContext()));
+ bSuccess = pass();
+ }
+ // 2. Now retry asking to enable JVM in case we didn't succeed first time
+ if (!bSuccess)
+ {
+ bSuccess = pass();
+ }
+ return bSuccess;
+}
+} // namespace
// Register Package
void SAL_CALL
@@ -487,29 +531,12 @@ MasterScriptProvider::insertByName( const OUString& aName, const Any& aElement )
"insertByName cannot instantiate "
"child script providers." );
}
- Sequence < Reference< provider::XScriptProvider > > xSProviders =
- providerCache()->getAllProviders();
- sal_Int32 index = 0;
-
- for ( ; index < xSProviders.getLength(); index++ )
- {
- Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
- if ( !xCont.is() )
- {
- continue;
- }
- try
- {
- xCont->insertByName( aName, aElement );
- break;
- }
- catch ( Exception& e )
- {
- SAL_INFO("scripting.provider", "ignoring " << e);
- }
-
- }
- if ( index == xSProviders.getLength() )
+ const bool bSuccess = FindProviderAndApply(
+ *providerCache(), [&aName, &aElement](Reference<container::XNameContainer>& xCont) {
+ xCont->insertByName(aName, aElement);
+ return true;
+ });
+ if (!bSuccess)
{
// No script providers could process the package
throw lang::IllegalArgumentException( "Failed to register package for " + aName,
@@ -550,27 +577,12 @@ MasterScriptProvider::removeByName( const OUString& Name )
"removeByName() cannot instantiate "
"child script providers." );
}
- Sequence < Reference< provider::XScriptProvider > > xSProviders =
- providerCache()->getAllProviders();
- sal_Int32 index = 0;
- for ( ; index < xSProviders.getLength(); index++ )
- {
- Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
- if ( !xCont.is() )
- {
- continue;
- }
- try
- {
- xCont->removeByName( Name );
- break;
- }
- catch ( Exception& )
- {
- }
-
- }
- if ( index == xSProviders.getLength() )
+ const bool bSuccess = FindProviderAndApply(
+ *providerCache(), [&Name](Reference<container::XNameContainer>& xCont) {
+ xCont->removeByName(Name);
+ return true;
+ });
+ if (!bSuccess)
{
// No script providers could process the package
throw lang::IllegalArgumentException( "Failed to revoke package for " + Name,
@@ -632,28 +644,10 @@ MasterScriptProvider::hasByName( const OUString& aName )
"removeByName() cannot instantiate "
"child script providers." );
}
- Sequence < Reference< provider::XScriptProvider > > xSProviders =
- providerCache()->getAllProviders();
- for ( sal_Int32 index = 0; index < xSProviders.getLength(); index++ )
- {
- Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
- if ( !xCont.is() )
- {
- continue;
- }
- try
- {
- result = xCont->hasByName( aName );
- if ( result )
- {
- break;
- }
- }
- catch ( Exception& )
- {
- }
-
- }
+ result = FindProviderAndApply(
+ *providerCache(), [&aName](Reference<container::XNameContainer>& xCont) {
+ return xCont->hasByName(aName);
+ });
}
return result;
}