[go: nahoru, domu]

blob: 7e3af2088b82b5f6c03c66d0e247edd2f3d354af [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2020 The Chromium Authors
Aya ElAttar5e8cfb082020-10-28 14:33:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Aya ElAttar281086a2020-10-29 12:09:225#ifndef UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_
6#define UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_
Aya ElAttar5e8cfb082020-10-28 14:33:187
Arthur Sonzogni3eb9fd512024-02-09 12:20:438#include <optional>
9
Alvin Lee79ffe462022-01-17 10:12:5010#include "build/build_config.h"
Aya ElAttar30cdfae2022-02-24 19:44:4311#include "url/gurl.h"
Aya ElAttar5e8cfb082020-10-28 14:33:1812
13namespace ui {
14
15// EndpointType can represent either the source of the transferred data or the
16// destination trying to read the data.
17// Whenever a new format is supported, a new enum should be added.
18enum class EndpointType {
19 kDefault = 0, // This type shouldn't be used if any of the following types is
20 // a better match.
Aya ElAttar687eabe2020-12-11 08:58:3721 kUrl = 1, // Website URL e.g. www.example.com.
22 kClipboardHistory = 2, // Clipboard History UI has privileged access to any
Aya ElAttar5e8cfb082020-10-28 14:33:1823 // clipboard data.
Xiaohan Wang84074092022-01-20 21:25:5424#if BUILDFLAG(IS_CHROMEOS)
Aya ElAttar687eabe2020-12-11 08:58:3725 kUnknownVm = 3, // The VM type is not identified.
26 kArc = 4, // ARC.
27 kBorealis = 5, // Borealis OS.
28 kCrostini = 6, // Crostini.
Alvin Lee920052662022-01-15 12:04:2729 kPluginVm = 7, // Plugin VM App.
30 kLacros = 8, // Lacros browser.
Xiaohan Wang84074092022-01-20 21:25:5431#endif // BUILDFLAG(IS_CHROMEOS)
Aya ElAttar5e8cfb082020-10-28 14:33:1832};
33
34// DataTransferEndpoint represents:
35// - The source of the data being ransferred.
36// - The destination trying to access the data.
37// - Whether the user should see a notification if the data access is not
38// allowed.
39// Passing DataTransferEndpoint as a nullptr is equivalent to
40// DataTransferEndpoint(kDefault, true). Both specify the same types of
41// endpoints (not a URL/ARC++/...etc, and should show a notification to the user
42// if the data read is not allowed.)
Aya ElAttar281086a2020-10-29 12:09:2243class COMPONENT_EXPORT(UI_BASE_DATA_TRANSFER_POLICY) DataTransferEndpoint {
Aya ElAttar5e8cfb082020-10-28 14:33:1844 public:
Aya ElAttare4df6e62021-12-08 22:12:2045 // In case DataTransferEndpoint is constructed from a RenderFrameHost object,
Aya ElAttar30cdfae2022-02-24 19:44:4346 // please use the url of its main frame.
47 explicit DataTransferEndpoint(const GURL& url,
Dominique Fauteux-Chapleau2cdc6a92024-01-29 17:39:3748 bool off_the_record = false,
Aya ElAttar5e8cfb082020-10-28 14:33:1849 bool notify_if_restricted = true);
50 // This constructor shouldn't be used if |type| == EndpointType::kUrl.
51 explicit DataTransferEndpoint(EndpointType type,
52 bool notify_if_restricted = true);
53
54 DataTransferEndpoint(const DataTransferEndpoint& other);
55 DataTransferEndpoint(DataTransferEndpoint&& other);
56
Aya ElAttar2e554e52021-01-11 13:03:4357 DataTransferEndpoint& operator=(const DataTransferEndpoint& other);
58 DataTransferEndpoint& operator=(DataTransferEndpoint&& other);
Aya ElAttar5e8cfb082020-10-28 14:33:1859
60 bool operator==(const DataTransferEndpoint& other) const;
Joel Hockeyc0acc8e2021-02-03 01:27:4561 bool operator!=(const DataTransferEndpoint& other) const {
62 return !(*this == other);
63 }
Aya ElAttar5e8cfb082020-10-28 14:33:1864
65 ~DataTransferEndpoint();
66
67 bool IsUrlType() const { return type_ == EndpointType::kUrl; }
68
Aya ElAttar30cdfae2022-02-24 19:44:4369 const GURL* GetURL() const;
Aya ElAttar5e8cfb082020-10-28 14:33:1870
71 EndpointType type() const { return type_; }
72
Dominique Fauteux-Chapleau2cdc6a92024-01-29 17:39:3773 bool off_the_record() const { return off_the_record_; }
74
Aya ElAttar5e8cfb082020-10-28 14:33:1875 bool notify_if_restricted() const { return notify_if_restricted_; }
76
Luca Accorsia0007c82022-07-29 07:17:0577 // Returns true if both of the endpoints have the same url_ and type_ ==
Aya ElAttar4ef6ba22021-02-02 10:52:2778 // kUrl.
Aya ElAttar30cdfae2022-02-24 19:44:4379 bool IsSameURLWith(const DataTransferEndpoint& other) const;
Aya ElAttar4ef6ba22021-02-02 10:52:2780
Aya ElAttar5e8cfb082020-10-28 14:33:1881 private:
82 // This variable should always have a value representing the object type.
Aya ElAttar2e554e52021-01-11 13:03:4383 EndpointType type_;
Dominique Fauteux-Chapleau2cdc6a92024-01-29 17:39:3784
Aya ElAttar30cdfae2022-02-24 19:44:4385 // The URL of the data endpoint. It always has a value if `type_` ==
Aya ElAttar5e8cfb082020-10-28 14:33:1886 // EndpointType::kUrl, otherwise it's empty.
Arthur Sonzogni3eb9fd512024-02-09 12:20:4387 std::optional<GURL> url_;
Dominique Fauteux-Chapleau2cdc6a92024-01-29 17:39:3788
89 // Whether the endpoint corresponds to an OTR browser context. This should
90 // only be set to true for `EndpointType::kUrl` endpoints.
91 bool off_the_record_ = false;
92
Aya ElAttar5e8cfb082020-10-28 14:33:1893 // This variable should be set to true, if paste is initiated by the user.
94 // Otherwise it should be set to false, so the user won't see a notification
95 // when the data is restricted by the rules of data leak prevention policy
96 // and something in the background is trying to access it.
97 bool notify_if_restricted_ = true;
98};
99
100} // namespace ui
101
Aya ElAttar281086a2020-10-29 12:09:22102#endif // UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_