Bug 1769952 - Fix running raptor on a Win10-64 VM r=sparky
[gecko.git] / dom / events / Clipboard.h
blobd0c63a6644723887d0e5d9f4e264ea0611348e21
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/. */
7 #ifndef mozilla_dom_Clipboard_h_
8 #define mozilla_dom_Clipboard_h_
10 #include "nsString.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/Logging.h"
13 #include "mozilla/dom/DataTransfer.h"
15 namespace mozilla::dom {
17 enum ClipboardReadType {
18 eRead,
19 eReadText,
22 class Promise;
23 class ClipboardItem;
25 // https://www.w3.org/TR/clipboard-apis/#clipboard-interface
26 class Clipboard : public DOMEventTargetHelper {
27 public:
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Clipboard, DOMEventTargetHelper)
31 IMPL_EVENT_HANDLER(message)
32 IMPL_EVENT_HANDLER(messageerror)
34 explicit Clipboard(nsPIDOMWindowInner* aWindow);
35 already_AddRefed<Promise> Read(nsIPrincipal& aSubjectPrincipal,
36 ErrorResult& aRv);
37 already_AddRefed<Promise> ReadText(nsIPrincipal& aSubjectPrincipal,
38 ErrorResult& aRv);
39 already_AddRefed<Promise> Write(
40 const Sequence<OwningNonNull<ClipboardItem>>& aData,
41 nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
42 already_AddRefed<Promise> WriteText(const nsAString& aData,
43 nsIPrincipal& aSubjectPrincipal,
44 ErrorResult& aRv);
46 static LogModule* GetClipboardLog();
48 // Check if the Clipboard.readText API should be enabled for this context.
49 // This API is only enabled for Extension and System contexts, as there is no
50 // way to request the required permission for web content. If the clipboard
51 // API testing pref is enabled, ReadText is enabled for web content for
52 // testing purposes.
53 static bool ReadTextEnabled(JSContext* aCx, JSObject* aGlobal);
55 virtual JSObject* WrapObject(JSContext* aCx,
56 JS::Handle<JSObject*> aGivenProto) override;
58 private:
59 // Checks if dom.events.testing.asyncClipboard pref is enabled.
60 // The aforementioned pref allows automated tests to bypass the security
61 // checks when writing to
62 // or reading from the clipboard.
63 static bool IsTestingPrefEnabled();
65 already_AddRefed<Promise> ReadHelper(nsIPrincipal& aSubjectPrincipal,
66 ClipboardReadType aClipboardReadType,
67 ErrorResult& aRv);
69 // If necessary, fill the data transfer with data from the clipboard and
70 // resolve a promise with the appropriate object based on aClipboardReadType
71 static void ProcessDataTransfer(DataTransfer& aDataTransfer,
72 Promise& aPromise,
73 ClipboardReadType aClipboardReadType,
74 nsPIDOMWindowInner& aOwner,
75 nsIPrincipal& aSubjectPrincipal,
76 bool aNeedToFill);
78 ~Clipboard();
81 } // namespace mozilla::dom
82 #endif // mozilla_dom_Clipboard_h_