diff options
Diffstat (limited to 'chromium/ui/base')
199 files changed, 2388 insertions, 1618 deletions
diff --git a/chromium/ui/base/BUILD.gn b/chromium/ui/base/BUILD.gn index 60d58740ef2..df0db2e2e26 100644 --- a/chromium/ui/base/BUILD.gn +++ b/chromium/ui/base/BUILD.gn @@ -7,6 +7,7 @@ import("//build/config/compiler/compiler.gni") import("//build/config/dcheck_always_on.gni") import("//build/config/linux/gtk/gtk.gni") import("//build/config/linux/pangocairo/pangocairo.gni") +import("//build/config/ozone.gni") import("//build/config/sanitizers/sanitizers.gni") import("//build/config/ui.gni") import("//build/util/branding.gni") @@ -14,7 +15,6 @@ import("//components/system_media_controls/linux/buildflags/buildflags.gni") import("//testing/test.gni") import("//tools/grit/grit_rule.gni") import("//ui/base/ui_features.gni") -import("//ui/ozone/ozone.gni") if (is_android) { import("//build/config/android/config.gni") @@ -96,6 +96,8 @@ component("base") { "dragdrop/os_exchange_data.h", "dragdrop/os_exchange_data_provider_factory.cc", "dragdrop/os_exchange_data_provider_factory.h", + "ime/utf_offset.cc", + "ime/utf_offset.h", "l10n/formatter.cc", "l10n/formatter.h", "l10n/l10n_font_util.cc", @@ -221,6 +223,8 @@ component("base") { "win/message_box_win.h", "win/mouse_wheel_util.cc", "win/mouse_wheel_util.h", + "win/power_setting_change_listener.cc", + "win/power_setting_change_listener.h", "win/scoped_ole_initializer.cc", "win/scoped_ole_initializer.h", "win/session_change_observer.cc", @@ -307,10 +311,6 @@ component("base") { ] } - if (is_posix) { - sources += [ "l10n/l10n_util_posix.cc" ] - } - if (is_ios) { sources += [ "device_form_factor_ios.mm", @@ -409,10 +409,7 @@ component("base") { } if (is_fuchsia) { - sources += [ - "l10n/l10n_util_posix.cc", - "resource/resource_bundle_fuchsia.cc", - ] + sources += [ "resource/resource_bundle_fuchsia.cc" ] } configs += [ "//build/config/compiler:wexit_time_destructors" ] @@ -447,6 +444,7 @@ component("base") { "//ui/display", "//ui/events", "//ui/events/devices", + "//ui/resources:webui_generated_resources_grd", "//ui/resources:webui_resources_grd", "//ui/strings", "//url", @@ -481,7 +479,7 @@ component("base") { deps += [ "//ui/events" ] } - if ((is_desktop_linux || is_chromeos) && (use_x11 || ozone_platform_x11)) { + if ((is_linux || is_chromeos) && (use_x11 || ozone_platform_x11)) { public_deps += [ "//ui/base/x" ] # X11 drag and drop wants to use common drag and drop types. @@ -614,6 +612,8 @@ component("data_exchange") { "//ui/gfx/geometry", "//url", ] + + public_deps = [ "//ui/base/data_transfer_policy" ] } component("features") { @@ -645,6 +645,7 @@ if (is_win || is_mac || (is_linux && !is_chromeos)) { ] deps = [ "//base", + "//base/test:test_config", "//testing/gtest", "//ui/gfx", "//ui/snapshot", @@ -856,6 +857,7 @@ test("ui_base_unittests") { sources = [ "class_property_unittest.cc", + "ime/utf_offset_unittest.cc", "l10n/l10n_util_unittest.cc", "l10n/time_format_unittest.cc", "layout_unittest.cc", diff --git a/chromium/ui/base/DEPS b/chromium/ui/base/DEPS index 10a3245a323..f333c5dc19c 100644 --- a/chromium/ui/base/DEPS +++ b/chromium/ui/base/DEPS @@ -12,6 +12,7 @@ include_rules = [ "+ui/gfx", "+ui/resources/grit/ui_resources.h", "+ui/resources/grit/ui_unscaled_resources.h", + "+ui/resources/grit/webui_generated_resources.h", "+ui/resources/grit/webui_resources.h", "+ui/strings/grit/app_locale_settings.h", "+ui/strings/grit/ui_strings.h", diff --git a/chromium/ui/base/clipboard/BUILD.gn b/chromium/ui/base/clipboard/BUILD.gn index 36048a6bc82..a24dfe52e7c 100644 --- a/chromium/ui/base/clipboard/BUILD.gn +++ b/chromium/ui/base/clipboard/BUILD.gn @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("///ui/ozone/ozone.gni") +import("///build/config/ozone.gni") import("//build/config/chromeos/ui_mode.gni") import("//build/config/ui.gni") @@ -35,7 +35,7 @@ component("clipboard_types") { } if (use_aura) { - if ((use_x11 && is_desktop_linux) || !is_win) { + if ((use_x11 && is_linux) || !is_win) { sources += [ "clipboard_format_type_aura.cc" ] } } @@ -59,10 +59,6 @@ component("clipboard") { sources = [ "clipboard.cc", "clipboard.h", - "clipboard_data_endpoint.cc", - "clipboard_data_endpoint.h", - "clipboard_dlp_controller.cc", - "clipboard_dlp_controller.h", "clipboard_metrics.cc", "clipboard_metrics.h", "clipboard_monitor.cc", @@ -107,15 +103,19 @@ component("clipboard") { "//mojo/public/cpp/base", "//net", "//skia", + "//ui/base:features", "//ui/gfx", "//ui/gfx/geometry", ] - public_deps = [ ":clipboard_types" ] + public_deps = [ + ":clipboard_types", + "//ui/base/data_transfer_policy", + ] if (use_aura) { # Linux clipboard implementations. - if (is_desktop_linux && !is_chromecast) { + if (is_linux && !is_chromecast) { sources += [ "clipboard_linux.cc" ] if (use_ozone) { sources += [ diff --git a/chromium/ui/base/clipboard/DIR_METADATA b/chromium/ui/base/clipboard/DIR_METADATA new file mode 100644 index 00000000000..185817f957c --- /dev/null +++ b/chromium/ui/base/clipboard/DIR_METADATA @@ -0,0 +1,12 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Blink>DataTransfer" +} +team_email: "storage-dev@chromium.org"
\ No newline at end of file diff --git a/chromium/ui/base/clipboard/OWNERS b/chromium/ui/base/clipboard/OWNERS index 4a0f01ac3b6..9317fe4e188 100644 --- a/chromium/ui/base/clipboard/OWNERS +++ b/chromium/ui/base/clipboard/OWNERS @@ -1,5 +1,2 @@ dcheng@chromium.org huangdarwin@chromium.org - -# TEAM: storage-dev@chromium.org -# COMPONENT: Blink>DataTransfer diff --git a/chromium/ui/base/clipboard/clipboard.cc b/chromium/ui/base/clipboard/clipboard.cc index b7445c0a98b..76f95800d1c 100644 --- a/chromium/ui/base/clipboard/clipboard.cc +++ b/chromium/ui/base/clipboard/clipboard.cc @@ -15,9 +15,37 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/geometry/size.h" +#if defined(USE_OZONE) +#include "ui/base/ui_base_features.h" +#endif + namespace ui { // static +bool Clipboard::IsSupportedClipboardBuffer(ClipboardBuffer buffer) { + switch (buffer) { + case ClipboardBuffer::kCopyPaste: + return true; + case ClipboardBuffer::kSelection: +#if defined(USE_OZONE) && !defined(OS_CHROMEOS) + if (features::IsUsingOzonePlatform()) { + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + CHECK(clipboard); + return clipboard->IsSelectionBufferAvailable(); + } +#endif +#if !defined(OS_WIN) && !defined(OS_APPLE) && !defined(OS_CHROMEOS) + return true; +#else + return false; +#endif + case ClipboardBuffer::kDrag: + return false; + } + NOTREACHED(); +} + +// static void Clipboard::SetAllowedThreads( const std::vector<base::PlatformThreadId>& allowed_threads) { base::AutoLock lock(ClipboardMapLock()); @@ -181,7 +209,7 @@ base::PlatformThreadId Clipboard::GetAndValidateThreadID() { // A Clipboard instance must be allocated for every thread that uses the // clipboard. To prevented unbounded memory use, CHECK that the current thread - // was whitelisted to use the clipboard. This is a CHECK rather than a DCHECK + // was allowlisted to use the clipboard. This is a CHECK rather than a DCHECK // to catch incorrect usage in production (e.g. https://crbug.com/872737). CHECK(AllowedThreads().empty() || base::Contains(AllowedThreads(), id)); diff --git a/chromium/ui/base/clipboard/clipboard.h b/chromium/ui/base/clipboard/clipboard.h index e596a20b40e..410e2936cfb 100644 --- a/chromium/ui/base/clipboard/clipboard.h +++ b/chromium/ui/base/clipboard/clipboard.h @@ -28,13 +28,14 @@ #include "mojo/public/cpp/base/big_buffer.h" #include "ui/base/clipboard/clipboard_buffer.h" #include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" class SkBitmap; namespace ui { class TestClipboard; class ScopedClipboardWriter; -class ClipboardDataEndpoint; +class DataTransferEndpoint; // Clipboard: // - reads from and writes to the system clipboard. @@ -47,21 +48,7 @@ class ClipboardDataEndpoint; class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard : public base::ThreadChecker { public: - static bool IsSupportedClipboardBuffer(ClipboardBuffer buffer) { - switch (buffer) { - case ClipboardBuffer::kCopyPaste: - return true; - case ClipboardBuffer::kSelection: -#if !defined(OS_WIN) && !defined(OS_APPLE) && !defined(OS_CHROMEOS) - return true; -#else - return false; -#endif - case ClipboardBuffer::kDrag: - return false; - } - NOTREACHED(); - } + static bool IsSupportedClipboardBuffer(ClipboardBuffer buffer); // Sets the list of threads that are allowed to access the clipboard. static void SetAllowedThreads( @@ -108,12 +95,10 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard virtual uint64_t GetSequenceNumber(ClipboardBuffer buffer) const = 0; // Tests whether the clipboard contains a certain format. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual bool IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const = 0; + const DataTransferEndpoint* data_dst) const = 0; // Returns whether the clipboard has data that is marked by its originator as // confidential. This is available for opt-in checking by the user of this API @@ -133,91 +118,69 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard // TODO(huangdarwin): Rename to ReadAvailablePortableFormatNames(). // Includes all sanitized types. // Also, includes pickled types by splitting them out of the pickled format. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originated uses. virtual void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const = 0; // Includes all types, including unsanitized types. // Omits formats held within pickles, as they're different from what a native // application would see. - // TODO(crbug.com/1103614): Update |dst| in all references to its appropriate - // ClipboardDataEndpoint for web-originates uses. virtual std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const = 0; + const DataTransferEndpoint* data_dst) const = 0; // Reads Unicode text from the clipboard, if available. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const = 0; // Reads ASCII text from the clipboard, if available. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const = 0; // Reads HTML from the clipboard, if available. If the HTML fragment requires // context to parse, |fragment_start| and |fragment_end| are indexes into // markup indicating the beginning and end of the actual fragment. Otherwise, // they will contain 0 and markup->size(). - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const = 0; // Reads an SVG image from the clipboard, if available. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const = 0; // Reads RTF from the clipboard, if available. Stores the result as a byte // vector. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const = 0; using ReadImageCallback = base::OnceCallback<void(const SkBitmap&)>; // Reads an image from the clipboard, if available. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const = 0; - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const = 0; // Reads a bookmark from the clipboard, if available. // |title| or |url| may be null. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. - virtual void ReadBookmark(const ClipboardDataEndpoint* data_dst, + virtual void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const = 0; // Reads raw data from the clipboard with the given format type. Stores result // as a byte vector. - // TODO(crbug.com/1103614): Update |data_dst| in all references to its - // appropriate ClipboardDataEndpoint for web-originates uses. virtual void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const = 0; // Returns an estimate of the time the clipboard was last updated. If the @@ -227,12 +190,6 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard // Resets the clipboard last modified time to Time::Time(). virtual void ClearLastModifiedTime(); -#if defined(USE_OZONE) - // Returns whether the selection buffer is available. This is true for some - // Linux platforms. - virtual bool IsSelectionBufferAvailable() const = 0; -#endif // defined(USE_OZONE) - protected: // PortableFormat designates the type of data to be stored in the clipboard. // This designation is shared across all OSes. The system-specific designation @@ -306,7 +263,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard virtual void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) = 0; + std::unique_ptr<DataTransferEndpoint> data_src) = 0; // Write |platform_representations|, in the order of their appearance in // |platform_representations|. Also, adds the source of the data to the @@ -316,7 +273,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard virtual void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) = 0; + std::unique_ptr<DataTransferEndpoint> data_src) = 0; void DispatchPortableRepresentation(PortableFormat format, const ObjectMapParams& params); @@ -362,6 +319,12 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard static base::PlatformThreadId GetAndValidateThreadID(); +#if defined(USE_OZONE) + // Returns whether the selection buffer is available. This is true for some + // Linux platforms. + virtual bool IsSelectionBufferAvailable() const = 0; +#endif // defined(USE_OZONE) + // A list of allowed threads. By default, this is empty and no thread checking // is done (in the unit test case), but a user (like content) can set which // threads are allowed to call this method. diff --git a/chromium/ui/base/clipboard/clipboard_android.cc b/chromium/ui/base/clipboard/clipboard_android.cc index caf32eb42ab..d1f728c1992 100644 --- a/chromium/ui/base/clipboard/clipboard_android.cc +++ b/chromium/ui/base/clipboard/clipboard_android.cc @@ -26,9 +26,9 @@ #include "base/time/time.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_metrics.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/ui_base_jni_headers/Clipboard_jni.h" #include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/image/image.h" @@ -76,7 +76,7 @@ SkBitmap GetImageData( } gfx::JavaBitmap java_bitmap(jbitmap); - if (java_bitmap.size().IsEmpty() || java_bitmap.stride() == 0U || + if (java_bitmap.size().IsEmpty() || java_bitmap.bytes_per_row() == 0U || java_bitmap.pixels() == nullptr) { return SkBitmap(); } @@ -375,7 +375,7 @@ uint64_t ClipboardAndroid::GetSequenceNumber( bool ClipboardAndroid::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -396,7 +396,7 @@ void ClipboardAndroid::Clear(ClipboardBuffer buffer) { // platforms. void ClipboardAndroid::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -425,7 +425,7 @@ void ClipboardAndroid::ReadAvailableTypes( std::vector<base::string16> ClipboardAndroid::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); std::vector<ClipboardFormatType> formats = g_map.Get().GetFormats(); @@ -440,7 +440,7 @@ ClipboardAndroid::ReadAvailablePlatformSpecificFormatNames( // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -452,7 +452,7 @@ void ClipboardAndroid::ReadText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -460,11 +460,11 @@ void ClipboardAndroid::ReadAsciiText(ClipboardBuffer buffer, *result = g_map.Get().Get(ClipboardFormatType::GetPlainTextType()); } -// Note: |src_url| isn't really used. It is only implemented in Windows. +// |src_url| isn't really used. It is only implemented in Windows. // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -485,7 +485,7 @@ void ClipboardAndroid::ReadHTML(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -496,7 +496,7 @@ void ClipboardAndroid::ReadSvg(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); NOTIMPLEMENTED(); @@ -505,7 +505,7 @@ void ClipboardAndroid::ReadRTF(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -517,7 +517,7 @@ void ClipboardAndroid::ReadImage(ClipboardBuffer buffer, // platforms. void ClipboardAndroid::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); NOTIMPLEMENTED(); @@ -525,7 +525,7 @@ void ClipboardAndroid::ReadCustomData(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. -void ClipboardAndroid::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardAndroid::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); @@ -535,7 +535,7 @@ void ClipboardAndroid::ReadBookmark(const ClipboardDataEndpoint* data_dst, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardAndroid::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kData); @@ -558,7 +558,7 @@ void ClipboardAndroid::ClearLastModifiedTime() { void ClipboardAndroid::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); g_map.Get().Clear(); @@ -574,7 +574,7 @@ void ClipboardAndroid::WritePortableRepresentations( void ClipboardAndroid::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); g_map.Get().Clear(); @@ -606,7 +606,7 @@ void ClipboardAndroid::WriteRTF(const char* rtf_data, size_t data_len) { NOTIMPLEMENTED(); } -// Note: according to other platforms implementations, this really writes the +// According to other platforms implementations, this really writes the // URL spec. void ClipboardAndroid::WriteBookmark(const char* title_data, size_t title_len, diff --git a/chromium/ui/base/clipboard/clipboard_android.h b/chromium/ui/base/clipboard/clipboard_android.h index 68ac63dd120..5a262fa3595 100644 --- a/chromium/ui/base/clipboard/clipboard_android.h +++ b/chromium/ui/base/clipboard/clipboard_android.h @@ -61,56 +61,56 @@ class ClipboardAndroid : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; base::Time GetLastModifiedTime() const override; void ClearLastModifiedTime() override; void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/clipboard_android_test_support.cc b/chromium/ui/base/clipboard/clipboard_android_test_support.cc index fa69f2ba17f..30b2d5ba81d 100644 --- a/chromium/ui/base/clipboard/clipboard_android_test_support.cc +++ b/chromium/ui/base/clipboard/clipboard_android_test_support.cc @@ -24,7 +24,7 @@ jboolean JNI_ClipboardAndroidTestSupport_NativeWriteHtml( const base::android::JavaParamRef<jstring>& j_html_text) { { // Simulate something writing HTML to the clipboard in native. - // NOTE: Android requires both a plaintext and HTML version. + // Android requires both a plaintext and HTML version. base::string16 html_text; base::android::ConvertJavaStringToUTF16(env, j_html_text, &html_text); std::string url; diff --git a/chromium/ui/base/clipboard/clipboard_constants.cc b/chromium/ui/base/clipboard/clipboard_constants.cc index 9fafdfaeea8..a64162fdd86 100644 --- a/chromium/ui/base/clipboard/clipboard_constants.cc +++ b/chromium/ui/base/clipboard/clipboard_constants.cc @@ -25,7 +25,6 @@ const char kMimeTypeLinuxText[] = "TEXT"; #if !defined(OS_APPLE) const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; -const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; #endif // defined(OS_APPLE) #if defined(OS_ANDROID) diff --git a/chromium/ui/base/clipboard/clipboard_constants.h b/chromium/ui/base/clipboard/clipboard_constants.h index aceeb8ea6e3..d0eea2208fb 100644 --- a/chromium/ui/base/clipboard/clipboard_constants.h +++ b/chromium/ui/base/clipboard/clipboard_constants.h @@ -52,8 +52,6 @@ COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeWebCustomData[]; COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern const char kMimeTypeWebkitSmartPaste[]; -COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) -extern const char kMimeTypePepperCustomData[]; #else // MacOS-specific Uniform Type Identifiers. @@ -70,10 +68,6 @@ extern NSString* const kWebCustomDataPboardType; COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern NSString* const kWebSmartPastePboardType; -// Pepper custom data format type. -COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) -extern NSString* const kPepperCustomDataPboardType; - // Data format used to tag the current data as confidential. COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern NSString* const kUTTypeConfidentialData; diff --git a/chromium/ui/base/clipboard/clipboard_constants_mac.mm b/chromium/ui/base/clipboard/clipboard_constants_mac.mm index a7bc458f284..a7a1c8ccadd 100644 --- a/chromium/ui/base/clipboard/clipboard_constants_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_constants_mac.mm @@ -12,8 +12,6 @@ NSString* const kImageSvg = @"public.svg-image"; // TODO(dcheng): This name is temporary. See crbug.com/106449. NSString* const kWebCustomDataPboardType = @"org.chromium.web-custom-data"; NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; -NSString* const kPepperCustomDataPboardType = - @"org.chromium.pepper-custom-data"; // It is the common convention on the Mac and on iOS that password managers tag // confidential data with the flavor "org.nspasteboard.ConcealedType". Obey this diff --git a/chromium/ui/base/clipboard/clipboard_data.cc b/chromium/ui/base/clipboard/clipboard_data.cc index 64f055b3266..956afe8c2fe 100644 --- a/chromium/ui/base/clipboard/clipboard_data.cc +++ b/chromium/ui/base/clipboard/clipboard_data.cc @@ -9,7 +9,7 @@ #include "base/notreached.h" #include "skia/ext/skia_utils_base.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/gfx/skia_util.h" namespace ui { @@ -29,7 +29,7 @@ ClipboardData::ClipboardData(const ClipboardData& other) { custom_data_data_ = other.custom_data_data_; web_smart_paste_ = other.web_smart_paste_; svg_data_ = other.svg_data_; - src_ = other.src_ ? std::make_unique<ClipboardDataEndpoint>(*other.src_.get()) + src_ = other.src_ ? std::make_unique<DataTransferEndpoint>(*other.src_.get()) : nullptr; } diff --git a/chromium/ui/base/clipboard/clipboard_data.h b/chromium/ui/base/clipboard/clipboard_data.h index a9eec23d950..ac89e4f65f4 100644 --- a/chromium/ui/base/clipboard/clipboard_data.h +++ b/chromium/ui/base/clipboard/clipboard_data.h @@ -10,7 +10,7 @@ #include "base/component_export.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" class SkBitmap; @@ -100,9 +100,9 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardData { format_ |= static_cast<int>(ClipboardInternalFormat::kWeb); } - ClipboardDataEndpoint* source() const { return src_.get(); } + DataTransferEndpoint* source() const { return src_.get(); } - void set_source(std::unique_ptr<ClipboardDataEndpoint> src) { + void set_source(std::unique_ptr<DataTransferEndpoint> src) { src_ = std::move(src); } @@ -137,7 +137,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardData { int format_; // The source of the data. - std::unique_ptr<ClipboardDataEndpoint> src_ = nullptr; + std::unique_ptr<DataTransferEndpoint> src_ = nullptr; }; } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_data_endpoint.cc b/chromium/ui/base/clipboard/clipboard_data_endpoint.cc index 8fbab3cbdbe..10aed991bcb 100644 --- a/chromium/ui/base/clipboard/clipboard_data_endpoint.cc +++ b/chromium/ui/base/clipboard/clipboard_data_endpoint.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/base/clipboard/clipboard_data_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "base/check_op.h" #include "base/optional.h" @@ -10,25 +10,31 @@ namespace ui { -ClipboardDataEndpoint::ClipboardDataEndpoint(const url::Origin& origin) - : type_(EndpointType::kUrl), origin_(origin) {} - -ClipboardDataEndpoint::ClipboardDataEndpoint(EndpointType type) - : type_(type), origin_(base::nullopt) { +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_(base::nullopt), + notify_if_restricted_(notify_if_restricted) { DCHECK_NE(type, EndpointType::kUrl); } -ClipboardDataEndpoint::ClipboardDataEndpoint( - const ClipboardDataEndpoint& other) = default; +DataTransferEndpoint::DataTransferEndpoint(const DataTransferEndpoint& other) = + default; -ClipboardDataEndpoint::ClipboardDataEndpoint(ClipboardDataEndpoint&& other) = +DataTransferEndpoint::DataTransferEndpoint(DataTransferEndpoint&& other) = default; -bool ClipboardDataEndpoint::operator==( - const ClipboardDataEndpoint& other) const { - return origin_ == other.origin_ && type_ == other.type_; +bool DataTransferEndpoint::operator==(const DataTransferEndpoint& other) const { + return origin_ == other.origin_ && type_ == other.type_ && + notify_if_restricted_ == other.notify_if_restricted_; } -ClipboardDataEndpoint::~ClipboardDataEndpoint() = default; +DataTransferEndpoint::~DataTransferEndpoint() = default; } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_data_endpoint.h b/chromium/ui/base/clipboard/clipboard_data_endpoint.h deleted file mode 100644 index 9e6f12dfd96..00000000000 --- a/chromium/ui/base/clipboard/clipboard_data_endpoint.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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_ diff --git a/chromium/ui/base/clipboard/clipboard_data_unittest.cc b/chromium/ui/base/clipboard/clipboard_data_unittest.cc index f0a0c784736..627793fd3c1 100644 --- a/chromium/ui/base/clipboard/clipboard_data_unittest.cc +++ b/chromium/ui/base/clipboard/clipboard_data_unittest.cc @@ -8,7 +8,7 @@ #include "base/strings/string_piece_forward.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "url/gurl.h" namespace ui { @@ -34,12 +34,12 @@ TEST(ClipboardDataTest, BitMapTest) { TEST(ClipboardDataTest, DataSrcTest) { url::Origin origin(url::Origin::Create(GURL("www.example.com"))); ClipboardData data1; - data1.set_source(std::make_unique<ClipboardDataEndpoint>(origin)); + data1.set_source(std::make_unique<DataTransferEndpoint>(origin)); ClipboardData data2; EXPECT_NE(data1, data2); - data2.set_source(std::make_unique<ClipboardDataEndpoint>(origin)); + data2.set_source(std::make_unique<DataTransferEndpoint>(origin)); EXPECT_EQ(data1, data2); } diff --git a/chromium/ui/base/clipboard/clipboard_dlp_controller.cc b/chromium/ui/base/clipboard/clipboard_dlp_controller.cc deleted file mode 100644 index 5ab980182c9..00000000000 --- a/chromium/ui/base/clipboard/clipboard_dlp_controller.cc +++ /dev/null @@ -1,33 +0,0 @@ -// 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/clipboard/clipboard_dlp_controller.h" - -namespace ui { - -// static -ClipboardDlpController* ClipboardDlpController::Get() { - return g_clipboard_dlp_controller_; -} - -// static -void ClipboardDlpController::DeleteInstance() { - if (!g_clipboard_dlp_controller_) - return; - - delete g_clipboard_dlp_controller_; -} - -ClipboardDlpController::ClipboardDlpController() { - g_clipboard_dlp_controller_ = this; -} - -ClipboardDlpController::~ClipboardDlpController() { - g_clipboard_dlp_controller_ = nullptr; -} - -ClipboardDlpController* ClipboardDlpController::g_clipboard_dlp_controller_ = - nullptr; - -} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_dlp_controller.h b/chromium/ui/base/clipboard/clipboard_dlp_controller.h deleted file mode 100644 index 8fca4a43961..00000000000 --- a/chromium/ui/base/clipboard/clipboard_dlp_controller.h +++ /dev/null @@ -1,42 +0,0 @@ -// 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_DLP_CONTROLLER_H_ -#define UI_BASE_CLIPBOARD_CLIPBOARD_DLP_CONTROLLER_H_ - -#include "base/component_export.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" - -namespace ui { - -// The Clipboard Data Leak Prevention controller is used to control clipboard -// read operations. It should allow/disallow clipboard data read given the -// source of the data and the destination trying to access the data and a set of -// rules controlling these source and destination. -class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardDlpController { - public: - // Returns a pointer to the existing instance of the class. - static ClipboardDlpController* Get(); - - // Deletes the existing instance of the class if it's already created. - // Indicates that restricting clipboard content is no longer required. - static void DeleteInstance(); - - virtual bool IsDataReadAllowed( - const ClipboardDataEndpoint* const data_src, - const ClipboardDataEndpoint* const data_dst) const = 0; - - protected: - ClipboardDlpController(); - virtual ~ClipboardDlpController(); - - private: - // A singleton of ClipboardDlpController. Equals nullptr when there's not any - // clipboard restrictions required. - static ClipboardDlpController* g_clipboard_dlp_controller_; -}; - -} // namespace ui - -#endif // UI_BASE_CLIPBOARD_CLIPBOARD_DLP_CONTROLLER_H_ diff --git a/chromium/ui/base/clipboard/clipboard_format_type.h b/chromium/ui/base/clipboard/clipboard_format_type.h index 687a0f87ed1..b5944b0ef7e 100644 --- a/chromium/ui/base/clipboard/clipboard_format_type.h +++ b/chromium/ui/base/clipboard/clipboard_format_type.h @@ -62,10 +62,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) ClipboardFormatType { static const ClipboardFormatType& GetSvgType(); static const ClipboardFormatType& GetRtfType(); static const ClipboardFormatType& GetBitmapType(); - // TODO(raymes): Unify web custom data and pepper custom data: - // crbug.com/158399. static const ClipboardFormatType& GetWebCustomDataType(); - static const ClipboardFormatType& GetPepperCustomDataType(); #if defined(OS_WIN) // ANSI formats. Only Windows differentiates between ANSI and UNICODE formats diff --git a/chromium/ui/base/clipboard/clipboard_format_type_android.cc b/chromium/ui/base/clipboard/clipboard_format_type_android.cc index 12a132edf1c..e773978a379 100644 --- a/chromium/ui/base/clipboard/clipboard_format_type_android.cc +++ b/chromium/ui/base/clipboard/clipboard_format_type_android.cc @@ -95,11 +95,4 @@ const ClipboardFormatType& ClipboardFormatType::GetWebCustomDataType() { return *type; } -// static -const ClipboardFormatType& ClipboardFormatType::GetPepperCustomDataType() { - static base::NoDestructor<ClipboardFormatType> type( - kMimeTypePepperCustomData); - return *type; -} - } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_format_type_aura.cc b/chromium/ui/base/clipboard/clipboard_format_type_aura.cc index 1d35f357e43..06e2293c01a 100644 --- a/chromium/ui/base/clipboard/clipboard_format_type_aura.cc +++ b/chromium/ui/base/clipboard/clipboard_format_type_aura.cc @@ -98,11 +98,4 @@ const ClipboardFormatType& ClipboardFormatType::GetWebCustomDataType() { return *type; } -// static -const ClipboardFormatType& ClipboardFormatType::GetPepperCustomDataType() { - static base::NoDestructor<ClipboardFormatType> type( - kMimeTypePepperCustomData); - return *type; -} - } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_format_type_mac.mm b/chromium/ui/base/clipboard/clipboard_format_type_mac.mm index 376bebae39e..3ee36e5bd9c 100644 --- a/chromium/ui/base/clipboard/clipboard_format_type_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_format_type_mac.mm @@ -110,11 +110,4 @@ const ClipboardFormatType& ClipboardFormatType::GetWebCustomDataType() { return *type; } -// static -const ClipboardFormatType& ClipboardFormatType::GetPepperCustomDataType() { - static base::NoDestructor<ClipboardFormatType> type( - kPepperCustomDataPboardType); - return *type; -} - } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_format_type_win.cc b/chromium/ui/base/clipboard/clipboard_format_type_win.cc index b0d0a9249df..7e7516fa801 100644 --- a/chromium/ui/base/clipboard/clipboard_format_type_win.cc +++ b/chromium/ui/base/clipboard/clipboard_format_type_win.cc @@ -23,35 +23,37 @@ const base::flat_map<UINT, std::string>& PredefinedFormatToNameMap() { static const base::NoDestructor<base::flat_map<UINT, std::string>> format_to_name({ {CF_TEXT, "CF_TEXT"}, - {CF_BITMAP, "CF_BITMAP"}, - {CF_METAFILEPICT, "CF_METAFILEPICT"}, - {CF_SYLK, "CF_SYLK"}, {CF_DIF, "CF_DIF"}, {CF_TIFF, "CF_TIFF"}, {CF_OEMTEXT, "CF_OEMTEXT"}, {CF_DIB, "CF_DIB"}, - {CF_PALETTE, "CF_PALETTE"}, {CF_PENDATA, "CF_PENDATA"}, {CF_RIFF, "CF_RIFF"}, {CF_WAVE, "CF_WAVE"}, {CF_UNICODETEXT, "CF_UNICODETEXT"}, - {CF_ENHMETAFILE, "CF_ENHMETAFILE"}, - {CF_HDROP, "CF_HDROP"}, - {CF_LOCALE, "CF_LOCALE"}, {CF_DIBV5, "CF_DIBV5"}, {CF_OWNERDISPLAY, "CF_OWNERDISPLAY"}, - {CF_DSPTEXT, "CF_DSPTEXT"}, - {CF_DSPBITMAP, "CF_DSPBITMAP"}, - {CF_DSPMETAFILEPICT, "CF_DSPMETAFILEPICT"}, - {CF_DSPENHMETAFILE, "CF_DSPENHMETAFILE"}, - - // These formats are predefined but explicitly blocked from use. - // TODO(huangdarwin): Which other formats should always be disallowed? - // {CF_MAX, "CF_MAX"}, - // {CF_PRIVATEFIRST, "CF_PRIVATEFIRST"}, - // {CF_PRIVATELAST, "CF_PRIVATELAST"}, - // {CF_GDIOBJFIRST, "CF_GDIOBJFIRST"}, - // {CF_GDIOBJLAST, "CF_GDIOBJLAST"}, + + // These formats are predefined but explicitly blocked from use, + // either due to passing along handles, or concerns regarding exposing + // private information. + // {CF_MAX, "CF_MAX"}, + // {CF_PRIVATEFIRST, "CF_PRIVATEFIRST"}, + // {CF_PRIVATELAST, "CF_PRIVATELAST"}, + // {CF_GDIOBJFIRST, "CF_GDIOBJFIRST"}, + // {CF_GDIOBJLAST, "CF_GDIOBJLAST"}, + // {CF_BITMAP, "CF_BITMAP"}, + // {CF_SYLK, "CF_SYLK"}, + // {CF_METAFILEPICT, "CF_METAFILEPICT"}, + // {CF_DSPTEXT, "CF_DSPTEXT"}, + // {CF_DSPBITMAP, "CF_DSPBITMAP"}, + // {CF_DSPMETAFILEPICT, "CF_DSPMETAFILEPICT"}, + // {CF_DSPENHMETAFILE, "CF_DSPENHMETAFILE"}, + // {CF_ENHMETAFILE, "CF_ENHMETAFILE"}, + // {CF_HDROP, "CF_HDROP"}, + // {CF_LOCALE, "CF_LOCALE"}, + // {CF_PALETTE, "CF_PALETTE"}, + }); return *format_to_name; } @@ -135,7 +137,7 @@ std::string ClipboardFormatType::GetName() const { return std::string(); } - return base::UTF16ToUTF8(base::string16(name_buffer->data(), name_size)); + return base::WideToUTF8(std::wstring(name_buffer->data(), name_size)); } bool ClipboardFormatType::operator<(const ClipboardFormatType& other) const { @@ -157,7 +159,7 @@ ClipboardFormatType ClipboardFormatType::GetType( return ClipboardFormatType(it->second); return ClipboardFormatType( - ::RegisterClipboardFormat(base::ASCIIToUTF16(format_string).c_str())); + ::RegisterClipboardFormat(base::ASCIIToWide(format_string).c_str())); } // The following formats can be referenced by ClipboardUtilWin::GetPlainText. @@ -263,7 +265,7 @@ const ClipboardFormatType& ClipboardFormatType::GetFileDescriptorType() { // static const ClipboardFormatType& ClipboardFormatType::GetFileContentZeroType() { - // Note this uses a storage media type of TYMED_HGLOBAL, which is not commonly + // This uses a storage media type of TYMED_HGLOBAL, which is not commonly // used with CFSTR_FILECONTENTS (but used in Chromium--see // OSExchangeDataProviderWin::SetFileContents). Use GetFileContentAtIndexType // if TYMED_ISTREAM and TYMED_ISTORAGE are needed. @@ -333,11 +335,4 @@ const ClipboardFormatType& ClipboardFormatType::GetWebCustomDataType() { return *format; } -// static -const ClipboardFormatType& ClipboardFormatType::GetPepperCustomDataType() { - static base::NoDestructor<ClipboardFormatType> format( - ::RegisterClipboardFormat(L"Chromium Pepper MIME Data Format")); - return *format; -} - } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_mac.h b/chromium/ui/base/clipboard/clipboard_mac.h index f220aa72ca4..b556901af5d 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.h +++ b/chromium/ui/base/clipboard/clipboard_mac.h @@ -33,55 +33,55 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardMac : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; bool IsMarkedByOriginatorAsConfidential() const override; void MarkAsConfidential() override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/clipboard_mac.mm b/chromium/ui/base/clipboard/clipboard_mac.mm index 2c1487fb632..67cb135e387 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_mac.mm @@ -24,10 +24,10 @@ #import "third_party/mozilla/NSPasteboard+Utils.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_util_mac.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" @@ -75,7 +75,7 @@ uint64_t ClipboardMac::GetSequenceNumber(ClipboardBuffer buffer) const { bool ClipboardMac::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -124,7 +124,7 @@ void ClipboardMac::Clear(ClipboardBuffer buffer) { // platforms. void ClipboardMac::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(CalledOnValidThread()); DCHECK(types); @@ -156,7 +156,7 @@ void ClipboardMac::ReadAvailableTypes( std::vector<base::string16> ClipboardMac::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -173,7 +173,7 @@ ClipboardMac::ReadAvailablePlatformSpecificFormatNames( // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -187,7 +187,7 @@ void ClipboardMac::ReadText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -204,7 +204,7 @@ void ClipboardMac::ReadAsciiText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -237,7 +237,7 @@ void ClipboardMac::ReadHTML(ClipboardBuffer buffer, } void ClipboardMac::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -251,7 +251,7 @@ void ClipboardMac::ReadSvg(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -263,7 +263,7 @@ void ClipboardMac::ReadRTF(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer, GetPasteboard())); @@ -273,7 +273,7 @@ void ClipboardMac::ReadImage(ClipboardBuffer buffer, // platforms. void ClipboardMac::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -289,7 +289,7 @@ void ClipboardMac::ReadCustomData(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. -void ClipboardMac::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardMac::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); @@ -313,7 +313,7 @@ void ClipboardMac::ReadBookmark(const ClipboardDataEndpoint* data_dst, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardMac::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kData); @@ -328,7 +328,7 @@ void ClipboardMac::ReadData(const ClipboardFormatType& format, void ClipboardMac::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -344,7 +344,7 @@ void ClipboardMac::WritePortableRepresentations( void ClipboardMac::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); diff --git a/chromium/ui/base/clipboard/clipboard_non_backed.cc b/chromium/ui/base/clipboard/clipboard_non_backed.cc index a53ca0a33d1..05513ec8398 100644 --- a/chromium/ui/base/clipboard/clipboard_non_backed.cc +++ b/chromium/ui/base/clipboard/clipboard_non_backed.cc @@ -24,12 +24,12 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/clipboard/clipboard_data.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" -#include "ui/base/clipboard/clipboard_dlp_controller.h" #include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #include "ui/gfx/geometry/size.h" #include "ui/ozone/buildflags.h" @@ -240,12 +240,13 @@ class ClipboardInternal { return previous_data; } - bool IsReadAllowed(const ClipboardDataEndpoint* data_dst) const { - ClipboardDlpController* dlp_controller = ClipboardDlpController::Get(); + bool IsReadAllowed(const DataTransferEndpoint* data_dst) const { + DataTransferPolicyController* policy_controller = + DataTransferPolicyController::Get(); auto* data = GetData(); - if (!dlp_controller || !data) + if (!policy_controller || !data) return true; - return dlp_controller->IsDataReadAllowed(data->source(), data_dst); + return policy_controller->IsDataReadAllowed(data->source(), data_dst); } private: @@ -271,7 +272,7 @@ class ClipboardDataBuilder { // confidential and the data can be pasted in any document. static void CommitToClipboard( ClipboardInternal* clipboard, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { ClipboardData* data = GetCurrentData(); data->set_source(std::move(data_src)); clipboard->WriteData(TakeCurrentData()); @@ -375,7 +376,7 @@ ClipboardNonBacked::~ClipboardNonBacked() { } const ClipboardData* ClipboardNonBacked::GetClipboardData( - ClipboardDataEndpoint* data_dst) const { + DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); if (!clipboard_internal_->IsReadAllowed(data_dst)) @@ -400,7 +401,7 @@ uint64_t ClipboardNonBacked::GetSequenceNumber(ClipboardBuffer buffer) const { bool ClipboardNonBacked::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); @@ -438,7 +439,7 @@ void ClipboardNonBacked::Clear(ClipboardBuffer buffer) { void ClipboardNonBacked::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(CalledOnValidThread()); DCHECK(types); @@ -472,7 +473,7 @@ void ClipboardNonBacked::ReadAvailableTypes( std::vector<base::string16> ClipboardNonBacked::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); std::vector<base::string16> types; @@ -503,7 +504,7 @@ ClipboardNonBacked::ReadAvailablePlatformSpecificFormatNames( } void ClipboardNonBacked::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); @@ -519,7 +520,7 @@ void ClipboardNonBacked::ReadText(ClipboardBuffer buffer, } void ClipboardNonBacked::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); @@ -535,7 +536,7 @@ void ClipboardNonBacked::ReadAsciiText(ClipboardBuffer buffer, } void ClipboardNonBacked::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -554,7 +555,7 @@ void ClipboardNonBacked::ReadHTML(ClipboardBuffer buffer, } void ClipboardNonBacked::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); @@ -566,7 +567,7 @@ void ClipboardNonBacked::ReadSvg(ClipboardBuffer buffer, } void ClipboardNonBacked::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); @@ -582,7 +583,7 @@ void ClipboardNonBacked::ReadRTF(ClipboardBuffer buffer, } void ClipboardNonBacked::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { DCHECK(CalledOnValidThread()); @@ -601,7 +602,7 @@ void ClipboardNonBacked::ReadImage(ClipboardBuffer buffer, void ClipboardNonBacked::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); @@ -616,7 +617,7 @@ void ClipboardNonBacked::ReadCustomData(ClipboardBuffer buffer, #endif } -void ClipboardNonBacked::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardNonBacked::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); @@ -633,7 +634,7 @@ void ClipboardNonBacked::ReadBookmark(const ClipboardDataEndpoint* data_dst, } void ClipboardNonBacked::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); @@ -649,13 +650,17 @@ void ClipboardNonBacked::ReadData(const ClipboardFormatType& format, } bool ClipboardNonBacked::IsSelectionBufferAvailable() const { +#if defined(OS_CHROMEOS) return false; +#else + return true; +#endif } void ClipboardNonBacked::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); for (const auto& object : objects) @@ -667,7 +672,7 @@ void ClipboardNonBacked::WritePortableRepresentations( void ClipboardNonBacked::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); diff --git a/chromium/ui/base/clipboard/clipboard_non_backed.h b/chromium/ui/base/clipboard/clipboard_non_backed.h index 76dee9c24ed..a9fa8b39c44 100644 --- a/chromium/ui/base/clipboard/clipboard_non_backed.h +++ b/chromium/ui/base/clipboard/clipboard_non_backed.h @@ -26,19 +26,22 @@ class ClipboardInternal; class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardNonBacked : public Clipboard { public: - // Returns the in-memory clipboard for the current thread. Note that this + // Returns the in-memory clipboard for the current thread. This // method must *only* be used when the caller is sure that the clipboard for // the current thread is in fact an instance of ClipboardNonBacked. static ClipboardNonBacked* GetForCurrentThread(); // Returns the current ClipboardData. - const ClipboardData* GetClipboardData(ClipboardDataEndpoint* data_dst) const; + const ClipboardData* GetClipboardData(DataTransferEndpoint* data_dst) const; // Writes the current ClipboardData and returns the previous data. // The data source is expected to be set in `data`. std::unique_ptr<ClipboardData> WriteClipboardData( std::unique_ptr<ClipboardData> data); + // Clipboard overrides: + uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; + private: friend class Clipboard; friend class ClipboardNonBackedTest; @@ -47,57 +50,56 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardNonBacked // Clipboard overrides: void OnPreShutdown() override; - uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; bool IsSelectionBufferAvailable() const override; void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/clipboard_ozone.cc b/chromium/ui/base/clipboard/clipboard_ozone.cc index 4c97d862b6f..774c8848ddf 100644 --- a/chromium/ui/base/clipboard/clipboard_ozone.cc +++ b/chromium/ui/base/clipboard/clipboard_ozone.cc @@ -19,10 +19,10 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_buffer.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/gfx/codec/png_codec.h" #include "ui/ozone/buildflags.h" #include "ui/ozone/public/ozone_platform.h" @@ -351,7 +351,7 @@ uint64_t ClipboardOzone::GetSequenceNumber(ClipboardBuffer buffer) const { bool ClipboardOzone::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); auto available_types = async_clipboard_ozone_->RequestMimeTypes(buffer); @@ -365,7 +365,7 @@ void ClipboardOzone::Clear(ClipboardBuffer buffer) { // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(CalledOnValidThread()); DCHECK(types); @@ -391,7 +391,7 @@ void ClipboardOzone::ReadAvailableTypes( std::vector<base::string16> ClipboardOzone::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); std::vector<std::string> mime_types = @@ -405,7 +405,7 @@ ClipboardOzone::ReadAvailablePlatformSpecificFormatNames( // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kText); @@ -418,7 +418,7 @@ void ClipboardOzone::ReadText(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kText); @@ -430,7 +430,7 @@ void ClipboardOzone::ReadAsciiText(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -454,7 +454,7 @@ void ClipboardOzone::ReadHTML(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kSvg); @@ -467,7 +467,7 @@ void ClipboardOzone::ReadSvg(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kRtf); @@ -479,7 +479,7 @@ void ClipboardOzone::ReadRTF(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer)); @@ -488,7 +488,7 @@ void ClipboardOzone::ReadImage(ClipboardBuffer buffer, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kCustomData); @@ -499,7 +499,7 @@ void ClipboardOzone::ReadCustomData(ClipboardBuffer buffer, } // TODO(crbug.com/1103194): |data_dst| should be supported. -void ClipboardOzone::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardOzone::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); @@ -509,7 +509,7 @@ void ClipboardOzone::ReadBookmark(const ClipboardDataEndpoint* data_dst, // TODO(crbug.com/1103194): |data_dst| should be supported. void ClipboardOzone::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kData); @@ -527,7 +527,7 @@ bool ClipboardOzone::IsSelectionBufferAvailable() const { void ClipboardOzone::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); for (const auto& object : objects) @@ -555,7 +555,7 @@ void ClipboardOzone::WritePortableRepresentations( void ClipboardOzone::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DispatchPlatformRepresentations(std::move(platform_representations)); diff --git a/chromium/ui/base/clipboard/clipboard_ozone.h b/chromium/ui/base/clipboard/clipboard_ozone.h index 43f7b5c2651..b46a7c5703e 100644 --- a/chromium/ui/base/clipboard/clipboard_ozone.h +++ b/chromium/ui/base/clipboard/clipboard_ozone.h @@ -28,54 +28,54 @@ class ClipboardOzone : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; bool IsSelectionBufferAvailable() const override; void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/clipboard_test_template.h b/chromium/ui/base/clipboard/clipboard_test_template.h index 372a758cd79..7be5cd2d0b8 100644 --- a/chromium/ui/base/clipboard/clipboard_test_template.h +++ b/chromium/ui/base/clipboard/clipboard_test_template.h @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 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. // -// Note: This header doesn't use REGISTER_TYPED_TEST_SUITE_P like most +// This header doesn't use REGISTER_TYPED_TEST_SUITE_P like most // type-parameterized gtests. There are lot of test cases in here that are only // enabled on certain platforms. However, preprocessor directives in macro // arguments result in undefined behavior (and don't work on MSVC). Instead, @@ -39,11 +39,11 @@ #include "third_party/skia/include/core/SkUnPreMultiply.h" #include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" -#include "ui/base/clipboard/clipboard_dlp_controller.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/test/clipboard_test_util.h" #include "ui/base/clipboard/test/test_clipboard.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/half_float.h" #include "url/origin.h" @@ -58,8 +58,8 @@ #endif using base::ASCIIToUTF16; -using base::UTF8ToUTF16; using base::UTF16ToUTF8; +using base::UTF8ToUTF16; using testing::Contains; @@ -104,27 +104,19 @@ class ClipboardTest : public PlatformTest { }; // A mock delegate for testing. -class MockClipboardDlpController : public ClipboardDlpController { +class MockPolicyController : public DataTransferPolicyController { public: - static MockClipboardDlpController* Init(); + MockPolicyController(); + ~MockPolicyController() override; MOCK_CONST_METHOD2(IsDataReadAllowed, - bool(const ClipboardDataEndpoint* const data_src, - const ClipboardDataEndpoint* const data_dst)); - - private: - MockClipboardDlpController(); - ~MockClipboardDlpController() override; + bool(const DataTransferEndpoint* const data_src, + const DataTransferEndpoint* const data_dst)); }; -// static -MockClipboardDlpController* MockClipboardDlpController::Init() { - return new MockClipboardDlpController(); -} +MockPolicyController::MockPolicyController() = default; -MockClipboardDlpController::MockClipboardDlpController() = default; - -MockClipboardDlpController::~MockClipboardDlpController() = default; +MockPolicyController::~MockPolicyController() = default; // Hack for tests that need to call static methods of ClipboardTest. struct NullClipboardTraits { @@ -270,10 +262,10 @@ TYPED_TEST(ClipboardTest, RTFTest) { #if defined(OS_LINUX) && !defined(OS_CHROMEOS) TYPED_TEST(ClipboardTest, MultipleBufferTest) { -#if defined(USE_OZONE) - if (!this->clipboard().IsSelectionBufferAvailable()) + if (!ui::Clipboard::IsSupportedClipboardBuffer( + ui::ClipboardBuffer::kSelection)) { return; -#endif + } base::string16 text(ASCIIToUTF16("Standard")), text_result; base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); @@ -753,18 +745,28 @@ TYPED_TEST(ClipboardTest, ReadAvailablePlatformSpecificFormatNamesTest) { EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("public.utf8-plain-text"))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("NSStringPboardType"))); EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(2)); -#elif defined(USE_X11) +#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && \ + !BUILDFLAG(IS_CHROMECAST) && !BUILDFLAG(IS_LACROS) EXPECT_THAT(raw_types, Contains(ASCIIToUTF16(kMimeTypeText))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("TEXT"))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("STRING"))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("UTF8_STRING"))); +#if defined(USE_OZONE) + if (features::IsUsingOzonePlatform()) { + EXPECT_THAT(raw_types, Contains(ASCIIToUTF16(kMimeTypeTextUtf8))); + EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(5)); + return; + } +#endif // USE_OZONE +#if defined(USE_X11) + EXPECT_FALSE(features::IsUsingOzonePlatform()); EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(4)); +#endif // USE_X11 #elif defined(OS_WIN) EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("CF_UNICODETEXT"))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("CF_TEXT"))); - EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("CF_LOCALE"))); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16("CF_OEMTEXT"))); - EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(4)); + EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(3)); #elif defined(USE_AURA) || defined(OS_ANDROID) EXPECT_THAT(raw_types, Contains(ASCIIToUTF16(kMimeTypeText))); EXPECT_EQ(raw_types.size(), static_cast<uint64_t>(1)); @@ -829,7 +831,7 @@ TYPED_TEST(ClipboardTest, PlatformSpecificDataTest) { this->clipboard().ReadAsciiText(ClipboardBuffer::kCopyPaste, /* data_dst = */ nullptr, &text_result); EXPECT_EQ(text_result, text); - // Note: Windows will automatically convert CF_TEXT to its UNICODE version. + // Windows will automatically convert CF_TEXT to its UNICODE version. EXPECT_TRUE(this->clipboard().IsFormatAvailable( ClipboardFormatType::GetPlainTextType(), ClipboardBuffer::kCopyPaste, /* data_dst = */ nullptr)); @@ -1017,59 +1019,56 @@ TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { scw.WriteImage(SkBitmap()); } -// DLP is only intended to be used in Chrome OS, so the following DLP related -// tests are only run on Chrome OS. +// Policy controller is only intended to be used in Chrome OS, so the following +// policy related tests are only run on Chrome OS. #if defined(OS_CHROMEOS) -// Test that copy/paste would work normally if the dlp controller didn't +// Test that copy/paste would work normally if the policy controller didn't // restrict the clipboard data. -TYPED_TEST(ClipboardTest, DlpAllowDataRead) { - auto* dlp_controller = MockClipboardDlpController::Init(); +TYPED_TEST(ClipboardTest, PolicyAllowDataRead) { + auto policy_controller = std::make_unique<MockPolicyController>(); const base::string16 kTestText(base::UTF8ToUTF16("World")); { ScopedClipboardWriter writer( ClipboardBuffer::kCopyPaste, - std::make_unique<ClipboardDataEndpoint>(url::Origin())); + std::make_unique<DataTransferEndpoint>(url::Origin())); writer.WriteText(kTestText); } - EXPECT_CALL(*dlp_controller, IsDataReadAllowed) + EXPECT_CALL(*policy_controller, IsDataReadAllowed) .WillRepeatedly(testing::Return(true)); base::string16 read_result; this->clipboard().ReadText(ClipboardBuffer::kCopyPaste, /* data_dst = */ nullptr, &read_result); - ::testing::Mock::VerifyAndClearExpectations(dlp_controller); + ::testing::Mock::VerifyAndClearExpectations(policy_controller.get()); EXPECT_EQ(kTestText, read_result); - MockClipboardDlpController::DeleteInstance(); } -// Test that pasting clipboard data would not work if the dlp controller +// Test that pasting clipboard data would not work if the policy controller // restricted it. -TYPED_TEST(ClipboardTest, DlpDisallow_ReadText) { - auto* dlp_controller = MockClipboardDlpController::Init(); +TYPED_TEST(ClipboardTest, PolicyDisallow_ReadText) { + auto policy_controller = std::make_unique<MockPolicyController>(); const base::string16 kTestText(base::UTF8ToUTF16("World")); { ScopedClipboardWriter writer( ClipboardBuffer::kCopyPaste, - std::make_unique<ClipboardDataEndpoint>(url::Origin())); + std::make_unique<DataTransferEndpoint>(url::Origin())); writer.WriteText(kTestText); } - EXPECT_CALL(*dlp_controller, IsDataReadAllowed) + EXPECT_CALL(*policy_controller, IsDataReadAllowed) .WillRepeatedly(testing::Return(false)); base::string16 read_result; this->clipboard().ReadText(ClipboardBuffer::kCopyPaste, /* data_dst = */ nullptr, &read_result); - ::testing::Mock::VerifyAndClearExpectations(dlp_controller); + ::testing::Mock::VerifyAndClearExpectations(policy_controller.get()); EXPECT_EQ(base::string16(), read_result); - MockClipboardDlpController::DeleteInstance(); } -TYPED_TEST(ClipboardTest, DlpDisallow_ReadImage) { - auto* dlp_controller = MockClipboardDlpController::Init(); - EXPECT_CALL(*dlp_controller, IsDataReadAllowed) +TYPED_TEST(ClipboardTest, PolicyDisallow_ReadImage) { + auto policy_controller = std::make_unique<MockPolicyController>(); + EXPECT_CALL(*policy_controller, IsDataReadAllowed) .WillRepeatedly(testing::Return(false)); const SkBitmap& image = clipboard_test_util::ReadImage(&this->clipboard()); - ::testing::Mock::VerifyAndClearExpectations(dlp_controller); + ::testing::Mock::VerifyAndClearExpectations(policy_controller.get()); EXPECT_EQ(true, image.empty()); - MockClipboardDlpController::DeleteInstance(); } #endif // defined(OS_CHROMEOS) diff --git a/chromium/ui/base/clipboard/clipboard_util_win.cc b/chromium/ui/base/clipboard/clipboard_util_win.cc index 708b5693bd5..8c6486c0212 100644 --- a/chromium/ui/base/clipboard/clipboard_util_win.cc +++ b/chromium/ui/base/clipboard/clipboard_util_win.cc @@ -67,9 +67,9 @@ bool GetUrlFromHDrop(IDataObject* data_object, if (0 == _wcsicmp(PathFindExtensionW(filename), L".url") && GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, url_buffer, base::size(url_buffer), filename)) { - *url = GURL(url_buffer); + *url = GURL(base::AsStringPiece16(url_buffer)); PathRemoveExtension(filename); - title->assign(PathFindFileName(filename)); + title->assign(base::as_u16cstr(PathFindFileName(filename))); success = url->is_valid(); } } @@ -112,7 +112,7 @@ bool ContainsFilePathCaseInsensitive( // emails with the same subject line are dragged out of Outlook.exe). // |uniquifier| is incremented on encountering a non-unique file name. base::FilePath GetUniqueVirtualFilename( - const base::string16& candidate_name, + const std::wstring& candidate_name, const std::vector<base::FilePath>& existing_filenames, unsigned int* uniquifier) { // Remove any possible filepath components/separators that drag source may @@ -122,9 +122,9 @@ base::FilePath GetUniqueVirtualFilename( // To mitigate against running up against MAX_PATH limitations (temp files // failing to be created), truncate the display name. const size_t kTruncatedDisplayNameLength = 128; - const base::string16 extension = unique_name.Extension(); + const std::wstring extension = unique_name.Extension(); unique_name = unique_name.RemoveExtension(); - base::string16 truncated = unique_name.value(); + std::wstring truncated = unique_name.value(); if (truncated.length() > kTruncatedDisplayNameLength) { truncated.erase(kTruncatedDisplayNameLength); unique_name = base::FilePath(truncated); @@ -133,7 +133,7 @@ base::FilePath GetUniqueVirtualFilename( // Replace any file name illegal characters. unique_name = net::GenerateFileName(GURL(), std::string(), std::string(), - base::UTF16ToUTF8(unique_name.value()), + base::WideToUTF8(unique_name.value()), std::string(), std::string()); // Make the file name unique. This is more involved than just marching through @@ -348,11 +348,11 @@ HGLOBAL CopyFileContentsToHGlobal(IDataObject* data_object, LONG index) { return hdata; } -base::string16 ConvertString(const char* string) { +std::wstring ConvertString(const char* string) { return base::UTF8ToWide(string); } -base::string16 ConvertString(const wchar_t* string) { +std::wstring ConvertString(const wchar_t* string) { return string; } @@ -424,7 +424,7 @@ bool GetVirtualFilenames(IDataObject* data_object, template <typename FileGroupDescriptorType> bool GetFileNameFromFirstDescriptor(IDataObject* data_object, - base::string16* filename) { + std::wstring* filename) { STGMEDIUM medium; if (!FileGroupDescriptorData<FileGroupDescriptorType>::get(data_object, @@ -505,7 +505,7 @@ bool ClipboardUtil::GetUrl(IDataObject* data_object, { // Mozilla URL format or Unicode URL base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); - SplitUrlAndTitle(data.get(), url, title); + SplitUrlAndTitle(base::WideToUTF16(data.get()), url, title); } ReleaseStgMedium(&store); return url->is_valid(); @@ -515,14 +515,14 @@ bool ClipboardUtil::GetUrl(IDataObject* data_object, { // URL using ASCII base::win::ScopedHGlobal<char*> data(store.hGlobal); - SplitUrlAndTitle(base::UTF8ToWide(data.get()), url, title); + SplitUrlAndTitle(base::UTF8ToUTF16(data.get()), url, title); } ReleaseStgMedium(&store); return url->is_valid(); } if (convert_filenames) { - std::vector<base::string16> filenames; + std::vector<std::wstring> filenames; if (!GetFilenames(data_object, &filenames)) return false; DCHECK_GT(filenames.size(), 0U); @@ -534,7 +534,7 @@ bool ClipboardUtil::GetUrl(IDataObject* data_object, } bool ClipboardUtil::GetFilenames(IDataObject* data_object, - std::vector<base::string16>* filenames) { + std::vector<std::wstring>* filenames) { DCHECK(data_object && filenames); if (!HasFilenames(data_object)) return false; @@ -646,7 +646,7 @@ bool ClipboardUtil::GetPlainText(IDataObject* data_object, { // Unicode text base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); - plain_text->assign(data.get()); + plain_text->assign(base::as_u16cstr(data.get())); } ReleaseStgMedium(&store); return true; @@ -656,7 +656,7 @@ bool ClipboardUtil::GetPlainText(IDataObject* data_object, { // ASCII text base::win::ScopedHGlobal<char*> data(store.hGlobal); - plain_text->assign(base::UTF8ToWide(data.get())); + plain_text->assign(base::UTF8ToUTF16(data.get())); } ReleaseStgMedium(&store); return true; @@ -686,7 +686,7 @@ bool ClipboardUtil::GetHtml(IDataObject* data_object, std::string html_utf8; CFHtmlToHtml(std::string(data.get(), data.Size()), &html_utf8, base_url); - html->assign(base::UTF8ToWide(html_utf8)); + html->assign(base::UTF8ToUTF16(html_utf8)); } ReleaseStgMedium(&store); return true; @@ -701,14 +701,14 @@ bool ClipboardUtil::GetHtml(IDataObject* data_object, { // text/html base::win::ScopedHGlobal<wchar_t*> data(store.hGlobal); - html->assign(data.get()); + html->assign(base::as_u16cstr(data.get())); } ReleaseStgMedium(&store); return true; } bool ClipboardUtil::GetFileContents(IDataObject* data_object, - base::string16* filename, + std::wstring* filename, std::string* file_contents) { DCHECK(data_object && filename && file_contents); if (!HasFileContents(data_object)) diff --git a/chromium/ui/base/clipboard/clipboard_util_win.h b/chromium/ui/base/clipboard/clipboard_util_win.h index a1e8d5438b0..2c0af5d665c 100644 --- a/chromium/ui/base/clipboard/clipboard_util_win.h +++ b/chromium/ui/base/clipboard/clipboard_util_win.h @@ -45,7 +45,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardUtil { bool convert_filenames); // Only returns true if |*filenames| is not empty. static bool GetFilenames(IDataObject* data_object, - std::vector<base::string16>* filenames); + std::vector<std::wstring>* filenames); // Fills a vector of display names of "virtual files" in the data store, but // does not actually retrieve the file contents. Display names are assured to @@ -78,7 +78,7 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardUtil { base::string16* text_html, std::string* base_url); static bool GetFileContents(IDataObject* data_object, - base::string16* filename, + std::wstring* filename, std::string* file_contents); // This represents custom MIME types a web page might set to transport its // own types of data for drag and drop. It is sandboxed in its own CLIPFORMAT diff --git a/chromium/ui/base/clipboard/clipboard_win.cc b/chromium/ui/base/clipboard/clipboard_win.cc index 260858079f2..344b847b0e2 100644 --- a/chromium/ui/base/clipboard/clipboard_win.cc +++ b/chromium/ui/base/clipboard/clipboard_win.cc @@ -30,10 +30,10 @@ #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_util_win.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/size.h" @@ -251,7 +251,7 @@ uint64_t ClipboardWin::GetSequenceNumber(ClipboardBuffer buffer) const { bool ClipboardWin::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); return ::IsClipboardFormatAvailable(format.ToFormatEtc().cfFormat) != FALSE; } @@ -269,7 +269,7 @@ void ClipboardWin::Clear(ClipboardBuffer buffer) { // platforms. void ClipboardWin::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(types); @@ -305,7 +305,7 @@ void ClipboardWin::ReadAvailableTypes( std::vector<base::string16> ClipboardWin::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { int count = ::CountClipboardFormats(); if (!count) return {}; @@ -331,7 +331,7 @@ ClipboardWin::ReadAvailablePlatformSpecificFormatNames( // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); RecordRead(ClipboardFormatMetric::kText); @@ -360,7 +360,7 @@ void ClipboardWin::ReadText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); RecordRead(ClipboardFormatMetric::kText); @@ -389,7 +389,7 @@ void ClipboardWin::ReadAsciiText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -450,7 +450,7 @@ void ClipboardWin::ReadHTML(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); RecordRead(ClipboardFormatMetric::kSvg); @@ -466,7 +466,7 @@ void ClipboardWin::ReadSvg(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); RecordRead(ClipboardFormatMetric::kRtf); @@ -478,7 +478,7 @@ void ClipboardWin::ReadRTF(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer)); @@ -488,7 +488,7 @@ void ClipboardWin::ReadImage(ClipboardBuffer buffer, // platforms. void ClipboardWin::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); RecordRead(ClipboardFormatMetric::kCustomData); @@ -509,7 +509,7 @@ void ClipboardWin::ReadCustomData(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. -void ClipboardWin::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardWin::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { RecordRead(ClipboardFormatMetric::kBookmark); @@ -540,7 +540,7 @@ void ClipboardWin::ReadBookmark(const ClipboardDataEndpoint* data_dst, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardWin::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { RecordRead(ClipboardFormatMetric::kData); if (!result) { @@ -566,7 +566,7 @@ void ClipboardWin::ReadData(const ClipboardFormatType& format, void ClipboardWin::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); ScopedClipboard clipboard; @@ -584,7 +584,7 @@ void ClipboardWin::WritePortableRepresentations( void ClipboardWin::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); ScopedClipboard clipboard; @@ -789,7 +789,7 @@ SkBitmap ClipboardWin::ReadImageInternal(ClipboardBuffer buffer) const { // Since Windows uses premultiplied alpha, we scan for instances where // (R, G, B) > A. If there are any invalid premultiplied colors in the image, // we assume the alpha channel contains garbage and force the bitmap to be - // opaque as well. Note that this heuristic will fail on a transparent bitmap + // opaque as well. This heuristic will fail on a transparent bitmap // containing only black pixels... SkPixmap device_pixels(SkImageInfo::MakeN32Premul(bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight), diff --git a/chromium/ui/base/clipboard/clipboard_win.h b/chromium/ui/base/clipboard/clipboard_win.h index 8fbe2722bff..e3532315b68 100644 --- a/chromium/ui/base/clipboard/clipboard_win.h +++ b/chromium/ui/base/clipboard/clipboard_win.h @@ -38,53 +38,53 @@ class ClipboardWin : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/clipboard_x11.cc b/chromium/ui/base/clipboard/clipboard_x11.cc index a1fbfcae549..13966680032 100644 --- a/chromium/ui/base/clipboard/clipboard_x11.cc +++ b/chromium/ui/base/clipboard/clipboard_x11.cc @@ -22,10 +22,10 @@ #include "base/strings/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/nine_image_painter_factory.h" #include "ui/base/x/selection_owner.h" #include "ui/base/x/selection_requestor.h" @@ -37,7 +37,6 @@ #include "ui/gfx/geometry/size.h" #include "ui/gfx/x/connection.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/xfixes.h" #include "ui/gfx/x/xproto.h" @@ -501,7 +500,7 @@ uint64_t ClipboardX11::GetSequenceNumber(ClipboardBuffer buffer) const { bool ClipboardX11::IsFormatAvailable( const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); @@ -523,7 +522,7 @@ void ClipboardX11::Clear(ClipboardBuffer buffer) { // platforms. void ClipboardX11::ReadAvailableTypes( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const { DCHECK(CalledOnValidThread()); DCHECK(types); @@ -553,7 +552,7 @@ void ClipboardX11::ReadAvailableTypes( std::vector<base::string16> ClipboardX11::ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const { + const DataTransferEndpoint* data_dst) const { DCHECK(CalledOnValidThread()); // Copy target_list(), so that XGetAtomNames can get a non-const Atom*. @@ -580,7 +579,7 @@ ClipboardX11::ReadAvailablePlatformSpecificFormatNames( // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kText); @@ -596,7 +595,7 @@ void ClipboardX11::ReadText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kText); @@ -612,7 +611,7 @@ void ClipboardX11::ReadAsciiText(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, @@ -640,7 +639,7 @@ void ClipboardX11::ReadHTML(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kSvg); @@ -658,7 +657,7 @@ void ClipboardX11::ReadSvg(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kRtf); @@ -673,7 +672,7 @@ void ClipboardX11::ReadRTF(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const { DCHECK(IsSupportedClipboardBuffer(buffer)); RecordRead(ClipboardFormatMetric::kImage); @@ -684,7 +683,7 @@ void ClipboardX11::ReadImage(ClipboardBuffer buffer, // platforms. void ClipboardX11::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kCustomData); @@ -698,7 +697,7 @@ void ClipboardX11::ReadCustomData(ClipboardBuffer buffer, // |data_dst| is not used. It's only passed to be consistent with other // platforms. -void ClipboardX11::ReadBookmark(const ClipboardDataEndpoint* data_dst, +void ClipboardX11::ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); @@ -709,7 +708,7 @@ void ClipboardX11::ReadBookmark(const ClipboardDataEndpoint* data_dst, // |data_dst| is not used. It's only passed to be consistent with other // platforms. void ClipboardX11::ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const { DCHECK(CalledOnValidThread()); RecordRead(ClipboardFormatMetric::kData); @@ -731,7 +730,7 @@ bool ClipboardX11::IsSelectionBufferAvailable() const { void ClipboardX11::WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); @@ -760,7 +759,7 @@ void ClipboardX11::WritePortableRepresentations( void ClipboardX11::WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) { + std::unique_ptr<DataTransferEndpoint> data_src) { DCHECK(CalledOnValidThread()); DCHECK(IsSupportedClipboardBuffer(buffer)); diff --git a/chromium/ui/base/clipboard/clipboard_x11.h b/chromium/ui/base/clipboard/clipboard_x11.h index cae0a85a29b..803b4408686 100644 --- a/chromium/ui/base/clipboard/clipboard_x11.h +++ b/chromium/ui/base/clipboard/clipboard_x11.h @@ -27,44 +27,44 @@ class ClipboardX11 : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::vector<base::string16>* types) const override; std::vector<base::string16> ReadAvailablePlatformSpecificFormatNames( ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst) const override; + const DataTransferEndpoint* data_dst) const override; void ReadText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadAsciiText(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadHTML(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* markup, std::string* src_url, uint32_t* fragment_start, uint32_t* fragment_end) const override; void ReadSvg(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; void ReadRTF(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; void ReadImage(ClipboardBuffer buffer, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, ReadImageCallback callback) const override; void ReadCustomData(ClipboardBuffer buffer, const base::string16& type, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, base::string16* result) const override; - void ReadBookmark(const ClipboardDataEndpoint* data_dst, + void ReadBookmark(const DataTransferEndpoint* data_dst, base::string16* title, std::string* url) const override; void ReadData(const ClipboardFormatType& format, - const ClipboardDataEndpoint* data_dst, + const DataTransferEndpoint* data_dst, std::string* result) const override; #if defined(USE_OZONE) bool IsSelectionBufferAvailable() const override; @@ -72,11 +72,11 @@ class ClipboardX11 : public Clipboard { void WritePortableRepresentations( ClipboardBuffer buffer, const ObjectMap& objects, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WritePlatformRepresentations( ClipboardBuffer buffer, std::vector<Clipboard::PlatformRepresentation> platform_representations, - std::unique_ptr<ClipboardDataEndpoint> data_src) override; + std::unique_ptr<DataTransferEndpoint> data_src) override; void WriteText(const char* text_data, size_t text_len) override; void WriteHTML(const char* markup_data, size_t markup_len, diff --git a/chromium/ui/base/clipboard/scoped_clipboard_writer.cc b/chromium/ui/base/clipboard/scoped_clipboard_writer.cc index f89d396d74e..d49f3ff31a4 100644 --- a/chromium/ui/base/clipboard/scoped_clipboard_writer.cc +++ b/chromium/ui/base/clipboard/scoped_clipboard_writer.cc @@ -19,7 +19,7 @@ namespace ui { ScopedClipboardWriter::ScopedClipboardWriter( ClipboardBuffer buffer, - std::unique_ptr<ClipboardDataEndpoint> data_src) + std::unique_ptr<DataTransferEndpoint> data_src) : buffer_(buffer), data_src_(std::move(data_src)) {} ScopedClipboardWriter::~ScopedClipboardWriter() { diff --git a/chromium/ui/base/clipboard/scoped_clipboard_writer.h b/chromium/ui/base/clipboard/scoped_clipboard_writer.h index bac40ada9ee..1dd0bae74fe 100644 --- a/chromium/ui/base/clipboard/scoped_clipboard_writer.h +++ b/chromium/ui/base/clipboard/scoped_clipboard_writer.h @@ -12,7 +12,7 @@ #include "base/strings/string16.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard.h" -#include "ui/base/clipboard/clipboard_data_endpoint.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" namespace base { class Pickle; @@ -33,10 +33,10 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ScopedClipboardWriter { // Create an instance that is a simple wrapper around the clipboard of the // given buffer with an optional parameter indicating the source of the data. // TODO(crbug.com/1103193): change its references to use - // ClipboardDataEndpoint, if possible. + // DataTransferEndpoint, if possible. explicit ScopedClipboardWriter( ClipboardBuffer buffer, - std::unique_ptr<ClipboardDataEndpoint> src = nullptr); + std::unique_ptr<DataTransferEndpoint> src = nullptr); ~ScopedClipboardWriter(); @@ -98,8 +98,8 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ScopedClipboardWriter { // The source of the data written in ScopedClipboardWriter, nullptr means it's // not set, or the source of the data can't be represented by - // ClipboardDataEndpoint. - std::unique_ptr<ClipboardDataEndpoint> data_src_ = nullptr; + // DataTransferEndpoint. + std::unique_ptr<DataTransferEndpoint> data_src_ = nullptr; DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); }; diff --git a/chromium/ui/base/cocoa/DIR_METADATA b/chromium/ui/base/cocoa/DIR_METADATA new file mode 100644 index 00000000000..2769d07edc7 --- /dev/null +++ b/chromium/ui/base/cocoa/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI" +}
\ No newline at end of file diff --git a/chromium/ui/base/cocoa/OWNERS b/chromium/ui/base/cocoa/OWNERS index 27991830902..f5de6bf4af9 100644 --- a/chromium/ui/base/cocoa/OWNERS +++ b/chromium/ui/base/cocoa/OWNERS @@ -2,5 +2,3 @@ avi@chromium.org rsesek@chromium.org tapted@chromium.org thakis@chromium.org - -# COMPONENT: UI diff --git a/chromium/ui/base/cocoa/permissions_utils.h b/chromium/ui/base/cocoa/permissions_utils.h index a8ec034cdf2..f410268162c 100644 --- a/chromium/ui/base/cocoa/permissions_utils.h +++ b/chromium/ui/base/cocoa/permissions_utils.h @@ -16,6 +16,15 @@ namespace ui { // has been granted. COMPONENT_EXPORT(UI_BASE) bool IsScreenCaptureAllowed(); +// Heuristic to prompt the user if they have never been prompted for permission. +// Starting on macOS 10.15, not only can we not tell if we have has permission +// granted, we also can't tell if we have requested the permission before. We +// must try capture a stream and the OS will show a modal dialog asking the user +// for permission if Chrome is not in the permission app list, then return +// a stream based on whether permission is granted. +// Returns whether or not permission was granted. +COMPONENT_EXPORT(UI_BASE) bool TryPromptUserForScreenCapture(); + } // namespace ui #endif // UI_BASE_COCOA_PERMISSIONS_UTILS_H_ diff --git a/chromium/ui/base/cocoa/permissions_utils.mm b/chromium/ui/base/cocoa/permissions_utils.mm index ae34a26d827..bea5c6477ea 100644 --- a/chromium/ui/base/cocoa/permissions_utils.mm +++ b/chromium/ui/base/cocoa/permissions_utils.mm @@ -8,6 +8,7 @@ #include <Foundation/Foundation.h> #include "base/mac/foundation_util.h" +#include "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" namespace ui { @@ -16,7 +17,7 @@ namespace ui { // or dock window running on another process is visible. // See https://crbug.com/993692. bool IsScreenCaptureAllowed() { - if (@available(macOS 10.15, *)) { + if (base::mac::IsAtLeastOS10_15()) { base::ScopedCFTypeRef<CFArrayRef> window_list( CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID)); int current_pid = [[NSProcessInfo processInfo] processIdentifier]; @@ -49,4 +50,22 @@ bool IsScreenCaptureAllowed() { return true; } +bool TryPromptUserForScreenCapture() { + if (base::mac::IsAtLeastOS10_15()) { + // On 10.15+, macOS will show the permissions prompt for Screen Recording + // if we request to create a display stream and our application is not + // in the applications list in System permissions. Stream creation will + // fail if the user denies permission, or if our application is already + // in the system permssion and is unchecked. + base::ScopedCFTypeRef<CGDisplayStreamRef> stream(CGDisplayStreamCreate( + CGMainDisplayID(), 1, 1, 'BGRA', nullptr, + ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, + IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef){ + })); + return stream != nullptr; + } else { + return true; + } +} + } // namespace ui diff --git a/chromium/ui/base/cocoa/touch_bar_util.h b/chromium/ui/base/cocoa/touch_bar_util.h index f69d2a392f1..19293c6f93a 100644 --- a/chromium/ui/base/cocoa/touch_bar_util.h +++ b/chromium/ui/base/cocoa/touch_bar_util.h @@ -31,21 +31,6 @@ enum TouchBarAction { // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram. COMPONENT_EXPORT(UI_BASE) void LogTouchBarUMA(TouchBarAction command); -// Returns the NSTouchBar Class. -COMPONENT_EXPORT(UI_BASE) Class NSTouchBar(); - -// Returns the NSCustomTouchBarItem Class. -COMPONENT_EXPORT(UI_BASE) Class NSCustomTouchBarItem(); - -// Returns the NSGroupTouchBarItem Class. -COMPONENT_EXPORT(UI_BASE) Class NSGroupTouchBarItem(); - -// Returns a stylized blue button for the touch bar. The button performs -// |action| from the |target|. -API_AVAILABLE(macosx(10.12.2)) -COMPONENT_EXPORT(UI_BASE) -NSButton* GetBlueTouchBarButton(NSString* title, id target, SEL action); - // Creates a touch bar identifier with the given |id|. COMPONENT_EXPORT(UI_BASE) NSString* GetTouchBarId(NSString* touch_bar_id); diff --git a/chromium/ui/base/cocoa/touch_bar_util.mm b/chromium/ui/base/cocoa/touch_bar_util.mm index 7125569488e..47c213021c9 100644 --- a/chromium/ui/base/cocoa/touch_bar_util.mm +++ b/chromium/ui/base/cocoa/touch_bar_util.mm @@ -15,28 +15,6 @@ void LogTouchBarUMA(TouchBarAction command) { TOUCH_BAR_ACTION_COUNT); } -Class NSTouchBar() { - return NSClassFromString(@"NSTouchBar"); -} - -Class NSCustomTouchBarItem() { - return NSClassFromString(@"NSCustomTouchBarItem"); -} - -Class NSGroupTouchBarItem() { - return NSClassFromString(@"NSGroupTouchBarItem"); -} - -NSButton* GetBlueTouchBarButton(NSString* title, id target, SEL action) { - NSButton* button = - [NSButton buttonWithTitle:title target:target action:action]; - [button setBezelColor:[NSColor colorWithSRGBRed:0.168 - green:0.51 - blue:0.843 - alpha:1.0]]; - return button; -} - NSString* GetTouchBarId(NSString* touch_bar_id) { NSString* chrome_bundle_id = base::SysUTF8ToNSString(base::mac::BaseBundleID()); diff --git a/chromium/ui/base/cocoa/views_hostable.h b/chromium/ui/base/cocoa/views_hostable.h index 9a9ae9324a5..00595d34ef3 100644 --- a/chromium/ui/base/cocoa/views_hostable.h +++ b/chromium/ui/base/cocoa/views_hostable.h @@ -74,6 +74,9 @@ class ViewsHostableView { virtual void ViewsHostableSetParentAccessible( gfx::NativeViewAccessible parent_accessibility_element) = 0; + // Get the WebContentsView's parent accessibility element. + virtual gfx::NativeViewAccessible ViewsHostableGetParentAccessible() = 0; + // Retrieve the WebContentsView's accessibility element. virtual gfx::NativeViewAccessible ViewsHostableGetAccessibilityElement() = 0; }; diff --git a/chromium/ui/base/cursor/BUILD.gn b/chromium/ui/base/cursor/BUILD.gn index f4e3f83c604..947ff85b6ef 100644 --- a/chromium/ui/base/cursor/BUILD.gn +++ b/chromium/ui/base/cursor/BUILD.gn @@ -55,8 +55,6 @@ if (use_aura) { "cursor_util.h", "cursors_aura.cc", "cursors_aura.h", - "image_cursors.cc", - "image_cursors.h", ] defines = [ "IS_UI_BASE_CURSOR_IMPL" ] public_deps = [ @@ -92,6 +90,7 @@ if (use_aura) { "//skia", "//ui/gfx/geometry", ] + deps += [ "//build:chromeos_buildflags" ] } if (use_x11 || use_ozone) { @@ -106,26 +105,39 @@ if (use_aura) { source_set("unittests") { testonly = true sources = [] - deps = [ "//testing/gtest" ] + deps = [ + ":cursor_base", + "//testing/gtest", + "//ui/base/cursor/mojom:cursor_type", + ] if (!is_ios) { sources += [ "cursor_unittest.cc" ] deps += [ - ":cursor_base", "//skia", - "//ui/base/cursor/mojom:cursor_type", "//ui/gfx:geometry_skia", "//ui/gfx/geometry", ] } if (use_aura) { - sources += [ "cursor_util_unittest.cc" ] + sources += [ + "cursor_loader_unittest.cc", + "cursor_util_unittest.cc", + ] deps += [ ":cursor", "//skia", "//ui/gfx/geometry", ] + + if (use_x11) { + deps += [ + "//skia", + "//ui/base/x", + "//ui/gfx/geometry", + ] + } } if (use_ozone) { @@ -133,7 +145,7 @@ source_set("unittests") { deps += [ ":cursor", "//base", - "//ui/base/cursor/mojom:cursor_type", + "//build:chromeos_buildflags", ] } } diff --git a/chromium/ui/base/cursor/DIR_METADATA b/chromium/ui/base/cursor/DIR_METADATA new file mode 100644 index 00000000000..198db497480 --- /dev/null +++ b/chromium/ui/base/cursor/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals>Input" +} diff --git a/chromium/ui/base/cursor/OWNERS b/chromium/ui/base/cursor/OWNERS index 776ce1a5de3..81aec02d68a 100644 --- a/chromium/ui/base/cursor/OWNERS +++ b/chromium/ui/base/cursor/OWNERS @@ -1 +1 @@ -# COMPONENT: Internal>Input +hferreiro@igalia.com diff --git a/chromium/ui/base/cursor/cursor.h b/chromium/ui/base/cursor/cursor.h index 804ba96c337..1c54756715d 100644 --- a/chromium/ui/base/cursor/cursor.h +++ b/chromium/ui/base/cursor/cursor.h @@ -20,6 +20,8 @@ namespace ui { #if defined(OS_WIN) typedef ::HCURSOR PlatformCursor; #else +// NOTE: On Ozone platforms, the type is chosen at runtime, and is either +// X11Cursor* or BitmapCursorOzone*. typedef void* PlatformCursor; #endif diff --git a/chromium/ui/base/cursor/cursor_factory.cc b/chromium/ui/base/cursor/cursor_factory.cc index 43645a5d446..5a987bf501a 100644 --- a/chromium/ui/base/cursor/cursor_factory.cc +++ b/chromium/ui/base/cursor/cursor_factory.cc @@ -39,13 +39,15 @@ base::Optional<PlatformCursor> CursorFactory::GetDefaultCursor( return base::nullopt; } -PlatformCursor CursorFactory::CreateImageCursor(const SkBitmap& bitmap, +PlatformCursor CursorFactory::CreateImageCursor(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot) { NOTIMPLEMENTED(); return 0; } PlatformCursor CursorFactory::CreateAnimatedCursor( + mojom::CursorType type, const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) { diff --git a/chromium/ui/base/cursor/cursor_factory.h b/chromium/ui/base/cursor/cursor_factory.h index f038a422819..57c70c9e60a 100644 --- a/chromium/ui/base/cursor/cursor_factory.h +++ b/chromium/ui/base/cursor/cursor_factory.h @@ -36,17 +36,21 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR_BASE) CursorFactory { virtual base::Optional<PlatformCursor> GetDefaultCursor( mojom::CursorType type); - // Return a image cursor from the specified image & hotspot. Image cursors - // are referenced counted and have an initial refcount of 1. Therefore, each - // CreateImageCursor call must be matched with a call to UnrefImageCursor. - virtual PlatformCursor CreateImageCursor(const SkBitmap& bitmap, + // Return an image cursor for the specified |type| with a |bitmap| and + // |hotspot|. Image cursors are referenced counted and have an initial + // refcount of 1. Therefore, each CreateImageCursor call must be matched with + // a call to UnrefImageCursor. + virtual PlatformCursor CreateImageCursor(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot); // Return a animated cursor from the specified image & hotspot. Animated // cursors are referenced counted and have an initial refcount of 1. // Therefore, each CreateAnimatedCursor call must be matched with a call to // UnrefImageCursor. + // |frame_delay_ms| is the delay between frames in millisecond. virtual PlatformCursor CreateAnimatedCursor( + mojom::CursorType type, const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms); diff --git a/chromium/ui/base/cursor/cursor_loader.h b/chromium/ui/base/cursor/cursor_loader.h index 2553c54e488..0c516d7fa7c 100644 --- a/chromium/ui/base/cursor/cursor_loader.h +++ b/chromium/ui/base/cursor/cursor_loader.h @@ -5,71 +5,70 @@ #ifndef UI_BASE_CURSOR_CURSOR_LOADER_H_ #define UI_BASE_CURSOR_CURSOR_LOADER_H_ +#include <memory> + #include "base/component_export.h" -#include "base/macros.h" +#include "ui/base/cursor/cursor_size.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" #include "ui/display/display.h" #include "ui/gfx/native_widget_types.h" -namespace gfx { -class Point; -} - namespace ui { class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoader { public: - CursorLoader() : scale_(1.f), rotation_(display::Display::ROTATE_0) {} - virtual ~CursorLoader() {} + CursorLoader() = default; + CursorLoader(const CursorLoader&) = delete; + CursorLoader& operator=(const CursorLoader&) = delete; + virtual ~CursorLoader() = default; + // Returns the rotation and scale of the currently loaded cursor. display::Display::Rotation rotation() const { return rotation_; } + float scale() const { return scale_; } - void set_rotation(display::Display::Rotation rotation) { - rotation_ = rotation; - } + // Sets the rotation and scale the cursors are loaded for. + // Returns true if the cursor image was reloaded. + bool SetDisplayData(display::Display::Rotation rotation, float scale) { + if (rotation_ == rotation && scale_ == scale) + return false; - // Returns the current scale of the mouse cursor icon. - float scale() const { - return scale_; - } - - // Sets the scale of the mouse cursor icon. - void set_scale(const float scale) { + rotation_ = rotation; scale_ = scale; + UnloadCursors(); + return true; } - // Creates a cursor from an image resource and puts it in the cursor map. - virtual void LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) = 0; + // Returns the size of the currently loaded cursor. + CursorSize size() const { return size_; } - // Creates an animated cursor from an image resource and puts it in the - // cursor map. The image is assumed to be a concatenation of animation frames - // from left to right. Also, each frame is assumed to be square - // (width == height). - // |frame_delay_ms| is the delay between frames in millisecond. - virtual void LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) = 0; + // Sets the size of the mouse cursor icon. + void set_size(CursorSize size) { + if (size_ == size) + return; - // Unloads all the cursors. - virtual void UnloadAll() = 0; + size_ = size; + UnloadCursors(); + } // Sets the platform cursor based on the native type of |cursor|. virtual void SetPlatformCursor(gfx::NativeCursor* cursor) = 0; // Creates a CursorLoader. - static CursorLoader* Create(); + static std::unique_ptr<CursorLoader> Create(bool use_platform_cursors = true); + + protected: + // Resets the cursor cache. + virtual void UnloadCursors() = 0; private: // The current scale of the mouse cursor icon. - float scale_; + float scale_ = 1.0f; // The current rotation of the mouse cursor icon. - display::Display::Rotation rotation_; + display::Display::Rotation rotation_ = display::Display::ROTATE_0; - DISALLOW_COPY_AND_ASSIGN(CursorLoader); + // The preferred size of the mouse cursor icon. + CursorSize size_ = CursorSize::kNormal; }; } // namespace ui diff --git a/chromium/ui/base/cursor/cursor_loader_ozone.cc b/chromium/ui/base/cursor/cursor_loader_ozone.cc index 6df16b5f1e7..6d386672c9e 100644 --- a/chromium/ui/base/cursor/cursor_loader_ozone.cc +++ b/chromium/ui/base/cursor/cursor_loader_ozone.cc @@ -4,50 +4,37 @@ #include "ui/base/cursor/cursor_loader_ozone.h" +#include <memory> #include <vector> +#include "base/ranges/algorithm.h" #include "ui/base/cursor/cursor_factory.h" #include "ui/base/cursor/cursor_size.h" #include "ui/base/cursor/cursor_util.h" #include "ui/base/cursor/cursors_aura.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" +#include "ui/gfx/geometry/point.h" namespace ui { -CursorLoaderOzone::CursorLoaderOzone() { - factory_ = CursorFactory::GetInstance(); -} +namespace { -CursorLoaderOzone::~CursorLoaderOzone() { - UnloadAll(); -} +constexpr mojom::CursorType kAnimatedCursorTypes[] = { + mojom::CursorType::kWait, mojom::CursorType::kProgress}; -void CursorLoaderOzone::LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) { - SkBitmap bitmap; - gfx::Point hotspot = hot; - - GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); - - image_cursors_[id] = factory_->CreateImageCursor(bitmap, hotspot); -} +const int kAnimatedCursorFrameDelayMs = 25; -void CursorLoaderOzone::LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) { - std::vector<SkBitmap> bitmaps; - gfx::Point hotspot = hot; +} // namespace - GetAnimatedCursorBitmaps( - resource_id, scale(), rotation(), &hotspot, &bitmaps); +CursorLoaderOzone::CursorLoaderOzone(bool use_platform_cursors) + : use_platform_cursors_(use_platform_cursors), + factory_(CursorFactory::GetInstance()) {} - image_cursors_[id] = - factory_->CreateAnimatedCursor(bitmaps, hotspot, frame_delay_ms); +CursorLoaderOzone::~CursorLoaderOzone() { + UnloadCursors(); } -void CursorLoaderOzone::UnloadAll() { +void CursorLoaderOzone::UnloadCursors() { for (const auto& image_cursor : image_cursors_) factory_->UnrefImageCursor(image_cursor.second); image_cursors_.clear(); @@ -63,43 +50,63 @@ void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { cursor->SetPlatformCursor(CursorFromType(cursor->type())); } +void CursorLoaderOzone::LoadImageCursor(mojom::CursorType type, + int resource_id, + const gfx::Point& hot) { + gfx::Point hotspot = hot; + if (base::ranges::count(kAnimatedCursorTypes, type) == 0) { + SkBitmap bitmap; + GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); + image_cursors_[type] = factory_->CreateImageCursor(type, bitmap, hotspot); + } else { + std::vector<SkBitmap> bitmaps; + GetAnimatedCursorBitmaps(resource_id, scale(), rotation(), &hotspot, + &bitmaps); + image_cursors_[type] = factory_->CreateAnimatedCursor( + type, bitmaps, hotspot, kAnimatedCursorFrameDelayMs); + } +} + PlatformCursor CursorLoaderOzone::CursorFromType(mojom::CursorType type) { // An image cursor is loaded for this type. if (image_cursors_.count(type)) return image_cursors_[type]; // Check if there's a default platform cursor available. - base::Optional<PlatformCursor> default_cursor = - factory_->GetDefaultCursor(type); - if (default_cursor) - return *default_cursor; + // For the none cursor, we also need to use the platform factory to take + // into account the different ways of creating an invisible cursor. + if (use_platform_cursors_ || type == mojom::CursorType::kNone) { + base::Optional<PlatformCursor> default_cursor = + factory_->GetDefaultCursor(type); + if (default_cursor) + return *default_cursor; + } // Loads the default Aura cursor bitmap for the cursor type. Falls back on // pointer cursor if this fails. - PlatformCursor platform = CreateFallbackCursor(type); + PlatformCursor platform = LoadCursorFromAsset(type); if (!platform && type != mojom::CursorType::kPointer) { platform = CursorFromType(mojom::CursorType::kPointer); factory_->RefImageCursor(platform); image_cursors_[type] = platform; } - DCHECK(platform) << "Failed to load a fallback bitmap for cursor " << type; + DCHECK(platform) << "Failed to load a bitmap for the pointer cursor."; return platform; } // Gets default Aura cursor bitmap/hotspot and creates a PlatformCursor with it. -PlatformCursor CursorLoaderOzone::CreateFallbackCursor(mojom::CursorType type) { +PlatformCursor CursorLoaderOzone::LoadCursorFromAsset(mojom::CursorType type) { int resource_id; - gfx::Point point; - if (ui::GetCursorDataFor(ui::CursorSize::kNormal, type, scale(), &resource_id, - &point)) { - LoadImageCursor(type, resource_id, point); + gfx::Point hotspot; + if (GetCursorDataFor(size(), type, scale(), &resource_id, &hotspot)) { + LoadImageCursor(type, resource_id, hotspot); return image_cursors_[type]; } return nullptr; } -CursorLoader* CursorLoader::Create() { - return new CursorLoaderOzone(); +std::unique_ptr<CursorLoader> CursorLoader::Create(bool use_platform_cursors) { + return std::make_unique<CursorLoaderOzone>(use_platform_cursors); } } // namespace ui diff --git a/chromium/ui/base/cursor/cursor_loader_ozone.h b/chromium/ui/base/cursor/cursor_loader_ozone.h index ccd23a3c9e0..bf1c11f6afb 100644 --- a/chromium/ui/base/cursor/cursor_loader_ozone.h +++ b/chromium/ui/base/cursor/cursor_loader_ozone.h @@ -13,28 +13,35 @@ #include "ui/base/cursor/cursor_loader.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" +namespace gfx { +class Point; +} + namespace ui { class CursorFactory; class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoaderOzone : public CursorLoader { public: - CursorLoaderOzone(); + explicit CursorLoaderOzone(bool use_platform_cursors); ~CursorLoaderOzone() override; // CursorLoader overrides: - void LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) override; - void LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) override; - void UnloadAll() override; void SetPlatformCursor(gfx::NativeCursor* cursor) override; private: + // CursorLoader overrides: + void UnloadCursors() override; + + void LoadImageCursor(mojom::CursorType id, + int resource_id, + const gfx::Point& hot); PlatformCursor CursorFromType(mojom::CursorType type); - PlatformCursor CreateFallbackCursor(mojom::CursorType type); + PlatformCursor LoadCursorFromAsset(mojom::CursorType type); + + // Whether to use cursors provided by the underlying platform (e.g. X11 + // cursors). If false or in the case of a failure, Chromium assets will be + // used instead. + const bool use_platform_cursors_; // Pointers are owned by ResourceBundle and must not be freed here. std::map<mojom::CursorType, PlatformCursor> image_cursors_; diff --git a/chromium/ui/base/cursor/cursor_loader_unittest.cc b/chromium/ui/base/cursor/cursor_loader_unittest.cc new file mode 100644 index 00000000000..67b4c2be1ce --- /dev/null +++ b/chromium/ui/base/cursor/cursor_loader_unittest.cc @@ -0,0 +1,57 @@ +// 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/cursor/cursor_loader.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" + +#if defined(USE_OZONE) +#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" +#endif + +#if defined(USE_X11) +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/x/x11_cursor_factory.h" // nogncheck +#include "ui/gfx/geometry/point.h" +#endif + +namespace ui { + +namespace { + +PlatformCursor LoadInvisibleCursor() { + auto cursor_loader = CursorLoader::Create(); + Cursor cursor(mojom::CursorType::kNone); + cursor_loader->SetPlatformCursor(&cursor); + return cursor.platform(); +} + +} // namespace + +#if !defined(USE_X11) +TEST(CursorLoaderTest, InvisibleCursorOnNotX11) { +#if defined(USE_OZONE) + BitmapCursorFactoryOzone cursor_factory; +#endif + EXPECT_EQ(LoadInvisibleCursor(), nullptr); +} +#endif + +#if defined(USE_X11) +TEST(CursorLoaderTest, InvisibleCursorOnX11) { + X11CursorFactory cursor_factory; + // Building an image cursor with an invalid SkBitmap should return the + // invisible cursor in X11. + auto* invisible_cursor = + cursor_factory.CreateImageCursor({}, SkBitmap(), gfx::Point()); + EXPECT_EQ(LoadInvisibleCursor(), invisible_cursor); + + // Release our refcount on the cursor + cursor_factory.UnrefImageCursor(invisible_cursor); +} +#endif + +} // namespace ui diff --git a/chromium/ui/base/cursor/cursor_loader_win.cc b/chromium/ui/base/cursor/cursor_loader_win.cc index 735568dddc0..392fd85d6f3 100644 --- a/chromium/ui/base/cursor/cursor_loader_win.cc +++ b/chromium/ui/base/cursor/cursor_loader_win.cc @@ -6,6 +6,8 @@ #include <windows.h> +#include <memory> + #include "base/lazy_instance.h" #include "base/notreached.h" #include "ui/base/cursor/cursor.h" @@ -122,8 +124,8 @@ const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) { } // namespace -CursorLoader* CursorLoader::Create() { - return new CursorLoaderWin; +std::unique_ptr<CursorLoader> CursorLoader::Create(bool use_platform_cursors) { + return std::make_unique<CursorLoaderWin>(); } CursorLoaderWin::CursorLoaderWin() { @@ -132,20 +134,7 @@ CursorLoaderWin::CursorLoaderWin() { CursorLoaderWin::~CursorLoaderWin() { } -void CursorLoaderWin::LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) { - // NOTIMPLEMENTED(); -} - -void CursorLoaderWin::LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) { - // NOTIMPLEMENTED(); -} - -void CursorLoaderWin::UnloadAll() { +void CursorLoaderWin::UnloadCursors() { // NOTIMPLEMENTED(); } diff --git a/chromium/ui/base/cursor/cursor_loader_win.h b/chromium/ui/base/cursor/cursor_loader_win.h index bf3ec63c961..cbe7d000138 100644 --- a/chromium/ui/base/cursor/cursor_loader_win.h +++ b/chromium/ui/base/cursor/cursor_loader_win.h @@ -18,14 +18,7 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoaderWin : public CursorLoader { ~CursorLoaderWin() override; // Overridden from CursorLoader: - void LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) override; - void LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) override; - void UnloadAll() override; + void UnloadCursors() override; void SetPlatformCursor(gfx::NativeCursor* cursor) override; // Used to pass the cursor resource module name to the cursor loader. This is diff --git a/chromium/ui/base/cursor/cursor_util.cc b/chromium/ui/base/cursor/cursor_util.cc index a19a4ddcf1e..ee513696649 100644 --- a/chromium/ui/base/cursor/cursor_util.cc +++ b/chromium/ui/base/cursor/cursor_util.cc @@ -133,6 +133,9 @@ void GetAnimatedCursorBitmaps(int resource_id, ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); SkBitmap bitmap = image_rep.GetBitmap(); + + // The image is assumed to be a concatenation of animation frames from left to + // right. Also, each frame is assumed to be square (width == height). int frame_width = bitmap.height(); int frame_height = frame_width; int total_width = bitmap.width(); diff --git a/chromium/ui/base/cursor/cursors_aura.cc b/chromium/ui/base/cursor/cursors_aura.cc index 710fb8dba11..c527ac4d8eb 100644 --- a/chromium/ui/base/cursor/cursors_aura.cc +++ b/chromium/ui/base/cursor/cursors_aura.cc @@ -42,8 +42,6 @@ struct CursorSizeData { const CursorSize id; const CursorData* cursors; const int length; - const CursorData* animated_cursors; - const int animated_length; }; const CursorData kNormalCursors[] = { @@ -127,6 +125,8 @@ const CursorData kNormalCursors[] = { {24, 23}}, {mojom::CursorType::kGrab, IDR_AURA_CURSOR_GRAB, {8, 5}, {16, 10}}, {mojom::CursorType::kGrabbing, IDR_AURA_CURSOR_GRABBING, {9, 9}, {18, 18}}, + {mojom::CursorType::kWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, + {mojom::CursorType::kProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, }; const CursorData kLargeCursors[] = { @@ -233,20 +233,12 @@ const CursorData kLargeCursors[] = { IDR_AURA_CURSOR_BIG_GRABBING, {20, 12}, {40, 24}}, -}; - -const CursorData kAnimatedCursors[] = { - {mojom::CursorType::kWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, - {mojom::CursorType::kProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, + // TODO(https://crbug.com/336867): create IDR_AURA_CURSOR_BIG_THROBBER. }; const CursorSizeData kCursorSizes[] = { - {CursorSize::kNormal, kNormalCursors, base::size(kNormalCursors), - kAnimatedCursors, base::size(kAnimatedCursors)}, - {CursorSize::kLarge, kLargeCursors, base::size(kLargeCursors), - // TODO(yoshiki): Replace animated cursors with big assets. - // crbug.com/247254 - kAnimatedCursors, base::size(kAnimatedCursors)}, + {CursorSize::kNormal, kNormalCursors, base::size(kNormalCursors)}, + {CursorSize::kLarge, kLargeCursors, base::size(kLargeCursors)}, }; const CursorSizeData* GetCursorSizeByType(CursorSize cursor_size) { @@ -302,25 +294,6 @@ bool GetCursorDataFor(CursorSize cursor_size, resource_id, point); } -bool GetAnimatedCursorDataFor(CursorSize cursor_size, - mojom::CursorType id, - float scale_factor, - int* resource_id, - gfx::Point* point) { - const CursorSizeData* cursor_set = GetCursorSizeByType(cursor_size); - if (cursor_set && - SearchTable(cursor_set->animated_cursors, cursor_set->animated_length, id, - scale_factor, resource_id, point)) { - return true; - } - - // Falls back to the default cursor set. - cursor_set = GetCursorSizeByType(ui::CursorSize::kNormal); - DCHECK(cursor_set); - return SearchTable(cursor_set->animated_cursors, cursor_set->animated_length, - id, scale_factor, resource_id, point); -} - SkBitmap GetDefaultBitmap(const Cursor& cursor) { #if defined(OS_WIN) Cursor cursor_copy = cursor; diff --git a/chromium/ui/base/cursor/cursors_aura.h b/chromium/ui/base/cursor/cursors_aura.h index cc82d976546..69e514ebd57 100644 --- a/chromium/ui/base/cursor/cursors_aura.h +++ b/chromium/ui/base/cursor/cursors_aura.h @@ -18,8 +18,6 @@ namespace ui { class Cursor; enum class CursorSize; -const int kAnimatedCursorFrameDelayMs = 25; - // Returns data about |id|, where id is a cursor constant like // ui::mojom::CursorType::kHelp. The IDR will be placed in |resource_id| and // the hotspots for the different DPIs will be placed in |hot_1x| and @@ -31,14 +29,6 @@ bool GetCursorDataFor(CursorSize cursor_size, int* resource_id, gfx::Point* point); -// Like above, but for animated cursors. -COMPONENT_EXPORT(UI_BASE_CURSOR) -bool GetAnimatedCursorDataFor(CursorSize cursor_size, - mojom::CursorType id, - float scale_factor, - int* resource_id, - gfx::Point* point); - SkBitmap GetDefaultBitmap(const Cursor& cursor); gfx::Point GetDefaultHotspot(const Cursor& cursor); diff --git a/chromium/ui/base/cursor/image_cursors.cc b/chromium/ui/base/cursor/image_cursors.cc deleted file mode 100644 index 42fd3249684..00000000000 --- a/chromium/ui/base/cursor/image_cursors.cc +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2014 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/cursor/image_cursors.h" - -#include "base/check.h" -#include "ui/base/cursor/cursor_loader.h" -#include "ui/base/cursor/cursors_aura.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" -#include "ui/gfx/geometry/point.h" - -namespace ui { - -namespace { - -constexpr mojom::CursorType kImageCursorIds[] = { - mojom::CursorType::kNull, - mojom::CursorType::kPointer, - mojom::CursorType::kNoDrop, - mojom::CursorType::kNotAllowed, - mojom::CursorType::kCopy, - mojom::CursorType::kHand, - mojom::CursorType::kMove, - mojom::CursorType::kNorthEastResize, - mojom::CursorType::kSouthWestResize, - mojom::CursorType::kSouthEastResize, - mojom::CursorType::kNorthWestResize, - mojom::CursorType::kNorthResize, - mojom::CursorType::kSouthResize, - mojom::CursorType::kEastResize, - mojom::CursorType::kWestResize, - mojom::CursorType::kIBeam, - mojom::CursorType::kAlias, - mojom::CursorType::kCell, - mojom::CursorType::kContextMenu, - mojom::CursorType::kCross, - mojom::CursorType::kHelp, - mojom::CursorType::kVerticalText, - mojom::CursorType::kZoomIn, - mojom::CursorType::kZoomOut, - mojom::CursorType::kRowResize, - mojom::CursorType::kColumnResize, - mojom::CursorType::kEastWestResize, - mojom::CursorType::kNorthSouthResize, - mojom::CursorType::kNorthEastSouthWestResize, - mojom::CursorType::kNorthWestSouthEastResize, - mojom::CursorType::kGrab, - mojom::CursorType::kGrabbing, -}; - -constexpr mojom::CursorType kAnimatedCursorIds[] = { - mojom::CursorType::kWait, mojom::CursorType::kProgress}; - -} // namespace - -ImageCursors::ImageCursors() - : cursor_loader_(CursorLoader::Create()), - cursor_size_(CursorSize::kNormal) {} - -ImageCursors::~ImageCursors() = default; - -float ImageCursors::GetScale() const { - return cursor_loader_->scale(); -} - -display::Display::Rotation ImageCursors::GetRotation() const { - return cursor_loader_->rotation(); -} - -bool ImageCursors::SetDisplay(const display::Display& display, - float scale_factor) { - if (cursor_loader_->rotation() == display.panel_rotation() && - cursor_loader_->scale() == scale_factor) - return false; - - cursor_loader_->set_rotation(display.panel_rotation()); - cursor_loader_->set_scale(scale_factor); - ReloadCursors(); - return true; -} - -void ImageCursors::ReloadCursors() { - float device_scale_factor = cursor_loader_->scale(); - - cursor_loader_->UnloadAll(); - - for (auto cursor_id : kImageCursorIds) { - int resource_id = -1; - gfx::Point hot_point; - bool success = GetCursorDataFor( - cursor_size_, cursor_id, device_scale_factor, &resource_id, &hot_point); - DCHECK(success); - cursor_loader_->LoadImageCursor(cursor_id, resource_id, hot_point); - } - for (auto cursor_id : kAnimatedCursorIds) { - int resource_id = -1; - gfx::Point hot_point; - bool success = GetAnimatedCursorDataFor( - cursor_size_, cursor_id, device_scale_factor, &resource_id, &hot_point); - DCHECK(success); - cursor_loader_->LoadAnimatedCursor(cursor_id, resource_id, hot_point, - kAnimatedCursorFrameDelayMs); - } -} - -void ImageCursors::SetCursorSize(CursorSize cursor_size) { - if (cursor_size_ == cursor_size) - return; - - cursor_size_ = cursor_size; - - ReloadCursors(); -} - -void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { - cursor_loader_->SetPlatformCursor(cursor); -} - -} // namespace ui diff --git a/chromium/ui/base/cursor/image_cursors.h b/chromium/ui/base/cursor/image_cursors.h deleted file mode 100644 index b5b5ec274dd..00000000000 --- a/chromium/ui/base/cursor/image_cursors.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2014 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_CURSOR_IMAGE_CURSORS_H_ -#define UI_BASE_CURSOR_IMAGE_CURSORS_H_ - -#include <memory> - -#include "base/component_export.h" -#include "ui/base/cursor/cursor_size.h" -#include "ui/display/display.h" -#include "ui/gfx/native_widget_types.h" - -namespace ui { - -class CursorLoader; - -// A utility class that provides cursors for NativeCursors for which we have -// image resources. -class COMPONENT_EXPORT(UI_BASE_CURSOR) ImageCursors { - public: - ImageCursors(); - ImageCursors(const ImageCursors&) = delete; - ImageCursors& operator=(const ImageCursors&) = delete; - ~ImageCursors(); - - // Returns the scale and rotation of the currently loaded cursor. - float GetScale() const; - display::Display::Rotation GetRotation() const; - - // Sets the display the cursors are loaded for. |scale_factor| determines the - // size of the image to load. Returns true if the cursor image is reloaded. - bool SetDisplay(const display::Display& display, float scale_factor); - - // Sets the size of the mouse cursor icon. - void SetCursorSize(CursorSize cursor_size); - - // Sets the platform cursor based on the native type of |cursor|. - void SetPlatformCursor(gfx::NativeCursor* cursor); - - private: - // Reloads the all loaded cursors in the cursor loader. - void ReloadCursors(); - - std::unique_ptr<CursorLoader> cursor_loader_; - CursorSize cursor_size_; -}; - -} // namespace ui - -#endif // UI_BASE_CURSOR_IMAGE_CURSORS_H_ diff --git a/chromium/ui/base/cursor/ozone/DIR_METADATA b/chromium/ui/base/cursor/ozone/DIR_METADATA new file mode 100644 index 00000000000..69e73155446 --- /dev/null +++ b/chromium/ui/base/cursor/ozone/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI>GFX" +}
\ No newline at end of file diff --git a/chromium/ui/base/cursor/ozone/OWNERS b/chromium/ui/base/cursor/ozone/OWNERS index 1c6f90ab829..479c4d806cc 100644 --- a/chromium/ui/base/cursor/ozone/OWNERS +++ b/chromium/ui/base/cursor/ozone/OWNERS @@ -1,4 +1,2 @@ rjkroege@chromium.org spang@chromium.org - -# COMPONENT: UI>GFX diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc index e86f70ea603..f16c01a02a7 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc @@ -7,11 +7,78 @@ #include <algorithm> #include "base/check_op.h" +#include "base/notreached.h" +#include "build/chromeos_buildflags.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" namespace ui { namespace { +#if BUILDFLAG(IS_CHROMEOS_LACROS) +// Returns true if ozone should use the default cursor for |type|, instead of +// loading and storing bitmaps for it. Used on Lacros to skip client-side bitmap +// loading for server-side cursors. +bool UseDefaultCursorForType(mojom::CursorType type) { + using mojom::CursorType; + switch (type) { + case CursorType::kNull: + case CursorType::kPointer: + case CursorType::kCross: + case CursorType::kHand: + case CursorType::kIBeam: + case CursorType::kWait: + case CursorType::kHelp: + case CursorType::kEastResize: + case CursorType::kNorthResize: + case CursorType::kNorthEastResize: + case CursorType::kNorthWestResize: + case CursorType::kSouthResize: + case CursorType::kSouthEastResize: + case CursorType::kSouthWestResize: + case CursorType::kWestResize: + case CursorType::kNorthSouthResize: + case CursorType::kEastWestResize: + case CursorType::kNorthEastSouthWestResize: + case CursorType::kNorthWestSouthEastResize: + case CursorType::kColumnResize: + case CursorType::kRowResize: + case CursorType::kMiddlePanning: + case CursorType::kEastPanning: + case CursorType::kNorthPanning: + case CursorType::kNorthEastPanning: + case CursorType::kNorthWestPanning: + case CursorType::kSouthPanning: + case CursorType::kSouthEastPanning: + case CursorType::kSouthWestPanning: + case CursorType::kWestPanning: + case CursorType::kMove: + case CursorType::kVerticalText: + case CursorType::kCell: + case CursorType::kContextMenu: + case CursorType::kAlias: + case CursorType::kProgress: + case CursorType::kNoDrop: + case CursorType::kCopy: + case CursorType::kNotAllowed: + case CursorType::kZoomIn: + case CursorType::kZoomOut: + case CursorType::kGrab: + case CursorType::kGrabbing: + case CursorType::kDndNone: + case CursorType::kDndMove: + case CursorType::kDndCopy: + case CursorType::kDndLink: + return true; + case CursorType::kNone: + case CursorType::kMiddlePanningVertical: + case CursorType::kMiddlePanningHorizontal: + case CursorType::kCustom: + return false; + } +} +#endif // BUILDFLAG(IS_CHROMEOS_LACROS) + BitmapCursorOzone* ToBitmapCursorOzone(PlatformCursor cursor) { return static_cast<BitmapCursorOzone*>(cursor); } @@ -22,17 +89,25 @@ PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) { } // namespace -BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap, +BitmapCursorOzone::BitmapCursorOzone(mojom::CursorType type) + : type_(type), frame_delay_ms_(0) {} + +BitmapCursorOzone::BitmapCursorOzone(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot) - : hotspot_(hotspot), frame_delay_ms_(0) { + : type_(type), hotspot_(hotspot), frame_delay_ms_(0) { if (!bitmap.isNull()) bitmaps_.push_back(bitmap); } -BitmapCursorOzone::BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps, +BitmapCursorOzone::BitmapCursorOzone(mojom::CursorType type, + const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) - : bitmaps_(bitmaps), hotspot_(hotspot), frame_delay_ms_(frame_delay_ms) { + : type_(type), + bitmaps_(bitmaps), + hotspot_(hotspot), + frame_delay_ms_(frame_delay_ms) { DCHECK_LT(0U, bitmaps.size()); DCHECK_LE(0, frame_delay_ms); // No null bitmap should be in the list. Blank cursors should just be an empty @@ -42,8 +117,7 @@ BitmapCursorOzone::BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps, bitmaps_.end()); } -BitmapCursorOzone::~BitmapCursorOzone() { -} +BitmapCursorOzone::~BitmapCursorOzone() = default; const gfx::Point& BitmapCursorOzone::hotspot() { return hotspot_; @@ -75,24 +149,35 @@ base::Optional<PlatformCursor> BitmapCursorFactoryOzone::GetDefaultCursor( mojom::CursorType type) { if (type == mojom::CursorType::kNone) return nullptr; // nullptr is used for the hidden cursor. +#if BUILDFLAG(IS_CHROMEOS_LACROS) + if (UseDefaultCursorForType(type)) { + // Lacros uses server-side cursors for most types. These cursors don't need + // to load bitmap images on the client. + BitmapCursorOzone* cursor = new BitmapCursorOzone(type); + cursor->AddRef(); // Balanced by UnrefImageCursor. + return ToPlatformCursor(cursor); + } +#endif // BUILDFLAG(IS_CHROMEOS_LACROS) return base::nullopt; } PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( + mojom::CursorType type, const SkBitmap& bitmap, const gfx::Point& hotspot) { - BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); + BitmapCursorOzone* cursor = new BitmapCursorOzone(type, bitmap, hotspot); cursor->AddRef(); // Balanced by UnrefImageCursor. return ToPlatformCursor(cursor); } PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( + mojom::CursorType type, const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) { DCHECK_LT(0U, bitmaps.size()); BitmapCursorOzone* cursor = - new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms); + new BitmapCursorOzone(type, bitmaps, hotspot, frame_delay_ms); cursor->AddRef(); // Balanced by UnrefImageCursor. return ToPlatformCursor(cursor); } diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h index b489e099ad0..db049fb4532 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h @@ -13,6 +13,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_factory.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" #include "ui/gfx/geometry/point.h" namespace ui { @@ -21,11 +22,22 @@ namespace ui { class COMPONENT_EXPORT(UI_BASE_CURSOR) BitmapCursorOzone : public base::RefCounted<BitmapCursorOzone> { public: - BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot); - BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps, + // Creates a cursor that doesn't need backing bitmaps (for example, a + // server-side cursor for Lacros). + explicit BitmapCursorOzone(mojom::CursorType type); + + // Creates a cursor with a single backing bitmap. + BitmapCursorOzone(mojom::CursorType type, + const SkBitmap& bitmap, + const gfx::Point& hotspot); + + // Creates a cursor with multiple bitmaps for animation. + BitmapCursorOzone(mojom::CursorType type, + const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms); + mojom::CursorType type() const { return type_; } const gfx::Point& hotspot(); const SkBitmap& bitmap(); @@ -37,6 +49,7 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR) BitmapCursorOzone friend class base::RefCounted<BitmapCursorOzone>; ~BitmapCursorOzone(); + const mojom::CursorType type_; std::vector<SkBitmap> bitmaps_; gfx::Point hotspot_; int frame_delay_ms_; @@ -64,9 +77,11 @@ class COMPONENT_EXPORT(UI_BASE_CURSOR) BitmapCursorFactoryOzone // CursorFactoryOzone: base::Optional<PlatformCursor> GetDefaultCursor( mojom::CursorType type) override; - PlatformCursor CreateImageCursor(const SkBitmap& bitmap, + PlatformCursor CreateImageCursor(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot) override; - PlatformCursor CreateAnimatedCursor(const std::vector<SkBitmap>& bitmaps, + PlatformCursor CreateAnimatedCursor(mojom::CursorType type, + const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) override; void RefImageCursor(PlatformCursor cursor) override; diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone_unittest.cc b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone_unittest.cc index 0d8dbbfca41..3ed24fe7047 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone_unittest.cc +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone_unittest.cc @@ -5,6 +5,7 @@ #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" #include "base/optional.h" +#include "build/chromeos_buildflags.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" @@ -21,4 +22,35 @@ TEST(BitmapCursorFactoryOzoneTest, InvisibleCursor) { EXPECT_EQ(cursor, nullptr); } +#if BUILDFLAG(IS_CHROMEOS_LACROS) +TEST(BitmapCursorFactoryOzoneTest, LacrosUsesDefaultCursorsForCommonTypes) { + BitmapCursorFactoryOzone factory; + + // Verify some common cursor types. + base::Optional<PlatformCursor> cursor = + factory.GetDefaultCursor(mojom::CursorType::kPointer); + ASSERT_TRUE(cursor.has_value()); + EXPECT_NE(cursor, nullptr); + factory.UnrefImageCursor(cursor.value()); + + cursor = factory.GetDefaultCursor(mojom::CursorType::kHand); + ASSERT_TRUE(cursor.has_value()); + EXPECT_NE(cursor, nullptr); + factory.UnrefImageCursor(cursor.value()); + + cursor = factory.GetDefaultCursor(mojom::CursorType::kIBeam); + ASSERT_TRUE(cursor.has_value()); + EXPECT_NE(cursor, nullptr); + factory.UnrefImageCursor(cursor.value()); +} + +TEST(BitmapCursorFactoryOzoneTest, LacrosCustomCursor) { + BitmapCursorFactoryOzone factory; + base::Optional<PlatformCursor> cursor = + factory.GetDefaultCursor(mojom::CursorType::kCustom); + // Custom cursors don't have a default platform cursor. + EXPECT_FALSE(cursor.has_value()); +} +#endif // BUILDFLAG(IS_CHROMEOS_LACROS) + } // namespace ui diff --git a/chromium/ui/base/data_transfer_policy/BUILD.gn b/chromium/ui/base/data_transfer_policy/BUILD.gn new file mode 100644 index 00000000000..aeea4b1d324 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/BUILD.gn @@ -0,0 +1,22 @@ +# 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. + +import("//build/config/ui.gni") + +component("data_transfer_policy") { + output_name = "ui_base_data_transfer_policy" + sources = [ + "data_transfer_endpoint.cc", + "data_transfer_endpoint.h", + "data_transfer_policy_controller.cc", + "data_transfer_policy_controller.h", + ] + + defines = [ "IS_UI_BASE_DATA_TRANSFER_POLICY_IMPL" ] + + deps = [ + "//base", + "//url", + ] +} diff --git a/chromium/ui/base/data_transfer_policy/DIR_METADATA b/chromium/ui/base/data_transfer_policy/DIR_METADATA new file mode 100644 index 00000000000..c4701852608 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/DIR_METADATA @@ -0,0 +1,12 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "OS>Software>Enterprise>DLP" +} +team_email: "chromeos-dlp@google.com"
\ No newline at end of file diff --git a/chromium/ui/base/data_transfer_policy/OWNERS b/chromium/ui/base/data_transfer_policy/OWNERS new file mode 100644 index 00000000000..11249b99d52 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/OWNERS @@ -0,0 +1,5 @@ +# Primary: +ayaelattar@chromium.org + +# Secondary: +huangdarwin@chromium.org
\ No newline at end of file diff --git a/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.cc b/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.cc new file mode 100644 index 00000000000..a5f3c7bdac8 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.cc @@ -0,0 +1,39 @@ +// 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 "base/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_(base::nullopt), + notify_if_restricted_(notify_if_restricted) { + DCHECK_NE(type, EndpointType::kUrl); +} + +DataTransferEndpoint::DataTransferEndpoint(const DataTransferEndpoint& other) = + default; + +DataTransferEndpoint::DataTransferEndpoint(DataTransferEndpoint&& other) = + default; + +bool DataTransferEndpoint::operator==(const DataTransferEndpoint& other) const { + return origin_ == other.origin_ && type_ == other.type_; +} + +DataTransferEndpoint::~DataTransferEndpoint() = default; + +} // namespace ui diff --git a/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.h b/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.h new file mode 100644 index 00000000000..cd510a56011 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/data_transfer_endpoint.h @@ -0,0 +1,82 @@ +// 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_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_ +#define UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_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 transferred data or the +// destination trying to read the data. +// Whenever a new format is supported, a new enum should be added. +enum class EndpointType { + kDefault = 0, // This type shouldn't be used if any of the following types is + // a better match. +#if defined(OS_CHROMEOS) || (OS_LINUX) || (OS_FUCHSIA) + kGuestOs = 1, // Guest OS: PluginVM, Crostini. +#endif // defined(OS_CHROMEOS) || (OS_LINUX) || (OS_FUCHSIA) +#if defined(OS_CHROMEOS) + kArc = 2, // ARC. +#endif // defined(OS_CHROMEOS) + kUrl = 3, // Website URL e.g. www.example.com. + kClipboardHistory = 4, // Clipboard History UI has privileged access to any + // clipboard data. + kMaxValue = kClipboardHistory +}; + +// DataTransferEndpoint represents: +// - The source of the data being ransferred. +// - The destination trying to access the data. +// - Whether the user should see a notification if the data access is not +// allowed. +// Passing DataTransferEndpoint as a nullptr is equivalent to +// DataTransferEndpoint(kDefault, true). Both specify the same types of +// endpoints (not a URL/ARC++/...etc, and should show a notification to the user +// if the data read is not allowed.) +class COMPONENT_EXPORT(UI_BASE_DATA_TRANSFER_POLICY) DataTransferEndpoint { + public: + explicit DataTransferEndpoint(const url::Origin& origin, + bool notify_if_restricted = true); + // This constructor shouldn't be used if |type| == EndpointType::kUrl. + explicit DataTransferEndpoint(EndpointType type, + bool notify_if_restricted = true); + + DataTransferEndpoint(const DataTransferEndpoint& other); + DataTransferEndpoint(DataTransferEndpoint&& other); + + DataTransferEndpoint& operator=(const DataTransferEndpoint& other) = delete; + DataTransferEndpoint& operator=(DataTransferEndpoint&& other) = delete; + + bool operator==(const DataTransferEndpoint& other) const; + + ~DataTransferEndpoint(); + + bool IsUrlType() const { return type_ == EndpointType::kUrl; } + + const url::Origin* origin() const { return base::OptionalOrNullptr(origin_); } + + EndpointType type() const { return type_; } + + bool notify_if_restricted() const { return notify_if_restricted_; } + + 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_; + // This variable should be set to true, if paste is initiated by the user. + // Otherwise it should be set to false, so the user won't see a notification + // when the data is restricted by the rules of data leak prevention policy + // and something in the background is trying to access it. + bool notify_if_restricted_ = true; +}; + +} // namespace ui + +#endif // UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_ENDPOINT_H_ diff --git a/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.cc b/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.cc new file mode 100644 index 00000000000..fc02854cf90 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.cc @@ -0,0 +1,38 @@ +// 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_policy_controller.h" + +namespace ui { + +// static +DataTransferPolicyController* DataTransferPolicyController::Get() { + return g_data_transfer_policy_controller_; +} + +// static +bool DataTransferPolicyController::HasInstance() { + return g_data_transfer_policy_controller_ != nullptr; +} + +// static +void DataTransferPolicyController::DeleteInstance() { + if (!g_data_transfer_policy_controller_) + return; + + delete g_data_transfer_policy_controller_; +} + +DataTransferPolicyController::DataTransferPolicyController() { + g_data_transfer_policy_controller_ = this; +} + +DataTransferPolicyController::~DataTransferPolicyController() { + g_data_transfer_policy_controller_ = nullptr; +} + +DataTransferPolicyController* + DataTransferPolicyController::g_data_transfer_policy_controller_ = nullptr; + +} // namespace ui diff --git a/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.h b/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.h new file mode 100644 index 00000000000..a858af9b447 --- /dev/null +++ b/chromium/ui/base/data_transfer_policy/data_transfer_policy_controller.h @@ -0,0 +1,46 @@ +// 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_DATA_TRANSFER_POLICY_DATA_TRANSFER_POLICY_CONTROLLER_H_ +#define UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_POLICY_CONTROLLER_H_ + +#include "base/component_export.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" + +namespace ui { + +// The DataTransfer filter controls transferring data via drag-and-drop and +// clipboard read operations. It allows/disallows transferring the data given +// the source of the data and the destination trying to access the data and a +// set of rules controlling these source and destination. +class COMPONENT_EXPORT(UI_BASE_DATA_TRANSFER_POLICY) + DataTransferPolicyController { + public: + // Returns a pointer to the existing instance of the class. + static DataTransferPolicyController* Get(); + + // Returns true if an instance exists, without forcing an initialization. + static bool HasInstance(); + + // Deletes the existing instance of the class if it's already created. + // Indicates that restricting data transfer is no longer required. + static void DeleteInstance(); + + virtual bool IsDataReadAllowed( + const DataTransferEndpoint* const data_src, + const DataTransferEndpoint* const data_dst) const = 0; + + protected: + DataTransferPolicyController(); + virtual ~DataTransferPolicyController(); + + private: + // A singleton of DataTransferPolicyController. Equals nullptr when there's + // not any data transfer restrictions required. + static DataTransferPolicyController* g_data_transfer_policy_controller_; +}; + +} // namespace ui + +#endif // UI_BASE_DATA_TRANSFER_POLICY_DATA_TRANSFER_POLICY_CONTROLLER_H_ diff --git a/chromium/ui/base/dragdrop/DIR_METADATA b/chromium/ui/base/dragdrop/DIR_METADATA new file mode 100644 index 00000000000..185817f957c --- /dev/null +++ b/chromium/ui/base/dragdrop/DIR_METADATA @@ -0,0 +1,12 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Blink>DataTransfer" +} +team_email: "storage-dev@chromium.org"
\ No newline at end of file diff --git a/chromium/ui/base/dragdrop/OWNERS b/chromium/ui/base/dragdrop/OWNERS index 9f471ef04e3..7baa107fd51 100644 --- a/chromium/ui/base/dragdrop/OWNERS +++ b/chromium/ui/base/dragdrop/OWNERS @@ -3,6 +3,3 @@ huangdarwin@chromium.org # Secondary: dcheng@chromium.org - -# TEAM: storage-dev@chromium.org -# COMPONENT: Blink>DataTransfer diff --git a/chromium/ui/base/dragdrop/os_exchange_data.cc b/chromium/ui/base/dragdrop/os_exchange_data.cc index 7f2da0ddeff..9d708acc056 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data.cc @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/pickle.h" #include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" #include "url/gurl.h" @@ -160,4 +161,13 @@ bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const { } #endif +void OSExchangeData::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) { + provider_->SetSource(std::move(data_source)); +} + +DataTransferEndpoint* OSExchangeData::GetSource() const { + return provider_->GetSource(); +} + } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data.h b/chromium/ui/base/dragdrop/os_exchange_data.h index a5098f57439..067e2108655 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.h +++ b/chromium/ui/base/dragdrop/os_exchange_data.h @@ -32,6 +32,7 @@ class Pickle; namespace ui { class ClipboardFormatType; +class DataTransferEndpoint; struct FileInfo; /////////////////////////////////////////////////////////////////////////////// @@ -186,6 +187,12 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeData { bool HasHtml() const; #endif + // Adds a DataTransferEndpoint to represent the source of the data. + // TODO(crbug.com/1142406): Update all drag-and-drop references to set the + // source of the data. + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source); + DataTransferEndpoint* GetSource() const; + private: // Provides the actual data. std::unique_ptr<OSExchangeDataProvider> provider_; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider.h b/chromium/ui/base/dragdrop/os_exchange_data_provider.h index 1a7186b2c6d..b398fe64fa0 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider.h @@ -31,6 +31,8 @@ namespace ui { +class DataTransferEndpoint; + // Controls whether or not filenames should be converted to file: URLs when // getting a URL. enum class FilenameToURLPolicy { @@ -71,7 +73,7 @@ class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider { virtual bool HasFile() const = 0; virtual bool HasCustomFormat(const ClipboardFormatType& format) const = 0; -#if defined(USE_X11) || defined(OS_WIN) +#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_WIN) virtual void SetFileContents(const base::FilePath& filename, const std::string& file_contents) = 0; #endif @@ -105,6 +107,10 @@ class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider { virtual gfx::ImageSkia GetDragImage() const = 0; virtual gfx::Vector2d GetDragImageOffset() const = 0; #endif + + // These functions are only implemented on Chrome OS currently. + virtual void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) = 0; + virtual DataTransferEndpoint* GetSource() const = 0; }; } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h index 8fb6a3ad5c6..1626a146078 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h @@ -76,6 +76,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderMac // OSExchangeData. static NSArray* SupportedPasteboardTypes(); + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override; + DataTransferEndpoint* GetSource() const override; + protected: OSExchangeDataProviderMac(); OSExchangeDataProviderMac(const OSExchangeDataProviderMac&); diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm index b7f144452f3..f264b8b5eb1 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm @@ -17,6 +17,7 @@ #include "ui/base/clipboard/clipboard_format_type.h" #import "ui/base/clipboard/clipboard_util_mac.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #import "ui/base/dragdrop/cocoa_dnd_util.h" #include "ui/base/dragdrop/file_info/file_info.h" #include "url/gurl.h" @@ -337,4 +338,11 @@ NSArray* OSExchangeDataProviderMac::SupportedPasteboardTypes() { ]; } +void OSExchangeDataProviderMac::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) {} + +DataTransferEndpoint* OSExchangeDataProviderMac::GetSource() const { + return nullptr; +} + } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc index a3722644622..a858abbe290 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc @@ -12,6 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "net/base/filename_util.h" #include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "url/gurl.h" @@ -42,10 +43,17 @@ std::unique_ptr<OSExchangeDataProvider> OSExchangeDataProviderNonBacked::Clone() void OSExchangeDataProviderNonBacked::MarkOriginatedFromRenderer() { // TODO(dcheng): Currently unneeded because ChromeOS Aura correctly separates // URL and filename metadata, and does not implement the DownloadURL protocol. +#if !defined(OS_CHROMEOS) + originated_from_renderer_ = true; +#endif } bool OSExchangeDataProviderNonBacked::DidOriginateFromRenderer() const { +#if defined(OS_CHROMEOS) return false; +#else + return originated_from_renderer_; +#endif } void OSExchangeDataProviderNonBacked::SetString(const base::string16& data) { @@ -85,6 +93,15 @@ void OSExchangeDataProviderNonBacked::SetPickledData( } bool OSExchangeDataProviderNonBacked::GetString(base::string16* data) const { +#if defined(OS_LINUX) || defined(OS_CHROMEOS) + if (HasFile()) { + // Various Linux file managers both pass a list of file:// URIs and set the + // string representation to the URI. We explicitly don't want to return use + // this representation. + return false; + } +#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) + if ((formats_ & OSExchangeData::STRING) == 0) return false; *data = string_; @@ -160,11 +177,11 @@ bool OSExchangeDataProviderNonBacked::HasCustomFormat( return base::Contains(pickle_data_, format); } -#if defined(USE_X11) +#if defined(OS_LINUX) || defined(OS_CHROMEOS) void OSExchangeDataProviderNonBacked::SetFileContents( const base::FilePath& filename, const std::string& file_contents) { - NOTREACHED(); + NOTIMPLEMENTED(); } #endif @@ -230,4 +247,13 @@ bool OSExchangeDataProviderNonBacked::GetPlainTextURL(GURL* url) const { return true; } +void OSExchangeDataProviderNonBacked::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) { + source_ = std::move(data_source); +} + +DataTransferEndpoint* OSExchangeDataProviderNonBacked::GetSource() const { + return source_.get(); +} + } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h index 0ae453e067a..c30cef45611 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h @@ -6,9 +6,11 @@ #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_ #include <map> +#include <memory> #include "base/component_export.h" #include "base/pickle.h" +#include "build/build_config.h" #include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/os_exchange_data_provider.h" #include "ui/gfx/geometry/vector2d.h" @@ -58,7 +60,7 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked bool HasURL(FilenameToURLPolicy policy) const override; bool HasFile() const override; bool HasCustomFormat(const ClipboardFormatType& format) const override; -#if defined(USE_X11) +#if defined(OS_LINUX) || defined(OS_CHROMEOS) void SetFileContents(const base::FilePath& filename, const std::string& file_contents) override; #endif @@ -71,6 +73,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked gfx::ImageSkia GetDragImage() const override; gfx::Vector2d GetDragImageOffset() const override; + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override; + DataTransferEndpoint* GetSource() const override; + private: // Returns true if |formats_| contains a file format and the file name can be // parsed as a URL. @@ -104,6 +109,13 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked // For HTML format base::string16 html_; GURL base_url_; + +#if !defined(OS_CHROMEOS) + bool originated_from_renderer_ = false; +#endif + + // Data source. + std::unique_ptr<DataTransferEndpoint> source_; }; } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc index 4fdfcbe7e01..516fb31fcbd 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -24,6 +24,7 @@ #include "base/notreached.h" #include "base/pickle.h" #include "base/stl_util.h" +#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/win/scoped_hdc.h" #include "base/win/scoped_hglobal.h" @@ -33,8 +34,10 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_util_win.h" +#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/l10n/l10n_util_win.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/skbitmap_operations.h" @@ -64,8 +67,8 @@ const ClipboardFormatType& GetRendererTaintFormatType(); // Creates the contents of an Internet Shortcut file for the given URL. std::string GetInternetShortcutFileContents(const GURL& url); // Creates a valid file name given a suggested title and URL. -base::string16 CreateValidFileNameFromTitle(const GURL& url, - const base::string16& title); +std::wstring CreateValidFileNameFromTitle(const GURL& url, + const std::wstring& title); } // namespace @@ -329,7 +332,8 @@ void OSExchangeDataProviderWin::SetURL(const GURL& url, ClipboardFormatType::GetMozUrlType().ToFormatEtc(), storage)); // Add a .URL shortcut file for dragging to Explorer. - base::string16 valid_file_name = CreateValidFileNameFromTitle(url, title); + std::wstring valid_file_name = + CreateValidFileNameFromTitle(url, base::AsWString(title)); std::string shortcut_url_file_contents = GetInternetShortcutFileContents(url); SetFileContents(base::FilePath(valid_file_name), shortcut_url_file_contents); @@ -400,7 +404,7 @@ void OSExchangeDataProviderWin::SetVirtualFileContentsForTesting( for (size_t i = 0; i < num_files; i++) { // Fill in each FILEDESCRIPTORW with file name. descriptor->fgd[i].dwFlags |= FD_UNICODE; - base::string16 file_name = filenames_and_contents[i].first.value(); + std::wstring file_name = filenames_and_contents[i].first.value(); wcsncpy_s(descriptor->fgd[i].cFileName, MAX_PATH, file_name.c_str(), std::min(file_name.size(), static_cast<size_t>(MAX_PATH - 1u))); @@ -544,7 +548,7 @@ bool OSExchangeDataProviderWin::GetURLAndTitle(FilenameToURLPolicy policy, } bool OSExchangeDataProviderWin::GetFilename(base::FilePath* path) const { - std::vector<base::string16> filenames; + std::vector<std::wstring> filenames; bool success = ClipboardUtil::GetFilenames(source_object_.Get(), &filenames); if (success) *path = base::FilePath(filenames[0]); @@ -553,11 +557,11 @@ bool OSExchangeDataProviderWin::GetFilename(base::FilePath* path) const { bool OSExchangeDataProviderWin::GetFilenames( std::vector<FileInfo>* filenames) const { - std::vector<base::string16> filenames_local; + std::vector<std::wstring> filenames_local; bool success = ClipboardUtil::GetFilenames(source_object_.Get(), &filenames_local); if (success) { - for (const base::string16& filename_local : filenames_local) + for (const std::wstring& filename_local : filenames_local) filenames->push_back( FileInfo(base::FilePath(filename_local), base::FilePath())); } @@ -619,7 +623,7 @@ bool OSExchangeDataProviderWin::GetPickledData( bool OSExchangeDataProviderWin::GetFileContents( base::FilePath* filename, std::string* file_contents) const { - base::string16 filename_str; + std::wstring filename_str; if (!ClipboardUtil::GetFileContents(source_object_.Get(), &filename_str, file_contents)) { return false; @@ -734,6 +738,13 @@ gfx::Vector2d OSExchangeDataProviderWin::GetDragImageOffset() const { return gfx::Vector2d(); } +void OSExchangeDataProviderWin::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) {} + +DataTransferEndpoint* OSExchangeDataProviderWin::GetSource() const { + return nullptr; +} + /////////////////////////////////////////////////////////////////////////////// // DataObjectImpl, IDataObject implementation: @@ -1195,7 +1206,7 @@ STGMEDIUM CreateIdListStorageForFileName(const base::FilePath& path) { } STGMEDIUM CreateStorageForFileDescriptor(const base::FilePath& path) { - base::string16 file_name = path.value(); + std::wstring file_name = path.value(); DCHECK(!file_name.empty()); HANDLE hdata = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTORW)); base::win::ScopedHGlobal<FILEGROUPDESCRIPTORW*> locked_mem(hdata); @@ -1224,16 +1235,16 @@ std::string GetInternetShortcutFileContents(const GURL& url) { return kInternetShortcutFileStart + url.spec() + kInternetShortcutFileEnd; } -base::string16 CreateValidFileNameFromTitle(const GURL& url, - const base::string16& title) { - base::string16 validated; +std::wstring CreateValidFileNameFromTitle(const GURL& url, + const std::wstring& title) { + std::wstring validated; if (title.empty()) { if (url.is_valid()) { - validated = net::GetSuggestedFilename(url, "", "", "", "", std::string()); + validated = base::AsWString( + net::GetSuggestedFilename(url, "", "", "", "", std::string())); } else { // Nothing else can be done, just use a default. - validated = - l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); + validated = l10n_util::GetWideString(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); } } else { validated = title; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h index 1fb90911a46..447a3efdba1 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h @@ -191,6 +191,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderWin gfx::ImageSkia GetDragImage() const override; gfx::Vector2d GetDragImageOffset() const override; + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override; + DataTransferEndpoint* GetSource() const override; + private: void SetVirtualFileContentAtIndexForTesting(base::span<const uint8_t> data, DWORD tymed, diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc index d4555f18894..8365cc492e5 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc @@ -8,6 +8,7 @@ #include "base/check.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #include "ui/base/x/selection_utils.h" #include "ui/events/platform/platform_event_source.h" #include "ui/gfx/x/x11_atom_cache.h" @@ -46,4 +47,11 @@ bool OSExchangeDataProviderX11::DispatchXEvent(x11::Event* xev) { return false; } +void OSExchangeDataProviderX11::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) {} + +DataTransferEndpoint* OSExchangeDataProviderX11::GetSource() const { + return nullptr; +} + } // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h index a85e864624e..60dac520176 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h @@ -38,6 +38,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderX11 // XEventDispatcher: bool DispatchXEvent(x11::Event* xev) override; + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override; + DataTransferEndpoint* GetSource() const override; + private: friend class OSExchangeDataProviderX11Test; }; diff --git a/chromium/ui/base/emoji/DIR_METADATA b/chromium/ui/base/emoji/DIR_METADATA new file mode 100644 index 00000000000..198db497480 --- /dev/null +++ b/chromium/ui/base/emoji/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals>Input" +} diff --git a/chromium/ui/base/emoji/OWNERS b/chromium/ui/base/emoji/OWNERS deleted file mode 100644 index 776ce1a5de3..00000000000 --- a/chromium/ui/base/emoji/OWNERS +++ /dev/null @@ -1 +0,0 @@ -# COMPONENT: Internal>Input diff --git a/chromium/ui/base/glib/DIR_METADATA b/chromium/ui/base/glib/DIR_METADATA new file mode 100644 index 00000000000..63fc482f75d --- /dev/null +++ b/chromium/ui/base/glib/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals" +}
\ No newline at end of file diff --git a/chromium/ui/base/glib/OWNERS b/chromium/ui/base/glib/OWNERS deleted file mode 100644 index f136fc175b8..00000000000 --- a/chromium/ui/base/glib/OWNERS +++ /dev/null @@ -1 +0,0 @@ -# COMPONENT: Internals diff --git a/chromium/ui/base/idle/BUILD.gn b/chromium/ui/base/idle/BUILD.gn index 3c137d0779d..adfd4c02bc5 100644 --- a/chromium/ui/base/idle/BUILD.gn +++ b/chromium/ui/base/idle/BUILD.gn @@ -55,12 +55,13 @@ component("idle") { } if (use_x11 && !is_chromeos) { - deps += [ "//ui/gfx/x" ] - sources += [ - "idle_query_x11.cc", - "idle_query_x11.h", - "screensaver_window_finder_x11.cc", - "screensaver_window_finder_x11.h", + deps += [ "//ui/base/x" ] + } + + if (use_ozone) { + deps += [ + "//ui/base:features", + "//ui/display", ] } diff --git a/chromium/ui/base/idle/DIR_METADATA b/chromium/ui/base/idle/DIR_METADATA new file mode 100644 index 00000000000..63fc482f75d --- /dev/null +++ b/chromium/ui/base/idle/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals" +}
\ No newline at end of file diff --git a/chromium/ui/base/idle/OWNERS b/chromium/ui/base/idle/OWNERS deleted file mode 100644 index f136fc175b8..00000000000 --- a/chromium/ui/base/idle/OWNERS +++ /dev/null @@ -1 +0,0 @@ -# COMPONENT: Internals diff --git a/chromium/ui/base/idle/idle_linux.cc b/chromium/ui/base/idle/idle_linux.cc index 3f13e93c146..bd8a44d733f 100644 --- a/chromium/ui/base/idle/idle_linux.cc +++ b/chromium/ui/base/idle/idle_linux.cc @@ -7,36 +7,56 @@ #include "ui/base/idle/idle_internal.h" #if defined(USE_X11) -#include "ui/base/idle/idle_query_x11.h" -#include "ui/base/idle/screensaver_window_finder_x11.h" +#include "ui/base/x/x11_idle_query.h" +#include "ui/base/x/x11_screensaver_window_finder.h" +#endif + +#if defined(USE_OZONE) #include "ui/base/ui_base_features.h" +#include "ui/display/screen.h" #endif namespace ui { int CalculateIdleTime() { -// TODO(https://crbug.com/1098201): calculate idle time for Ozone/Linux. -#if defined(USE_X11) - if (!features::IsUsingOzonePlatform()) { - IdleQueryX11 idle_query; - return idle_query.IdleTime(); +#if defined(USE_OZONE) + if (features::IsUsingOzonePlatform()) { + auto* const screen = display::Screen::GetScreen(); + // The screen can be nullptr in tests. + if (!screen) + return 0; + return screen->CalculateIdleTime().InSeconds(); } #endif +#if defined(USE_X11) + IdleQueryX11 idle_query; + return idle_query.IdleTime(); +#else + NOTIMPLEMENTED_LOG_ONCE(); return 0; +#endif } bool CheckIdleStateIsLocked() { if (IdleStateForTesting().has_value()) return IdleStateForTesting().value() == IDLE_STATE_LOCKED; -// TODO(https://crbug.com/1098202): fix screensaver. -#if defined(USE_X11) - if (!features::IsUsingOzonePlatform()) { - // Usually the screensaver is used to lock the screen. - return ScreensaverWindowFinder::ScreensaverWindowExists(); +#if defined(USE_OZONE) + if (features::IsUsingOzonePlatform()) { + auto* const screen = display::Screen::GetScreen(); + // The screen can be nullptr in tests. + if (!screen) + return false; + return screen->IsScreenSaverActive(); } #endif +#if defined(USE_X11) + // Usually the screensaver is used to lock the screen. + return ScreensaverWindowFinder::ScreensaverWindowExists(); +#else + NOTIMPLEMENTED_LOG_ONCE(); return false; +#endif } } // namespace ui diff --git a/chromium/ui/base/ime/DIR_METADATA b/chromium/ui/base/ime/DIR_METADATA new file mode 100644 index 00000000000..40507e198d2 --- /dev/null +++ b/chromium/ui/base/ime/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI>Input>Text>IME" +}
\ No newline at end of file diff --git a/chromium/ui/base/ime/OWNERS b/chromium/ui/base/ime/OWNERS index 42b1af0cd7a..5e184ce0640 100644 --- a/chromium/ui/base/ime/OWNERS +++ b/chromium/ui/base/ime/OWNERS @@ -7,5 +7,4 @@ keithlee@chromium.org yukishiino@chromium.org # For Windows. -yukawa@chromium.org -# COMPONENT: UI>Input>Text>IME +yukawa@chromium.org
\ No newline at end of file diff --git a/chromium/ui/base/ime/chromeos/BUILD.gn b/chromium/ui/base/ime/chromeos/BUILD.gn index ed2a8b8f88a..0d4ff07fd7d 100644 --- a/chromium/ui/base/ime/chromeos/BUILD.gn +++ b/chromium/ui/base/ime/chromeos/BUILD.gn @@ -14,6 +14,7 @@ component("chromeos") { sources = [ "component_extension_ime_manager.cc", "component_extension_ime_manager.h", + "component_extension_ime_manager_delegate.h", "extension_ime_util.cc", "extension_ime_util.h", "fake_ime_keyboard.cc", diff --git a/chromium/ui/base/ime/input_method_base.cc b/chromium/ui/base/ime/input_method_base.cc index eac91312d04..36a615a58b4 100644 --- a/chromium/ui/base/ime/input_method_base.cc +++ b/chromium/ui/base/ime/input_method_base.cc @@ -5,7 +5,7 @@ #include "ui/base/ime/input_method_base.h" #include "base/bind.h" -#include "base/bind_helpers.h" +#include "base/callback_helpers.h" #include "base/check.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" diff --git a/chromium/ui/base/ime/linux/composition_text_util_pango.cc b/chromium/ui/base/ime/linux/composition_text_util_pango.cc index 84ccf531bde..db18d1949f5 100644 --- a/chromium/ui/base/ime/linux/composition_text_util_pango.cc +++ b/chromium/ui/base/ime/linux/composition_text_util_pango.cc @@ -30,10 +30,10 @@ void ExtractCompositionTextFromGtkPreedit(const char* utf8_text, // conversion here. std::vector<size_t> char16_offsets; size_t length = composition->text.length(); - base::i18n::UTF16CharIterator char_iterator(&composition->text); - do { + for (base::i18n::UTF16CharIterator char_iterator(composition->text); + !char_iterator.end(); char_iterator.Advance()) { char16_offsets.push_back(char_iterator.array_pos()); - } while (char_iterator.Advance()); + } // The text length in Unicode characters. int char_length = static_cast<int>(char16_offsets.size()); diff --git a/chromium/ui/base/ime/mock_input_method.cc b/chromium/ui/base/ime/mock_input_method.cc index 62702077507..6ef10947256 100644 --- a/chromium/ui/base/ime/mock_input_method.cc +++ b/chromium/ui/base/ime/mock_input_method.cc @@ -4,8 +4,8 @@ #include "ui/base/ime/mock_input_method.h" -#include "base/bind_helpers.h" #include "base/callback.h" +#include "base/callback_helpers.h" #include "build/build_config.h" #include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/text_input_client.h" diff --git a/chromium/ui/base/ime/mojom/text_input_state.mojom b/chromium/ui/base/ime/mojom/text_input_state.mojom index d52feb42d0a..cba3427a944 100644 --- a/chromium/ui/base/ime/mojom/text_input_state.mojom +++ b/chromium/ui/base/ime/mojom/text_input_state.mojom @@ -33,7 +33,7 @@ struct TextInputState { uint32 flags; // The value of input field. - mojo_base.mojom.String16? value; + mojo_base.mojom.BigString16? value; // The current selection range, or the caret position if nothing is selected. gfx.mojom.Range selection; diff --git a/chromium/ui/base/ime/utf_offset.cc b/chromium/ui/base/ime/utf_offset.cc new file mode 100644 index 00000000000..f6d4bd13d50 --- /dev/null +++ b/chromium/ui/base/ime/utf_offset.cc @@ -0,0 +1,41 @@ +// 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/ime/utf_offset.h" + +#include <string> + +#include "base/strings/string16.h" +#include "base/strings/string_piece.h" +#include "base/strings/utf_string_conversions.h" + +namespace ui { + +base::Optional<size_t> Utf16OffsetFromUtf8Offset(base::StringPiece text, + size_t utf8_offset) { + if (utf8_offset > text.length()) + return base::nullopt; + + // TODO(hidehiko): Update not to depend on UTF8ToUTF16 to avoid + // unnecessary memory allocation. + base::string16 converted; + if (!base::UTF8ToUTF16(text.data(), utf8_offset, &converted)) + return base::nullopt; + return converted.length(); +} + +base::Optional<size_t> Utf8OffsetFromUtf16Offset(base::StringPiece16 text, + size_t utf16_offset) { + if (utf16_offset > text.length()) + return base::nullopt; + + // TODO(hidehiko): Update not to depend on UTF16ToUTF8 to avoid + // unnecessary memory allocation. + std::string converted; + if (!base::UTF16ToUTF8(text.data(), utf16_offset, &converted)) + return base::nullopt; + return converted.length(); +} + +} // namespace ui diff --git a/chromium/ui/base/ime/utf_offset.h b/chromium/ui/base/ime/utf_offset.h new file mode 100644 index 00000000000..fc2ce21d4bc --- /dev/null +++ b/chromium/ui/base/ime/utf_offset.h @@ -0,0 +1,30 @@ +// 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_IME_UTF_OFFSET_H_ +#define UI_BASE_IME_UTF_OFFSET_H_ + +#include "base/component_export.h" +#include "base/optional.h" +#include "base/strings/string_piece_forward.h" + +namespace ui { + +// Given UTF8 string and its valid offset, returns the offset in UTF16. +// Returns nullopt if the given offset is invalid (not at a valid boundary +// or out of range). +COMPONENT_EXPORT(UI_BASE) +base::Optional<size_t> Utf16OffsetFromUtf8Offset(base::StringPiece text, + size_t utf8_offset); + +// Given UTF16 string and its valid offset, returns the offset in UTF8. +// Returns nullopt if the given offset is invalid (not at a valid boundary +// or out of range). +COMPONENT_EXPORT(UI_BASE) +base::Optional<size_t> Utf8OffsetFromUtf16Offset(base::StringPiece16 text, + size_t utf16_offset); + +} // namespace ui + +#endif // UI_BASE_IME_UTF_OFFSET_H_ diff --git a/chromium/ui/base/ime/utf_offset_unittest.cc b/chromium/ui/base/ime/utf_offset_unittest.cc new file mode 100644 index 00000000000..2c4af2576dc --- /dev/null +++ b/chromium/ui/base/ime/utf_offset_unittest.cc @@ -0,0 +1,140 @@ +// 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/ime/utf_offset.h" + +#include "base/optional.h" +#include "base/strings/string16.h" +#include "base/strings/string_piece.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace ui { +namespace { + +TEST(UtfOffsetTest, Utf16OffsetFromUtf8Offset) { + constexpr struct { + const char* str; + size_t offset; + base::Optional<size_t> expect; + } kTestCases[] = { + // 1 byte letters. + {u8"ab", 0, 0}, + {u8"ab", 1, 1}, + {u8"ab", 2, 2}, + {u8"ab", 3, base::nullopt}, + + // 2 byte letters. \u03A9=\xCE\xA9 is greek OMEGA. + {u8"\u03A9\u03A9", 0, 0}, + {u8"\u03A9\u03A9", 1, base::nullopt}, + {u8"\u03A9\u03A9", 2, 1}, + {u8"\u03A9\u03A9", 3, base::nullopt}, + {u8"\u03A9\u03A9", 4, 2}, + {u8"\u03A9\u03A9", 5, base::nullopt}, + + // 3 byte letters. \u3042=\xE3\x81\x82 is Japanese "A". + {u8"\u3042\u3042", 0, 0}, + {u8"\u3042\u3042", 1, base::nullopt}, + {u8"\u3042\u3042", 2, base::nullopt}, + {u8"\u3042\u3042", 3, 1}, + {u8"\u3042\u3042", 4, base::nullopt}, + {u8"\u3042\u3042", 5, base::nullopt}, + {u8"\u3042\u3042", 6, 2}, + {u8"\u3042\u3042", 7, base::nullopt}, + + // 4 byte letters. \U0001F3B7=\xF0\x9F\x8E\xB7 is "SAXOPHONE" emoji. + // Note that a surrogate pair advances by 2 in UTF16. + {u8"\U0001F3B7\U0001F3B7", 0, 0}, + {u8"\U0001F3B7\U0001F3B7", 1, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 2, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 3, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 4, 2}, + {u8"\U0001F3B7\U0001F3B7", 5, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 6, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 7, base::nullopt}, + {u8"\U0001F3B7\U0001F3B7", 8, 4}, + {u8"\U0001F3B7\U0001F3B7", 9, base::nullopt}, + + // Mix case. + {u8"a\u03A9b\u3042c\U0001F3B7d", 0, 0}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 1, 1}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 2, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 3, 2}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 4, 3}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 5, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 6, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 7, 4}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 8, 5}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 9, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 10, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 11, base::nullopt}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 12, 7}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 13, 8}, + {u8"a\u03A9b\u3042c\U0001F3B7d", 14, base::nullopt}, + }; + + for (const auto& test_case : kTestCases) { + EXPECT_EQ(test_case.expect, + Utf16OffsetFromUtf8Offset(test_case.str, test_case.offset)) + << " at " << test_case.str << "[" << test_case.offset << "]"; + } +} + +TEST(UtfOffsetTest, Utf8OffsetFromUtf16Offset) { + constexpr struct { + const char16_t* str; + size_t offset; + base::Optional<size_t> expect; + } kTestCases[] = { + // 1 byte letters. + {u"ab", 0, 0}, + {u"ab", 1, 1}, + {u"ab", 2, 2}, + {u"ab", 3, base::nullopt}, + + // 2 byte letters. + {u"\u03A9\u03A9", 0, 0}, + {u"\u03A9\u03A9", 1, 2}, + {u"\u03A9\u03A9", 2, 4}, + {u"\u03A9\u03A9", 3, base::nullopt}, + + // 3 byte letters. + {u"\u3042\u3042", 0, 0}, + {u"\u3042\u3042", 1, 3}, + {u"\u3042\u3042", 2, 6}, + {u"\u3042\u3042", 3, base::nullopt}, + + // 4 byte letters = surrogate pairs. + {u"\U0001F3B7\U0001F3B7", 0, 0}, + {u"\U0001F3B7\U0001F3B7", 1, base::nullopt}, + {u"\U0001F3B7\U0001F3B7", 2, 4}, + {u"\U0001F3B7\U0001F3B7", 3, base::nullopt}, + {u"\U0001F3B7\U0001F3B7", 4, 8}, + {u"\U0001F3B7\U0001F3B7", 5, base::nullopt}, + {u"\U0001F3B7\U0001F3B7", 6, base::nullopt}, + + // Mix case. + {u"a\u03A9b\u3042c\U0001F3B7d", 0, 0}, + {u"a\u03A9b\u3042c\U0001F3B7d", 1, 1}, + {u"a\u03A9b\u3042c\U0001F3B7d", 2, 3}, + {u"a\u03A9b\u3042c\U0001F3B7d", 3, 4}, + {u"a\u03A9b\u3042c\U0001F3B7d", 4, 7}, + {u"a\u03A9b\u3042c\U0001F3B7d", 5, 8}, + {u"a\u03A9b\u3042c\U0001F3B7d", 6, base::nullopt}, + {u"a\u03A9b\u3042c\U0001F3B7d", 7, 12}, + {u"a\u03A9b\u3042c\U0001F3B7d", 8, 13}, + {u"a\u03A9b\u3042c\U0001F3B7d", 9, base::nullopt}, + }; + + for (const auto& test_case : kTestCases) { + // TODO(crbug.com/911896): Get rid of reinterpret_cast on switching + // to char16_t. + base::string16 text(reinterpret_cast<const base::char16*>(test_case.str)); + EXPECT_EQ(test_case.expect, + Utf8OffsetFromUtf16Offset(text, test_case.offset)) + << " at " << text << "[" << test_case.offset << "]"; + } +} + +} // namespace +} // namespace ui diff --git a/chromium/ui/base/l10n/DIR_METADATA b/chromium/ui/base/l10n/DIR_METADATA new file mode 100644 index 00000000000..34512e7607a --- /dev/null +++ b/chromium/ui/base/l10n/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI>Internationalization" +}
\ No newline at end of file diff --git a/chromium/ui/base/l10n/OWNERS b/chromium/ui/base/l10n/OWNERS index b2ce105d5b7..a3be676b08b 100644 --- a/chromium/ui/base/l10n/OWNERS +++ b/chromium/ui/base/l10n/OWNERS @@ -1,2 +1 @@ -jshin@chromium.org -# COMPONENT: UI>Internationalization +jshin@chromium.org
\ No newline at end of file diff --git a/chromium/ui/base/l10n/formatter.cc b/chromium/ui/base/l10n/formatter.cc index e4446d4786f..684ead8c0a0 100644 --- a/chromium/ui/base/l10n/formatter.cc +++ b/chromium/ui/base/l10n/formatter.cc @@ -234,7 +234,7 @@ void Formatter::Format(Unit unit, int value, icu::UnicodeString* formatted_string) const { DCHECK(simple_format_[unit]); - DCHECK(formatted_string->isEmpty() == TRUE); + DCHECK(formatted_string->isEmpty()); UErrorCode error = U_ZERO_ERROR; FormatNumberInPlural(*simple_format_[unit], value, formatted_string, &error); @@ -250,7 +250,7 @@ void Formatter::Format(TwoUnits units, << "Detailed() not implemented for your (format, length) combination!"; DCHECK(detailed_format_[units][1]) << "Detailed() not implemented for your (format, length) combination!"; - DCHECK(formatted_string->isEmpty() == TRUE); + DCHECK(formatted_string->isEmpty()); UErrorCode error = U_ZERO_ERROR; FormatNumberInPlural(*detailed_format_[units][0], value_1, formatted_string, &error); @@ -283,7 +283,7 @@ std::unique_ptr<icu::MessageFormat> Formatter::InitFormat( base::string16 pattern = l10n_util::GetStringUTF16(pluralities.id); UErrorCode error = U_ZERO_ERROR; std::unique_ptr<icu::MessageFormat> format(new icu::MessageFormat( - icu::UnicodeString(FALSE, pattern.data(), pattern.length()), error)); + icu::UnicodeString(false, pattern.data(), pattern.length()), error)); DCHECK(U_SUCCESS(error)); if (format.get()) return format; diff --git a/chromium/ui/base/l10n/l10n_util.cc b/chromium/ui/base/l10n/l10n_util.cc index fdfc14ef542..291e24f9e77 100644 --- a/chromium/ui/base/l10n/l10n_util.cc +++ b/chromium/ui/base/l10n/l10n_util.cc @@ -270,9 +270,6 @@ bool IsLocaleAvailable(const std::string& locale) { // under a system locale Chrome is not localized to (e.g.Farsi on Linux), // but it'd slow down the start up time a little bit for locales Chrome is // localized to. So, we don't call it here. - if (!l10n_util::IsLocaleSupportedByOS(locale)) - return false; - return ui::ResourceBundle::LocaleDataPakExists(locale); } #endif @@ -309,8 +306,6 @@ struct AvailableLocalesTraits // and to which Chrome is not localized. if (IsLocalePartiallyPopulated(locale_name)) continue; - if (!l10n_util::IsLocaleSupportedByOS(locale_name)) - continue; // Normalize underscores to hyphens because that's what our locale files // use. std::replace(locale_name.begin(), locale_name.end(), '_', '-'); @@ -727,7 +722,7 @@ base::string16 GetStringFUTF16(int message_id, ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); const base::string16& format_string = rb.GetLocalizedString(message_id); -#ifndef NDEBUG +#if DCHECK_IS_ON() // Make sure every replacement string is being used, so we don't just // silently fail to insert one. If |offsets| is non-NULL, then don't do this // check as the code may simply want to find the placeholders rather than diff --git a/chromium/ui/base/l10n/l10n_util.h b/chromium/ui/base/l10n/l10n_util.h index 124248defa8..b821be44665 100644 --- a/chromium/ui/base/l10n/l10n_util.h +++ b/chromium/ui/base/l10n/l10n_util.h @@ -58,11 +58,6 @@ COMPONENT_EXPORT(UI_BASE) bool IsLocaleNameTranslated(const char* locale, const std::string& display_locale); -// Given a locale code, return true if the OS is capable of supporting it. -// For instance, Oriya is not well supported on Windows XP and we return -// false for "or". -bool IsLocaleSupportedByOS(const std::string& locale); - // This method returns the display name of the locale code in |display_locale|. // For example, for |locale| = "fr" and |display_locale| = "en", diff --git a/chromium/ui/base/l10n/l10n_util_posix.cc b/chromium/ui/base/l10n/l10n_util_posix.cc deleted file mode 100644 index 3f75f324cf2..00000000000 --- a/chromium/ui/base/l10n/l10n_util_posix.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2011 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 <stddef.h> - -#include <string> - -#include "base/stl_util.h" -#include "build/build_config.h" - -#if defined(OS_CHROMEOS) -#include "base/strings/string_util.h" -#endif - -namespace l10n_util { - -bool IsLocaleSupportedByOS(const std::string& locale) { -#if defined(OS_CHROMEOS) - // We don't have translations yet for am, and sw. - // TODO(jungshik): Once the above issues are resolved, change this back - // to return true. - static const char kUnsupportedLocales[][3] = {"am", "sw"}; - for (size_t i = 0; i < base::size(kUnsupportedLocales); ++i) { - if (base::LowerCaseEqualsASCII(locale, kUnsupportedLocales[i])) - return false; - } - return true; -#else - // Return true blindly for now. - return true; -#endif -} - -} // namespace l10n_util diff --git a/chromium/ui/base/l10n/l10n_util_win.cc b/chromium/ui/base/l10n/l10n_util_win.cc index 8b3850c2441..fec321f8904 100644 --- a/chromium/ui/base/l10n/l10n_util_win.cc +++ b/chromium/ui/base/l10n/l10n_util_win.cc @@ -63,18 +63,14 @@ void HWNDSetRTLLayout(HWND hwnd) { } } -bool IsLocaleSupportedByOS(const std::string& locale) { - return true; -} - -bool NeedOverrideDefaultUIFont(base::string16* override_font_family, +bool NeedOverrideDefaultUIFont(std::wstring* override_font_family, double* font_size_scaler) { // This is rather simple-minded to deal with the UI font size // issue for some Indian locales (ml, bn, hi) for which // the default Windows fonts are too small to be legible. For those // locales, IDS_UI_FONT_FAMILY is set to an actual font family to // use while for other locales, it's set to 'default'. - base::string16 ui_font_family = GetStringUTF16(IDS_UI_FONT_FAMILY); + std::wstring ui_font_family = GetWideString(IDS_UI_FONT_FAMILY); int scaler100; if (!base::StringToInt(l10n_util::GetStringUTF16(IDS_UI_FONT_SIZE_SCALER), &scaler100)) @@ -97,12 +93,12 @@ bool NeedOverrideDefaultUIFont(base::string16* override_font_family, } void OverrideLocaleWithUILanguageList() { - std::vector<base::string16> ui_languages; + std::vector<std::wstring> ui_languages; if (base::win::i18n::GetThreadPreferredUILanguageList(&ui_languages)) { std::vector<std::string> ascii_languages; ascii_languages.reserve(ui_languages.size()); std::transform(ui_languages.begin(), ui_languages.end(), - std::back_inserter(ascii_languages), &base::UTF16ToASCII); + std::back_inserter(ascii_languages), &base::WideToASCII); override_locale_holder.Get().swap_value(&ascii_languages); } else { NOTREACHED() << "Failed to determine the UI language for locale override."; @@ -113,4 +109,8 @@ const std::vector<std::string>& GetLocaleOverrides() { return override_locale_holder.Get().value(); } +std::wstring GetWideString(int message_id) { + return base::UTF16ToWide(GetStringUTF16(message_id)); +} + } // namespace l10n_util diff --git a/chromium/ui/base/l10n/l10n_util_win.h b/chromium/ui/base/l10n/l10n_util_win.h index 70a7be88046..380bba077d3 100644 --- a/chromium/ui/base/l10n/l10n_util_win.h +++ b/chromium/ui/base/l10n/l10n_util_win.h @@ -10,7 +10,6 @@ #include <vector> #include "base/component_export.h" -#include "base/strings/string16.h" namespace l10n_util { @@ -41,7 +40,7 @@ COMPONENT_EXPORT(UI_BASE) void HWNDSetRTLLayout(HWND hwnd); // filled with the font family name and the size scaler. The output // parameters are not modified if the return value is false. COMPONENT_EXPORT(UI_BASE) -bool NeedOverrideDefaultUIFont(base::string16* override_font_family, +bool NeedOverrideDefaultUIFont(std::wstring* override_font_family, double* font_size_scaler); // Allow processes to override the configured locale with the user's Windows UI @@ -53,6 +52,9 @@ COMPONENT_EXPORT(UI_BASE) void OverrideLocaleWithUILanguageList(); // or failed to be overridden. COMPONENT_EXPORT(UI_BASE) const std::vector<std::string>& GetLocaleOverrides(); +// Pulls resource string from the string bundle and returns it. +COMPONENT_EXPORT(UI_BASE) std::wstring GetWideString(int message_id); + } // namespace l10n_util #endif // UI_BASE_L10N_L10N_UTIL_WIN_H_ diff --git a/chromium/ui/base/models/dialog_model.cc b/chromium/ui/base/models/dialog_model.cc index 5479c788846..b1077c7788f 100644 --- a/chromium/ui/base/models/dialog_model.cc +++ b/chromium/ui/base/models/dialog_model.cc @@ -4,7 +4,7 @@ #include "ui/base/models/dialog_model.h" -#include "base/bind_helpers.h" +#include "base/callback_helpers.h" #include "base/ranges/algorithm.h" namespace ui { @@ -12,6 +12,9 @@ namespace ui { DialogModel::Builder::Builder(std::unique_ptr<DialogModelDelegate> delegate) : model_(std::make_unique<DialogModel>(util::PassKey<Builder>(), std::move(delegate))) {} + +DialogModel::Builder::Builder() : Builder(nullptr) {} + DialogModel::Builder::~Builder() { DCHECK(!model_) << "Model should've been built."; } @@ -75,7 +78,8 @@ DialogModel::Builder& DialogModel::Builder::SetInitiallyFocusedField( DialogModel::DialogModel(util::PassKey<Builder>, std::unique_ptr<DialogModelDelegate> delegate) : delegate_(std::move(delegate)) { - delegate_->set_dialog_model(this); + if (delegate_) + delegate_->set_dialog_model(this); } DialogModel::~DialogModel() = default; diff --git a/chromium/ui/base/models/dialog_model.h b/chromium/ui/base/models/dialog_model.h index 30f8176630a..4a5be0d6837 100644 --- a/chromium/ui/base/models/dialog_model.h +++ b/chromium/ui/base/models/dialog_model.h @@ -14,6 +14,7 @@ #include "base/util/type_safety/pass_key.h" #include "ui/base/models/dialog_model_field.h" #include "ui/base/models/dialog_model_host.h" +#include "ui/base/models/image_model.h" #include "ui/base/ui_base_types.h" namespace ui { @@ -83,15 +84,41 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { public: // Builder for DialogModel. Used for properties that are either only or // commonly const after construction. - class COMPONENT_EXPORT(UI_BASE) Builder { + class COMPONENT_EXPORT(UI_BASE) Builder final { public: + // Constructs a Builder for a DialogModel with a DialogModelDelegate whose + // lifetime (and storage) is tied to the lifetime of the DialogModel. explicit Builder(std::unique_ptr<DialogModelDelegate> delegate); + + // Constructs a DialogModel without a DialogModelDelegate (that doesn't + // require storage tied to the DialogModel). For access to the DialogModel + // during construction (for use in callbacks), use model(). + Builder(); + + Builder(const Builder&) = delete; + Builder& operator=(const Builder&) = delete; + ~Builder(); std::unique_ptr<DialogModel> Build() WARN_UNUSED_RESULT; - Builder& SetShowCloseButton(bool show_close_button) { - model_->show_close_button_ = show_close_button; + // Gets the DialogModel. Used for setting up callbacks that make use of the + // model later once it's fully constructed. This is useful for dialogs or + // callbacks that don't use DialogModelDelegate and don't have direct access + // to the model through DialogModelDelegate::dialog_model(). + // + // Note that the DialogModel* returned here is only for registering + // callbacks with the DialogModel::Builder. These callbacks share lifetimes + // with the DialogModel so uses of it will not result in use-after-frees. + DialogModel* model() { return model_.get(); } + + // Overrides the close-x use for the dialog. Should be avoided as the + // close-x is generally derived from dialog modality. Kept to allow + // conversion of dialogs that currently do not allow style. + // TODO(pbos): Propose UX updates to existing dialogs that require this, + // then remove OverrideShowCloseButton(). + Builder& OverrideShowCloseButton(bool show_close_button) { + model_->override_show_close_button_ = show_close_button; return *this; } @@ -100,6 +127,11 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { return *this; } + Builder& SetIcon(ImageModel icon) { + model_->icon_ = std::move(icon); + return *this; + } + // Make screen readers announce the contents of the dialog as it appears. // See |ax::mojom::Role::kAlertDialog|. Builder& SetIsAlertDialog() { @@ -192,6 +224,10 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { DialogModel(util::PassKey<DialogModel::Builder>, std::unique_ptr<DialogModelDelegate> delegate); + + DialogModel(const DialogModel&) = delete; + DialogModel& operator=(const DialogModel&) = delete; + ~DialogModel(); // The host in which this model is hosted. Set by the Host implementation @@ -242,14 +278,17 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { host_ = host; } - bool show_close_button(util::PassKey<DialogModelHost>) const { - return show_close_button_; + const base::Optional<bool>& override_show_close_button( + util::PassKey<DialogModelHost>) const { + return override_show_close_button_; } const base::string16& title(util::PassKey<DialogModelHost>) const { return title_; } + const ImageModel& icon(util::PassKey<DialogModelHost>) const { return icon_; } + base::Optional<int> initially_focused_field( util::PassKey<DialogModelHost>) const { return initially_focused_field_; @@ -293,11 +332,11 @@ class COMPONENT_EXPORT(UI_BASE) DialogModel final { std::unique_ptr<DialogModelDelegate> delegate_; DialogModelHost* host_ = nullptr; - bool show_close_button_ = false; + base::Optional<bool> override_show_close_button_; bool close_on_deactivate_ = true; base::string16 title_; + ImageModel icon_; - static constexpr int kExtraButtonId = DIALOG_BUTTON_LAST + 1; std::vector<std::unique_ptr<DialogModelField>> fields_; base::Optional<int> initially_focused_field_; bool is_alert_dialog_ = false; diff --git a/chromium/ui/base/models/dialog_model_field.cc b/chromium/ui/base/models/dialog_model_field.cc index 0781fdb60f1..3432b970aa8 100644 --- a/chromium/ui/base/models/dialog_model_field.cc +++ b/chromium/ui/base/models/dialog_model_field.cc @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "ui/base/models/dialog_model_field.h" + #include "base/bind.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/models/dialog_model.h" namespace ui { @@ -18,9 +20,23 @@ DialogModelLabel::Link::Link(int message_id, base::RepeatingClosure closure) DialogModelLabel::Link::Link(const Link&) = default; DialogModelLabel::Link::~Link() = default; -DialogModelLabel::DialogModelLabel(int message_id) : message_id_(message_id) {} +DialogModelLabel::DialogModelLabel(int message_id) + : message_id_(message_id), + string_(l10n_util::GetStringUTF16(message_id_)) {} DialogModelLabel::DialogModelLabel(int message_id, std::vector<Link> links) - : message_id_(message_id), links_(std::move(links)) {} + : message_id_(message_id), links_(std::move(links)) { + // Note that this constructor does not set |string_| which is invalid for + // labels with links. +} + +DialogModelLabel::DialogModelLabel(base::string16 fixed_string) + : message_id_(-1), string_(std::move(fixed_string)) {} + +const base::string16& DialogModelLabel::GetString( + util::PassKey<DialogModelHost>) const { + DCHECK(links_.empty()); + return string_; +} DialogModelLabel::DialogModelLabel(const DialogModelLabel&) = default; diff --git a/chromium/ui/base/models/dialog_model_field.h b/chromium/ui/base/models/dialog_model_field.h index 35a622dad5e..1e2c2c87d50 100644 --- a/chromium/ui/base/models/dialog_model_field.h +++ b/chromium/ui/base/models/dialog_model_field.h @@ -45,6 +45,7 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelLabel { }; explicit DialogModelLabel(int message_id); + explicit DialogModelLabel(base::string16 fixed_string); DialogModelLabel(const DialogModelLabel&); DialogModelLabel& operator=(const DialogModelLabel&) = delete; ~DialogModelLabel(); @@ -54,11 +55,22 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelLabel { static DialogModelLabel CreateWithLinks(int message_id, std::vector<Link> links); + // Gets the string. Not for use with links, in which case the caller must use + // links() and message_id() to construct the final label. This is required to + // style the final label appropriately and support link callbacks. The caller + // is responsible for checking links().empty() before calling this. + const base::string16& GetString(util::PassKey<DialogModelHost>) const; + DialogModelLabel& set_is_secondary() { is_secondary_ = true; return *this; } + DialogModelLabel& set_allow_character_break() { + allow_character_break_ = true; + return *this; + } + int message_id(util::PassKey<DialogModelHost>) const { return message_id_; } const std::vector<Link> links(util::PassKey<DialogModelHost>) const { return links_; @@ -66,13 +78,18 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelLabel { bool is_secondary(util::PassKey<DialogModelHost>) const { return is_secondary_; } + bool allow_character_break(util::PassKey<DialogModelHost>) const { + return allow_character_break_; + } private: explicit DialogModelLabel(int message_id, std::vector<Link> links); const int message_id_; + const base::string16 string_; const std::vector<Link> links_; bool is_secondary_ = false; + bool allow_character_break_ = false; }; // These "field" classes represent entries in a DialogModel. They are owned diff --git a/chromium/ui/base/pointer/DIR_METADATA b/chromium/ui/base/pointer/DIR_METADATA new file mode 100644 index 00000000000..198db497480 --- /dev/null +++ b/chromium/ui/base/pointer/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals>Input" +} diff --git a/chromium/ui/base/pointer/OWNERS b/chromium/ui/base/pointer/OWNERS index c55b9d29ec6..b3dbc20b12b 100644 --- a/chromium/ui/base/pointer/OWNERS +++ b/chromium/ui/base/pointer/OWNERS @@ -2,5 +2,3 @@ sadrul@chromium.org per-file touch_ui_controller*=kylixrd@chromium.org per-file touch_ui_controller*=robliao@chromium.org - -# COMPONENT: Internal>Input diff --git a/chromium/ui/base/pointer/touch_ui_controller_unittest.cc b/chromium/ui/base/pointer/touch_ui_controller_unittest.cc index 1cfa4b8e170..98d7baa0848 100644 --- a/chromium/ui/base/pointer/touch_ui_controller_unittest.cc +++ b/chromium/ui/base/pointer/touch_ui_controller_unittest.cc @@ -6,7 +6,7 @@ #include "base/macros.h" #include "base/scoped_observer.h" -#include "base/test/bind_test_util.h" +#include "base/test/bind.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/pointer/touch_ui_controller.h" diff --git a/chromium/ui/base/prediction/prediction_metrics_handler.cc b/chromium/ui/base/prediction/prediction_metrics_handler.cc index e782e6736e5..f01862443c8 100644 --- a/chromium/ui/base/prediction/prediction_metrics_handler.cc +++ b/chromium/ui/base/prediction/prediction_metrics_handler.cc @@ -2,22 +2,43 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <utility> + #include "ui/base/prediction/prediction_metrics_handler.h" #include "base/metrics/histogram_functions.h" +#include "base/strings/strcat.h" namespace ui { -PredictionMetricsHandler::PredictionMetricsHandler() {} -PredictionMetricsHandler::~PredictionMetricsHandler() {} +PredictionMetricsHandler::PredictionMetricsHandler(const char* histogram_name) + : histogram_name_(std::move(histogram_name)) {} +PredictionMetricsHandler::~PredictionMetricsHandler() = default; void PredictionMetricsHandler::AddRealEvent(const gfx::PointF& pos, const base::TimeTicks& time_stamp, const base::TimeTicks& frame_time, bool scrolling) { - // Be sure real events are ordered over time - DCHECK(events_queue_.empty() || - time_stamp >= events_queue_.back().time_stamp); + // Real events should arrive in order over time, and if they aren't then just + // bail. Early out instead of DCHECKing in order to handle delegated ink + // trails. Delegated ink trails may submit points out of order in a situation + // such as three points with timestamps = 1, 2, and 3 making up the trail on + // one frame, and then on the next frame only the points with timestamp 2 and + // 3 make up the trail. In this case, 2 would be added as a real point again, + // but it has a timestamp earlier than 3, so a DCHECK would fail. Early out + // here will not impact correctness since 2 already exists in |events_queue_|. + if (!events_queue_.empty() && time_stamp <= events_queue_.back().time_stamp) { + // Confirm that the above assertion is true, and that timestamp 2 (from + // the above example) exists in |events_queue_|. + bool event_exists = false; + for (uint64_t i = 0; i < events_queue_.size() && !event_exists; ++i) { + if (events_queue_[i].time_stamp == time_stamp) + event_exists = true; + } + DCHECK(event_exists); + return; + } + EventData e; if (scrolling) e.pos = gfx::PointF(0, pos.y()); @@ -130,25 +151,25 @@ void PredictionMetricsHandler::ComputeMetrics() { for (int i = 0; i < first_needed_event - 1; i++) events_queue_.pop_front(); - std::string kPredictionMetrics = "Event.InputEventPrediction.Scroll."; - double score = ComputeOverUnderPredictionMetric(); if (score >= 0) { - base::UmaHistogramCounts1000(kPredictionMetrics + "OverPrediction", score); + base::UmaHistogramCounts1000( + base::StrCat({histogram_name_, ".OverPrediction"}), score); } else { - base::UmaHistogramCounts1000(kPredictionMetrics + "UnderPrediction", - -score); + base::UmaHistogramCounts1000( + base::StrCat({histogram_name_, ".UnderPrediction"}), -score); } // Need |last_predicted_| to compute WrongDirection and Jitter metrics. if (!last_predicted_.has_value()) return; - base::UmaHistogramBoolean(kPredictionMetrics + "WrongDirection", + base::UmaHistogramBoolean(base::StrCat({histogram_name_, ".WrongDirection"}), ComputeWrongDirectionMetric()); - base::UmaHistogramCounts1000(kPredictionMetrics + "PredictionJitter", - ComputePredictionJitterMetric()); - base::UmaHistogramCounts1000(kPredictionMetrics + "VisualJitter", + base::UmaHistogramCounts1000( + base::StrCat({histogram_name_, ".PredictionJitter"}), + ComputePredictionJitterMetric()); + base::UmaHistogramCounts1000(base::StrCat({histogram_name_, ".VisualJitter"}), ComputeVisualJitterMetric()); } diff --git a/chromium/ui/base/prediction/prediction_metrics_handler.h b/chromium/ui/base/prediction/prediction_metrics_handler.h index 648ccdd9998..24167f5954f 100644 --- a/chromium/ui/base/prediction/prediction_metrics_handler.h +++ b/chromium/ui/base/prediction/prediction_metrics_handler.h @@ -25,7 +25,7 @@ class PredictionMetricsHandlerTest; // few metrics. class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler { public: - explicit PredictionMetricsHandler(); + explicit PredictionMetricsHandler(const char* histogram_name); ~PredictionMetricsHandler(); // Struct used to store predicted and real event information. @@ -103,6 +103,12 @@ class COMPONENT_EXPORT(UI_BASE_PREDICTION) PredictionMetricsHandler { base::Optional<gfx::PointF> last_predicted_ = base::nullopt; // The first real event position which time is later than the predicted time. gfx::PointF next_real_; + + // Beginning of the full histogram name. It will have the various metrics' + // names (.OverPrediction, .UnderPrediction, .WrongDirection, + // .PredictionJitter, .VisualJitter) appended to it when counting the metric + // in a histogram. + const char* const histogram_name_; }; } // namespace ui diff --git a/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc b/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc index f44df0d01dd..fcfa9c052a7 100644 --- a/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc +++ b/chromium/ui/base/prediction/prediction_metrics_handler_unittest.cc @@ -29,7 +29,8 @@ class PredictionMetricsHandlerTest : public testing::Test { explicit PredictionMetricsHandlerTest() {} void SetUp() override { - metrics_handler_ = std::make_unique<PredictionMetricsHandler>(); + metrics_handler_ = std::make_unique<PredictionMetricsHandler>( + "Event.InputEventPrediction.Scroll"); histogram_tester_ = std::make_unique<base::HistogramTester>(); } diff --git a/chromium/ui/base/resource/DIR_METADATA b/chromium/ui/base/resource/DIR_METADATA new file mode 100644 index 00000000000..63fc482f75d --- /dev/null +++ b/chromium/ui/base/resource/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "Internals" +}
\ No newline at end of file diff --git a/chromium/ui/base/resource/OWNERS b/chromium/ui/base/resource/OWNERS index 1c5b89efccb..56c2d34b387 100644 --- a/chromium/ui/base/resource/OWNERS +++ b/chromium/ui/base/resource/OWNERS @@ -1,2 +1 @@ -per-file *_android.*=file://chrome/browser/android/OWNERS -# COMPONENT: Internals +per-file *_android.*=file://chrome/browser/android/OWNERS
\ No newline at end of file diff --git a/chromium/ui/base/resource/mock_resource_bundle_delegate.h b/chromium/ui/base/resource/mock_resource_bundle_delegate.h index 0df2e07a7d6..54e75e18b4b 100644 --- a/chromium/ui/base/resource/mock_resource_bundle_delegate.h +++ b/chromium/ui/base/resource/mock_resource_bundle_delegate.h @@ -26,6 +26,8 @@ class MockResourceBundleDelegate : public ResourceBundle::Delegate { MOCK_METHOD2(LoadDataResourceBytes, base::RefCountedMemory*(int resource_id, ScaleFactor scale_factor)); + MOCK_METHOD1(LoadDataResourceString, + base::Optional<std::string>(int resource_id)); MOCK_CONST_METHOD3(GetRawDataResource, bool(int resource_id, ScaleFactor scale_factor, diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc index d14bc858f56..2b24b4ce2e2 100644 --- a/chromium/ui/base/resource/resource_bundle.cc +++ b/chromium/ui/base/resource/resource_bundle.cc @@ -85,7 +85,7 @@ base::FilePath GetResourcesPakFilePath(const std::string& pak_name) { // Return just the name of the pak file. #if defined(OS_WIN) - return base::FilePath(base::ASCIIToUTF16(pak_name)); + return base::FilePath(base::ASCIIToWide(pak_name)); #else return base::FilePath(pak_name.c_str()); #endif // OS_WIN @@ -659,6 +659,13 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale( } std::string ResourceBundle::LoadDataResourceString(int resource_id) const { + if (delegate_) { + base::Optional<std::string> data = + delegate_->LoadDataResourceString(resource_id); + if (data) + return data.value(); + } + return LoadDataResourceStringForScale(resource_id, ui::SCALE_FACTOR_NONE); } diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h index 317ad685e41..51dbdfab396 100644 --- a/chromium/ui/base/resource/resource_bundle.h +++ b/chromium/ui/base/resource/resource_bundle.h @@ -18,6 +18,7 @@ #include "base/files/memory_mapped_file.h" #include "base/gtest_prod_util.h" #include "base/macros.h" +#include "base/optional.h" #include "base/sequence_checker.h" #include "base/strings/string16.h" #include "base/strings/string_piece.h" @@ -73,6 +74,8 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle { // Delegate class that allows interception of pack file loading and resource // requests. The methods of this class may be called on multiple threads. + // TODO(crbug.com/1146446): The interface and usage model of this class are + // clunky; it would be good to clean them up. class Delegate { public: // Called before a resource pack file is loaded. Return the full path for @@ -105,6 +108,14 @@ class COMPONENT_EXPORT(UI_BASE) ResourceBundle { int resource_id, ScaleFactor scale_factor) = 0; + // Supports intercepting of ResourceBundle::LoadDataResourceString(): Return + // a populated base::Optional instance to override the value that + // ResourceBundle::LoadDataResourceString() would return by default, or an + // empty base::Optional instance to pass through to the default behavior of + // ResourceBundle::LoadDataResourceString(). + virtual base::Optional<std::string> LoadDataResourceString( + int resource_id) = 0; + // Retrieve a raw data resource. Return true if a resource was provided or // false to attempt retrieval of the default resource. virtual bool GetRawDataResource(int resource_id, diff --git a/chromium/ui/base/resource/resource_bundle_android.cc b/chromium/ui/base/resource/resource_bundle_android.cc index e8cf7b78c66..ddb0e045499 100644 --- a/chromium/ui/base/resource/resource_bundle_android.cc +++ b/chromium/ui/base/resource/resource_bundle_android.cc @@ -238,9 +238,10 @@ void LoadMainAndroidPackFile(const char* path_within_apk, } } -void LoadPackFileFromApk(const std::string& path) { +void LoadPackFileFromApk(const std::string& path, + const std::string& split_name) { base::MemoryMappedFile::Region region; - int fd = base::android::OpenApkAsset(path, ®ion); + int fd = base::android::OpenApkAsset(path, split_name, ®ion); CHECK_GE(fd, 0) << "Could not find " << path << " in APK."; ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( base::File(fd), region, ui::SCALE_FACTOR_NONE); diff --git a/chromium/ui/base/resource/resource_bundle_android.h b/chromium/ui/base/resource/resource_bundle_android.h index 99096888fc9..f3b480e2117 100644 --- a/chromium/ui/base/resource/resource_bundle_android.h +++ b/chromium/ui/base/resource/resource_bundle_android.h @@ -20,7 +20,9 @@ void LoadMainAndroidPackFile(const char* path_within_apk, const base::FilePath& disk_file_path); // Loads a PAK file from the APK and makes the contained resources accessible. -COMPONENT_EXPORT(UI_BASE) void LoadPackFileFromApk(const std::string& path); +COMPONENT_EXPORT(UI_BASE) +void LoadPackFileFromApk(const std::string& path, + const std::string& split_name); // Returns the file descriptor and region for resources.pak. COMPONENT_EXPORT(UI_BASE) diff --git a/chromium/ui/base/resource/resource_bundle_fuchsia.cc b/chromium/ui/base/resource/resource_bundle_fuchsia.cc index e4139f25896..0a54b752ce4 100644 --- a/chromium/ui/base/resource/resource_bundle_fuchsia.cc +++ b/chromium/ui/base/resource/resource_bundle_fuchsia.cc @@ -4,13 +4,22 @@ #include "ui/base/resource/resource_bundle.h" +#include "base/base_paths.h" #include "base/macros.h" +#include "base/path_service.h" #include "ui/gfx/image/image.h" namespace ui { void ResourceBundle::LoadCommonResources() { - LoadChromeResources(); + constexpr char kCommonResourcesPakPath[] = "common_resources.pak"; + + base::FilePath asset_root; + bool result = base::PathService::Get(base::DIR_ASSETS, &asset_root); + DCHECK(result); + + AddDataPackFromPath(asset_root.Append(kCommonResourcesPakPath), + ui::SCALE_FACTOR_100P); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { diff --git a/chromium/ui/base/text/DIR_METADATA b/chromium/ui/base/text/DIR_METADATA new file mode 100644 index 00000000000..55a8d5782a3 --- /dev/null +++ b/chromium/ui/base/text/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI>Localization" +}
\ No newline at end of file diff --git a/chromium/ui/base/text/OWNERS b/chromium/ui/base/text/OWNERS index b999cb152dd..b9e8da980ec 100644 --- a/chromium/ui/base/text/OWNERS +++ b/chromium/ui/base/text/OWNERS @@ -1,3 +1 @@ asvitkine@chromium.org - -# COMPONENT: UI>Localization diff --git a/chromium/ui/base/ui_base_features.cc b/chromium/ui/base/ui_base_features.cc index d35c5b6fe04..2d856a29782 100644 --- a/chromium/ui/base/ui_base_features.cc +++ b/chromium/ui/base/ui_base_features.cc @@ -10,12 +10,20 @@ #include "base/win/windows_version.h" #endif +#if defined(OS_ANDROID) +#include "base/android/build_info.h" +#endif + namespace features { #if defined(OS_WIN) // If enabled, calculate native window occlusion - Windows-only. const base::Feature kCalculateNativeWinOcclusion{ "CalculateNativeWinOcclusion", base::FEATURE_ENABLED_BY_DEFAULT}; + +const base::Feature kCalculateNativeWinOcclusionCheckVirtualDesktopUsed{ + "CalculateNativeWinOcclusionCheckVirtualDesktopUsed", + base::FEATURE_DISABLED_BY_DEFAULT}; #endif // OW_WIN // Whether or not to delegate color queries to the color provider. @@ -50,7 +58,7 @@ const base::Feature kPercentBasedScrolling = { // Allows requesting unadjusted movement when entering pointerlock. const base::Feature kPointerLockOptions = {"PointerLockOptions", - base::FEATURE_DISABLED_BY_DEFAULT}; + base::FEATURE_ENABLED_BY_DEFAULT}; // Allows system caption style for WebVTT Captions. const base::Feature kSystemCaptionStyle{"SystemCaptionStyle", @@ -67,7 +75,7 @@ bool IsNotificationIndicatorEnabled() { return base::FeatureList::IsEnabled(kNotificationIndicator); } -// Enables GPU rasterization for all UI drawing (where not blacklisted). +// Enables GPU rasterization for all UI drawing (where not blocklisted). const base::Feature kUiGpuRasterization = {"UiGpuRasterization", #if defined(OS_APPLE) || defined(OS_CHROMEOS) || defined(OS_FUCHSIA) base::FEATURE_ENABLED_BY_DEFAULT @@ -100,7 +108,8 @@ const base::Feature kCompositorThreadedScrollbarScrolling = { // native apps on Windows. const base::Feature kExperimentalFlingAnimation { "ExperimentalFlingAnimation", -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) +#if defined(OS_WIN) || \ + (defined(OS_LINUX) && !defined(OS_CHROMEOS) && !BUILDFLAG(IS_LACROS)) base::FEATURE_ENABLED_BY_DEFAULT #else base::FEATURE_DISABLED_BY_DEFAULT @@ -156,9 +165,16 @@ bool IsForcedColorsEnabled() { return forced_colors_enabled; } -// Enables the eye-dropper in the refresh color-picker. -const base::Feature kEyeDropper{"EyeDropper", - base::FEATURE_DISABLED_BY_DEFAULT}; +// Enables the eye-dropper in the refresh color-picker for Windows and Mac. +// This feature will be released for other platforms in later milestones. +const base::Feature kEyeDropper { + "EyeDropper", +#if defined(OS_WIN) || defined(OS_MAC) + base::FEATURE_ENABLED_BY_DEFAULT +#else + base::FEATURE_DISABLED_BY_DEFAULT +#endif +}; bool IsEyeDropperEnabled() { return IsFormControlsRefreshEnabled() && @@ -258,4 +274,16 @@ const char kFilterNameOneEuro[] = "one_euro_filter"; const base::Feature kSwipeToMoveCursor{"SwipeToMoveCursor", base::FEATURE_DISABLED_BY_DEFAULT}; +bool IsSwipeToMoveCursorEnabled() { + static const bool enabled = + base::FeatureList::IsEnabled(kSwipeToMoveCursor) +#if defined(OS_ANDROID) + && base::android::BuildInfo::GetInstance()->sdk_int() >= + base::android::SDK_VERSION_R; +#else + ; +#endif + return enabled; +} + } // namespace features diff --git a/chromium/ui/base/ui_base_features.h b/chromium/ui/base/ui_base_features.h index fbd1bb06fe2..304805ea7f8 100644 --- a/chromium/ui/base/ui_base_features.h +++ b/chromium/ui/base/ui_base_features.h @@ -47,6 +47,8 @@ COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsUiGpuRasterizationEnabled(); COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kCalculateNativeWinOcclusion; COMPONENT_EXPORT(UI_BASE_FEATURES) +extern const base::Feature kCalculateNativeWinOcclusionCheckVirtualDesktopUsed; +COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kElasticOverscrollWin; COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kInputPaneOnScreenKeyboard; @@ -146,6 +148,8 @@ COMPONENT_EXPORT(UI_BASE_FEATURES) extern const char kFilterNameOneEuro[]; COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kSwipeToMoveCursor; +COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsSwipeToMoveCursorEnabled(); + } // namespace features #endif // UI_BASE_UI_BASE_FEATURES_H_ diff --git a/chromium/ui/base/webui/DIR_METADATA b/chromium/ui/base/webui/DIR_METADATA new file mode 100644 index 00000000000..cf1499073d6 --- /dev/null +++ b/chromium/ui/base/webui/DIR_METADATA @@ -0,0 +1,11 @@ +# Metadata information for this directory. +# +# For more information on DIR_METADATA files, see: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md +# +# For the schema of this file, see Metadata message: +# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto + +monorail { + component: "UI>Browser>WebUI" +}
\ No newline at end of file diff --git a/chromium/ui/base/webui/OWNERS b/chromium/ui/base/webui/OWNERS index 918baa1330f..a42ad1efcbd 100644 --- a/chromium/ui/base/webui/OWNERS +++ b/chromium/ui/base/webui/OWNERS @@ -1,3 +1 @@ file://ui/webui/PLATFORM_OWNERS - -# COMPONENT: UI>Browser>WebUI diff --git a/chromium/ui/base/webui/jstemplate_builder.cc b/chromium/ui/base/webui/jstemplate_builder.cc index 50c52507d00..0506b643ea3 100644 --- a/chromium/ui/base/webui/jstemplate_builder.cc +++ b/chromium/ui/base/webui/jstemplate_builder.cc @@ -15,6 +15,7 @@ #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/template_expressions.h" +#include "ui/resources/grit/webui_generated_resources.h" #include "ui/resources/grit/webui_resources.h" namespace webui { @@ -41,7 +42,7 @@ void AppendLoadTimeData(std::string* output) { // fetch and cache the pointer of the jstemplate resource source text. std::string load_time_data_src = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( - IDR_WEBUI_JS_LOAD_TIME_DATA); + IDR_WEBUI_JS_LOAD_TIME_DATA_JS); if (load_time_data_src.empty()) { NOTREACHED() << "Unable to get loadTimeData src"; @@ -58,7 +59,7 @@ void AppendJsTemplateSourceHtml(std::string* output) { // fetch and cache the pointer of the jstemplate resource source text. std::string jstemplate_src = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( - IDR_WEBUI_JSTEMPLATE_JS); + IDR_WEBUI_JS_JSTEMPLATE_COMPILED_JS); if (jstemplate_src.empty()) { NOTREACHED() << "Unable to get jstemplate src"; diff --git a/chromium/ui/base/webui/web_ui_util.cc b/chromium/ui/base/webui/web_ui_util.cc index 9b8ad27b170..a3fa61f66d8 100644 --- a/chromium/ui/base/webui/web_ui_util.cc +++ b/chromium/ui/base/webui/web_ui_util.cc @@ -21,12 +21,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/template_expressions.h" -#include "ui/base/ui_base_features.h" #include "ui/base/window_open_disposition.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image_skia.h" -#include "ui/resources/grit/webui_resources.h" +#include "ui/resources/grit/webui_generated_resources.h" #include "ui/strings/grit/app_locale_settings.h" #include "url/gurl.h" @@ -34,10 +33,6 @@ #include "base/win/windows_version.h" #endif -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include "ui/base/ui_base_features.h" -#endif - namespace webui { namespace { std::string GetWebUiCssTextDefaults(const std::string& css_template) { @@ -187,10 +182,6 @@ void ParsePathAndScale(const GURL& url, ParsePathAndImageSpec(url, path, scale_factor, nullptr); } -void ParsePathAndFrame(const GURL& url, std::string* path, int* frame_index) { - ParsePathAndImageSpec(url, path, nullptr, frame_index); -} - void SetLoadTimeDataDefaults(const std::string& app_locale, base::DictionaryValue* localized_strings) { localized_strings->SetString("fontfamily", GetFontFamily()); @@ -211,14 +202,14 @@ std::string GetWebUiCssTextDefaults() { const ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); return GetWebUiCssTextDefaults( - resource_bundle.LoadDataResourceString(IDR_WEBUI_CSS_TEXT_DEFAULTS)); + resource_bundle.LoadDataResourceString(IDR_WEBUI_CSS_TEXT_DEFAULTS_CSS)); } std::string GetWebUiCssTextDefaultsMd() { const ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); - return GetWebUiCssTextDefaults( - resource_bundle.LoadDataResourceString(IDR_WEBUI_CSS_TEXT_DEFAULTS_MD)); + return GetWebUiCssTextDefaults(resource_bundle.LoadDataResourceString( + IDR_WEBUI_CSS_TEXT_DEFAULTS_MD_CSS)); } void AppendWebUiCssTextDefaults(std::string* html) { @@ -230,15 +221,13 @@ void AppendWebUiCssTextDefaults(std::string* html) { std::string GetFontFamily() { std::string font_family = l10n_util::GetStringUTF8(IDS_WEB_FONT_FAMILY); -// TODO(dnicoara) Remove Ozone check when PlatformFont support is introduced -// into Ozone: crbug.com/320050 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) - if (!features::IsUsingOzonePlatform()) { - font_family = ui::ResourceBundle::GetSharedInstance() - .GetFont(ui::ResourceBundle::BaseFont) - .GetFontName() + - ", " + font_family; - } + std::string font_name = ui::ResourceBundle::GetSharedInstance() + .GetFont(ui::ResourceBundle::BaseFont) + .GetFontName(); + // Wrap |font_name| with quotes to ensure it will always be parsed correctly + // in CSS. + font_family = "\"" + font_name + "\", " + font_family; #endif return font_family; diff --git a/chromium/ui/base/webui/web_ui_util.h b/chromium/ui/base/webui/web_ui_util.h index 1aa12627756..a0c1ca2fee6 100644 --- a/chromium/ui/base/webui/web_ui_util.h +++ b/chromium/ui/base/webui/web_ui_util.h @@ -62,11 +62,6 @@ void ParsePathAndImageSpec(const GURL& url, COMPONENT_EXPORT(UI_BASE) void ParsePathAndScale(const GURL& url, std::string* path, float* scale_factor); -// Parses a URL containing some path [{frame}]. If it does not contain a frame -// index then the default frame index is returned. -COMPONENT_EXPORT(UI_BASE) -void ParsePathAndFrame(const GURL& url, std::string* path, int* frame_index); - // Helper function to set some default values (e.g., font family, size, // language, and text direction) into the given dictionary. Requires an // application locale (i.e. g_browser_process->GetApplicationLocale()). diff --git a/chromium/ui/base/webui/web_ui_util_unittest.cc b/chromium/ui/base/webui/web_ui_util_unittest.cc index 362cc3e9535..a934bbe7cd9 100644 --- a/chromium/ui/base/webui/web_ui_util_unittest.cc +++ b/chromium/ui/base/webui/web_ui_util_unittest.cc @@ -53,70 +53,6 @@ TEST(WebUIUtilTest, ParsePathAndScale) { EXPECT_EQ(1.3f, factor); } -TEST(WebUIUtilTest, ParsePathAndFrame) { - std::string path; - - int index = -2; - GURL url("http://[::192.9.5.5]/and/some/more"); - webui::ParsePathAndFrame(url, &path, &index); - EXPECT_EQ("and/some/more", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url2("http://host/and/some/more"); - webui::ParsePathAndFrame(url2, &path, &index); - EXPECT_EQ("and/some/more", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url3("http://host/and/some/more[2a]"); - webui::ParsePathAndFrame(url3, &path, &index); - EXPECT_EQ("and/some/more[2a]", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url4("http://host/and/some/more[]"); - webui::ParsePathAndFrame(url4, &path, &index); - EXPECT_EQ("and/some/more[]", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url5("http://host/and/some/more[-2]"); - webui::ParsePathAndFrame(url5, &path, &index); - EXPECT_EQ("and/some/more[-2]", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url6("http://[::192.9.5.5]/and/some/more[0]"); - webui::ParsePathAndFrame(url6, &path, &index); - EXPECT_EQ("and/some/more", path); - EXPECT_EQ(0, index); - - index = -2; - GURL url7("http://host/and/some/more[1]"); - webui::ParsePathAndFrame(url7, &path, &index); - EXPECT_EQ("and/some/more", path); - EXPECT_EQ(1, index); - - index = -2; - GURL url8("http://host/and/some/more[3]"); - webui::ParsePathAndFrame(url8, &path, &index); - EXPECT_EQ("and/some/more", path); - EXPECT_EQ(3, index); - - index = -2; - GURL url9("http://host/and/some/more0]"); - webui::ParsePathAndFrame(url9, &path, &index); - EXPECT_EQ("and/some/more0]", path); - EXPECT_EQ(-1, index); - - index = -2; - GURL url10("http://host/and/some/more[0"); - webui::ParsePathAndFrame(url10, &path, &index); - EXPECT_EQ("and/some/more[0", path); - EXPECT_EQ(-1, index); -} - TEST(WebUIUtilTest, ParsePathAndImageSpec) { std::string path; diff --git a/chromium/ui/base/win/message_box_win.cc b/chromium/ui/base/win/message_box_win.cc index 27277a213ea..8665536bf4c 100644 --- a/chromium/ui/base/win/message_box_win.cc +++ b/chromium/ui/base/win/message_box_win.cc @@ -5,6 +5,9 @@ #include "ui/base/win/message_box_win.h" #include "base/i18n/rtl.h" +#include "base/strings/string16.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" namespace ui { @@ -12,20 +15,20 @@ namespace ui { // RTL locale, we need to make sure that LTR strings are rendered correctly by // adding the appropriate Unicode directionality marks. int MessageBox(HWND hwnd, - const base::string16& text, - const base::string16& caption, + const std::wstring& text, + const std::wstring& caption, UINT flags) { UINT actual_flags = flags; if (base::i18n::IsRTL()) actual_flags |= MB_RIGHT | MB_RTLREADING; - base::string16 localized_text = text; + base::string16 localized_text = base::WideToUTF16(text); base::i18n::AdjustStringForLocaleDirection(&localized_text); - const wchar_t* text_ptr = localized_text.c_str(); + const wchar_t* text_ptr = base::as_wcstr(localized_text); - base::string16 localized_caption = caption; + base::string16 localized_caption = base::WideToUTF16(caption); base::i18n::AdjustStringForLocaleDirection(&localized_caption); - const wchar_t* caption_ptr = localized_caption.c_str(); + const wchar_t* caption_ptr = base::as_wcstr(localized_caption); return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags); } diff --git a/chromium/ui/base/win/message_box_win.h b/chromium/ui/base/win/message_box_win.h index f19bb39e6fa..9b0ecdc21d4 100644 --- a/chromium/ui/base/win/message_box_win.h +++ b/chromium/ui/base/win/message_box_win.h @@ -7,8 +7,9 @@ #include <windows.h> +#include <string> + #include "base/component_export.h" -#include "base/strings/string16.h" namespace ui { @@ -18,8 +19,8 @@ namespace ui { // right-to-left locale. COMPONENT_EXPORT(UI_BASE) int MessageBox(HWND hwnd, - const base::string16& text, - const base::string16& caption, + const std::wstring& text, + const std::wstring& caption, UINT flags); } // namespace ui diff --git a/chromium/ui/base/win/power_setting_change_listener.cc b/chromium/ui/base/win/power_setting_change_listener.cc new file mode 100644 index 00000000000..d62e55b7bff --- /dev/null +++ b/chromium/ui/base/win/power_setting_change_listener.cc @@ -0,0 +1,110 @@ +// 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/win/power_setting_change_listener.h" + +#include "base/bind.h" +#include "base/callback_helpers.h" +#include "base/location.h" +#include "base/memory/singleton.h" +#include "base/observer_list.h" +#include "ui/gfx/win/singleton_hwnd.h" +#include "ui/gfx/win/singleton_hwnd_observer.h" + +namespace ui { + +class PowerSettingChangeObserver { + public: + static PowerSettingChangeObserver* GetInstance(); + + void AddListener(PowerSettingChangeListener* listener); + void RemoveListener(PowerSettingChangeListener* listener); + + private: + friend struct base::DefaultSingletonTraits<PowerSettingChangeObserver>; + + PowerSettingChangeObserver(); + virtual ~PowerSettingChangeObserver(); + + void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); + + void OnDisplayStateChanged(bool display_on); + + static HPOWERNOTIFY RegisterNotification(LPCGUID power_setting); + static BOOL UnregisterNotification(HPOWERNOTIFY handle); + + base::ObserverList<PowerSettingChangeListener>::Unchecked listeners_; + std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_; + HPOWERNOTIFY power_display_state_; +}; + +// static +PowerSettingChangeObserver* PowerSettingChangeObserver::GetInstance() { + return base::Singleton<PowerSettingChangeObserver>::get(); +} + +PowerSettingChangeObserver::PowerSettingChangeObserver() + : singleton_hwnd_observer_(new gfx::SingletonHwndObserver( + base::BindRepeating(&PowerSettingChangeObserver::OnWndProc, + base::Unretained(this)))), + power_display_state_(RegisterNotification(&GUID_SESSION_DISPLAY_STATUS)) { +} + +PowerSettingChangeObserver::~PowerSettingChangeObserver() { + UnregisterNotification(power_display_state_); +} + +void PowerSettingChangeObserver::AddListener( + PowerSettingChangeListener* listener) { + listeners_.AddObserver(listener); +} + +void PowerSettingChangeObserver::RemoveListener( + PowerSettingChangeListener* listener) { + listeners_.RemoveObserver(listener); +} + +void PowerSettingChangeObserver::OnWndProc(HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam) { + if (message == WM_POWERBROADCAST && wparam == PBT_POWERSETTINGCHANGE) { + POWERBROADCAST_SETTING* setting = (POWERBROADCAST_SETTING*)lparam; + if (setting && + IsEqualGUID(setting->PowerSetting, GUID_SESSION_DISPLAY_STATUS) && + setting->DataLength == sizeof(DWORD)) { + OnDisplayStateChanged( + PowerMonitorOff != + static_cast<MONITOR_DISPLAY_STATE>(setting->Data[0])); + } + } +} + +void PowerSettingChangeObserver::OnDisplayStateChanged(bool display_on) { + for (PowerSettingChangeListener& observer : listeners_) + observer.OnDisplayStateChanged(display_on); +} + +HPOWERNOTIFY PowerSettingChangeObserver::RegisterNotification( + LPCGUID power_setting) { + return RegisterPowerSettingNotification( + gfx::SingletonHwnd::GetInstance()->hwnd(), power_setting, + DEVICE_NOTIFY_WINDOW_HANDLE); +} + +BOOL PowerSettingChangeObserver::UnregisterNotification(HPOWERNOTIFY handle) { + return UnregisterPowerSettingNotification(handle); +} + +ScopedPowerSettingChangeListener::ScopedPowerSettingChangeListener( + PowerSettingChangeListener* listener) + : listener_(listener) { + PowerSettingChangeObserver::GetInstance()->AddListener(listener_); +} + +ScopedPowerSettingChangeListener::~ScopedPowerSettingChangeListener() { + PowerSettingChangeObserver::GetInstance()->RemoveListener(listener_); +} + +} // namespace ui diff --git a/chromium/ui/base/win/power_setting_change_listener.h b/chromium/ui/base/win/power_setting_change_listener.h new file mode 100644 index 00000000000..0a48115ecca --- /dev/null +++ b/chromium/ui/base/win/power_setting_change_listener.h @@ -0,0 +1,40 @@ +// 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_WIN_POWER_SETTING_CHANGE_LISTENER_H_ +#define UI_BASE_WIN_POWER_SETTING_CHANGE_LISTENER_H_ + +#include "base/component_export.h" + +namespace ui { + +// Interface for classes that want to listen to power setting changes. +class COMPONENT_EXPORT(UI_BASE) PowerSettingChangeListener { + public: + virtual void OnDisplayStateChanged(bool display_on) = 0; + + protected: + virtual ~PowerSettingChangeListener() = default; +}; + +// Create an instance of this class in any object that wants to listen +// for power setting changes. +class COMPONENT_EXPORT(UI_BASE) ScopedPowerSettingChangeListener { + public: + explicit ScopedPowerSettingChangeListener( + PowerSettingChangeListener* listener); + ~ScopedPowerSettingChangeListener(); + + private: + PowerSettingChangeListener* listener_; + + ScopedPowerSettingChangeListener(const ScopedPowerSettingChangeListener&) = + delete; + const ScopedPowerSettingChangeListener& operator=( + const ScopedPowerSettingChangeListener&) = delete; +}; + +} // namespace ui + +#endif // UI_BASE_WIN_POWER_SETTING_CHANGE_LISTENER_H_ diff --git a/chromium/ui/base/win/session_change_observer.cc b/chromium/ui/base/win/session_change_observer.cc index 44c20e2969b..a717568fb19 100644 --- a/chromium/ui/base/win/session_change_observer.cc +++ b/chromium/ui/base/win/session_change_observer.cc @@ -10,8 +10,8 @@ #include <utility> #include "base/bind.h" -#include "base/bind_helpers.h" #include "base/callback.h" +#include "base/callback_helpers.h" #include "base/location.h" #include "base/macros.h" #include "base/memory/singleton.h" diff --git a/chromium/ui/base/win/shell.cc b/chromium/ui/base/win/shell.cc index d1ce18112b5..aabdfee8ceb 100644 --- a/chromium/ui/base/win/shell.cc +++ b/chromium/ui/base/win/shell.cc @@ -39,10 +39,10 @@ namespace { const DWORD kDefaultShellExecuteFlags = SEE_MASK_NOASYNC; // Invokes ShellExecuteExW() with the given parameters. -bool InvokeShellExecute(const base::string16 path, - const base::string16 working_directory, - const base::string16 args, - const base::string16 verb, +bool InvokeShellExecute(const std::wstring& path, + const std::wstring& working_directory, + const std::wstring& args, + const std::wstring& verb, DWORD mask) { base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::BlockingType::WILL_BLOCK); @@ -67,7 +67,7 @@ bool InvokeShellExecute(const base::string16 path, bool OpenFileViaShell(const base::FilePath& full_path) { // Invoke the default verb on the file with no arguments. return InvokeShellExecute(full_path.value(), full_path.DirName().value(), - base::string16(), base::string16(), + std::wstring(), std::wstring(), kDefaultShellExecuteFlags); } @@ -75,7 +75,7 @@ bool OpenFolderViaShell(const base::FilePath& full_path) { // The "explore" verb causes the folder at |full_path| to be displayed in a // file browser. This will fail if |full_path| is not a directory. return InvokeShellExecute(full_path.value(), full_path.value(), - base::string16(), L"explore", + std::wstring(), L"explore", kDefaultShellExecuteFlags); } @@ -92,11 +92,11 @@ bool PreventWindowFromPinning(HWND hwnd) { // TODO(calamity): investigate moving this out of the UI thread as COM // operations may spawn nested run loops which can cause issues. -void SetAppDetailsForWindow(const base::string16& app_id, +void SetAppDetailsForWindow(const std::wstring& app_id, const base::FilePath& app_icon_path, int app_icon_index, - const base::string16& relaunch_command, - const base::string16& relaunch_display_name, + const std::wstring& relaunch_command, + const std::wstring& relaunch_display_name, HWND hwnd) { DCHECK(hwnd); @@ -127,23 +127,23 @@ void SetAppDetailsForWindow(const base::string16& app_id, } } -void SetAppIdForWindow(const base::string16& app_id, HWND hwnd) { - SetAppDetailsForWindow(app_id, base::FilePath(), 0, base::string16(), - base::string16(), hwnd); +void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { + SetAppDetailsForWindow(app_id, base::FilePath(), 0, std::wstring(), + std::wstring(), hwnd); } void SetAppIconForWindow(const base::FilePath& app_icon_path, int app_icon_index, HWND hwnd) { - SetAppDetailsForWindow(base::string16(), app_icon_path, app_icon_index, - base::string16(), base::string16(), hwnd); + SetAppDetailsForWindow(std::wstring(), app_icon_path, app_icon_index, + std::wstring(), std::wstring(), hwnd); } -void SetRelaunchDetailsForWindow(const base::string16& relaunch_command, - const base::string16& display_name, +void SetRelaunchDetailsForWindow(const std::wstring& relaunch_command, + const std::wstring& display_name, HWND hwnd) { - SetAppDetailsForWindow(base::string16(), base::FilePath(), 0, - relaunch_command, display_name, hwnd); + SetAppDetailsForWindow(std::wstring(), base::FilePath(), 0, relaunch_command, + display_name, hwnd); } void ClearWindowPropertyStore(HWND hwnd) { diff --git a/chromium/ui/base/x/BUILD.gn b/chromium/ui/base/x/BUILD.gn index 69fc364223c..b1aa641a4fe 100644 --- a/chromium/ui/base/x/BUILD.gn +++ b/chromium/ui/base/x/BUILD.gn @@ -3,8 +3,8 @@ # found in the LICENSE file. import("//build/config/linux/gtk/gtk.gni") +import("//build/config/ozone.gni") import("//build/config/ui.gni") -import("//ui/ozone/ozone.gni") assert(use_x11 || ozone_platform_x11) @@ -26,8 +26,8 @@ component("x") { "x11_display_manager.h", "x11_display_util.cc", "x11_display_util.h", - "x11_error_handler.cc", - "x11_error_handler.h", + "x11_idle_query.cc", + "x11_idle_query.h", "x11_menu_list.cc", "x11_menu_list.h", "x11_menu_registrar.cc", @@ -36,6 +36,8 @@ component("x") { "x11_move_loop_delegate.h", "x11_pointer_grab.cc", "x11_pointer_grab.h", + "x11_screensaver_window_finder.cc", + "x11_screensaver_window_finder.h", "x11_shm_image_pool.cc", "x11_shm_image_pool.h", "x11_software_bitmap_presenter.cc", @@ -44,6 +46,8 @@ component("x") { "x11_topmost_window_finder.h", "x11_ui_thread.cc", "x11_ui_thread.h", + "x11_user_input_monitor.cc", + "x11_user_input_monitor.h", "x11_util.cc", "x11_util.h", "x11_whole_screen_move_loop.cc", @@ -54,7 +58,7 @@ component("x") { "x11_workspace_handler.h", ] - if (is_desktop_linux || is_chromeos) { + if (is_linux || is_chromeos) { sources += [ "selection_owner.cc", "selection_owner.h", @@ -118,10 +122,15 @@ source_set("test_support") { sources = [ "test/x11_property_change_waiter.cc", "test/x11_property_change_waiter.h", + "test/x11_ui_controls_test_helper.cc", + "test/x11_ui_controls_test_helper.h", ] deps = [ + ":x", + "//ui/base:test_support", "//ui/events:platform_event", + "//ui/events:test_support", "//ui/events/platform/x11", "//ui/gfx/x", ] diff --git a/chromium/ui/base/x/selection_owner.cc b/chromium/ui/base/x/selection_owner.cc index 47bb2b6359b..6cbe80cc372 100644 --- a/chromium/ui/base/x/selection_owner.cc +++ b/chromium/ui/base/x/selection_owner.cc @@ -12,7 +12,6 @@ #include "ui/base/x/x11_util.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/x/x11_window_event_manager.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto_util.h" diff --git a/chromium/ui/base/x/selection_owner.h b/chromium/ui/base/x/selection_owner.h index 1dad4df144d..2d82e43ec31 100644 --- a/chromium/ui/base/x/selection_owner.h +++ b/chromium/ui/base/x/selection_owner.h @@ -17,7 +17,6 @@ #include "base/timer/timer.h" #include "ui/base/x/selection_utils.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11_types.h" namespace ui { diff --git a/chromium/ui/base/x/selection_requestor.cc b/chromium/ui/base/x/selection_requestor.cc index 7a83c814a75..6e01199f153 100644 --- a/chromium/ui/base/x/selection_requestor.cc +++ b/chromium/ui/base/x/selection_requestor.cc @@ -7,14 +7,12 @@ #include <algorithm> #include "base/memory/ref_counted_memory.h" -#include "base/run_loop.h" #include "ui/base/x/selection_owner.h" #include "ui/base/x/selection_utils.h" #include "ui/base/x/x11_util.h" #include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" namespace ui { @@ -28,7 +26,7 @@ const char kChromeSelection[] = "CHROME_SELECTION"; const int KSelectionRequestorTimerPeriodMs = 100; // The amount of time to wait for a request to complete before aborting it. -const int kRequestTimeoutMs = 10000; +const int kRequestTimeoutMs = 1000; static_assert(KSelectionRequestorTimerPeriodMs <= kRequestTimeoutMs, "timer period must be <= request timeout"); @@ -235,37 +233,30 @@ void SelectionRequestor::ConvertSelectionForCurrentRequest() { } void SelectionRequestor::BlockTillSelectionNotifyForRequest(Request* request) { - if (X11EventSource::HasInstance()) { - if (!abort_timer_.IsRunning()) { - abort_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(KSelectionRequestorTimerPeriodMs), - this, &SelectionRequestor::AbortStaleRequests); - } - - base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); - request->quit_closure = run_loop.QuitClosure(); - run_loop.Run(); - - // We cannot put logic to process the next request here because the RunLoop - // might be nested. For instance, request 'B' may start a RunLoop while the - // RunLoop for request 'A' is running. It is not possible to end the RunLoop - // for request 'A' without first ending the RunLoop for request 'B'. - } else { - // This occurs if PerformBlockingConvertSelection() is called during - // shutdown and the X11EventSource has already been destroyed. - auto* conn = x11::Connection::Get(); - auto& events = conn->events(); - while (!request->completed && request->timeout > base::TimeTicks::Now()) { - conn->Flush(); - conn->ReadResponses(); - if (!conn->events().empty()) { - x11::Event event = std::move(events.front()); - events.pop_front(); - dispatcher_->DispatchXEvent(&event); + auto* connection = x11::Connection::Get(); + auto& events = connection->events(); + size_t i = 0; + while (!request->completed && request->timeout > base::TimeTicks::Now()) { + connection->Flush(); + connection->ReadResponses(); + size_t events_size = events.size(); + for (; i < events_size; ++i) { + auto& event = events[i]; + if (auto* notify = event.As<x11::SelectionNotifyEvent>()) { + if (notify->requestor == x_window_) { + OnSelectionNotify(*notify); + event = x11::Event(); + } + } else if (auto* prop = event.As<x11::PropertyNotifyEvent>()) { + if (CanDispatchPropertyEvent(event)) { + OnPropertyEvent(event); + event = x11::Event(); + } } } + DCHECK_EQ(events_size, events.size()); } + AbortStaleRequests(); } SelectionRequestor::Request* SelectionRequestor::GetCurrentRequest() { diff --git a/chromium/ui/base/x/selection_requestor.h b/chromium/ui/base/x/selection_requestor.h index 9a32c88986e..e9a38ceb19c 100644 --- a/chromium/ui/base/x/selection_requestor.h +++ b/chromium/ui/base/x/selection_requestor.h @@ -17,8 +17,6 @@ #include "base/timer/timer.h" #include "ui/events/platform_event.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" namespace ui { class XEventDispatcher; diff --git a/chromium/ui/base/x/selection_requestor_unittest.cc b/chromium/ui/base/x/selection_requestor_unittest.cc index c67b8e62213..ba68529c289 100644 --- a/chromium/ui/base/x/selection_requestor_unittest.cc +++ b/chromium/ui/base/x/selection_requestor_unittest.cc @@ -19,9 +19,7 @@ #include "ui/events/platform/platform_event_source.h" #include "ui/gfx/x/connection.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" namespace ui { @@ -102,7 +100,8 @@ void PerformBlockingConvertSelection(SelectionRequestor* requestor, // Test that SelectionRequestor correctly handles receiving a request while it // is processing another request. -TEST_F(SelectionRequestorTest, NestedRequests) { +// TODO(https://crbug.com/443355): Reenable once clipboard interface is async. +TEST_F(SelectionRequestorTest, DISABLED_NestedRequests) { // Assume that |selection| will have no owner. If there is an owner, the owner // will set the property passed into the XConvertSelection() request which is // undesirable. diff --git a/chromium/ui/base/x/selection_utils.h b/chromium/ui/base/x/selection_utils.h index 3e90ed3f20b..2183832130b 100644 --- a/chromium/ui/base/x/selection_utils.h +++ b/chromium/ui/base/x/selection_utils.h @@ -10,7 +10,7 @@ #include "base/component_export.h" #include "base/memory/ref_counted_memory.h" -#include "ui/gfx/x/x11.h" +#include "ui/gfx/x/xproto.h" namespace ui { class SelectionData; diff --git a/chromium/ui/base/x/x11_cursor_factory.cc b/chromium/ui/base/x/x11_cursor_factory.cc index 4a97b8dc009..bfd662b201a 100644 --- a/chromium/ui/base/x/x11_cursor_factory.cc +++ b/chromium/ui/base/x/x11_cursor_factory.cc @@ -11,7 +11,6 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/x/connection.h" -#include "ui/gfx/x/x11.h" namespace ui { @@ -160,7 +159,8 @@ base::Optional<PlatformCursor> X11CursorFactory::GetDefaultCursor( return ToPlatformCursor(cursor.get()); } -PlatformCursor X11CursorFactory::CreateImageCursor(const SkBitmap& bitmap, +PlatformCursor X11CursorFactory::CreateImageCursor(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot) { // There is a problem with custom cursors that have no custom data. The // resulting SkBitmap is empty and X crashes when creating a zero size cursor @@ -181,6 +181,7 @@ PlatformCursor X11CursorFactory::CreateImageCursor(const SkBitmap& bitmap, } PlatformCursor X11CursorFactory::CreateAnimatedCursor( + mojom::CursorType type, const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) { diff --git a/chromium/ui/base/x/x11_cursor_factory.h b/chromium/ui/base/x/x11_cursor_factory.h index 464c75f2306..ab4d55b233a 100644 --- a/chromium/ui/base/x/x11_cursor_factory.h +++ b/chromium/ui/base/x/x11_cursor_factory.h @@ -34,9 +34,11 @@ class COMPONENT_EXPORT(UI_BASE_X) X11CursorFactory // CursorFactoryOzone: base::Optional<PlatformCursor> GetDefaultCursor( mojom::CursorType type) override; - PlatformCursor CreateImageCursor(const SkBitmap& bitmap, + PlatformCursor CreateImageCursor(mojom::CursorType type, + const SkBitmap& bitmap, const gfx::Point& hotspot) override; - PlatformCursor CreateAnimatedCursor(const std::vector<SkBitmap>& bitmaps, + PlatformCursor CreateAnimatedCursor(mojom::CursorType type, + const std::vector<SkBitmap>& bitmaps, const gfx::Point& hotspot, int frame_delay_ms) override; void RefImageCursor(PlatformCursor cursor) override; diff --git a/chromium/ui/base/x/x11_cursor_factory_unittest.cc b/chromium/ui/base/x/x11_cursor_factory_unittest.cc index 8c317fba402..bb6b0f8e51e 100644 --- a/chromium/ui/base/x/x11_cursor_factory_unittest.cc +++ b/chromium/ui/base/x/x11_cursor_factory_unittest.cc @@ -19,7 +19,7 @@ TEST(X11CursorFactoryTest, InvisibleRefcount) { // than a single reference since the factory should hold a reference and // CreateImageCursor should return an incremented refcount. auto* invisible_cursor = static_cast<X11Cursor*>( - factory.CreateImageCursor(SkBitmap(), gfx::Point())); + factory.CreateImageCursor({}, SkBitmap(), gfx::Point())); ASSERT_FALSE(invisible_cursor->HasOneRef()); // Release our refcount on the cursor diff --git a/chromium/ui/base/x/x11_desktop_window_move_client.cc b/chromium/ui/base/x/x11_desktop_window_move_client.cc index 9b810e0f39e..0c53079dc0f 100644 --- a/chromium/ui/base/x/x11_desktop_window_move_client.cc +++ b/chromium/ui/base/x/x11_desktop_window_move_client.cc @@ -7,7 +7,6 @@ #include "ui/base/x/x11_util.h" #include "ui/base/x/x11_window.h" #include "ui/events/event.h" -#include "ui/gfx/x/x11.h" namespace ui { diff --git a/chromium/ui/base/x/x11_desktop_window_move_client.h b/chromium/ui/base/x/x11_desktop_window_move_client.h index aaa32c3c16c..dc8462919a2 100644 --- a/chromium/ui/base/x/x11_desktop_window_move_client.h +++ b/chromium/ui/base/x/x11_desktop_window_move_client.h @@ -11,7 +11,6 @@ #include "ui/base/x/x11_move_loop_delegate.h" #include "ui/base/x/x11_whole_screen_move_loop.h" #include "ui/gfx/geometry/point.h" -#include "ui/gfx/x/x11.h" namespace ui { diff --git a/chromium/ui/base/x/x11_display_manager.cc b/chromium/ui/base/x/x11_display_manager.cc index ac1e99da7e2..170aeb8b914 100644 --- a/chromium/ui/base/x/x11_display_manager.cc +++ b/chromium/ui/base/x/x11_display_manager.cc @@ -10,7 +10,6 @@ #include "base/threading/thread_task_runner_handle.h" #include "ui/base/x/x11_display_util.h" #include "ui/gfx/x/randr.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/xproto.h" diff --git a/chromium/ui/base/x/x11_display_manager.h b/chromium/ui/base/x/x11_display_manager.h index ec6c676249e..069ec82c926 100644 --- a/chromium/ui/base/x/x11_display_manager.h +++ b/chromium/ui/base/x/x11_display_manager.h @@ -15,7 +15,6 @@ #include "ui/display/display_change_notifier.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11_types.h" namespace views { class DesktopScreenX11Test; diff --git a/chromium/ui/base/x/x11_display_util.cc b/chromium/ui/base/x/x11_display_util.cc index e8d433ad4b6..f5d93cffb3d 100644 --- a/chromium/ui/base/x/x11_display_util.cc +++ b/chromium/ui/base/x/x11_display_util.cc @@ -19,7 +19,6 @@ #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/vector3d_f.h" #include "ui/gfx/x/randr.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" namespace ui { @@ -138,11 +137,10 @@ int DefaultBitsPerComponent() { // Get the EDID data from the |output| and stores to |edid|. std::vector<uint8_t> GetEDIDProperty(x11::RandR* randr, x11::RandR::Output output) { - auto future = randr->GetOutputProperty({ + auto future = randr->GetOutputProperty(x11::RandR::GetOutputPropertyRequest{ .output = output, .property = gfx::GetAtom(kRandrEdidProperty), - .long_length = 128, - }); + .long_length = 128}); auto response = future.Sync(); std::vector<uint8_t> edid; if (response && response->format == 8 && response->type != x11::Atom::None) diff --git a/chromium/ui/base/x/x11_display_util.h b/chromium/ui/base/x/x11_display_util.h index 7a128004483..484d35ca662 100644 --- a/chromium/ui/base/x/x11_display_util.h +++ b/chromium/ui/base/x/x11_display_util.h @@ -8,8 +8,6 @@ #include "base/component_export.h" #include "base/time/time.h" #include "ui/display/display.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" namespace ui { diff --git a/chromium/ui/base/x/x11_drag_context.h b/chromium/ui/base/x/x11_drag_context.h index f01efc28210..5e9a2ca6a39 100644 --- a/chromium/ui/base/x/x11_drag_context.h +++ b/chromium/ui/base/x/x11_drag_context.h @@ -13,7 +13,6 @@ #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/xproto.h" namespace ui { diff --git a/chromium/ui/base/x/x11_drag_drop_client.h b/chromium/ui/base/x/x11_drag_drop_client.h index 274e90adc4d..e32e73185ce 100644 --- a/chromium/ui/base/x/x11_drag_drop_client.h +++ b/chromium/ui/base/x/x11_drag_drop_client.h @@ -14,7 +14,6 @@ #include "ui/base/x/x11_drag_context.h" #include "ui/base/x/x11_topmost_window_finder.h" #include "ui/gfx/geometry/point.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/xproto.h" namespace ui { diff --git a/chromium/ui/base/x/x11_error_handler.cc b/chromium/ui/base/x/x11_error_handler.cc deleted file mode 100644 index cab6e26be74..00000000000 --- a/chromium/ui/base/x/x11_error_handler.cc +++ /dev/null @@ -1,105 +0,0 @@ -// 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/x/x11_error_handler.h" - -#include "base/check.h" -#include "base/compiler_specific.h" -#include "base/lazy_instance.h" -#include "base/logging.h" -#include "base/sequenced_task_runner.h" -#include "base/task/current_thread.h" -#include "base/threading/sequenced_task_runner_handle.h" -#include "ui/base/x/x11_util.h" -#include "ui/gfx/x/xproto_util.h" - -namespace ui { - -namespace { - -// Indicates that we're currently responding to an IO error (by shutting down). -bool g_in_x11_io_error_handler = false; - -base::LazyInstance<base::OnceClosure>::Leaky g_shutdown_cb = - LAZY_INSTANCE_INITIALIZER; - -// Number of seconds to wait for UI thread to get an IO error if we get it on -// the background thread. -const int kWaitForUIThreadSeconds = 10; - -int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { - if (!g_in_x11_io_error_handler) { - base::SequencedTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(&x11::LogErrorEventDescription, error->serial, - error->error_code, error->request_code, - error->minor_code)); - } - return 0; -} - -// This function is used to help us diagnose crash dumps that happen -// during the shutdown process. -NOINLINE void WaitingForUIThreadToHandleIOError() { - // Ensure function isn't optimized away. - asm(""); - sleep(kWaitForUIThreadSeconds); -} - -int BrowserX11IOErrorHandler(Display* d) { - if (!base::CurrentUIThread::IsSet()) { - // Wait for the UI thread (which has a different connection to the X server) - // to get the error. We can't call shutdown from this thread without - // tripping an error. Doing it through a function so that we'll be able - // to see it in any crash dumps. - WaitingForUIThreadToHandleIOError(); - return 0; - } - - // If there's an IO error it likely means the X server has gone away. - // If this CHECK fails, then that means SessionEnding() below triggered some - // code that tried to talk to the X server, resulting in yet another error. - CHECK(!g_in_x11_io_error_handler); - - g_in_x11_io_error_handler = true; - LOG(ERROR) << "X IO error received (X server probably went away)"; - DCHECK(!g_shutdown_cb.Get().is_null()); - std::move(g_shutdown_cb.Get()).Run(); - - return 0; -} - -int X11EmptyErrorHandler(Display* d, XErrorEvent* error) { - return 0; -} - -int X11EmptyIOErrorHandler(Display* d) { - return 0; -} - -} // namespace - -void SetNullErrorHandlers() { - // Installs the X11 error handlers for the browser process used during - // startup. They simply print error messages and exit because - // we can't shutdown properly while creating and initializing services. - ui::SetX11ErrorHandlers(nullptr, nullptr); -} - -void SetErrorHandlers(base::OnceCallback<void()> shutdown_cb) { - // Installs the X11 error handlers for the browser process after the - // main message loop has started. This will allow us to exit cleanly - // if X exits before we do. - DCHECK(g_shutdown_cb.Get().is_null()); - g_shutdown_cb.Get() = std::move(shutdown_cb); - ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); -} - -void SetEmptyErrorHandlers() { - // Unset the X11 error handlers. The X11 error handlers log the errors using a - // |PostTask()| on the message-loop. But since the message-loop is in the - // process of terminating, this can cause errors. - ui::SetX11ErrorHandlers(X11EmptyErrorHandler, X11EmptyIOErrorHandler); -} - -} // namespace ui diff --git a/chromium/ui/base/x/x11_error_handler.h b/chromium/ui/base/x/x11_error_handler.h deleted file mode 100644 index 49011beb3d8..00000000000 --- a/chromium/ui/base/x/x11_error_handler.h +++ /dev/null @@ -1,26 +0,0 @@ -// 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_X_X11_ERROR_HANDLER_H_ -#define UI_BASE_X_X11_ERROR_HANDLER_H_ - -#include "base/callback.h" -#include "base/component_export.h" - -namespace ui { - -// Sets null error handlers that just catch error messages. -COMPONENT_EXPORT(UI_BASE_X) void SetNullErrorHandlers(); - -// Sets error handlers that catch the error messages on ui thread, waits until -// errors are received on io thread, and stops the browser. -COMPONENT_EXPORT(UI_BASE_X) -void SetErrorHandlers(base::OnceCallback<void()> shutdown_cb); - -// Unsets the error handlers. -COMPONENT_EXPORT(UI_BASE_X) void SetEmptyErrorHandlers(); - -} // namespace ui - -#endif // UI_BASE_X_X11_ERROR_HANDLER_H_ diff --git a/chromium/ui/base/x/x11_gl_egl_utility.cc b/chromium/ui/base/x/x11_gl_egl_utility.cc index 0e5fcf9fff6..b921f6291c7 100644 --- a/chromium/ui/base/x/x11_gl_egl_utility.cc +++ b/chromium/ui/base/x/x11_gl_egl_utility.cc @@ -5,7 +5,6 @@ #include "ui/base/x/x11_gl_egl_utility.h" #include "ui/base/x/x11_util.h" -#include "ui/gfx/x/x11.h" #include "ui/gl/gl_surface_egl.h" #ifndef EGL_ANGLE_x11_visual diff --git a/chromium/ui/base/idle/idle_query_x11.cc b/chromium/ui/base/x/x11_idle_query.cc index 569c57a2d71..c880e49080f 100644 --- a/chromium/ui/base/idle/idle_query_x11.cc +++ b/chromium/ui/base/x/x11_idle_query.cc @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/base/idle/idle_query_x11.h" +#include "ui/base/x/x11_idle_query.h" #include "ui/gfx/x/connection.h" #include "ui/gfx/x/screensaver.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" namespace ui { diff --git a/chromium/ui/base/idle/idle_query_x11.h b/chromium/ui/base/x/x11_idle_query.h index 457aada6a1e..ffdc12cb9ac 100644 --- a/chromium/ui/base/idle/idle_query_x11.h +++ b/chromium/ui/base/x/x11_idle_query.h @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_BASE_IDLE_IDLE_QUERY_X11_H_ -#define UI_BASE_IDLE_IDLE_QUERY_X11_H_ - -#include <memory> +#ifndef UI_BASE_X_X11_IDLE_QUERY_H_ +#define UI_BASE_X_X11_IDLE_QUERY_H_ +#include "base/component_export.h" #include "base/macros.h" namespace x11 { @@ -15,7 +14,7 @@ class Connection; namespace ui { -class IdleQueryX11 { +class COMPONENT_EXPORT(UI_BASE_X) IdleQueryX11 { public: IdleQueryX11(); ~IdleQueryX11(); @@ -30,4 +29,4 @@ class IdleQueryX11 { } // namespace ui -#endif // UI_BASE_IDLE_IDLE_QUERY_X11_H_ +#endif // UI_BASE_X_X11_IDLE_QUERY_H_ diff --git a/chromium/ui/base/x/x11_menu_list.h b/chromium/ui/base/x/x11_menu_list.h index 8f45b83e50d..f0327944e87 100644 --- a/chromium/ui/base/x/x11_menu_list.h +++ b/chromium/ui/base/x/x11_menu_list.h @@ -9,7 +9,7 @@ #include "base/component_export.h" #include "base/macros.h" -#include "ui/gfx/x/x11_types.h" +#include "ui/gfx/x/xproto.h" // A process wide singleton cache for X menus. namespace base { diff --git a/chromium/ui/base/x/x11_menu_registrar.cc b/chromium/ui/base/x/x11_menu_registrar.cc index 8b4da2347eb..847829c4664 100644 --- a/chromium/ui/base/x/x11_menu_registrar.cc +++ b/chromium/ui/base/x/x11_menu_registrar.cc @@ -10,9 +10,9 @@ #include "ui/base/x/x11_menu_list.h" #include "ui/base/x/x11_util.h" #include "ui/events/x/x11_window_event_manager.h" -#include "ui/gfx/x/x11.h" +#include "ui/gfx/x/connection.h" +#include "ui/gfx/x/scoped_ignore_errors.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/xproto.h" namespace { @@ -66,7 +66,7 @@ void X11MenuRegistrar::OnWindowCreatedOrDestroyed(bool created, if (created) { // The window might be destroyed if the message pump did not get a chance to // run but we can safely ignore the X error. - gfx::X11ErrorTracker error_tracker; + x11::ScopedIgnoreErrors ignore_errors(x11::Connection::Get()); XMenuList::GetInstance()->MaybeRegisterMenu(window); } else { XMenuList::GetInstance()->MaybeUnregisterMenu(window); diff --git a/chromium/ui/base/x/x11_menu_registrar.h b/chromium/ui/base/x/x11_menu_registrar.h index 65b19e7c844..2e6584fb696 100644 --- a/chromium/ui/base/x/x11_menu_registrar.h +++ b/chromium/ui/base/x/x11_menu_registrar.h @@ -13,8 +13,6 @@ #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" namespace ui { diff --git a/chromium/ui/base/x/x11_move_loop.h b/chromium/ui/base/x/x11_move_loop.h index 9a00455409c..4a358af2d10 100644 --- a/chromium/ui/base/x/x11_move_loop.h +++ b/chromium/ui/base/x/x11_move_loop.h @@ -6,8 +6,6 @@ #define UI_BASE_X_X11_MOVE_LOOP_H_ #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" namespace ui { diff --git a/chromium/ui/base/x/x11_os_exchange_data_provider.cc b/chromium/ui/base/x/x11_os_exchange_data_provider.cc index ef6463f78c6..d76cbc9d28c 100644 --- a/chromium/ui/base/x/x11_os_exchange_data_provider.cc +++ b/chromium/ui/base/x/x11_os_exchange_data_provider.cc @@ -13,6 +13,7 @@ #include "net/base/filename_util.h" #include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/x/selection_utils.h" #include "ui/base/x/x11_util.h" @@ -367,7 +368,6 @@ bool XOSExchangeDataProvider::HasCustomFormat( return !requested_types.empty(); } -#if defined(USE_X11) void XOSExchangeDataProvider::SetFileContents( const base::FilePath& filename, const std::string& file_contents) { @@ -398,7 +398,6 @@ void XOSExchangeDataProvider::SetFileContents( scoped_refptr<base::RefCountedMemory>( base::RefCountedString::TakeString(&file_contents_copy))); } -#endif void XOSExchangeDataProvider::SetHtml(const base::string16& html, const GURL& base_url) { @@ -477,4 +476,11 @@ void XOSExchangeDataProvider::InsertData( format_map_.Insert(format, data); } +void XOSExchangeDataProvider::SetSource( + std::unique_ptr<DataTransferEndpoint> data_source) {} + +DataTransferEndpoint* XOSExchangeDataProvider::GetSource() const { + return nullptr; +} + } // namespace ui diff --git a/chromium/ui/base/x/x11_os_exchange_data_provider.h b/chromium/ui/base/x/x11_os_exchange_data_provider.h index 24c0f42dbac..fbc79e53b91 100644 --- a/chromium/ui/base/x/x11_os_exchange_data_provider.h +++ b/chromium/ui/base/x/x11_os_exchange_data_provider.h @@ -18,7 +18,6 @@ #include "ui/base/x/selection_utils.h" #include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/image/image_skia.h" -#include "ui/gfx/x/x11.h" #include "url/gurl.h" namespace ui { @@ -82,10 +81,8 @@ class COMPONENT_EXPORT(UI_BASE_X) XOSExchangeDataProvider bool HasURL(FilenameToURLPolicy policy) const override; bool HasFile() const override; bool HasCustomFormat(const ClipboardFormatType& format) const override; -#if defined(USE_X11) void SetFileContents(const base::FilePath& filename, const std::string& file_contents) override; -#endif void SetHtml(const base::string16& html, const GURL& base_url) override; bool GetHtml(base::string16* html, GURL* base_url) const override; @@ -95,6 +92,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XOSExchangeDataProvider gfx::ImageSkia GetDragImage() const override; gfx::Vector2d GetDragImageOffset() const override; + void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override; + DataTransferEndpoint* GetSource() const override; + protected: friend class OSExchangeDataProviderX11Test; using PickleData = std::map<ClipboardFormatType, base::Pickle>; diff --git a/chromium/ui/base/x/x11_pointer_grab.cc b/chromium/ui/base/x/x11_pointer_grab.cc index e422d880c41..9e003369a0d 100644 --- a/chromium/ui/base/x/x11_pointer_grab.cc +++ b/chromium/ui/base/x/x11_pointer_grab.cc @@ -12,7 +12,6 @@ #include "ui/base/x/x11_util.h" #include "ui/events/devices/x11/device_data_manager_x11.h" #include "ui/gfx/x/connection.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/xinput.h" #include "ui/gfx/x/xproto.h" diff --git a/chromium/ui/base/x/x11_pointer_grab.h b/chromium/ui/base/x/x11_pointer_grab.h index 534a9402247..265b28f9457 100644 --- a/chromium/ui/base/x/x11_pointer_grab.h +++ b/chromium/ui/base/x/x11_pointer_grab.h @@ -6,7 +6,6 @@ #define UI_BASE_X_X11_POINTER_GRAB_H_ #include "base/component_export.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" namespace ui { diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.cc b/chromium/ui/base/x/x11_screensaver_window_finder.cc index 1813d9ab560..41c0da28282 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.cc +++ b/chromium/ui/base/x/x11_screensaver_window_finder.cc @@ -2,21 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/base/idle/screensaver_window_finder_x11.h" +#include "ui/base/x/x11_screensaver_window_finder.h" #include "base/command_line.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/switches.h" #include "ui/gfx/x/connection.h" +#include "ui/gfx/x/scoped_ignore_errors.h" #include "ui/gfx/x/screensaver.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_error_tracker.h" namespace ui { ScreensaverWindowFinder::ScreensaverWindowFinder() : exists_(false) {} +// static bool ScreensaverWindowFinder::ScreensaverWindowExists() { // Avoid calling into potentially missing X11 APIs in headless mode. if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) @@ -50,10 +50,10 @@ bool ScreensaverWindowFinder::ScreensaverWindowExists() { } // Also check the top level windows to see if any of them are screensavers. - gfx::X11ErrorTracker err_tracker; + x11::ScopedIgnoreErrors ignore_errors(connection); ScreensaverWindowFinder finder; ui::EnumerateTopLevelWindows(&finder); - return finder.exists_ && !err_tracker.FoundNewError(); + return finder.exists_; } bool ScreensaverWindowFinder::ShouldStopIterating(x11::Window window) { diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.h b/chromium/ui/base/x/x11_screensaver_window_finder.h index a502daa6fbe..147099a629c 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.h +++ b/chromium/ui/base/x/x11_screensaver_window_finder.h @@ -2,16 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ -#define UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ +#ifndef UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_ +#define UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_ -#include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/x/x11_util.h" namespace ui { -class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { +class COMPONENT_EXPORT(UI_BASE_X) ScreensaverWindowFinder + : public ui::EnumerateWindowsDelegate { public: static bool ScreensaverWindowExists(); @@ -30,4 +31,4 @@ class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { } // namespace ui -#endif // UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ +#endif // UI_BASE_X_X11_SCREENSAVER_WINDOW_FINDER_H_ diff --git a/chromium/ui/base/x/x11_shm_image_pool.cc b/chromium/ui/base/x/x11_shm_image_pool.cc index 91dd0122693..3adadda03cd 100644 --- a/chromium/ui/base/x/x11_shm_image_pool.cc +++ b/chromium/ui/base/x/x11_shm_image_pool.cc @@ -70,16 +70,9 @@ bool ShouldUseMitShm(x11::Connection* connection) { // codepath. It may be possible in contrived cases for there to be a // false-positive, but in that case we'll just fallback to the non-SHM // codepath. - const std::string& display_string = connection->DisplayString(); - char* host = nullptr; - int display_id = 0; - int screen = 0; - if (xcb_parse_display(display_string.c_str(), &host, &display_id, &screen)) { - std::string name = host; - free(host); - if (IsRemoteHost(name)) - return false; - } + auto host = connection->GetConnectionHostname(); + if (!host.empty() && IsRemoteHost(host)) + return false; std::unique_ptr<base::Environment> env = base::Environment::Create(); diff --git a/chromium/ui/base/x/x11_shm_image_pool.h b/chromium/ui/base/x/x11_shm_image_pool.h index dfd480550ed..a0e44920307 100644 --- a/chromium/ui/base/x/x11_shm_image_pool.h +++ b/chromium/ui/base/x/x11_shm_image_pool.h @@ -21,7 +21,6 @@ #include "ui/gfx/geometry/size.h" #include "ui/gfx/x/event.h" #include "ui/gfx/x/shm.h" -#include "ui/gfx/x/x11.h" namespace ui { diff --git a/chromium/ui/base/x/x11_software_bitmap_presenter.cc b/chromium/ui/base/x/x11_software_bitmap_presenter.cc index 0894413c511..2c0a8bf8095 100644 --- a/chromium/ui/base/x/x11_software_bitmap_presenter.cc +++ b/chromium/ui/base/x/x11_software_bitmap_presenter.cc @@ -16,6 +16,7 @@ #include "base/logging.h" #include "base/macros.h" #include "base/memory/ref_counted_memory.h" +#include "skia/ext/legacy_display_globals.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkImageInfo.h" #include "third_party/skia/include/core/SkSurface.h" @@ -23,9 +24,6 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/x/connection.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_error_tracker.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto_types.h" @@ -78,11 +76,11 @@ bool X11SoftwareBitmapPresenter::CompositeBitmap(x11::Connection* connection, connection->CreatePixmap({depth, pixmap_id, widget, width, height}); ScopedPixmap pixmap(connection, pixmap_id); - connection->ChangeGC( - {.gc = gc, .subwindow_mode = x11::SubwindowMode::IncludeInferiors}); + connection->ChangeGC(x11::ChangeGCRequest{ + .gc = gc, .subwindow_mode = x11::SubwindowMode::IncludeInferiors}); connection->CopyArea({widget, pixmap_id, gc, x, y, 0, 0, width, height}); - connection->ChangeGC( - {.gc = gc, .subwindow_mode = x11::SubwindowMode::ClipByChildren}); + connection->ChangeGC(x11::ChangeGCRequest{ + .gc = gc, .subwindow_mode = x11::SubwindowMode::ClipByChildren}); auto req = connection->GetImage({x11::ImageFormat::ZPixmap, pixmap_id, 0, 0, width, height, kAllPlanes}); @@ -174,7 +172,8 @@ void X11SoftwareBitmapPresenter::Resize(const gfx::Size& pixel_size) { SkImageInfo info = SkImageInfo::Make(viewport_pixel_size_.width(), viewport_pixel_size_.height(), color_type, kOpaque_SkAlphaType); - surface_ = SkSurface::MakeRaster(info); + SkSurfaceProps props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(); + surface_ = SkSurface::MakeRaster(info, &props); } } diff --git a/chromium/ui/base/x/x11_software_bitmap_presenter.h b/chromium/ui/base/x/x11_software_bitmap_presenter.h index d4859e43749..d862609d2b3 100644 --- a/chromium/ui/base/x/x11_software_bitmap_presenter.h +++ b/chromium/ui/base/x/x11_software_bitmap_presenter.h @@ -15,8 +15,6 @@ #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto.h" class SkCanvas; diff --git a/chromium/ui/base/x/x11_topmost_window_finder.h b/chromium/ui/base/x/x11_topmost_window_finder.h index 8099ce8bbcb..f2b75cf195c 100644 --- a/chromium/ui/base/x/x11_topmost_window_finder.h +++ b/chromium/ui/base/x/x11_topmost_window_finder.h @@ -8,7 +8,6 @@ #include "base/component_export.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/geometry/point.h" -#include "ui/gfx/x/x11.h" namespace ui { diff --git a/chromium/ui/base/x/x11_user_input_monitor.cc b/chromium/ui/base/x/x11_user_input_monitor.cc new file mode 100644 index 00000000000..4b9ae0158a4 --- /dev/null +++ b/chromium/ui/base/x/x11_user_input_monitor.cc @@ -0,0 +1,131 @@ +// 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/x/x11_user_input_monitor.h" + +#include "base/logging.h" +#include "ui/events/devices/x11/xinput_util.h" +#include "ui/events/keycodes/keyboard_code_conversion_x.h" + +namespace ui { + +XUserInputMonitor::XUserInputMonitor( + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) + : io_task_runner_(io_task_runner) {} + +XUserInputMonitor::~XUserInputMonitor() { + DCHECK(!connection_); +} + +void XUserInputMonitor::WillDestroyCurrentMessageLoop() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + StopMonitor(); +} + +bool XUserInputMonitor::ShouldContinueStream() const { + return true; +} + +void XUserInputMonitor::DispatchXEvent(x11::Event* event) { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + DCHECK(write_key_press_callback_); + + auto* raw = event->As<x11::Input::RawDeviceEvent>(); + if (!raw || (raw->opcode != x11::Input::RawDeviceEvent::RawKeyPress && + raw->opcode != x11::Input::RawDeviceEvent::RawKeyRelease)) { + return; + } + + EventType type = raw->opcode == x11::Input::RawDeviceEvent::RawKeyPress + ? ET_KEY_PRESSED + : ET_KEY_RELEASED; + + auto key_sym = + connection_->KeycodeToKeysym(static_cast<x11::KeyCode>(raw->detail), 0); + KeyboardCode key_code = KeyboardCodeFromXKeysym(key_sym); + counter_.OnKeyboardEvent(type, key_code); + + // Update count value in shared memory. + if (key_press_count_mapping_) { + write_key_press_callback_.Run(*key_press_count_mapping_, + GetKeyPressCount()); + } +} + +uint32_t XUserInputMonitor::GetKeyPressCount() const { + return counter_.GetKeyPressCount(); +} + +void XUserInputMonitor::StartMonitor(WriteKeyPressCallback& callback) { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + write_key_press_callback_ = callback; + + if (!connection_) { + // TODO(jamiewalch): We should pass the connection in. + if (auto* connection = x11::Connection::Get()) { + connection_ = x11::Connection::Get()->Clone(); + } else { + LOG(ERROR) << "Couldn't open X connection"; + StopMonitor(); + return; + } + } + + if (!connection_->xinput().present()) { + LOG(ERROR) << "X Input extension not available."; + StopMonitor(); + return; + } + // Let the server know the client XInput version. + connection_->xinput().XIQueryVersion( + {x11::Input::major_version, x11::Input::minor_version}); + + x11::Input::XIEventMask mask; + SetXinputMask(&mask, x11::Input::RawDeviceEvent::RawKeyPress); + SetXinputMask(&mask, x11::Input::RawDeviceEvent::RawKeyRelease); + connection_->xinput().XISelectEvents( + {connection_->default_root(), + {{x11::Input::DeviceId::AllMaster, {mask}}}}); + connection_->Flush(); + + // Register OnConnectionData() to be called every time there is something to + // read from |connection_|. + watch_controller_ = base::FileDescriptorWatcher::WatchReadable( + connection_->GetFd(), + base::BindRepeating(&XUserInputMonitor::OnConnectionData, + base::Unretained(this))); + + // Start observing message loop destruction if we start monitoring the first + // event. + base::CurrentThread::Get()->AddDestructionObserver(this); + + // Fetch pending events if any. + OnConnectionData(); +} + +void XUserInputMonitor::StartMonitorWithMapping( + WriteKeyPressCallback& callback, + base::WritableSharedMemoryMapping mapping) { + StartMonitor(callback); + key_press_count_mapping_ = + std::make_unique<base::WritableSharedMemoryMapping>(std::move(mapping)); +} + +void XUserInputMonitor::StopMonitor() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + + watch_controller_.reset(); + connection_.reset(); + key_press_count_mapping_.reset(); + + // Stop observing message loop destruction if no event is being monitored. + base::CurrentThread::Get()->RemoveDestructionObserver(this); +} + +void XUserInputMonitor::OnConnectionData() { + DCHECK(io_task_runner_->BelongsToCurrentThread()); + connection_->Dispatch(this); +} + +} // namespace ui diff --git a/chromium/ui/base/x/x11_user_input_monitor.h b/chromium/ui/base/x/x11_user_input_monitor.h new file mode 100644 index 00000000000..708817c9321 --- /dev/null +++ b/chromium/ui/base/x/x11_user_input_monitor.h @@ -0,0 +1,68 @@ +// 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_X_X11_USER_INPUT_MONITOR_H_ +#define UI_BASE_X_X11_USER_INPUT_MONITOR_H_ + +#include <memory> + +#include "base/component_export.h" +#include "base/files/file_descriptor_watcher_posix.h" +#include "base/memory/shared_memory_mapping.h" +#include "base/single_thread_task_runner.h" +#include "base/task/current_thread.h" +#include "ui/events/keyboard_event_counter.h" +#include "ui/gfx/x/connection.h" +#include "ui/gfx/x/xinput.h" + +namespace ui { + +// This is the actual implementation of event monitoring. It's separated from +// UserInputMonitorLinux since it needs to be deleted on the IO thread. +class COMPONENT_EXPORT(UI_BASE_X) XUserInputMonitor + : public base::SupportsWeakPtr<XUserInputMonitor>, + public base::CurrentThread::DestructionObserver, + public x11::Connection::Delegate { + public: + using WriteKeyPressCallback = base::RepeatingCallback< + void(const base::WritableSharedMemoryMapping& shmem, uint32_t count)>; + + explicit XUserInputMonitor( + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); + XUserInputMonitor(const XUserInputMonitor&) = delete; + XUserInputMonitor& operator=(const XUserInputMonitor&) = delete; + ~XUserInputMonitor() override; + + uint32_t GetKeyPressCount() const; + void StartMonitor(WriteKeyPressCallback& callback); + void StartMonitorWithMapping(WriteKeyPressCallback& callback, + base::WritableSharedMemoryMapping mapping); + void StopMonitor(); + + private: + // base::CurrentThread::DestructionObserver: + void WillDestroyCurrentMessageLoop() override; + + // x11::Connection::Delegate: + bool ShouldContinueStream() const override; + void DispatchXEvent(x11::Event* event) override; + + void OnConnectionData(); + + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; + + // Used for sharing key press count value. + std::unique_ptr<base::WritableSharedMemoryMapping> key_press_count_mapping_; + + // The following members should only be accessed on the IO thread. + std::unique_ptr<base::FileDescriptorWatcher::Controller> watch_controller_; + std::unique_ptr<x11::Connection> connection_; + KeyboardEventCounter counter_; + + WriteKeyPressCallback write_key_press_callback_; +}; + +} // namespace ui + +#endif // UI_BASE_X_X11_USER_INPUT_MONITOR_H_ diff --git a/chromium/ui/base/x/x11_util.cc b/chromium/ui/base/x/x11_util.cc index c604bcd0f9b..e9e4671a80c 100644 --- a/chromium/ui/base/x/x11_util.cc +++ b/chromium/ui/base/x/x11_util.cc @@ -22,6 +22,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/compiler_specific.h" +#include "base/environment.h" #include "base/location.h" #include "base/logging.h" #include "base/memory/ref_counted_memory.h" @@ -67,9 +68,7 @@ #include "ui/gfx/x/screensaver.h" #include "ui/gfx/x/shm.h" #include "ui/gfx/x/sync.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto_util.h" @@ -93,33 +92,6 @@ namespace { constexpr int kNetWMStateAdd = 1; constexpr int kNetWMStateRemove = 0; -int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) { - // This callback can be invoked by drivers very late in thread destruction, - // when Chrome TLS is no longer usable. https://crbug.com/849225. - if (TLSDestructionCheckerForX11::HasBeenDestroyed()) - return 0; - - if (base::CurrentThread::Get()) { - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, - base::BindOnce(&x11::LogErrorEventDescription, e->serial, e->error_code, - e->request_code, e->minor_code)); - } else { - LOG(ERROR) << "X error received: " - << "serial " << e->serial << ", " - << "error_code " << static_cast<int>(e->error_code) << ", " - << "request_code " << static_cast<int>(e->request_code) << ", " - << "minor_code " << static_cast<int>(e->minor_code); - } - return 0; -} - -int DefaultX11IOErrorHandler(XDisplay* d) { - // If there's an IO error it likely means the X server has gone away - LOG(ERROR) << "X IO error received (X server probably went away)"; - _exit(1); -} - bool SupportsEWMH() { static bool supports_ewmh = false; static bool supports_ewmh_cached = false; @@ -142,13 +114,11 @@ bool SupportsEWMH() { // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale // property referencing an ID that's been recycled for another window), so // we check that too. - gfx::X11ErrorTracker err_tracker; x11::Window wm_window_property = x11::Window::None; - bool result = + supports_ewmh = GetProperty(wm_window, gfx::GetAtom("_NET_SUPPORTING_WM_CHECK"), - &wm_window_property); - supports_ewmh = !err_tracker.FoundNewError() && result && - wm_window_property == wm_window; + &wm_window_property) && + wm_window_property == wm_window; } return supports_ewmh; @@ -165,9 +135,7 @@ bool GetWindowManagerName(std::string* wm_name) { return false; } - gfx::X11ErrorTracker err_tracker; - bool result = GetStringProperty(wm_window, "_NET_WM_NAME", wm_name); - return !err_tracker.FoundNewError() && result; + return GetStringProperty(wm_window, "_NET_WM_NAME", wm_name); } // Returns whether the X11 Screen Saver Extension can be used to disable the @@ -188,6 +156,15 @@ bool IsX11ScreenSaverAvailable() { version->server_minor_version >= 1)); } +// Must be in sync with the copy in //content/browser/gpu/gpu_internals_ui.cc. +base::Value NewDescriptionValuePair(base::StringPiece desc, + base::StringPiece value) { + base::Value dict(base::Value::Type::DICTIONARY); + dict.SetKey("description", base::Value(desc)); + dict.SetKey("value", base::Value(value)); + return dict; +} + } // namespace void DeleteProperty(x11::Window window, x11::Atom name) { @@ -243,13 +220,13 @@ void WithdrawWindow(x11::Window window) { } void RaiseWindow(x11::Window window) { - x11::Connection::Get()->ConfigureWindow( - {.window = window, .stack_mode = x11::StackMode::Above}); + x11::Connection::Get()->ConfigureWindow(x11::ConfigureWindowRequest{ + .window = window, .stack_mode = x11::StackMode::Above}); } void LowerWindow(x11::Window window) { - x11::Connection::Get()->ConfigureWindow( - {.window = window, .stack_mode = x11::StackMode::Below}); + x11::Connection::Get()->ConfigureWindow(x11::ConfigureWindowRequest{ + .window = window, .stack_mode = x11::StackMode::Below}); } void DefineCursor(x11::Window window, x11::Cursor cursor) { @@ -258,14 +235,15 @@ void DefineCursor(x11::Window window, x11::Cursor cursor) { // timing on BookmarkBarViewTest8.DNDBackToOriginatingMenu on // linux-chromeos-rel, causing it to flake. x11::Connection::Get() - ->ChangeWindowAttributes({.window = window, .cursor = cursor}) + ->ChangeWindowAttributes(x11::ChangeWindowAttributesRequest{ + .window = window, .cursor = cursor}) .Sync(); } x11::Window CreateDummyWindow(const std::string& name) { auto* connection = x11::Connection::Get(); auto window = connection->GenerateId<x11::Window>(); - connection->CreateWindow({ + connection->CreateWindow(x11::CreateWindowRequest{ .wid = window, .parent = connection->default_root(), .x = -100, @@ -348,16 +326,14 @@ int CoalescePendingMotionEvents(const x11::Event* x11_event, conn->ReadResponses(); if (motion) { - for (auto it = conn->events().begin(); it != conn->events().end();) { - const auto& next_event = *it; + for (auto& next_event : conn->events()) { // Discard all but the most recent motion event that targets the same // window with unchanged state. const auto* next_motion = next_event.As<x11::MotionNotifyEvent>(); if (next_motion && next_motion->event == motion->event && next_motion->child == motion->child && next_motion->state == motion->state) { - *last_event = std::move(*it); - it = conn->events().erase(it); + *last_event = std::move(next_event); } else { break; } @@ -367,8 +343,8 @@ int CoalescePendingMotionEvents(const x11::Event* x11_event, device->opcode == x11::Input::DeviceEvent::TouchUpdate); auto* ddmx11 = ui::DeviceDataManagerX11::GetInstance(); - for (auto it = conn->events().begin(); it != conn->events().end();) { - auto* next_device = it->As<x11::Input::DeviceEvent>(); + for (auto& event : conn->events()) { + auto* next_device = event.As<x11::Input::DeviceEvent>(); if (!next_device) break; @@ -379,13 +355,13 @@ int CoalescePendingMotionEvents(const x11::Event* x11_event, // always be at least one pending. if (!ui::TouchFactory::GetInstance()->ShouldProcessDeviceEvent( *next_device)) { - it = conn->events().erase(it); + event = x11::Event(); continue; } if (next_device->opcode == device->opcode && - !ddmx11->IsCMTGestureEvent(*it) && - ddmx11->GetScrollClassEventDetail(*it) == SCROLL_TYPE_NO_SCROLL) { + !ddmx11->IsCMTGestureEvent(event) && + ddmx11->GetScrollClassEventDetail(event) == SCROLL_TYPE_NO_SCROLL) { // Confirm that the motion event is targeted at the same window // and that no buttons or modifiers have changed. if (device->event == next_device->event && @@ -396,12 +372,12 @@ int CoalescePendingMotionEvents(const x11::Event* x11_event, device->mods.latched == next_device->mods.latched && device->mods.locked == next_device->mods.locked && device->mods.effective == next_device->mods.effective) { - *last_event = std::move(*it); - it = conn->events().erase(it); + *last_event = std::move(event); num_coalesced++; continue; } } + break; } } @@ -487,6 +463,8 @@ bool GetInnerWindowBounds(x11::Window window, gfx::Rect* rect) { auto translate_coords = connection->TranslateCoordinates({x11_window, root}); // Sync after making both requests so only one round-trip is made. + // Flush so all requests are sent before waiting on any replies. + connection->Flush(); auto geometry = get_geometry.Sync(); auto coords = translate_coords.Sync(); @@ -583,7 +561,7 @@ bool WindowContainsPoint(x11::Window window, gfx::Point screen_loc) { bool PropertyExists(x11::Window window, const std::string& property_name) { auto response = x11::Connection::Get() - ->GetProperty({ + ->GetProperty(x11::GetPropertyRequest{ .window = static_cast<x11::Window>(window), .property = gfx::GetAtom(property_name), .long_length = 1, @@ -596,7 +574,7 @@ bool GetRawBytesOfProperty(x11::Window window, x11::Atom property, scoped_refptr<base::RefCountedMemory>* out_data, x11::Atom* out_type) { - auto future = x11::Connection::Get()->GetProperty({ + auto future = x11::Connection::Get()->GetProperty(x11::GetPropertyRequest{ .window = static_cast<x11::Window>(window), .property = property, // Don't limit the amount of returned data. @@ -794,12 +772,6 @@ bool GetWindowDesktop(x11::Window window, int* desktop) { return GetIntProperty(window, "_NET_WM_DESKTOP", desktop); } -std::string GetX11ErrorString(XDisplay* display, int err) { - char buffer[256]; - XGetErrorText(display, err, buffer, base::size(buffer)); - return buffer; -} - // Returns true if |window| is a named window. bool IsWindowNamed(x11::Window window) { return PropertyExists(window, "WM_NAME"); @@ -1011,10 +983,6 @@ bool IsCompositingManagerPresent() { return is_compositing_manager_present; } -void SetDefaultX11ErrorHandlers() { - SetX11ErrorHandlers(nullptr, nullptr); -} - bool IsX11WindowFullScreen(x11::Window window) { // If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or // absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine @@ -1048,6 +1016,31 @@ void SuspendX11ScreenSaver(bool suspend) { x11::Connection::Get()->screensaver().Suspend({suspend}); } +base::Value GpuExtraInfoAsListValue(unsigned long system_visual, + unsigned long rgba_visual) { + base::Value result(base::Value::Type::LIST); + result.Append( + NewDescriptionValuePair("Window manager", ui::GuessWindowManagerName())); + { + std::unique_ptr<base::Environment> env(base::Environment::Create()); + std::string value; + const char kXDGCurrentDesktop[] = "XDG_CURRENT_DESKTOP"; + if (env->GetVar(kXDGCurrentDesktop, &value)) + result.Append(NewDescriptionValuePair(kXDGCurrentDesktop, value)); + const char kGDMSession[] = "GDMSESSION"; + if (env->GetVar(kGDMSession, &value)) + result.Append(NewDescriptionValuePair(kGDMSession, value)); + result.Append(NewDescriptionValuePair( + "Compositing manager", + ui::IsCompositingManagerPresent() ? "Yes" : "No")); + } + result.Append(NewDescriptionValuePair("System visual ID", + base::NumberToString(system_visual))); + result.Append(NewDescriptionValuePair("RGBA visual ID", + base::NumberToString(rgba_visual))); + return result; +} + bool WmSupportsHint(x11::Atom atom) { if (!SupportsEWMH()) return false; @@ -1148,13 +1141,6 @@ x11::Future<void> SendClientMessage(x11::Window window, return SendEvent(event, target, event_mask); } -void SetX11ErrorHandlers(XErrorHandler error_handler, - XIOErrorHandler io_error_handler) { - XSetErrorHandler(error_handler ? error_handler : DefaultX11ErrorHandler); - XSetIOErrorHandler(io_error_handler ? io_error_handler - : DefaultX11IOErrorHandler); -} - bool IsVulkanSurfaceSupported() { static const char* extensions[] = { "DRI3", // open source driver. @@ -1169,6 +1155,22 @@ bool IsVulkanSurfaceSupported() { return false; } +bool DoesVisualHaveAlphaForTest() { + // testing/xvfb.py runs xvfb and xcompmgr. + std::unique_ptr<base::Environment> env(base::Environment::Create()); + + uint8_t depth = 0; + bool visual_has_alpha = false; + ui::XVisualManager::GetInstance()->ChooseVisualForWindow( + env->HasVar("_CHROMIUM_INSIDE_XVFB"), nullptr, &depth, nullptr, + &visual_has_alpha); + + if (visual_has_alpha) + DCHECK_EQ(32, depth); + + return visual_has_alpha; +} + // static XVisualManager* XVisualManager::GetInstance() { return base::Singleton<XVisualManager>::get(); diff --git a/chromium/ui/base/x/x11_util.h b/chromium/ui/base/x/x11_util.h index 5c84aa3691d..ca024c442a6 100644 --- a/chromium/ui/base/x/x11_util.h +++ b/chromium/ui/base/x/x11_util.h @@ -24,15 +24,15 @@ #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_refptr.h" #include "base/synchronization/lock.h" +#include "base/values.h" #include "build/build_config.h" #include "ui/base/x/x11_cursor.h" #include "ui/events/event_constants.h" #include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/platform_event.h" #include "ui/gfx/icc_profile.h" +#include "ui/gfx/x/connection.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xproto_types.h" typedef unsigned long Cursor; @@ -113,15 +113,15 @@ struct WmHints { // See below int32_t initial_state; // Pixmap to be used as icon - xcb_pixmap_t icon_pixmap; + x11::Pixmap icon_pixmap; // Window to be used as icon - xcb_window_t icon_window; + x11::Window icon_window; // Initial position of icon int32_t icon_x, icon_y; // Icon mask bitmap - xcb_pixmap_t icon_mask; + x11::Pixmap icon_mask; // Identifier of related window group - xcb_window_t window_group; + x11::Window window_group; }; // These functions use the default display and this /must/ be called from @@ -143,11 +143,11 @@ bool GetArrayProperty(x11::Window window, using lentype = decltype(x11::GetPropertyRequest::long_length); auto response = x11::Connection::Get() - ->GetProperty( - {.window = static_cast<x11::Window>(window), - .property = name, - .long_length = - amount ? length : std::numeric_limits<lentype>::max()}) + ->GetProperty(x11::GetPropertyRequest{ + .window = static_cast<x11::Window>(window), + .property = name, + .long_length = + amount ? length : std::numeric_limits<lentype>::max()}) .Sync(); if (!response || response->format != CHAR_BIT * sizeof(T)) return false; @@ -178,13 +178,13 @@ void SetArrayProperty(x11::Window window, static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4, ""); std::vector<uint8_t> data(sizeof(T) * values.size()); memcpy(data.data(), values.data(), sizeof(T) * values.size()); - x11::Connection::Get()->ChangeProperty( - {.window = static_cast<x11::Window>(window), - .property = name, - .type = type, - .format = CHAR_BIT * sizeof(T), - .data_len = values.size(), - .data = base::RefCountedBytes::TakeVector(&data)}); + x11::Connection::Get()->ChangeProperty(x11::ChangePropertyRequest{ + .window = static_cast<x11::Window>(window), + .property = name, + .type = type, + .format = CHAR_BIT * sizeof(T), + .data_len = values.size(), + .data = base::RefCountedBytes::TakeVector(&data)}); } template <typename T> @@ -406,10 +406,6 @@ static const int kAllDesktops = -1; COMPONENT_EXPORT(UI_BASE_X) bool GetWindowDesktop(x11::Window window, int* desktop); -// Translates an X11 error code into a printable string. -COMPONENT_EXPORT(UI_BASE_X) -std::string GetX11ErrorString(XDisplay* display, int err); - // Implementers of this interface receive a notification for every X window of // the main display. class EnumerateWindowsDelegate { @@ -515,17 +511,18 @@ COMPONENT_EXPORT(UI_BASE_X) bool IsWmTiling(WindowManagerName window_manager); // Returns true if a compositing manager is present. COMPONENT_EXPORT(UI_BASE_X) bool IsCompositingManagerPresent(); -// Enable the default X error handlers. These will log the error and abort -// the process if called. Use SetX11ErrorHandlers() to set your own error -// handlers. -COMPONENT_EXPORT(UI_BASE_X) void SetDefaultX11ErrorHandlers(); - // Returns true if a given window is in full-screen mode. COMPONENT_EXPORT(UI_BASE_X) bool IsX11WindowFullScreen(x11::Window window); // Suspends or resumes the X screen saver. Must be called on the UI thread. COMPONENT_EXPORT(UI_BASE_X) void SuspendX11ScreenSaver(bool suspend); +// Returns human readable description of the window manager, desktop, and +// other system properties related to the compositing. +COMPONENT_EXPORT(UI_BASE_X) +base::Value GpuExtraInfoAsListValue(unsigned long system_visual, + unsigned long rgba_visual); + // Returns true if the window manager supports the given hint. COMPONENT_EXPORT(UI_BASE_X) bool WmSupportsHint(x11::Atom atom); @@ -550,17 +547,13 @@ x11::Future<void> SendClientMessage( x11::EventMask event_mask = x11::EventMask::SubstructureNotify | x11::EventMask::SubstructureRedirect); -// -------------------------------------------------------------------------- -// X11 error handling. -// Sets the X Error Handlers. Passing NULL for either will enable the default -// error handler, which if called will log the error and abort the process. -COMPONENT_EXPORT(UI_BASE_X) -void SetX11ErrorHandlers(XErrorHandler error_handler, - XIOErrorHandler io_error_handler); - // Return true if VulkanSurface is supported. COMPONENT_EXPORT(UI_BASE_X) bool IsVulkanSurfaceSupported(); +// Returns whether the visual supports alpha. +// The function examines the _CHROMIUM_INSIDE_XVFB environment variable. +COMPONENT_EXPORT(UI_BASE_X) bool DoesVisualHaveAlphaForTest(); + // -------------------------------------------------------------------------- // Selects a visual with a preference for alpha support on compositing window // managers. diff --git a/chromium/ui/base/x/x11_whole_screen_move_loop.cc b/chromium/ui/base/x/x11_whole_screen_move_loop.cc index e26532b8403..09a0c5a7f58 100644 --- a/chromium/ui/base/x/x11_whole_screen_move_loop.cc +++ b/chromium/ui/base/x/x11_whole_screen_move_loop.cc @@ -27,15 +27,13 @@ #include "ui/events/x/events_x_utils.h" #include "ui/events/x/x11_window_event_manager.h" #include "ui/gfx/x/connection.h" -#include "ui/gfx/x/x11.h" +#include "ui/gfx/x/keysyms/keysyms.h" #include "ui/gfx/x/xproto.h" namespace ui { namespace { -constexpr x11::KeySym kEscKeysym = static_cast<x11::KeySym>(0xff1b); - // XGrabKey requires the modifier mask to explicitly be specified. constexpr x11::ModMask kModifiersMasks[] = { {}, // No additional modifier. @@ -48,6 +46,23 @@ constexpr x11::ModMask kModifiersMasks[] = { x11::ModMask::c_2 | x11::ModMask::Lock | x11::ModMask::c_5, }; +const char* GrabStatusToString(x11::GrabStatus grab_status) { + switch (grab_status) { + case x11::GrabStatus::Success: + return "Success"; + case x11::GrabStatus::AlreadyGrabbed: + return "AlreadyGrabbed"; + case x11::GrabStatus::InvalidTime: + return "InvalidTime"; + case x11::GrabStatus::NotViewable: + return "NotViewable"; + case x11::GrabStatus::Frozen: + return "Frozen"; + } + NOTREACHED(); + return ""; +} + } // namespace X11WholeScreenMoveLoop::X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate) @@ -207,7 +222,7 @@ void X11WholeScreenMoveLoop::EndMoveLoop() { UpdateCursor(initial_cursor_); auto* connection = x11::Connection::Get(); - auto esc_keycode = connection->KeysymToKeycode(kEscKeysym); + auto esc_keycode = connection->KeysymToKeycode(XK_Escape); for (auto mask : kModifiersMasks) connection->UngrabKey({esc_keycode, grab_input_window_, mask}); @@ -230,8 +245,7 @@ bool X11WholeScreenMoveLoop::GrabPointer(scoped_refptr<X11Cursor> cursor) { auto ret = ui::GrabPointer(grab_input_window_, false, cursor); if (ret != x11::GrabStatus::Success) { DLOG(ERROR) << "Grabbing pointer for dragging failed: " - << ui::GetX11ErrorString(connection->display(), - static_cast<int>(ret)); + << GrabStatusToString(ret); } connection->Flush(); return ret == x11::GrabStatus::Success; @@ -239,7 +253,7 @@ bool X11WholeScreenMoveLoop::GrabPointer(scoped_refptr<X11Cursor> cursor) { void X11WholeScreenMoveLoop::GrabEscKey() { auto* connection = x11::Connection::Get(); - auto esc_keycode = connection->KeysymToKeycode(kEscKeysym); + auto esc_keycode = connection->KeysymToKeycode(XK_Escape); for (auto mask : kModifiersMasks) { connection->GrabKey({false, grab_input_window_, mask, esc_keycode, x11::GrabMode::Async, x11::GrabMode::Async}); @@ -249,7 +263,7 @@ void X11WholeScreenMoveLoop::GrabEscKey() { void X11WholeScreenMoveLoop::CreateDragInputWindow( x11::Connection* connection) { grab_input_window_ = connection->GenerateId<x11::Window>(); - connection->CreateWindow({ + connection->CreateWindow(x11::CreateWindowRequest{ .wid = grab_input_window_, .parent = connection->default_root(), .x = -100, diff --git a/chromium/ui/base/x/x11_whole_screen_move_loop.h b/chromium/ui/base/x/x11_whole_screen_move_loop.h index 7717b3d3913..e56d82910ab 100644 --- a/chromium/ui/base/x/x11_whole_screen_move_loop.h +++ b/chromium/ui/base/x/x11_whole_screen_move_loop.h @@ -20,7 +20,7 @@ #include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/x/x11_types.h" +#include "ui/gfx/x/connection.h" namespace ui { class MouseEvent; diff --git a/chromium/ui/base/x/x11_window.cc b/chromium/ui/base/x/x11_window.cc index 7d151df864f..988ffa93bf2 100644 --- a/chromium/ui/base/x/x11_window.cc +++ b/chromium/ui/base/x/x11_window.cc @@ -35,7 +35,6 @@ #include "ui/gfx/skia_util.h" #include "ui/gfx/x/connection.h" #include "ui/gfx/x/x11_atom_cache.h" -#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/x11_path.h" #include "ui/gfx/x/xfixes.h" #include "ui/gfx/x/xinput.h" @@ -719,7 +718,7 @@ void XWindow::StackXWindowAbove(x11::Window window) { if (it_below_window != window_below_parents.rend() && it_above_window != window_above_parents.rend()) { - connection_->ConfigureWindow({ + connection_->ConfigureWindow(x11::ConfigureWindowRequest{ .window = *it_above_window, .sibling = *it_below_window, .stack_mode = x11::StackMode::Above, @@ -838,7 +837,7 @@ bool XWindow::IsXWindowVisibleOnAllWorkspaces() const { } void XWindow::MoveCursorTo(const gfx::Point& location_in_pixels) { - connection_->WarpPointer({ + connection_->WarpPointer(x11::WarpPointerRequest{ .dst_window = x_root_window_, .dst_x = bounds_in_pixels_.x() + location_in_pixels.x(), .dst_y = bounds_in_pixels_.y() + location_in_pixels.y(), @@ -1425,7 +1424,7 @@ void XWindow::SetOverrideRedirect(bool override_redirect) { bool remap = window_mapped_in_client_; if (remap) Hide(); - connection_->ChangeWindowAttributes({ + connection_->ChangeWindowAttributes(x11::ChangeWindowAttributesRequest{ .window = xwindow_, .override_redirect = x11::Bool32(override_redirect), }); @@ -1488,7 +1487,7 @@ void XWindow::UnconfineCursor() { void XWindow::UpdateWindowRegion( std::unique_ptr<std::vector<x11::Rectangle>> region) { auto set_shape = [&](const std::vector<x11::Rectangle>& rectangles) { - connection_->shape().Rectangles({ + connection_->shape().Rectangles(x11::Shape::RectanglesRequest{ .operation = x11::Shape::So::Set, .destination_kind = x11::Shape::Sk::Bounding, .ordering = x11::ClipOrdering::YXBanded, @@ -1516,7 +1515,7 @@ void XWindow::UpdateWindowRegion( // If the window has system borders, the mask must be set to null (not a // rectangle), because several window managers (eg, KDE, XFCE, XMonad) will // not put borders on a window with a custom shape. - connection_->shape().Mask({ + connection_->shape().Mask(x11::Shape::MaskRequest{ .operation = x11::Shape::So::Set, .destination_kind = x11::Shape::Sk::Bounding, .destination_window = xwindow_, diff --git a/chromium/ui/base/x/x11_window.h b/chromium/ui/base/x/x11_window.h index af282d4190d..4078ea5dc7b 100644 --- a/chromium/ui/base/x/x11_window.h +++ b/chromium/ui/base/x/x11_window.h @@ -23,8 +23,6 @@ #include "ui/gfx/geometry/size_f.h" #include "ui/gfx/x/event.h" #include "ui/gfx/x/sync.h" -#include "ui/gfx/x/x11.h" -#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/xfixes.h" #include "ui/gfx/x/xproto.h" diff --git a/chromium/ui/base/x/x11_workspace_handler.cc b/chromium/ui/base/x/x11_workspace_handler.cc index 65a7b1705cd..84ae4701b14 100644 --- a/chromium/ui/base/x/x11_workspace_handler.cc +++ b/chromium/ui/base/x/x11_workspace_handler.cc @@ -17,7 +17,7 @@ namespace { x11::Future<x11::GetPropertyReply> GetWorkspace() { auto* connection = x11::Connection::Get(); - return connection->GetProperty({ + return connection->GetProperty(x11::GetPropertyRequest{ .window = connection->default_screen().root, .property = static_cast<x11::Atom>(gfx::GetAtom("_NET_CURRENT_DESKTOP")), .type = static_cast<x11::Atom>(gfx::GetAtom("CARDINAL")), diff --git a/chromium/ui/base/x/x11_workspace_handler.h b/chromium/ui/base/x/x11_workspace_handler.h index 1a253ab62f1..cf6f1b45603 100644 --- a/chromium/ui/base/x/x11_workspace_handler.h +++ b/chromium/ui/base/x/x11_workspace_handler.h @@ -11,7 +11,6 @@ #include "base/memory/weak_ptr.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/gfx/x/event.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/xproto.h" namespace ui { diff --git a/chromium/ui/base/x/xwmstartupcheck/BUILD.gn b/chromium/ui/base/x/xwmstartupcheck/BUILD.gn index 50f34ca6460..0f3c1b4e23f 100644 --- a/chromium/ui/base/x/xwmstartupcheck/BUILD.gn +++ b/chromium/ui/base/x/xwmstartupcheck/BUILD.gn @@ -11,6 +11,4 @@ executable("xwmstartupcheck") { "//base", "//ui/gfx/x", ] - - configs += [ "//build/config/linux:x11" ] } diff --git a/chromium/ui/base/x/xwmstartupcheck/xwmstartupcheck.cc b/chromium/ui/base/x/xwmstartupcheck/xwmstartupcheck.cc index c5a03fd54c6..9954e562e97 100644 --- a/chromium/ui/base/x/xwmstartupcheck/xwmstartupcheck.cc +++ b/chromium/ui/base/x/xwmstartupcheck/xwmstartupcheck.cc @@ -14,7 +14,6 @@ #include "base/command_line.h" #include "ui/gfx/x/connection.h" -#include "ui/gfx/x/x11.h" #include "ui/gfx/x/xproto.h" void CalculateTimeout(const timespec& now, |