//static
void LLFloaterWebContent::geometryChanged(const std::string &uuid, S32 x, S32 y, S32 width, S32 height)
{
    LLFloaterWebContent* floaterp = instance_tracker_t::getInstance(uuid);
    if (floaterp)
    {
        floaterp->geometryChanged(x, y, width, height);
    }
}
//static
void LLFloaterWebContent::closeRequest(const std::string &uuid)
{
    LLFloaterWebContent* floaterp = instance_tracker_t::getInstance(uuid);
    if (floaterp)
    {
        floaterp->close();
    }
}
//static
void LLFloaterWebContent::create( const std::string &url, const std::string& target, const std::string& uuid )
{
	lldebugs << "url = " << url << ", target = " << target << ", uuid = " << uuid << llendl;

	std::string tag = target;

	if(target.empty() || target == "_blank")
	{
		if(!uuid.empty())
		{
			tag = uuid;
		}
		else
		{
			// create a unique tag for this instance
			LLUUID id;
			id.generate();
			tag = id.asString();
		}
	}

	S32 browser_window_limit = gSavedSettings.getS32("WebContentWindowLimit");

	if(LLFloaterReg::findInstance("web_content", tag) != NULL)
	{
		// There's already a web browser for this tag, so we won't be opening a new window.
	}
	else if(browser_window_limit != 0)
	{
		// showInstance will open a new window.  Figure out how many web browsers are already open,
		// and close the least recently opened one if this will put us over the limit.

		LLFloaterReg::const_instance_list_t &instances = LLFloaterReg::getFloaterList("web_content");
		lldebugs << "total instance count is " << instances.size() << llendl;

		for(LLFloaterReg::const_instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); iter++)
		{
			lldebugs << "    " << (*iter)->getKey() << llendl;
		}

		if(instances.size() >= (size_t)browser_window_limit)
		{
			// Destroy the least recently opened instance
			(*instances.begin())->closeFloater();
		}
	}

	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);
	}
}
//static
void LLFloaterWebContent::geometryChanged(const std::string &uuid, S32 x, S32 y, S32 width, S32 height)
{
	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("web_content");
	lldebugs << "instance list size is " << inst_list.size() << ", incoming uuid is " << uuid << llendl;
	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
	{
		LLFloaterWebContent* i = dynamic_cast<LLFloaterWebContent*>(*iter);
		lldebugs << "    " << i->mUUID << llendl;
		if (i && i->mUUID == uuid)
		{
			i->geometryChanged(x, y, width, height);
			return;
		}
	}
}
//static
void LLFloaterWebContent::closeRequest(const std::string &uuid)
{
	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("web_content");
	lldebugs << "instance list size is " << inst_list.size() << ", incoming uuid is " << uuid << llendl;
	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
	{
		LLFloaterWebContent* i = dynamic_cast<LLFloaterWebContent*>(*iter);
		lldebugs << "    " << i->mUUID << llendl;
		if (i && i->mUUID == uuid)
		{
			i->closeFloater(false);
			return;
 		}
 	}
}
//static
void LLFloaterWebContent::create( const std::string &url, const std::string& target, const std::string& uuid,  bool show_chrome, const LLRect& preferred_media_size)
{
	lldebugs << "url = " << url << ", target = " << target << ", uuid = " << uuid << llendl;

	std::string tag = target;

	if(target.empty() || target == "_blank")
	{
		if(!uuid.empty())
		{
			tag = uuid;
		}
		else
		{
			// create a unique tag for this instance
			LLUUID id;
			id.generate();
			tag = id.asString();
		}
	}

	S32 browser_window_limit = gSavedSettings.getS32("WebContentWindowLimit");

	if(LLFloaterReg::findInstance("web_content", tag) != NULL)
	{
		// There's already a web browser for this tag, so we won't be opening a new window.
	}
	else if(browser_window_limit != 0)
	{
		// showInstance will open a new window.  Figure out how many web browsers are already open,
		// and close the least recently opened one if this will put us over the limit.

		LLFloaterReg::const_instance_list_t &instances = LLFloaterReg::getFloaterList("web_content");
		lldebugs << "total instance count is " << instances.size() << llendl;

		for(LLFloaterReg::const_instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); iter++)
		{
			lldebugs << "    " << (*iter)->getKey() << llendl;
		}

		if(instances.size() >= (size_t)browser_window_limit)
		{
			// Destroy the least recently opened instance
			(*instances.begin())->closeFloater();
		}
	}

	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());
		}
	}
}