diff --git a/mozilla/modules/plugin/tools/sdk/Makefile.in b/mozilla/modules/plugin/tools/sdk/Makefile.in new file mode 100644 index 00000000000..65b918ddded --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/Makefile.in @@ -0,0 +1,68 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + +install:: + $(INSTALL) $(XPDIST)/idl/nsISupports.idl ./idl + $(INSTALL) $(XPDIST)/idl/nsrootidl.idl ./idl + + $(INSTALL) $(XPDIST)/include/npapi.h ./include + $(INSTALL) $(XPDIST)/include/npupp.h ./include + + $(MAKE_INSTALL) $(XPDIST)\include\java\jni.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jni_md.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jri.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jri_md.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jritypes.h .\include + + $(INSTALL) $(XPDIST)/include/xpcom/nsCom.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsComponentManagerUtils.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsCOMPtr.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nscore.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsDebug.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsError.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIClassInfo.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIComponentManager.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsID.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIFactory.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIID.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIMemory.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIProgrammingLanguage.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsIServiceManager.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsISupports.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsISupportsUtils.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsrootidl.h ./include + $(INSTALL) $(XPDIST)/include/xpcom/nsTraceRefcnt.h ./include + + $(INSTALL) $(XPDIST)/include/nspr/pratom.h ./include + $(INSTALL) $(XPDIST)/include/nspr/prcpucfg.h ./include + $(INSTALL) $(XPDIST)/include/nspr/prlock.h ./include + $(INSTALL) $(XPDIST)/include/nspr/prlong.h ./include + $(INSTALL) $(XPDIST)/include/nspr/prtime.h ./include + $(INSTALL) $(XPDIST)/include/nspr/prtypes.h ./include + + $(INSTALL) $(DIST)/bin/regxpcom ./bin + $(INSTALL) $(DIST)/bin/xpidl ./bin + $(INSTALL) $(DIST)/bin/xpt_dump ./bin diff --git a/mozilla/modules/plugin/tools/sdk/makefile.win b/mozilla/modules/plugin/tools/sdk/makefile.win new file mode 100644 index 00000000000..3fa14285ae4 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/makefile.win @@ -0,0 +1,81 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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\NPL\ +# +# 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 Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. +include <$(DEPTH)\config\rules.mak> + +install:: + if not exist "bin" mkdir "bin" + if not exist "idl" mkdir "idl" + if not exist "include" mkdir "include" + + $(MAKE_INSTALL) $(XPDIST)\idl\nsISupports.idl .\idl + $(MAKE_INSTALL) $(XPDIST)\idl\nsrootidl.idl .\idl + + $(MAKE_INSTALL) $(XPDIST)\include\npapi.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\npupp.h .\include + + $(MAKE_INSTALL) $(XPDIST)\include\java\jni.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jni_md.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jri.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jri_md.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\java\jritypes.h .\include + + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsCom.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsComponentManagerUtils.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsCOMPtr.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nscore.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsDebug.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsError.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIClassInfo.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIComponentManager.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsID.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIDirectoryService.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIFactory.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIFile.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIID.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIInputStream.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIInterfaceRequestor.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsILocalFile.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIMemory.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIModule.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIObserver.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIOutputStream.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIProgrammingLanguage.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIProperties.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIServiceManager.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISimpleEmumerator.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupports.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupportsUtils.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIWeakReference.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsrootidl.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsTraceRefcnt.h .\include + + $(MAKE_INSTALL) $(XPDIST)\include\nspr\pratom.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\nspr\prcpucfg.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\nspr\prlock.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\nspr\prlong.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\nspr\prtime.h .\include + $(MAKE_INSTALL) $(XPDIST)\include\nspr\prtypes.h .\include + + $(MAKE_INSTALL) $(DIST)\bin\regxpcom.exe .\bin + $(MAKE_INSTALL) $(DIST)\bin\xpidl.exe .\bin + $(MAKE_INSTALL) $(DIST)\bin\xpt_dump.exe .\bin diff --git a/mozilla/modules/plugin/tools/sdk/readme.txt b/mozilla/modules/plugin/tools/sdk/readme.txt new file mode 100644 index 00000000000..5907176487d --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/readme.txt @@ -0,0 +1,51 @@ +Last updated 10.02.2001 + +The current version of the Netscape Plugin API is designed to help +the developers to start creating plugins for Mozilla based browsers. + +This SDK is based on the API developed originally for Netscape browsers +starting with Netscape 2.x. Some additions have been made at the time +of release Netscape 3.x and Netscape 4.x. The present SDK reflects major +changes related to Mozilla code base: LiveConnect for plugin scriptability +is no longer supported, existing plugins should be modified slightly to +become scriptable again; the browser services are now accessible from +the plugin through the access to the service manager. + +The SDK is intended to help in creating full-blown plugins to work with +Mozilla code base without actually having the whole Mozilla source tree +present and built. + +The Common folder contains stub implementations of the NPAPI methods, there +is no need to modify files in this folder, just include them into your project. +This is not necessary though, some samples or plugin projects may use +there own implementations, the files in this folder are just an illustration +of one possible way to do that. + +The Samples section at this point contains the following plugin samples: + +1. Basic plugin + +Shows the bare bones of the plugin dll. It does not do anything special, +'Hello, World' type of thing. Demonstrates how the plugin dll is invoked +and how NPAPI methods are called. Can be used as a starting template for +writing your own plugin. + +2. Simple plugin + +This plugin example illustrates specific for Mozilla code base features. +It is scriptable via JavaScript and uses services provided by the browser. +Some xpcom interfaces are implemented here so the Mozilla browser is aware +of its capabilities. The plugin does not draw in the native window but +rather JavaScript box is used to display the result of its work. Therefore, +there are no separate projects for different platforms in this sample. + +3. Scriptable plugin + +Yet another example of plugin scriptability. This plugin implements two +native methods callable from the JavaScript and uses native window drawings. + +Scriptable samples require generation of .xpt files which should reside +in the Mozilla Components directory. To make sure Mozilla is aware of +the presence of the new .xpt file one may look at xpi.dat. To force +Mozilla to re-scan the Components directory xpi.dat should be removed +before Mozilla is started. \ No newline at end of file diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/test.html b/mozilla/modules/plugin/tools/sdk/samples/basic/test.html new file mode 100644 index 00000000000..006e3de71bd --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/test.html @@ -0,0 +1,16 @@ + + + +

Basic Plugin Example for Mozilla Test Case

+ +This test case is to demonstrate the Basic Plugin example. You should see the +plugin window with the black frame aroung it and the browser user agent string +which plugin draws inside the window. +

