diff options
Diffstat (limited to 'indra/newview/llfloaterbuycurrencyhtml.cpp')
| -rw-r--r-- | indra/newview/llfloaterbuycurrencyhtml.cpp | 152 |
1 files changed, 80 insertions, 72 deletions
diff --git a/indra/newview/llfloaterbuycurrencyhtml.cpp b/indra/newview/llfloaterbuycurrencyhtml.cpp index d3712869b0..55b7c32169 100644 --- a/indra/newview/llfloaterbuycurrencyhtml.cpp +++ b/indra/newview/llfloaterbuycurrencyhtml.cpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2010&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * Copyright (C) 2026, Linden Research, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,97 +27,105 @@ #include "llviewerprecompiledheaders.h" #include "llfloaterbuycurrencyhtml.h" -#include "llhttpconstants.h" +#include "llfloaterbuycurrency.h" +#include "llmediactrl.h" #include "llstatusbar.h" +#include "llviewercontrol.h" +#include "llweb.h" -//////////////////////////////////////////////////////////////////////////////// -// -LLFloaterBuyCurrencyHTML::LLFloaterBuyCurrencyHTML( const LLSD& key ): - LLFloater( key ), - mSpecificSumRequested( false ), - mMessage( "" ), - mSum( 0 ) + +LLFloaterBuyCurrencyHTML::LLFloaterBuyCurrencyHTML(const LLSD& key) + : LLFloater(key), + mBrowser(nullptr) { } -//////////////////////////////////////////////////////////////////////////////// -// -bool LLFloaterBuyCurrencyHTML::postBuild() +LLFloaterBuyCurrencyHTML::~LLFloaterBuyCurrencyHTML() { - // observer media events - mBrowser = getChild<LLMediaCtrl>( "browser" ); - mBrowser->addObserver( this ); - - return true; } -//////////////////////////////////////////////////////////////////////////////// -// -void LLFloaterBuyCurrencyHTML::navigateToFinalURL() +void LLFloaterBuyCurrencyHTML::onClose(bool app_quitting) { - // URL for actual currency buy contents is in XUI file - std::string buy_currency_url = getString( "buy_currency_url" ); - - // replace [LANGUAGE] meta-tag with view language - LLStringUtil::format_map_t replace; - - // viewer language - replace[ "[LANGUAGE]" ] = LLUI::getLanguage(); - - // flag that specific amount requested - replace[ "[SPECIFIC_AMOUNT]" ] = ( mSpecificSumRequested ? "y":"n" ); - - // amount requested - std::ostringstream codec( "" ); - codec << mSum; - replace[ "[SUM]" ] = codec.str(); - - // users' current balance - codec.clear(); - codec.str( "" ); - codec << gStatusBar->getBalance(); - replace[ "[BAL]" ] = codec.str(); - - // message - "This cost L$x,xxx for example - replace[ "[MSG]" ] = LLURI::escape( mMessage ); - LLStringUtil::format( buy_currency_url, replace ); + if (!app_quitting) + LLStatusBar::sendMoneyBalanceRequest(); - // write final URL to debug console - LL_INFOS() << "Buy currency HTML parsed URL is " << buy_currency_url << LL_ENDL; + LLFloater::onClose(app_quitting); +} - // kick off the navigation - mBrowser->navigateTo( buy_currency_url, HTTP_CONTENT_TEXT_HTML ); +bool LLFloaterBuyCurrencyHTML::postBuild() +{ + mBrowser = getChild<LLMediaCtrl>("browser"); + mBrowser->addObserver(this); + mBrowser->setErrorPageURL(gSavedSettings.getString("GenericErrorPageURL")); + LLViewerMedia::getInstance()->getOpenIDCookie(mBrowser); + return true; } -//////////////////////////////////////////////////////////////////////////////// -// -void LLFloaterBuyCurrencyHTML::handleMediaEvent( LLPluginClassMedia* self, EMediaEvent event ) +// static +std::string LLFloaterBuyCurrencyHTML::buildURL(S32 shortfall) { - // placeholder for now - just in case we want to catch media events - if ( LLPluginClassMediaOwner::MEDIA_EVENT_NAVIGATE_COMPLETE == event ) + std::string url = gSavedSettings.getString("BuyCurrencyPacksURL"); + LLStringUtil::format_map_t replace; + replace["[LANGUAGE]"] = LLUI::getLanguage(); + if (shortfall > 0) { - // update currency after we complete a navigation since there are many ways - // this can result in a different L$ balance - LLStatusBar::sendMoneyBalanceRequest(); - }; + replace["[SHORTFALL]"] = std::to_string(shortfall); + } + LLStringUtil::format(url, replace); + if (shortfall <= 0) + { + LLStringUtil::replaceString(url, "&shortfall=[SHORTFALL]", ""); + } + return url; } -//////////////////////////////////////////////////////////////////////////////// -// -void LLFloaterBuyCurrencyHTML::onClose( bool app_quitting ) +void LLFloaterBuyCurrencyHTML::navigateToFinalURL() { - // Update L$ balance one more time - LLStatusBar::sendMoneyBalanceRequest(); + mBrowser->navigateTo(buildURL(mShortfall), HTTP_CONTENT_TEXT_HTML); +} - destroy(); +void LLFloaterBuyCurrencyHTML::setFallbackContext(const std::string& message, S32 sum) +{ + mFallbackMessage = message; + mFallbackSum = sum; + mHasFallbackTarget = true; } -//////////////////////////////////////////////////////////////////////////////// -// -void LLFloaterBuyCurrencyHTML::setParams( bool specific_sum_requested, const std::string& message, S32 sum ) +void LLFloaterBuyCurrencyHTML::fallbackToLegacy() { - // save these away - used to construct URL later - mSpecificSumRequested = specific_sum_requested; - mMessage = message; - mSum = sum; + LL_WARNS() << "Buy Currency HTML page failed to load, falling back to legacy floater" << LL_ENDL; + closeFloater(); + if (mHasFallbackTarget) + { + LLFloaterBuyCurrency::buyCurrency(mFallbackMessage, mFallbackSum); + } + else + { + LLFloaterBuyCurrency::buyCurrency(); + } +} + +void LLFloaterBuyCurrencyHTML::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event) +{ + if (LLPluginClassMediaOwner::MEDIA_EVENT_NAVIGATE_COMPLETE == event) + { + if (self->getNavigateURI().find("done=success") != std::string::npos) + { + LLStatusBar::sendMoneyBalanceRequest(); + } + else + { + // HTTP 4xx/5xx: fall back to legacy floater + if (self->getNavigateResultCode() >= 400) + { + fallbackToLegacy(); + } + } + } + else if (event == LLPluginClassMediaOwner::MEDIA_EVENT_NAVIGATE_ERROR_PAGE || + event == LLPluginClassMediaOwner::MEDIA_EVENT_PLUGIN_FAILED_LAUNCH || + event == LLPluginClassMediaOwner::MEDIA_EVENT_PLUGIN_FAILED) + { + fallbackToLegacy(); + } } |
