File: platform_clipboard.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (95 lines) | stat: -rw-r--r-- 4,283 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_OZONE_PUBLIC_PLATFORM_CLIPBOARD_H_
#define UI_OZONE_PUBLIC_PLATFORM_CLIPBOARD_H_

#include <string>
#include <unordered_map>
#include <vector>

#include "base/component_export.h"
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted_memory.h"
#include "ui/base/clipboard/clipboard_buffer.h"

namespace ui {

// Allows Chrome controls and windows to exchange data with each other and other
// applications, e.g., to copy and paste.
//
// In environments that have multiple clipboards (like Linux X11 or OS X, see
// ui::ClipboardBuffer), the implementation should provide a separate data
// buffer for each system clipboard.  When data is requested or offered, the
// caller specifies which buffer to use by providing the |buffer| parameter.
class COMPONENT_EXPORT(OZONE_BASE) PlatformClipboard {
 public:
  virtual ~PlatformClipboard() {}

  // DataMap is a map from "mime type" to associated data, whereas
  // the data can be organized differently for each mime type.
  using Data = scoped_refptr<base::RefCountedBytes>;
  using DataMap = std::unordered_map<std::string, Data>;

  // Offers a given clipboard data 'data_map' to the host system clipboard.
  //
  // It is common that host clipboard implementations simply get offered
  // the set of mime types available for the data being shared. In such cases,
  // the actual clipboard data is only 'transferred' to the consuming
  // application asynchronously, upon an explicit request for data given a
  // specific mime type. This is the case of Wayland compositors and MacOS
  // (NSPasteboard), for example.
  //
  // The invoker assumes the Ozone implementation will not free |DataMap|
  // before |OfferDataClosure| is called.
  //
  // OfferDataClosure should be invoked when the host clipboard implementation
  // acknowledges that the "offer to clipboard" operation is performed.
  using OfferDataClosure = base::OnceCallback<void()>;
  virtual void OfferClipboardData(ClipboardBuffer buffer,
                                  const DataMap& data_map,
                                  OfferDataClosure callback) = 0;

  // Reads data from host system clipboard given mime type. The resulting data
  // is returned asynchronously through |callback|, whereas nullptr is returned
  // if the request fails for some reason (i.e: no data available, etc).
  using RequestDataClosure = base::OnceCallback<void(const Data& result)>;
  virtual void RequestClipboardData(ClipboardBuffer buffer,
                                    const std::string& mime_type,
                                    RequestDataClosure callback) = 0;

  // Gets the mime types of the data available for clipboard operations
  // in the host system clipboard.
  //
  // GetMimeTypesClosure is invoked when the mime types available for clipboard
  // operations are known.
  using GetMimeTypesClosure =
      base::OnceCallback<void(const std::vector<std::string>&)>;
  virtual void GetAvailableMimeTypes(ClipboardBuffer buffer,
                                     GetMimeTypesClosure callback) = 0;

  // Returns true if the current application writing data to the host clipboard
  // data is this one; false otherwise.
  //
  // It can be relevant to know this information in case the client wants to
  // caches the clipboard data, and wants to know if it is possible to use
  // the cached data in order to reply faster to read-clipboard operations.
  virtual bool IsSelectionOwner(ClipboardBuffer buffer) = 0;

  // ClipboardDataChangedCallback is used to notify the PlatformClipboard client
  // that the clipboard content for a given |buffer| has changed, so that it can
  // take the necessary actions, e.g: to update clipboard's sequence number,
  // notify observers, etc.
  using ClipboardDataChangedCallback =
      base::RepeatingCallback<void(ClipboardBuffer buffer)>;
  virtual void SetClipboardDataChangedCallback(
      ClipboardDataChangedCallback callback) = 0;

  // Returns whether the kSelection buffer is available.
  virtual bool IsSelectionBufferAvailable() const = 0;
};

}  // namespace ui

#endif  // UI_OZONE_PUBLIC_PLATFORM_CLIPBOARD_H_