mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 14:30:43 +00:00
Ongoing new X Remote Code. Not part of the build.
This commit is contained in:
parent
8e9cd9b510
commit
80efc3e4ee
30
xpfe/components/xremote/Makefile.in
Normal file
30
xpfe/components/xremote/Makefile.in
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# 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
|
||||
# <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
# are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
35
xpfe/components/xremote/public/Makefile.in
Normal file
35
xpfe/components/xremote/public/Makefile.in
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# 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
|
||||
# <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
# are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xremoteservice
|
||||
XPIDL_MODULE = xremoteservice
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIXRemoteService.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
54
xpfe/components/xremote/public/nsIXRemoteService.idl
Normal file
54
xpfe/components/xremote/public/nsIXRemoteService.idl
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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
|
||||
* <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
* are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* This interface provides the clue that allows you set up a specific
|
||||
* browser instance so that it will respond to X remote requests. */
|
||||
|
||||
interface nsIDOMWindowInternal;
|
||||
|
||||
[scriptable, uuid(510c0946-1dd2-11b2-b210-f5031abff3f0)]
|
||||
interface nsIXRemoteService : nsISupports {
|
||||
|
||||
// this is called once the browser starts up so that we can create a
|
||||
// dummy window to respond to requests on
|
||||
[noscript] void startup ();
|
||||
|
||||
// this is called right before shutdown so we can destroy the window
|
||||
// that we are receving requests on
|
||||
[noscript] void shutdown ();
|
||||
|
||||
// parse the command given and generate a response
|
||||
[noscript] void parseCommand (in string aCommand, out string aResponse);
|
||||
|
||||
// add a new browser instance to listen for remote requests on
|
||||
void addBrowserInstance (in nsIDOMWindowInternal aBrowser);
|
||||
|
||||
// remove a browser instance from the list to listen for requests on
|
||||
void removeBrowserInstance (in nsIDOMWindowInternal aBrowser);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IXREMOTESERVICE_CONTRACTID "@mozilla.org/browser/xremoteservice;1"
|
||||
#define NS_IXREMOTESERVICE_CLASSNAME "Mozilla XRemote Service"
|
||||
%}
|
||||
|
35
xpfe/components/xremote/src/Makefile.in
Normal file
35
xpfe/components/xremote/src/Makefile.in
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# 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
|
||||
# <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
# are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xremoteservice
|
||||
LIBRARY_NAME = xremoteservice
|
||||
EXPORT_LIBRARY = 1
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = XRemoteService.cpp
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
316
xpfe/components/xremote/src/XRemoteService.cpp
Normal file
316
xpfe/components/xremote/src/XRemoteService.cpp
Normal file
@ -0,0 +1,316 @@
|
||||
/*
|
||||
* 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
|
||||
* <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
* are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "XRemoteService.h"
|
||||
|
||||
#include <nsIGenericFactory.h>
|
||||
#include <nsIWebNavigation.h>
|
||||
#include <nsIDOMWindowInternal.h>
|
||||
#include <nsIDocShell.h>
|
||||
#include <nsIScriptGlobalObject.h>
|
||||
#include <nsIBaseWindow.h>
|
||||
#include <nsWidgetsCID.h>
|
||||
#include <nsIXRemoteWidgetHelper.h>
|
||||
#include <nsIServiceManager.h>
|
||||
#include <nsRect.h>
|
||||
#include <nsString.h>
|
||||
|
||||
NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID);
|
||||
|
||||
// protocol strings
|
||||
static char *s200ExecutedCommand = "200 executed command:";
|
||||
static char *s500ParseCommand = "500 command not parsable:";
|
||||
static char *s501UnrecognizedCommand = "501 unrecognized command:";
|
||||
// not using this yet...
|
||||
// static char *s502NoWindow = "502 no appropriate window for:";
|
||||
static char *s509InternalError = "509 internal error";
|
||||
|
||||
XRemoteService::XRemoteService()
|
||||
{
|
||||
printf("XRemoteService\n");
|
||||
NS_INIT_ISUPPORTS();
|
||||
mNumWindows = 0;
|
||||
}
|
||||
|
||||
XRemoteService::~XRemoteService()
|
||||
{
|
||||
printf("~XRemoteService\n");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(XRemoteService, nsIXRemoteService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
XRemoteService::Startup(void)
|
||||
{
|
||||
if (mNumWindows == 0)
|
||||
CreateProxyWindow();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XRemoteService::Shutdown(void)
|
||||
{
|
||||
DestroyProxyWindow();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XRemoteService::ParseCommand(const char *aCommand, char **aResponse)
|
||||
{
|
||||
printf("ParseCommand\n");
|
||||
if (!aCommand || !aResponse)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// is there no command?
|
||||
if (aCommand[0] == '\0') {
|
||||
*aResponse = nsCRT::strdup(s509InternalError);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aResponse = nsnull;
|
||||
|
||||
// begin our parse
|
||||
nsCString tempString;
|
||||
PRInt32 begin_arg = 0;
|
||||
PRInt32 end_arg = 0;
|
||||
|
||||
tempString.Append(aCommand);
|
||||
printf("raw data is %s\n", tempString.get());
|
||||
|
||||
// find the () in the command
|
||||
begin_arg = tempString.FindChar('(');
|
||||
end_arg = tempString.RFindChar(')');
|
||||
|
||||
printf("begin_arg is %d, end_arg is %d\n", begin_arg, end_arg);
|
||||
|
||||
// make sure that both were found, the string doesn't start with '('
|
||||
// and that the ')' follows the '('
|
||||
if (begin_arg == kNotFound || end_arg == kNotFound ||
|
||||
begin_arg == 0 || end_arg < begin_arg) {
|
||||
*aResponse = BuildResponse(s500ParseCommand, tempString.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// truncate the closing paren and anything following it
|
||||
tempString.Truncate(end_arg);
|
||||
|
||||
// save the argument and trim whitespace off of it
|
||||
nsCString argument;
|
||||
argument.Append(tempString);
|
||||
argument.Cut(0, begin_arg + 1);
|
||||
argument.Trim(" ", PR_TRUE, PR_TRUE);
|
||||
|
||||
// remove the argument
|
||||
tempString.Truncate(begin_arg);
|
||||
|
||||
// get the action, strip off whitespace and convert to lower case
|
||||
nsCString action;
|
||||
action.Append(tempString);
|
||||
action.Trim(" ", PR_TRUE, PR_TRUE);
|
||||
action.ToLowerCase();
|
||||
|
||||
printf("action %s argument\n", action.get(), argument.get());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XRemoteService::AddBrowserInstance(nsIDOMWindowInternal *aBrowser)
|
||||
{
|
||||
printf("AddBrowserInstance %p\n", (void *)aBrowser);
|
||||
|
||||
// get the native window for this instance
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObject;
|
||||
scriptObject = do_QueryInterface(aBrowser);
|
||||
if (!scriptObject) {
|
||||
NS_WARNING("Failed to get script object for browser instance");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptObject->GetDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) {
|
||||
NS_WARNING("Failed to get docshell object for browser instance");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow;
|
||||
baseWindow = do_QueryInterface(docShell);
|
||||
if (!baseWindow) {
|
||||
NS_WARNING("Failed to get base window for browser instance");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> mainWidget;
|
||||
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
|
||||
if (!mainWidget) {
|
||||
NS_WARNING("Failed to get main widget for browser instance");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
printf("widget is %p\n", (void *)mainWidget.get());
|
||||
|
||||
// walk up the widget tree and find the toplevel window in the
|
||||
// heirarchy
|
||||
|
||||
nsCOMPtr<nsIWidget> tempWidget;
|
||||
|
||||
tempWidget = getter_AddRefs(mainWidget->GetParent());
|
||||
|
||||
while (tempWidget) {
|
||||
tempWidget = getter_AddRefs(tempWidget->GetParent());
|
||||
if (tempWidget)
|
||||
mainWidget = tempWidget;
|
||||
}
|
||||
|
||||
// Tell the widget code to set up X remote for this window
|
||||
nsCOMPtr<nsIXRemoteWidgetHelper> widgetHelper =
|
||||
do_GetService(NS_IXREMOTEWIDGETHELPER_CONTRACTID);
|
||||
if (!widgetHelper) {
|
||||
NS_WARNING("couldn't get widget helper service");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
rv = widgetHelper->EnableXRemoteCommands(mainWidget);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("failed to enable x remote commands for widget");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// It's assumed that someone will call RemoveBrowserInstance before
|
||||
// this DOM window is destroyed so we don't addref or release or
|
||||
// keep a weak ptr or anything.
|
||||
nsVoidKey *key;
|
||||
key = new nsVoidKey (mainWidget.get());
|
||||
mWindowList.Put(key, aBrowser);
|
||||
delete key;
|
||||
|
||||
// ...and the reverse lookup
|
||||
key = new nsVoidKey (aBrowser);
|
||||
mBrowserList.Put(key, mainWidget.get());
|
||||
delete key;
|
||||
|
||||
// now that we have a real browser window listening to requests
|
||||
// destroy the proxy window.
|
||||
DestroyProxyWindow();
|
||||
mNumWindows++;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XRemoteService::RemoveBrowserInstance(nsIDOMWindowInternal *aBrowser)
|
||||
{
|
||||
printf("RemoveBrowserInstance\n");
|
||||
mNumWindows--;
|
||||
if (mNumWindows == 0)
|
||||
CreateProxyWindow();
|
||||
|
||||
// remove our keys
|
||||
nsVoidKey *key;
|
||||
key = new nsVoidKey(aBrowser);
|
||||
nsIWidget *widget = NS_STATIC_CAST(nsIWidget *,
|
||||
mBrowserList.Remove(key));
|
||||
delete key;
|
||||
|
||||
key = new nsVoidKey(widget);
|
||||
mWindowList.Remove(key);
|
||||
delete key;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char *
|
||||
XRemoteService::BuildResponse(const char *aError, const char *aMessage)
|
||||
{
|
||||
nsCString retvalString;
|
||||
char *retval;
|
||||
|
||||
// check to make sure that we have the minimum for allocating this
|
||||
// buffer
|
||||
if (!aError || !aMessage)
|
||||
return nsnull;
|
||||
|
||||
retvalString.Append(aError);
|
||||
retvalString.Append(" ");
|
||||
retvalString.Append(aMessage);
|
||||
|
||||
retval = retvalString.ToNewCString();
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
XRemoteService::CreateProxyWindow(void)
|
||||
{
|
||||
if (mProxyWindow)
|
||||
return;
|
||||
|
||||
mProxyWindow = do_CreateInstance(kWindowCID);
|
||||
if (!mProxyWindow)
|
||||
return;
|
||||
|
||||
nsWidgetInitData initData;
|
||||
initData.mWindowType = eWindowType_toplevel;
|
||||
|
||||
// create the window as a new toplevel
|
||||
nsRect rect(0,0,100,100);
|
||||
mProxyWindow->Create(NS_STATIC_CAST(nsIWidget *, nsnull),
|
||||
rect,
|
||||
nsnull, nsnull, nsnull, nsnull,
|
||||
&initData);
|
||||
|
||||
// Tell the widget code to set up X remote for this window
|
||||
nsCOMPtr<nsIXRemoteWidgetHelper> widgetHelper =
|
||||
do_GetService(NS_IXREMOTEWIDGETHELPER_CONTRACTID);
|
||||
if (!widgetHelper) {
|
||||
NS_WARNING("couldn't get widget helper service");
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
rv = widgetHelper->EnableXRemoteCommands(mProxyWindow);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("failed to enable x remote commands for proxy window");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
XRemoteService::DestroyProxyWindow(void)
|
||||
{
|
||||
if (!mProxyWindow)
|
||||
return;
|
||||
|
||||
mProxyWindow->Destroy();
|
||||
mProxyWindow = nsnull;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(XRemoteService)
|
||||
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ NS_IXREMOTESERVICE_CLASSNAME,
|
||||
NS_XREMOTESERVICE_CID,
|
||||
NS_IXREMOTESERVICE_CONTRACTID,
|
||||
XRemoteServiceConstructor }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(XRemoteServiceModule, components);
|
63
xpfe/components/xremote/src/XRemoteService.h
Normal file
63
xpfe/components/xremote/src/XRemoteService.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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
|
||||
* <blizzard@mozilla.org>. Portions created by Christopher Blizzard
|
||||
* are Copyright (C) Christopher Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include <nsIXRemoteService.h>
|
||||
#include <nsHashtable.h>
|
||||
#include <nsIWidget.h>
|
||||
#include <nsCOMPtr.h>
|
||||
|
||||
// {3dfe7324-1dd2-11b2-9ff2-8853f91e8a20}
|
||||
|
||||
#define NS_XREMOTESERVICE_CID \
|
||||
{ 0x3dfe7324, 0x1dd2, 0x11b2, \
|
||||
{ 0x9f, 0xf2, 0x88, 0x53, 0xf9, 0x1e, 0x8a, 0x20 } }
|
||||
|
||||
class XRemoteService : public nsIXRemoteService {
|
||||
public:
|
||||
XRemoteService();
|
||||
virtual ~XRemoteService();
|
||||
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_XREMOTESERVICE_CID);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIXREMOTESERVICE
|
||||
|
||||
private:
|
||||
|
||||
// this builds a response for any parsing
|
||||
char *BuildResponse(const char *aError, const char *aMessage);
|
||||
|
||||
// create and destroy the proxy window
|
||||
void CreateProxyWindow();
|
||||
void DestroyProxyWindow();
|
||||
|
||||
// hidden window for proxy requests
|
||||
nsCOMPtr<nsIWidget> mProxyWindow;
|
||||
|
||||
// native window to internal dom window map
|
||||
nsHashtable mWindowList;
|
||||
// internal dom window to native window map
|
||||
nsHashtable mBrowserList;
|
||||
|
||||
// the number of non-proxy windows that are set up for X Remote
|
||||
PRUint32 mNumWindows;
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user