From daca555592f8029df6a3d66d80a6a29fd268143f Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Tue, 18 Apr 2023 23:33:19 +0300
Subject: [PATCH] SL-19609 Urls aren't dispatched according to the indicated
 grid

---
 indra/newview/llagentlistener.cpp             |  3 +-
 indra/newview/llappearancemgr.cpp             | 11 ++-
 indra/newview/llbuycurrencyhtml.cpp           |  2 +-
 indra/newview/llchathistory.cpp               |  2 +-
 indra/newview/llchatitemscontainerctrl.cpp    |  2 +-
 indra/newview/llcommanddispatcherlistener.cpp |  2 +-
 indra/newview/llcommandhandler.cpp            |  7 +-
 indra/newview/llcommandhandler.h              |  4 +-
 indra/newview/lleventnotifier.cpp             |  6 +-
 indra/newview/llfloaterexperienceprofile.cpp  |  6 +-
 indra/newview/llfloaterhandler.cpp            |  2 +-
 indra/newview/llfloaterhandler.h              |  2 +-
 indra/newview/llfloaterimnearbychat.cpp       |  6 +-
 indra/newview/llfloatersearch.cpp             |  2 +-
 indra/newview/llfloaterworldmap.cpp           | 11 ++-
 indra/newview/llgroupactions.cpp              |  6 +-
 indra/newview/llloginhandler.cpp              |  1 +
 indra/newview/llloginhandler.h                |  2 +-
 indra/newview/llpaneleditwearable.cpp         |  2 +-
 indra/newview/llpanellogin.cpp                |  2 +-
 indra/newview/llpanelplaces.cpp               |  6 +-
 indra/newview/llpanelprofile.cpp              | 12 ++--
 indra/newview/llpanelprofileclassifieds.cpp   |  2 +-
 indra/newview/llpanelprofilepicks.cpp         |  6 +-
 indra/newview/llshareavatarhandler.cpp        |  2 +-
 indra/newview/llstatusbar.cpp                 |  2 +-
 indra/newview/llurldispatcher.cpp             | 69 ++++++++++++-------
 indra/newview/llviewerfloaterreg.cpp          |  1 +
 indra/newview/llviewerhelp.cpp                |  2 +-
 indra/newview/llviewerinventory.cpp           |  6 +-
 indra/newview/llviewerregion.cpp              |  8 ++-
 indra/newview/llvoicecallhandler.cpp          |  2 +-
 indra/newview/llvoiceclient.cpp               |  2 +-
 indra/newview/llworldmapview.cpp              |  3 +-
 34 files changed, 131 insertions(+), 73 deletions(-)

diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp
index 7887184a11b..5a720af038f 100644
--- a/indra/newview/llagentlistener.cpp
+++ b/indra/newview/llagentlistener.cpp
@@ -35,6 +35,7 @@
 #include "llcommandhandler.h"
 #include "llslurl.h"
 #include "llurldispatcher.h"
+#include "llviewernetwork.h"
 #include "llviewerobject.h"
 #include "llviewerobjectlist.h"
 #include "llviewerregion.h"
@@ -148,7 +149,7 @@ void LLAgentListener::requestTeleport(LLSD const & event_data) const
         params.append(event_data["x"]);
         params.append(event_data["y"]);
         params.append(event_data["z"]);
-        LLCommandDispatcher::dispatch("teleport", params, LLSD(), NULL, "clicked", true);
+        LLCommandDispatcher::dispatch("teleport", params, LLSD(), LLGridManager::getInstance()->getGrid(), NULL, "clicked", true);
         // *TODO - lookup other LLCommandHandlers for "agent", "classified", "event", "group", "floater", "parcel", "login", login_refresh", "balance", "chat"
         // should we just compose LLCommandHandler and LLDispatchListener?
     }
diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 07d6efd2fae..d0fad07f1c5 100644
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -147,7 +147,10 @@ class LLAppearanceHandler : public LLCommandHandler
 	// requests will be throttled from a non-trusted browser
 	LLAppearanceHandler() : LLCommandHandler("appearance", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		// support secondlife:///app/appearance/show, but for now we just
 		// make all secondlife:///app/appearance SLapps behave this way
@@ -4472,8 +4475,10 @@ class LLWearFolderHandler : public LLCommandHandler
 	// not allowed from outside the app
 	LLWearFolderHandler() : LLCommandHandler("wear_folder", UNTRUSTED_BLOCK) { }
 
-	bool handle(const LLSD& tokens, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& tokens,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		LLSD::UUID folder_uuid;
 
diff --git a/indra/newview/llbuycurrencyhtml.cpp b/indra/newview/llbuycurrencyhtml.cpp
index 7ad06f8eaa4..37de89a48b7 100644
--- a/indra/newview/llbuycurrencyhtml.cpp
+++ b/indra/newview/llbuycurrencyhtml.cpp
@@ -43,7 +43,7 @@ class LLBuyCurrencyHTMLHandler :
 	// requests will be throttled from a non-trusted browser
 	LLBuyCurrencyHTMLHandler() : LLCommandHandler( "buycurrencyhtml", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		std::string action( "" );
 		if ( params.size() >= 1 )
diff --git a/indra/newview/llchathistory.cpp b/indra/newview/llchathistory.cpp
index 9a608fba8e4..43dc10ef5f4 100644
--- a/indra/newview/llchathistory.cpp
+++ b/indra/newview/llchathistory.cpp
@@ -82,7 +82,7 @@ class LLObjectIMHandler : public LLCommandHandler
 	// requests will be throttled from a non-trusted browser
 	LLObjectIMHandler() : LLCommandHandler("objectim", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (params.size() < 1)
 		{
diff --git a/indra/newview/llchatitemscontainerctrl.cpp b/indra/newview/llchatitemscontainerctrl.cpp
index 1c22e055bb8..dc2cc57f0fc 100644
--- a/indra/newview/llchatitemscontainerctrl.cpp
+++ b/indra/newview/llchatitemscontainerctrl.cpp
@@ -57,7 +57,7 @@ class LLObjectHandler : public LLCommandHandler
 public:
 	LLObjectHandler() : LLCommandHandler("object", UNTRUSTED_BLOCK) { }
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (params.size() < 2) return false;
 
diff --git a/indra/newview/llcommanddispatcherlistener.cpp b/indra/newview/llcommanddispatcherlistener.cpp
index 586f45fd8f4..1b85c09071a 100644
--- a/indra/newview/llcommanddispatcherlistener.cpp
+++ b/indra/newview/llcommanddispatcherlistener.cpp
@@ -64,7 +64,7 @@ void LLCommandDispatcherListener::dispatch(const LLSD& params) const
         // But for testing, allow a caller to specify untrusted.
         trusted_browser = params["trusted"].asBoolean();
     }
-    LLCommandDispatcher::dispatch(params["cmd"], params["params"], params["query"], NULL,
+    LLCommandDispatcher::dispatch(params["cmd"], params["params"], params["query"], "", NULL,
                                   "clicked", trusted_browser);
 }
 
diff --git a/indra/newview/llcommandhandler.cpp b/indra/newview/llcommandhandler.cpp
index 74f37961c74..e774a9390a6 100644
--- a/indra/newview/llcommandhandler.cpp
+++ b/indra/newview/llcommandhandler.cpp
@@ -60,6 +60,7 @@ class LLCommandHandlerRegistry
 	bool dispatch(const std::string& cmd,
 				  const LLSD& params,
 				  const LLSD& query_map,
+                  const std::string& grid,
 				  LLMediaCtrl* web,
 				  const std::string& nav_type,
 				  bool trusted_browser);
@@ -96,6 +97,7 @@ void LLCommandHandlerRegistry::add(const char* cmd,
 bool LLCommandHandlerRegistry::dispatch(const std::string& cmd,
 										const LLSD& params,
 										const LLSD& query_map,
+										const std::string& grid,
 										LLMediaCtrl* web,
 										const std::string& nav_type,
 										bool trusted_browser)
@@ -163,7 +165,7 @@ bool LLCommandHandlerRegistry::dispatch(const std::string& cmd,
 		}
 	}
 	if (!info.mHandler) return false;
-	return info.mHandler->handle(params, query_map, web);
+	return info.mHandler->handle(params, query_map, grid, web);
 }
 
 void LLCommandHandlerRegistry::notifySlurlBlocked()
@@ -218,12 +220,13 @@ LLCommandHandler::~LLCommandHandler()
 bool LLCommandDispatcher::dispatch(const std::string& cmd,
 								   const LLSD& params,
 								   const LLSD& query_map,
+								   const std::string& grid,
 								   LLMediaCtrl* web,
 								   const std::string& nav_type,
 								   bool trusted_browser)
 {
 	return LLCommandHandlerRegistry::instance().dispatch(
-		cmd, params, query_map, web, nav_type, trusted_browser);
+		cmd, params, query_map, grid, web, nav_type, trusted_browser);
 }
 
 static std::string lookup(LLCommandHandler::EUntrustedAccess value);
diff --git a/indra/newview/llcommandhandler.h b/indra/newview/llcommandhandler.h
index 763e3ee51f3..c7a7a18c7de 100644
--- a/indra/newview/llcommandhandler.h
+++ b/indra/newview/llcommandhandler.h
@@ -42,7 +42,7 @@ class LLFooHandler : public LLCommandHandler
 	LLFooHandler() : LLCommandHandler("foo", UNTRUSTED_BLOCK) { }
 
     // Your code here
-	bool handle(const LLSD& tokens, const LLSD& query_map,
+	bool handle(const LLSD& tokens, const LLSD& query_map, const std::string& grid,
 				LLMediaCtrl* web)
 	{
 		if (tokens.size() < 1) return false;
@@ -88,6 +88,7 @@ class LLCommandHandler
 
 	virtual bool handle(const LLSD& params,
 						const LLSD& query_map,
+						const std::string& grid,
 						LLMediaCtrl* web) = 0;
 		// For URL secondlife:///app/foo/bar/baz?cat=1&dog=2
 		// @params - array of "bar", "baz", possibly empty
@@ -104,6 +105,7 @@ class LLCommandDispatcher
 	static bool dispatch(const std::string& cmd,
 						 const LLSD& params,
 						 const LLSD& query_map,
+						 const std::string& grid,
 						 LLMediaCtrl* web,
 						 const std::string& nav_type,
 						 bool trusted_browser);
diff --git a/indra/newview/lleventnotifier.cpp b/indra/newview/lleventnotifier.cpp
index f1a44a68c90..788b61b3812 100644
--- a/indra/newview/lleventnotifier.cpp
+++ b/indra/newview/lleventnotifier.cpp
@@ -43,8 +43,10 @@ class LLEventHandler : public LLCommandHandler
 public:
 	// requires trusted browser to trigger
 	LLEventHandler() : LLCommandHandler("event", UNTRUSTED_THROTTLE) { }
-	bool handle(const LLSD& params, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (params.size() < 2)
 		{
diff --git a/indra/newview/llfloaterexperienceprofile.cpp b/indra/newview/llfloaterexperienceprofile.cpp
index a99a096ea7b..f6afdd29fba 100644
--- a/indra/newview/llfloaterexperienceprofile.cpp
+++ b/indra/newview/llfloaterexperienceprofile.cpp
@@ -92,8 +92,10 @@ class LLExperienceHandler : public LLCommandHandler
 public:
     LLExperienceHandler() : LLCommandHandler("experience", UNTRUSTED_THROTTLE) { }
 
-    bool handle(const LLSD& params, const LLSD& query_map,
-        LLMediaCtrl* web)
+    bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
     {
         if(params.size() != 2 || params[1].asString() != "profile")
             return false;
diff --git a/indra/newview/llfloaterhandler.cpp b/indra/newview/llfloaterhandler.cpp
index 8ebb14149c9..b66049de7f1 100644
--- a/indra/newview/llfloaterhandler.cpp
+++ b/indra/newview/llfloaterhandler.cpp
@@ -49,7 +49,7 @@ LLFloater* get_parent_floater(LLView* view)
 }
 
 
-bool LLFloaterHandler::handle(const LLSD &params, const LLSD &query_map, LLMediaCtrl *web)
+bool LLFloaterHandler::handle(const LLSD &params, const LLSD &query_map, const std::string& grid, LLMediaCtrl *web)
 {
 	if (params.size() < 1) return false;
 	LLFloater* floater = NULL;
diff --git a/indra/newview/llfloaterhandler.h b/indra/newview/llfloaterhandler.h
index 5915642d667..959c9722752 100644
--- a/indra/newview/llfloaterhandler.h
+++ b/indra/newview/llfloaterhandler.h
@@ -33,7 +33,7 @@ class LLFloaterHandler
 {
 public:
 	LLFloaterHandler() : LLCommandHandler("floater", UNTRUSTED_BLOCK) { }
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web);
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web);
 };
 
 #endif
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index f1807f1c5be..f63268660c2 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -901,8 +901,10 @@ class LLChatCommandHandler : public LLCommandHandler
 	LLChatCommandHandler() : LLCommandHandler("chat", UNTRUSTED_BLOCK) { }
 
     // Your code here
-	bool handle(const LLSD& tokens, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& tokens,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		bool retval = false;
 		// Need at least 2 tokens to have a valid message.
diff --git a/indra/newview/llfloatersearch.cpp b/indra/newview/llfloatersearch.cpp
index 7e6af45515e..37ae80fa8fc 100644
--- a/indra/newview/llfloatersearch.cpp
+++ b/indra/newview/llfloatersearch.cpp
@@ -46,7 +46,7 @@ class LLSearchHandler : public LLCommandHandler
 public:
 	// requires trusted browser to trigger
 	LLSearchHandler() : LLCommandHandler("search", UNTRUSTED_CLICK_ONLY) { }
-	bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableSearch"))
 		{
diff --git a/indra/newview/llfloaterworldmap.cpp b/indra/newview/llfloaterworldmap.cpp
index 704abd269fa..8f3ec8af053 100755
--- a/indra/newview/llfloaterworldmap.cpp
+++ b/indra/newview/llfloaterworldmap.cpp
@@ -124,8 +124,10 @@ class LLWorldMapHandler : public LLCommandHandler
 	// requires trusted browser to trigger
 	LLWorldMapHandler() : LLCommandHandler("worldmap", UNTRUSTED_CLICK_ONLY ) { }
 	
-	bool handle(const LLSD& params, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableWorldMap"))
 		{
@@ -163,7 +165,10 @@ class LLMapTrackAvatarHandler : public LLCommandHandler
 	{ 
 	}
 	
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableWorldMap"))
 		{
diff --git a/indra/newview/llgroupactions.cpp b/indra/newview/llgroupactions.cpp
index be52e280e19..85b8ff0570d 100644
--- a/indra/newview/llgroupactions.cpp
+++ b/indra/newview/llgroupactions.cpp
@@ -78,8 +78,10 @@ class LLGroupHandler : public LLCommandHandler
         return true;
     }
 
-	bool handle(const LLSD& tokens, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& tokens,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (LLStartUp::getStartupState() < STATE_STARTED)
 		{
diff --git a/indra/newview/llloginhandler.cpp b/indra/newview/llloginhandler.cpp
index 22cedf450eb..92e341ce939 100644
--- a/indra/newview/llloginhandler.cpp
+++ b/indra/newview/llloginhandler.cpp
@@ -87,6 +87,7 @@ void LLLoginHandler::parse(const LLSD& queryMap)
 
 bool LLLoginHandler::handle(const LLSD& tokens,
 							const LLSD& query_map,
+							const std::string& grid,
 							LLMediaCtrl* web)
 {
 	// do nothing if we are already logged in
diff --git a/indra/newview/llloginhandler.h b/indra/newview/llloginhandler.h
index 1f2eacd094e..2579341dbf9 100644
--- a/indra/newview/llloginhandler.h
+++ b/indra/newview/llloginhandler.h
@@ -35,7 +35,7 @@ class LLLoginHandler : public LLCommandHandler
  public:
 	// allow from external browsers
 	LLLoginHandler() : LLCommandHandler("login", UNTRUSTED_ALLOW) { }
-	/*virtual*/ bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web);
+	/*virtual*/ bool handle(const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web);
 
 	// Fill in our internal fields from a SLURL like
 	// secondlife:///app/login?first=Bob&last=Dobbs
diff --git a/indra/newview/llpaneleditwearable.cpp b/indra/newview/llpaneleditwearable.cpp
index 0103bf628a9..1b4684d0735 100644
--- a/indra/newview/llpaneleditwearable.cpp
+++ b/indra/newview/llpaneleditwearable.cpp
@@ -1665,7 +1665,7 @@ class LLMetricSystemHandler : public LLCommandHandler
 public:
         LLMetricSystemHandler() : LLCommandHandler("metricsystem", UNTRUSTED_CLICK_ONLY) { }
 
-        bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+        bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
         {
                 // change height units TRUE for meters and FALSE for feet
                 BOOL new_value = (gSavedSettings.getBOOL("HeightUnits") == FALSE) ? TRUE : FALSE;
diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp
index b14fdbf38e8..8f1e57e44ce 100644
--- a/indra/newview/llpanellogin.cpp
+++ b/indra/newview/llpanellogin.cpp
@@ -97,7 +97,7 @@ class LLLoginLocationAutoHandler : public LLCommandHandler
 public:
 	// don't allow from external browsers
 	LLLoginLocationAutoHandler() : LLCommandHandler("location_login", UNTRUSTED_BLOCK) { }
-	bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{	
 		if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)
 		{
diff --git a/indra/newview/llpanelplaces.cpp b/indra/newview/llpanelplaces.cpp
index 0f00231643c..1d5ed93c4d8 100644
--- a/indra/newview/llpanelplaces.cpp
+++ b/indra/newview/llpanelplaces.cpp
@@ -91,8 +91,10 @@ class LLParcelHandler : public LLCommandHandler
 public:
 	// requires trusted browser to trigger
 	LLParcelHandler() : LLCommandHandler("parcel", UNTRUSTED_THROTTLE) { }
-	bool handle(const LLSD& params, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{		
 		if (params.size() < 2)
 		{
diff --git a/indra/newview/llpanelprofile.cpp b/indra/newview/llpanelprofile.cpp
index 708ff26ced8..79b7ed82166 100644
--- a/indra/newview/llpanelprofile.cpp
+++ b/indra/newview/llpanelprofile.cpp
@@ -460,8 +460,10 @@ class LLProfileHandler : public LLCommandHandler
 	// requires trusted browser to trigger
 	LLProfileHandler() : LLCommandHandler("profile", UNTRUSTED_THROTTLE) { }
 
-	bool handle(const LLSD& params, const LLSD& query_map,
-		LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (params.size() < 1) return false;
 		std::string agent_name = params[0];
@@ -508,8 +510,10 @@ class LLAgentHandler : public LLCommandHandler
         return false;
     }
 
-	bool handle(const LLSD& params, const LLSD& query_map,
-		LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (params.size() < 2) return false;
 		LLUUID avatar_id;
diff --git a/indra/newview/llpanelprofileclassifieds.cpp b/indra/newview/llpanelprofileclassifieds.cpp
index 1ff12b4f378..dec6cfd83b9 100644
--- a/indra/newview/llpanelprofileclassifieds.cpp
+++ b/indra/newview/llpanelprofileclassifieds.cpp
@@ -106,7 +106,7 @@ class LLClassifiedHandler : public LLCommandHandler, public LLAvatarPropertiesOb
         return true;
     }
     
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
     {
         if (LLStartUp::getStartupState() < STATE_STARTED)
         {
diff --git a/indra/newview/llpanelprofilepicks.cpp b/indra/newview/llpanelprofilepicks.cpp
index 45d0252e4fe..274d42f7eb3 100644
--- a/indra/newview/llpanelprofilepicks.cpp
+++ b/indra/newview/llpanelprofilepicks.cpp
@@ -87,8 +87,10 @@ class LLPickHandler : public LLCommandHandler
         return true;
     }
 
-    bool handle(const LLSD& params, const LLSD& query_map,
-        LLMediaCtrl* web)
+    bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
     {
         if (LLStartUp::getStartupState() < STATE_STARTED)
         {
diff --git a/indra/newview/llshareavatarhandler.cpp b/indra/newview/llshareavatarhandler.cpp
index 142e00c3f7e..8c5ebb75efa 100644
--- a/indra/newview/llshareavatarhandler.cpp
+++ b/indra/newview/llshareavatarhandler.cpp
@@ -38,7 +38,7 @@ class LLShareWithAvatarHandler : public LLCommandHandler
 	{ 
 	}
 	
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableAvatarShare"))
 		{
diff --git a/indra/newview/llstatusbar.cpp b/indra/newview/llstatusbar.cpp
index 0a87b14e17f..1ef5d1c50b9 100644
--- a/indra/newview/llstatusbar.cpp
+++ b/indra/newview/llstatusbar.cpp
@@ -729,7 +729,7 @@ class LLBalanceHandler : public LLCommandHandler
 public:
 	// Requires "trusted" browser/URL source
 	LLBalanceHandler() : LLCommandHandler("balance", UNTRUSTED_BLOCK) { }
-	bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (tokens.size() == 1
 			&& tokens[0].asString() == "request")
diff --git a/indra/newview/llurldispatcher.cpp b/indra/newview/llurldispatcher.cpp
index 7c92e7ef98a..6fc870f8901 100644
--- a/indra/newview/llurldispatcher.cpp
+++ b/indra/newview/llurldispatcher.cpp
@@ -97,6 +97,8 @@ class LLURLDispatcherImpl
 		// Called by LLWorldMap when a region name has been resolved to a
 		// location in-world, used by places-panel display.
 
+    static bool handleGrid(const LLSLURL& slurl);
+
 	friend class LLTeleportHandler;
 };
 
@@ -155,7 +157,7 @@ bool LLURLDispatcherImpl::dispatchApp(const LLSLURL& slurl,
 	LL_INFOS() << "cmd: " << slurl.getAppCmd() << " path: " << slurl.getAppPath() << " query: " << slurl.getAppQuery() << LL_ENDL;
 	const LLSD& query_map = LLURI::queryMap(slurl.getAppQuery());
 	bool handled = LLCommandDispatcher::dispatch(
-			slurl.getAppCmd(), slurl.getAppPath(), query_map, web, nav_type, trusted_browser);
+			slurl.getAppCmd(), slurl.getAppPath(), query_map, slurl.getGrid(), web, nav_type, trusted_browser);
 
 	// alert if we didn't handle this secondlife:///app/ SLURL
 	// (but still return true because it is a valid app SLURL)
@@ -184,6 +186,11 @@ bool LLURLDispatcherImpl::dispatchRegion(const LLSLURL& slurl, const std::string
 		return true;
 	}
 
+    if (!handleGrid(slurl))
+    {
+        return true;
+    }
+
 	// Request a region handle by name
 	LLWorldMapMessage::getInstance()->sendNamedRegionRequest(slurl.getRegion(),
 									  LLURLDispatcherImpl::regionNameCallback,
@@ -202,31 +209,39 @@ void LLURLDispatcherImpl::regionNameCallback(U64 region_handle, const LLSLURL& s
     }
 }
 
+bool LLURLDispatcherImpl::handleGrid(const LLSLURL& slurl)
+{
+    if (LLGridManager::getInstance()->getGrid(slurl.getGrid())
+        != LLGridManager::getInstance()->getGrid())
+    {
+        LLSD args;
+        args["SLURL"] = slurl.getLocationString();
+        args["CURRENT_GRID"] = LLGridManager::getInstance()->getGridLabel();
+        std::string grid_label =
+            LLGridManager::getInstance()->getGridLabel(slurl.getGrid());
+
+        if (!grid_label.empty())
+        {
+            args["GRID"] = grid_label;
+        }
+        else
+        {
+            args["GRID"] = slurl.getGrid();
+        }
+        LLNotificationsUtil::add("CantTeleportToGrid", args);
+        return false;
+    }
+    return true;
+}
+
 /* static */
 void LLURLDispatcherImpl::regionHandleCallback(U64 region_handle, const LLSLURL& slurl, const LLUUID& snapshot_id, bool teleport)
 {
-
-  // we can't teleport cross grid at this point
-	if(   LLGridManager::getInstance()->getGrid(slurl.getGrid())
-	   != LLGridManager::getInstance()->getGrid())
-	{
-		LLSD args;
-		args["SLURL"] = slurl.getLocationString();
-		args["CURRENT_GRID"] = LLGridManager::getInstance()->getGridLabel();
-		std::string grid_label = 
-			LLGridManager::getInstance()->getGridLabel(slurl.getGrid());
-		
-		if(!grid_label.empty())
-		{
-			args["GRID"] = grid_label;
-		}
-		else 
-		{
-			args["GRID"] = slurl.getGrid();
-		}
-		LLNotificationsUtil::add("CantTeleportToGrid", args);
-		return;
-	}
+    if (!handleGrid(slurl))
+    {
+        // we can't teleport cross grid at this point
+        return;
+    }
 	
 	LLVector3d global_pos = from_region_handle(region_handle);
 	global_pos += LLVector3d(slurl.getPosition());
@@ -274,8 +289,10 @@ class LLTeleportHandler : public LLCommandHandler, public LLEventAPI
 						&LLTeleportHandler::from_event);
 	}
 
-	bool handle(const LLSD& tokens, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& tokens,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		// construct a "normal" SLURL, resolve the region to
 		// a global position, and teleport to it
@@ -297,7 +314,7 @@ class LLTeleportHandler : public LLCommandHandler, public LLEventAPI
 
 		LLSD payload;
 		payload["region_name"] = region_name;
-		payload["callback_url"] = LLSLURL(region_name, coords).getSLURLString();
+		payload["callback_url"] = LLSLURL(grid, region_name, coords).getSLURLString();
 
 		LLNotificationsUtil::add("TeleportViaSLAPP", args, payload);
 		return true;
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index c0398372b43..23b79993998 100644
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -270,6 +270,7 @@ class LLFloaterOpenHandler : public LLCommandHandler
 	bool handle(
         const LLSD& params,
         const LLSD& query_map,
+        const std::string& grid,
         LLMediaCtrl* web) override
 	{
 		if (params.size() != 1)
diff --git a/indra/newview/llviewerhelp.cpp b/indra/newview/llviewerhelp.cpp
index 04c2e27c9d0..b03942db9f8 100644
--- a/indra/newview/llviewerhelp.cpp
+++ b/indra/newview/llviewerhelp.cpp
@@ -45,7 +45,7 @@ class LLHelpHandler : public LLCommandHandler
 	// requests will be throttled from a non-trusted browser
 	LLHelpHandler() : LLCommandHandler("help", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		LLViewerHelp* vhelp = LLViewerHelp::getInstance();
 		if (! vhelp)
diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp
index 50252556deb..793eb567349 100644
--- a/indra/newview/llviewerinventory.cpp
+++ b/indra/newview/llviewerinventory.cpp
@@ -234,8 +234,10 @@ class LLInventoryHandler : public LLCommandHandler
 	// requires trusted browser to trigger
 	LLInventoryHandler() : LLCommandHandler("inventory", UNTRUSTED_CLICK_ONLY) { }
 	
-	bool handle(const LLSD& params, const LLSD& query_map,
-				LLMediaCtrl* web)
+	bool handle(const LLSD& params,
+                const LLSD& query_map,
+                const std::string& grid,
+                LLMediaCtrl* web)
 	{
 		if (params.size() < 1)
 		{
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index ad7321ca4be..e122baadce2 100755
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -131,8 +131,8 @@ class LLRegionHandler : public LLCommandHandler
 public:
     // requests will be throttled from a non-trusted browser
     LLRegionHandler() : LLCommandHandler("region", UNTRUSTED_THROTTLE) {}
-       
-    bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+
+    bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
     {
         // make sure that we at least have a region name
         int num_params = params.size();
@@ -143,6 +143,10 @@ class LLRegionHandler : public LLCommandHandler
            
         // build a secondlife://{PLACE} SLurl from this SLapp
         std::string url = "secondlife://";
+        if (!grid.empty())
+        {
+            url += grid + "/secondlife/";
+        }
 		boost::regex name_rx("[A-Za-z0-9()_%]+");
 		boost::regex coord_rx("[0-9]+");
         for (int i = 0; i < num_params; i++)
diff --git a/indra/newview/llvoicecallhandler.cpp b/indra/newview/llvoicecallhandler.cpp
index 1e993d13843..95e11abd829 100644
--- a/indra/newview/llvoicecallhandler.cpp
+++ b/indra/newview/llvoicecallhandler.cpp
@@ -38,7 +38,7 @@ class LLVoiceCallAvatarHandler : public LLCommandHandler
 	{ 
 	}
 	
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableVoiceCall"))
 		{
diff --git a/indra/newview/llvoiceclient.cpp b/indra/newview/llvoiceclient.cpp
index 6bb987ede4e..bf96f0bbb4f 100644
--- a/indra/newview/llvoiceclient.cpp
+++ b/indra/newview/llvoiceclient.cpp
@@ -53,7 +53,7 @@ class LLVoiceHandler : public LLCommandHandler
 	// requests will be throttled from a non-trusted browser
 	LLVoiceHandler() : LLCommandHandler("voice", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
+	bool handle(const LLSD& params, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
 	{
 		if (params[0].asString() == "effects")
 		{
diff --git a/indra/newview/llworldmapview.cpp b/indra/newview/llworldmapview.cpp
index 6e994b4e68a..b59bbaaa88d 100755
--- a/indra/newview/llworldmapview.cpp
+++ b/indra/newview/llworldmapview.cpp
@@ -50,6 +50,7 @@
 #include "lltextureview.h"
 #include "lltracker.h"
 #include "llviewercamera.h"
+#include "llviewernetwork.h"
 #include "llviewertexture.h"
 #include "llviewertexturelist.h"
 #include "llviewerregion.h"
@@ -1829,7 +1830,7 @@ BOOL LLWorldMapView::handleDoubleClick( S32 x, S32 y, MASK mask )
 				// Invoke the event details floater if someone is clicking on an event.
 				LLSD params(LLSD::emptyArray());
 				params.append(event_id);
-				LLCommandDispatcher::dispatch("event", params, LLSD(), NULL, "clicked", true);
+				LLCommandDispatcher::dispatch("event", params, LLSD(), LLGridManager::getInstance()->getGrid(), NULL, "clicked", true);
 				break;
 			}
 		case MAP_ITEM_LAND_FOR_SALE:
-- 
GitLab