tor-browser

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

Clipboard.h (2757B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_Clipboard_h_
      8 #define mozilla_dom_Clipboard_h_
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "mozilla/Logging.h"
     12 #include "nsString.h"
     13 #include "nsStringFwd.h"
     14 
     15 class nsIClipboardDataSnapshot;
     16 
     17 namespace mozilla::dom {
     18 
     19 class Promise;
     20 class ClipboardItem;
     21 
     22 // https://www.w3.org/TR/clipboard-apis/#clipboard-interface
     23 class Clipboard : public DOMEventTargetHelper {
     24 public:
     25  NS_DECL_ISUPPORTS_INHERITED
     26  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Clipboard, DOMEventTargetHelper)
     27 
     28  IMPL_EVENT_HANDLER(message)
     29  IMPL_EVENT_HANDLER(messageerror)
     30 
     31  explicit Clipboard(nsPIDOMWindowInner* aWindow);
     32  already_AddRefed<Promise> Read(nsIPrincipal& aSubjectPrincipal,
     33                                 ErrorResult& aRv);
     34  already_AddRefed<Promise> ReadText(nsIPrincipal& aSubjectPrincipal,
     35                                     ErrorResult& aRv);
     36  already_AddRefed<Promise> Write(
     37      const Sequence<OwningNonNull<ClipboardItem>>& aData,
     38      nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
     39  already_AddRefed<Promise> WriteText(const nsAString& aData,
     40                                      nsIPrincipal& aSubjectPrincipal,
     41                                      ErrorResult& aRv);
     42 
     43  static LogModule* GetClipboardLog();
     44 
     45  static Span<const nsLiteralCString> MandatoryDataTypes();
     46 
     47  virtual JSObject* WrapObject(JSContext* aCx,
     48                               JS::Handle<JSObject*> aGivenProto) override;
     49 
     50 private:
     51  enum class ReadRequestType {
     52    eRead,
     53    eReadText,
     54  };
     55 
     56  // Checks if dom.events.testing.asyncClipboard pref is enabled.
     57  // The aforementioned pref allows automated tests to bypass the security
     58  // checks when writing to
     59  //  or reading from the clipboard.
     60  static bool IsTestingPrefEnabled();
     61 
     62  static bool IsTestingPrefEnabledOrHasReadPermission(
     63      nsIPrincipal& aSubjectPrincipal);
     64 
     65  already_AddRefed<Promise> ReadHelper(nsIPrincipal& aSubjectPrincipal,
     66                                       ReadRequestType aType, ErrorResult& aRv);
     67 
     68  ~Clipboard();
     69 
     70  void RequestRead(Promise* aPromise, ReadRequestType aType,
     71                   nsPIDOMWindowInner* aOwner, nsIPrincipal& aPrincipal);
     72 
     73  void RequestRead(Promise& aPromise, const ReadRequestType& aType,
     74                   nsPIDOMWindowInner& aOwner, nsIPrincipal& aSubjectPrincipal,
     75                   nsIClipboardDataSnapshot& aRequest);
     76 };
     77 
     78 }  // namespace mozilla::dom
     79 #endif  // mozilla_dom_Clipboard_h_