+ +
+ +
+ + + \ No newline at end of file diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/unix/makefile b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/makefile new file mode 100644 index 00000000000..af97d67caf4 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/makefile @@ -0,0 +1,50 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +# This makefile contains some of our defines for the compiler: +# +# XP_UNIX This needs to get defined for npapi.h on unix platforms. + +PLUGIN_DEFINES = -DXP_UNIX -I../../../include -I../../include -I../include +CCC = gcc +OPTIMIZER = -g +CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include + +CPPSRCS = ../../common/npn_gate.cpp \ + ../../common/npp_gate.cpp \ + ../../common/np_entry.cpp \ + plugin.cpp + +OBJS = $(strip $(CPPSRCS:.cpp=.o)) + +%.o: %.cpp makefile + $(CCC) -o $@ -c $(CFLAGS) $< + +SHAREDTARGET=npbasic.so + +default all: $(SHAREDTARGET) + +$(SHAREDTARGET): $(OBJS) + $(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS) + +clean: + $(RM) $(OBJS) $(SHAREDTARGET) + diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.cpp new file mode 100644 index 00000000000..50e390d73b1 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.cpp @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "plugin.h" + +#define MIME_TYPES_HANDLED "application/basic-plugin" +#define PLUGIN_NAME "Basic Example Plugin for Mozilla" +#define PLUGIN_DESCRIPTION "Basic Example Plugin for Mozilla" + +char* NPP_GetMIMEDescription(void) +{ + return(MIME_TYPES_HANDLED); +} + +///////////////////////////////////// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance) +{ + nsPluginInstance * plugin = new nsPluginInstance(aInstance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mWindow(0), + mInitialized(FALSE) +{ +} + +nsPluginInstance::~nsPluginInstance() +{ +} + +static void +xt_event_handler(Widget xtwidget, nsPluginInstance *plugin, XEvent *xevent, Boolean *b) +{ + switch (xevent->type) { + case Expose: + // get rid of all other exposure events + if (plugin) { + //while(XCheckTypedWindowEvent(plugin->Display(), plugin->Window(), Expose, xevent)); + plugin->draw(); + } + default: + break; + } +} + +void nsPluginInstance::draw() +{ + unsigned int h = mHeight/2; + unsigned int w = 3 * mWidth/4; + int x = (mWidth - w)/2; // center + int y = h/2; + XDrawRectangle(mDisplay, mWindow, mGC, x, y, w, h); + const char *string = getVersion(); + if (string && *string) { + int l = strlen(string); + int fmba = mFontInfo->max_bounds.ascent; + int fmbd = mFontInfo->max_bounds.descent; + int fh = fmba + fmbd; + y += fh; + x += 32; + XDrawString(mDisplay, mWindow, mGC, x, y, string, l); + } +} + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + + if(aWindow == NULL) + return FALSE; + + NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info; + mWindow = (Window) aWindow->window; + mX = aWindow->x; + mY = aWindow->y; + mWidth = aWindow->width; + mHeight = aWindow->height; + mDisplay = ws_info->display; + mVisual = ws_info->visual; + mDepth = ws_info->depth; + mColormap = ws_info->colormap; + mFontInfo = XLoadQueryFont(mDisplay, "9x15"); + if (!mFontInfo) { + printf("Cannot open 9X15 font\n"); + return FALSE; + } + mGC = XCreateGC(mDisplay, mWindow, 0, NULL); + + // add xt event handler + Widget xtwidget = XtWindowToWidget(mDisplay, mWindow); + if (xtwidget) { + long event_mask = ExposureMask; + XSelectInput(mDisplay, mWindow, event_mask); + XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this); + } + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + mInitialized = FALSE; +} + +const char * nsPluginInstance::getVersion() +{ + return NPN_UserAgent(mInstance); +} + +NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) +{ + NPError err = NPERR_NO_ERROR; + switch (aVariable) { + case NPPVpluginNameString: + *((char **)aValue) = PLUGIN_NAME; + break; + case NPPVpluginDescriptionString: + *((char **)aValue) = PLUGIN_DESCRIPTION; + break; + default: + break; + } + return err; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.h new file mode 100644 index 00000000000..f9703f7f0b4 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/unix/plugin.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +/* Xlib/Xt stuff */ +#include +#include +#include + +#include "pluginbase.h" + +class nsPluginInstance : public nsPluginInstanceBase +{ +public: + nsPluginInstance(NPP aInstance); + ~nsPluginInstance(); + + NPBool init(NPWindow* aWindow); + void shut(); + NPBool isInitialized() {return mInitialized;} + NPError GetValue(NPPVariable variable, void *value); + + // locals + const char * getVersion(); + void draw(); + +private: + NPP mInstance; + NPBool mInitialized; + + Window mWindow; + Display *mDisplay; + int mX, mY; + int mWidth, mHeight; + Visual* mVisual; + Colormap mColormap; + unsigned int mDepth; + XFontStruct *mFontInfo; + GC mGC; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.def b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.def new file mode 100644 index 00000000000..ba436738fc7 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.def @@ -0,0 +1,6 @@ +LIBRARY NPBASIC + +EXPORTS + NP_GetEntryPoints @1 + NP_Initialize @2 + NP_Shutdown @3 diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.rc b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.rc new file mode 100644 index 00000000000..49e1613a86a --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/basic.rc @@ -0,0 +1,112 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", " \0" + VALUE "FileDescription", "npbasic\0" + VALUE "FileExtents", "bic\0" + VALUE "FileOpenName", "npbasic\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "npbasic\0" + VALUE "LegalCopyright", "Copyright © 2001\0" + VALUE "LegalTrademarks", "\0" + VALUE "MIMEType", "application/basic-plugin\0" + VALUE "OriginalFilename", "npbasic.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "Basic Example Plugin for Mozilla\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // !_MAC + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsp b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsp new file mode 100644 index 00000000000..6780b653496 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsp @@ -0,0 +1,131 @@ +# Microsoft Developer Studio Project File - Name="npbasic" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=npbasic - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "npbasic.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "npbasic.mak" CFG="npbasic - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "npbasic - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "npbasic - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "npbasic - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPBASIC_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /I "..\..\..\include" /D "NDEBUG" /D "XP_WIN" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPBASIC_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /machine:I386 + +!ELSEIF "$(CFG)" == "npbasic - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPBASIC_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /I "..\..\..\include" /D "_DEBUG" /D "XP_WIN" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPBASIC_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "npbasic - Win32 Release" +# Name "npbasic - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\basic.def +# End Source File +# Begin Source File + +SOURCE=..\..\common\np_entry.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\common\npn_gate.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\common\npp_gate.cpp +# End Source File +# Begin Source File + +SOURCE=.\plugin.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\plugin.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\basic.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsw b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsw new file mode 100644 index 00000000000..439bdfe830f --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/npbasic.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "npbasic"=.\npbasic.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.cpp new file mode 100644 index 00000000000..3ee82ead7c0 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.cpp @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include +#include + +#include "plugin.h" + +////////////////////////////////////// +// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance) +{ + nsPluginInstance * plugin = new nsPluginInstance(aInstance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mInitialized(FALSE) +{ + mhWnd = NULL; +} + +nsPluginInstance::~nsPluginInstance() +{ +} + +static LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM); +static WNDPROC lpOldProc = NULL; + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + if(aWindow == NULL) + return FALSE; + + mhWnd = (HWND)aWindow->window; + if(mhWnd == NULL) + return FALSE; + + // subclass window so we can intercept window messages and + // do our drawing to it + lpOldProc = SubclassWindow(mhWnd, (WNDPROC)PluginWinProc); + + // associate window with our nsPluginInstance object so we can access + // it in the window procedure + SetWindowLong(mhWnd, GWL_USERDATA, (LONG)this); + + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + // subclass it back + SubclassWindow(mhWnd, lpOldProc); + mhWnd = NULL; + mInitialized = FALSE; +} + +NPBool nsPluginInstance::isInitialized() +{ + return mInitialized; +} + +const char * nsPluginInstance::getVersion() +{ + return NPN_UserAgent(mInstance); +} + +static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_PAINT: + { + // draw a frame and display the string + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + RECT rc; + GetClientRect(hWnd, &rc); + FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); + + // get our plugin instance object and ask it for the version string + nsPluginInstance *plugin = (nsPluginInstance *)GetWindowLong(hWnd, GWL_USERDATA); + if (plugin) { + const char * string = plugin->getVersion(); + DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + } + else { + char string[] = "Error occured"; + DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + } + + EndPaint(hWnd, &ps); + } + break; + default: + break; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.h new file mode 100644 index 00000000000..3bcc3469025 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/plugin.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +#include "pluginbase.h" + +class nsPluginInstance : public nsPluginInstanceBase +{ +public: + nsPluginInstance(NPP aInstance); + ~nsPluginInstance(); + + NPBool init(NPWindow* aWindow); + void shut(); + NPBool isInitialized(); + + // locals + const char * getVersion(); + +private: + NPP mInstance; + NPBool mInitialized; + HWND mhWnd; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/basic/windows/resource.h b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/resource.h new file mode 100644 index 00000000000..238cbec66a5 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/basic/windows/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by basic.rc +// +#define IDD_MAIN 101 +#define IDC_BUTTON_GO 1002 +#define IDC_STATIC_UA 1003 +#define IDC_BUTTON1 1005 +#define IDC_BUTTON_DONT 1005 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/mozilla/modules/plugin/tools/sdk/samples/common/np_entry.cpp b/mozilla/modules/plugin/tools/sdk/samples/common/np_entry.cpp new file mode 100644 index 00000000000..312aacfa421 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/common/np_entry.cpp @@ -0,0 +1,323 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +////////////////////////////////////////////////////////////// +// +// Main plugin entry point implementation -- exports from the +// plugin library +// +#include "npplat.h" +#include "pluginbase.h" + +NPNetscapeFuncs NPNFuncs; + +NPError OSCALL NP_Shutdown() +{ + NS_PluginShutdown(); + return NPERR_NO_ERROR; +} + +static NPError fillPluginFunctionTable(NPPluginFuncs* aNPPFuncs) +{ + if(aNPPFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(aNPPFuncs->size < sizeof(NPPluginFuncs)) + return NPERR_INVALID_FUNCTABLE_ERROR; + + aNPPFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; + aNPPFuncs->newp = NPP_New; + aNPPFuncs->destroy = NPP_Destroy; + aNPPFuncs->setwindow = NPP_SetWindow; + aNPPFuncs->newstream = NPP_NewStream; + aNPPFuncs->destroystream = NPP_DestroyStream; + aNPPFuncs->asfile = NPP_StreamAsFile; + aNPPFuncs->writeready = NPP_WriteReady; + aNPPFuncs->write = NPP_Write; + aNPPFuncs->print = NPP_Print; + aNPPFuncs->event = NPP_HandleEvent; + aNPPFuncs->urlnotify = NPP_URLNotify; + aNPPFuncs->getvalue = NPP_GetValue; + aNPPFuncs->setvalue = NPP_SetValue; + aNPPFuncs->javaClass = NULL; + + return NPERR_NO_ERROR; +} + +static NPError fillNetscapeFunctionTable(NPNetscapeFuncs* aNPNFuncs) +{ + if(aNPNFuncs == NULL) + return NPERR_INVALID_FUNCTABLE_ERROR; + + if(HIBYTE(aNPNFuncs->version) > NP_VERSION_MAJOR) + return NPERR_INCOMPATIBLE_VERSION_ERROR; + + if(aNPNFuncs->size < sizeof(NPNetscapeFuncs)) + return NPERR_INVALID_FUNCTABLE_ERROR; + + NPNFuncs.size = aNPNFuncs->size; + NPNFuncs.version = aNPNFuncs->version; + NPNFuncs.geturlnotify = aNPNFuncs->geturlnotify; + NPNFuncs.geturl = aNPNFuncs->geturl; + NPNFuncs.posturlnotify = aNPNFuncs->posturlnotify; + NPNFuncs.posturl = aNPNFuncs->posturl; + NPNFuncs.requestread = aNPNFuncs->requestread; + NPNFuncs.newstream = aNPNFuncs->newstream; + NPNFuncs.write = aNPNFuncs->write; + NPNFuncs.destroystream = aNPNFuncs->destroystream; + NPNFuncs.status = aNPNFuncs->status; + NPNFuncs.uagent = aNPNFuncs->uagent; + NPNFuncs.memalloc = aNPNFuncs->memalloc; + NPNFuncs.memfree = aNPNFuncs->memfree; + NPNFuncs.memflush = aNPNFuncs->memflush; + NPNFuncs.reloadplugins = aNPNFuncs->reloadplugins; + NPNFuncs.getJavaEnv = aNPNFuncs->getJavaEnv; + NPNFuncs.getJavaPeer = aNPNFuncs->getJavaPeer; + NPNFuncs.getvalue = aNPNFuncs->getvalue; + NPNFuncs.setvalue = aNPNFuncs->setvalue; + NPNFuncs.invalidaterect = aNPNFuncs->invalidaterect; + NPNFuncs.invalidateregion = aNPNFuncs->invalidateregion; + NPNFuncs.forceredraw = aNPNFuncs->forceredraw; + + return NPERR_NO_ERROR; +} + +// +// Some exports are different on different platforms +// + +/**************************************************/ +/* */ +/* Windows */ +/* */ +/**************************************************/ +#ifdef XP_WIN + +NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs) +{ + NPError rv = fillNetscapeFunctionTable(aNPNFuncs); + if(rv != NPERR_NO_ERROR) + return rv; + + return NS_PluginInitialize(); +} + +NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* aNPPFuncs) +{ + return fillPluginFunctionTable(aNPPFuncs); +} + +#endif //XP_WIN + +/**************************************************/ +/* */ +/* Unix */ +/* */ +/**************************************************/ +#ifdef XP_UNIX + +NPError NP_Initialize(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs) +{ + NPError rv = fillNetscapeFunctionTable(aNPNFuncs); + if(rv != NPERR_NO_ERROR) + return rv; + + rv = fillPluginFunctionTable(aNPPFuncs); + if(rv != NPERR_NO_ERROR) + return rv; + + return NS_PluginInitialize(); +} + +char * NP_GetMIMEDescription(void) +{ + return NPP_GetMIMEDescription(); +} + +NPError NP_GetValue(void *future, NPPVariable aVariable, void *aValue) +{ + return NPP_GetValue((NPP_t *)future, aVariable, aValue); +} + +#endif //XP_UNIX + +/**************************************************/ +/* */ +/* Mac */ +/* */ +/**************************************************/ +#ifdef XP_MAC + +#if !TARGET_API_MAC_CARBON +QDGlobals* gQDPtr; // Pointer to Netscape's QuickDraw globals +#endif + +short gResFile; // Refnum of the plugin's resource file + +NPError Private_Initialize(void) +{ + EnterCodeResource(); + NPError rv = NS_PluginInitialize(); + ExitCodeResource(); + return rv; +} + +void Private_Shutdown(void) +{ + EnterCodeResource(); + NS_PluginShutdown(); + __destroy_global_chain(); + ExitCodeResource(); +} + +void SetUpQD(void); + +void SetUpQD(void) +{ + ProcessSerialNumber PSN; + FSSpec myFSSpec; + Str63 name; + ProcessInfoRec infoRec; + OSErr result = noErr; + CFragConnectionID connID; + Str255 errName; + + // Memorize the plugin¹s resource file refnum for later use. + gResFile = CurResFile(); + +#if !TARGET_API_MAC_CARBON + // Ask the system if CFM is available. + long response; + OSErr err = Gestalt(gestaltCFMAttr, &response); + Boolean hasCFM = BitTst(&response, 31-gestaltCFMPresent); + + if (hasCFM) { + // GetProcessInformation takes a process serial number and + // will give us back the name and FSSpec of the application. + // See the Process Manager in IM. + infoRec.processInfoLength = sizeof(ProcessInfoRec); + infoRec.processName = name; + infoRec.processAppSpec = &myFSSpec; + + PSN.highLongOfPSN = 0; + PSN.lowLongOfPSN = kCurrentProcess; + + result = GetProcessInformation(&PSN, &infoRec); + } + else + // If no CFM installed, assume it must be a 68K app. + result = -1; + + if (result == noErr) { + // Now that we know the app name and FSSpec, we can call GetDiskFragment + // to get a connID to use in a subsequent call to FindSymbol (it will also + // return the address of ³main² in app, which we ignore). If GetDiskFragment + // returns an error, we assume the app must be 68K. + Ptr mainAddr; + result = GetDiskFragment(infoRec.processAppSpec, 0L, 0L, infoRec.processName, + kReferenceCFrag, &connID, (Ptr*)&mainAddr, errName); + } + + if (result == noErr) { + // The app is a PPC code fragment, so call FindSymbol + // to get the exported ³qd² symbol so we can access its + // QuickDraw globals. + CFragSymbolClass symClass; + result = FindSymbol(connID, "\pqd", (Ptr*)&gQDPtr, &symClass); + } + else { + // The app is 68K, so use its A5 to compute the address + // of its QuickDraw globals. + gQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr))); + } +#endif /* !TARGET_API_MAC_CARBON */ +} + +NPError main(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs, NPP_ShutdownUPP* aUnloadUpp); + +#pragma export on + +#if !TARGET_API_MAC_CARBON +RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(uppNPP_MainEntryProcInfo, main); +#endif + +#pragma export off + +NPError main(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs, NPP_ShutdownUPP* aUnloadUpp) +{ + EnterCodeResource(); + NPError rv = NPERR_NO_ERROR; + + if (aUnloadUpp == NULL) + rv = NPERR_INVALID_FUNCTABLE_ERROR; + + if (rv == NPERR_NO_ERROR) + rv = fillNetscapeFunctionTable(aNPNFuncs); + + if (rv == NPERR_NO_ERROR) { + // defer static constructors until the global functions are initialized. + __InitCode__(); + + // 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->event = NewNPP_HandleEventProc(Private_HandleEvent); + pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify); + pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue); + pluginFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue); + pluginFuncs->javaClass = NULL; + } + + *aUnloadUpp = NewNPP_ShutdownProc(Private_Shutdown); + SetUpQD(); + rv = Private_Initialize(); + + ExitCodeResource(); + return rv; +} +#endif //XP_MAC diff --git a/mozilla/modules/plugin/tools/sdk/samples/common/npn_gate.cpp b/mozilla/modules/plugin/tools/sdk/samples/common/npn_gate.cpp new file mode 100644 index 00000000000..5d595208d7a --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/common/npn_gate.cpp @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +//////////////////////////////////////////////////////////// +// +// Implementation of Netscape entry points (NPN_*) +// +#include "npplat.h" + +extern NPNetscapeFuncs NPNFuncs; + +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; + *netscape_major = HIBYTE(NPNFuncs.version); + *netscape_minor = LOBYTE(NPNFuncs.version); +} + +NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + NPError rv = NPERR_NO_ERROR; + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = CallNPN_GetURLNotifyProc(NPNFuncs.geturlnotify, instance, url, target, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + return rv; +} + +NPError NPN_GetURL(NPP instance, const char *url, const char *target) +{ + NPError rv = CallNPN_GetURLProc(NPNFuncs.geturl, instance, url, target); + return rv; +} + +NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData) +{ + int navMinorVers = NPNFuncs.version & 0xFF; + NPError rv = NPERR_NO_ERROR; + + if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) + rv = CallNPN_PostURLNotifyProc(NPNFuncs.posturlnotify, instance, url, window, len, buf, file, notifyData); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + return rv; +} + +NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file) +{ + NPError rv = CallNPN_PostURLProc(NPNFuncs.posturl, instance, url, window, len, buf, file); + return rv; +} + +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) +{ + NPError rv = CallNPN_RequestReadProc(NPNFuncs.requestread, stream, rangeList); + return rv; +} + +NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + + NPError rv = NPERR_NO_ERROR; + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = CallNPN_NewStreamProc(NPNFuncs.newstream, instance, type, target, stream); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + return rv; +} + +int32 NPN_Write(NPP instance, NPStream *stream, int32 len, void *buffer) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + int32 rv = 0; + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = CallNPN_WriteProc(NPNFuncs.write, instance, stream, len, buffer); + else + rv = -1; + + return rv; +} + +NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + int navMinorVersion = NPNFuncs.version & 0xFF; + NPError rv = NPERR_NO_ERROR; + + if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) + rv = CallNPN_DestroyStreamProc(NPNFuncs.destroystream, instance, stream, reason); + else + rv = NPERR_INCOMPATIBLE_VERSION_ERROR; + + return rv; +} + +void NPN_Status(NPP instance, const char *message) +{ + CallNPN_StatusProc(NPNFuncs.status, instance, message); +} + +const char* NPN_UserAgent(NPP instance) +{ + const char * rv = NULL; + rv = CallNPN_UserAgentProc(NPNFuncs.uagent, instance); + return rv; +} + +void* NPN_MemAlloc(uint32 size) +{ + void * rv = NULL; + rv = CallNPN_MemAllocProc(NPNFuncs.memalloc, size); + return rv; +} + +void NPN_MemFree(void* ptr) +{ + CallNPN_MemFreeProc(NPNFuncs.memfree, ptr); +} + +uint32 NPN_MemFlush(uint32 size) +{ + uint32 rv = CallNPN_MemFlushProc(NPNFuncs.memflush, size); + return rv; +} + +void NPN_ReloadPlugins(NPBool reloadPages) +{ + CallNPN_ReloadPluginsProc(NPNFuncs.reloadplugins, reloadPages); +} + +JRIEnv* NPN_GetJavaEnv(void) +{ + JRIEnv * rv = NULL; + rv = CallNPN_GetJavaEnvProc(NPNFuncs.getJavaEnv); + return rv; +} + +jref NPN_GetJavaPeer(NPP instance) +{ + jref rv; + rv = CallNPN_GetJavaPeerProc(NPNFuncs.getJavaPeer, instance); + return rv; +} + +NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value) +{ + NPError rv = CallNPN_GetValueProc(NPNFuncs.getvalue, instance, variable, value); + return rv; +} + +NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value) +{ + NPError rv = CallNPN_SetValueProc(NPNFuncs.setvalue, instance, variable, value); + return rv; +} + +void NPN_InvalidateRect(NPP instance, NPRect *invalidRect) +{ + CallNPN_InvalidateRectProc(NPNFuncs.invalidaterect, instance, invalidRect); +} + +void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion) +{ + CallNPN_InvalidateRegionProc(NPNFuncs.invalidateregion, instance, invalidRegion); +} + +void NPN_ForceRedraw(NPP instance) +{ + CallNPN_ForceRedrawProc(NPNFuncs.forceredraw, instance); +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/common/npp_gate.cpp b/mozilla/modules/plugin/tools/sdk/samples/common/npp_gate.cpp new file mode 100644 index 00000000000..af3d7835734 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/common/npp_gate.cpp @@ -0,0 +1,371 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +//////////////////////////////////////////////////////////// +// +// Implementation of plugin entry points (NPP_*) +// +#include "pluginbase.h" + +// here the plugin creates a plugin instance object which +// will be associated with this newly created NPP instance and +// will do all the neccessary job +NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + NPError rv = NPERR_NO_ERROR; + + // create a new plugin instance object + // initialization will be done when the associated window is ready + nsPluginInstanceBase * plugin = NS_NewPluginInstance(instance); + if(plugin == NULL) + return NPERR_OUT_OF_MEMORY_ERROR; + + // associate the plugin instance object with NPP instance + instance->pdata = (void *)plugin; + return rv; +} + +// here is the place to clean up and destroy the nsPluginInstance object +NPError NPP_Destroy (NPP instance, NPSavedData** save) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + NPError rv = NPERR_NO_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin != NULL) { + plugin->shut(); + NS_DestroyPluginInstance(plugin); + } + return rv; +} + +// during this call we know when the plugin window is ready or +// is about to be destroyed so we can do some gui specific +// initialization and shutdown +NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + NPError rv = NPERR_NO_ERROR; + + if(pNPWindow == NULL) + return NPERR_GENERIC_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + + if(plugin == NULL) + return NPERR_GENERIC_ERROR; + + // window just created + if(!plugin->isInitialized() && (pNPWindow->window != NULL)) { + if(!plugin->init(pNPWindow)) { + NS_DestroyPluginInstance(plugin); + return NPERR_MODULE_LOAD_FAILED_ERROR; + } + } + + // window goes away + if((pNPWindow->window == NULL) && plugin->isInitialized()) + return plugin->SetWindow(pNPWindow); + + // window resized? + if(plugin->isInitialized() && (pNPWindow->window != NULL)) + return plugin->SetWindow(pNPWindow); + + // this should not happen, nothing to do + if((pNPWindow->window == NULL) && !plugin->isInitialized()) + return plugin->SetWindow(pNPWindow); + + return rv; +} + +NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return NPERR_GENERIC_ERROR; + + NPError rv = plugin->NewStream(type, stream, seekable, stype); + return rv; +} + +int32 NPP_WriteReady (NPP instance, NPStream *stream) +{ + if(instance == NULL) + return 0x0fffffff; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return 0x0fffffff; + + int32 rv = plugin->WriteReady(stream); + return rv; +} + +int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) +{ + if(instance == NULL) + return len; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return len; + + int32 rv = plugin->Write(stream, offset, len, buffer); + return rv; +} + +NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return NPERR_GENERIC_ERROR; + + NPError rv = plugin->DestroyStream(stream, reason); + return rv; +} + +void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname) +{ + if(instance == NULL) + return; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return; + + plugin->StreamAsFile(stream, fname); +} + +void NPP_Print (NPP instance, NPPrint* printInfo) +{ + if(instance == NULL) + return; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return; + + plugin->Print(printInfo); +} + +void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + if(instance == NULL) + return; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return; + + plugin->URLNotify(url, reason, notifyData); +} + +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return NPERR_GENERIC_ERROR; + + NPError rv = plugin->GetValue(variable, value); + return rv; +} + +NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) +{ + if(instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return NPERR_GENERIC_ERROR; + + NPError rv = plugin->SetValue(variable, value); + return rv; +} + +int16 NPP_HandleEvent(NPP instance, void* event) +{ + if(instance == NULL) + return 0; + + nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; + if(plugin == NULL) + return 0; + + uint16 rv = plugin->HandleEvent(event); + return rv; +} + +jref NPP_GetJavaClass (void) +{ + return NULL; +} + +/**************************************************/ +/* */ +/* Mac */ +/* */ +/**************************************************/ + +// Mac needs these wrappers, see npplat.h for more info + +#ifdef XP_MAC + +NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + EnterCodeResource(); + NPError rv = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); + ExitCodeResource(); + return rv; +} + +NPError Private_Destroy(NPP instance, NPSavedData** save) +{ + EnterCodeResource(); + NPError rv = NPP_Destroy(instance, save); + ExitCodeResource(); + return rv; +} + +NPError Private_SetWindow(NPP instance, NPWindow* window) +{ + EnterCodeResource(); + NPError rv = NPP_SetWindow(instance, window); + ExitCodeResource(); + return rv; +} + +NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) +{ + EnterCodeResource(); + NPError rv = NPP_NewStream(instance, type, stream, seekable, stype); + ExitCodeResource(); + return rv; +} + +int32 Private_WriteReady(NPP instance, NPStream* stream) +{ + EnterCodeResource(); + int32 rv = NPP_WriteReady(instance, stream); + ExitCodeResource(); + return rv; +} + +int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) +{ + EnterCodeResource(); + int32 rv = NPP_Write(instance, stream, offset, len, buffer); + ExitCodeResource(); + return rv; +} + +void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname) +{ + EnterCodeResource(); + NPP_StreamAsFile(instance, stream, fname); + ExitCodeResource(); +} + + +NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + EnterCodeResource(); + NPError rv = NPP_DestroyStream(instance, stream, reason); + ExitCodeResource(); + return rv; +} + +int16 Private_HandleEvent(NPP instance, void* event) +{ + EnterCodeResource(); + int16 rv = NPP_HandleEvent(instance, event); + ExitCodeResource(); + return rv; +} + +void Private_Print(NPP instance, NPPrint* platformPrint) +{ + EnterCodeResource(); + NPP_Print(instance, platformPrint); + ExitCodeResource(); +} + +void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) +{ + EnterCodeResource(); + NPP_URLNotify(instance, url, reason, notifyData); + ExitCodeResource(); +} + +jref Private_GetJavaClass(void) +{ + return NULL; +} + +NPError Private_GetValue(NPP instance, NPPVariable variable, void *result) +{ + EnterCodeResource(); + NPError rv = NPP_GetValue(instance, variable, result); + ExitCodeResource(); + return rv; +} + +NPError Private_SetValue(NPP instance, NPNVariable variable, void *value) +{ + EnterCodeResource(); + NPError rv = NPP_SetValue(instance, variable, value); + ExitCodeResource(); + return rv; +} + +#endif //XP_MAC diff --git a/mozilla/modules/plugin/tools/sdk/samples/include/npplat.h b/mozilla/modules/plugin/tools/sdk/samples/include/npplat.h new file mode 100644 index 00000000000..d12efff7f1b --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/include/npplat.h @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _NPPLAT_H_ +#define _NPPLAT_H_ + +/**************************************************/ +/* */ +/* Windows */ +/* */ +/**************************************************/ +#ifdef XP_WIN + +#include "windows.h" + +#include "npapi.h" +#include "npupp.h" + +#endif //XP_WIN + +/**************************************************/ +/* */ +/* Unix */ +/* */ +/**************************************************/ +#ifdef XP_UNIX + +#include + +#include "npapi.h" +#include "npupp.h" + +#define HIBYTE(i) (i >> 8) +#define LOBYTE(i) (i & 0xff) + +#endif //XP_UNIX + +/**************************************************/ +/* */ +/* Mac */ +/* */ +/**************************************************/ +#ifdef XP_MAC + +#include +#include +#include +#include +#include +#include + +// A4Stuff.h contains the definition of EnterCodeResource and +// EnterCodeResource, used for setting up the code resource¹s +// globals for 68K (analagous to the function SetCurrentA5 +// defined by the toolbox). +// +#include + +#include "jri.h" +#include "npapi.h" + +// The Mixed Mode procInfos defined in npupp.h assume Think C- +// style calling conventions. These conventions are used by +// Metrowerks with the exception of pointer return types, which +// in Metrowerks 68K are returned in A0, instead of the standard +// D0. Thus, since NPN_MemAlloc and NPN_UserAgent return pointers, +// Mixed Mode will return the values to a 68K plugin in D0, but +// a 68K plugin compiled by Metrowerks will expect the result in +// A0. The following pragma forces Metrowerks to use D0 instead. +// +#ifdef __MWERKS__ +#ifndef powerc +#pragma pointers_in_D0 +#endif +#endif + +#include "npupp.h" + +#ifdef __MWERKS__ +#ifndef powerc +#pragma pointers_in_A0 +#endif +#endif + +// The following fix for static initializers (which fixes a preious +// incompatibility with some parts of PowerPlant, was submitted by +// Jan Ulbrich. +#ifdef __MWERKS__ + #ifdef __cplusplus + extern "C" { + #endif + #ifndef powerc + extern void __InitCode__(void); + #else + extern void __sinit(void); + #define __InitCode__ __sinit + #endif + extern void __destroy_global_chain(void); + #ifdef __cplusplus + } + #endif // __cplusplus +#endif // __MWERKS__ + +// Wrapper functions for all calls from Netscape to the 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. +NPError Private_Initialize(void); +void Private_Shutdown(void); +NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); +NPError Private_Destroy(NPP instance, NPSavedData** save); +NPError Private_SetWindow(NPP instance, NPWindow* window); +NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); +NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason); +int32 Private_WriteReady(NPP instance, NPStream* stream); +int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); +void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname); +void Private_Print(NPP instance, NPPrint* platformPrint); +int16 Private_HandleEvent(NPP instance, void* event); +void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData); +jref Private_GetJavaClass(void); +NPError Private_GetValue(NPP instance, NPPVariable variable, void *result); +NPError Private_SetValue(NPP instance, NPNVariable variable, void *value); + +#endif //XP_MAC + +#endif //_NPPLAT_H_ diff --git a/mozilla/modules/plugin/tools/sdk/samples/include/pluginbase.h b/mozilla/modules/plugin/tools/sdk/samples/include/pluginbase.h new file mode 100644 index 00000000000..aedcb318a50 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/include/pluginbase.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGININSTANCEBASE_H__ +#define __PLUGININSTANCEBASE_H__ + +#include "npplat.h" + +class nsPluginInstanceBase +{ +public: + // these three methods must be implemented in the derived + // class platform specific way + virtual NPBool init(NPWindow* aWindow) = 0; + virtual void shut() = 0; + virtual NPBool isInitialized() = 0; + + // implement all or part of those methods in the derived + // class as needed + virtual NPError SetWindow(NPWindow* pNPWindow) { return NPERR_NO_ERROR; } + virtual NPError NewStream(NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stype) { return NPERR_NO_ERROR; } + virtual NPError DestroyStream(NPStream *stream, NPError reason) { return NPERR_NO_ERROR; } + virtual void StreamAsFile(NPStream* stream, const char* fname) { return; } + virtual int32 WriteReady(NPStream *stream) { return 0x0fffffff; } + virtual int32 Write(NPStream *stream, int32 offset, + int32 len, void *buffer) { return len; } + virtual void Print(NPPrint* printInfo) { return; } + virtual uint16 HandleEvent(void* event) { return 0; } + virtual void URLNotify(const char* url, NPReason reason, + void* notifyData) { return; } + virtual NPError GetValue(NPPVariable variable, void *value) { return NPERR_NO_ERROR; } + virtual NPError SetValue(NPNVariable variable, void *value) { return NPERR_NO_ERROR; } +}; + +// functions that should be implemented for each specific plugin + +// creation and destruction of the object of the derived class +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance); +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin); + +// global plugin initialization and shutdown +NPError NS_PluginInitialize(); +void NS_PluginShutdown(); + +#endif // __PLUGININSTANCEBASE_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/test.html b/mozilla/modules/plugin/tools/sdk/samples/scriptable/test.html new file mode 100644 index 00000000000..171980ddf7a --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/test.html @@ -0,0 +1,48 @@ + + +4x Scriptable Plug-in Test + + + +
+

