tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ControllerCommand.h (3133B)


      1 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_ControllerCommand_h_
      7 #define mozilla_ControllerCommand_h_
      8 
      9 #include "mozilla/Attributes.h"
     10 #include "nsISupportsImpl.h"
     11 #include "nsStringFwd.h"
     12 class nsISupports;
     13 class nsICommandParams;
     14 
     15 namespace mozilla {
     16 
     17 class ControllerCommand {
     18  NS_INLINE_DECL_REFCOUNTING(ControllerCommand);
     19 
     20  /**
     21   * Returns true if the command is currently enabled. An nsIControllerCommand
     22   * can implement more than one commands; say, a group of related commands
     23   * (e.g. delete left/delete right). Because of this, the command name is
     24   * passed to each method.
     25   *
     26   * @param aCommandName  the name of the command for which we want the enabled
     27   *                      state.
     28   * @param aCommandContext    a cookie held by the nsIControllerCommandTable,
     29   *                  allowing the command to get some context information.
     30   *                  The contents of this cookie are implementation-defined.
     31   */
     32  virtual bool IsCommandEnabled(const nsACString& aCommandName,
     33                                nsISupports* aCommandContext) = 0;
     34  virtual void GetCommandStateParams(const nsACString& aCommandName,
     35                                     nsICommandParams*,
     36                                     nsISupports* aCommandContext) = 0;
     37 
     38  /**
     39   * Execute the name command.
     40   *
     41   * @param aCommandName  the name of the command to execute.
     42   *
     43   * @param aCommandParams the command parameters or null.
     44   * @param aCommandContext    a cookie held by the nsIControllerCommandTable,
     45   *                  allowing the command to get some context information.
     46   *                  The contents of this cookie are implementation-defined.
     47   */
     48  MOZ_CAN_RUN_SCRIPT
     49  virtual nsresult DoCommand(const nsACString& aCommandName,
     50                             nsICommandParams* aParams,
     51                             nsISupports* aCommandContext) = 0;
     52 
     53 protected:
     54  virtual ~ControllerCommand() = default;
     55 };
     56 
     57 #define DECL_CONTROLLER_COMMAND                                          \
     58  bool IsCommandEnabled(const nsACString&, nsISupports*) override;       \
     59  void GetCommandStateParams(const nsACString&, nsICommandParams*,       \
     60                             nsISupports*) override;                     \
     61  MOZ_CAN_RUN_SCRIPT                                                     \
     62  nsresult DoCommand(const nsACString&, nsICommandParams*, nsISupports*) \
     63      override;
     64 
     65 #define DECL_CONTROLLER_COMMAND_NO_PARAMS                                \
     66  bool IsCommandEnabled(const nsACString&, nsISupports*) override;       \
     67  void GetCommandStateParams(const nsACString&, nsICommandParams*,       \
     68                             nsISupports*) override {}                   \
     69  MOZ_CAN_RUN_SCRIPT                                                     \
     70  nsresult DoCommand(const nsACString&, nsICommandParams*, nsISupports*) \
     71      override;
     72 
     73 }  // namespace mozilla
     74 
     75 #endif