summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorMaxim Nikolenko <maximnproductengine@lindenlab.com>2024-06-11 12:27:22 +0300
committerGitHub <noreply@github.com>2024-06-11 12:27:22 +0300
commit3d1aac4f5c369e9d402c41f1c790d9015f7c7773 (patch)
treef911416d189a02775a21e3fc94b4bf8027e4ada9 /indra/llui
parentdbc785d4433080ca49b9cd899c756c9700a1a794 (diff)
parent7331d281e84da73907e1067b03ad4662991f4808 (diff)
Merge pull request #1481 from secondlife/lua-ui-callbacks
Add trusted flag to UI callbacks, so not everything is accessible from the script
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llmenugl.h10
-rw-r--r--indra/llui/llnotifications.cpp2
-rw-r--r--indra/llui/llscrolllistctrl.cpp2
-rw-r--r--indra/llui/lltextbase.cpp2
-rw-r--r--indra/llui/lltoolbar.cpp2
-rw-r--r--indra/llui/llui.cpp3
-rw-r--r--indra/llui/lluictrl.cpp14
-rw-r--r--indra/llui/lluictrl.h47
8 files changed, 64 insertions, 18 deletions
diff --git a/indra/llui/llmenugl.h b/indra/llui/llmenugl.h
index e8d6043e54..baa6e9624d 100644
--- a/indra/llui/llmenugl.h
+++ b/indra/llui/llmenugl.h
@@ -950,16 +950,18 @@ public:
LLUICtrl::EnableCallbackRegistry::currentRegistrar().add(name, boost::bind(&view_listener_t::handleEvent, listener, _2));
}
- static void addCommit(view_listener_t* listener, const std::string& name)
+ typedef LLUICtrl::CommitCallbackInfo cb_info;
+ static void addCommit(view_listener_t *listener, const std::string &name, cb_info::EUntrustedCall handle_untrusted = cb_info::UNTRUSTED_ALLOW)
{
- LLUICtrl::CommitCallbackRegistry::currentRegistrar().add(name, boost::bind(&view_listener_t::handleEvent, listener, _2));
+ LLUICtrl::CommitCallbackRegistry::currentRegistrar().add(name,
+ cb_info([listener](LLUICtrl*, const LLSD& param){ return listener->handleEvent(param); }, handle_untrusted));
}
- static void addMenu(view_listener_t* listener, const std::string& name)
+ static void addMenu(view_listener_t *listener, const std::string &name, cb_info::EUntrustedCall handle_untrusted = cb_info::UNTRUSTED_ALLOW)
{
// For now, add to both click and enable registries
addEnable(listener, name);
- addCommit(listener, name);
+ addCommit(listener, name, handle_untrusted);
}
static void cleanup()
diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp
index 2fbae73b65..7905ff7ce0 100644
--- a/indra/llui/llnotifications.cpp
+++ b/indra/llui/llnotifications.cpp
@@ -1243,7 +1243,7 @@ LLNotifications::LLNotifications()
mIgnoreAllNotifications(false)
{
mListener.reset(new LLNotificationsListener(*this));
- LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Notification.Show", boost::bind(&LLNotifications::addFromCallback, this, _2));
+ LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("Notification.Show", { boost::bind(&LLNotifications::addFromCallback, this, _2) });
// touch the instance tracker for notification channels, so that it will still be around in our destructor
LLInstanceTracker<LLNotificationChannel, std::string>::instanceCount();
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 7fb732eca3..d32af15f0c 100644
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -1991,7 +1991,7 @@ BOOL LLScrollListCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask)
// set up the callbacks for all of the avatar/group menu items
// (N.B. callbacks don't take const refs as id is local scope)
bool is_group = (mContextMenuType == MENU_GROUP);
- LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
+ ScopedRegistrarHelper registrar;
registrar.add("Url.ShowProfile", boost::bind(&LLScrollListCtrl::showProfile, id, is_group));
registrar.add("Url.SendIM", boost::bind(&LLScrollListCtrl::sendIM, id));
registrar.add("Url.AddFriend", boost::bind(&LLScrollListCtrl::addFriend, id));
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index c1eedf93a7..32b28834b2 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -2085,7 +2085,7 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
// set up the callbacks for all of the potential menu items, N.B. we
// don't use const ref strings in callbacks in case url goes out of scope
- LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
+ CommitRegistrarHelper registrar(LLUICtrl::CommitCallbackRegistry::currentRegistrar());
registrar.add("Url.Open", boost::bind(&LLUrlAction::openURL, url));
registrar.add("Url.OpenInternal", boost::bind(&LLUrlAction::openURLInternal, url));
registrar.add("Url.OpenExternal", boost::bind(&LLUrlAction::openURLExternal, url));
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 8a6cb683d2..cb9539a573 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -144,7 +144,7 @@ void LLToolBar::createContextMenu()
{
// Setup bindings specific to this instance for the context menu options
- LLUICtrl::CommitCallbackRegistry::ScopedRegistrar commit_reg;
+ CommitRegistrarHelper commit_reg(LLUICtrl::CommitCallbackRegistry::currentRegistrar());
commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2));
commit_reg.add("Toolbars.RemoveSelectedCommand", boost::bind(&LLToolBar::onRemoveSelectedCommand, this));
diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp
index c7539fcec7..07a962e515 100644
--- a/indra/llui/llui.cpp
+++ b/indra/llui/llui.cpp
@@ -167,8 +167,7 @@ mHelpImpl(NULL)
LLFontGL::sShadowColor = LLUIColorTable::instance().getColor("ColorDropShadow");
- LLUICtrl::CommitCallbackRegistry::Registrar& reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar();
-
+ LLUICtrl::CommitRegistrarHelper reg(LLUICtrl::CommitCallbackRegistry::defaultRegistrar());
// Callbacks for associating controls with floater visibility:
reg.add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleInstance, _2, LLSD()));
reg.add("Floater.ToggleOrBringToFront", boost::bind(&LLFloaterReg::toggleInstanceOrBringToFront, _2, LLSD()));
diff --git a/indra/llui/lluictrl.cpp b/indra/llui/lluictrl.cpp
index 69093393d9..68d15eb424 100644
--- a/indra/llui/lluictrl.cpp
+++ b/indra/llui/lluictrl.cpp
@@ -220,10 +220,10 @@ void LLUICtrl::initFromParams(const Params& p)
}
else
{
- commit_callback_t* initfunc = (CommitCallbackRegistry::getValue(p.init_callback.function_name));
- if (initfunc)
+ LLUICtrl::CommitCallbackInfo *info = (CommitCallbackRegistry::getValue(p.init_callback.function_name));
+ if (info && info->callback_func)
{
- (*initfunc)(this, p.init_callback.parameter);
+ (info->callback_func)(this, p.init_callback.parameter);
}
}
}
@@ -283,13 +283,13 @@ LLUICtrl::commit_signal_t::slot_type LLUICtrl::initCommitCallback(const CommitCa
{
std::string function_name = cb.function_name;
setFunctionName(function_name);
- commit_callback_t* func = (CommitCallbackRegistry::getValue(function_name));
- if (func)
+ LLUICtrl::CommitCallbackInfo *info = (CommitCallbackRegistry::getValue(function_name));
+ if (info && info->callback_func)
{
if (cb.parameter.isProvided())
- return boost::bind((*func), _1, cb.parameter);
+ return boost::bind((info->callback_func), _1, cb.parameter);
else
- return commit_signal_t::slot_type(*func);
+ return commit_signal_t::slot_type(info->callback_func);
}
else if (!function_name.empty())
{
diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h
index d21e8dc1c6..46d651b19c 100644
--- a/indra/llui/lluictrl.h
+++ b/indra/llui/lluictrl.h
@@ -273,11 +273,56 @@ public:
template <typename F, typename DERIVED> class CallbackRegistry : public LLRegistrySingleton<std::string, F, DERIVED >
{};
+ struct CommitCallbackInfo
+ {
+ enum EUntrustedCall
+ {
+ UNTRUSTED_ALLOW,
+ UNTRUSTED_BLOCK,
+ UNTRUSTED_THROTTLE
+ };
+
+ CommitCallbackInfo(commit_callback_t func = {}, EUntrustedCall handle_untrusted = UNTRUSTED_ALLOW) :
+ callback_func(func),
+ handle_untrusted(handle_untrusted)
+ {
+ }
- class CommitCallbackRegistry : public CallbackRegistry<commit_callback_t, CommitCallbackRegistry>
+ public:
+ commit_callback_t callback_func;
+ EUntrustedCall handle_untrusted;
+ };
+ typedef LLUICtrl::CommitCallbackInfo cb_info;
+ class CommitCallbackRegistry : public CallbackRegistry<CommitCallbackInfo, CommitCallbackRegistry>
{
LLSINGLETON_EMPTY_CTOR(CommitCallbackRegistry);
};
+
+ class CommitRegistrarHelper
+ {
+ public:
+ CommitRegistrarHelper(LLUICtrl::CommitCallbackRegistry::Registrar &registrar) : mRegistrar(registrar) {}
+
+ template <typename... ARGS> void add(const std::string &name, ARGS &&...args)
+ {
+ mRegistrar.add(name, {std::forward<ARGS>(args)...});
+ }
+ private:
+ LLUICtrl::CommitCallbackRegistry::Registrar &mRegistrar;
+ };
+
+ class ScopedRegistrarHelper
+ {
+ public:
+ template <typename... ARGS> void add(const std::string &name, ARGS &&...args)
+ {
+ mRegistrar.add(name, {std::forward<ARGS>(args)...});
+ }
+
+ private:
+ LLUICtrl::CommitCallbackRegistry::ScopedRegistrar mRegistrar;
+ };
+
// the enable callback registry is also used for visiblity callbacks
class EnableCallbackRegistry : public CallbackRegistry<enable_callback_t, EnableCallbackRegistry>
{