/indra/newview/llcommandhandler.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 108 lines · 31 code · 10 blank · 67 comment · 0 complexity · 1c4e8e7f7879098edeea211c6391c22a MD5 · raw file

  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=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #ifndef LLCOMMANDHANDLER_H
  29. #define LLCOMMANDHANDLER_H
  30. #include "llsd.h"
  31. /* Example: secondlife:///app/foo/<uuid>
  32. Command "foo" that takes one parameter, a UUID.
  33. class LLFooHandler : public LLCommandHandler
  34. {
  35. public:
  36. // Inform the system you handle commands starting
  37. // with "foo" and they are only allowed from
  38. // "trusted" (pointed at Linden content) browsers
  39. LLFooHandler() : LLCommandHandler("foo", UNTRUSTED_BLOCK) { }
  40. // Your code here
  41. bool handle(const LLSD& tokens, const LLSD& query_map,
  42. LLMediaCtrl* web)
  43. {
  44. if (tokens.size() < 1) return false;
  45. LLUUID id( tokens[0] );
  46. return do_foo(id);
  47. }
  48. };
  49. // *NOTE: Creating the object registers with the dispatcher.
  50. LLFooHandler gFooHandler;
  51. */
  52. class LLMediaCtrl;
  53. class LLCommandHandler
  54. {
  55. public:
  56. enum EUntrustedAccess
  57. {
  58. UNTRUSTED_ALLOW, // allow commands from untrusted browsers
  59. UNTRUSTED_BLOCK, // ignore commands from untrusted browsers
  60. UNTRUSTED_THROTTLE // allow untrusted, but only a few per min.
  61. };
  62. LLCommandHandler(const char* command, EUntrustedAccess untrusted_access);
  63. // Automatically registers object to get called when
  64. // command is executed. All commands can be processed
  65. // in links from LLMediaCtrl, but some (like teleport)
  66. // should not be allowed from outside the app.
  67. virtual ~LLCommandHandler();
  68. virtual bool handle(const LLSD& params,
  69. const LLSD& query_map,
  70. LLMediaCtrl* web) = 0;
  71. // For URL secondlife:///app/foo/bar/baz?cat=1&dog=2
  72. // @params - array of "bar", "baz", possibly empty
  73. // @query_map - map of "cat" -> 1, "dog" -> 2, possibly empty
  74. // @web - pointer to web browser control, possibly NULL
  75. // Return true if you did something, false if the parameters
  76. // are invalid or on error.
  77. };
  78. class LLCommandDispatcher
  79. {
  80. public:
  81. static bool dispatch(const std::string& cmd,
  82. const LLSD& params,
  83. const LLSD& query_map,
  84. LLMediaCtrl* web,
  85. const std::string& nav_type,
  86. bool trusted_browser);
  87. // Execute a command registered via the above mechanism,
  88. // passing string parameters.
  89. // Returns true if command was found and executed correctly.
  90. /// Return an LLSD::Map of registered LLCommandHandlers and associated
  91. /// info (e.g. EUntrustedAccess).
  92. static LLSD enumerate();
  93. };
  94. #endif