From abf9ccb0dee2e707c94f1f14f8869f2a991fea94 Mon Sep 17 00:00:00 2001
From: Rider Linden <rider@lindenlab.com>
Date: Fri, 23 Oct 2015 10:23:01 -0700
Subject: [PATCH] MAINT-5791: Change the way the TOS dialog is retrieved after
 the site-alive test coro.  Use handles rather than findTypedInstance.

---
 indra/newview/llfloatertos.cpp | 18 +++++++++++++-----
 indra/newview/llfloatertos.h   |  2 +-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/indra/newview/llfloatertos.cpp b/indra/newview/llfloatertos.cpp
index 3597d70e0d7..5fa44419140 100755
--- a/indra/newview/llfloatertos.cpp
+++ b/indra/newview/llfloatertos.cpp
@@ -196,8 +196,10 @@ void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent ev
 			mLoadingScreenLoaded = true;
             std::string url(getString("real_url"));
 
+            LLHandle<LLFloater> handle = getHandle();
+
             LLCoros::instance().launch("LLFloaterTOS::testSiteIsAliveCoro",
-                boost::bind(&LLFloaterTOS::testSiteIsAliveCoro, url));
+                boost::bind(&LLFloaterTOS::testSiteIsAliveCoro, handle, url));
 		}
 		else if(mRealNavigateBegun)
 		{
@@ -209,7 +211,7 @@ void LLFloaterTOS::handleMediaEvent(LLPluginClassMedia* /*self*/, EMediaEvent ev
 	}
 }
 
-void LLFloaterTOS::testSiteIsAliveCoro(std::string url)
+void LLFloaterTOS::testSiteIsAliveCoro(LLHandle<LLFloater> handle, std::string url)
 {
     LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
     LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
@@ -228,13 +230,19 @@ void LLFloaterTOS::testSiteIsAliveCoro(std::string url)
     LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
     LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
 
-    LLFloaterTOS *that = LLFloaterReg::findTypedInstance<LLFloaterTOS>("message_tos");
-    // double not.  
+    if (handle.isDead())
+    {
+        LL_WARNS("testSiteIsAliveCoro") << "Dialog canceled before response." << LL_ENDL;
+        return;
+    }
+
+    LLFloaterTOS *that = dynamic_cast<LLFloaterTOS *>(handle.get());
+    
     if (that)
         that->setSiteIsAlive(static_cast<bool>(status)); 
     else
     {
-        LL_WARNS("testSiteIsAliveCoro") << "Dialog canceled before response." << LL_ENDL;
+        LL_WARNS("testSiteIsAliveCoro") << "Handle was not a TOS floater." << LL_ENDL;
     }
 }
 
diff --git a/indra/newview/llfloatertos.h b/indra/newview/llfloatertos.h
index b71b80ed24f..e70c9f24afc 100755
--- a/indra/newview/llfloatertos.h
+++ b/indra/newview/llfloatertos.h
@@ -62,7 +62,7 @@ class LLFloaterTOS :
 	/*virtual*/ void handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event);
 
 private:
-    static void testSiteIsAliveCoro(std::string url);
+    static void testSiteIsAliveCoro(LLHandle<LLFloater> handle, std::string url);
 
 	std::string		mMessage;
 	bool			mLoadingScreenLoaded;
-- 
GitLab