diff options
Diffstat (limited to 'indra/newview/llfloaterwebcontent.cpp')
-rw-r--r-- | indra/newview/llfloaterwebcontent.cpp | 129 |
1 files changed, 81 insertions, 48 deletions
diff --git a/indra/newview/llfloaterwebcontent.cpp b/indra/newview/llfloaterwebcontent.cpp index 43eecbf048..785441a67e 100644 --- a/indra/newview/llfloaterwebcontent.cpp +++ b/indra/newview/llfloaterwebcontent.cpp @@ -40,8 +40,18 @@ #include "llfloaterwebcontent.h" -LLFloaterWebContent::LLFloaterWebContent( const LLSD& key ) - : LLFloater( key ) +LLFloaterWebContent::_Params::_Params() +: url("url"), + target("target"), + id("id"), + show_chrome("show_chrome", true), + allow_address_entry("allow_address_entry", true), + preferred_media_size("preferred_media_size"), + trusted_content("trusted_content", false) +{} + +LLFloaterWebContent::LLFloaterWebContent( const Params& key ) +: LLFloater( key ) { mCommitCallbackRegistrar.add( "WebContent.Back", boost::bind( &LLFloaterWebContent::onClickBack, this )); mCommitCallbackRegistrar.add( "WebContent.Forward", boost::bind( &LLFloaterWebContent::onClickForward, this )); @@ -75,6 +85,20 @@ BOOL LLFloaterWebContent::postBuild() return TRUE; } +bool LLFloaterWebContent::matchesKey(const LLSD& key) +{ + LLUUID id = key["id"]; + if (id.notNull()) + { + return id == mKey["id"].asUUID(); + } + else + { + return key["target"].asString() == mKey["target"].asString(); + } +} + + void LLFloaterWebContent::initializeURLHistory() { // start with an empty list @@ -99,30 +123,23 @@ void LLFloaterWebContent::initializeURLHistory() } //static -void LLFloaterWebContent::create( const std::string &url, const std::string& target, const std::string& uuid, bool show_chrome, const LLRect& preferred_media_size) +void LLFloaterWebContent::create( Params p) { - lldebugs << "url = " << url << ", target = " << target << ", uuid = " << uuid << llendl; + lldebugs << "url = " << p.url() << ", target = " << p.target() << ", uuid = " << p.id().asString() << llendl; - std::string tag = target; + if (!p.id.isProvided()) + { + p.id = LLUUID::generateNewID(); + } - if(target.empty() || target == "_blank") + if(!p.target.isProvided() || p.target() == "_blank") { - if(!uuid.empty()) - { - tag = uuid; - } - else - { - // create a unique tag for this instance - LLUUID id; - id.generate(); - tag = id.asString(); - } + p.target = p.id().asString(); } S32 browser_window_limit = gSavedSettings.getS32("WebContentWindowLimit"); - if(LLFloaterReg::findInstance("web_content", tag) != NULL) + if(LLFloaterReg::findInstance("web_content", p.target()) != NULL) { // There's already a web browser for this tag, so we won't be opening a new window. } @@ -136,7 +153,7 @@ void LLFloaterWebContent::create( const std::string &url, const std::string& tar for(LLFloaterReg::const_instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); iter++) { - lldebugs << " " << (*iter)->getKey() << llendl; + lldebugs << " " << (*iter)->getKey()["target"] << llendl; } if(instances.size() >= (size_t)browser_window_limit) @@ -146,30 +163,7 @@ void LLFloaterWebContent::create( const std::string &url, const std::string& tar } } - LLFloaterWebContent *browser = dynamic_cast<LLFloaterWebContent*> (LLFloaterReg::showInstance("web_content", tag)); - llassert(browser); - if(browser) - { - browser->mUUID = uuid; - - // tell the browser instance to load the specified URL - browser->open_media(url, target); - LLViewerMedia::proxyWindowOpened(target, uuid); - - browser->getChild<LLLayoutPanel>("status_bar")->setVisible(show_chrome); - browser->getChild<LLLayoutPanel>("nav_controls")->setVisible(show_chrome); - - if (!show_chrome) - { - browser->setResizeLimits(100, 100); - } - - if (!preferred_media_size.isEmpty()) - { - //ignore x, y for now - browser->geometryChanged(browser->getRect().mLeft, browser->getRect().mBottom, preferred_media_size.getWidth(), preferred_media_size.getHeight()); - } - } + LLFloaterReg::showInstance("web_content", p); } //static @@ -227,13 +221,52 @@ void LLFloaterWebContent::geometryChanged(S32 x, S32 y, S32 width, S32 height) setShape(geom); } -void LLFloaterWebContent::open_media(const std::string& web_url, const std::string& target) +void LLFloaterWebContent::open_media(const Params& p) { // Specifying a mime type of text/html here causes the plugin system to skip the MIME type probe and just open a browser plugin. - mWebBrowser->setHomePageUrl(web_url, "text/html"); - mWebBrowser->setTarget(target); - mWebBrowser->navigateTo(web_url, "text/html"); - set_current_url(web_url); + LLViewerMedia::proxyWindowOpened(p.target(), p.id().asString()); + mWebBrowser->setHomePageUrl(p.url, "text/html"); + mWebBrowser->setTarget(p.target); + mWebBrowser->navigateTo(p.url, "text/html"); + + set_current_url(p.url); + + getChild<LLLayoutPanel>("status_bar")->setVisible(p.show_chrome); + getChild<LLLayoutPanel>("nav_controls")->setVisible(p.show_chrome); + getChild<LLUICtrl>("address")->setEnabled(p.allow_address_entry && !p.trusted_content); + + if (!p.show_chrome) + { + setResizeLimits(100, 100); + } + + if (!p.preferred_media_size().isEmpty()) + { + //ignore x, y for now + geometryChanged(getRect().mLeft, getRect().mBottom, p.preferred_media_size().getWidth(), p.preferred_media_size().getHeight()); + } + +} + +void LLFloaterWebContent::onOpen(const LLSD& key) +{ + Params params(key); + + if (!params.validateBlock()) + { + closeFloater(); + return; + } + + if (params.target() == params.id().asString()) + { + setRectControl(""); + } + mUUID = params.id().asString(); + mWebBrowser->setTrustedContent(params.trusted_content); + + // tell the browser instance to load the specified URL + open_media(params); } //virtual |