forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-02-17 557c24d082b6ecb9bfe5407b77ae43fa7650a5dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
Upstream-Status: Backport
 
Fixes "interface 'wl_output' has no event 4" error.
 
Signed-off-by: Markus Volk f_l_k@t-online.de
 
author    Alexander Dunaev <adunaev@igalia.com>    Tue Dec 14 09:54:52 2021
committer    Chromium LUCI CQ <chromium-scoped@luci-project-accounts.iam.gserviceaccount.com>    Tue Dec 14 09:54:52 2021
tree    20c9ca1d8d2caf14be6eccf113550b929e2530e5
parent    d5684ab99411bd973c4c5fcb400070c4094dd57d [diff]
 
[linux/wayland] Fixed terminate caused by binding to wrong version.
 
The Ozone/Wayland implementation had a few places where the Wayland
objects were bound without proper checking for their versions.  That was
part of the technical debt not addressed before, and ended up causing
the issue explained in the linked crbug: the compositor terminates the
client that binds to the protocol that it does not actually support.
 
This patch fixes the issue by adding the necessary checks in all places
where they were missing.  Also a convenience macro for validating the
version is proposed.
 
Bug: 1279574
Change-Id: I74efa97f64b480bed47372d8d559593ae84eeb18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3337037
Reviewed-by: Maksim Sisov <msisov@igalia.com>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/main@{#951428}
 
diff --git a/ui/ozone/platform/wayland/common/wayland_object.cc b/ui/ozone/platform/wayland/common/wayland_object.cc
index e2b62ca..9a7c613 100644
--- a/ui/ozone/platform/wayland/common/wayland_object.cc
+++ b/ui/ozone/platform/wayland/common/wayland_object.cc
 
@@ -35,6 +35,8 @@
 #include <xdg-shell-client-protocol.h>
 #include <xdg-shell-unstable-v6-client-protocol.h>
 
+#include "base/logging.h"
+
 namespace wl {
 namespace {
 
@@ -77,6 +79,25 @@
 
 }  // namespace
 
+bool CanBind(const std::string& interface,
+             uint32_t available_version,
+             uint32_t min_version,
+             uint32_t max_version) {
+  if (available_version < min_version) {
+    LOG(WARNING) << "Unable to bind to " << interface << " version "
+                 << available_version << ".  The minimum supported version is "
+                 << min_version << ".";
+    return false;
+  }
+
+  if (available_version > max_version) {
+    LOG(WARNING) << "Binding to " << interface << " version " << max_version
+                 << " but version " << available_version << " is available.";
+  }
+
+  return true;
+}
+
 void (*ObjectTraits<wl_cursor_theme>::deleter)(wl_cursor_theme*) =
     &wl_cursor_theme_destroy;
 
 
diff --git a/ui/ozone/platform/wayland/common/wayland_object.h b/ui/ozone/platform/wayland/common/wayland_object.h
index 2ebfa51d..da91ffb 100644
--- a/ui/ozone/platform/wayland/common/wayland_object.h
+++ b/ui/ozone/platform/wayland/common/wayland_object.h
 
@@ -79,6 +79,17 @@
   static void (*deleter)(void*);
 };
 
+// Checks the given |available_version| exposed by the server against
+// |min_version| and |max_version| supported by the client.
+// Returns false (with rendering a warning) if |available_version| is less than
+// the minimum supported version.
+// Returns true otherwise, renders an info message if |available_version| is
+// greater than the maximum supported one.
+bool CanBind(const std::string& interface,
+             uint32_t available_version,
+             uint32_t min_version,
+             uint32_t max_version);
+
 }  // namespace wl
 
 // Puts the forward declaration for struct TYPE and declares the template
 
diff --git a/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc b/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
index af3087d..2991233 100644
--- a/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
+++ b/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
 
@@ -16,7 +16,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxGtkPrimarySelectionDeviceManagerVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 // static
@@ -31,12 +31,13 @@
     uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->gtk_primary_selection_device_manager())
+  if (connection->gtk_primary_selection_device_manager() ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
-  auto manager = wl::Bind<gtk_primary_selection_device_manager>(
-      registry, name,
-      std::min(version, kMaxGtkPrimarySelectionDeviceManagerVersion));
+  auto manager = wl::Bind<gtk_primary_selection_device_manager>(registry, name,
+                                                                kMinVersion);
   if (!manager) {
     LOG(ERROR) << "Failed to bind gtk_primary_selection_device_manager";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/gtk_shell1.cc b/ui/ozone/platform/wayland/host/gtk_shell1.cc
index cb3b0c8..26dfd7fb 100644
--- a/ui/ozone/platform/wayland/host/gtk_shell1.cc
+++ b/ui/ozone/platform/wayland/host/gtk_shell1.cc
 
@@ -17,8 +17,8 @@
 // gtk_shell1 exposes request_focus() since version 3.  Below that, it is not
 // interesting for us, although it provides some shell integration that might be
 // useful.
-constexpr uint32_t kMinGtkShell1Version = 3;
-constexpr uint32_t kMaxGtkShell1Version = 4;
+constexpr uint32_t kMinVersion = 3;
+constexpr uint32_t kMaxVersion = 4;
 }  // namespace
 
 // static
@@ -32,11 +32,13 @@
                             uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->gtk_shell1_ || version < kMinGtkShell1Version)
+  if (connection->gtk_shell1_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) {
     return;
+  }
 
-  auto gtk_shell1 = wl::Bind<::gtk_shell1>(
-      registry, name, std::min(version, kMaxGtkShell1Version));
+  auto gtk_shell1 =
+      wl::Bind<::gtk_shell1>(registry, name, std::min(version, kMaxVersion));
   if (!gtk_shell1) {
     LOG(ERROR) << "Failed to bind gtk_shell1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_data_device_manager.cc b/ui/ozone/platform/wayland/host/wayland_data_device_manager.cc
index 408cb1c7..0f03942 100644
--- a/ui/ozone/platform/wayland/host/wayland_data_device_manager.cc
+++ b/ui/ozone/platform/wayland/host/wayland_data_device_manager.cc
 
@@ -14,7 +14,8 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxDeviceManagerVersion = 3;
+constexpr uint32_t kMinVersion = 1;
+constexpr uint32_t kMaxVersion = 3;
 }
 
 // static
@@ -28,11 +29,13 @@
                                            uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->data_device_manager_)
+  if (connection->data_device_manager_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) {
     return;
+  }
 
   auto data_device_manager = wl::Bind<wl_data_device_manager>(
-      registry, name, std::min(version, kMaxDeviceManagerVersion));
+      registry, name, std::min(version, kMaxVersion));
   if (!data_device_manager) {
     LOG(ERROR) << "Failed to bind to wl_data_device_manager global";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_drm.cc b/ui/ozone/platform/wayland/host/wayland_drm.cc
index d806e8e..a7ed2e2 100644
--- a/ui/ozone/platform/wayland/host/wayland_drm.cc
+++ b/ui/ozone/platform/wayland/host/wayland_drm.cc
 
@@ -17,7 +17,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMinWlDrmVersion = 2;
+constexpr uint32_t kMinVersion = 2;
 }
 
 // static
@@ -31,8 +31,10 @@
                              uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->drm_ || version < kMinWlDrmVersion)
+  if (connection->drm_ ||
+      !!wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
   auto wl_drm = wl::Bind<struct wl_drm>(registry, name, version);
   if (!wl_drm) {
 
diff --git a/ui/ozone/platform/wayland/host/wayland_output.cc b/ui/ozone/platform/wayland/host/wayland_output.cc
index 585568f..2186d6a 100644
--- a/ui/ozone/platform/wayland/host/wayland_output.cc
+++ b/ui/ozone/platform/wayland/host/wayland_output.cc
 
@@ -16,7 +16,8 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMinWlOutputVersion = 2;
+// TODO(crbug.com/1279681): support newer versions.
+constexpr uint32_t kMinVersion = 2;
 }
 
 // static
@@ -30,14 +31,11 @@
                                 uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (version < kMinWlOutputVersion) {
-    LOG(ERROR)
-        << "Unable to bind to the unsupported wl_output object with version= "
-        << version << ". Minimum supported version is " << kMinWlOutputVersion;
+  if (!wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
   }
 
-  auto output = wl::Bind<wl_output>(registry, name, version);
+  auto output = wl::Bind<wl_output>(registry, name, kMinVersion);
   if (!output) {
     LOG(ERROR) << "Failed to bind to wl_output global";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_shm.cc b/ui/ozone/platform/wayland/host/wayland_shm.cc
index 7c6cd40..de97ad1 100644
--- a/ui/ozone/platform/wayland/host/wayland_shm.cc
+++ b/ui/ozone/platform/wayland/host/wayland_shm.cc
 
@@ -10,7 +10,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxShmVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 constexpr uint32_t kShmFormat = WL_SHM_FORMAT_ARGB8888;
 }  // namespace
 
@@ -25,11 +25,12 @@
                              uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->shm_)
+  if (connection->shm_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
-  auto shm =
-      wl::Bind<wl_shm>(registry, name, std::min(version, kMaxShmVersion));
+  auto shm = wl::Bind<wl_shm>(registry, name, kMinVersion);
   if (!shm) {
     LOG(ERROR) << "Failed to bind to wl_shm global";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zaura_shell.cc b/ui/ozone/platform/wayland/host/wayland_zaura_shell.cc
index b1ae436d..1b5585f 100644
--- a/ui/ozone/platform/wayland/host/wayland_zaura_shell.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zaura_shell.cc
 
@@ -18,7 +18,8 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxAuraShellVersion = 24;
+constexpr uint32_t kMinVersion = 1;
+constexpr uint32_t kMaxVersion = 24;
 }
 
 // static
@@ -33,11 +34,13 @@
                                     uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->zaura_shell_)
+  if (connection->zaura_shell_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) {
     return;
+  }
 
   auto zaura_shell = wl::Bind<struct zaura_shell>(
-      registry, name, std::min(version, kMaxAuraShellVersion));
+      registry, name, std::min(version, kMaxVersion));
   if (!zaura_shell) {
     LOG(ERROR) << "Failed to bind zaura_shell";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.cc b/ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.cc
index 094a2f9..84d847e 100644
--- a/ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.cc
 
@@ -16,7 +16,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxCursorShapesVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 using mojom::CursorType;
@@ -32,11 +32,13 @@
                                          uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->zcr_cursor_shapes_)
+  if (connection->zcr_cursor_shapes_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
-  auto zcr_cursor_shapes = wl::Bind<zcr_cursor_shapes_v1>(
-      registry, name, std::min(version, kMaxCursorShapesVersion));
+  auto zcr_cursor_shapes =
+      wl::Bind<zcr_cursor_shapes_v1>(registry, name, kMinVersion);
   if (!zcr_cursor_shapes) {
     LOG(ERROR) << "Failed to bind zcr_cursor_shapes_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc b/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
index 45177f2..6b4ec38 100644
--- a/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
 
@@ -14,7 +14,8 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxLinuxDmabufVersion = 3;
+constexpr uint32_t kMinVersion = 1;
+constexpr uint32_t kMaxVersion = 3;
 }
 
 // static
@@ -28,11 +29,13 @@
                                         uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->zwp_dmabuf())
+  if (connection->zwp_dmabuf() ||
+      !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) {
     return;
+  }
 
   auto zwp_linux_dmabuf = wl::Bind<zwp_linux_dmabuf_v1>(
-      registry, name, std::min(version, kMaxLinuxDmabufVersion));
+      registry, name, std::min(version, kMaxVersion));
   if (!zwp_linux_dmabuf) {
     LOG(ERROR) << "Failed to bind zwp_linux_dmabuf_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.cc b/ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.cc
index 24e4dac..c1aca77 100644
--- a/ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.cc
 
@@ -15,7 +15,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMinZwpPointerConstraintsVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 // static
@@ -30,12 +30,12 @@
   DCHECK_EQ(interface, kInterfaceName);
 
   if (connection->wayland_zwp_pointer_constraints_ ||
-      version < kMinZwpPointerConstraintsVersion) {
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
   }
 
   auto zwp_pointer_constraints_v1 =
-      wl::Bind<struct zwp_pointer_constraints_v1>(registry, name, version);
+      wl::Bind<struct zwp_pointer_constraints_v1>(registry, name, kMinVersion);
   if (!zwp_pointer_constraints_v1) {
     LOG(ERROR) << "Failed to bind wp_pointer_constraints_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.cc b/ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.cc
index 5d96c89..31bffb7 100644
--- a/ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.cc
 
@@ -19,7 +19,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMinZwpPointerGesturesVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 // static
@@ -34,11 +34,12 @@
   DCHECK_EQ(interface, kInterfaceName);
 
   if (connection->wayland_zwp_pointer_gestures_ ||
-      version < kMinZwpPointerGesturesVersion)
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
   auto zwp_pointer_gestures_v1 =
-      wl::Bind<struct zwp_pointer_gestures_v1>(registry, name, version);
+      wl::Bind<struct zwp_pointer_gestures_v1>(registry, name, kMinVersion);
   if (!zwp_pointer_gestures_v1) {
     LOG(ERROR) << "Failed to bind wp_pointer_gestures_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.cc b/ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.cc
index 3a8ef4c..c84a891 100644
--- a/ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.cc
+++ b/ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.cc
 
@@ -14,7 +14,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMinZwpRelativePointerManagerVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 // static
@@ -30,11 +30,13 @@
   DCHECK_EQ(interface, kInterfaceName);
 
   if (connection->wayland_zwp_relative_pointer_manager_ ||
-      version < kMinZwpRelativePointerManagerVersion)
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
   auto zwp_relative_pointer_manager_v1 =
-      wl::Bind<struct zwp_relative_pointer_manager_v1>(registry, name, version);
+      wl::Bind<struct zwp_relative_pointer_manager_v1>(registry, name,
+                                                       kMinVersion);
   if (!zwp_relative_pointer_manager_v1) {
     LOG(ERROR) << "Failed to bind zwp_relative_pointer_manager_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc b/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
index a34b684..2586adf 100644
--- a/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
+++ b/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
 
@@ -19,6 +19,8 @@
 // static
 constexpr char XdgForeignWrapper::kInterfaceNameV2[];
 
+constexpr uint32_t kMinVersion = 1;
+
 using OnHandleExported = XdgForeignWrapper::OnHandleExported;
 
 namespace {
@@ -185,15 +187,17 @@
                                     uint32_t name,
                                     const std::string& interface,
                                     uint32_t version) {
-  if (connection->xdg_foreign_)
+  if (connection->xdg_foreign_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
   if (interface == kInterfaceNameV1) {
-    connection->xdg_foreign_ =
-        CreateWrapper<zxdg_exporter_v1>(connection, registry, name, version);
+    connection->xdg_foreign_ = CreateWrapper<zxdg_exporter_v1>(
+        connection, registry, name, kMinVersion);
   } else if (interface == kInterfaceNameV2) {
-    connection->xdg_foreign_ =
-        CreateWrapper<zxdg_exporter_v2>(connection, registry, name, version);
+    connection->xdg_foreign_ = CreateWrapper<zxdg_exporter_v2>(
+        connection, registry, name, kMinVersion);
   } else {
     NOTREACHED() << " unexpected interface name: " << interface;
   }
 
diff --git a/ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.cc b/ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.cc
index 4712129..fc05de6 100644
--- a/ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.cc
+++ b/ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.cc
 
@@ -12,7 +12,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxZwpIdleInhibitManagerVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }
 
 // static
@@ -26,11 +26,13 @@
                                         uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->zwp_idle_inhibit_manager_)
+  if (connection->zwp_idle_inhibit_manager_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
-  auto manager = wl::Bind<zwp_idle_inhibit_manager_v1>(
-      registry, name, std::min(version, kMaxZwpIdleInhibitManagerVersion));
+  auto manager =
+      wl::Bind<zwp_idle_inhibit_manager_v1>(registry, name, kMinVersion);
   if (!manager) {
     LOG(ERROR) << "Failed to bind zwp_idle_inhibit_manager_v1";
     return;
 
diff --git a/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc b/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
index f6f9fd2..795a09c 100644
--- a/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
+++ b/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
 
@@ -16,7 +16,7 @@
 namespace ui {
 
 namespace {
-constexpr uint32_t kMaxGtkPrimarySelectionDeviceManagerVersion = 1;
+constexpr uint32_t kMinVersion = 1;
 }  // namespace
 
 // static
@@ -31,12 +31,13 @@
     uint32_t version) {
   DCHECK_EQ(interface, kInterfaceName);
 
-  if (connection->zwp_primary_selection_device_manager_)
+  if (connection->zwp_primary_selection_device_manager_ ||
+      !wl::CanBind(interface, version, kMinVersion, kMinVersion)) {
     return;
+  }
 
   auto manager = wl::Bind<zwp_primary_selection_device_manager_v1>(
-      registry, name,
-      std::min(version, kMaxGtkPrimarySelectionDeviceManagerVersion));
+      registry, name, kMinVersion);
   if (!manager) {
     LOG(ERROR) << "Failed to bind zwp_primary_selection_device_manager_v1";
     return;