Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Aya ElAttar | 281086a | 2020-10-29 12:09:22 | [diff] [blame] | 5 | #ifndef UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_ |
| 6 | #define UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_ |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 7 | |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 8 | #include <optional> |
| 9 | |
Alvin Lee | 79ffe46 | 2022-01-17 10:12:50 | [diff] [blame] | 10 | #include "build/build_config.h" |
Aya ElAttar | 30cdfae | 2022-02-24 19:44:43 | [diff] [blame] | 11 | #include "url/gurl.h" |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 12 | |
| 13 | namespace 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. |
| 18 | enum class EndpointType { |
| 19 | kDefault = 0, // This type shouldn't be used if any of the following types is |
| 20 | // a better match. |
Aya ElAttar | 687eabe | 2020-12-11 08:58:37 | [diff] [blame] | 21 | kUrl = 1, // Website URL e.g. www.example.com. |
| 22 | kClipboardHistory = 2, // Clipboard History UI has privileged access to any |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 23 | // clipboard data. |
Xiaohan Wang | 8407409 | 2022-01-20 21:25:54 | [diff] [blame] | 24 | #if BUILDFLAG(IS_CHROMEOS) |
Aya ElAttar | 687eabe | 2020-12-11 08:58:37 | [diff] [blame] | 25 | kUnknownVm = 3, // The VM type is not identified. |
| 26 | kArc = 4, // ARC. |
| 27 | kBorealis = 5, // Borealis OS. |
| 28 | kCrostini = 6, // Crostini. |
Alvin Lee | 92005266 | 2022-01-15 12:04:27 | [diff] [blame] | 29 | kPluginVm = 7, // Plugin VM App. |
| 30 | kLacros = 8, // Lacros browser. |
Xiaohan Wang | 8407409 | 2022-01-20 21:25:54 | [diff] [blame] | 31 | #endif // BUILDFLAG(IS_CHROMEOS) |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 32 | }; |
| 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 ElAttar | 281086a | 2020-10-29 12:09:22 | [diff] [blame] | 43 | class COMPONENT_EXPORT(UI_BASE_DATA_TRANSFER_POLICY) DataTransferEndpoint { |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 44 | public: |
Aya ElAttar | e4df6e6 | 2021-12-08 22:12:20 | [diff] [blame] | 45 | // In case DataTransferEndpoint is constructed from a RenderFrameHost object, |
Aya ElAttar | 30cdfae | 2022-02-24 19:44:43 | [diff] [blame] | 46 | // please use the url of its main frame. |
| 47 | explicit DataTransferEndpoint(const GURL& url, |
Dominique Fauteux-Chapleau | 2cdc6a9 | 2024-01-29 17:39:37 | [diff] [blame] | 48 | bool off_the_record = false, |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 49 | 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 ElAttar | 2e554e5 | 2021-01-11 13:03:43 | [diff] [blame] | 57 | DataTransferEndpoint& operator=(const DataTransferEndpoint& other); |
| 58 | DataTransferEndpoint& operator=(DataTransferEndpoint&& other); |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 59 | |
| 60 | bool operator==(const DataTransferEndpoint& other) const; |
Joel Hockey | c0acc8e | 2021-02-03 01:27:45 | [diff] [blame] | 61 | bool operator!=(const DataTransferEndpoint& other) const { |
| 62 | return !(*this == other); |
| 63 | } |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 64 | |
| 65 | ~DataTransferEndpoint(); |
| 66 | |
| 67 | bool IsUrlType() const { return type_ == EndpointType::kUrl; } |
| 68 | |
Aya ElAttar | 30cdfae | 2022-02-24 19:44:43 | [diff] [blame] | 69 | const GURL* GetURL() const; |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 70 | |
| 71 | EndpointType type() const { return type_; } |
| 72 | |
Dominique Fauteux-Chapleau | 2cdc6a9 | 2024-01-29 17:39:37 | [diff] [blame] | 73 | bool off_the_record() const { return off_the_record_; } |
| 74 | |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 75 | bool notify_if_restricted() const { return notify_if_restricted_; } |
| 76 | |
Luca Accorsi | a0007c8 | 2022-07-29 07:17:05 | [diff] [blame] | 77 | // Returns true if both of the endpoints have the same url_ and type_ == |
Aya ElAttar | 4ef6ba2 | 2021-02-02 10:52:27 | [diff] [blame] | 78 | // kUrl. |
Aya ElAttar | 30cdfae | 2022-02-24 19:44:43 | [diff] [blame] | 79 | bool IsSameURLWith(const DataTransferEndpoint& other) const; |
Aya ElAttar | 4ef6ba2 | 2021-02-02 10:52:27 | [diff] [blame] | 80 | |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 81 | private: |
| 82 | // This variable should always have a value representing the object type. |
Aya ElAttar | 2e554e5 | 2021-01-11 13:03:43 | [diff] [blame] | 83 | EndpointType type_; |
Dominique Fauteux-Chapleau | 2cdc6a9 | 2024-01-29 17:39:37 | [diff] [blame] | 84 | |
Aya ElAttar | 30cdfae | 2022-02-24 19:44:43 | [diff] [blame] | 85 | // The URL of the data endpoint. It always has a value if `type_` == |
Aya ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 86 | // EndpointType::kUrl, otherwise it's empty. |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 87 | std::optional<GURL> url_; |
Dominique Fauteux-Chapleau | 2cdc6a9 | 2024-01-29 17:39:37 | [diff] [blame] | 88 | |
| 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 ElAttar | 5e8cfb08 | 2020-10-28 14:33:18 | [diff] [blame] | 93 | // 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 ElAttar | 281086a | 2020-10-29 12:09:22 | [diff] [blame] | 102 | #endif // UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_ |