2009-09-03 00:47:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=2:tabstop=8:
|
2004-04-08 18:01:17 +04:00
|
|
|
*/
|
2003-11-21 03:09:50 +03:00
|
|
|
/* vim:set ts=8 sw=2 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2015-04-22 05:02:55 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2000-10-20 09:10:43 +04:00
|
|
|
#include "XRemoteClient.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prsystem.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2001-09-19 01:45:43 +04:00
|
|
|
#include "prenv.h"
|
2005-04-04 23:08:55 +04:00
|
|
|
#include "prdtoa.h"
|
2000-10-20 09:10:43 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2005-04-04 23:08:55 +04:00
|
|
|
#include <string.h>
|
2001-01-17 00:47:04 +03:00
|
|
|
#include <strings.h>
|
2000-10-20 09:10:43 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2009-02-23 21:28:12 +03:00
|
|
|
#include <limits.h>
|
2000-10-20 09:10:43 +04:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
|
|
|
|
#define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
|
2005-04-04 23:08:55 +04:00
|
|
|
#define MOZILLA_COMMANDLINE_PROP "_MOZILLA_COMMANDLINE"
|
2000-10-20 09:10:43 +04:00
|
|
|
#define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
|
2001-09-19 01:45:43 +04:00
|
|
|
#define MOZILLA_USER_PROP "_MOZILLA_USER"
|
2004-04-08 18:01:17 +04:00
|
|
|
#define MOZILLA_PROFILE_PROP "_MOZILLA_PROFILE"
|
|
|
|
#define MOZILLA_PROGRAM_PROP "_MOZILLA_PROGRAM"
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2005-12-26 06:10:35 +03:00
|
|
|
#ifdef IS_BIG_ENDIAN
|
|
|
|
#define TO_LITTLE_ENDIAN32(x) \
|
|
|
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
|
|
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
|
|
|
#else
|
|
|
|
#define TO_LITTLE_ENDIAN32(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
#ifndef MAX_PATH
|
2009-02-23 21:28:12 +03:00
|
|
|
#ifdef PATH_MAX
|
|
|
|
#define MAX_PATH PATH_MAX
|
|
|
|
#else
|
2005-04-04 23:08:55 +04:00
|
|
|
#define MAX_PATH 1024
|
|
|
|
#endif
|
2009-02-23 21:28:12 +03:00
|
|
|
#endif
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
using mozilla::LogLevel;
|
|
|
|
|
2013-10-28 18:05:51 +04:00
|
|
|
static PRLogModuleInfo *sRemoteLm = nullptr;
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
static int (*sOldHandler)(Display *, XErrorEvent *);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sGotBadWindow;
|
2009-09-03 00:47:44 +04:00
|
|
|
|
2000-10-20 09:10:43 +04:00
|
|
|
XRemoteClient::XRemoteClient()
|
|
|
|
{
|
|
|
|
mDisplay = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = false;
|
2000-10-20 09:10:43 +04:00
|
|
|
mMozVersionAtom = 0;
|
|
|
|
mMozLockAtom = 0;
|
|
|
|
mMozResponseAtom = 0;
|
2001-09-11 05:36:19 +04:00
|
|
|
mMozWMStateAtom = 0;
|
2001-09-19 01:45:43 +04:00
|
|
|
mMozUserAtom = 0;
|
2001-12-29 01:17:20 +03:00
|
|
|
mLockData = 0;
|
2000-10-20 09:10:43 +04:00
|
|
|
if (!sRemoteLm)
|
|
|
|
sRemoteLm = PR_NewLogModule("XRemoteClient");
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("XRemoteClient::XRemoteClient"));
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
XRemoteClient::~XRemoteClient()
|
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("XRemoteClient::~XRemoteClient"));
|
2000-10-20 09:10:43 +04:00
|
|
|
if (mInitialized)
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2005-02-19 19:11:58 +03:00
|
|
|
// Minimize the roundtrips to the X-server
|
2012-12-27 09:57:57 +04:00
|
|
|
static const char *XAtomNames[] = {
|
2005-02-19 19:11:58 +03:00
|
|
|
MOZILLA_VERSION_PROP,
|
|
|
|
MOZILLA_LOCK_PROP,
|
|
|
|
MOZILLA_RESPONSE_PROP,
|
|
|
|
"WM_STATE",
|
|
|
|
MOZILLA_USER_PROP,
|
|
|
|
MOZILLA_PROFILE_PROP,
|
2005-04-04 23:08:55 +04:00
|
|
|
MOZILLA_PROGRAM_PROP,
|
|
|
|
MOZILLA_COMMANDLINE_PROP
|
2005-02-19 19:11:58 +03:00
|
|
|
};
|
2015-04-22 05:02:55 +03:00
|
|
|
static Atom XAtoms[MOZ_ARRAY_LENGTH(XAtomNames)];
|
2005-02-19 19:11:58 +03:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
nsresult
|
|
|
|
XRemoteClient::Init()
|
2000-10-20 09:10:43 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("XRemoteClient::Init"));
|
2000-10-20 09:10:43 +04:00
|
|
|
|
|
|
|
if (mInitialized)
|
|
|
|
return NS_OK;
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2000-10-20 09:10:43 +04:00
|
|
|
// try to open the display
|
|
|
|
mDisplay = XOpenDisplay(0);
|
|
|
|
if (!mDisplay)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get our atoms
|
2012-12-27 09:57:57 +04:00
|
|
|
XInternAtoms(mDisplay, const_cast<char**>(XAtomNames),
|
2015-04-22 05:02:55 +03:00
|
|
|
MOZ_ARRAY_LENGTH(XAtomNames), False, XAtoms);
|
2005-02-19 19:11:58 +03:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
mMozVersionAtom = XAtoms[i++];
|
|
|
|
mMozLockAtom = XAtoms[i++];
|
|
|
|
mMozResponseAtom = XAtoms[i++];
|
|
|
|
mMozWMStateAtom = XAtoms[i++];
|
|
|
|
mMozUserAtom = XAtoms[i++];
|
|
|
|
mMozProfileAtom = XAtoms[i++];
|
|
|
|
mMozProgramAtom = XAtoms[i++];
|
2005-04-04 23:08:55 +04:00
|
|
|
mMozCommandLineAtom = XAtoms[i++];
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
void
|
2000-10-20 09:10:43 +04:00
|
|
|
XRemoteClient::Shutdown (void)
|
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("XRemoteClient::Shutdown"));
|
2000-10-20 09:10:43 +04:00
|
|
|
|
|
|
|
if (!mInitialized)
|
2005-04-04 23:08:55 +04:00
|
|
|
return;
|
|
|
|
|
2000-10-20 09:10:43 +04:00
|
|
|
// shut everything down
|
|
|
|
XCloseDisplay(mDisplay);
|
|
|
|
mDisplay = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = false;
|
2001-12-29 01:17:20 +03:00
|
|
|
if (mLockData) {
|
|
|
|
free(mLockData);
|
|
|
|
mLockData = 0;
|
|
|
|
}
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
static int
|
|
|
|
HandleBadWindow(Display *display, XErrorEvent *event)
|
|
|
|
{
|
|
|
|
if (event->error_code == BadWindow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
sGotBadWindow = true;
|
2009-09-03 00:47:44 +04:00
|
|
|
return 0; // ignored
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (*sOldHandler)(display, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
XRemoteClient::SendCommandLine (const char *aProgram, const char *aUsername,
|
|
|
|
const char *aProfile,
|
|
|
|
int32_t argc, char **argv,
|
|
|
|
const char* aDesktopStartupID,
|
|
|
|
char **aResponse, bool *aWindowFound)
|
2009-09-03 00:47:44 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("XRemoteClient::SendCommandLine"));
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aWindowFound = false;
|
2009-09-03 00:47:44 +04:00
|
|
|
|
|
|
|
// FindBestWindow() iterates down the window hierarchy, so catch X errors
|
|
|
|
// when windows get destroyed before being accessed.
|
|
|
|
sOldHandler = XSetErrorHandler(HandleBadWindow);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
Window w = FindBestWindow(aProgram, aUsername, aProfile);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
// ok, let the caller know that we at least found a window.
|
2011-10-17 18:59:28 +04:00
|
|
|
*aWindowFound = true;
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
// Ignore BadWindow errors up to this point. The last request from
|
|
|
|
// FindBestWindow() was a synchronous XGetWindowProperty(), so no need to
|
|
|
|
// Sync. Leave the error handler installed to detect if w gets destroyed.
|
2011-10-17 18:59:28 +04:00
|
|
|
sGotBadWindow = false;
|
2009-09-03 00:47:44 +04:00
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
// make sure we get the right events on that window
|
|
|
|
XSelectInput(mDisplay, w,
|
|
|
|
(PropertyChangeMask|StructureNotifyMask));
|
2009-09-03 00:47:44 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool destroyed = false;
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
// get the lock on the window
|
|
|
|
rv = GetLock(w, &destroyed);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// send our command
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
rv = DoSendCommandLine(w, argc, argv, aDesktopStartupID, aResponse,
|
|
|
|
&destroyed);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
// if the window was destroyed, don't bother trying to free the
|
|
|
|
// lock.
|
|
|
|
if (!destroyed)
|
|
|
|
FreeLock(w); // doesn't really matter what this returns
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
XSetErrorHandler(sOldHandler);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("SendCommandInternal returning 0x%x\n", rv));
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-11 05:36:19 +04:00
|
|
|
Window
|
|
|
|
XRemoteClient::CheckWindow(Window aWindow)
|
|
|
|
{
|
|
|
|
Atom type = None;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
|
|
|
unsigned char *data;
|
|
|
|
Window innerWindow;
|
|
|
|
|
|
|
|
XGetWindowProperty(mDisplay, aWindow, mMozWMStateAtom,
|
|
|
|
0, 0, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &bytesafter, &data);
|
|
|
|
|
2005-08-19 19:15:34 +04:00
|
|
|
if (type) {
|
|
|
|
XFree(data);
|
2001-09-11 05:36:19 +04:00
|
|
|
return aWindow;
|
2005-08-19 19:15:34 +04:00
|
|
|
}
|
2001-09-11 05:36:19 +04:00
|
|
|
|
|
|
|
// didn't find it here so check the children of this window
|
|
|
|
innerWindow = CheckChildren(aWindow);
|
|
|
|
|
|
|
|
if (innerWindow)
|
|
|
|
return innerWindow;
|
|
|
|
|
|
|
|
return aWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window
|
|
|
|
XRemoteClient::CheckChildren(Window aWindow)
|
|
|
|
{
|
|
|
|
Window root, parent;
|
|
|
|
Window *children;
|
|
|
|
unsigned int nchildren;
|
|
|
|
unsigned int i;
|
|
|
|
Atom type = None;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, after;
|
|
|
|
unsigned char *data;
|
|
|
|
Window retval = None;
|
|
|
|
|
|
|
|
if (!XQueryTree(mDisplay, aWindow, &root, &parent, &children,
|
|
|
|
&nchildren))
|
|
|
|
return None;
|
|
|
|
|
|
|
|
// scan the list first before recursing into the list of windows
|
|
|
|
// which can get quite deep.
|
|
|
|
for (i=0; !retval && (i < nchildren); i++) {
|
|
|
|
XGetWindowProperty(mDisplay, children[i], mMozWMStateAtom,
|
|
|
|
0, 0, False, AnyPropertyType, &type, &format,
|
|
|
|
&nitems, &after, &data);
|
2005-08-19 19:15:34 +04:00
|
|
|
if (type) {
|
|
|
|
XFree(data);
|
2001-09-11 05:36:19 +04:00
|
|
|
retval = children[i];
|
2005-08-19 19:15:34 +04:00
|
|
|
}
|
2001-09-11 05:36:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise recurse into the list
|
|
|
|
for (i=0; !retval && (i < nchildren); i++) {
|
|
|
|
retval = CheckChildren(children[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (children)
|
|
|
|
XFree((char *)children);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-10-20 09:10:43 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
XRemoteClient::GetLock(Window aWindow, bool *aDestroyed)
|
2000-10-20 09:10:43 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool locked = false;
|
|
|
|
bool waited = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDestroyed = false;
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-12-29 01:17:20 +03:00
|
|
|
if (!mLockData) {
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2001-12-29 01:17:20 +03:00
|
|
|
char pidstr[32];
|
|
|
|
char sysinfobuf[SYS_INFO_BUFFER_LENGTH];
|
|
|
|
PR_snprintf(pidstr, sizeof(pidstr), "pid%d@", getpid());
|
2000-10-20 09:10:43 +04:00
|
|
|
PRStatus status;
|
|
|
|
status = PR_GetSystemInfo(PR_SI_HOSTNAME, sysinfobuf,
|
|
|
|
SYS_INFO_BUFFER_LENGTH);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-12-29 01:17:20 +03:00
|
|
|
|
|
|
|
// allocate enough space for the string plus the terminating
|
|
|
|
// char
|
|
|
|
mLockData = (char *)malloc(strlen(pidstr) + strlen(sysinfobuf) + 1);
|
|
|
|
if (!mLockData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
strcpy(mLockData, pidstr);
|
|
|
|
if (!strcat(mLockData, sysinfobuf))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
int result;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
|
|
|
|
XGrabServer(mDisplay);
|
|
|
|
|
|
|
|
result = XGetWindowProperty (mDisplay, aWindow, mMozLockAtom,
|
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
False, /* don't delete */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2009-09-03 00:47:44 +04:00
|
|
|
|
|
|
|
// aWindow may have been destroyed before XSelectInput was processed, in
|
|
|
|
// which case there may not be any DestroyNotify event in the queue to
|
|
|
|
// tell us. XGetWindowProperty() was synchronous so error responses have
|
|
|
|
// now been processed, setting sGotBadWindow.
|
|
|
|
if (sGotBadWindow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDestroyed = true;
|
2009-09-03 00:47:44 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else if (result != Success || actual_type == None) {
|
2000-10-20 09:10:43 +04:00
|
|
|
/* It's not now locked - lock it. */
|
|
|
|
XChangeProperty (mDisplay, aWindow, mMozLockAtom, XA_STRING, 8,
|
|
|
|
PropModeReplace,
|
2001-12-29 01:17:20 +03:00
|
|
|
(unsigned char *)mLockData,
|
|
|
|
strlen(mLockData));
|
2000-10-20 09:10:43 +04:00
|
|
|
locked = True;
|
|
|
|
}
|
|
|
|
|
|
|
|
XUngrabServer(mDisplay);
|
2009-09-03 00:47:44 +04:00
|
|
|
XFlush(mDisplay); // ungrab now!
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
if (!locked && !NS_FAILED(rv)) {
|
2000-10-20 09:10:43 +04:00
|
|
|
/* We tried to grab the lock this time, and failed because someone
|
|
|
|
else is holding it already. So, wait for a PropertyDelete event
|
|
|
|
to come in, and try again. */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2000-10-20 09:10:43 +04:00
|
|
|
("window 0x%x is locked by %s; waiting...\n",
|
|
|
|
(unsigned int) aWindow, data));
|
|
|
|
waited = True;
|
|
|
|
while (1) {
|
|
|
|
XEvent event;
|
|
|
|
int select_retval;
|
2001-07-16 15:36:06 +04:00
|
|
|
fd_set select_set;
|
2000-10-20 09:10:43 +04:00
|
|
|
struct timeval delay;
|
|
|
|
delay.tv_sec = 10;
|
|
|
|
delay.tv_usec = 0;
|
|
|
|
|
|
|
|
FD_ZERO(&select_set);
|
|
|
|
// add the x event queue to the select set
|
|
|
|
FD_SET(ConnectionNumber(mDisplay), &select_set);
|
|
|
|
select_retval = select(ConnectionNumber(mDisplay) + 1,
|
2013-10-28 18:05:51 +04:00
|
|
|
&select_set, nullptr, nullptr, &delay);
|
2000-10-20 09:10:43 +04:00
|
|
|
// did we time out?
|
|
|
|
if (select_retval == 0) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("timed out waiting for window\n"));
|
2009-09-03 00:47:44 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("xevent...\n"));
|
2000-10-20 09:10:43 +04:00
|
|
|
XNextEvent (mDisplay, &event);
|
|
|
|
if (event.xany.type == DestroyNotify &&
|
|
|
|
event.xdestroywindow.window == aWindow) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDestroyed = true;
|
2009-09-03 00:47:44 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
|
|
|
event.xproperty.state == PropertyDelete &&
|
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.atom == mMozLockAtom) {
|
|
|
|
/* Ok! Someone deleted their lock, so now we can try
|
|
|
|
again. */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2000-10-20 09:10:43 +04:00
|
|
|
("(0x%x unlocked, trying again...)\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
XFree(data);
|
2009-09-03 00:47:44 +04:00
|
|
|
} while (!locked && !NS_FAILED(rv));
|
2000-10-20 09:10:43 +04:00
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
if (waited && locked) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("obtained lock.\n"));
|
2009-09-03 00:47:44 +04:00
|
|
|
} else if (*aDestroyed) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2009-09-03 00:47:44 +04:00
|
|
|
("window 0x%x unexpectedly destroyed.\n",
|
|
|
|
(unsigned int) aWindow));
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 00:47:44 +04:00
|
|
|
return rv;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2004-04-08 18:01:17 +04:00
|
|
|
Window
|
|
|
|
XRemoteClient::FindBestWindow(const char *aProgram, const char *aUsername,
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
const char *aProfile)
|
2004-04-08 18:01:17 +04:00
|
|
|
{
|
|
|
|
Window root = RootWindowOfScreen(DefaultScreenOfDisplay(mDisplay));
|
|
|
|
Window bestWindow = 0;
|
|
|
|
Window root2, parent, *kids;
|
|
|
|
unsigned int nkids;
|
|
|
|
|
|
|
|
// Get a list of the children of the root window, walk the list
|
|
|
|
// looking for the best window that fits the criteria.
|
|
|
|
if (!XQueryTree(mDisplay, root, &root2, &parent, &kids, &nkids)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2004-04-08 18:01:17 +04:00
|
|
|
("XQueryTree failed in XRemoteClient::FindBestWindow"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(kids && nkids)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("root window has no children"));
|
2004-04-08 18:01:17 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll walk the list of windows looking for a window that best
|
|
|
|
// fits the criteria here.
|
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
for (unsigned int i = 0; i < nkids; i++) {
|
2004-04-08 18:01:17 +04:00
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
|
|
|
unsigned char *data_return = 0;
|
|
|
|
Window w;
|
|
|
|
w = kids[i];
|
|
|
|
// find the inner window with WM_STATE on it
|
|
|
|
w = CheckWindow(w);
|
|
|
|
|
|
|
|
int status = XGetWindowProperty(mDisplay, w, mMozVersionAtom,
|
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
if (!data_return)
|
|
|
|
continue;
|
|
|
|
|
2012-08-09 11:09:42 +04:00
|
|
|
double version = PR_strtod((char*) data_return, nullptr);
|
2004-04-08 18:01:17 +04:00
|
|
|
XFree(data_return);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
if (!(version >= 5.1 && version < 6))
|
2005-04-04 23:08:55 +04:00
|
|
|
continue;
|
|
|
|
|
2004-04-08 18:01:17 +04:00
|
|
|
data_return = 0;
|
|
|
|
|
|
|
|
if (status != Success || type == None)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If someone passed in a program name, check it against this one
|
|
|
|
// unless it's "any" in which case, we don't care. If someone did
|
|
|
|
// pass in a program name and this window doesn't support that
|
|
|
|
// protocol, we don't include it in our list.
|
|
|
|
if (aProgram && strcmp(aProgram, "any")) {
|
|
|
|
status = XGetWindowProperty(mDisplay, w, mMozProgramAtom,
|
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
// If the return name is not the same as what someone passed in,
|
|
|
|
// we don't want this window.
|
|
|
|
if (data_return) {
|
|
|
|
if (strcmp(aProgram, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is actually the success condition.
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Doesn't support the protocol, even though the user
|
|
|
|
// requested it. So we're not going to use this window.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
const char *username;
|
|
|
|
if (aUsername) {
|
|
|
|
username = aUsername;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
username = PR_GetEnv("LOGNAME");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (username) {
|
|
|
|
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 aren't equal, we don't want this window.
|
|
|
|
if (strcmp(username, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if there's a profile name on this window. If
|
|
|
|
// there is, then we need to make sure it matches what someone
|
|
|
|
// passed in.
|
|
|
|
if (aProfile) {
|
|
|
|
status = XGetWindowProperty(mDisplay, w, mMozProfileAtom,
|
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
// If there's a profile compare it with what we have
|
|
|
|
if (data_return) {
|
|
|
|
// If the profiles aren't equal, we don't want this window.
|
|
|
|
if (strcmp(aProfile, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
// Check to see if the window supports the new command-line passing
|
|
|
|
// protocol, if that is requested.
|
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
// If we got this far, this is the best window. It passed
|
2004-04-08 18:01:17 +04:00
|
|
|
// all the tests.
|
|
|
|
bestWindow = w;
|
2008-12-04 19:09:53 +03:00
|
|
|
break;
|
2004-04-08 18:01:17 +04:00
|
|
|
}
|
|
|
|
|
2005-08-19 19:15:34 +04:00
|
|
|
if (kids)
|
|
|
|
XFree((char *) kids);
|
|
|
|
|
2004-04-08 18:01:17 +04:00
|
|
|
return bestWindow;
|
|
|
|
}
|
|
|
|
|
2000-10-20 09:10:43 +04:00
|
|
|
nsresult
|
|
|
|
XRemoteClient::FreeLock(Window aWindow)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
|
|
|
|
result = XGetWindowProperty(mDisplay, aWindow, mMozLockAtom,
|
2004-04-08 18:01:17 +04:00
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
True, /* atomic delete after */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2000-10-20 09:10:43 +04:00
|
|
|
if (result != Success) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2004-04-08 18:01:17 +04:00
|
|
|
("unable to read and delete " MOZILLA_LOCK_PROP
|
|
|
|
" property\n"));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
else if (!data || !*data){
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2004-04-08 18:01:17 +04:00
|
|
|
("invalid data on " MOZILLA_LOCK_PROP
|
|
|
|
" of window 0x%x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
2001-12-29 01:17:20 +03:00
|
|
|
else if (strcmp((char *)data, mLockData)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2004-04-08 18:01:17 +04:00
|
|
|
(MOZILLA_LOCK_PROP " was stolen! Expected \"%s\", saw \"%s\"!\n",
|
|
|
|
mLockData, data));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
2004-04-08 18:01:17 +04:00
|
|
|
XFree(data);
|
2000-10-20 09:10:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
/* like strcpy, but return the char after the final null */
|
|
|
|
static char*
|
2007-02-09 04:33:26 +03:00
|
|
|
estrcpy(const char* s, char* d)
|
2005-04-04 23:08:55 +04:00
|
|
|
{
|
|
|
|
while (*s)
|
|
|
|
*d++ = *s++;
|
|
|
|
|
|
|
|
*d++ = '\0';
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
XRemoteClient::DoSendCommandLine(Window aWindow, int32_t argc, char **argv,
|
2007-02-09 04:33:26 +03:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 10:19:26 +04:00
|
|
|
char **aResponse, bool *aDestroyed)
|
2005-04-04 23:08:55 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDestroyed = false;
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
char cwdbuf[MAX_PATH];
|
|
|
|
if (!getcwd(cwdbuf, MAX_PATH))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// the commandline property is constructed as an array of int32_t
|
2005-04-04 23:08:55 +04:00
|
|
|
// followed by a series of null-terminated strings:
|
|
|
|
//
|
|
|
|
// [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
|
|
|
|
// (offset is from the beginning of the buffer)
|
|
|
|
|
2007-02-09 04:33:26 +03:00
|
|
|
static char desktopStartupPrefix[] = " DESKTOP_STARTUP_ID=";
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t argvlen = strlen(cwdbuf);
|
2008-12-04 19:09:53 +03:00
|
|
|
for (int i = 0; i < argc; ++i) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = strlen(argv[i]);
|
2007-02-09 04:33:26 +03:00
|
|
|
if (i == 0 && aDesktopStartupID) {
|
|
|
|
len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
|
|
|
|
}
|
|
|
|
argvlen += len;
|
|
|
|
}
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* buffer = (int32_t*) malloc(argvlen + argc + 1 +
|
|
|
|
sizeof(int32_t) * (argc + 1));
|
2005-04-04 23:08:55 +04:00
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2005-12-26 06:10:35 +03:00
|
|
|
buffer[0] = TO_LITTLE_ENDIAN32(argc);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
char *bufend = (char*) (buffer + argc + 1);
|
|
|
|
|
|
|
|
bufend = estrcpy(cwdbuf, bufend);
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
2005-12-26 06:10:35 +03:00
|
|
|
buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer));
|
2005-04-04 23:08:55 +04:00
|
|
|
bufend = estrcpy(argv[i], bufend);
|
2007-02-09 04:33:26 +03:00
|
|
|
if (i == 0 && aDesktopStartupID) {
|
|
|
|
bufend = estrcpy(desktopStartupPrefix, bufend - 1);
|
|
|
|
bufend = estrcpy(aDesktopStartupID, bufend - 1);
|
|
|
|
}
|
2005-04-04 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_bsmedberg
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t debug_argc = TO_LITTLE_ENDIAN32(*buffer);
|
2005-04-04 23:08:55 +04:00
|
|
|
char *debug_workingdir = (char*) (buffer + argc + 1);
|
|
|
|
|
|
|
|
printf("Sending command line:\n"
|
|
|
|
" working dir: %s\n"
|
|
|
|
" argc:\t%i",
|
|
|
|
debug_workingdir,
|
|
|
|
debug_argc);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *debug_offset = buffer + 1;
|
2005-04-04 23:08:55 +04:00
|
|
|
for (int debug_i = 0; debug_i < debug_argc; ++debug_i)
|
|
|
|
printf(" argv[%i]:\t%s\n", debug_i,
|
2005-12-26 06:10:35 +03:00
|
|
|
((char*) buffer) + TO_LITTLE_ENDIAN32(debug_offset[debug_i]));
|
2005-04-04 23:08:55 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,
|
|
|
|
PropModeReplace, (unsigned char *) buffer,
|
|
|
|
bufend - ((char*) buffer));
|
2007-09-04 08:13:24 +04:00
|
|
|
free(buffer);
|
2005-04-04 23:08:55 +04:00
|
|
|
|
|
|
|
if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandLineAtom))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-04-04 23:08:55 +04:00
|
|
|
XRemoteClient::WaitForResponse(Window aWindow, char **aResponse,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aDestroyed, Atom aCommandAtom)
|
2005-04-04 23:08:55 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool done = false;
|
|
|
|
bool accepted = false;
|
2000-10-20 09:10:43 +04:00
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent (mDisplay, &event);
|
|
|
|
if (event.xany.type == DestroyNotify &&
|
2005-04-04 23:08:55 +04:00
|
|
|
event.xdestroywindow.window == aWindow) {
|
2000-10-20 09:10:43 +04:00
|
|
|
/* Print to warn user...*/
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("window 0x%x was destroyed.\n",
|
|
|
|
(unsigned int) aWindow));
|
2004-04-08 18:01:17 +04:00
|
|
|
*aResponse = strdup("Window was destroyed while reading response.");
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDestroyed = true;
|
|
|
|
return false;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
2005-04-04 23:08:55 +04:00
|
|
|
event.xproperty.state == PropertyNewValue &&
|
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.atom == mMozResponseAtom) {
|
2000-10-20 09:10:43 +04:00
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
Bool result;
|
|
|
|
result = XGetWindowProperty (mDisplay, aWindow, mMozResponseAtom,
|
2005-04-04 23:08:55 +04:00
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
True, /* atomic delete after */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2000-10-20 09:10:43 +04:00
|
|
|
if (result != Success) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("failed reading " MOZILLA_RESPONSE_PROP
|
|
|
|
" from window 0x%0x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
*aResponse = strdup("Internal error reading response from window.");
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
else if (!data || strlen((char *) data) < 5) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("invalid data on " MOZILLA_RESPONSE_PROP
|
|
|
|
" property of window 0x%0x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
*aResponse = strdup("Server returned invalid data in response.");
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
2005-04-04 23:08:55 +04:00
|
|
|
else if (*data == '1') { /* positive preliminary reply */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("%s\n", data + 4));
|
2005-04-04 23:08:55 +04:00
|
|
|
/* keep going */
|
2011-10-17 18:59:28 +04:00
|
|
|
done = false;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strncmp ((char *)data, "200", 3)) { /* positive completion */
|
2005-04-04 23:08:55 +04:00
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 18:59:28 +04:00
|
|
|
accepted = true;
|
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
else if (*data == '2') { /* positive completion */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("%s\n", data + 4));
|
2005-04-04 23:08:55 +04:00
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 18:59:28 +04:00
|
|
|
accepted = true;
|
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
else if (*data == '3') { /* positive intermediate reply */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("internal error: "
|
|
|
|
"server wants more information? (%s)\n",
|
|
|
|
data));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
else if (*data == '4' || /* transient negative completion */
|
|
|
|
*data == '5') { /* permanent negative completion */
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug, ("%s\n", data + 4));
|
2005-04-04 23:08:55 +04:00
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("unrecognised " MOZILLA_RESPONSE_PROP
|
|
|
|
" from window 0x%x: %s\n",
|
|
|
|
(unsigned int) aWindow, data));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
2005-04-04 23:08:55 +04:00
|
|
|
XFree(data);
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
2005-04-04 23:08:55 +04:00
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.state == PropertyDelete &&
|
|
|
|
event.xproperty.atom == aCommandAtom) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(sRemoteLm, LogLevel::Debug,
|
2005-04-04 23:08:55 +04:00
|
|
|
("(server 0x%x has accepted "
|
Bug 1080319 - Remove the -remote option. r=bsmedberg
The -remote option has existed essentially forever, but its usefulness is
questionable:
- It requires a running instance to be any useful, so any script actually
using it should first do -remote 'ping()' and handle the response properly.
- It is not cross-application. The remote service dispatches the -remote
commands to the command line handler, and, for example, desktop b2g builds
don't have handlers for -remote (although thunderbird and seamonkey do).
- It is not a cross-platform option, which leads to the following point:
- There are other command line ways to do the same thing (at least in
Firefox), without having to jump through hoops with -remote 'ping()',
because there are command line options to do those same things on non-X11
platforms.
For the latter, in Firefox case:
- -remote 'openURL(url)' can be replaced with firefox url
- -remote 'openURL(url,new-tab)' can be replaced with firefox -new-tab url
- -remote 'openURL(url,new-window)' can be replaced with firefox -new-window
url
- -remote 'openfile(file,...)' is the same as -remote 'openurl(file,...) so,
can be replaced as above
- -remote 'xfedocommand(openbrowser)' is inherited from the mozilla suite and
doesn't make much sense, but can be replaced with firefox -new-window
The interesting part is that without changing nsBrowserContentHandler.js,
-remote still works, meaning that if people really feel strongly about
-remote, they'll still be able to write an addon to bring it back. This also
means this patch actually doesn't remove -remote for applications other than
Firefox that do support it, although -remote 'ping()' doesn't work as
expected. However, other -remote commands will now work even without a
running instance.
2014-10-14 02:19:52 +04:00
|
|
|
MOZILLA_COMMANDLINE_PROP ".)\n",
|
2005-04-04 23:08:55 +04:00
|
|
|
(unsigned int) aWindow));
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-04 23:08:55 +04:00
|
|
|
return accepted;
|
2000-10-20 09:10:43 +04:00
|
|
|
}
|