summaryrefslogtreecommitdiff
path: root/chromium/ui/base/clipboard/clipboard_data_endpoint.h
blob: 9e6f12dfd96cd628c521e160c14ec74d8b4ca23c (plain)
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_BASE_CLIPBOARD_CLIPBOARD_DATA_ENDPOINT_H_
#define UI_BASE_CLIPBOARD_CLIPBOARD_DATA_ENDPOINT_H_

#include "base/optional.h"
#include "base/stl_util.h"
#include "url/origin.h"

namespace ui {

// EndpointType can represent either the source of the clipboard data or the
// destination trying to read the clipboard data.
// Whenever a new format is supported, a new enum should be added.
enum class EndpointType {
#if defined(OS_CHROMEOS) || (OS_LINUX) || (OS_FUCHSIA)
  kGuestOs = 0,  // Guest OS: PluginVM, Crostini.
#endif           // defined(OS_CHROMEOS) || (OS_LINUX) || (OS_FUCHSIA)
#if defined(OS_CHROMEOS)
  kArc = 1,               // ARC.
#endif                    // defined(OS_CHROMEOS)
  kUrl = 2,               // Website URL e.g. www.example.com.
  kClipboardHistory = 3,  // Clipboard History UI has privileged access to any
                          // clipboard data.
  kMaxValue = kClipboardHistory
};

// ClipboardDataEndpoint can represent:
// - The source of the data in the clipboard.
// - The destination trying to access the clipboard data.
class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardDataEndpoint {
 public:
  explicit ClipboardDataEndpoint(const url::Origin& origin);
  // This constructor shouldn't be used if |type| == EndpointType::kUrl.
  explicit ClipboardDataEndpoint(EndpointType type);

  ClipboardDataEndpoint(const ClipboardDataEndpoint& other);
  ClipboardDataEndpoint(ClipboardDataEndpoint&& other);

  ClipboardDataEndpoint& operator=(const ClipboardDataEndpoint& other) = delete;
  ClipboardDataEndpoint& operator=(ClipboardDataEndpoint&& other) = delete;

  bool operator==(const ClipboardDataEndpoint& other) const;

  ~ClipboardDataEndpoint();

  bool IsUrlType() const { return type_ == EndpointType::kUrl; }

  const url::Origin* origin() const { return base::OptionalOrNullptr(origin_); }

  EndpointType type() const { return type_; }

 private:
  // This variable should always have a value representing the object type.
  const EndpointType type_;
  // The url::Origin of the data endpoint. It always has a value if |type_| ==
  // EndpointType::kUrl, otherwise it's empty.
  const base::Optional<url::Origin> origin_;
};

}  // namespace ui

#endif  // UI_BASE_CLIPBOARD_CLIPBOARD_DATA_ENDPOINT_H_