Commit 633c0115 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Avoid using X11 SHM for remote connections

For remote connections, SHM doesn't work, but the MIT-SHM extension may
still be available, so we need to do an explicit check before trying to
use SHM.

BUG=1035803

Change-Id: I189ab94b82922572e52b717dc2043b8404745dec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980971
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728564}
parent fbed6404
......@@ -64,6 +64,7 @@ jumbo_component("x") {
deps = [
"//base",
"//base:i18n",
"//net",
"//skia",
"//ui/base:hit_test",
"//ui/base/clipboard:clipboard_types",
......
......@@ -18,6 +18,7 @@
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "net/base/url_util.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/geometry/rect.h"
......@@ -54,8 +55,35 @@ std::size_t MaxShmSegmentSize() {
return max_size;
}
bool IsRemoteHost(const std::string& name) {
if (name.empty())
return false;
char hostname[256];
if (!gethostname(hostname, sizeof(hostname)) && name == hostname)
return false;
return !net::HostStringIsLocalhost(name);
}
bool ShouldUseMitShm(XDisplay* display) {
// MIT-SHM may be available on remote connetions, but it will be unusable. Do
// a best-effort check to see if the host is remote to disable the SHM
// 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.
char* display_string = DisplayString(display);
char* host = nullptr;
int display_id = 0;
int screen = 0;
if (xcb_parse_display(display_string, &host, &display_id, &screen)) {
std::string name = host;
free(host);
if (IsRemoteHost(name))
return false;
}
#if !defined(OS_CHROMEOS)
bool ShouldUseMitShm() {
std::unique_ptr<base::Environment> env = base::Environment::Create();
// Used by QT.
......@@ -73,10 +101,10 @@ bool ShouldUseMitShm() {
// Used by GTK.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoXshm))
return false;
#endif
return true;
}
#endif
} // namespace
......@@ -119,10 +147,8 @@ bool XShmImagePoolBase::Resize(const gfx::Size& pixel_size) {
if (!event_task_runner_)
return false;
#if !defined(OS_CHROMEOS)
if (!ShouldUseMitShm())
if (!ShouldUseMitShm(display_))
return false;
#endif
if (!ui::QueryShmSupport())
return false;
......
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