XPConnect Scriptable Sample Plug-in

+
+ +This page contains a test case which demonstrates the work of scriptable plug-in +with Mozilla. The example plug-in occupies the area right below this text, +and you should see a frame the plug-in draws around its window. Below the plug-in window +there are two buttons. Clicking on the buttons will result in calling native plugin +methods from JavaScript. Show Version will instruct the plug-in to retrieve the +Mozilla user agent string and display it in the plug-in window, Clear button will +call plug-in method to erase the window. + +

+ +
+ +
+ + + +
+
+ + +
+ +
+ + + diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/makefile b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/makefile new file mode 100644 index 00000000000..938ccbb07fd --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/makefile @@ -0,0 +1,50 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +# This makefile contains some of our defines for the compiler: +# +# XP_UNIX This needs to get defined for npapi.h on unix platforms. + +PLUGIN_DEFINES = -DXP_UNIX -I../../../include -I../../include -I../include +CCC = gcc +OPTIMIZER = -g +CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include + +CPPSRCS = ../../common/npn_gate.cpp \ + ../../common/npp_gate.cpp \ + ../../common/np_entry.cpp \ + plugin.cpp + +OBJS = $(strip $(CPPSRCS:.cpp=.o)) + +%.o: %.cpp makefile + $(CCC) -o $@ -c $(CFLAGS) $< + +SHAREDTARGET=npscriptable.so + +default all: $(SHAREDTARGET) + +$(SHAREDTARGET): $(OBJS) + $(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS) + +clean: + $(RM) $(OBJS) $(SHAREDTARGET) + diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/nsIScriptablePlugin.idl b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/nsIScriptablePlugin.idl new file mode 100644 index 00000000000..37972f706a5 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/nsIScriptablePlugin.idl @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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 Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +[scriptable, uuid(d2d536a0-b6fc-11d5-9d10-0060b0fbd8ac)] +interface nsIScriptablePlugin : nsISupports { + void showVersion(); + void clear(); +}; diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.cpp new file mode 100644 index 00000000000..662482d2baa --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.cpp @@ -0,0 +1,261 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include +#include +#include + +#include "plugin.h" +#include "nsIServiceManager.h" + +#define MIME_TYPES_HANDLED "application/scriptable-plugin" +#define PLUGIN_NAME "Scriptable Example Plugin for Mozilla" +#define PLUGIN_DESCRIPTION "Scriptable Example Plugin for Mozilla" + +char* NPP_GetMIMEDescription(void) +{ + return(MIME_TYPES_HANDLED); +} + +////////////////////////////////////// +// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance) +{ + nsPluginInstance * plugin = new nsPluginInstance(aInstance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mInitialized(FALSE), + mWindow(0), + mScriptablePeer(NULL) +{ + mString[0] = '\0'; +} + +nsPluginInstance::~nsPluginInstance() +{ + NS_IF_RELEASE(mScriptablePeer); +} + +static void +xt_event_handler(Widget xtwidget, nsPluginInstance *plugin, XEvent *xevent, Boolean *b) +{ + switch (xevent->type) { + case Expose: + // get rid of all other exposure events + if (plugin) { + //while(XCheckTypedWindowEvent(plugin->Display(), plugin->Window(), Expose, xevent)); + plugin->draw(); + } + default: + break; + } +} + +void nsPluginInstance::draw() +{ + unsigned int h = mHeight/2; + unsigned int w = 3 * mWidth/4; + int x = (mWidth - w)/2; // center + int y = h/2; + XDrawRectangle(mDisplay, mWindow, mGC, x, y, w, h); + + int l = strlen(mString); + int fmba = mFontInfo->max_bounds.ascent; + int fmbd = mFontInfo->max_bounds.descent; + int fh = fmba + fmbd; + y += fh; + x += 32; + XDrawString(mDisplay, mWindow, mGC, x, y, mString, l); +} + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + if(aWindow == NULL) + return FALSE; + + NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info; + mWindow = (Window) aWindow->window; + mX = aWindow->x; + mY = aWindow->y; + mWidth = aWindow->width; + mHeight = aWindow->height; + mDisplay = ws_info->display; + mVisual = ws_info->visual; + mDepth = ws_info->depth; + mColormap = ws_info->colormap; + mFontInfo = XLoadQueryFont(mDisplay, "9x15"); + if (!mFontInfo) { + printf("Cannot open 9X15 font\n"); + return FALSE; + } + mGC = XCreateGC(mDisplay, mWindow, 0, NULL); + + // add xt event handler + Widget xtwidget = XtWindowToWidget(mDisplay, mWindow); + if (xtwidget) { + long event_mask = ExposureMask; + XSelectInput(mDisplay, mWindow, event_mask); + XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this); + } + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + mInitialized = FALSE; +} + +NPBool nsPluginInstance::isInitialized() +{ + return mInitialized; +} + +// this will force to draw a version string in the plugin window +void nsPluginInstance::showVersion() +{ + const char *ua = NPN_UserAgent(mInstance); + strcpy(mString, ua); + draw(); +} + +// this will clean the plugin window +void nsPluginInstance::clear() +{ + strcpy(mString, ""); + draw(); +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// here the plugin is asked by Mozilla to tell if it is scriptable +// we should return a valid interface id and a pointer to +// nsScriptablePeer interface which we should have implemented +// and which should be defined in the corressponding *.xpt file +// in the bin/components folder +NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) +{ + NPError rv = NPERR_NO_ERROR; + + switch (aVariable) { + case NPPVpluginScriptableInstance: { + // addref happens in getter, so we don't addref here + nsISimplePlugin * scriptablePeer = getScriptablePeer(); + if (scriptablePeer) { + *(nsISupports **)aValue = scriptablePeer; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + + case NPPVpluginScriptableIID: { + static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID; + nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID)); + if (ptr) { + *ptr = scriptableIID; + *(nsIID **)aValue = ptr; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + + case NPPVpluginNameString: + *((char **)aValue) = PLUGIN_NAME; + break; + case NPPVpluginDescriptionString: + *((char **)aValue) = PLUGIN_DESCRIPTION; + break; + + default: + break; + } + + return rv; +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// this method will return the scriptable object (and create it if necessary) +nsIScriptablePlugin* nsPluginInstance::getScriptablePeer() +{ + if (!mScriptablePeer) { + mScriptablePeer = new nsScriptablePeer(this); + if(!mScriptablePeer) + return NULL; + + NS_ADDREF(mScriptablePeer); + } + + // add reference for the caller requesting the object + NS_ADDREF(mScriptablePeer); + return mScriptablePeer; + + return NULL; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.h new file mode 100644 index 00000000000..62750423f63 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/unix/plugin.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +#include "pluginbase.h" +#include "nsScriptablePeer.h" + +class nsPluginInstance : public nsPluginInstanceBase +{ +public: + nsPluginInstance(NPP aInstance); + ~nsPluginInstance(); + + NPBool init(NPWindow* aWindow); + void shut(); + NPBool isInitialized(); + + NPError GetValue(NPPVariable variable, void *value); + + // locals + void showVersion(); + void clear(); + void draw(); + + nsIScriptablePlugin* getScriptablePeer(); + +private: + NPP mInstance; + + Window mWindow; + Display *mDisplay; + int mX, mY; + int mWidth, mHeight; + Visual* mVisual; + Colormap mColormap; + unsigned int mDepth; + XFontStruct *mFontInfo; + GC mGC; + + nsIScriptablePlugin * mScriptablePeer; + +public: + char mString[128]; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.def b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.def new file mode 100644 index 00000000000..d510319da3f --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.def @@ -0,0 +1,6 @@ +LIBRARY NPSCRIPTABLE + +EXPORTS + NP_GetEntryPoints @1 + NP_Initialize @2 + NP_Shutdown @3 diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsp b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsp new file mode 100644 index 00000000000..977a058653d --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsp @@ -0,0 +1,139 @@ +# Microsoft Developer Studio Project File - Name="npscriptable" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=npscriptable - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "npscriptable.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "npscriptable.mak" CFG="npscriptable - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "npscriptable - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "npscriptable - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "npscriptable - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSCRIPTABLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\include" /I "..\..\..\include" /D "NDEBUG" /D "XP_WIN" /D "XP_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSCRIPTABLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /machine:I386 + +!ELSEIF "$(CFG)" == "npscriptable - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "npscriptable___Win32_Debug" +# PROP BASE Intermediate_Dir "npscriptable___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSCRIPTABLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\include" /I "..\..\..\include" /D "_DEBUG" /D "XP_WIN" /D "XP_WIN32" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSCRIPTABLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "npscriptable - Win32 Release" +# Name "npscriptable - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\common\np_entry.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\common\npn_gate.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\common\npp_gate.cpp +# End Source File +# Begin Source File + +SOURCE=.\npscriptable.def +# End Source File +# Begin Source File + +SOURCE=.\nsScriptablePeer.cpp +# End Source File +# Begin Source File + +SOURCE=.\plugin.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\nsScriptablePeer.h +# End Source File +# Begin Source File + +SOURCE=.\plugin.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\npscriptable.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsw b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsw new file mode 100644 index 00000000000..5432d327f1c --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "npscriptable"=.\npscriptable.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.rc b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.rc new file mode 100644 index 00000000000..a9135e647de --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/npscriptable.rc @@ -0,0 +1,112 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", " \0" + VALUE "FileDescription", "npscriptable\0" + VALUE "FileExtents", "scr\0" + VALUE "FileOpenName", "npscriptable\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "npscriptable\0" + VALUE "LegalCopyright", "Copyright © 2001\0" + VALUE "LegalTrademarks", "\0" + VALUE "MIMEType", "application/scriptable-plugin\0" + VALUE "OriginalFilename", "npscriptable.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "Scriptable Plugin Example for Mozilla\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // !_MAC + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsIScriptablePlugin.idl b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsIScriptablePlugin.idl new file mode 100644 index 00000000000..37972f706a5 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsIScriptablePlugin.idl @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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 Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +[scriptable, uuid(d2d536a0-b6fc-11d5-9d10-0060b0fbd8ac)] +interface nsIScriptablePlugin : nsISupports { + void showVersion(); + void clear(); +}; diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.cpp b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.cpp new file mode 100644 index 00000000000..404b38cb7e9 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.cpp @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, 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 "plugin.h" + +static NS_DEFINE_IID(kIScriptableIID, NS_ISCRIPTABLEPLUGIN_IID); +static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsScriptablePeer::nsScriptablePeer(nsPluginInstance* aPlugin) +{ + mPlugin = aPlugin; + mRefCnt = 0; +} + +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) +{ + if(!aInstancePtr) + return NS_ERROR_NULL_POINTER; + + if(aIID.Equals(kIScriptableIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kIClassInfoIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kISupportsIID)) { + *aInstancePtr = static_cast(static_cast(this)); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +// +// the following methods will be callable from JavaScript +// +NS_IMETHODIMP nsScriptablePeer::ShowVersion() +{ + if (mPlugin) + mPlugin->showVersion(); + + return NS_OK; +} + +NS_IMETHODIMP nsScriptablePeer::Clear() +{ + if (mPlugin) + mPlugin->clear(); + + return NS_OK; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.h b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.h new file mode 100644 index 00000000000..15467e287b3 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/nsScriptablePeer.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// nsScriptablePeer - xpconnect scriptable peer +// + +#ifndef __nsScriptablePeer_h__ +#define __nsScriptablePeer_h__ + +#include "nsIScriptablePlugin.h" +#include "nsIClassInfo.h" + +class nsPluginInstance; + +// 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 nsIScriptablePlugin, + public nsClassInfoMixin +{ +public: + nsScriptablePeer(nsPluginInstance* plugin); + ~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_NSISCRIPTABLEPLUGIN + +protected: + nsPluginInstance* mPlugin; +}; + +#endif \ No newline at end of file diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.cpp new file mode 100644 index 00000000000..6dffe2f4e41 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.cpp @@ -0,0 +1,230 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include +#include + +#include "plugin.h" +#include "nsIServiceManager.h" + +////////////////////////////////////// +// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance) +{ + nsPluginInstance * plugin = new nsPluginInstance(aInstance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mInitialized(FALSE), + mScriptablePeer(NULL) +{ + mhWnd = NULL; + mString[0] = '\0'; +} + +nsPluginInstance::~nsPluginInstance() +{ + NS_IF_RELEASE(mScriptablePeer); +} + +static LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM); +static WNDPROC lpOldProc = NULL; + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + if(aWindow == NULL) + return FALSE; + + mhWnd = (HWND)aWindow->window; + if(mhWnd == NULL) + return FALSE; + + // subclass window so we can intercept window messages and + // do our drawing to it + lpOldProc = SubclassWindow(mhWnd, (WNDPROC)PluginWinProc); + + // associate window with our nsPluginInstance object so we can access + // it in the window procedure + SetWindowLong(mhWnd, GWL_USERDATA, (LONG)this); + + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + // subclass it back + SubclassWindow(mhWnd, lpOldProc); + mhWnd = NULL; + mInitialized = FALSE; +} + +NPBool nsPluginInstance::isInitialized() +{ + return mInitialized; +} + +// this will force to draw a version string in the plugin window +void nsPluginInstance::showVersion() +{ + const char *ua = NPN_UserAgent(mInstance); + strcpy(mString, ua); + InvalidateRect(mhWnd, NULL, TRUE); + UpdateWindow(mhWnd); +} + +// this will clean the plugin window +void nsPluginInstance::clear() +{ + strcpy(mString, ""); + InvalidateRect(mhWnd, NULL, TRUE); + UpdateWindow(mhWnd); +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// here the plugin is asked by Mozilla to tell if it is scriptable +// we should return a valid interface id and a pointer to +// nsScriptablePeer interface which we should have implemented +// and which should be defined in the corressponding *.xpt file +// in the bin/components folder +NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) +{ + NPError rv = NPERR_NO_ERROR; + + if (aVariable == NPPVpluginScriptableInstance) { + // addref happens in getter, so we don't addref here + nsIScriptablePlugin * scriptablePeer = getScriptablePeer(); + if (scriptablePeer) { + *(nsISupports **)aValue = scriptablePeer; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + else if (aVariable == NPPVpluginScriptableIID) { + static nsIID scriptableIID = NS_ISCRIPTABLEPLUGIN_IID; + nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID)); + if (ptr) { + *ptr = scriptableIID; + *(nsIID **)aValue = ptr; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + + return rv; +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// this method will return the scriptable object (and create it if necessary) +nsIScriptablePlugin* nsPluginInstance::getScriptablePeer() +{ + if (!mScriptablePeer) { + mScriptablePeer = new nsScriptablePeer(this); + if(!mScriptablePeer) + return NULL; + + NS_ADDREF(mScriptablePeer); + } + + // add reference for the caller requesting the object + NS_ADDREF(mScriptablePeer); + return mScriptablePeer; + + return NULL; +} + +static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_PAINT: + { + // draw a frame and display the string + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + RECT rc; + GetClientRect(hWnd, &rc); + FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH)); + + // get our plugin instance object and ask it for the version string + nsPluginInstance *plugin = (nsPluginInstance *)GetWindowLong(hWnd, GWL_USERDATA); + if (plugin) + DrawText(hdc, plugin->mString, strlen(plugin->mString), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + else { + char string[] = "Error occured"; + DrawText(hdc, string, strlen(string), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + } + + EndPaint(hWnd, &ps); + } + break; + default: + break; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.h new file mode 100644 index 00000000000..3ec74aa810b --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/plugin.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +#include "pluginbase.h" +#include "nsScriptablePeer.h" + +class nsPluginInstance : public nsPluginInstanceBase +{ +public: + nsPluginInstance(NPP aInstance); + ~nsPluginInstance(); + + NPBool init(NPWindow* aWindow); + void shut(); + NPBool isInitialized(); + + // we need to provide implementation of this method as it will be + // used by Mozilla to retrive the scriptable peer + NPError GetValue(NPPVariable variable, void *value); + + // locals + void showVersion(); + void clear(); + + nsIScriptablePlugin* getScriptablePeer(); + +private: + NPP mInstance; + NPBool mInitialized; + HWND mhWnd; + nsIScriptablePlugin * mScriptablePeer; + +public: + char mString[128]; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/readme.txt b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/readme.txt new file mode 100644 index 00000000000..85c0dff76a2 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/readme.txt @@ -0,0 +1,9 @@ +Before building the project the following must be done. + +1. ..\..\..\bin\xpidl -m header -I..\..\..\idl nsIScriptablePlugin.idl +This will generate nsIScriptablePlugin.h which is needed to successfuly +compile the plugin + +2. ..\..\..\bin\xpidl -m typelib -I..\..\..\idl nsIScriptablePlugin.idl +This will create nsIScriptablePlugin.xpt file which should go to the +Mozilla Components folder. diff --git a/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/resource.h b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/resource.h new file mode 100644 index 00000000000..6a9ecdf1d76 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/scriptable/windows/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by scriptable.rc +// +#define IDD_MAIN 101 +#define IDC_BUTTON_GO 1002 +#define IDC_STATIC_UA 1003 +#define IDC_BUTTON1 1005 +#define IDC_BUTTON_DONT 1005 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/makefile b/mozilla/modules/plugin/tools/sdk/samples/simple/makefile new file mode 100644 index 00000000000..af7b1991093 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/makefile @@ -0,0 +1,51 @@ +#!nmake +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +# This makefile contains some of our defines for the compiler: +# +# XP_UNIX This needs to get defined for npapi.h on unix platforms. + +PLUGIN_DEFINES = -DXP_UNIX -I../../include -I../include +CCC = gcc +OPTIMIZER = -g +CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include + +CPPSRCS = ../common/npn_gate.cpp \ + ../common/npp_gate.cpp \ + ../common/np_entry.cpp \ + nsScriptablePeer.cpp \ + plugin.cpp + +OBJS = $(strip $(CPPSRCS:.cpp=.o)) + +%.o: %.cpp makefile + $(CCC) -o $@ -c $(CFLAGS) $< + +SHAREDTARGET=npsimple.so + +default all: $(SHAREDTARGET) + +$(SHAREDTARGET): $(OBJS) + $(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS) + +clean: + $(RM) $(OBJS) $(SHAREDTARGET) + diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.def b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.def new file mode 100644 index 00000000000..227d26c721c --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.def @@ -0,0 +1,6 @@ +LIBRARY NPSIMPLE + +EXPORTS + NP_GetEntryPoints @1 + NP_Initialize @2 + NP_Shutdown @3 diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsp b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsp new file mode 100644 index 00000000000..5443a5bde6f --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsp @@ -0,0 +1,139 @@ +# Microsoft Developer Studio Project File - Name="npsimple" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=npsimple - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "npsimple.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "npsimple.mak" CFG="npsimple - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "npsimple - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "npsimple - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "npsimple - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSIMPLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "XP_WIN" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSIMPLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /machine:I386 + +!ELSEIF "$(CFG)" == "npsimple - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "npsimple___Win32_Debug" +# PROP BASE Intermediate_Dir "npsimple___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSIMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\..\include" /D "XP_WIN32" /D "XP_WIN" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "NPSIMPLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "npsimple - Win32 Release" +# Name "npsimple - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\common\np_entry.cpp +# End Source File +# Begin Source File + +SOURCE=..\common\npn_gate.cpp +# End Source File +# Begin Source File + +SOURCE=..\common\npp_gate.cpp +# End Source File +# Begin Source File + +SOURCE=.\npsimple.def +# End Source File +# Begin Source File + +SOURCE=.\nsScriptablePeer.cpp +# End Source File +# Begin Source File + +SOURCE=.\plugin.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\nsScriptablePeer.h +# End Source File +# Begin Source File + +SOURCE=.\plugin.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\npsimple.rc +# End Source File +# End Group +# End Target +# End Project diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsw b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsw new file mode 100644 index 00000000000..bfcc970ea47 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "npsimple"=.\npsimple.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.rc b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.rc new file mode 100644 index 00000000000..fa0d8099aec --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/npsimple.rc @@ -0,0 +1,112 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", " \0" + VALUE "FileDescription", "npsimple\0" + VALUE "FileExtents", "spl\0" + VALUE "FileOpenName", "npsimple\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "npsimple\0" + VALUE "LegalCopyright", "Copyright © 2001\0" + VALUE "LegalTrademarks", "\0" + VALUE "MIMEType", "application/simple-plugin\0" + VALUE "OriginalFilename", "npsimple.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "Simple Example Plugin for Mozilla\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // !_MAC + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/nsISimplePlugin.idl b/mozilla/modules/plugin/tools/sdk/samples/simple/nsISimplePlugin.idl new file mode 100644 index 00000000000..e2e709fb89d --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/nsISimplePlugin.idl @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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 Netscape are + * Copyright (C) 2001 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)] +interface nsISimplePlugin : nsISupports { + readonly attribute string version; +}; diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp new file mode 100644 index 00000000000..86f6c95f3f3 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, 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 "plugin.h" + +static NS_DEFINE_IID(kISimplePluginIID, NS_ISIMPLEPLUGIN_IID); +static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsScriptablePeer::nsScriptablePeer(nsPluginInstance* aPlugin) +{ + mPlugin = aPlugin; + mRefCnt = 0; +} + +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) +{ + if(!aInstancePtr) + return NS_ERROR_NULL_POINTER; + + if(aIID.Equals(kISimplePluginIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kIClassInfoIID)) { + *aInstancePtr = static_cast(this); + AddRef(); + return NS_OK; + } + + if(aIID.Equals(kISupportsIID)) { + *aInstancePtr = static_cast(static_cast(this)); + AddRef(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +// +// the following method will be callable from JavaScript +// +NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion) +{ + if (mPlugin) + mPlugin->getVersion(aVersion); + return NS_OK; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h new file mode 100644 index 00000000000..fc6c2542e44 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/nsScriptablePeer.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// nsScriptablePeer - xpconnect scriptable peer +// + +#ifndef __nsScriptablePeer_h__ +#define __nsScriptablePeer_h__ + +#include "nsISimplePlugin.h" +#include "nsIClassInfo.h" + +class nsPluginInstance; + +// 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 nsISimplePlugin, + public nsClassInfoMixin +{ +public: + nsScriptablePeer(nsPluginInstance* plugin); + ~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_NSISIMPLEPLUGIN + +protected: + nsPluginInstance* mPlugin; +}; + +#endif \ No newline at end of file diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp new file mode 100644 index 00000000000..540f3739f1c --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.cpp @@ -0,0 +1,229 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "plugin.h" +#include "nsIServiceManager.h" +#include "nsIMemory.h" + +// service manager which will give the access to all public browser services +// we will use memory service as an illustration +nsIServiceManager * gServiceManager = NULL; + +//static NS_DEFINE_IID(kMemoryCID, NS_MEMORY_CID); + +// Unix needs this +#ifdef XP_UNIX +#define MIME_TYPES_HANDLED "application/simple-plugin" +#define PLUGIN_NAME "Simple Plugin Example for Mozilla" +#define PLUGIN_DESCRIPTION "Simple Plugin Example for Mozilla" + +char* NPP_GetMIMEDescription(void) +{ + return(MIME_TYPES_HANDLED); +} +#endif //XP_UNIX + +////////////////////////////////////// +// +// general initialization and shutdown +// +NPError NS_PluginInitialize() +{ + // this is probably a good place to get the service manager + // note that Mozilla will add reference, so do not forget to release + NPN_GetValue(NULL, NPNVserviceManager, &gServiceManager); + + return NPERR_NO_ERROR; +} + +void NS_PluginShutdown() +{ + // we should release the service manager + NS_IF_RELEASE(gServiceManager); + gServiceManager = NULL; +} + +///////////////////////////////////////////////////////////// +// +// construction and destruction of our plugin instance object +// +nsPluginInstanceBase * NS_NewPluginInstance(NPP aInstance) +{ + nsPluginInstance * plugin = new nsPluginInstance(aInstance); + return plugin; +} + +void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin) +{ + if(aPlugin) + delete aPlugin; +} + +//////////////////////////////////////// +// +// nsPluginInstance class implementation +// +nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(), + mInstance(aInstance), + mInitialized(FALSE), + mScriptablePeer(NULL) +{ + mString[0] = '\0'; +} + +nsPluginInstance::~nsPluginInstance() +{ + NS_IF_RELEASE(mScriptablePeer); +} + +NPBool nsPluginInstance::init(NPWindow* aWindow) +{ + if(aWindow == NULL) + return FALSE; + + mInitialized = TRUE; + return TRUE; +} + +void nsPluginInstance::shut() +{ + mInitialized = FALSE; +} + +NPBool nsPluginInstance::isInitialized() +{ + return mInitialized; +} + +void nsPluginInstance::getVersion(char* *aVersion) +{ + const char *ua = NPN_UserAgent(mInstance); + char*& version = *aVersion; + + // although we can use NPAPI NPN_MemAlloc call to allocate memory: + // version = (char*)NPN_MemAlloc(strlen(ua) + 1); + // for illustration purposed we use the service manager to access + // the memory service provided by Mozilla + nsIMemory * nsMemoryService = NULL; + + if (gServiceManager) { + // get service using its contract id and use it to allocate the memory + gServiceManager->GetService("@mozilla.org/xpcom/memory-service;1", NS_GET_IID(nsIMemory), (nsISupports**)&nsMemoryService); + if(nsMemoryService) + version = (char *)nsMemoryService->Alloc(strlen(ua) + 1); + } + + if (version) + strcpy(version, ua); + + // release service + NS_IF_RELEASE(nsMemoryService); +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// here the plugin is asked by Mozilla to tell if it is scriptable +// we should return a valid interface id and a pointer to +// nsScriptablePeer interface which we should have implemented +// and which should be defined in the corressponding *.xpt file +// in the bin/components folder +NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue) +{ + NPError rv = NPERR_NO_ERROR; + + switch (aVariable) { + case NPPVpluginScriptableInstance: { + // addref happens in getter, so we don't addref here + nsISimplePlugin * scriptablePeer = getScriptablePeer(); + if (scriptablePeer) { + *(nsISupports **)aValue = scriptablePeer; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + + case NPPVpluginScriptableIID: { + static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID; + nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID)); + if (ptr) { + *ptr = scriptableIID; + *(nsIID **)aValue = ptr; + } else + rv = NPERR_OUT_OF_MEMORY_ERROR; + } + break; + +#ifdef XP_UNIX + // Unix needs some additional cases + case NPPVpluginNameString: + *((char **)aValue) = PLUGIN_NAME; + break; + case NPPVpluginDescriptionString: + *((char **)aValue) = PLUGIN_DESCRIPTION; + break; +#endif //XP_UNIX + + default: + break; + } + + return rv; +} + +// ============================== +// ! Scriptability related code ! +// ============================== +// +// this method will return the scriptable object (and create it if necessary) +nsISimplePlugin* nsPluginInstance::getScriptablePeer() +{ + if (!mScriptablePeer) { + mScriptablePeer = new nsScriptablePeer(this); + if(!mScriptablePeer) + return NULL; + + NS_ADDREF(mScriptablePeer); + } + + // add reference for the caller requesting the object + NS_ADDREF(mScriptablePeer); + return mScriptablePeer; + + return NULL; +} diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h new file mode 100644 index 00000000000..de539577772 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/plugin.h @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +#include "pluginbase.h" +#include "nsScriptablePeer.h" + +class nsPluginInstance : public nsPluginInstanceBase +{ +public: + nsPluginInstance(NPP aInstance); + ~nsPluginInstance(); + + NPBool init(NPWindow* aWindow); + void shut(); + NPBool isInitialized(); + + // we need to provide implementation of this method as it will be + // used by Mozilla to retrive the scriptable peer + // and couple of other things on Unix + NPError GetValue(NPPVariable variable, void *value); + + // locals + void getVersion(char* *aVersion); + + nsISimplePlugin* getScriptablePeer(); + +private: + NPP mInstance; + NPBool mInitialized; + nsISimplePlugin * mScriptablePeer; + +public: + char mString[128]; +}; + +#endif // __PLUGIN_H__ diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/readme.txt b/mozilla/modules/plugin/tools/sdk/samples/simple/readme.txt new file mode 100644 index 00000000000..8a539ce8a61 --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/readme.txt @@ -0,0 +1,12 @@ +Before building the project the following must be done. + +1. ..\..\bin\xpidl -m header -I..\..\idl nsISimplePlugin.idl +This will generate nsISimplePlugin.h which is needed to successfuly +compile the plugin + +2. ..\..\bin\xpidl -m typelib -I..\..\idl nsISimplePlugin.idl +This will create nsISimplePlugin.xpt file which should go to the +Mozilla Components folder. + +Mechanism of accessing the service manager is implemented in Mozilla +builds starting with 0.9.4. It will not work with Netscape 6.1. diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h b/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h new file mode 100644 index 00000000000..55e59cd1f9c --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/resource.h @@ -0,0 +1,20 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by simple.rc +// +#define IDD_MAIN 101 +#define IDC_BUTTON_GO 1002 +#define IDC_STATIC_UA 1003 +#define IDC_BUTTON1 1005 +#define IDC_BUTTON_DONT 1005 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1006 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/mozilla/modules/plugin/tools/sdk/samples/simple/test.html b/mozilla/modules/plugin/tools/sdk/samples/simple/test.html new file mode 100644 index 00000000000..a6f2c07577b --- /dev/null +++ b/mozilla/modules/plugin/tools/sdk/samples/simple/test.html @@ -0,0 +1,41 @@ + + +Simple Plug-in Test + + + +
+

XPConnect Scriptable Sample Plug-in

+
+ +This page contains a testcase which demonstrates the work of scriptable +plug-in with Mozilla. This example plug-in has no native GUI and does not +draw anything in the plugin window. Clicking on the button will result in calling +native plugin method from JavaScript. Show Version will instruct the plug-in +to retrieve the Mozilla user agent string and return it to JavaScript to show +in the alert box. + +

+ +
+ +
+ + + +
+
+ +
+ +
+ + +