Bug 1550658 - [Linux/Gtk] Don't use Wayland display in content process when it's disabled in chrome, r=sotaro
authorMartin Stransky <stransky@redhat.com>
Mon, 13 May 2019 11:19:41 +0000
changeset 473591 194ec02ee76d472699c9458a1915df5430c82135
parent 473590 16c03995ac55ce131282881c7c5d31ee6061441e
child 473592 b7145dad7ce17f1f8f72c8974b7472ffd1c84e17
push id113093
push userapavel@mozilla.com
push dateMon, 13 May 2019 22:09:34 +0000
treeherdermozilla-inbound@a0403c2bfae4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1550658
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550658 - [Linux/Gtk] Don't use Wayland display in content process when it's disabled in chrome, r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D30724
dom/ipc/ContentChild.cpp
gfx/ipc/GPUParent.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsAppRunner.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -619,21 +619,25 @@ bool ContentChild::Init(MessageLoop* aIO
   // on its own when deciding which backend to use, and when starting under
   // XWayland, it may choose to start with the wayland backend
   // instead of the x11 backend.
   // The DISPLAY environment variable is normally set by the parent process.
   // The MOZ_GDK_DISPLAY environment variable is set from nsAppRunner.cpp
   // when --display is set by the command line.
   if (!gfxPlatform::IsHeadless()) {
     const char* display_name = PR_GetEnv("MOZ_GDK_DISPLAY");
-#  ifndef MOZ_WAYLAND
     if (!display_name) {
-      display_name = PR_GetEnv("DISPLAY");
+      bool waylandDisabled = true;
+#  ifdef MOZ_WAYLAND
+      waylandDisabled = IsWaylandDisabled();
+#  endif
+      if (waylandDisabled) {
+        display_name = PR_GetEnv("DISPLAY");
+      }
     }
-#  endif
     if (display_name) {
       int argc = 3;
       char option_name[] = "--display";
       char* argv[] = {
           // argv0 is unused because g_set_prgname() was called in
           // XRE_InitChildProcess().
           nullptr, option_name, const_cast<char*>(display_name), nullptr};
       char** argvp = argv;
--- a/gfx/ipc/GPUParent.cpp
+++ b/gfx/ipc/GPUParent.cpp
@@ -59,16 +59,17 @@
 #endif
 #ifdef MOZ_WIDGET_GTK
 #  include <gtk/gtk.h>
 #  include "skia/include/ports/SkTypeface_cairo.h"
 #endif
 #ifdef MOZ_GECKO_PROFILER
 #  include "ChildProfilerController.h"
 #endif
+#include "nsAppRunner.h"
 
 namespace mozilla {
 namespace gfx {
 
 using namespace ipc;
 using namespace layers;
 
 static GPUParent* sGPUParent;
@@ -219,17 +220,26 @@ mozilla::ipc::IPCResult GPUParent::RecvI
     nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
     Unused << gfxInfo;
 
     Factory::EnsureDWriteFactory();
   }
 #endif
 
 #if defined(MOZ_WIDGET_GTK)
-  char* display_name = PR_GetEnv("DISPLAY");
+  char* display_name = PR_GetEnv("MOZ_GDK_DISPLAY");
+  if (!display_name) {
+    bool waylandDisabled = true;
+#  ifdef MOZ_WAYLAND
+    waylandDisabled = IsWaylandDisabled();
+#  endif
+    if (waylandDisabled) {
+      display_name = PR_GetEnv("DISPLAY");
+    }
+  }
   if (display_name) {
     int argc = 3;
     char option_name[] = "--display";
     char* argv[] = {// argv0 is unused because g_set_prgname() was called in
                     // XRE_InitChildProcess().
                     nullptr, option_name, display_name, nullptr};
     char** argvp = argv;
     gtk_init(&argc, &argvp);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -243,17 +243,17 @@ extern uint32_t gRestartMode;
 extern void InstallSignalHandlers(const char* ProgramName);
 
 #define FILE_COMPATIBILITY_INFO NS_LITERAL_CSTRING("compatibility.ini")
 #define FILE_INVALIDATE_CACHES NS_LITERAL_CSTRING(".purgecaches")
 #define FILE_STARTUP_INCOMPLETE NS_LITERAL_STRING(".startup-incomplete")
 
 #if defined(MOZ_BLOCK_PROFILE_DOWNGRADE) || defined(MOZ_LAUNCHER_PROCESS)
 static const char kPrefHealthReportUploadEnabled[] =
-  "datareporting.healthreport.uploadEnabled";
+    "datareporting.healthreport.uploadEnabled";
 #endif  // defined(MOZ_BLOCK_PROFILE_DOWNGRADE) || defined(MOZ_LAUNCHER_PROCESS)
 
 int gArgc;
 char** gArgv;
 
 #include "buildid.h"
 
 static const char gToolkitVersion[] = NS_STRINGIFY(GRE_MILESTONE);
@@ -1553,18 +1553,18 @@ static void SetupLauncherProcessPref() {
     // Reflect the launcher process registry state into user prefs
     Preferences::SetBool(
         PREF_WIN_LAUNCHER_PROCESS_ENABLED,
         enabledState.unwrap() !=
             mozilla::LauncherRegistryInfo::EnabledState::ForceDisabled);
   }
 
   mozilla::LauncherVoidResult reflectResult =
-    launcherRegInfo.ReflectTelemetryPrefToRegistry(
-      Preferences::GetBool(kPrefHealthReportUploadEnabled, true));
+      launcherRegInfo.ReflectTelemetryPrefToRegistry(
+          Preferences::GetBool(kPrefHealthReportUploadEnabled, true));
   MOZ_ASSERT(reflectResult.isOk());
 
   Preferences::RegisterCallback(&OnLauncherPrefChanged,
                                 PREF_WIN_LAUNCHER_PROCESS_ENABLED);
   Preferences::RegisterCallback(&OnLauncherTelemetryPrefChanged,
                                 kPrefHealthReportUploadEnabled);
 }
 
@@ -2059,18 +2059,18 @@ static void SubmitDowngradeTelemetry(con
   nsCOMPtr<nsIPrefService> prefSvc =
       do_GetService("@mozilla.org/preferences-service;1");
   NS_ENSURE_TRUE_VOID(prefSvc);
 
   nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefSvc);
   NS_ENSURE_TRUE_VOID(prefBranch);
 
   bool enabled;
-  nsresult rv = prefBranch->GetBoolPref(kPrefHealthReportUploadEnabled,
-                                        &enabled);
+  nsresult rv =
+      prefBranch->GetBoolPref(kPrefHealthReportUploadEnabled, &enabled);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (!enabled) {
     return;
   }
 
   nsCString server;
   rv = prefBranch->GetCharPref("toolkit.telemetry.server", server);
   NS_ENSURE_SUCCESS_VOID(rv);
@@ -3587,16 +3587,31 @@ static void SetShutdownChecks() {
     } else if (strcmp(mozShutdownChecksEnv, "record") == 0) {
       gShutdownChecks = SCM_RECORD;
     } else if (strcmp(mozShutdownChecksEnv, "nothing") == 0) {
       gShutdownChecks = SCM_NOTHING;
     }
   }
 }
 
+#if defined(MOZ_WAYLAND)
+bool IsWaylandDisabled() {
+  // Enable Wayland on Gtk+ >= 3.22 where we can expect recent enough
+  // compositor & libwayland interface.
+  bool disableWayland = (gtk_check_version(3, 22, 0) != nullptr);
+  if (!disableWayland) {
+    // Make X11 backend the default one unless MOZ_ENABLE_WAYLAND or
+    // GDK_BACKEND are specified.
+    disableWayland = (PR_GetEnv("GDK_BACKEND") == nullptr) &&
+                     (PR_GetEnv("MOZ_ENABLE_WAYLAND") == nullptr);
+  }
+  return disableWayland;
+}
+#endif
+
 namespace mozilla {
 namespace startup {
 Result<nsCOMPtr<nsIFile>, nsresult> GetIncompleteStartupFile(nsIFile* aProfLD) {
   nsCOMPtr<nsIFile> crashFile;
   MOZ_TRY(aProfLD->Clone(getter_AddRefs(crashFile)));
   MOZ_TRY(crashFile->Append(FILE_STARTUP_INCOMPLETE));
   return std::move(crashFile);
 }
@@ -3760,25 +3775,17 @@ int XREMain::XRE_mainStartup(bool* aExit
     // also passed to ContentChild::Init() by MOZ_GDK_DISPLAY.
     if (display_name) {
       SaveWordToEnv("MOZ_GDK_DISPLAY", nsDependentCString(display_name));
       saveDisplayArg = true;
     }
 
     bool disableWayland = true;
 #  if defined(MOZ_WAYLAND)
-    // Enable Wayland on Gtk+ >= 3.22 where we can expect recent enough
-    // compositor & libwayland interface.
-    disableWayland = (gtk_check_version(3, 22, 0) != nullptr);
-    if (!disableWayland) {
-      // Make X11 backend the default one unless MOZ_ENABLE_WAYLAND or
-      // GDK_BACKEND are specified.
-      disableWayland = (PR_GetEnv("GDK_BACKEND") == nullptr) &&
-                       (PR_GetEnv("MOZ_ENABLE_WAYLAND") == nullptr);
-    }
+    disableWayland = IsWaylandDisabled();
 #  endif
     // On Wayland disabled builds read X11 DISPLAY env exclusively
     // and don't care about different displays.
     if (disableWayland && !display_name) {
       display_name = PR_GetEnv("DISPLAY");
       if (!display_name) {
         PR_fprintf(PR_STDERR,
                    "Error: no DISPLAY environment variable specified\n");
--- a/toolkit/xre/nsAppRunner.h
+++ b/toolkit/xre/nsAppRunner.h
@@ -132,9 +132,13 @@ void SetupErrorHandling(const char* prog
 
 #ifdef MOZ_ASAN_REPORTER
 extern "C" {
 void MOZ_EXPORT __sanitizer_set_report_path(const char* path);
 }
 void setASanReporterPath(nsIFile* aDir);
 #endif
 
+#ifdef MOZ_WAYLAND
+bool IsWaylandDisabled();
+#endif
+
 #endif  // nsAppRunner_h__