ScriptForge (dialogs, documents, widgets) Secure listeners

Listeners programmed in Basic are created with
  CreateUnoListener(prefix, listener)

The prefix argument determines the series of
routines run when an event is triggered.

So far, for SF internal listeners, the prefix
was chosen to minimize the risk of naming
collisions with routines present in user scripts.

In fact the prefix argument may be provided as
  Library.Module.Prefix
which eliminates the risk of ambiguity or
homonymy.

With the actual change forcing the full
qualification of prefixes, the risk is reduced
from epsilon to zero.

No impact on the user documentation.

Change-Id: I95ef4beec80c89a074c8bec809f416479e64d8cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182384
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
This commit is contained in:
Jean-Pierre Ledure
2025-03-01 14:38:42 +01:00
parent 05ed03e70f
commit dec9f7d5b2
7 changed files with 47 additions and 26 deletions
+4 -2
View File
@@ -1989,7 +1989,8 @@ Try:
_DialogModel.DesktopAsParent = Not ( _BuiltFromScratch And _BuiltInPython )
_DialogControl.setVisible(True)
&apos; Watch the window Close button
Set oListener = CreateUnoListener(&quot;_SFNONMODAL_&quot;, &quot;com.sun.star.awt.XTopWindowListener&quot;)
Set oListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFNONMODAL_&quot; _
, &quot;com.sun.star.awt.XTopWindowListener&quot;)
_DialogControl.addTopWindowListener(oListener)
lExecute = 0
End If
@@ -2359,7 +2360,8 @@ Dim bManager As Boolean &apos; Return value
Dim vControls As Variant &apos; Array of involved controls
Dim oControl As Object &apos; A DialogControl object
Dim i As Long
Const cstPrefix = &quot;_SFTAB_&quot; &apos; Prefix of Subs to trigger when involved controls are clicked
Const cstPrefix = &quot;SFDialogs.SF_DialogListener._SFTAB_&quot;
&apos; Prefix of Subs to trigger when involved controls are clicked
Const cstComma = &quot;,&quot;
Const cstThisSub = &quot;SFDialogs.Dialog.SetPageManager&quot;
@@ -2308,7 +2308,8 @@ Const cstSubArgs = &quot;Value&quot;
End If
&apos; Setup a new fresh listener
If Len(pvValue) &gt; 0 Then
Set _ExpandListener = CreateUnoListener(&quot;_SFEXP_&quot;, &quot;com.sun.star.awt.tree.XTreeExpansionListener&quot;)
Set _ExpandListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFEXP_&quot; _
, &quot;com.sun.star.awt.tree.XTreeExpansionListener&quot;)
_ControlView.addTreeExpansionListener(_ExpandListener)
_OnNodeExpanded = pvValue
End If
@@ -2326,7 +2327,8 @@ Const cstSubArgs = &quot;Value&quot;
End If
&apos; Setup a new fresh listener
If Len(pvValue) &gt; 0 Then
Set _SelectListener = CreateUnoListener(&quot;_SFSEL_&quot;, &quot;com.sun.star.view.XSelectionChangeListener&quot;)
Set _SelectListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFSEL_&quot; _
, &quot;com.sun.star.view.XSelectionChangeListener&quot;)
_ControlView.addSelectionChangeListener(_SelectListener)
_OnNodeSelected = pvValue
End If
+24 -8
View File
@@ -564,7 +564,9 @@ Try:
Case &quot;XActionListener&quot;
._ActionCounter = ._ActionCounter + iCounterIncrement
If ._ActionCounter = 1 Then
If IsNull(._ActionListener) Then Set ._ActionListener = CreateUnoListener(&quot;_SFACTION_&quot;, cstPrefix &amp; sListener)
If IsNull(._ActionListener) Then
Set ._ActionListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFACTION_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addActionListener(._ActionListener)
ElseIf ._ActionCounter &lt;= 0 Then
If Not IsNull(._ActionListener) Then oView.removeActionListener(._ActionListener)
@@ -573,7 +575,9 @@ Try:
Case &quot;XAdjustmentListener&quot;
._AdjustmentCounter = ._AdjustmentCounter + iCounterIncrement
If ._AdjustmentCounter = 1 Then
If IsNull(._AdjustmentListener) Then Set ._AdjustmentListener = CreateUnoListener(&quot;_SFADJUST_&quot;, cstPrefix &amp; sListener)
If IsNull(._AdjustmentListener) Then
Set ._AdjustmentListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFADJUST_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addAdjustmentListener(._AdjustmentListener)
ElseIf ._AdjustmentCounter &lt;= 0 Then
If Not IsNull(._AdjustmentListener) Then oView.removeAdjustmentListener(._AdjustmentListener)
@@ -582,7 +586,9 @@ Try:
Case &quot;XFocusListener&quot;
._FocusCounter = ._FocusCounter + iCounterIncrement
If ._FocusCounter = 1 Then
If IsNull(._FocusListener) Then Set ._FocusListener = CreateUnoListener(&quot;_SFFOCUS_&quot;, cstPrefix &amp; sListener)
If IsNull(._FocusListener) Then
Set ._FocusListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFFOCUS_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addFocusListener(._FocusListener)
ElseIf ._FocusCounter &lt;= 0 Then
If Not IsNull(._FocusListener) Then oView.removeFocusListener(._FocusListener)
@@ -591,7 +597,9 @@ Try:
Case &quot;XItemListener&quot;
._ItemCounter = ._ItemCounter + iCounterIncrement
If ._ItemCounter = 1 Then
If IsNull(._ItemListener) Then Set ._ItemListener = CreateUnoListener(&quot;_SFITEM_&quot;, cstPrefix &amp; sListener)
If IsNull(._ItemListener) Then
Set ._ItemListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFITEM_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addItemListener(._ItemListener)
ElseIf ._ItemCounter &lt;= 0 Then
If Not IsNull(._ItemListener) Then oView.removeItemListener(._ItemListener)
@@ -600,7 +608,9 @@ Try:
Case &quot;XKeyListener&quot;
._KeyCounter = ._KeyCounter + iCounterIncrement
If ._KeyCounter= 1 Then
If IsNull(._KeyListener) Then Set ._KeyListener = CreateUnoListener(&quot;_SFKEY_&quot;, cstPrefix &amp; sListener)
If IsNull(._KeyListener) Then
Set ._KeyListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFKEY_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addKeyListener(._KeyListener)
ElseIf ._KeyCounter &lt;= 0 Then
If Not IsNull(._KeyListener) Then oView.removeKeyListener(._KeyListener)
@@ -609,7 +619,9 @@ Try:
Case &quot;XMouseListener&quot;
._MouseCounter = ._MouseCounter + iCounterIncrement
If ._MouseCounter= 1 Then
If IsNull(._MouseListener) Then Set ._MouseListener = CreateUnoListener(&quot;_SFMOUSE_&quot;, cstPrefix &amp; sListener)
If IsNull(._MouseListener) Then
Set ._MouseListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFMOUSE_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addMouseListener(._MouseListener)
ElseIf ._MouseCounter &lt;= 0 Then
If Not IsNull(._MouseListener) Then oView.removeMouseListener(._MouseListener)
@@ -618,7 +630,9 @@ Try:
Case &quot;XMouseMotionListener&quot;
._MouseMotionCounter = ._MouseMotionCounter + iCounterIncrement
If ._MouseMotionCounter = 1 Then
If IsNull(._MouseMotionListener) Then Set ._MouseMotionListener = CreateUnoListener(&quot;_SFMOVE_&quot;, cstPrefix &amp; sListener)
If IsNull(._MouseMotionListener) Then
Set ._MouseMotionListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFMOVE_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addMouseMotionListener(._MouseMotionListener)
ElseIf ._MouseMotionCounter &lt;= 0 Then
If Not IsNull(._MouseMotionListener) Then oView.removeMouseMotionListener(._MouseMotionListener)
@@ -627,7 +641,9 @@ Try:
Case &quot;XTextListener&quot;
._TextCounter = ._TextCounter + iCounterIncrement
If ._TextCounter = 1 Then
If IsNull(._TextListener) Then Set ._TextListener = CreateUnoListener(&quot;_SFTEXT_&quot;, cstPrefix &amp; sListener)
If IsNull(._TextListener) Then
Set ._TextListener = CreateUnoListener(&quot;SFDialogs.SF_DialogListener._SFTEXT_&quot;, cstPrefix &amp; sListener)
End If
If iCounterIncrement = 1 Then oView.addTextListener(._TextListener)
ElseIf ._TextCounter &lt;= 0 Then
If Not IsNull(._TextListener) Then oView.removeTextListener(._TextListener)
+5 -5
View File
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDialogs" library:readonly="false" library:passwordprotected="false">
<library:element library:name="__License"/>
<library:element library:name="SF_Register"/>
<library:element library:name="SF_Dialog"/>
<library:element library:name="SF_DialogControl"/>
<library:element library:name="SF_DialogListener"/>
<library:element library:name="SF_DialogUtils"/>
<library:element library:name="SF_DialogListener"/>
<library:element library:name="SF_DialogControl"/>
<library:element library:name="SF_Dialog"/>
<library:element library:name="SF_Register"/>
<library:element library:name="__License"/>
</library:library>
@@ -47,7 +47,8 @@ Dim oController As Object &apos; com.sun.star.frame.Controller
Dim oListener As Object &apos; com.sun.star.sheet.XRangeSelectionListener
Dim lCountLoops As Long &apos; Sleep cycles counter
Const cstListenerPrefix = &quot;_SFRGSEL_&quot; &apos; Prefix used for naming events Subs
Const cstListenerPrefix = &quot;SFDocuments.SF_DocumentListener._SFRGSEL_&quot;
&apos; Prefix used for naming events Subs
Const cstSleep = 50 &apos; Sleep steps in ms while waiting for the end of the interaction
Const cstMaxSleep = (60 * 5 * 1000) / cstSleep &apos; Never sleep more than 5 minutes. Afterwards, processing continues
+1 -1
View File
@@ -29,7 +29,7 @@ Dim MenuListener As Object &apos; com.sun.star.awt.XMenuListener
REM =========================================================== PRIVATE CONSTANTS
Private Const _MenuListenerPrefix = &quot;_SFMENU_&quot;
Private Const _MenuListenerPrefix = &quot;SFWidgets.SF_MenuListener._SFMENU_&quot;
Private Const _MenuListener = &quot;com.sun.star.awt.XMenuListener&quot;
Private Const cstUnoPrefix = &quot;.uno:&quot;
Private Const cstScriptArg = &quot;:::&quot;
+7 -7
View File
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFWidgets" library:readonly="false" library:passwordprotected="false">
<library:element library:name="SF_ToolbarButton"/>
<library:element library:name="SF_Toolbar"/>
<library:element library:name="SF_MenuListener"/>
<library:element library:name="SF_Menu"/>
<library:element library:name="SF_ContextMenu"/>
<library:element library:name="SF_PopupMenu"/>
<library:element library:name="SF_Register"/>
<library:element library:name="__License"/>
<library:element library:name="SF_Register"/>
<library:element library:name="SF_PopupMenu"/>
<library:element library:name="SF_ContextMenu"/>
<library:element library:name="SF_Menu"/>
<library:element library:name="SF_MenuListener"/>
<library:element library:name="SF_Toolbar"/>
<library:element library:name="SF_ToolbarButton"/>
</library:library>