tor-browser

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

LNAPermissionRequest.h (1770B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef LNAPermissionRequest_h__
      8 #define LNAPermissionRequest_h__
      9 #include "nsContentPermissionHelper.h"
     10 #include "nsISupports.h"
     11 #include "nsPIDOMWindow.h"
     12 
     13 namespace mozilla::net {
     14 static constexpr nsLiteralCString LOCAL_HOST_PERMISSION_KEY = "localhost"_ns;
     15 static constexpr nsLiteralCString LOCAL_NETWORK_PERMISSION_KEY =
     16    "local-network"_ns;
     17 
     18 using PermissionPromptCallback =
     19    std::function<void(bool granted, const nsACString& type, bool promptShown)>;
     20 
     21 /**
     22 * Handles permission dialog management for local network accesses
     23 */
     24 class LNAPermissionRequest final : public dom::ContentPermissionRequestBase {
     25 public:
     26  LNAPermissionRequest(PermissionPromptCallback&& aCallback,
     27                       nsILoadInfo* aLoadInfo, const nsACString& aType);
     28 
     29  NS_DECL_ISUPPORTS_INHERITED
     30  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LNAPermissionRequest,
     31                                           ContentPermissionRequestBase)
     32 
     33  // nsIContentPermissionRequest
     34  NS_IMETHOD
     35  Cancel(void) override;
     36  NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
     37  NS_IMETHOD NotifyShown(void) override;
     38  NS_IMETHOD GetElement(mozilla::dom::Element** aElement) override;
     39 
     40  nsresult RequestPermission();
     41 
     42 private:
     43  ~LNAPermissionRequest() = default;
     44  nsCOMPtr<nsILoadInfo> mLoadInfo;
     45  PermissionPromptCallback mPermissionPromptCallback;
     46  bool mPromptWasShown = false;
     47 };
     48 
     49 }  // namespace mozilla::net
     50 
     51 #endif  // LNAPermissionRequest_h