123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- /**
- * @file llfloatermediabrowser.cpp
- * @brief Web browser floaters
- *
- * $LicenseInfo:firstyear=2006&license=viewergpl$
- *
- * Copyright (c) 2006-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include "llfloatermediabrowser.h"
- #include "llcombobox.h"
- #include "llhttpconstants.h" // For HTTP_CONTENT_TEXT_HTML
- #include "llpluginclassmedia.h"
- #include "llsdutil.h"
- #include "lltextbox.h"
- #include "lluictrlfactory.h"
- #include "llurlhistory.h"
- #include "llwindow.h"
- #include "llcommandhandler.h"
- #include "llgridmanager.h"
- #include "llviewercontrol.h"
- #include "llviewerparcelmedia.h"
- #include "llviewerparcelmgr.h"
- #include "llweb.h"
- #include "roles_constants.h"
- // Global
- LLViewerHtmlHelp gViewerHtmlHelp;
- ////////////////////////////////////////////////////////////////////////////////
- // Command handler for secondlife:///app/help/{TOPIC} SLapps SLURL support
- ////////////////////////////////////////////////////////////////////////////////
- // Note: TOPIC is ignored (it is pretty dumb anyway: only pre and post login
- // topics are used in LL's v3 viewer). HB
- class LLHelpHandler final : public LLCommandHandler
- {
- public:
- // Requests will be throttled from a non-trusted browser
- LLHelpHandler()
- : LLCommandHandler("help", UNTRUSTED_THROTTLE)
- {
- }
- bool handle(const LLSD&, const LLSD&, LLMediaCtrl*) override
- {
- gViewerHtmlHelp.show();
- return true;
- }
- };
- LLHelpHandler gHelpHandler;
- ////////////////////////////////////////////////////////////////////////////////
- // LLFloaterMediaBrowser class
- ////////////////////////////////////////////////////////////////////////////////
- //static
- LLFloaterMediaBrowser::instances_vec_t LLFloaterMediaBrowser::sInstances;
- //static
- LLFloaterMediaBrowser* LLFloaterMediaBrowser::getInstance(const LLSD& media_url)
- {
- std::string url = media_url.asString();
- // Try and find a corresponding open instance
- U32 count = sInstances.size();
- for (U32 i = 0; i < count; ++i)
- {
- LLFloaterMediaBrowser* floaterp = sInstances[i];
- if (floaterp->mInitalUrl == url || floaterp->mCurrentURL == url)
- {
- return floaterp;
- }
- }
- U32 max_count = gSavedSettings.getU32("MaxBrowserInstances");
- if (max_count < 1)
- {
- max_count = 1;
- gSavedSettings.setU32("MaxBrowserInstances", 1);
- }
- if (count >= max_count)
- {
- llinfos << "Maximum Web floaters instances reached, reusing the last one."
- << llendl;
- // Pick the last instance.
- return sInstances.back();
- }
- return new LLFloaterMediaBrowser(media_url);
- }
- //static
- LLFloaterMediaBrowser* LLFloaterMediaBrowser::showInstance(const LLSD& media_url,
- bool trusted)
- {
- LLFloaterMediaBrowser* floaterp =
- LLFloaterMediaBrowser::getInstance(media_url);
- if (floaterp) // Paranoia
- {
- floaterp->openMedia(media_url.asString(), trusted);
- gFloaterViewp->bringToFront(floaterp);
- }
- return floaterp;
- }
- LLFloaterMediaBrowser::LLFloaterMediaBrowser(const LLSD& media_url)
- : mInitalUrl(media_url.asString()),
- mBrowser(NULL),
- mParcel(NULL),
- mBackButton(NULL),
- mForwardButton(NULL),
- mReloadButton(NULL),
- mRewindButton(NULL),
- mPlayButton(NULL),
- mPauseButton(NULL),
- mStopButton(NULL),
- mSeekButton(NULL),
- mGoButton(NULL),
- mCloseButton(NULL),
- mBrowserButton(NULL),
- mAssignButton(NULL),
- mAddressCombo(NULL),
- mLoadingText(NULL)
- {
- sInstances.push_back(this);
- LLUICtrlFactory::getInstance()->buildFloater(this,
- "floater_media_browser.xml");
- }
- //virtual
- LLFloaterMediaBrowser::~LLFloaterMediaBrowser()
- {
- for (instances_vec_t::iterator it = sInstances.begin(),
- end = sInstances.end();
- it != end; ++it)
- {
- if (*it == this)
- {
- sInstances.erase(it);
- break;
- }
- }
- }
- bool LLFloaterMediaBrowser::postBuild()
- {
- // Note: we use the "build dummy widget if missing" version of getChild<T>
- // so that all pointers are non-NULL and warnings are issued in the log
- // about missing UI elements. All the UI elements are considered mandatory.
- mBrowser = getChild<LLMediaCtrl>("browser");
- mBrowser->addObserver(this);
- mAddressCombo = getChild<LLComboBox>("address");
- mAddressCombo->setCommitCallback(onEnterAddress);
- mAddressCombo->setCallbackUserData(this);
- mBackButton = getChild<LLButton>("back");
- mBackButton->setClickedCallback(onClickBack, this);
- mForwardButton = getChild<LLButton>("forward");
- mForwardButton->setClickedCallback(onClickForward, this);
- mReloadButton = getChild<LLButton>("reload");
- mReloadButton->setClickedCallback(onClickRefresh, this);
- mRewindButton = getChild<LLButton>("rewind");
- mRewindButton->setClickedCallback(onClickRewind, this);
- mPlayButton = getChild<LLButton>("play");
- mPlayButton->setClickedCallback(onClickPlay, this);
- mPauseButton = getChild<LLButton>("pause");
- mPauseButton->setClickedCallback(onClickPlay, this);
- mStopButton = getChild<LLButton>("stop");
- mStopButton->setClickedCallback(onClickStop, this);
- mSeekButton = getChild<LLButton>("seek");
- mSeekButton->setClickedCallback(onClickSeek, this);
- mGoButton = getChild<LLButton>("go");
- mGoButton->setClickedCallback(onClickGo, this);
- mCloseButton = getChild<LLButton>("close");
- mCloseButton->setClickedCallback(onClickClose, this);
- mBrowserButton = getChild<LLButton>("open_browser");
- mBrowserButton->setClickedCallback(onClickOpenWebBrowser, this);
- mAssignButton = getChild<LLButton>("assign");
- mAssignButton->setClickedCallback(onClickAssign, this);
- mLoadingText = getChild<LLTextBox>("loading");
- buildURLHistory();
- return true;
- }
- void LLFloaterMediaBrowser::geometryChanged(S32 x, S32 y, S32 width,
- S32 height)
- {
- // Make sure the layout of the browser control is updated, so this
- // calculation is correct.
- LLLayoutStack::updateClass();
- LLCoordWindow window_size;
- gWindowp->getSize(&window_size);
- // Adjust width and height for the size of the chrome on the Media Browser
- // window.
- width += getRect().getWidth() - mBrowser->getRect().getWidth();
- height += getRect().getHeight() - mBrowser->getRect().getHeight();
- LLRect geom;
- geom.setOriginAndSize(x, window_size.mY - (y + height), width, height);
- LL_DEBUGS("MediaBrowser") << "geometry change: " << geom << LL_ENDL;
- userSetShape(geom);
- }
- void LLFloaterMediaBrowser::draw()
- {
- if (!mBrowser)
- {
- // There is something *very* wrong: abort
- llwarns_once << "Incomplete floater media browser !" << llendl;
- LLFloater::draw();
- return;
- }
- mBackButton->setEnabled(mBrowser->canNavigateBack());
- mForwardButton->setEnabled(mBrowser->canNavigateForward());
- mGoButton->setEnabled(!mAddressCombo->getValue().asString().empty() &&
- // Forbid changing a trusted browser URL
- !mBrowser->isTrusted());
- LLParcel* parcelp = gViewerParcelMgr.getAgentParcel();
- if (mParcel != parcelp)
- {
- mParcel = parcelp;
- bool can_change =
- LLViewerParcelMgr::isParcelModifiableByAgent(parcelp,
- GP_LAND_CHANGE_MEDIA);
- mAssignButton->setVisible(can_change);
- bool not_empty = !mAddressCombo->getValue().asString().empty();
- mAssignButton->setEnabled(not_empty);
- }
- bool show_time_controls = false;
- bool media_playing = false;
- LLPluginClassMedia* pluginp = mBrowser->getMediaPlugin();
- if (pluginp)
- {
- show_time_controls = pluginp->pluginSupportsMediaTime();
- media_playing =
- pluginp->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING;
- }
- mRewindButton->setVisible(show_time_controls);
- mPlayButton->setVisible(show_time_controls && !media_playing);
- mPlayButton->setEnabled(!media_playing);
- mPauseButton->setVisible(show_time_controls && media_playing);
- mStopButton->setVisible(show_time_controls);
- mStopButton->setEnabled(media_playing);
- mSeekButton->setVisible(show_time_controls);
- LLFloater::draw();
- }
- void LLFloaterMediaBrowser::buildURLHistory()
- {
- mAddressCombo->operateOnAll(LLComboBox::OP_DELETE);
- // Get all of the entries in the "browser" collection
- LLSD browser_history = LLURLHistory::getURLHistory("browser");
- std::string url;
- for(LLSD::array_iterator iter_history = browser_history.beginArray(),
- end_history = browser_history.endArray();
- iter_history != end_history; ++iter_history)
- {
- url = iter_history->asString();
- if (!url.empty())
- {
- mAddressCombo->addSimpleElement(url);
- }
- }
- // Initialize URL history in the plugin
- LLPluginClassMedia* pluginp = mBrowser->getMediaPlugin();
- if (pluginp)
- {
- pluginp->initializeUrlHistory(browser_history);
- }
- }
- void LLFloaterMediaBrowser::onClose(bool app_quitting)
- {
- if (mBrowser)
- {
- mBrowser->remObserver(this);
- if (mBrowser->getMediaSource())
- {
- mBrowser->getMediaSource()->cancelMimeTypeProbe();
- }
- }
- destroy();
- }
- void LLFloaterMediaBrowser::handleMediaEvent(LLPluginClassMedia* self,
- EMediaEvent event)
- {
- if (event == MEDIA_EVENT_LOCATION_CHANGED)
- {
- setCurrentURL(self->getLocation());
- mAddressCombo->setVisible(false);
- mLoadingText->setVisible(true);
- }
- else if (event == MEDIA_EVENT_NAVIGATE_COMPLETE)
- {
- // This is the event these flags are sent with.
- mBackButton->setEnabled(self->getHistoryBackAvailable());
- mForwardButton->setEnabled(self->getHistoryForwardAvailable());
- mAddressCombo->setVisible(true);
- mLoadingText->setVisible(false);
- }
- else if (event == MEDIA_EVENT_CLOSE_REQUEST)
- {
- // The browser instance wants its window closed.
- close();
- }
- else if (event == MEDIA_EVENT_GEOMETRY_CHANGE)
- {
- geometryChanged(self->getGeometryX(), self->getGeometryY(),
- self->getGeometryWidth(), self->getGeometryHeight());
- }
- }
- void LLFloaterMediaBrowser::setCurrentURL(const std::string& url)
- {
- mCurrentURL = url;
- // Redirects will navigate momentarily to about:blank: do not add to
- // history
- if (mCurrentURL != "about:blank")
- {
- mAddressCombo->remove(mCurrentURL);
- mAddressCombo->add(mCurrentURL, ADD_SORTED);
- mAddressCombo->selectByValue(mCurrentURL);
- // Serialize url history
- LLURLHistory::removeURL("browser", mCurrentURL);
- LLURLHistory::addURL("browser", mCurrentURL);
- }
- mBackButton->setEnabled(mBrowser->canNavigateBack());
- mForwardButton->setEnabled(mBrowser->canNavigateForward());
- mReloadButton->setEnabled(true);
- }
- //static
- void LLFloaterMediaBrowser::onEnterAddress(LLUICtrl* ctrl, void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickRefresh(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- self->mAddressCombo->remove(0);
- std::string url = self->mCurrentURL;
- // Force a reload by changing the page first
- self->mBrowser->navigateTo("about:blank");
- self->mBrowser->navigateTo(url);
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickForward(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- self->mBrowser->navigateForward();
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickBack(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- self->mBrowser->navigateBack();
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickGo(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
- }
- //static
- void LLFloaterMediaBrowser::onClickClose(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- self->close();
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickOpenWebBrowser(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (self)
- {
- // NOTE: we favour the URL in the combo box, because in case of a page
- // loading failure (SSL handshake failures, for example), mCurrentURL
- // contains about:blank or another URL than the failed page URL...
- std::string url = self->mAddressCombo->getValue().asString();
- if (url.empty())
- {
- url = self->mCurrentURL;
- }
- if (url.empty())
- {
- url = self->mBrowser->getHomePageUrl();
- }
- LLWeb::loadURLExternal(url);
- }
- }
- void LLFloaterMediaBrowser::onClickAssign(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (!self) return;
- LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
- if (!parcel)
- {
- return;
- }
- std::string media_url = self->mAddressCombo->getValue().asString();
- LLStringUtil::trim(media_url);
- if (parcel->getMediaType() != HTTP_CONTENT_TEXT_HTML)
- {
- parcel->setMediaURL(media_url);
- parcel->setMediaCurrentURL(media_url);
- parcel->setMediaType(HTTP_CONTENT_TEXT_HTML);
- gViewerParcelMgr.sendParcelPropertiesUpdate(parcel, true);
- LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
- LLViewerParcelMedia::stop();
- #if 0
- LLViewerParcelMedia::update(parcel);
- #endif
- }
- LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
- }
- //static
- void LLFloaterMediaBrowser::onClickRewind(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (!self) return; // Paranoia
- LLPluginClassMedia* pluginp = self->mBrowser->getMediaPlugin();
- if (pluginp)
- {
- pluginp->start(-2.f);
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickPlay(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (!self) return; // Paranoia
- LLPluginClassMedia* pluginp = self->mBrowser->getMediaPlugin();
- if (!pluginp) return;
- if (pluginp->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING)
- {
- pluginp->pause();
- }
- else
- {
- pluginp->start();
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickStop(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (!self) return; // Paranoia
- LLPluginClassMedia* pluginp = self->mBrowser->getMediaPlugin();
- if (pluginp)
- {
- pluginp->stop();
- }
- }
- //static
- void LLFloaterMediaBrowser::onClickSeek(void* user_data)
- {
- LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
- if (!self) return; // Paranoia
- LLPluginClassMedia* pluginp = self->mBrowser->getMediaPlugin();
- if (pluginp)
- {
- pluginp->start(2.f);
- }
- }
- void LLFloaterMediaBrowser::openMedia(const std::string& media_url,
- bool trusted)
- {
- openMedia(media_url, "", trusted);
- }
- void LLFloaterMediaBrowser::openMedia(const std::string& media_url,
- const std::string& target,
- bool trusted)
- {
- mBrowser->setHomePageUrl(media_url);
- mBrowser->setTarget(target);
- mBrowser->setTrusted(trusted);
- mAddressCombo->setEnabled(!trusted);
- mGoButton->setEnabled(!trusted);
- mAddressCombo->setVisible(false);
- mLoadingText->setVisible(true);
- mBrowser->navigateTo(media_url);
- setCurrentURL(media_url);
- }
- ////////////////////////////////////////////////////////////////////////////////
- // LLViewerHtmlHelp class
- ////////////////////////////////////////////////////////////////////////////////
- LLViewerHtmlHelp::LLViewerHtmlHelp()
- {
- LLUI::setHtmlHelp(this);
- }
- LLViewerHtmlHelp::~LLViewerHtmlHelp()
- {
- LLUI::setHtmlHelp(NULL);
- }
- void LLViewerHtmlHelp::show()
- {
- show("");
- }
- void LLViewerHtmlHelp::show(std::string url)
- {
- if (url.empty())
- {
- url = LLGridManager::getInstance()->getSupportURL();
- }
- if (gSavedSettings.getBool("UseExternalBrowser"))
- {
- LLSD data;
- data["url"] = url;
- gNotifications.add("ClickOpenF1Help", data, LLSD(),
- onClickF1HelpLoadURL);
- return;
- }
- LLFloaterMediaBrowser* floaterp = LLFloaterMediaBrowser::getInstance(url);
- if (floaterp)
- {
- floaterp->setVisible(true);
- floaterp->openMedia(url);
- }
- }
- //static
- bool LLViewerHtmlHelp::onClickF1HelpLoadURL(const LLSD& notification,
- const LLSD& response)
- {
- if (LLNotification::getSelectedOption(notification, response) == 0)
- {
- LLWeb::loadURL(LLGridManager::getInstance()->getSupportURL());
- }
- return false;
- }
|