From 2493c401f95ac8144d94b660431a2089e4dbd58c Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Sat, 9 Feb 2019 16:50:38 -0500 Subject: [PATCH] Force replacing registered urls everywhere that's not from another user I think I covered all my bases: Local Chat, IMs/Group/Conference Chats Script Dialogs Group Notices There are a few others maybe, like notifications EMs can spawn but if those are intentionally tricking people, grid owners should be informed. --- indra/llui/lltexteditor.cpp | 18 ++++++++---------- indra/llui/lltexteditor.h | 4 ++-- indra/newview/llfloaterchat.cpp | 4 ++-- indra/newview/llgroupnotify.cpp | 7 ++++--- indra/newview/llimpanel.cpp | 4 ++-- indra/newview/llnotify.cpp | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 5aae494be..8696951cd 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -4262,7 +4262,7 @@ void LLTextEditor::appendColoredText(const std::string &new_text, static LLTrace::BlockTimerStatHandle FTM_APPEND_TEXT("Append Text"); void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool prepend_newline, - const LLStyleSP style) + const LLStyleSP style, bool force_replace_links) { LL_RECORD_BLOCK_TIME(FTM_APPEND_TEXT); if (new_text.empty()) @@ -4280,10 +4280,11 @@ void LLTextEditor::appendText(const std::string &new_text, bool allow_undo, bool static LLTrace::BlockTimerStatHandle FTM_PARSE_HTML("Parse HTML"); // Appends new text to end of document -void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP style) +void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP style, bool force_replace_links) { std::string text = new_text; - static LLUICachedControl replace_links("SinguReplaceLinks"); + static const LLUICachedControl replace_links("SinguReplaceLinks"); + force_replace_links = force_replace_links || replace_links; bool is_link = style && style->isLink(); // Don't search for URLs inside a link segment (STORM-358). S32 part = (S32)LLTextParser::WHOLE; @@ -4309,8 +4310,8 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s if (mLinkColor) link_style->setColor(*mLinkColor); appendAndHighlightText(link, part, link_style, true/*match.underlineOnHoverOnly()*/); }; - while (!text.empty() && LLUrlRegistry::instance().findUrl(text, match, - boost::bind(&LLTextEditor::replaceUrl, this, _1, _2, _3))) + const auto&& cb = force_replace_links ? boost::bind(&LLTextEditor::replaceUrl, this, _1, _2, _3) : LLUrlLabelCallback::slot_function_type(); + while (!text.empty() && LLUrlRegistry::instance().findUrl(text, match, cb)) { start = match.getStart(); end = match.getEnd()+1; @@ -4332,7 +4333,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s auto url = match.getUrl(); const auto& label = match.getLabel(); - if (replace_links || url == label) + if (force_replace_links || replace_links || url == label) { // add icon before url if need /* Singu TODO: Icons next to links? @@ -4371,7 +4372,7 @@ void LLTextEditor::appendTextImpl(const std::string &new_text, const LLStyleSP s } }*/ } - else if (!replace_links) // Still link the link itself + else // Still link the link itself { const auto pos = text.find(url); bool fallback(pos == std::string::npos); // In special cases like no protocol and brackets @@ -4454,9 +4455,6 @@ void LLTextEditor::replaceUrl(const std::string &url, const std::string &label, const std::string &icon) { - static LLUICachedControl replace_links("SinguReplaceLinks"); - if (!replace_links) return; - // get the full (wide) text for the editor so we can change it LLWString text = getWText(); LLWString wlabel = utf8str_to_wstring(label); diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index 9f55412be..4eba4842b 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -181,8 +181,8 @@ public: void insertText(const std::string &text, BOOL deleteSelection = TRUE); // appends text at end void appendText(const std::string &wtext, bool allow_undo, bool prepend_newline, - const LLStyleSP stylep = NULL); - void appendTextImpl(const std::string& new_text, const LLStyleSP style); + const LLStyleSP stylep = NULL, bool force_replace_links = true); + void appendTextImpl(const std::string& new_text, const LLStyleSP style, bool force_replace_links = true); void setLastSegmentToolTip(const std::string& tooltip); diff --git a/indra/newview/llfloaterchat.cpp b/indra/newview/llfloaterchat.cpp index e544bed80..b0607210f 100644 --- a/indra/newview/llfloaterchat.cpp +++ b/indra/newview/llfloaterchat.cpp @@ -217,14 +217,14 @@ void add_timestamped_line(LLViewerTextEditor* edit, LLChat chat, const LLColor4& line = line.substr(chat.mFromName.length()); LLStyleSP sourceStyle = LLStyleMap::instance().lookup(chat.mFromID, chat.mURL); sourceStyle->mItalic = is_irc; - edit->appendText(chat.mFromName, false, prepend_newline, sourceStyle); + edit->appendText(chat.mFromName, false, prepend_newline, sourceStyle, false); prepend_newline = false; } LLStyleSP style(new LLStyle); style->setColor(color); style->mItalic = is_irc; style->mBold = chat.mChatType == CHAT_TYPE_SHOUT; - edit->appendText(line, false, prepend_newline, style); + edit->appendText(line, false, prepend_newline, style, false); } void log_chat_text(const LLChat& chat) diff --git a/indra/newview/llgroupnotify.cpp b/indra/newview/llgroupnotify.cpp index 982dfcad4..4d70787a7 100644 --- a/indra/newview/llgroupnotify.cpp +++ b/indra/newview/llgroupnotify.cpp @@ -175,11 +175,12 @@ LLGroupNotifyBox::LLGroupNotifyBox(const std::string& subject, static const LLStyleSP headerstyle(new LLStyle(true,LLColor4::black,"SansSerifBig")); static const LLStyleSP datestyle(new LLStyle(true,LLColor4::black,"serif")); + static const LLStyleSP msgstyle(new LLStyle(true, LLColor4::grey4, LLStringUtil::null)); - text->appendText(subject + '\n',false,false,headerstyle); + text->appendText(subject + '\n',false,false,headerstyle,false); - text->appendText(time_buf,false,false,datestyle); - text->appendColoredText(std::string(" \n\n") + message,false,false,LLColor4::grey4); + text->appendText(time_buf,false,false,datestyle,false); + text->appendText(std::string(" \n\n") + message,false,false,msgstyle,false); LLColor4 semi_transparent(1.0f,1.0f,1.0f,0.8f); text->setCursor(0,0); diff --git a/indra/newview/llimpanel.cpp b/indra/newview/llimpanel.cpp index 7a0b33ec7..2739d7c74 100644 --- a/indra/newview/llimpanel.cpp +++ b/indra/newview/llimpanel.cpp @@ -804,7 +804,7 @@ void LLFloaterIMPanel::addHistoryLine(const std::string &utf8msg, LLColor4 incol // Convert the name to a hotlink and add to message. LLStyleSP source_style = LLStyleMap::instance().lookupAgent(source); source_style->mItalic = is_irc; - mHistoryEditor->appendText(show_name,false,prepend_newline,source_style); + mHistoryEditor->appendText(show_name,false,prepend_newline,source_style, false); } prepend_newline = false; } @@ -815,7 +815,7 @@ void LLFloaterIMPanel::addHistoryLine(const std::string &utf8msg, LLColor4 incol style->setColor(incolor); style->mItalic = is_irc; style->mBold = from_user && gSavedSettings.getBOOL("SingularityBoldGroupModerator") && isModerator(source); - mHistoryEditor->appendText(utf8msg, false, prepend_newline, style); + mHistoryEditor->appendText(utf8msg, false, prepend_newline, style, false); } if (log_to_file diff --git a/indra/newview/llnotify.cpp b/indra/newview/llnotify.cpp index 93e8b1663..174af5c7c 100644 --- a/indra/newview/llnotify.cpp +++ b/indra/newview/llnotify.cpp @@ -249,7 +249,7 @@ LLNotifyBox::LLNotifyBox(LLNotificationPtr notification) if (!mIsCaution) // We could do some extra color math here to determine if bg's too close to link color, but let's just cross with the link color instead text->setLinkColor(new LLColor4(lerp(text_color, gSavedSettings.getColor4("HTMLLinkColor"), 0.4))); text->setTabStop(FALSE); // can't tab to it (may be a problem for scrolling via keyboard) - text->setText(message); // Now we can set the text, since colors have been set. + text->appendText(message,false,false,nullptr,!layout_script_dialog); // Now we can set the text, since colors have been set. addChild(text); }