llcommandhandler.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * @file llcommandhandler.h
  3. * @brief Central registry for text-driven "commands", most of
  4. * which manipulate user interface. For example, the command
  5. * "agent (uuid) about" will open the UI for an avatar's profile.
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewergpl$
  8. *
  9. * Copyright (c) 2007-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. #ifndef LLCOMMANDHANDLER_H
  35. #define LLCOMMANDHANDLER_H
  36. /* Example: secondlife:///app/foo/<uuid>
  37. Command "foo" that takes one parameter, a UUID.
  38. class LLFooHandler : public LLCommandHandler
  39. {
  40. public:
  41. // Inform the system you handle commands starting with "foo" and they are
  42. // only allowed from "trusted" (pointed at Linden content) browsers
  43. LLFooHandler() : LLCommandHandler("foo", UNTRUSTED_BLOCK) {}
  44. // Your code here
  45. bool handle(const LLSD& tokens, const LLSD& query_map, LLMediaCtrl* web)
  46. {
  47. if (tokens.size() < 1) return false;
  48. LLUUID id( tokens[0] );
  49. return do_foo(id);
  50. }
  51. };
  52. // *NOTE: Creating the object registers with the dispatcher.
  53. LLFooHandler gFooHandler;
  54. */
  55. class LLMediaCtrl;
  56. class LLCommandHandler
  57. {
  58. public:
  59. enum EUntrustedAccess
  60. {
  61. UNTRUSTED_ALLOW, // Allow commands from untrusted browsers.
  62. UNTRUSTED_BLOCK, // Ignore commands from untrusted browsers.
  63. UNTRUSTED_CLICK_ONLY, // Allow untrusted, but only if link clicked.
  64. UNTRUSTED_THROTTLE // Allow untrusted, but only a few per min.
  65. };
  66. // Automatically registers object to get called when command is executed.
  67. // All commands can be processed in links from LLMediaCtrl, but some (like
  68. // teleport) should not be allowed from outside the app.
  69. LLCommandHandler(const char* command, EUntrustedAccess untrusted_access);
  70. virtual ~LLCommandHandler() = default;
  71. LL_INLINE virtual bool canHandleUntrusted(const LLSD& params,
  72. const LLSD& query_map,
  73. LLMediaCtrl* web,
  74. const std::string& nav_type)
  75. {
  76. return true;
  77. }
  78. // For URL secondlife:///app/foo/bar/baz?cat=1&dog=2
  79. // @params - array of "bar", "baz", possibly empty
  80. // @query_map - map of "cat" -> 1, "dog" -> 2, possibly empty
  81. // @web - pointer to web browser control, possibly NULL
  82. // Return true if you did something, false if the parameters are invalid or
  83. // on error.
  84. virtual bool handle(const LLSD& params, const LLSD& query_map,
  85. LLMediaCtrl* web) = 0;
  86. static void dump();
  87. // Executes a command registered via the above mechanism, passing string
  88. // parameters. Returns true if command was found and executed correctly.
  89. static bool dispatch(const std::string& cmd, const LLSD& params,
  90. const LLSD& query_map, LLMediaCtrl* web,
  91. const std::string& nav_type, bool trusted_browser);
  92. };
  93. #endif