// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CLIPBOARD_CLIPBOARD_WRITER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_CLIPBOARD_CLIPBOARD_WRITER_H_ #include "base/sequence_checker.h" #include "base/task/single_thread_task_runner.h" #include "third_party/blink/renderer/core/fileapi/blob.h" #include "third_party/blink/renderer/core/fileapi/file_reader_client.h" #include "third_party/blink/renderer/modules/clipboard/clipboard_promise.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h" #include "third_party/blink/renderer/platform/heap/self_keep_alive.h" #include "third_party/skia/include/core/SkImage.h" namespace blink { class FileReaderLoader; class SystemClipboard; // Interface for writing an individual Clipboard API format as a Blob to the // System Clipboard, safely and asynchronously. // // ClipboardWriter takes as input a ClipboardPromise, which manages writing // multiple formats and passes in unsanitized clipboard payloads. // ClipboardWriter then sanitizes a Blob payload and writes it onto the // underlying system clipboard. All System Clipboard operations should be // called from the main thread. // // Writing a Blob's data to the system clipboard is accomplished by: // (1) Reading - the Blob's contents using a FileReaderLoader. // (2) Decoding - or sanitizing the Blob's contents to avoid RCE in native // applications that may take advantage of vulnerabilities in their // decoders, whenever possible. Decoding may be time-consuming, so it // is done on a background thread whenever possible. An example where // decoding is done on the main thread is HTML, where Blink's HTML decoder // can only be used on the main thread. // (3) Writing - the Blob's decoded contents to the system clipboard. // // Subclasses of ClipboardWriter should be implemented for each supported // format. Subclasses should: // (1) Begin execution by implementing ClipboardWriter::StartWrite(). // (2) Decode the payload on a background thread (if possible) by implementing // a static DecodeOnBackgroundThread() function. This function is called by // StartWrite() via worker_pool::PostTask(). // (3) Write the decoded content to the system clipboard by implementing // ClipboardWriter::Write(); // // ClipboardWriter is owned only by itself and ClipboardPromise. It keeps // itself alive for the duration of FileReaderLoader's async operations using // SelfKeepAlive, and keeps itself alive afterwards during cross-thread // operations by using WrapCrossThreadPersistent. class ClipboardWriter : public GarbageCollected<ClipboardWriter>, public FileReaderAccumulator { … }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CLIPBOARD_CLIPBOARD_WRITER_H_