Skip to content
Snippets Groups Projects
Commit 2f0e3de4 authored by Rider Linden's avatar Rider Linden
Browse files

Land Media URL entry to coroutine.

parent dcd36402
No related branches found
No related tags found
No related merge requests found
...@@ -40,40 +40,10 @@ ...@@ -40,40 +40,10 @@
#include "lluictrlfactory.h" #include "lluictrlfactory.h"
#include "llwindow.h" #include "llwindow.h"
#include "llviewerwindow.h" #include "llviewerwindow.h"
#include "llcorehttputil.h"
static LLFloaterURLEntry* sInstance = NULL; static LLFloaterURLEntry* sInstance = NULL;
// Move this to its own file.
// helper class that tries to download a URL from a web site and calls a method
// on the Panel Land Media and to discover the MIME type
class LLMediaTypeResponder : public LLHTTPClient::Responder
{
LOG_CLASS(LLMediaTypeResponder);
public:
LLMediaTypeResponder( const LLHandle<LLFloater> parent ) :
mParent( parent )
{}
LLHandle<LLFloater> mParent;
private:
/* virtual */ void httpCompleted()
{
const std::string& media_type = getResponseHeader(HTTP_IN_HEADER_CONTENT_TYPE);
std::string::size_type idx1 = media_type.find_first_of(";");
std::string mime_type = media_type.substr(0, idx1);
// Set empty type to none/none. Empty string is reserved for legacy parcels
// which have no mime type set.
std::string resolved_mime_type = ! mime_type.empty() ? mime_type : LLMIMETypes::getDefaultMimeType();
LLFloaterURLEntry* floater_url_entry = (LLFloaterURLEntry*)mParent.get();
if ( floater_url_entry )
{
floater_url_entry->headerFetchComplete( getStatus(), resolved_mime_type );
}
}
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// LLFloaterURLEntry() // LLFloaterURLEntry()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -225,8 +195,8 @@ void LLFloaterURLEntry::onBtnOK( void* userdata ) ...@@ -225,8 +195,8 @@ void LLFloaterURLEntry::onBtnOK( void* userdata )
if(!media_url.empty() && if(!media_url.empty() &&
(scheme == "http" || scheme == "https")) (scheme == "http" || scheme == "https"))
{ {
LLHTTPClient::getHeaderOnly( media_url, LLCoros::instance().launch("LLFloaterURLEntry::getMediaTypeCoro",
new LLMediaTypeResponder(self->getHandle())); boost::bind(&LLFloaterURLEntry::getMediaTypeCoro, _1, media_url, self->getHandle()));
} }
else else
{ {
...@@ -239,6 +209,58 @@ void LLFloaterURLEntry::onBtnOK( void* userdata ) ...@@ -239,6 +209,58 @@ void LLFloaterURLEntry::onBtnOK( void* userdata )
self->getChildView("media_entry")->setEnabled(false); self->getChildView("media_entry")->setEnabled(false);
} }
// static
void LLFloaterURLEntry::getMediaTypeCoro(LLCoros::self& self, std::string url, LLHandle<LLFloater> parentHandle)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("getMediaTypeCoro", httpPolicy));
LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
LLCore::HttpOptions::ptr_t httpOpts = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions);
httpOpts->setHeadersOnly(true);
LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL;
LLSD result = httpAdapter->getAndYield(self, httpRequest, url, httpOpts);
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
LLFloaterURLEntry* floaterUrlEntry = (LLFloaterURLEntry*)parentHandle.get();
if (!floaterUrlEntry)
{
LL_WARNS() << "Could not get URL entry floater." << LL_ENDL;
return;
}
// Set empty type to none/none. Empty string is reserved for legacy parcels
// which have no mime type set.
std::string resolvedMimeType = LLMIMETypes::getDefaultMimeType();
if (!status)
{
floaterUrlEntry->headerFetchComplete(status.getType(), resolvedMimeType);
return;
}
LLSD resultHeaders = httpResults[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_HEADERS];
if (resultHeaders.has(HTTP_IN_HEADER_CONTENT_TYPE))
{
const std::string& mediaType = resultHeaders[HTTP_IN_HEADER_CONTENT_TYPE];
std::string::size_type idx1 = mediaType.find_first_of(";");
std::string mimeType = mediaType.substr(0, idx1);
if (!mimeType.empty())
{
resolvedMimeType = mimeType;
}
}
floaterUrlEntry->headerFetchComplete(status.getType(), resolvedMimeType);
}
// static // static
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// onBtnCancel() // onBtnCancel()
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "llfloater.h" #include "llfloater.h"
#include "llpanellandmedia.h" #include "llpanellandmedia.h"
#include "lleventcoro.h"
#include "llcoros.h"
class LLLineEditor; class LLLineEditor;
class LLComboBox; class LLComboBox;
...@@ -57,6 +59,9 @@ private: ...@@ -57,6 +59,9 @@ private:
static void onBtnCancel(void*); static void onBtnCancel(void*);
static void onBtnClear(void*); static void onBtnClear(void*);
bool callback_clear_url_list(const LLSD& notification, const LLSD& response); bool callback_clear_url_list(const LLSD& notification, const LLSD& response);
static void getMediaTypeCoro(LLCoros::self& self, std::string url, LLHandle<LLFloater> parentHandle);
}; };
#endif // LL_LLFLOATERURLENTRY_H #endif // LL_LLFLOATERURLENTRY_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment