From 643618026a8fd43f5705116a2829adeb2cc00df8 Mon Sep 17 00:00:00 2001 From: "blizzard%redhat.com" Date: Tue, 18 Sep 2001 21:45:43 +0000 Subject: [PATCH] Fix bug #80051. Attach the user running the mozilla process to the x remote windows so that another user running mozilla can run another copy of the process tothe same display. r/sr=alecf,shaver git-svn-id: svn://10.0.0.236/trunk@103110 18797224-902f-48f8-a5cc-f745e15eee43 --- .../widget/src/gtk/nsGtkMozRemoteHelper.cpp | 22 +++++++- mozilla/widget/src/gtk/nsGtkMozRemoteHelper.h | 2 +- mozilla/widget/src/xremoteclient/Makefile.in | 4 ++ .../src/xremoteclient/XRemoteClient.cpp | 51 ++++++++++++++++--- .../widget/src/xremoteclient/XRemoteClient.h | 1 + 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.cpp b/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.cpp index 7d1137a18f9..7d07dba08b9 100644 --- a/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.cpp +++ b/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.cpp @@ -25,18 +25,21 @@ #include #include #include +#include +#include #include "nsGtkMozRemoteHelper.h" - #define MOZILLA_VERSION_PROP "_MOZILLA_VERSION" #define MOZILLA_LOCK_PROP "_MOZILLA_LOCK" #define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND" #define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE" +#define MOZILLA_USER_PROP "_MOZILLA_USER" Atom nsGtkMozRemoteHelper::sMozVersionAtom = 0; Atom nsGtkMozRemoteHelper::sMozLockAtom = 0; Atom nsGtkMozRemoteHelper::sMozCommandAtom = 0; Atom nsGtkMozRemoteHelper::sMozResponseAtom = 0; +Atom nsGtkMozRemoteHelper::sMozUserAtom = 0; // XXX get this dynamically static char *sRemoteVersion = "5.0"; @@ -49,9 +52,21 @@ nsGtkMozRemoteHelper::SetupVersion(GdkWindow *aWindow) EnsureAtoms(); window = GDK_WINDOW_XWINDOW(aWindow); + // set our version XChangeProperty(GDK_DISPLAY(), window, sMozVersionAtom, XA_STRING, 8, PropModeReplace, data, strlen(sRemoteVersion)); + // get our username + char *logname; + logname = PR_GetEnv("LOGNAME"); + if (logname) { + data = (unsigned char *)logname; + + // set the property on the window if it's available + XChangeProperty(GDK_DISPLAY(), window, sMozUserAtom, XA_STRING, + 8, PropModeReplace, data, strlen(logname)); + } + } gboolean @@ -157,7 +172,10 @@ nsGtkMozRemoteHelper::EnsureAtoms(void) if (!sMozCommandAtom) sMozCommandAtom = XInternAtom(GDK_DISPLAY(), MOZILLA_COMMAND_PROP, False); if (!sMozResponseAtom) - sMozResponseAtom = XInternAtom(GDK_DISPLAY(), MOZILLA_RESPONSE_PROP, False); + sMozResponseAtom = XInternAtom(GDK_DISPLAY(), MOZILLA_RESPONSE_PROP, + False); + if (!sMozUserAtom) + sMozUserAtom = XInternAtom(GDK_DISPLAY(), MOZILLA_USER_PROP, False); } diff --git a/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.h b/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.h index 0e4b83ec4dd..bb60ed9dbd7 100644 --- a/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.h +++ b/mozilla/widget/src/gtk/nsGtkMozRemoteHelper.h @@ -49,7 +49,7 @@ public: static Atom sMozLockAtom; static Atom sMozCommandAtom; static Atom sMozResponseAtom; - + static Atom sMozUserAtom; }; diff --git a/mozilla/widget/src/xremoteclient/Makefile.in b/mozilla/widget/src/xremoteclient/Makefile.in index d7fa9d682c3..51dbd39a085 100644 --- a/mozilla/widget/src/xremoteclient/Makefile.in +++ b/mozilla/widget/src/xremoteclient/Makefile.in @@ -47,3 +47,7 @@ EXPORTS = \ nsXRemoteClientCID.h include $(topsrcdir)/config/rules.mk + +ifeq ($(OS_ARCH), Linux) +DEFINES += -D_BSD_SOURCE +endif diff --git a/mozilla/widget/src/xremoteclient/XRemoteClient.cpp b/mozilla/widget/src/xremoteclient/XRemoteClient.cpp index 6afd8ad378d..a9e942e22c9 100644 --- a/mozilla/widget/src/xremoteclient/XRemoteClient.cpp +++ b/mozilla/widget/src/xremoteclient/XRemoteClient.cpp @@ -36,6 +36,7 @@ #include "plstr.h" #include "prsystem.h" #include "prlog.h" +#include "prenv.h" #include #include #include @@ -51,6 +52,7 @@ #define MOZILLA_LOCK_PROP "_MOZILLA_LOCK" #define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND" #define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE" +#define MOZILLA_USER_PROP "_MOZILLA_USER" static PRLogModuleInfo *sRemoteLm = NULL; @@ -64,6 +66,7 @@ XRemoteClient::XRemoteClient() mMozCommandAtom = 0; mMozResponseAtom = 0; mMozWMStateAtom = 0; + mMozUserAtom = 0; if (!sRemoteLm) sRemoteLm = PR_NewLogModule("XRemoteClient"); PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::XRemoteClient")); @@ -96,6 +99,7 @@ XRemoteClient::Init (void) mMozCommandAtom = XInternAtom(mDisplay, MOZILLA_COMMAND_PROP, False); mMozResponseAtom = XInternAtom(mDisplay, MOZILLA_RESPONSE_PROP, False); mMozWMStateAtom = XInternAtom(mDisplay, "WM_STATE", False); + mMozUserAtom = XInternAtom(mDisplay, MOZILLA_USER_PROP, False); mInitialized = PR_TRUE; @@ -188,7 +192,7 @@ XRemoteClient::FindWindow(void) Atom type; int format; unsigned long nitems, bytesafter; - unsigned char *version = 0; + unsigned char *data_return = 0; Window w; w = kids[i]; // find the inner window with WM_STATE on it @@ -198,13 +202,48 @@ XRemoteClient::FindWindow(void) 0, (65536 / sizeof (long)), False, XA_STRING, &type, &format, &nitems, &bytesafter, - &version); - if (!version) + &data_return); + + if (!data_return) continue; - XFree(version); + + XFree(data_return); + data_return = 0; + if (status == Success && type != None) { - result = w; - break; + // Check to see if it has the user atom on that window. If there + // is then we need to make sure that it matches what we have. + char *logname; + logname = PR_GetEnv("LOGNAME"); + + if (logname) { + status = XGetWindowProperty(mDisplay, w, mMozUserAtom, + 0, (65536 / sizeof(long)), + False, XA_STRING, + &type, &format, &nitems, &bytesafter, + &data_return); + + // if there's a username compare it with what we have + if (data_return) { + + // if the IDs are equal then this is the window we want. if + // they aren't fall through to the next loop iteration. + if (!strcmp(logname, (const char *)data_return)) { + XFree(data_return); + result = w; + break; + } + + XFree(data_return); + } + } + + // ok, this is the one we want since there's no username attribute on + // it. + else { + result = w; + break; + } } } diff --git a/mozilla/widget/src/xremoteclient/XRemoteClient.h b/mozilla/widget/src/xremoteclient/XRemoteClient.h index 5a5aad68872..b46dcb4f1e4 100644 --- a/mozilla/widget/src/xremoteclient/XRemoteClient.h +++ b/mozilla/widget/src/xremoteclient/XRemoteClient.h @@ -63,6 +63,7 @@ private: Atom mMozCommandAtom; Atom mMozResponseAtom; Atom mMozWMStateAtom; + Atom mMozUserAtom; nsCString mLockData;