summaryrefslogtreecommitdiff
path: root/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.cc
blob: 3d8c18e69e33a2fecb5c76e10ef4a9f52c39ed8b (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
// 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.

#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"

#include "base/check_op.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"

namespace ui {

DataTransferEndpoint::DataTransferEndpoint(const url::Origin& origin,
                                           bool notify_if_restricted)
    : type_(EndpointType::kUrl),
      origin_(origin),
      notify_if_restricted_(notify_if_restricted) {}

DataTransferEndpoint::DataTransferEndpoint(EndpointType type,
                                           bool notify_if_restricted)
    : type_(type),
      origin_(absl::nullopt),
      notify_if_restricted_(notify_if_restricted) {
  DCHECK_NE(type, EndpointType::kUrl);
}

DataTransferEndpoint::DataTransferEndpoint(const DataTransferEndpoint& other) =
    default;

DataTransferEndpoint::DataTransferEndpoint(DataTransferEndpoint&& other) =
    default;

DataTransferEndpoint& DataTransferEndpoint::operator=(
    const DataTransferEndpoint& other) = default;

DataTransferEndpoint& DataTransferEndpoint::operator=(
    DataTransferEndpoint&& other) = default;

bool DataTransferEndpoint::operator==(const DataTransferEndpoint& other) const {
  return origin_ == other.origin_ && type_ == other.type_ &&
         notify_if_restricted_ == other.notify_if_restricted_;
}

DataTransferEndpoint::~DataTransferEndpoint() = default;

bool DataTransferEndpoint::IsSameOriginWith(
    const DataTransferEndpoint& other) const {
  return IsUrlType() && (type_ == other.type_) && (origin_ == other.origin_);
}

}  // namespace ui