mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
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
This commit is contained in:
parent
5fa841a6c4
commit
d5b3341812
@ -25,18 +25,21 @@
|
||||
#include <nsIXRemoteService.h>
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsIServiceManager.h>
|
||||
#include <prprf.h>
|
||||
#include <prenv.h>
|
||||
#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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
static Atom sMozLockAtom;
|
||||
static Atom sMozCommandAtom;
|
||||
static Atom sMozResponseAtom;
|
||||
|
||||
static Atom sMozUserAtom;
|
||||
|
||||
};
|
||||
|
||||
|
@ -47,3 +47,7 @@ EXPORTS = \
|
||||
nsXRemoteClientCID.h
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
DEFINES += -D_BSD_SOURCE
|
||||
endif
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "plstr.h"
|
||||
#include "prsystem.h"
|
||||
#include "prlog.h"
|
||||
#include "prenv.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ private:
|
||||
Atom mMozCommandAtom;
|
||||
Atom mMozResponseAtom;
|
||||
Atom mMozWMStateAtom;
|
||||
Atom mMozUserAtom;
|
||||
|
||||
nsCString mLockData;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user