Attached is a patch for discussion. It doesn't work, but I'm not entirely sure why. The earlier Gtk-VNC plugin works, and this code does basically the same thing but doesn't work. It connects to the VNC server, gets framebuffer updates and everything, it just doesn't draw anything -- I'm sure it's something very simple.
Anyway ...The idea is that you can put the following code into your web page, and that will display the corresponding console:
<embed type="application/x-virt-viewer"
width="900"
height="700"
uri="qemu:///system"
name="1"
waitvnc="1">
</embed>
The full parameters are uri & name (required), waitvnc & direct (optional).
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
diff -r fe1efb558b4b .hgignore
--- a/.hgignore Fri Jan 11 17:43:30 2008 -0500
+++ b/.hgignore Fri Jan 25 15:22:49 2008 +0000
@@ -6,3 +6,8 @@ Makefile\.in$
^config\.guess$
^config\.sub$
^configure$
+^compile$
+^depcomp$
+^install-sh$
+^ltmain.sh$
+^missing$
diff -r fe1efb558b4b Makefile.am
--- a/Makefile.am Fri Jan 11 17:43:30 2008 -0500
+++ b/Makefile.am Fri Jan 25 15:22:49 2008 +0000
@@ -1,5 +1,5 @@
-SUBDIRS = src man
+SUBDIRS = src man plugin
EXTRA_DIST = @[EMAIL PROTECTED]
diff -r fe1efb558b4b autogen.sh
--- a/autogen.sh Fri Jan 11 17:43:30 2008 -0500
+++ b/autogen.sh Fri Jan 25 15:22:49 2008 +0000
@@ -36,6 +36,7 @@ if test -z "$*"; then
echo "the $0 command line."
fi
+libtoolize --copy --force
aclocal
automake --add-missing
autoconf
diff -r fe1efb558b4b configure.ac
--- a/configure.ac Fri Jan 11 17:43:30 2008 -0500
+++ b/configure.ac Fri Jan 25 15:22:49 2008 +0000
@@ -2,6 +2,8 @@ AM_INIT_AUTOMAKE(virt-viewer, 0.0.2)
AM_INIT_AUTOMAKE(virt-viewer, 0.0.2)
AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
VIRT_VIEWER_COMPILE_WARNINGS(maximum)
@@ -10,7 +12,25 @@ PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.2.
PKG_CHECK_MODULES(GTK2, gtk+-2.0 >= 2.2.0)
PKG_CHECK_MODULES(GTKVNC, gtk-vnc-1.0 >= 0.0.1)
+dnl --enable-plugin to enable the browser plugin.
+NSPR_REQUIRED=4.0.0
+FIREFOX_PLUGIN_REQUIRED=2.0.0
+AC_ARG_ENABLE(plugin,
+ [ --enable-plugin=[no/yes] enable browser plugin [default=no]],,
+ enable_plugin=no)
+if test "x$enable_plugin" = "xyes"; then
+ dnl Check for Netscape Portable Runtime development package.
+ PKG_CHECK_MODULES(NSPR, nspr >= $NSPR_REQUIRED)
+ dnl Check for Firefox plugin package (also includes NSPR cflags/libs).
+ PKG_CHECK_MODULES(FIREFOX_PLUGIN,
+ firefox-plugin >= $FIREFOX_PLUGIN_REQUIRED)
+ AC_SUBST(FIREFOX_PLUGIN_CFLAGS)
+ AC_SUBST(FIREFOX_PLUGIN_LIBS)
+fi
+AM_CONDITIONAL(ENABLE_PLUGIN, [test "x$enable_plugin" = "xyes"])
+
AC_OUTPUT(Makefile
src/Makefile
man/Makefile
+ plugin/Makefile
virt-viewer.spec)
diff -r fe1efb558b4b plugin/Makefile.am
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/Makefile.am Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,35 @@
+if ENABLE_PLUGIN
+
+plugindir = $(libdir)/mozilla/plugins
+plugin_LTLIBRARIES = virt-viewer-plugin.la
+
+virt_viewer_plugin_la_SOURCES = \
+ ../src/main.c ../src/viewer.h \
+ virt-viewer-plugin.c virt-viewer-plugin.h \
+ npshell.c npunix.c
+virt_viewer_plugin_la_LIBADD = \
+ @FIREFOX_PLUGIN_LIBS@ \
+ @GTKVNC_LIBS@ @GTK2_LIBS@ @LIBXML2_LIBS@ @LIBVIRT_LIBS@
+virt_viewer_plugin_la_LDFLAGS = \
+ -module -avoid-version
+virt_viewer_plugin_la_CFLAGS = \
+ -DPLUGIN=1 -DENABLE_DEBUG=1 -DDEBUG=1 \
+ @FIREFOX_PLUGIN_CFLAGS@ \
+ @GTKVNC_CFLAGS@ @GTK2_CFLAGS@ @LIBXML2_CFLAGS@ @LIBVIRT_CFLAGS@ \
+ @WARN_CFLAGS@ \
+ -I$(top_srcdir)/src
+
+all-local: virt-viewer-plugin.so
+
+virt-viewer-plugin.so: virt-viewer-plugin.la
+ cp .libs/virt-viewer-plugin.so $@
+
+# Only leave the .so file in the plugins directory.
+install-data-hook:
+ rm -f $(plugindir)/virt-viewer-plugin.a $(plugindir)/virt-viewer-plugin.la
+
+EXTRA_DIST = README
+
+CLEANFILES = virt-viewer-plugin.so
+
+endif
diff -r fe1efb558b4b plugin/npshell.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/npshell.c Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,388 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * 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
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Stephen Mak <[EMAIL PROTECTED]>
+ *
+ * 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
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * npshell.c
+ *
+ * Netscape Client Plugin API
+ * - Function that need to be implemented by plugin developers
+ *
+ * This file defines a "shell" plugin that plugin developers can use
+ * as the basis for a real plugin. This shell just provides empty
+ * implementations of all functions that the plugin can implement
+ * that will be called by Netscape (the NPP_xxx methods defined in
+ * npapi.h).
+ *
+ * dp Suresh <[EMAIL PROTECTED]>
+ * updated 5/1998 <[EMAIL PROTECTED]>
+ * updated 9/2000 <[EMAIL PROTECTED]>
+ *
+ */
+
+
+/*
+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 stub code that defines the binary interface to a Mozilla
+plugin.
+
+The Initial Developer of the Original Code is Mozilla.
+
+Portions created by Adobe Systems Incorporated are Copyright (C) 2007. All Rights Reserved.
+
+Contributor(s): Adobe Systems Incorporated.
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <npapi.h>
+#include <npupp.h>
+
+#include "virt-viewer-plugin.h"
+
+/***********************************************************************
+ *
+ * Implementations of plugin API functions
+ *
+ ***********************************************************************/
+
+char *
+NPP_GetMIMEDescription(void)
+{
+ return (char *) MIME_TYPES_HANDLED;
+}
+
+NPError
+NPP_GetValue(NPP instance G_GNUC_UNUSED, NPPVariable variable, void *value)
+{
+ NPError err = NPERR_NO_ERROR;
+
+ debug ("NPP_GetValue %d", variable);
+
+ switch (variable) {
+ case NPPVpluginNameString:
+ *((const char **)value) = PLUGIN_NAME;
+ break;
+ case NPPVpluginDescriptionString:
+ *((const char **)value) = PLUGIN_DESCRIPTION;
+ break;
+ case NPPVpluginNeedsXEmbed:
+ *((PRBool *)value) = PR_TRUE;
+ break;
+ default:
+ err = NPERR_GENERIC_ERROR;
+ }
+ return err;
+}
+
+NPError
+NPP_Initialize(void)
+{
+ debug ("NPP_Initialize");
+
+ gtk_init(0, 0);
+
+ return NPERR_NO_ERROR;
+}
+
+#ifdef OJI
+jref
+NPP_GetJavaClass()
+{
+ return NULL;
+}
+#endif
+
+void
+NPP_Shutdown(void)
+{
+ debug ("NPP_Shutdown");
+}
+
+NPError
+NPP_New(NPMIMEType pluginType G_GNUC_UNUSED,
+ NPP instance,
+ uint16 mode,
+ int16 argc,
+ char* argn[],
+ char* argv[],
+ NPSavedData *saved G_GNUC_UNUSED)
+{
+ PluginInstance *This;
+ NPError err = NPERR_NO_ERROR;
+ PRBool supportsXEmbed = PR_FALSE;
+ NPNToolkitType toolkit = 0;
+ int i;
+
+ debug ("NPP_New");
+
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ /* http://developer.mozilla.org/en/docs/XEmbed_Extension_for_Mozilla_Plugins
+ * Check for XEmbed and Gtk toolkit.
+ */
+ err = NPN_GetValue (instance,
+ NPNVSupportsXEmbedBool,
+ (void *)&supportsXEmbed);
+ if (err != NPERR_NO_ERROR || supportsXEmbed != PR_TRUE)
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+
+#if 1
+ err = NPN_GetValue (instance,
+ NPNVToolkit,
+ (void *)&toolkit);
+ if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+#endif
+
+ instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
+
+ This = (PluginInstance*) instance->pdata;
+
+ if (This == NULL) {
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ }
+
+ memset(This, 0, sizeof(PluginInstance));
+
+ /* Mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h). */
+ This->mode = mode;
+ This->instance = instance;
+ This->uri = This->name = NULL;
+ This->direct = This->waitvnc = 0;
+
+ /* Read the parameters passed to the plugin. */
+ for (i = 0; i < argc; i++)
+ {
+ if (strcasecmp (argn[i], "uri") == 0)
+ This->uri = strdup (argv[i]);
+ else if (strcasecmp (argn[i], "name") == 0)
+ This->name = strdup (argv[i]);
+ else if (strcasecmp (argn[i], "direct") == 0)
+ This->direct = strcmp (argv[i], "1") == 0;
+ else if (strcasecmp (argn[i], "waitvnc") == 0)
+ This->waitvnc = strcmp (argv[i], "1") == 0;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+NPError
+NPP_Destroy(NPP instance, NPSavedData** save G_GNUC_UNUSED)
+{
+ PluginInstance* This;
+
+ debug ("NPP_Destroy");
+
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ This = (PluginInstance*) instance->pdata;
+
+ if (This != NULL)
+ {
+ (void) VirtViewerDestroyWindow (instance);
+ if (This->uri) free (This->uri);
+ if (This->name) free (This->name);
+ NPN_MemFree(instance->pdata);
+ instance->pdata = NULL;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+
+NPError
+NPP_SetWindow(NPP instance, NPWindow* window)
+{
+ debug ("NPP_SetWindow");
+
+ return VirtViewerXSetWindow(instance, window);
+}
+
+int32
+NPP_WriteReady(NPP instance, NPStream *stream)
+{
+ /*printf("NPP_WriteReady()\n");*/
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ /* We don't want any data, kill the stream */
+ NPN_DestroyStream(instance, stream, NPRES_DONE);
+
+ /* Number of bytes ready to accept in NPP_Write() */
+ return -1L; /* don't accept any bytes in NPP_Write() */
+}
+
+int32
+NPP_Write(NPP instance, NPStream *stream,
+ int32 offset G_GNUC_UNUSED, int32 len G_GNUC_UNUSED,
+ void *buffer G_GNUC_UNUSED)
+{
+ /*printf("NPP_Write()\n");*/
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ /* We don't want any data, kill the stream */
+ NPN_DestroyStream(instance, stream, NPRES_DONE);
+
+ return -1L; /* don't accept any bytes in NPP_Write() */
+}
+
+NPError
+NPP_DestroyStream(NPP instance, NPStream *stream G_GNUC_UNUSED,
+ NPError reason G_GNUC_UNUSED)
+{
+ /*printf("NPP_DestroyStream()\n");*/
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ /***** Insert NPP_DestroyStream code here *****\
+ PluginInstance* This;
+ This = (PluginInstance*) instance->pdata;
+ \**********************************************/
+
+ return NPERR_NO_ERROR;
+}
+
+void
+NPP_StreamAsFile(NPP instance G_GNUC_UNUSED, NPStream *stream G_GNUC_UNUSED,
+ const char* fname G_GNUC_UNUSED)
+{
+ /*printf("NPP_StreamAsFile()\n");*/
+ /***** Insert NPP_StreamAsFile code here *****\
+ PluginInstance* This;
+ if (instance != NULL)
+ This = (PluginInstance*) instance->pdata;
+ \*********************************************/
+}
+
+void
+NPP_URLNotify(NPP instance G_GNUC_UNUSED, const char* url G_GNUC_UNUSED,
+ NPReason reason G_GNUC_UNUSED, void* notifyData G_GNUC_UNUSED)
+{
+ /*printf("NPP_URLNotify()\n");*/
+ /***** Insert NPP_URLNotify code here *****\
+ PluginInstance* This;
+ if (instance != NULL)
+ This = (PluginInstance*) instance->pdata;
+ \*********************************************/
+}
+
+
+void
+NPP_Print(NPP instance, NPPrint* printInfo)
+{
+ /*printf("NPP_Print()\n");*/
+ if(printInfo == NULL)
+ return;
+
+ if (instance != NULL) {
+ /***** Insert NPP_Print code here *****\
+ PluginInstance* This = (PluginInstance*) instance->pdata;
+ \**************************************/
+
+ if (printInfo->mode == NP_FULL) {
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin would like to take over
+ * printing completely when it is in full-screen mode,
+ * set printInfo->pluginPrinted to TRUE and print your
+ * plugin as you see fit. If your plugin wants Netscape
+ * to handle printing in this case, set
+ * printInfo->pluginPrinted to FALSE (the default) and
+ * do nothing. If you do want to handle printing
+ * yourself, printOne is true if the print button
+ * (as opposed to the print menu) was clicked.
+ * On the Macintosh, platformPrint is a THPrint; on
+ * Windows, platformPrint is a structure
+ * (defined in npapi.h) containing the printer name, port,
+ * etc.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ void* platformPrint =
+ printInfo->print.fullPrint.platformPrint;
+ NPBool printOne =
+ printInfo->print.fullPrint.printOne;
+ \**************************************/
+
+ /* Do the default*/
+ printInfo->print.fullPrint.pluginPrinted = FALSE;
+ }
+ else { /* If not fullscreen, we must be embedded */
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin is embedded, or is full-screen
+ * but you returned false in pluginPrinted above, NPP_Print
+ * will be called with mode == NP_EMBED. The NPWindow
+ * in the printInfo gives the location and dimensions of
+ * the embedded plugin on the printed page. On the
+ * Macintosh, platformPrint is the printer port; on
+ * Windows, platformPrint is the handle to the printing
+ * device context.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ NPWindow* printWindow =
+ &(printInfo->print.embedPrint.window);
+ void* platformPrint =
+ printInfo->print.embedPrint.platformPrint;
+ \**************************************/
+ }
+ }
+}
+
+int16 NPP_HandleEvent(NPP instance, void* event)
+{
+ /*printf("NPP_HandleEvent()\n");*/
+
+ return VirtViewerXHandleEvent(instance, event);
+}
diff -r fe1efb558b4b plugin/npunix.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/npunix.c Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,537 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * 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
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Stephen Mak <[EMAIL PROTECTED]>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * npunix.c
+ *
+ * Netscape Client Plugin API
+ * - Wrapper function to interface with the Netscape Navigator
+ *
+ * dp Suresh <[EMAIL PROTECTED]>
+ *
+ *----------------------------------------------------------------------
+ * PLUGIN DEVELOPERS:
+ * YOU WILL NOT NEED TO EDIT THIS FILE.
+ *----------------------------------------------------------------------
+ */
+
+#define XP_UNIX 1
+
+#include <stdio.h>
+#include <npapi.h>
+#include <npupp.h>
+
+#include <glib.h> /* just for G_GNUC_UNUSED */
+
+/*
+ * Define PLUGIN_TRACE to have the wrapper functions print
+ * messages to stderr whenever they are called.
+ */
+
+#ifdef PLUGIN_TRACE
+#include <stdio.h>
+#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
+#else
+#define PLUGINDEBUGSTR(msg)
+#endif
+
+
+/***********************************************************************
+ *
+ * Globals
+ *
+ ***********************************************************************/
+
+static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
+
+
+/***********************************************************************
+ *
+ * Wrapper functions : plugin calling Netscape Navigator
+ *
+ * These functions let the plugin developer just call the APIs
+ * as documented and defined in npapi.h, without needing to know
+ * about the function table and call macros in npupp.h.
+ *
+ ***********************************************************************/
+
+void
+NPN_Version(int* plugin_major, int* plugin_minor,
+ int* netscape_major, int* netscape_minor)
+{
+ *plugin_major = NP_VERSION_MAJOR;
+ *plugin_minor = NP_VERSION_MINOR;
+
+ /* Major version is in high byte */
+ *netscape_major = gNetscapeFuncs.version >> 8;
+ /* Minor version is in low byte */
+ *netscape_minor = gNetscapeFuncs.version & 0xFF;
+}
+
+NPError
+NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
+{
+ return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
+ instance, variable, r_value);
+}
+
+NPError
+NPN_SetValue(NPP instance, NPPVariable variable, void *value)
+{
+ return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
+ instance, variable, value);
+}
+
+NPError
+NPN_GetURL(NPP instance, const char* url, const char* window)
+{
+ return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
+}
+
+NPError
+NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
+{
+ return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
+}
+
+NPError
+NPN_PostURL(NPP instance, const char* url, const char* window,
+ uint32 len, const char* buf, NPBool file)
+{
+ return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
+ url, window, len, buf, file);
+}
+
+NPError
+NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
+ const char* buf, NPBool file, void* notifyData)
+{
+ return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
+ instance, url, window, len, buf, file, notifyData);
+}
+
+NPError
+NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
+{
+ return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
+ stream, rangeList);
+}
+
+NPError
+NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
+ NPStream** stream_ptr)
+{
+ return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
+ type, window, stream_ptr);
+}
+
+int32
+NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
+{
+ return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
+ stream, len, buffer);
+}
+
+NPError
+NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
+{
+ return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
+ instance, stream, reason);
+}
+
+void
+NPN_Status(NPP instance, const char* message)
+{
+ CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
+}
+
+const char*
+NPN_UserAgent(NPP instance)
+{
+ return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
+}
+
+void*
+NPN_MemAlloc(uint32 size)
+{
+ return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
+}
+
+void NPN_MemFree(void* ptr)
+{
+ CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
+}
+
+uint32 NPN_MemFlush(uint32 size)
+{
+ return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
+}
+
+void NPN_ReloadPlugins(NPBool reloadPages)
+{
+ CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
+}
+
+#ifdef OJI
+JRIEnv* NPN_GetJavaEnv()
+{
+ return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
+}
+
+jref NPN_GetJavaPeer(NPP instance)
+{
+ return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
+ instance);
+}
+#endif
+
+void
+NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
+{
+ CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
+ invalidRect);
+}
+
+void
+NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
+{
+ CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
+ invalidRegion);
+}
+
+void
+NPN_ForceRedraw(NPP instance)
+{
+ CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
+}
+
+void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
+{
+ CallNPN_PushPopupsEnabledStateProc(gNetscapeFuncs.pushpopupsenabledstate,
+ instance, enabled);
+}
+
+void NPN_PopPopupsEnabledState(NPP instance)
+{
+ CallNPN_PopPopupsEnabledStateProc(gNetscapeFuncs.poppopupsenabledstate,
+ instance);
+}
+
+
+
+/***********************************************************************
+ *
+ * Wrapper functions : Netscape Navigator -> plugin
+ *
+ * These functions let the plugin developer just create the APIs
+ * as documented and defined in npapi.h, without needing to
+ * install those functions in the function table or worry about
+ * setting up globals for 68K plugins.
+ *
+ ***********************************************************************/
+
+static NPError
+Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
+ int16 argc, char* argn[], char* argv[], NPSavedData* saved)
+{
+ NPError ret;
+ PLUGINDEBUGSTR("New");
+ ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
+ return ret;
+}
+
+static NPError
+Private_Destroy(NPP instance, NPSavedData** save)
+{
+ PLUGINDEBUGSTR("Destroy");
+ return NPP_Destroy(instance, save);
+}
+
+static NPError
+Private_SetWindow(NPP instance, NPWindow* window)
+{
+ NPError err;
+ PLUGINDEBUGSTR("SetWindow");
+ err = NPP_SetWindow(instance, window);
+ return err;
+}
+
+static NPError
+Private_NewStream(NPP instance G_GNUC_UNUSED, NPMIMEType type G_GNUC_UNUSED,
+ NPStream* stream G_GNUC_UNUSED,
+ NPBool seekable G_GNUC_UNUSED, uint16* stype G_GNUC_UNUSED)
+{
+ NPError err = NPERR_NO_ERROR;
+ PLUGINDEBUGSTR("NewStream");
+/* err = NPP_NewStream(instance, type, stream, seekable, stype);*/
+ return err;
+}
+
+static int32
+Private_WriteReady(NPP instance, NPStream* stream)
+{
+ unsigned int result;
+ PLUGINDEBUGSTR("WriteReady");
+ result = NPP_WriteReady(instance, stream);
+ return result;
+}
+
+static int32
+Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
+ void* buffer)
+{
+ unsigned int result;
+ PLUGINDEBUGSTR("Write");
+ result = NPP_Write(instance, stream, offset, len, buffer);
+ return result;
+}
+
+static void
+Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
+{
+ PLUGINDEBUGSTR("StreamAsFile");
+ NPP_StreamAsFile(instance, stream, fname);
+}
+
+
+static NPError
+Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
+{
+ NPError err;
+ PLUGINDEBUGSTR("DestroyStream");
+ err = NPP_DestroyStream(instance, stream, reason);
+ return err;
+}
+
+static void
+Private_URLNotify(NPP instance, const char* url,
+ NPReason reason, void* notifyData)
+
+{
+ PLUGINDEBUGSTR("URLNotify");
+ NPP_URLNotify(instance, url, reason, notifyData);
+}
+
+static NPError
+Private_GetValue(void *instance, NPPVariable variable, void *result)
+{
+ NPError rv = NPP_GetValue(instance, variable, result);
+ return rv;
+}
+
+static void
+Private_Print(NPP instance, NPPrint* platformPrint)
+{
+ PLUGINDEBUGSTR("Print");
+ NPP_Print(instance, platformPrint);
+}
+
+#ifdef OJI
+static JRIGlobalRef
+Private_GetJavaClass(void)
+{
+ jref clazz = NPP_GetJavaClass();
+ if (clazz) {
+ JRIEnv* env = NPN_GetJavaEnv();
+ return JRI_NewGlobalRef(env, clazz);
+ }
+ return NULL;
+}
+#endif
+
+static int16
+Private_HandleEvent(NPP instance, void* event)
+{
+ return NPP_HandleEvent(instance, event);
+}
+
+/***********************************************************************
+ *
+ * These functions are located automagically by netscape.
+ *
+ ***********************************************************************/
+
+/*
+ * NP_GetMIMEDescription
+ * - Netscape needs to know about this symbol
+ * - Netscape uses the return value to identify when an object instance
+ * of this plugin should be created.
+ */
+char *
+NP_GetMIMEDescription(void)
+{
+ return NPP_GetMIMEDescription();
+}
+
+/*
+ * NP_GetValue [optional]
+ * - Netscape needs to know about this symbol.
+ * - Interfaces with plugin to get values for predefined variables
+ * that the navigator needs.
+ */
+NPError
+NP_GetValue(void* future, NPPVariable variable, void *value)
+{
+ return NPP_GetValue(future, variable, value);
+}
+
+/*
+ * NP_Initialize
+ * - Netscape needs to know about this symbol.
+ * - It calls this function after looking up its symbol before it
+ * is about to create the first ever object of this kind.
+ *
+ * PARAMETERS
+ * nsTable - The netscape function table. If developers just use these
+ * wrappers, they dont need to worry about all these function
+ * tables.
+ * RETURN
+ * pluginFuncs
+ * - This functions needs to fill the plugin function table
+ * pluginFuncs and return it. Netscape Navigator plugin
+ * library will use this function table to call the plugin.
+ *
+ */
+NPError
+NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
+{
+ NPError err = NPERR_NO_ERROR;
+
+ PLUGINDEBUGSTR("NP_Initialize");
+
+ /* validate input parameters */
+
+ if ((nsTable == NULL) || (pluginFuncs == NULL))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+
+ /*
+ * Check the major version passed in Netscape's function table.
+ * We won't load if the major version is newer than what we expect.
+ * Also check that the function tables passed in are big enough for
+ * all the functions we need (they could be bigger, if Netscape added
+ * new APIs, but that's OK with us -- we'll just ignore them).
+ *
+ */
+
+ if (err == NPERR_NO_ERROR) {
+ if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
+ err = NPERR_INCOMPATIBLE_VERSION_ERROR;
+ if (nsTable->size < sizeof(NPNetscapeFuncs))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+ if (pluginFuncs->size < sizeof(NPPluginFuncs))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+ }
+
+
+ if (err == NPERR_NO_ERROR) {
+ /*
+ * Copy all the fields of Netscape function table into our
+ * copy so we can call back into Netscape later. Note that
+ * we need to copy the fields one by one, rather than assigning
+ * the whole structure, because the Netscape function table
+ * could actually be bigger than what we expect.
+ */
+ gNetscapeFuncs.version = nsTable->version;
+ gNetscapeFuncs.size = nsTable->size;
+ gNetscapeFuncs.posturl = nsTable->posturl;
+ gNetscapeFuncs.geturl = nsTable->geturl;
+ gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
+ gNetscapeFuncs.requestread = nsTable->requestread;
+ gNetscapeFuncs.newstream = nsTable->newstream;
+ gNetscapeFuncs.write = nsTable->write;
+ gNetscapeFuncs.destroystream = nsTable->destroystream;
+ gNetscapeFuncs.status = nsTable->status;
+ gNetscapeFuncs.uagent = nsTable->uagent;
+ gNetscapeFuncs.memalloc = nsTable->memalloc;
+ gNetscapeFuncs.memfree = nsTable->memfree;
+ gNetscapeFuncs.memflush = nsTable->memflush;
+ gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
+#ifdef OJI
+ gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
+ gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
+#endif
+ gNetscapeFuncs.getvalue = nsTable->getvalue;
+ gNetscapeFuncs.setvalue = nsTable->setvalue;
+ gNetscapeFuncs.pushpopupsenabledstate = nsTable->pushpopupsenabledstate;
+ gNetscapeFuncs.poppopupsenabledstate = nsTable->poppopupsenabledstate;
+
+ /*
+ * Set up the plugin function table that Netscape will use to
+ * call us. Netscape needs to know about our version and size
+ * and have a UniversalProcPointer for every function we
+ * implement.
+ */
+ pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
+ pluginFuncs->size = sizeof(NPPluginFuncs);
+ pluginFuncs->newp = NewNPP_NewProc(Private_New);
+ pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
+ pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
+ pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
+ pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
+ pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
+ pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
+ pluginFuncs->write = NewNPP_WriteProc(Private_Write);
+ pluginFuncs->print = NewNPP_PrintProc(Private_Print);
+ pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
+ pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
+ pluginFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent);
+#ifdef OJI
+ pluginFuncs->javaClass = Private_GetJavaClass();
+#endif
+
+ err = NPP_Initialize();
+ }
+
+ return err;
+}
+
+/*
+ * NP_Shutdown [optional]
+ * - Netscape needs to know about this symbol.
+ * - It calls this function after looking up its symbol after
+ * the last object of this kind has been destroyed.
+ *
+ */
+NPError
+NP_Shutdown(void)
+{
+ PLUGINDEBUGSTR("NP_Shutdown");
+ NPP_Shutdown();
+ return NPERR_NO_ERROR;
+}
diff -r fe1efb558b4b plugin/test.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/test.html Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,19 @@
+<html>
+<body>
+
+ <h1>Virt Viewer plugin test</h1>
+
+ <p>You will need to edit the source to
+ set <code>uri</code>, <code>name</code> etc.</p>
+
+ <embed type="application/x-virt-viewer"
+ width="900"
+ height="700"
+ uri="qemu:///system"
+ name="1">
+ </embed>
+
+ <p>End of page</p>
+
+</body>
+</html>
diff -r fe1efb558b4b plugin/virt-viewer-plugin.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/virt-viewer-plugin.c Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,147 @@
+/*
+ VIRT-VIEWER-PLUGIN
+
+ By Richard W.M. Jones <[EMAIL PROTECTED]>
+ Copyright (C) 2008 Red Hat Inc.
+
+ Largely based on DiamondX (http://multimedia.cx/diamondx/), which itself
+ is based on Mozilla sources.
+
+ DiamondX copyright notice:
+
+ Example XEmbed-aware Mozilla browser plugin by Adobe.
+
+ Copyright (c) 2007 Adobe Systems Incorporated
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <vncdisplay.h>
+
+#include "virt-viewer-plugin.h"
+
+static GtkWidget *
+get_container (void *thisv)
+{
+ PluginInstance *This = (PluginInstance *) thisv;
+ return This->container;
+}
+
+NPError
+VirtViewerXSetWindow (NPP instance, NPWindow *window)
+{
+ PluginInstance *This;
+ NPSetWindowCallbackStruct *ws_info;
+ int r;
+
+ if (instance == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ This = (PluginInstance*) instance->pdata;
+
+ debug ("ViewViewerXSetWindow, This=%p", This);
+
+ if (This == NULL)
+ return NPERR_INVALID_INSTANCE_ERROR;
+
+ ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
+
+ /* Mozilla likes to re-run its greatest hits */
+ if (window == This->window &&
+ window->x == This->x &&
+ window->y == This->y &&
+ window->width == This->width &&
+ window->height == This->height) {
+ debug ("virt-viewer-plugin: window re-run; returning");
+ return NPERR_NO_ERROR;
+ }
+
+ This->window = window;
+ This->x = window->x;
+ This->y = window->y;
+ This->width = window->width;
+ This->height = window->height;
+
+ /* Create a GtkPlug container and a Gtk-VNC widget inside it. */
+ This->container = gtk_plug_new ((GdkNativeWindow)(long)window->window);
+
+ /* Make the VNC widget. */
+ if (This->uri && This->name) {
+ debug ("calling viewer_start uri=%s name=%s direct=%d waitvnc=%d container=%p", This->uri, This->name, This->direct, This->waitvnc, This->container);
+ r = viewer_start (This->uri, This->name, This->direct, This->waitvnc, 1,
+ get_container, This);
+ if (r != 0)
+ fprintf (stderr, "viewer_start returned %d != 0\n", r);
+ }
+
+ gtk_widget_show (This->container);
+
+ return NPERR_NO_ERROR;
+}
+
+NPError
+VirtViewerDestroyWindow (NPP instance)
+{
+ PluginInstance *This = (PluginInstance*) instance->pdata;
+
+ debug ("VirtViewerDestroyWindow, This=%p", This);
+
+ if (This && This->container) {
+ gtk_widget_destroy (This->container);
+ This->container = NULL;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+static NPWindow windowlessWindow;
+
+int16
+VirtViewerXHandleEvent(NPP instance, void *event)
+{
+ XGraphicsExposeEvent exposeEvent;
+ XEvent *nsEvent;
+
+ debug ("VirtViewerXHandleEvent");
+
+ nsEvent = (XEvent *) event;
+ exposeEvent = nsEvent->xgraphicsexpose;
+
+ /*printf(" event: x, y, w, h = %d, %d, %d, %d; display @ %p, window/drawable = %d\n",
+ exposeEvent.x,
+ exposeEvent.y,
+ exposeEvent.width,
+ exposeEvent.height,
+ exposeEvent.display,
+ exposeEvent.drawable);*/
+
+ windowlessWindow.window = exposeEvent.display;
+ windowlessWindow.x = exposeEvent.x;
+ windowlessWindow.y = exposeEvent.y;
+ windowlessWindow.width = exposeEvent.width;
+ windowlessWindow.height = exposeEvent.height;
+ windowlessWindow.ws_info = (void *)exposeEvent.drawable;
+
+ NPP_SetWindow(instance, &windowlessWindow);
+
+ return 0;
+}
diff -r fe1efb558b4b plugin/virt-viewer-plugin.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/virt-viewer-plugin.h Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,83 @@
+/*
+ VIRT_VIEWER-PLUGIN
+
+ By Richard W.M. Jones <[EMAIL PROTECTED]>
+ Copyright (C) 2008 Red Hat Inc.
+
+ Largely based on DiamondX (http://multimedia.cx/diamondx/), which itself
+ is based on Mozilla sources.
+
+ DiamondX copyright notice:
+
+ Example XEmbed-aware Mozilla browser plugin by Adobe.
+
+ Copyright (c) 2007 Adobe Systems Incorporated
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef VIRT_VIEWER_PLUGIN_H
+#define VIRT_VIEWER_PLUGIN_H
+
+#include <npapi.h>
+#include <gtk/gtk.h>
+#include <X11/Xlib.h>
+#include "viewer.h"
+
+#define PLUGIN_NAME "Virt-viewer browser plugin"
+#define MIME_TYPES_HANDLED "application/x-virt-viewer:virt-viewer:Virt viewer"
+#define PLUGIN_DESCRIPTION "Virtual machine console viewer plugin"
+
+typedef struct {
+ uint16 mode;
+ NPWindow *window;
+ int32 x, y;
+ uint32 width, height;
+
+ NPP instance;
+ NPBool pluginsHidden;
+
+ GtkWidget *container;
+
+ char *uri, *name;
+ int direct, waitvnc;
+} PluginInstance;
+
+extern NPError VirtViewerXSetWindow (NPP instance, NPWindow* window);
+extern NPError VirtViewerDestroyWindow (NPP instance);
+extern int16 VirtViewerXHandleEvent (NPP instance, void* event);
+
+#ifdef ENABLE_DEBUG
+static void
+debug (const char *msg, ...)
+{
+ va_list args;
+
+ va_start (args, msg);
+ vfprintf (stderr, msg, args);
+ va_end (args);
+ fprintf (stderr, "\n");
+ fflush (stderr);
+}
+#else
+static void debug (const char *msg G_GNUC_UNUSED, ...) { }
+#endif
+
+#endif /* VIRT_VIEWER_PLUGIN_H */
diff -r fe1efb558b4b src/Makefile.am
--- a/src/Makefile.am Fri Jan 11 17:43:30 2008 -0500
+++ b/src/Makefile.am Fri Jan 25 15:22:49 2008 +0000
@@ -1,6 +1,6 @@
bin_PROGRAMS = virt-viewer
-virt_viewer_SOURCES = main.c
+virt_viewer_SOURCES = main.c viewer.h
virt_viewer_LDADD = @GTKVNC_LIBS@ @GTK2_LIBS@ @LIBXML2_LIBS@ @LIBVIRT_LIBS@
virt_viewer_CFLAGS = @GTKVNC_CFLAGS@ @GTK2_CFLAGS@ @LIBXML2_CFLAGS@ @LIBVIRT_CFLAGS@ @WARN_CFLAGS@
diff -r fe1efb558b4b src/main.c
--- a/src/main.c Fri Jan 11 17:43:30 2008 -0500
+++ b/src/main.c Fri Jan 25 15:22:49 2008 +0000
@@ -35,6 +35,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "viewer.h"
+
// #define DEBUG 1
#ifdef DEBUG
#define DEBUG_LOG(s, ...) fprintf(stderr, (s), ## __VA_ARGS__)
@@ -67,7 +69,7 @@ static const struct keyComboDef keyCombo
{ { GDK_Print }, 1, "_PrintScreen"},
};
-static void viewer_set_title(VncDisplay *vnc, GtkWidget *window, gboolean grabbed)
+static void viewer_set_title(VncDisplay *vnc G_GNUC_UNUSED, GtkWidget *window, gboolean grabbed)
{
char title[1024];
const char *subtitle;
@@ -99,10 +101,12 @@ static void viewer_shutdown(GtkWidget *s
gtk_main_quit();
}
+#ifndef PLUGIN
static void viewer_quit(GtkWidget *src G_GNUC_UNUSED, GtkWidget *vnc)
{
viewer_shutdown(src, NULL, vnc);
}
+#endif
static void viewer_connected(GtkWidget *vnc G_GNUC_UNUSED)
{
@@ -122,6 +126,7 @@ static void viewer_disconnected(GtkWidge
gtk_main_quit();
}
+#ifndef PLUGIN
static void viewer_send_key(GtkWidget *menu, GtkWidget *vnc)
{
int i;
@@ -140,7 +145,6 @@ static void viewer_send_key(GtkWidget *m
DEBUG_LOG("Failed to find key combo %s\n", gtk_label_get_text(GTK_LABEL(label)));
}
-
static void viewer_save_screenshot(GtkWidget *vnc, const char *file)
{
GdkPixbuf *pix = vnc_display_get_pixbuf(VNC_DISPLAY(vnc));
@@ -174,7 +178,7 @@ static void viewer_screenshot(GtkWidget
gtk_widget_destroy (dialog);
}
-
+#endif
static void viewer_credential(GtkWidget *vnc, GValueArray *credList)
{
@@ -279,6 +283,7 @@ static void viewer_credential(GtkWidget
gtk_widget_destroy(GTK_WIDGET(dialog));
}
+#ifndef PLUGIN
static void viewer_about(GtkWidget *menu G_GNUC_UNUSED)
{
GtkWidget *about;
@@ -406,20 +411,42 @@ static GtkWidget *viewer_build_menu(VncD
return menubar;
}
-static GtkWidget *viewer_build_window(VncDisplay *vnc)
+static GtkWidget *viewer_get_toplevel (void *data G_GNUC_UNUSED)
+{
+ GtkWidget *window;
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
+ return window;
+}
+#endif
+
+static GtkWidget *viewer_build_window(VncDisplay *vnc,
+ GtkWidget *(*get_toplevel)(void *),
+ void *data)
{
GtkWidget *window;
GtkWidget *menubar;
+#ifndef PLUGIN
GtkWidget *layout;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+#endif
+
+ /* In the standalone program, calls viewer_get_toplevel above
+ * to make a window. In the browser plugin this calls a function
+ * in the plugin which returns the GtkPlug that we live inside.
+ * In both cases they are GTK_CONTAINERs and NOT resizable.
+ */
+ window = get_toplevel (data);
+
+#ifndef PLUGIN
layout = gtk_vbox_new(FALSE, 3);
menubar = viewer_build_menu(vnc);
-
gtk_container_add(GTK_CONTAINER(window), layout);
gtk_container_add(GTK_CONTAINER(layout), menubar);
gtk_container_add(GTK_CONTAINER(layout), GTK_WIDGET(vnc));
- gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
+#else
+ gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vnc));
+#endif
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-grab",
GTK_SIGNAL_FUNC(viewer_grab), window);
@@ -440,29 +467,6 @@ static GtkWidget *viewer_build_window(Vn
GTK_SIGNAL_FUNC(viewer_credential), NULL);
return window;
-}
-
-
-static void viewer_version(FILE *out)
-{
- fprintf(out, "%s version %s\n", PACKAGE, VERSION);
-}
-
-static void viewer_help(FILE *out, const char *app)
-{
- fprintf(out, "\n");
- fprintf(out, "syntax: %s [OPTIONS] DOMAIN-NAME|ID|UUID\n", app);
- fprintf(out, "\n");
- viewer_version(out);
- fprintf(out, "\n");
- fprintf(out, "Options:\n\n");
- fprintf(out, " -h, --help display command line help\n");
- fprintf(out, " -v, --verbose display verbose information\n");
- fprintf(out, " -V, --version display version information\n");
- fprintf(out, " -d, --direct direct connection with no automatic tunnels\n");
- fprintf(out, " -c URI, --connect URI connect to hypervisor URI\n");
- fprintf(out, " -w, --wait wait for domain to start\n");
- fprintf(out, "\n");
}
static int viewer_parse_uuid(const char *name, unsigned char *uuid)
@@ -683,12 +687,111 @@ static int viewer_open_tunnel_ssh(const
return viewer_open_tunnel(cmd);
}
-
-int main(int argc, char **argv)
+int
+viewer_start (const char *uri, const char *name,
+ int direct, int waitvnc, int set_verbose,
+ GtkWidget *(*get_toplevel)(void *), void *data)
{
GtkWidget *window;
GtkWidget *vnc;
+ virConnectPtr conn = NULL;
+ virDomainPtr dom = NULL;
+ char *host = NULL;
+ char *vncport = NULL;
+ char *transport = NULL;
+ char *user = NULL;
+ const char *tmpname = NULL;
+ int port = 0;
+ int fd = -1;
+
+ verbose = set_verbose;
+
+ conn = virConnectOpenReadOnly(uri);
+ if (!conn) {
+ fprintf(stderr, "unable to connect to libvirt %s\n",
+ uri ? uri : "xen");
+ return 2;
+ }
+
+ do {
+ dom = viewer_lookup_domain(conn, name);
+ if (!dom && !waitvnc) {
+ fprintf(stderr, "unable to lookup domain %s\n", name);
+ return 3;
+ }
+ if (!dom)
+ usleep(500*1000);
+ } while (!dom);
+
+ do {
+ viewer_extract_vnc_graphics(dom, &vncport);
+ if (!vncport && !waitvnc) {
+ fprintf(stderr, "unable to find vnc graphics for %s\n", name);
+ return 4;
+ }
+ if (!vncport)
+ usleep(300*1000);
+ } while (!vncport);
+ tmpname = virDomainGetName(dom);
+ if (tmpname != NULL) {
+ domname = strdup(tmpname);
+ }
+ virDomainFree(dom);
+ virConnectClose(conn);
+
+ if (viewer_extract_host(uri, &host, &transport, &user, &port) < 0) {
+ fprintf(stderr, "unable to determine hostname for URI %s\n", uri);
+ return 5;
+ }
+ DEBUG_LOG("Remote host is %s and transport %s user %s\n", host, transport ? transport : "", user ? user : "");
+
+ if (transport && strcasecmp(transport, "ssh") == 0 && !direct)
+ fd = viewer_open_tunnel_ssh(host, port, user, vncport);
+
+ vnc = vnc_display_new();
+ window = viewer_build_window (VNC_DISPLAY(vnc), get_toplevel, data);
+ gtk_widget_realize(vnc);
+
+ vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
+ vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
+
+ if (fd >= 0)
+ vnc_display_open_fd(VNC_DISPLAY(vnc), fd);
+ else
+ vnc_display_open_host(VNC_DISPLAY(vnc), host, vncport);
+
+ return 0;
+}
+
+#ifndef PLUGIN
+/* Standalone program. */
+
+static void viewer_version(FILE *out)
+{
+ fprintf(out, "%s version %s\n", PACKAGE, VERSION);
+}
+
+static void viewer_help(FILE *out, const char *app)
+{
+ fprintf(out, "\n");
+ fprintf(out, "syntax: %s [OPTIONS] DOMAIN-NAME|ID|UUID\n", app);
+ fprintf(out, "\n");
+ viewer_version(out);
+ fprintf(out, "\n");
+ fprintf(out, "Options:\n\n");
+ fprintf(out, " -h, --help display command line help\n");
+ fprintf(out, " -v, --verbose display verbose information\n");
+ fprintf(out, " -V, --version display version information\n");
+ fprintf(out, " -d, --direct direct connection with no automatic tunnels\n");
+ fprintf(out, " -c URI, --connect URI connect to hypervisor URI\n");
+ fprintf(out, " -w, --wait wait for domain to start\n");
+ fprintf(out, "\n");
+}
+
+int main(int argc, char **argv)
+{
char *uri = NULL;
+ char *name = NULL;
int opt_ind;
const char *sopts = "hVc:";
static const struct option lopts[] = {
@@ -701,17 +804,10 @@ int main(int argc, char **argv)
{ 0, 0, 0, 0 }
};
int ch;
+ int direct = 0;
int waitvnc = 0;
- virConnectPtr conn = NULL;
- virDomainPtr dom = NULL;
- char *host = NULL;
- char *vncport = NULL;
- char *transport = NULL;
- char *user = NULL;
- const char *tmpname = NULL;
- int port = 0;
- int fd = -1;
- int direct = 0;
+ int set_verbose = 0;
+ int ret;
while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
switch (ch) {
@@ -722,7 +818,7 @@ int main(int argc, char **argv)
viewer_version(stdout);
return 0;
case 'v':
- verbose = 1;
+ set_verbose = 1;
break;
case 'c':
uri = strdup(optarg);
@@ -739,7 +835,6 @@ int main(int argc, char **argv)
}
}
-
if (argc != (optind+1)) {
viewer_help(stderr, argv[0]);
return 1;
@@ -747,64 +842,16 @@ int main(int argc, char **argv)
gtk_init(&argc, &argv);
- conn = virConnectOpenReadOnly(uri);
- if (!conn) {
- fprintf(stderr, "unable to connect to libvirt %s\n",
- uri ? uri : "xen");
- return 2;
- }
-
- do {
- dom = viewer_lookup_domain(conn, argv[optind]);
- if (!dom && !waitvnc) {
- fprintf(stderr, "unable to lookup domain %s\n", argv[optind]);
- return 3;
- }
- if (!dom)
- usleep(500*1000);
- } while (!dom);
-
- do {
- viewer_extract_vnc_graphics(dom, &vncport);
- if (!vncport && !waitvnc) {
- fprintf(stderr, "unable to find vnc graphics for %s\n", argv[optind]);
- return 4;
- }
- if (!vncport)
- usleep(300*1000);
- } while (!vncport);
- tmpname = virDomainGetName(dom);
- if (tmpname != NULL) {
- domname = strdup(tmpname);
- }
- virDomainFree(dom);
- virConnectClose(conn);
-
- if (viewer_extract_host(uri, &host, &transport, &user, &port) < 0) {
- fprintf(stderr, "unable to determine hostname for URI %s\n", uri);
- return 5;
- }
- DEBUG_LOG("Remote host is %s and transport %s user %s\n", host, transport ? transport : "", user ? user : "");
-
- if (transport && strcasecmp(transport, "ssh") == 0 && !direct)
- fd = viewer_open_tunnel_ssh(host, port, user, vncport);
-
- vnc = vnc_display_new();
- window = viewer_build_window(VNC_DISPLAY(vnc));
- gtk_widget_realize(vnc);
-
- vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
- vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
-
- if (fd >= 0)
- vnc_display_open_fd(VNC_DISPLAY(vnc), fd);
- else
- vnc_display_open_host(VNC_DISPLAY(vnc), host, vncport);
+ name = argv[optind];
+ ret = viewer_start (uri, name, direct, waitvnc, set_verbose,
+ viewer_get_toplevel, NULL);
+ if (ret != 0) return ret;
gtk_main();
return 0;
}
+#endif /* !PLUGIN */
/*
* Local variables:
diff -r fe1efb558b4b src/viewer.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/viewer.h Fri Jan 25 15:22:49 2008 +0000
@@ -0,0 +1,28 @@
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2007 Red Hat,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Daniel P. Berrange <[EMAIL PROTECTED]>
+ */
+
+#ifndef VIEWER_H
+#define VIEWER_H
+
+extern int viewer_start (const char *uri, const char *name, int direct, int waitvnc, int set_verbose, GtkWidget *(*get_toplevel)(void *), void *data);
+
+#endif /* VIEWER_H */
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ et-mgmt-tools mailing list [email protected] https://www.redhat.com/mailman/listinfo/et-mgmt-tools
