See bugzilla bug 280725. Changes were made to the xremote mechanism to move it out of the os-specific widget code and into the more generic command line code in the toolkit. This bug implements the corresponding changes for the QNX Neutrino Mozilla based browser: 1) The xremote related code is removed from widget/src/photon/. 2) The nsPhMozRemoteHelper.* source files removed in step 1 are renamed to nsPhRemoteService.* and modified to work under toolkit/components/remote/. 3) Finally the photon specific code in widget/src/xremoteclient is modified so that the mozilla-xremote-client utility works as it did before. These changes are all Neutrino-only and should not affect any other platform, and in theory cannot bust any Tinderbox builds. p=407800 r=bsmedberg

This commit is contained in:
maxf@magma.ca 2007-12-18 14:00:51 -08:00
parent 13991274ed
commit aaf51b348f
7 changed files with 251 additions and 53 deletions

View File

@ -74,7 +74,7 @@ CPPSRCS += nsGTKRemoteService.cpp
endif
ifeq (photon,$(MOZ_WIDGET_TOOLKIT))
CPPSRCS += nsPhMozRemoteHelper.cpp
CPPSRCS += nsPhRemoteService.cpp
endif
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,193 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Adrian Mardare <amardare@qnx.com>
* Max Feil <mfeil@qnx.com>
*/
#include <stdlib.h>
#include <nsIWidget.h>
#include <nsCOMPtr.h>
#include "nsIGenericFactory.h"
#include "nsPhRemoteService.h"
#include "nsIServiceManager.h"
#include "nsCRT.h"
#ifdef MOZ_XUL_APP
#include "nsICommandLineRunner.h"
#include "nsXULAppAPI.h"
#else
#include "nsISuiteRemoteService.h"
#endif
#include <Pt.h>
NS_IMPL_QUERY_INTERFACE2(nsPhRemoteService,
nsIRemoteService,
nsIObserver)
NS_IMETHODIMP_(nsrefcnt)
nsPhRemoteService::AddRef()
{
return 1;
}
NS_IMETHODIMP_(nsrefcnt)
nsPhRemoteService::Release()
{
return 1;
}
NS_IMETHODIMP
nsPhRemoteService::Startup(const char* aAppName, const char* aProfileName)
{
NS_ASSERTION(aAppName, "Don't pass a null appname!");
if (mIsInitialized)
return NS_ERROR_ALREADY_INITIALIZED;
mIsInitialized = PR_TRUE;
mAppName = aAppName;
ToLowerCase(mAppName);
HandleCommandsFor(nsnull, nsnull);
return NS_OK;
}
NS_IMETHODIMP
nsPhRemoteService::RegisterWindow(nsIDOMWindow* aWindow)
{
return NS_OK;
}
NS_IMETHODIMP
nsPhRemoteService::Shutdown()
{
if (!mIsInitialized)
return NS_ERROR_NOT_INITIALIZED;
mIsInitialized = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsPhRemoteService::Observe(nsISupports* aSubject,
const char *aTopic,
const PRUnichar *aData)
{
// This can be xpcom-shutdown or quit-application, but it's the same either
// way.
Shutdown();
return NS_OK;
}
#define MOZ_REMOTE_MSG_TYPE 100
static void const * RemoteMsgHandler( PtConnectionServer_t *connection, void *user_data,
unsigned long type, void const *msg, unsigned len, unsigned *reply_len )
{
nsresult rv;
if( type != MOZ_REMOTE_MSG_TYPE ) return NULL;
/* we are given strings and we reply with strings */
char *response = NULL;
// parse the command
nsCOMPtr<nsICommandLineRunner> cmdline
(do_CreateInstance("@mozilla.org/toolkit/command-line;1", &rv));
if (!NS_FAILED(rv)) {
// 1) Make sure that it looks remotely valid with parens
// 2) Treat ping() immediately and specially
nsCAutoString command((char *)msg);
PRInt32 p1, p2;
p1 = command.FindChar('(');
p2 = command.FindChar(')');
if (p1 != kNotFound && p2 != kNotFound && p1 != 0 && p2 >= p1) {
command.Truncate(p1);
command.Trim(" ", PR_TRUE, PR_TRUE);
ToLowerCase(command);
//printf("Processing xremote command: %s\n", command.get());
if (!command.EqualsLiteral("ping")) {
char* argv[3] = {"dummyappname", "-remote", (char *)msg};
rv = cmdline->Init(3, argv, nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
if (!NS_FAILED(rv)) {
rv = cmdline->Run();
if (NS_ERROR_ABORT == rv)
response = "500 command not parseable";
if (NS_FAILED(rv))
response = "509 internal error";
} else
response = "509 internal error";
}
} else
response = "500 command not parseable";
} else
response = "509 internal error";
PtConnectionReply( connection, response ? strlen(response) : 0, response );
return ( void * ) 1; /* return any non NULL value to indicate we handled the message */
}
static void client_connect( PtConnector_t *cntr, PtConnectionServer_t *csrvr, void *data )
{
static PtConnectionMsgHandler_t handlers[] = { { 0, RemoteMsgHandler } };
PtConnectionAddMsgHandlers( csrvr, handlers, sizeof(handlers)/sizeof(handlers[0]) );
}
void
nsPhRemoteService::HandleCommandsFor( nsIWidget *aWidget, nsIWeakReference* aWindow )
{
static PRBool ConnectorCreated = PR_FALSE;
///* ATENTIE */ printf( "aProgram=%s aProfile=%s aWidget=%p\n", aProgram?aProgram:"NULL", aProfile?aProfile:"NULL", aWidget );
if( !ConnectorCreated ) {
char RemoteServerName[128];
sprintf( RemoteServerName, "%s_RemoteServer", (char *) mAppName.get() );
/* create a connector for the remote control */
PtConnectorCreate( RemoteServerName, client_connect, NULL );
ConnectorCreated = PR_TRUE;
}
return;
}
// {C0773E90-5799-4eff-AD03-3EBCD85624AC}
#define NS_REMOTESERVICE_CID \
{ 0xc0773e90, 0x5799, 0x4eff, { 0xad, 0x3, 0x3e, 0xbc, 0xd8, 0x56, 0x24, 0xac } }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPhRemoteService)
static const nsModuleComponentInfo components[] =
{
{ "Remote Service",
NS_REMOTESERVICE_CID,
"@mozilla.org/toolkit/remote-service;1",
nsPhRemoteServiceConstructor
}
};
NS_IMPL_NSGETMODULE(RemoteServiceModule, components)

View File

@ -14,12 +14,13 @@
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard.
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adrian Mardare <amaradre@qnx.com>
* Adrian Mardare <amardare@qnx.com>
* Max Feil <mfeil@qnx.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -35,25 +36,34 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef __nsPhMozRemoteHelper_h__
#define __nsPhMozRemoteHelper_h__
#ifndef __nsPhRemoteService_h__
#define __nsPhRemoteService_h__
#include <nsIXRemoteWidgetHelper.h>
#include "nsIRemoteService.h"
#include "nsIObserver.h"
#include "nsString.h"
// {84f94aac-1dd2-11b2-a05f-9b338fea662c}
#define NS_PHXREMOTEWIDGETHELPER_CID \
{ 0x84f94aac, 0x1dd2, 0x11b2, \
{ 0xa0, 0x5f, 0x9b, 0x33, 0x8f, 0xea, 0x66, 0x2c } }
class nsPhXRemoteWidgetHelper : public nsIXRemoteWidgetHelper {
public:
nsPhXRemoteWidgetHelper();
virtual ~nsPhXRemoteWidgetHelper();
class nsIWeakReference;
class nsPhRemoteService : public nsIRemoteService,
public nsIObserver
{
public:
// We will be a static singleton, so don't use the ordinary methods.
NS_DECL_ISUPPORTS
NS_DECL_NSIREMOTESERVICE
NS_DECL_NSIOBSERVER
nsPhRemoteService() { mIsInitialized = PR_FALSE; }
private:
~nsPhRemoteService() { }
void HandleCommandsFor(nsIWidget *aWidget,
nsIWeakReference* aWindow);
PRBool mIsInitialized;
nsCString mAppName;
NS_IMETHOD EnableXRemoteCommands( nsIWidget *aWidget, const char *aProfile, const char *aProgram );
};
#endif /* __nsPhMozRemoteHelper_h__ */
#endif /* __nsPhRemoteService_h__ */

View File

@ -80,11 +80,6 @@ CPPSRCS = \
nsSound.cpp \
$(NULL)
ifdef MOZ_ENABLE_XREMOTE
REQUIRES += xremoteservice
CPPSRCS += nsPhMozRemoteHelper.cpp
endif
# always include the PHOTON_DND in the build - the bookmarks in firefox require it
PHOTON_DND=1
ifdef PHOTON_DND

View File

@ -58,10 +58,6 @@
#include "nsBidiKeyboard.h"
#endif
#ifdef MOZ_ENABLE_XREMOTE
#include "nsPhMozRemoteHelper.h"
#endif
#include "nsFilePicker.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
@ -79,10 +75,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
#ifdef MOZ_ENABLE_XREMOTE
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPhXRemoteWidgetHelper)
#endif
#ifdef IBMBIDI
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
#endif
@ -142,13 +134,6 @@ static nsModuleComponentInfo components[] =
nsBidiKeyboardConstructor },
#endif // IBMBIDI
#ifdef MOZ_ENABLE_XREMOTE
{ NS_IXREMOTEWIDGETHELPER_CLASSNAME,
NS_PHXREMOTEWIDGETHELPER_CID,
NS_IXREMOTEWIDGETHELPER_CONTRACTID,
nsPhXRemoteWidgetHelperConstructor },
#endif
{ "Photon File Picker",
NS_FILEPICKER_CID,
"@mozilla.org/filepicker;1",

View File

@ -63,9 +63,7 @@ XRemoteClient::~XRemoteClient()
Shutdown();
}
NS_IMPL_ISUPPORTS1(XRemoteClient, nsIXRemoteClient)
NS_IMETHODIMP
nsresult
XRemoteClient::Init (void)
{
@ -80,9 +78,10 @@ XRemoteClient::Init (void)
return NS_OK;
}
NS_IMETHODIMP
nsresult
XRemoteClient::SendCommand (const char *aProgram, const char *aUsername,
const char *aProfile, const char *aCommand,
const char* aDesktopStartupID,
char **aResponse, PRBool *aWindowFound)
{
*aWindowFound = PR_TRUE;
@ -104,15 +103,25 @@ XRemoteClient::SendCommand (const char *aProgram, const char *aUsername,
return NS_OK;
}
NS_IMETHODIMP
nsresult
XRemoteClient::SendCommandLine (const char *aProgram, const char *aUsername,
const char *aProfile,
PRInt32 argc, char **argv,
const char* aDesktopStartupID,
char **aResponse, PRBool *aWindowFound)
{
return NS_ERROR_FAILURE;
}
void
XRemoteClient::Shutdown (void)
{
if (!mInitialized)
return NS_OK;
return;
// shut everything down
mInitialized = PR_FALSE;
return NS_OK;
return;
}

View File

@ -36,19 +36,25 @@
* ***** END LICENSE BLOCK ***** */
#include "nsIXRemoteClient.h"
#include "nsRemoteClient.h"
class XRemoteClient : public nsIXRemoteClient
class XRemoteClient : public nsRemoteClient
{
public:
XRemoteClient();
virtual ~XRemoteClient();
~XRemoteClient();
// nsISupports
NS_DECL_ISUPPORTS
// nsIXRemoteClient
NS_DECL_NSIXREMOTECLIENT
virtual nsresult Init();
virtual nsresult SendCommand(const char *aProgram, const char *aUsername,
const char *aProfile, const char *aCommand,
const char* aDesktopStartupID,
char **aResponse, PRBool *aSucceeded);
virtual nsresult SendCommandLine(const char *aProgram, const char *aUsername,
const char *aProfile,
PRInt32 argc, char **argv,
const char* aDesktopStartupID,
char **aResponse, PRBool *aSucceeded);
void Shutdown();
private:
PRBool mInitialized;