PageRenderTime 246ms CodeModel.GetById 100ms app.highlight 49ms RepoModel.GetById 92ms app.codeStats 0ms

/indra/newview/llurldispatcher.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 323 lines | 200 code | 42 blank | 81 comment | 15 complexity | d082f86906df8f74442e3dbfaa65e6ff MD5 | raw file
  1/**
  2 * @file llurldispatcher.cpp
  3 * @brief Central registry for all URL handlers
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26#include "llviewerprecompiledheaders.h"
 27
 28#include "llurldispatcher.h"
 29
 30// viewer includes
 31#include "llagent.h"			// teleportViaLocation()
 32#include "llcommandhandler.h"
 33#include "llfloaterhelpbrowser.h"
 34#include "llfloaterreg.h"
 35#include "llfloatersidepanelcontainer.h"
 36#include "llfloaterworldmap.h"
 37#include "llpanellogin.h"
 38#include "llregionhandle.h"
 39#include "llslurl.h"
 40#include "llstartup.h"			// gStartupState
 41#include "llweb.h"
 42#include "llworldmapmessage.h"
 43#include "llurldispatcherlistener.h"
 44#include "llviewernetwork.h"
 45
 46// library includes
 47#include "llnotificationsutil.h"
 48#include "llsd.h"
 49
 50static LLURLDispatcherListener sURLDispatcherListener;
 51
 52class LLURLDispatcherImpl
 53{
 54public:
 55	static bool dispatch(const LLSLURL& slurl,
 56						 const std::string& nav_type,
 57						 LLMediaCtrl* web,
 58						 bool trusted_browser);
 59		// returns true if handled or explicitly blocked.
 60
 61	static bool dispatchRightClick(const LLSLURL& slurl);
 62
 63private:
 64	static bool dispatchCore(const LLSLURL& slurl, 
 65							 const std::string& nav_type,
 66							 bool right_mouse,
 67							 LLMediaCtrl* web,
 68							 bool trusted_browser);
 69		// handles both left and right click
 70
 71	static bool dispatchHelp(const LLSLURL& slurl, bool right_mouse);
 72		// Handles sl://app.floater.html.help by showing Help floater.
 73		// Returns true if handled.
 74
 75	static bool dispatchApp(const LLSLURL& slurl,
 76							const std::string& nav_type,
 77							bool right_mouse,
 78							LLMediaCtrl* web,
 79							bool trusted_browser);
 80		// Handles secondlife:///app/agent/<agent_id>/about and similar
 81		// by showing panel in Search floater.
 82		// Returns true if handled or explicitly blocked.
 83
 84	static bool dispatchRegion(const LLSLURL& slurl, const std::string& nav_type, bool right_mouse);
 85		// handles secondlife://Ahern/123/45/67/
 86		// Returns true if handled.
 87
 88	static void regionHandleCallback(U64 handle, const LLSLURL& slurl,
 89		const LLUUID& snapshot_id, bool teleport);
 90		// Called by LLWorldMap when a location has been resolved to a
 91	    // region name
 92
 93	static void regionNameCallback(U64 handle, const LLSLURL& slurl,
 94		const LLUUID& snapshot_id, bool teleport);
 95		// Called by LLWorldMap when a region name has been resolved to a
 96		// location in-world, used by places-panel display.
 97
 98	friend class LLTeleportHandler;
 99};
100
101// static
102bool LLURLDispatcherImpl::dispatchCore(const LLSLURL& slurl,
103									   const std::string& nav_type,
104									   bool right_mouse,
105									   LLMediaCtrl* web,
106									   bool trusted_browser)
107{
108	//if (dispatchHelp(slurl, right_mouse)) return true;
109	switch(slurl.getType())
110	{
111		case LLSLURL::APP: 
112			return dispatchApp(slurl, nav_type, right_mouse, web, trusted_browser);
113		case LLSLURL::LOCATION:
114			return dispatchRegion(slurl, nav_type, right_mouse);
115		default:
116			return false;
117	}
118
119	/*
120	// Inform the user we can't handle this
121	std::map<std::string, std::string> args;
122	args["SLURL"] = slurl;
123	r;
124	*/
125}
126
127// static
128bool LLURLDispatcherImpl::dispatch(const LLSLURL& slurl,
129								   const std::string& nav_type,
130								   LLMediaCtrl* web,
131								   bool trusted_browser)
132{
133	const bool right_click = false;
134	return dispatchCore(slurl, nav_type, right_click, web, trusted_browser);
135}
136
137// static
138bool LLURLDispatcherImpl::dispatchRightClick(const LLSLURL& slurl)
139{
140	const bool right_click = true;
141	LLMediaCtrl* web = NULL;
142	const bool trusted_browser = false;
143	return dispatchCore(slurl, "clicked", right_click, web, trusted_browser);
144}
145
146// static
147bool LLURLDispatcherImpl::dispatchApp(const LLSLURL& slurl, 
148									  const std::string& nav_type,
149									  bool right_mouse,
150									  LLMediaCtrl* web,
151									  bool trusted_browser)
152{
153	llinfos << "cmd: " << slurl.getAppCmd() << " path: " << slurl.getAppPath() << " query: " << slurl.getAppQuery() << llendl;
154	const LLSD& query_map = LLURI::queryMap(slurl.getAppQuery());
155	bool handled = LLCommandDispatcher::dispatch(
156			slurl.getAppCmd(), slurl.getAppPath(), query_map, web, nav_type, trusted_browser);
157
158	// alert if we didn't handle this secondlife:///app/ SLURL
159	// (but still return true because it is a valid app SLURL)
160	if (! handled)
161	{
162		LLNotificationsUtil::add("UnsupportedCommandSLURL");
163	}
164	return true;
165}
166
167// static
168bool LLURLDispatcherImpl::dispatchRegion(const LLSLURL& slurl, const std::string& nav_type, bool right_mouse)
169{
170	if(slurl.getType() != LLSLURL::LOCATION)
171    {
172		return false;
173    }
174	// Before we're logged in, need to update the startup screen
175	// to tell the user where they are going.
176	if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)
177	{
178		// We're at the login screen, so make sure user can see
179		// the login location box to know where they are going.
180		
181		LLPanelLogin::setLocation(slurl);
182		return true;
183	}
184
185	// Request a region handle by name
186	LLWorldMapMessage::getInstance()->sendNamedRegionRequest(slurl.getRegion(),
187									  LLURLDispatcherImpl::regionNameCallback,
188									  slurl.getSLURLString(),
189									  LLUI::sSettingGroups["config"]->getBOOL("SLURLTeleportDirectly"));	// don't teleport
190	return true;
191}
192
193/*static*/
194void LLURLDispatcherImpl::regionNameCallback(U64 region_handle, const LLSLURL& slurl, const LLUUID& snapshot_id, bool teleport)
195{
196      
197  if(slurl.getType() == LLSLURL::LOCATION)
198    {        
199      regionHandleCallback(region_handle, slurl, snapshot_id, teleport);
200    }
201}
202
203/* static */
204void LLURLDispatcherImpl::regionHandleCallback(U64 region_handle, const LLSLURL& slurl, const LLUUID& snapshot_id, bool teleport)
205{
206
207  // we can't teleport cross grid at this point
208	if((!LLGridManager::getInstance()->isSystemGrid(slurl.getGrid()) || !LLGridManager::getInstance()->isSystemGrid()) &&
209	   (slurl.getGrid() != LLGridManager::getInstance()->getGrid()))
210	{
211		LLSD args;
212		args["SLURL"] = slurl.getLocationString();
213		args["CURRENT_GRID"] = LLGridManager::getInstance()->getGridLabel();
214		LLSD grid_info;
215		LLGridManager::getInstance()->getGridInfo(slurl.getGrid(), grid_info);
216		
217		if(grid_info.has(GRID_LABEL_VALUE))
218		{
219			args["GRID"] = grid_info[GRID_LABEL_VALUE].asString();
220		}
221		else 
222		{
223			args["GRID"] = slurl.getGrid();
224		}
225		LLNotificationsUtil::add("CantTeleportToGrid", args);
226		return;
227	}
228	
229	LLVector3d global_pos = from_region_handle(region_handle);
230	global_pos += LLVector3d(slurl.getPosition());
231	
232	if (teleport)
233	{	
234		gAgent.teleportViaLocation(global_pos);
235		LLFloaterWorldMap* instance = LLFloaterWorldMap::getInstance();
236		if(instance)
237		{
238			instance->trackLocation(global_pos);
239		}
240	}
241	else
242	{
243		LLSD key;
244		key["type"] = "remote_place";
245		key["x"] = global_pos.mdV[VX];
246		key["y"] = global_pos.mdV[VY];
247		key["z"] = global_pos.mdV[VZ];
248
249		LLFloaterSidePanelContainer::showPanel("places", key);
250	}
251}
252
253//---------------------------------------------------------------------------
254// Teleportation links are handled here because they are tightly coupled
255// to SLURL parsing and sim-fragment parsing
256class LLTeleportHandler : public LLCommandHandler
257{
258public:
259	// Teleport requests *must* come from a trusted browser
260	// inside the app, otherwise a malicious web page could
261	// cause a constant teleport loop.  JC
262	LLTeleportHandler() : LLCommandHandler("teleport", UNTRUSTED_BLOCK) { }
263
264	bool handle(const LLSD& tokens, const LLSD& query_map,
265				LLMediaCtrl* web)
266	{
267		// construct a "normal" SLURL, resolve the region to
268		// a global position, and teleport to it
269		if (tokens.size() < 1) return false;
270
271		LLVector3 coords(128, 128, 0);
272		if (tokens.size() <= 4)
273		{
274			coords = LLVector3(tokens[1].asReal(), 
275							   tokens[2].asReal(), 
276							   tokens[3].asReal());
277		}
278		
279		// Region names may be %20 escaped.
280		
281		std::string region_name = LLURI::unescape(tokens[0]);
282
283		LLWorldMapMessage::getInstance()->sendNamedRegionRequest(region_name,
284			LLURLDispatcherImpl::regionHandleCallback,
285			LLSLURL(region_name, coords).getSLURLString(),
286			true);	// teleport
287		return true;
288	}
289};
290LLTeleportHandler gTeleportHandler;
291
292//---------------------------------------------------------------------------
293
294// static
295bool LLURLDispatcher::dispatch(const std::string& slurl,
296							   const std::string& nav_type,
297							   LLMediaCtrl* web,
298							   bool trusted_browser)
299{
300	return LLURLDispatcherImpl::dispatch(LLSLURL(slurl), nav_type, web, trusted_browser);
301}
302
303// static
304bool LLURLDispatcher::dispatchRightClick(const std::string& slurl)
305{
306	return LLURLDispatcherImpl::dispatchRightClick(LLSLURL(slurl));
307}
308
309// static
310bool LLURLDispatcher::dispatchFromTextEditor(const std::string& slurl)
311{
312	// *NOTE: Text editors are considered sources of trusted URLs
313	// in order to make avatar profile links in chat history work.
314	// While a malicious resident could chat an app SLURL, the
315	// receiving resident will see it and must affirmatively
316	// click on it.
317	// *TODO: Make this trust model more refined.  JC
318	const bool trusted_browser = true;
319	LLMediaCtrl* web = NULL;
320	return LLURLDispatcherImpl::dispatch(LLSLURL(slurl), "clicked", web, trusted_browser);
321}
322
323