Commit 7caeddea authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/wayland: Fix crashes when primary selection is not available

Segfaults were observed when running under Wayland compositors that do
not advertise primary selection protocol extension objects. For now,
Ozone/Wayland supports only gtk_primary_selection version 1, which is
likely not available in some compositors, such as, weston, sway, etc.
This fixes the crashes by properly handling cases where the gtk primary
selection protocol objects are not in place.

R=msisov@igalia.com

Bug: 1064410
Change-Id: Ia90b423208e64919f717442309a4c92cdb6749a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2118237Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#753161}
parent 42c60091
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/ozone/platform/wayland/host/wayland_clipboard.h" #include "ui/ozone/platform/wayland/host/wayland_clipboard.h"
#include <string>
#include "ui/ozone/platform/wayland/host/gtk_primary_selection_device.h" #include "ui/ozone/platform/wayland/host/gtk_primary_selection_device.h"
#include "ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.h" #include "ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.h"
#include "ui/ozone/platform/wayland/host/gtk_primary_selection_source.h" #include "ui/ozone/platform/wayland/host/gtk_primary_selection_source.h"
...@@ -38,7 +40,7 @@ void WaylandClipboard::OfferClipboardData( ...@@ -38,7 +40,7 @@ void WaylandClipboard::OfferClipboardData(
clipboard_data_source_ = data_device_manager_->CreateSource(); clipboard_data_source_ = data_device_manager_->CreateSource();
data_source = clipboard_data_source_.get(); data_source = clipboard_data_source_.get();
} else { } else {
if (!primary_selection_device_manager_) { if (!IsPrimarySelectionSupported()) {
std::move(callback).Run(); std::move(callback).Run();
return; return;
} }
...@@ -66,8 +68,10 @@ void WaylandClipboard::RequestClipboardData( ...@@ -66,8 +68,10 @@ void WaylandClipboard::RequestClipboardData(
if (!data_device_->RequestSelectionData(mime_type)) if (!data_device_->RequestSelectionData(mime_type))
SetData({}, mime_type); SetData({}, mime_type);
} else { } else {
if (!primary_selection_device_->RequestSelectionData(mime_type)) if (!IsPrimarySelectionSupported() ||
!primary_selection_device_->RequestSelectionData(mime_type)) {
SetData({}, mime_type); SetData({}, mime_type);
}
} }
} }
...@@ -91,8 +95,10 @@ void WaylandClipboard::GetAvailableMimeTypes( ...@@ -91,8 +95,10 @@ void WaylandClipboard::GetAvailableMimeTypes(
if (buffer == ClipboardBuffer::kCopyPaste) { if (buffer == ClipboardBuffer::kCopyPaste) {
std::move(callback).Run(data_device_->GetAvailableMimeTypes()); std::move(callback).Run(data_device_->GetAvailableMimeTypes());
} else { } else {
DCHECK(primary_selection_device_); std::move(callback).Run(
std::move(callback).Run(primary_selection_device_->GetAvailableMimeTypes()); IsPrimarySelectionSupported()
? primary_selection_device_->GetAvailableMimeTypes()
: std::vector<std::string>{});
} }
} }
...@@ -128,4 +134,8 @@ void WaylandClipboard::UpdateSequenceNumber(ClipboardBuffer buffer) { ...@@ -128,4 +134,8 @@ void WaylandClipboard::UpdateSequenceNumber(ClipboardBuffer buffer) {
update_sequence_cb_.Run(buffer); update_sequence_cb_.Run(buffer);
} }
bool WaylandClipboard::IsPrimarySelectionSupported() const {
return primary_selection_device_manager_ && primary_selection_device_;
}
} // namespace ui } // namespace ui
...@@ -57,6 +57,8 @@ class WaylandClipboard : public PlatformClipboard { ...@@ -57,6 +57,8 @@ class WaylandClipboard : public PlatformClipboard {
void UpdateSequenceNumber(ClipboardBuffer buffer); void UpdateSequenceNumber(ClipboardBuffer buffer);
private: private:
bool IsPrimarySelectionSupported() const;
// Holds a temporary instance of the client's clipboard content // Holds a temporary instance of the client's clipboard content
// so that we can asynchronously write to it. // so that we can asynchronously write to it.
PlatformClipboard::DataMap* data_map_ = nullptr; PlatformClipboard::DataMap* data_map_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment