gecko-dev/widget/ClipboardReadRequestParent.h
Edgar Chen 14d41cb7f9 Bug 1852947 - Redesign the async clipboard read API; r=nika
In bug 1755863, we introduce two async APIs in `nsIClipboard` to make async
clipboard API reads the clipboard data asynchronously. When reading, async
clipboard API first check the available types, and then retrieve the actual data
for that type. This process has a potential race condition: the clipboard content
might change between the time between the time we check the types and when we
retrieve the data. Although we currently fetch the actual data immediately after
checking available types (in line with the spec), this minimizes the chance of
encountering this race condition. However, if we would like to support retrieving
the data only when `getType()` is invoked (bug 1691825), this potential race
condition could become a significant issue.

Furthermore, bug 1777448 aims to have a way to track the clipboard data and suppress
the paste context menu when the clipboard data originates from a same-origin page.
This also requires a better way to track read requests, clipboard content and
invalidate the request when the system's clipboard content is changed.

After some refacting around nsBaseClipboard, all platform now use sequence
number to track clipboard content, so `nsIAsyncGetClipboardData` can be associated
with a sequence number and deemed invalid if the associated sequence number isn't
matched the latest system value.

With these new API, it also becomes possible to write some tests.

Depends on D191409

Differential Revision: https://phabricator.services.mozilla.com/D182108
2023-11-14 09:21:24 +00:00

40 lines
1.3 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_ClipboardReadRequestParent_h
#define mozilla_ClipboardReadRequestParent_h
#include "mozilla/dom/ContentParent.h"
#include "mozilla/PClipboardReadRequestParent.h"
#include "nsIClipboard.h"
namespace mozilla {
class ClipboardReadRequestParent final : public PClipboardReadRequestParent {
using IPCResult = mozilla::ipc::IPCResult;
using ContentParent = mozilla::dom::ContentParent;
public:
ClipboardReadRequestParent(ContentParent* aManager,
nsIAsyncGetClipboardData* aAsyncGetClipboardData)
: mManager(aManager), mAsyncGetClipboardData(aAsyncGetClipboardData) {}
NS_INLINE_DECL_REFCOUNTING(ClipboardReadRequestParent, override)
// PClipboardReadRequestParent
IPCResult RecvGetData(const nsTArray<nsCString>& aFlavors,
GetDataResolver&& aResolver);
private:
~ClipboardReadRequestParent() = default;
RefPtr<ContentParent> mManager;
nsCOMPtr<nsIAsyncGetClipboardData> mAsyncGetClipboardData;
};
} // namespace mozilla
#endif // mozilla_ClipboardReadRequestParent_h