Skip to content

Commit

Permalink
Triage Issue #49 Better inspection of data urls in media
Browse files Browse the repository at this point in the history
  • Loading branch information
akleshchev committed Feb 9, 2024
1 parent c8ee05a commit b895292
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 16 deletions.
16 changes: 16 additions & 0 deletions indra/llcommon/llbase64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ std::string LLBase64::encode(const U8* input, size_t input_size)
return output;
}

std::string LLBase64::decodeAsString(const std::string &input)
{
int b64_buffer_length = apr_base64_decode_len(input.c_str());
char* b64_buffer = new char[b64_buffer_length];

// This is faster than apr_base64_encode() if you know
// you're not on an EBCDIC machine. Also, the output is
// null terminated, even though the documentation doesn't
// specify. See apr_base64.c for details. JC
b64_buffer_length = apr_base64_decode(b64_buffer, input.c_str());
std::string res;
res.assign(b64_buffer);
delete[] b64_buffer;
return res;
}

1 change: 1 addition & 0 deletions indra/llcommon/llbase64.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LL_COMMON_API LLBase64
{
public:
static std::string encode(const U8* input, size_t input_size);
static std::string decodeAsString(const std::string& input);
};

#endif
83 changes: 69 additions & 14 deletions indra/newview/llpanelnearbymedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "llpanelnearbymedia.h"

#include "llaudioengine.h"
#include "llbase64.h"
#include "llcheckboxctrl.h"
#include "llclipboard.h"
#include "llcombobox.h"
Expand Down Expand Up @@ -107,6 +108,11 @@ LLPanelNearByMedia::LLPanelNearByMedia()
{
onMenuAction(data);
});
mEnableCallbackRegistrar.add("SelectedMediaCtrl.Visible",
[this](LLUICtrl* ctrl, const LLSD& data)
{
return onMenuVisible(data);
});

buildFromFile( "panel_nearby_media.xml");
}
Expand Down Expand Up @@ -270,6 +276,16 @@ BOOL LLPanelNearByMedia::handleRightMouseDown(S32 x, S32 y, MASK mask)
return LLPanelPulldown::handleRightMouseDown(x, y, mask);
}


void LLPanelNearByMedia::onVisibilityChange(BOOL new_visibility)
{
if (!new_visibility && mContextMenu->getVisible())
{
gMenuHolder->hideMenus();
}
LLPanelPulldown::onVisibilityChange(new_visibility);
}

bool LLPanelNearByMedia::getParcelAudioAutoStart()
{
return mParcelAudioAutoStart;
Expand Down Expand Up @@ -1213,34 +1229,49 @@ void LLPanelNearByMedia::onClickSelectedMediaUnzoom()
void LLPanelNearByMedia::onMenuAction(const LLSD& userdata)
{
const std::string command_name = userdata.asString();
if ("copy" == command_name)
if ("copy_url" == command_name)
{
LLClipboard::instance().reset();
LLUUID selected_media_id = mMediaList->getValue().asUUID();
std::string url;
std::string url = getSelectedUrl();

if (selected_media_id == PARCEL_AUDIO_LIST_ITEM_UUID)
if (!url.empty())
{
url = LLViewerMedia::getInstance()->getParcelAudioURL();
LLClipboard::instance().copyToClipboard(utf8str_to_wstring(url), 0, url.size());
}
else if (selected_media_id == PARCEL_MEDIA_LIST_ITEM_UUID)
}
else if ("copy_data" == command_name)
{
LLClipboard::instance().reset();
std::string url = getSelectedUrl();
static const std::string encoding_specifier = "base64,";
size_t pos = url.find(encoding_specifier);
if (pos != std::string::npos)
{
url = LLViewerParcelMedia::getInstance()->getURL();
pos += encoding_specifier.size();
std::string res = LLBase64::decodeAsString(url.substr(pos));
LLClipboard::instance().copyToClipboard(utf8str_to_wstring(res), 0, res.size());
}
else
{
LLViewerMediaImpl* impl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(selected_media_id);
if (NULL != impl)
{
url = impl->getCurrentMediaURL();
}
url = LLURI::unescape(url);
LLClipboard::instance().copyToClipboard(utf8str_to_wstring(url), 0, url.size());
}
}
}

if (!url.empty())
bool LLPanelNearByMedia::onMenuVisible(const LLSD& userdata)
{
const std::string command_name = userdata.asString();
if ("copy_data" == command_name)
{
std::string url = getSelectedUrl();
if (url.rfind("data:", 0) == 0)
{
LLClipboard::instance().copyToClipboard(utf8str_to_wstring(url), 0, url.size());
// might be a a good idea to permit text/html only
return true;
}
}
return false;
}

// static
Expand Down Expand Up @@ -1268,3 +1299,27 @@ void LLPanelNearByMedia::getNameAndUrlHelper(LLViewerMediaImpl* impl, std::strin
}
}

std::string LLPanelNearByMedia::getSelectedUrl()
{
std::string url;
LLUUID selected_media_id = mMediaList->getValue().asUUID();
if (selected_media_id == PARCEL_AUDIO_LIST_ITEM_UUID)
{
url = LLViewerMedia::getInstance()->getParcelAudioURL();
}
else if (selected_media_id == PARCEL_MEDIA_LIST_ITEM_UUID)
{
url = LLViewerParcelMedia::getInstance()->getURL();
}
else
{
LLViewerMediaImpl* impl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(selected_media_id);
if (NULL != impl)
{
std::string name;
getNameAndUrlHelper(impl, name, url, mEmptyNameString);
}
}
return url;
}

3 changes: 3 additions & 0 deletions indra/newview/llpanelnearbymedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class LLPanelNearByMedia : public LLPanelPulldown
void reshape(S32 width, S32 height, BOOL called_from_parent) override;
BOOL handleHover(S32 x, S32 y, MASK mask) override;
BOOL handleRightMouseDown(S32 x, S32 y, MASK mask) override;
void onVisibilityChange(BOOL new_visibility) override;

// this is part of the nearby media *dialog* so we can track whether
// the user *implicitly* wants audio on or off via their *explicit*
Expand Down Expand Up @@ -123,6 +124,7 @@ class LLPanelNearByMedia : public LLPanelPulldown
bool setDisabled(const LLUUID &id, bool disabled);

static void getNameAndUrlHelper(LLViewerMediaImpl* impl, std::string& name, std::string & url, const std::string &defaultName);
std::string getSelectedUrl();

void updateColumns();

Expand All @@ -141,6 +143,7 @@ class LLPanelNearByMedia : public LLPanelPulldown
void onClickSelectedMediaZoom();
void onClickSelectedMediaUnzoom();
void onMenuAction(const LLSD& userdata);
bool onMenuVisible(const LLSD& userdata);

LLUICtrl* mNearbyMediaPanel;
LLScrollListCtrl* mMediaList;
Expand Down
14 changes: 12 additions & 2 deletions indra/newview/skins/default/xui/en/menu_nearby_media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
mouse_opaque="false">
<menu_item_call
label="Copy Url"
name="copy">
name="copy_url">
<menu_item_call.on_click
function="SelectedMediaCtrl.Action"
parameter="copy" />
parameter="copy_url" />
</menu_item_call>
<menu_item_call
label="Copy Data"
name="copy_data">
<menu_item_call.on_click
function="SelectedMediaCtrl.Action"
parameter="copy_data" />
<menu_item_call.on_visible
function="SelectedMediaCtrl.Visible"
parameter="copy_data" />
</menu_item_call>
</toggleable_menu>

0 comments on commit b895292

Please sign in to comment.