Author: everaldo
Date: 2007-06-04 15:24:37 -0400 (Mon, 04 Jun 2007)
New Revision: 78584
Added:
trunk/moon/plugin/nsIScriptableMoonPlugin.h
trunk/moon/plugin/nsIScriptableMoonPlugin.idl
trunk/moon/plugin/nsScriptablePeer.cpp
trunk/moon/plugin/nsScriptablePeer.h
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/Makefile.am
trunk/moon/plugin/moon-plugin-glue.cpp
trunk/moon/plugin/moon-plugin.cpp
trunk/moon/plugin/moon-plugin.h
trunk/moon/plugin/test/index.html
Log:
2007-06-04 Everaldo Canuto <[EMAIL PROTECTED]>
[Implement scriptable to plugin]
* plugin/test/index.html: Sample jscript included.
* plugin/Makefile.am: Generates .h from idl file use xpidl.
* plugin/moon-plugin.h,
* plugin/moon-plugin.cpp,
* plugin/moon-plugin-glue.cpp: Implement scriptable and some clean up.
* plugin/nsIScriptableMoonPlugin.h,
* plugin/nsIScriptableMoonPlugin.idl,
* plugin/nsScriptablePeer.cpp,
* plugin/nsScriptablePeer.h: New scriptable classes.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-06-04 19:17:18 UTC (rev 78583)
+++ trunk/moon/plugin/ChangeLog 2007-06-04 19:24:37 UTC (rev 78584)
@@ -1,3 +1,20 @@
+2007-06-04 Everaldo Canuto <[EMAIL PROTECTED]>
+
+ [Implement scriptable to plugin]
+
+ * plugin/test/index.html: Sample jscript included.
+
+ * plugin/Makefile.am: Generates .h from idl file use xpidl.
+
+ * plugin/moon-plugin.h,
+ * plugin/moon-plugin.cpp,
+ * plugin/moon-plugin-glue.cpp: Implement scriptable and some clean up.
+
+ * plugin/nsIScriptableMoonPlugin.h,
+ * plugin/nsIScriptableMoonPlugin.idl,
+ * plugin/nsScriptablePeer.cpp,
+ * plugin/nsScriptablePeer.h: New scriptable classes.
+
2007-06-03 Everaldo Canuto <[EMAIL PROTECTED]>
* moon-plugin-glue.cpp,
Modified: trunk/moon/plugin/Makefile.am
===================================================================
--- trunk/moon/plugin/Makefile.am 2007-06-04 19:17:18 UTC (rev 78583)
+++ trunk/moon/plugin/Makefile.am 2007-06-04 19:24:37 UTC (rev 78584)
@@ -1,4 +1,7 @@
+XPIDL=`pkg-config --variable=libdir xulrunner-xpcom`/xpidl
+XPFLAGS=-I `pkg-config --variable=includedir xulrunner-xpcom`
+
lib_LTLIBRARIES = libmoonplugin.la
INCLUDES = \
@@ -18,9 +21,15 @@
libmoonplugin_la_SOURCES = \
moon-plugin.cpp \
moon-plugin.h \
- moon-plugin-glue.cpp
+ moon-plugin-glue.cpp \
+ nsScriptablePeer.cpp \
+ nsScriptablePeer.h
# custom install rule
+idl:
+ $(XPIDL) -m header $(XPFLAGS) nsIScriptableMoonPlugin.idl
+ $(XPIDL) -m typelib $(XPFLAGS) nsIScriptableMoonPlugin.idl
+
install-plugin: libmoonplugin.la
mkdir -p ~/.mozilla/plugins
cp .libs/libmoonplugin.so ~/.mozilla/plugins
Modified: trunk/moon/plugin/moon-plugin-glue.cpp
===================================================================
--- trunk/moon/plugin/moon-plugin-glue.cpp 2007-06-04 19:17:18 UTC (rev
78583)
+++ trunk/moon/plugin/moon-plugin-glue.cpp 2007-06-04 19:24:37 UTC (rev
78584)
@@ -152,6 +152,170 @@
}
/**
+ * NPRuntime support
+ */
+NPIdentifier NPN_GetStringIdentifier (const NPUTF8 *name)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_GetStringIdentifierProc
(MozillaFuncs.getstringidentifier, name);
+
+ return NULL;
+}
+
+void NPN_GetStringIdentifiers (const NPUTF8 **names, int32_t nameCount,
NPIdentifier *identifiers)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ CallNPN_GetStringIdentifiersProc
(MozillaFuncs.getstringidentifiers, names, nameCount, identifiers);
+}
+
+NPIdentifier NPN_GetIntIdentifier (int32_t intid)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_GetIntIdentifierProc
(MozillaFuncs.getintidentifier, intid);
+
+ return NULL;
+}
+
+bool NPN_IdentifierIsString (NPIdentifier identifier)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_IdentifierIsStringProc
(MozillaFuncs.identifierisstring, identifier);
+
+ return false;
+}
+
+NPUTF8 *NPN_UTF8FromIdentifier (NPIdentifier identifier)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_UTF8FromIdentifierProc
(MozillaFuncs.utf8fromidentifier, identifier);
+
+ return NULL;
+}
+
+int32_t NPN_IntFromIdentifier (NPIdentifier identifier)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_IntFromIdentifierProc
(MozillaFuncs.intfromidentifier, identifier);
+
+ return 0;
+}
+
+NPObject *NPN_CreateObject (NPP instance, NPClass *aClass)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_CreateObjectProc (MozillaFuncs.createobject,
instance, aClass);
+ return NULL;
+}
+
+NPObject *NPN_RetainObject (NPObject *npobj)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_RetainObjectProc (MozillaFuncs.retainobject,
npobj);
+ return NULL;
+}
+
+void NPN_ReleaseObject (NPObject *npobj)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ CallNPN_ReleaseObjectProc (MozillaFuncs.releaseobject, npobj);
+}
+
+bool NPN_Invoke (NPP instance, NPObject *npobj, NPIdentifier methodName, const
NPVariant *args, uint32_t argCount, NPVariant *result)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_InvokeProc (MozillaFuncs.invoke, instance,
npobj, methodName, args, argCount, result);
+
+ return false;
+}
+
+bool NPN_InvokeDefault (NPP instance, NPObject *npobj, const NPVariant *args,
uint32_t argCount, NPVariant *result)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_InvokeDefaultProc (MozillaFuncs.invokeDefault,
instance, npobj, args, argCount, result);
+
+ return false;
+}
+
+bool NPN_Evaluate (NPP instance, NPObject *npobj, NPString *script, NPVariant
*result)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_EvaluateProc (MozillaFuncs.evaluate, instance,
npobj, script, result);
+
+ return false;
+}
+
+bool NPN_GetProperty (NPP instance, NPObject *npobj, NPIdentifier
propertyName, NPVariant *result)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_GetPropertyProc (MozillaFuncs.getproperty,
instance, npobj, propertyName, result);
+
+ return false;
+}
+
+bool NPN_SetProperty (NPP instance, NPObject *npobj, NPIdentifier
propertyName, const NPVariant *value)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_SetPropertyProc (MozillaFuncs.setproperty,
instance, npobj, propertyName, value);
+
+ return false;
+}
+
+bool NPN_RemoveProperty (NPP instance, NPObject *npobj, NPIdentifier
propertyName)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_RemovePropertyProc (MozillaFuncs.removeproperty,
instance, npobj, propertyName);
+
+ return false;
+}
+
+bool NPN_HasProperty (NPP instance, NPObject *npobj, NPIdentifier propertyName)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_HasPropertyProc (MozillaFuncs.hasproperty,
instance, npobj, propertyName);
+
+ return false;
+}
+
+bool NPN_HasMethod (NPP instance, NPObject *npobj, NPIdentifier methodName)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ return CallNPN_HasMethodProc (MozillaFuncs.hasmethod, instance,
npobj, methodName);
+
+ return false;
+}
+
+void NPN_ReleaseVariantValue (NPVariant *variant)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ CallNPN_ReleaseVariantValueProc
(MozillaFuncs.releasevariantvalue, variant);
+}
+
+void NPN_SetException (NPObject *npobj, const NPUTF8 *message)
+{
+ int navMinorVers = MozillaFuncs.version & 0xFF;
+ if (navMinorVers >= 14)
+ CallNPN_SetExceptionProc (MozillaFuncs.setexception, npobj,
message);
+}
+
+/**
* Plugin functions
*/
NPError
@@ -164,20 +328,15 @@
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
- instance->pdata = NPN_MemAlloc (sizeof (PluginInstance));
+ instance->pdata = NPN_MemAlloc (sizeof (PluginInstance));
- plugin = (PluginInstance*) instance->pdata;
+ plugin = (PluginInstance*) instance->pdata;
- if (plugin == NULL)
- {
- return NPERR_OUT_OF_MEMORY_ERROR;
- }
+ if (plugin == NULL)
+ return NPERR_OUT_OF_MEMORY_ERROR;
- memset (plugin, 0, sizeof (PluginInstance));
+ memset (plugin, 0, sizeof (PluginInstance));
- //plugin->mode = mode;
- //plugin->instance = instance;
-
return NPERR_NO_ERROR;
}
@@ -425,6 +584,32 @@
MozillaFuncs.pushpopupsenabledstate =
mozilla_funcs->pushpopupsenabledstate;
MozillaFuncs.poppopupsenabledstate =
mozilla_funcs->poppopupsenabledstate;
+ int navMinorVers = mozilla_funcs->version & 0xFF;
+
+ if (navMinorVers >= 14 )
+ {
+ // NPRuntime support
+ MozillaFuncs.getstringidentifier =
mozilla_funcs->getstringidentifier;
+ MozillaFuncs.getstringidentifiers =
mozilla_funcs->getstringidentifiers;
+ MozillaFuncs.getintidentifier =
mozilla_funcs->getintidentifier;
+ MozillaFuncs.identifierisstring =
mozilla_funcs->identifierisstring;
+ MozillaFuncs.utf8fromidentifier =
mozilla_funcs->utf8fromidentifier;
+ MozillaFuncs.intfromidentifier =
mozilla_funcs->intfromidentifier;
+ MozillaFuncs.createobject = mozilla_funcs->createobject;
+ MozillaFuncs.retainobject = mozilla_funcs->retainobject;
+ MozillaFuncs.releaseobject =
mozilla_funcs->releaseobject;
+ MozillaFuncs.invoke = mozilla_funcs->invoke;
+ MozillaFuncs.invokeDefault =
mozilla_funcs->invokeDefault;
+ MozillaFuncs.evaluate = mozilla_funcs->evaluate;
+ MozillaFuncs.getproperty = mozilla_funcs->getproperty;
+ MozillaFuncs.setproperty = mozilla_funcs->setproperty;
+ MozillaFuncs.removeproperty =
mozilla_funcs->removeproperty;
+ MozillaFuncs.hasproperty = mozilla_funcs->hasproperty;
+ MozillaFuncs.hasmethod = mozilla_funcs->hasmethod;
+ MozillaFuncs.releasevariantvalue =
mozilla_funcs->releasevariantvalue;
+ MozillaFuncs.setexception = mozilla_funcs->setexception;
+ }
+
/* Set up the plugin function table */
plugin_funcs->size = sizeof (NPPluginFuncs);
plugin_funcs->version = (NP_VERSION_MAJOR << 8) +
NP_VERSION_MINOR;
Modified: trunk/moon/plugin/moon-plugin.cpp
===================================================================
--- trunk/moon/plugin/moon-plugin.cpp 2007-06-04 19:17:18 UTC (rev 78583)
+++ trunk/moon/plugin/moon-plugin.cpp 2007-06-04 19:24:37 UTC (rev 78584)
@@ -11,7 +11,14 @@
*/
#include "moon-plugin.h"
+#include "nsIServiceManager.h"
+#include "nsISupportsUtils.h"
+#include "nsIMemory.h"
+NPNetscapeFuncs PluginInstance::sNPN;
+
+nsIServiceManager * gServiceManager = NULL;
+
static void moon_plugin_demo (Surface *surface)
{
DEBUG ("*** moon_plugin_demo");
@@ -104,10 +111,27 @@
{
this->mode = mode;
this->instance = instance;
+ this->window = NULL;
+
+ this->mScriptablePeer = NULL;
+
+ nsISupports * sm = NULL;
+ NPN_GetValue(NULL, NPNVserviceManager, &sm);
+
+ if(sm) {
+ sm->QueryInterface(NS_GET_IID(nsIServiceManager),
(void**)&gServiceManager);
+ NS_RELEASE(sm);
+ }
}
PluginInstance::~PluginInstance ()
{
+ this->mScriptablePeer->SetInstance(NULL);
+ NS_IF_RELEASE(mScriptablePeer);
+
+ NS_IF_RELEASE(gServiceManager);
+ gServiceManager = NULL;
+
if (this->container != NULL)
gtk_widget_destroy (this->container);
@@ -119,11 +143,34 @@
PluginInstance::GetValue (NPPVariable variable, void *result)
{
NPError err = NPERR_NO_ERROR;
+
switch (variable) {
case NPPVpluginNeedsXEmbed:
*((PRBool *)result) = PR_TRUE;
break;
+ case NPPVpluginScriptableInstance: {
+ nsIScriptableMoonPlugin * scriptablePeer =
this->getScriptablePeer();
+ if (scriptablePeer)
+ *(nsISupports **)result = scriptablePeer;
+ else
+ err = NPERR_OUT_OF_MEMORY_ERROR;
+
+ break;
+ }
+
+ case NPPVpluginScriptableIID: {
+ static nsIID scriptableIID =
NS_ISCRIPTABLEMOONPLUGIN_IID;
+ nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
+ if (ptr) {
+ *ptr = scriptableIID;
+ *(nsIID **)result = ptr;
+ } else
+ err = NPERR_OUT_OF_MEMORY_ERROR;
+
+ break;
+ }
+
default:
err = NPERR_INVALID_PARAM;
}
@@ -241,3 +288,54 @@
/* Our plugin is a windowed so we dont need the windowless code */
return 0;
}
+
+void
+PluginInstance::getVersion(char* *aVersion)
+{
+ const char *ua = NPN_UserAgent(this->instance);
+ char*& version = *aVersion;
+
+ nsIMemory * nsMemoryService = NULL;
+
+ if (gServiceManager) {
+
gServiceManager->GetServiceByContractID("@mozilla.org/xpcom/memory-service;1",
NS_GET_IID(nsIMemory), (void **)&nsMemoryService);
+ if(nsMemoryService)
+ version = (char *)nsMemoryService->Alloc(strlen(ua) +
1);
+ }
+
+ if (version)
+ strcpy(version, ua);
+
+ NS_IF_RELEASE(nsMemoryService);
+}
+
+void
+PluginInstance::showVersion()
+{
+ DEBUG ("====> showVersion");
+ const char *ua = NPN_UserAgent(this->instance);
+ strcpy(mString, ua);
+}
+
+void
+PluginInstance::clear()
+{
+ DEBUG ("====> clear");
+ strcpy(mString, "");
+}
+
+nsScriptablePeer*
+PluginInstance::getScriptablePeer()
+{
+ if (!mScriptablePeer) {
+ mScriptablePeer = new nsScriptablePeer(this);
+
+ if(!mScriptablePeer)
+ return NULL;
+
+ NS_ADDREF(mScriptablePeer);
+ }
+
+ NS_ADDREF(mScriptablePeer);
+ return mScriptablePeer;
+}
Modified: trunk/moon/plugin/moon-plugin.h
===================================================================
--- trunk/moon/plugin/moon-plugin.h 2007-06-04 19:17:18 UTC (rev 78583)
+++ trunk/moon/plugin/moon-plugin.h 2007-06-04 19:24:37 UTC (rev 78584)
@@ -19,6 +19,7 @@
#include "npapi.h"
#include "npupp.h"
+#include "nsScriptablePeer.h"
#include "glib.h"
#include "gtk/gtk.h"
@@ -51,11 +52,16 @@
NPWindow *window; // Mozilla window object
NPP instance; // Mozilla instance object
bool xembed_supported; // XEmbed Extension supported
-
+
+ nsScriptablePeer* mScriptablePeer;
+
+
public:
PluginInstance (NPP instance, uint16 mode);
~PluginInstance ();
+ static _NPNetscapeFuncs sNPN;
+
NPError GetValue (NPPVariable variable, void *result);
NPError SetValue (NPPVariable variable, void *value);
NPError SetWindow (NPWindow* window);
@@ -71,6 +77,14 @@
GtkWidget *container; // plugin container object
GtkWidget *canvas; // plugin canvas object
Surface *surface; // plugin surface object
-};
+ char mString[128];
+ nsScriptablePeer* getScriptablePeer();
+
+ // locals
+ void getVersion(char* *aVersion);
+ void showVersion();
+ void clear();
+ };
+
#endif /* MOON_PLUGIN */
Added: trunk/moon/plugin/nsIScriptableMoonPlugin.h
===================================================================
--- trunk/moon/plugin/nsIScriptableMoonPlugin.h 2007-06-04 19:17:18 UTC (rev
78583)
+++ trunk/moon/plugin/nsIScriptableMoonPlugin.h 2007-06-04 19:24:37 UTC (rev
78584)
@@ -0,0 +1,113 @@
+/*
+ * DO NOT EDIT. THIS FILE IS GENERATED FROM nsIScriptableMoonPlugin.idl
+ */
+
+#ifndef __gen_nsIScriptableMoonPlugin_h__
+#define __gen_nsIScriptableMoonPlugin_h__
+
+
+#ifndef __gen_nsISupports_h__
+#include "nsISupports.h"
+#endif
+
+/* For IDL files that don't want to include root IDL files. */
+#ifndef NS_NO_VTABLE
+#define NS_NO_VTABLE
+#endif
+
+/* starting interface: nsIScriptableMoonPlugin */
+#define NS_ISCRIPTABLEMOONPLUGIN_IID_STR "d2d536a0-b6fc-11d5-9d10-0060b0fbd8ac"
+
+#define NS_ISCRIPTABLEMOONPLUGIN_IID \
+ {0xd2d536a0, 0xb6fc, 0x11d5, \
+ { 0x9d, 0x10, 0x00, 0x60, 0xb0, 0xfb, 0xd8, 0xac }}
+
+class NS_NO_VTABLE nsIScriptableMoonPlugin : public nsISupports {
+ public:
+
+ NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTABLEMOONPLUGIN_IID)
+
+ /* readonly attribute string version; */
+ NS_IMETHOD GetVersion(char * *aVersion) = 0;
+
+ /* void showVersion (); */
+ NS_IMETHOD ShowVersion(void) = 0;
+
+ /* void clear (); */
+ NS_IMETHOD Clear(void) = 0;
+
+};
+
+/* Use this macro when declaring classes that implement this interface. */
+#define NS_DECL_NSISCRIPTABLEMOONPLUGIN \
+ NS_IMETHOD GetVersion(char * *aVersion); \
+ NS_IMETHOD ShowVersion(void); \
+ NS_IMETHOD Clear(void);
+
+/* Use this macro to declare functions that forward the behavior of this
interface to another object. */
+#define NS_FORWARD_NSISCRIPTABLEMOONPLUGIN(_to) \
+ NS_IMETHOD GetVersion(char * *aVersion) { return _to GetVersion(aVersion); }
\
+ NS_IMETHOD ShowVersion(void) { return _to ShowVersion(); } \
+ NS_IMETHOD Clear(void) { return _to Clear(); }
+
+/* Use this macro to declare functions that forward the behavior of this
interface to another object in a safe way. */
+#define NS_FORWARD_SAFE_NSISCRIPTABLEMOONPLUGIN(_to) \
+ NS_IMETHOD GetVersion(char * *aVersion) { return !_to ?
NS_ERROR_NULL_POINTER : _to->GetVersion(aVersion); } \
+ NS_IMETHOD ShowVersion(void) { return !_to ? NS_ERROR_NULL_POINTER :
_to->ShowVersion(); } \
+ NS_IMETHOD Clear(void) { return !_to ? NS_ERROR_NULL_POINTER : _to->Clear();
}
+
+#if 0
+/* Use the code below as a template for the implementation class for this
interface. */
+
+/* Header file */
+class nsScriptableMoonPlugin : public nsIScriptableMoonPlugin
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSISCRIPTABLEMOONPLUGIN
+
+ nsScriptableMoonPlugin();
+
+private:
+ ~nsScriptableMoonPlugin();
+
+protected:
+ /* additional members */
+};
+
+/* Implementation file */
+NS_IMPL_ISUPPORTS1(nsScriptableMoonPlugin, nsIScriptableMoonPlugin)
+
+nsScriptableMoonPlugin::nsScriptableMoonPlugin()
+{
+ /* member initializers and constructor code */
+}
+
+nsScriptableMoonPlugin::~nsScriptableMoonPlugin()
+{
+ /* destructor code */
+}
+
+/* readonly attribute string version; */
+NS_IMETHODIMP nsScriptableMoonPlugin::GetVersion(char * *aVersion)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* void showVersion (); */
+NS_IMETHODIMP nsScriptableMoonPlugin::ShowVersion()
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* void clear (); */
+NS_IMETHODIMP nsScriptableMoonPlugin::Clear()
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* End of implementation class template. */
+#endif
+
+
+#endif /* __gen_nsIScriptableMoonPlugin_h__ */
Added: trunk/moon/plugin/nsIScriptableMoonPlugin.idl
===================================================================
--- trunk/moon/plugin/nsIScriptableMoonPlugin.idl 2007-06-04 19:17:18 UTC
(rev 78583)
+++ trunk/moon/plugin/nsIScriptableMoonPlugin.idl 2007-06-04 19:24:37 UTC
(rev 78584)
@@ -0,0 +1,20 @@
+/*
+ * nsIScriptableMoonPlugin.idl: MoonLight browser plugin.
+ *
+ * Author:
+ * Everaldo Canuto ([EMAIL PROTECTED])
+ *
+ * Copyright 2007 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(d2d536a0-b6fc-11d5-9d10-0060b0fbd8ac)]
+interface nsIScriptableMoonPlugin : nsISupports {
+ readonly attribute string version;
+ void showVersion();
+ void clear();
+};
Added: trunk/moon/plugin/nsScriptablePeer.cpp
===================================================================
--- trunk/moon/plugin/nsScriptablePeer.cpp 2007-06-04 19:17:18 UTC (rev
78583)
+++ trunk/moon/plugin/nsScriptablePeer.cpp 2007-06-04 19:24:37 UTC (rev
78584)
@@ -0,0 +1,140 @@
+/* -*- 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):
+ *
+ * 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 ***** */
+
+// ==============================
+// ! Scriptability related code !
+// ==============================
+
+/////////////////////////////////////////////////////
+//
+// This file implements the nsScriptablePeer object
+// The native methods of this class are supposed to
+// be callable from JavaScript
+//
+#include "moon-plugin.h"
+
+static NS_DEFINE_IID(kIScriptableIID, NS_ISCRIPTABLEMOONPLUGIN_IID);
+static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
+static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
+
+nsScriptablePeer::nsScriptablePeer(PluginInstance* aPlugin)
+{
+ mPlugin = aPlugin;
+ mRefCnt = 0;
+printf ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
+}
+
+nsScriptablePeer::~nsScriptablePeer()
+{
+}
+
+// AddRef, Release and QueryInterface are common methods and must
+// be implemented for any interface
+NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::AddRef()
+{
+ ++mRefCnt;
+ return mRefCnt;
+}
+
+NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::Release()
+{
+ --mRefCnt;
+ if (mRefCnt == 0) {
+ delete this;
+ return 0;
+ }
+ return mRefCnt;
+}
+
+// here nsScriptablePeer should return three interfaces it can be asked for by
their iid's
+// static casts are necessary to ensure that correct pointer is returned
+NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void**
aInstancePtr)
+{ printf ("#######################");
+ if(!aInstancePtr)
+ return NS_ERROR_NULL_POINTER;
+
+ if(aIID.Equals(kIScriptableIID)) {
+ *aInstancePtr = static_cast<nsIScriptableMoonPlugin*>(this);
+ AddRef();
+ return NS_OK;
+ }
+
+ if(aIID.Equals(kIClassInfoIID)) {
+ *aInstancePtr = static_cast<nsIClassInfo*>(this);
+ AddRef();
+ return NS_OK;
+ }
+
+ if(aIID.Equals(kISupportsIID)) {
+ *aInstancePtr =
static_cast<nsISupports*>(static_cast<nsIScriptableMoonPlugin*>(this));
+ AddRef();
+ return NS_OK;
+ }
+
+ return NS_NOINTERFACE;
+}
+
+void nsScriptablePeer::SetInstance(PluginInstance* plugin)
+{
+ mPlugin = plugin;
+}
+
+//
+// the following methods will be callable from JavaScript
+//
+NS_IMETHODIMP nsScriptablePeer::ShowVersion()
+{printf ("-=-=-=-=-=-=-=-=-=-=-=-");
+ if (mPlugin)
+ mPlugin->showVersion();
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::Clear()
+{
+ if (mPlugin)
+ mPlugin->clear();
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion)
+{
+ if (mPlugin)
+ mPlugin->getVersion(aVersion);
+ return NS_OK;
+}
Added: trunk/moon/plugin/nsScriptablePeer.h
===================================================================
--- trunk/moon/plugin/nsScriptablePeer.h 2007-06-04 19:17:18 UTC (rev
78583)
+++ trunk/moon/plugin/nsScriptablePeer.h 2007-06-04 19:24:37 UTC (rev
78584)
@@ -0,0 +1,107 @@
+/* -*- 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):
+ *
+ * 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 ***** */
+
+// ==============================
+// ! Scriptability related code !
+// ==============================
+//
+// nsScriptablePeer - xpconnect scriptable peer
+//
+
+#ifndef __nsScriptablePeer_h__
+#define __nsScriptablePeer_h__
+
+#include "nsIScriptableMoonPlugin.h"
+#include "nsIClassInfo.h"
+
+class PluginInstance;
+
+// We must implement nsIClassInfo because it signals the
+// Mozilla Security Manager to allow calls from JavaScript.
+
+class nsClassInfoMixin : public nsIClassInfo
+{
+ // These flags are used by the DOM and security systems to signal that
+ // JavaScript callers are allowed to call this object's scritable methods.
+ NS_IMETHOD GetFlags(PRUint32 *aFlags)
+ {*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
+ return NS_OK;}
+ NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
+ {*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
+ return NS_OK;}
+ // The rest of the methods can safely return error codes...
+ NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetContractID(char * *aContractID)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassDescription(char * *aClassDescription)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassID(nsCID * *aClassID)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+};
+
+class nsScriptablePeer : public nsIScriptableMoonPlugin,
+ public nsClassInfoMixin
+{
+public:
+ nsScriptablePeer(PluginInstance* plugin);
+ virtual ~nsScriptablePeer();
+
+public:
+ // methods from nsISupports
+ NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
+ NS_IMETHOD_(nsrefcnt) AddRef();
+ NS_IMETHOD_(nsrefcnt) Release();
+
+protected:
+ nsrefcnt mRefCnt;
+
+public:
+ // native methods callable from JavaScript
+ NS_DECL_NSISCRIPTABLEMOONPLUGIN
+
+ void SetInstance(PluginInstance* plugin);
+
+protected:
+ PluginInstance* mPlugin;
+};
+
+#endif
Modified: trunk/moon/plugin/test/index.html
===================================================================
--- trunk/moon/plugin/test/index.html 2007-06-04 19:17:18 UTC (rev 78583)
+++ trunk/moon/plugin/test/index.html 2007-06-04 19:24:37 UTC (rev 78584)
@@ -6,6 +6,17 @@
<embed src="moonlight.scr" type="application/ag-plugin" width="80%"
height="300"></embed>
+<script>
+var embed = document.embeds[0];
+
+embed.showVersion();
+
+//function ShowVersion()
+//{
+ alert(embed.version);
+//}
+
+</script>
<br><br>
</body>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches