Commit db0cf440 authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

Change ClipboardDataEndpoint to support virtual machines

Changed ClipboardDataEndpoint to support virtual machines,
like Crostini, PluginVM, ARC++ as potential sources
or destinations of the clipboard data.

Bug: 1103217
Change-Id: I3ff721a8fbc685adfb5779b1edb579da4062ff24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315030
Commit-Queue: Aya Elsayed <ayaelattar@google.com>
Reviewed-by: default avatarDarwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791647}
parent 4e3835aa
......@@ -4,11 +4,19 @@
#include "ui/base/clipboard/clipboard_data_endpoint.h"
#include "base/check_op.h"
#include "base/optional.h"
#include "url/origin.h"
namespace ui {
ClipboardDataEndpoint::ClipboardDataEndpoint(const GURL& url) : url_(url) {}
ClipboardDataEndpoint::ClipboardDataEndpoint(const GURL& url)
: type_(EndpointType::kUrl), url_(url) {}
ClipboardDataEndpoint::ClipboardDataEndpoint(EndpointType type)
: type_(type), url_(base::nullopt) {
DCHECK_NE(type, EndpointType::kUrl);
}
ClipboardDataEndpoint::ClipboardDataEndpoint(
const ClipboardDataEndpoint& other) = default;
......@@ -16,15 +24,9 @@ ClipboardDataEndpoint::ClipboardDataEndpoint(
ClipboardDataEndpoint::ClipboardDataEndpoint(ClipboardDataEndpoint&& other) =
default;
ClipboardDataEndpoint& ClipboardDataEndpoint::operator=(
const ClipboardDataEndpoint& other) = default;
ClipboardDataEndpoint& ClipboardDataEndpoint::operator=(
ClipboardDataEndpoint&& other) = default;
bool ClipboardDataEndpoint::operator==(
const ClipboardDataEndpoint& other) const {
return url_ == other.url_;
return url_ == other.url_ && type_ == other.type_;
}
ClipboardDataEndpoint::~ClipboardDataEndpoint() = default;
......
......@@ -5,31 +5,52 @@
#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/gurl.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 {
kUrl = 0, // Website URL e.g. www.example.com
kVm = 1, // Virtual machine: ARC++, PluginVM, Crostini.
kMaxValue = kVm
};
// 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 GURL& url);
// 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);
ClipboardDataEndpoint& operator=(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 GURL* url() const { return base::OptionalOrNullptr(url_); }
EndpointType type() const { return type_; }
private:
GURL url_;
// TODO(crbug.com/1103217): Add more formats to be supported in addition to
// GURL.
// This variable should always have a value representing the object type.
const EndpointType type_;
// The url of the data endpoint. It always has a value if |type_| ==
// EndpointType::URL, otherwise it's empty.
const base::Optional<GURL> url_;
};
} // namespace ui
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment