File: test_selection_device_manager.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (187 lines) | stat: -rw-r--r-- 6,152 bytes parent folder | download | duplicates (6)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2021 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_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_

#include <cstdint>
#include <memory>
#include <string>
#include <vector>

#include "base/files/scoped_file.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/threading/thread.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
#include "ui/ozone/public/platform_clipboard.h"

namespace base {
class SequencedTaskRunner;
}

namespace wl {

class TestSelectionSource;
class TestSelectionDevice;

// Base classes for data device implementations. Protocol specific derived
// classes must bind request handlers and factory methods for data device and
// source instances. E.g: Standard data device (wl_data_*), as well as zwp and
// gtk primary selection protocols.

class TestSelectionDeviceManager : public GlobalObject {
 public:
  struct Delegate {
    virtual ~Delegate() = default;

    virtual TestSelectionDevice* CreateDevice(wl_client* client,
                                              uint32_t id) = 0;
    virtual TestSelectionSource* CreateSource(wl_client* client,
                                              uint32_t id) = 0;
  };

  struct InterfaceInfo {
    raw_ptr<const struct wl_interface> interface;
    raw_ptr<const void> implementation;
    uint32_t version;
  };

  TestSelectionDeviceManager(const InterfaceInfo& info,
                             std::unique_ptr<Delegate> delegate);
  ~TestSelectionDeviceManager() override;

  TestSelectionDeviceManager(const TestSelectionDeviceManager&) = delete;
  TestSelectionDeviceManager& operator=(const TestSelectionDeviceManager&) =
      delete;

  TestSelectionDevice* device() { return device_; }
  TestSelectionSource* source() { return source_; }

  void set_source(TestSelectionSource* source) { source_ = source; }

  // Protocol object requests:
  static void CreateSource(wl_client* client,
                           wl_resource* manager_resource,
                           uint32_t id);
  static void GetDevice(wl_client* client,
                        wl_resource* manager_resource,
                        uint32_t id,
                        wl_resource* seat_resource);

 private:
  const std::unique_ptr<Delegate> delegate_;
  raw_ptr<TestSelectionDevice, DanglingUntriaged> device_ = nullptr;
  raw_ptr<TestSelectionSource, DanglingUntriaged> source_ = nullptr;
};

class TestSelectionOffer : public ServerObject {
 public:
  struct Delegate {
    virtual ~Delegate() = default;

    virtual void SendOffer(const std::string& mime_type) = 0;
  };

  TestSelectionOffer(wl_resource* resource, std::unique_ptr<Delegate> delegate);
  ~TestSelectionOffer() override;

  TestSelectionOffer(const TestSelectionOffer&) = delete;
  TestSelectionOffer& operator=(const TestSelectionOffer&) = delete;

  void OnOffer(const std::string& mime_type, ui::PlatformClipboard::Data data);

  // Protocol object requests:
  static void Receive(wl_client* client,
                      wl_resource* resource,
                      const char* mime_type,
                      int fd);

 private:
  const std::unique_ptr<Delegate> delegate_;
  const scoped_refptr<base::SequencedTaskRunner> task_runner_;
  ui::PlatformClipboard::DataMap data_to_offer_;
};

class TestSelectionSource : public ServerObject {
 public:
  struct Delegate {
    virtual ~Delegate() = default;

    virtual void SendSend(const std::string& mime_type,
                          base::ScopedFD write_fd) = 0;
    virtual void SendFinished() = 0;
    virtual void SendCancelled() = 0;
    virtual void SendDndAction(uint32_t action) = 0;
    virtual void SendDndDropPerformed() = 0;
  };

  TestSelectionSource(wl_resource* resource,
                      std::unique_ptr<Delegate> delegate);
  ~TestSelectionSource() override;

  using ReadDataCallback = base::OnceCallback<void(std::vector<uint8_t>&&)>;
  void ReadData(const std::string& mime_type, ReadDataCallback callback);

  void OnFinished();
  void OnCancelled();
  void OnDndAction(uint32_t action);
  void OnDndDropPerformed();

  const std::vector<std::string>& mime_types() const { return mime_types_; }

  // Protocol object requests:
  static void Offer(struct wl_client* client,
                    struct wl_resource* resource,
                    const char* mime_type);

 private:
  const std::unique_ptr<Delegate> delegate_;

  std::vector<std::string> mime_types_;
  const scoped_refptr<base::SequencedTaskRunner> task_runner_;
};

class TestSelectionDevice : public ServerObject {
 public:
  struct Delegate {
    virtual ~Delegate() = default;

    virtual TestSelectionOffer* CreateAndSendOffer() = 0;
    virtual void SendSelection(TestSelectionOffer* offer) = 0;
    virtual void HandleSetSelection(TestSelectionSource* source,
                                    uint32_t serial) = 0;
  };

  TestSelectionDevice(wl_resource* resource,
                      std::unique_ptr<Delegate> delegate);
  ~TestSelectionDevice() override;

  TestSelectionDevice(const TestSelectionDevice&) = delete;
  TestSelectionDevice& operator=(const TestSelectionDevice&) = delete;

  TestSelectionOffer* OnDataOffer();
  void OnSelection(TestSelectionOffer* offer);

  void set_manager(TestSelectionDeviceManager* manager) { manager_ = manager; }

  // Protocol object requests:
  static void SetSelection(struct wl_client* client,
                           struct wl_resource* resource,
                           struct wl_resource* source,
                           uint32_t serial);

  uint32_t selection_serial() const { return selection_serial_; }

 private:
  const std::unique_ptr<Delegate> delegate_;
  uint32_t selection_serial_ = 0;
  raw_ptr<TestSelectionDeviceManager> manager_ = nullptr;
};

}  // namespace wl

#endif  // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SELECTION_DEVICE_MANAGER_H_