From 1c591c06b72d222cff7775ef3aa067cba9c52cd3 Mon Sep 17 00:00:00 2001
From: Lynx Linden <lynx@lindenlab.com>
Date: Fri, 6 Nov 2009 12:08:15 +0000
Subject: [PATCH] EXT-2232: Arghhh! Code Duplication == Bugs.

Apparently, pre-login notifications use LLAlertDialog, but post-login
notifications use LLToastAlertPanel. The latter is basically a copy
and paste of the former, with some local modifications. However, the
person who copy/pasted the code did not initialize the URLLoader
callback, so all notifications that tried to open a web page on a
button click after login were failing.

I've added comments that this code should be refactored, preferably as
a subclass of LLAlertDialog. In the meantime, I've tried to clean it
up a bit by not duplicating the nested URLLoader class (which would've
required further duplication to reimplement the exact same loader class
that LLAlertDialog uses). This let me then initialize the URLLoader
callback for LLToastAlertPanel, to fix this specific bug.

Again... arghhh!!
---
 indra/newview/lltoastalertpanel.cpp |  5 ++++-
 indra/newview/lltoastalertpanel.h   | 16 +++++++---------
 indra/newview/llweb.cpp             |  4 +++-
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/indra/newview/lltoastalertpanel.cpp b/indra/newview/lltoastalertpanel.cpp
index e4a3f8603b8..beb31bc8334 100644
--- a/indra/newview/lltoastalertpanel.cpp
+++ b/indra/newview/lltoastalertpanel.cpp
@@ -30,6 +30,9 @@
  * $/LicenseInfo$
  */
 
+// *NOTE: this module is a copy-paste of llui/llalertdialog.h
+// Can we re-implement this as a subclass of LLAlertDialog and
+// avoid all this code duplication? It already caused EXT-2232.
 
 #include "llviewerprecompiledheaders.h" // must be first include
 
@@ -56,7 +59,7 @@ const F32 DEFAULT_BUTTON_DELAY = 0.5f;
 const S32 MSG_PAD = 8;
 
 /*static*/ LLControlGroup* LLToastAlertPanel::sSettings = NULL;
-/*static*/ LLToastAlertPanel::URLLoader* LLToastAlertPanel::sURLLoader;
+/*static*/ LLAlertURLLoader* LLToastAlertPanel::sURLLoader;
 
 //-----------------------------------------------------------------------------
 // Private methods
diff --git a/indra/newview/lltoastalertpanel.h b/indra/newview/lltoastalertpanel.h
index af0c9a9ddd9..840143a2a93 100644
--- a/indra/newview/lltoastalertpanel.h
+++ b/indra/newview/lltoastalertpanel.h
@@ -30,6 +30,10 @@
  * $/LicenseInfo$
  */
 
+// *NOTE: this module is a copy-paste of llui/llalertdialog.h
+// Can we re-implement this as a subclass of LLAlertDialog and
+// avoid all this code duplication? It already caused EXT-2232.
+
 #ifndef LL_TOASTALERTPANEL_H
 #define LL_TOASTALERTPANEL_H
 
@@ -37,6 +41,7 @@
 #include "llfloater.h"
 #include "llui.h"
 #include "llnotifications.h"
+#include "llalertdialog.h"
 
 class LLButton;
 class LLCheckBoxCtrl;
@@ -57,14 +62,7 @@ class LLToastAlertPanel
 public:
 	typedef bool (*display_callback_t)(S32 modal);
 
-	class URLLoader
-	{
-	public:
-		virtual void load(const std::string& url,  bool force_open_externally = 0 ) = 0;
-		virtual ~URLLoader() {}
-	};
-	
-	static void setURLLoader(URLLoader* loader)
+	static void setURLLoader(LLAlertURLLoader* loader)
 	{
 		sURLLoader = loader;
 	}
@@ -97,7 +95,7 @@ class LLToastAlertPanel
 	BOOL hasTitleBar() const;
 
 private:
-	static URLLoader* sURLLoader;
+	static LLAlertURLLoader* sURLLoader;
 	static LLControlGroup* sSettings;
 
 	struct ButtonData
diff --git a/indra/newview/llweb.cpp b/indra/newview/llweb.cpp
index 3204c2d2642..72431bd22f2 100644
--- a/indra/newview/llweb.cpp
+++ b/indra/newview/llweb.cpp
@@ -43,8 +43,9 @@
 #include "llfloatermediabrowser.h"
 #include "llfloaterreg.h"
 #include "llalertdialog.h"
+#include "lltoastalertpanel.h"
 
-class URLLoader : public LLAlertDialog::URLLoader
+class URLLoader : public LLAlertURLLoader
 {
 	virtual void load(const std::string& url , bool force_open_externally)
 	{
@@ -65,6 +66,7 @@ static URLLoader sAlertURLLoader;
 void LLWeb::initClass()
 {
 	LLAlertDialog::setURLLoader(&sAlertURLLoader);
+	LLToastAlertPanel::setURLLoader(&sAlertURLLoader);
 }
 
 
-- 
GitLab