From 82c371bd69bc8ae49b134943c62bd00fe294e5bc Mon Sep 17 00:00:00 2001 From: warren Date: Thu, 9 Jul 1998 08:42:58 +0000 Subject: [PATCH] Breaking out new plugin APIs into separate classes. Moving lib/plugin into a module. git-svn-id: svn://10.0.0.236/trunk@5217 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/Makefile | 31 + mozilla/modules/plugin/base/public/MANIFEST | 41 + mozilla/modules/plugin/base/public/Makefile | 44 + .../modules/plugin/base/public/makefile.win | 47 + .../plugin/base/public/nsIFileUtilities.h | 75 + .../base/public/nsIJRILiveConnectPlugin.h | 77 + .../nsIJRILiveConnectPluginInstancePeer.h | 86 + .../plugin/base/public/nsILiveConnectPlugin.h | 65 + .../public/nsILiveConnectPluginInstancePeer.h | 74 + .../modules/plugin/base/public/nsIPlugin.h | 97 + .../plugin/base/public/nsIPluginInstance.h | 111 + .../base/public/nsIPluginInstancePeer.h | 80 + .../base/public/nsIPluginInstancePeer2.h | 79 + .../plugin/base/public/nsIPluginManager.h | 128 + .../plugin/base/public/nsIPluginManager2.h | 67 + .../plugin/base/public/nsIPluginStream.h | 66 + .../plugin/base/public/nsIPluginStreamPeer.h | 84 + .../plugin/base/public/nsIPluginStreamPeer2.h | 70 + .../plugin/base/public/nsIPluginTagInfo.h | 74 + .../plugin/base/public/nsIPluginTagInfo2.h | 110 + .../base/public/nsISeekablePluginStreamPeer.h | 67 + .../public/nsIWindowlessPluginInstancePeer.h | 69 + mozilla/modules/plugin/base/public/nsplugin.h | 238 + .../modules/plugin/base/public/nsplugindefs.h | 365 ++ mozilla/modules/plugin/makefile.win | 30 + mozilla/modules/plugin/public/MANIFEST | 41 + mozilla/modules/plugin/public/Makefile | 44 + mozilla/modules/plugin/public/makefile.win | 47 + .../modules/plugin/public/nsIFileUtilities.h | 75 + .../plugin/public/nsIJRILiveConnectPlugin.h | 77 + .../nsIJRILiveConnectPluginInstancePeer.h | 86 + .../plugin/public/nsILiveConnectPlugin.h | 65 + .../public/nsILiveConnectPluginInstancePeer.h | 74 + mozilla/modules/plugin/public/nsIPlugin.h | 97 + .../modules/plugin/public/nsIPluginInstance.h | 111 + .../plugin/public/nsIPluginInstancePeer.h | 80 + .../plugin/public/nsIPluginInstancePeer2.h | 79 + .../modules/plugin/public/nsIPluginManager.h | 128 + .../modules/plugin/public/nsIPluginManager2.h | 67 + .../modules/plugin/public/nsIPluginStream.h | 66 + .../plugin/public/nsIPluginStreamPeer.h | 84 + .../plugin/public/nsIPluginStreamPeer2.h | 70 + .../modules/plugin/public/nsIPluginTagInfo.h | 74 + .../modules/plugin/public/nsIPluginTagInfo2.h | 110 + .../public/nsISeekablePluginStreamPeer.h | 67 + .../public/nsIWindowlessPluginInstancePeer.h | 69 + mozilla/modules/plugin/public/nsplugin.h | 238 + mozilla/modules/plugin/public/nsplugindefs.h | 365 ++ mozilla/modules/plugin/src/MANIFEST | 25 + mozilla/modules/plugin/src/Makefile | 46 + mozilla/modules/plugin/src/makefile.win | 47 + mozilla/modules/plugin/src/npassoc.c | 239 + mozilla/modules/plugin/src/npglue.cpp | 5501 +++++++++++++++++ mozilla/modules/plugin/src/npglue.h | 730 +++ mozilla/modules/plugin/src/nppg.h | 65 + mozilla/modules/plugin/src/nppriv.h | 153 + mozilla/modules/plugin/src/npupp.h | 1225 ++++ mozilla/modules/plugin/src/nsplugin.cpp | 1010 +++ 58 files changed, 13530 insertions(+) create mode 100644 mozilla/modules/plugin/Makefile create mode 100644 mozilla/modules/plugin/base/public/MANIFEST create mode 100644 mozilla/modules/plugin/base/public/Makefile create mode 100644 mozilla/modules/plugin/base/public/makefile.win create mode 100644 mozilla/modules/plugin/base/public/nsIFileUtilities.h create mode 100644 mozilla/modules/plugin/base/public/nsIJRILiveConnectPlugin.h create mode 100644 mozilla/modules/plugin/base/public/nsIJRILiveConnectPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/base/public/nsILiveConnectPlugin.h create mode 100644 mozilla/modules/plugin/base/public/nsILiveConnectPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/base/public/nsIPlugin.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginInstance.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginInstancePeer2.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginManager.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginManager2.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginStream.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginTagInfo.h create mode 100644 mozilla/modules/plugin/base/public/nsIPluginTagInfo2.h create mode 100644 mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h create mode 100644 mozilla/modules/plugin/base/public/nsIWindowlessPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/base/public/nsplugin.h create mode 100644 mozilla/modules/plugin/base/public/nsplugindefs.h create mode 100644 mozilla/modules/plugin/makefile.win create mode 100644 mozilla/modules/plugin/public/MANIFEST create mode 100644 mozilla/modules/plugin/public/Makefile create mode 100644 mozilla/modules/plugin/public/makefile.win create mode 100644 mozilla/modules/plugin/public/nsIFileUtilities.h create mode 100644 mozilla/modules/plugin/public/nsIJRILiveConnectPlugin.h create mode 100644 mozilla/modules/plugin/public/nsIJRILiveConnectPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/public/nsILiveConnectPlugin.h create mode 100644 mozilla/modules/plugin/public/nsILiveConnectPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/public/nsIPlugin.h create mode 100644 mozilla/modules/plugin/public/nsIPluginInstance.h create mode 100644 mozilla/modules/plugin/public/nsIPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/public/nsIPluginInstancePeer2.h create mode 100644 mozilla/modules/plugin/public/nsIPluginManager.h create mode 100644 mozilla/modules/plugin/public/nsIPluginManager2.h create mode 100644 mozilla/modules/plugin/public/nsIPluginStream.h create mode 100644 mozilla/modules/plugin/public/nsIPluginStreamPeer.h create mode 100644 mozilla/modules/plugin/public/nsIPluginStreamPeer2.h create mode 100644 mozilla/modules/plugin/public/nsIPluginTagInfo.h create mode 100644 mozilla/modules/plugin/public/nsIPluginTagInfo2.h create mode 100644 mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h create mode 100644 mozilla/modules/plugin/public/nsIWindowlessPluginInstancePeer.h create mode 100644 mozilla/modules/plugin/public/nsplugin.h create mode 100644 mozilla/modules/plugin/public/nsplugindefs.h create mode 100644 mozilla/modules/plugin/src/MANIFEST create mode 100644 mozilla/modules/plugin/src/Makefile create mode 100644 mozilla/modules/plugin/src/makefile.win create mode 100644 mozilla/modules/plugin/src/npassoc.c create mode 100644 mozilla/modules/plugin/src/npglue.cpp create mode 100644 mozilla/modules/plugin/src/npglue.h create mode 100644 mozilla/modules/plugin/src/nppg.h create mode 100644 mozilla/modules/plugin/src/nppriv.h create mode 100644 mozilla/modules/plugin/src/npupp.h create mode 100644 mozilla/modules/plugin/src/nsplugin.cpp diff --git a/mozilla/modules/plugin/Makefile b/mozilla/modules/plugin/Makefile new file mode 100644 index 00000000000..46dc9f6fe3a --- /dev/null +++ b/mozilla/modules/plugin/Makefile @@ -0,0 +1,31 @@ +#//------------------------------------------------------------------------ +#// +#// Makefile to build the MODULES/OJI tree +#// +#//------------------------------------------------------------------------ + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH=../.. + +#//------------------------------------------------------------------------ +#// +#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...) +#// (these must come before the common makefiles are included) +#// +#// DIRS - There are subdirectories to process +#// +#//------------------------------------------------------------------------ +DIRS= public src + +#//------------------------------------------------------------------------ +#// +#// Include the common makefile rules +#// +#//------------------------------------------------------------------------ +include $(DEPTH)/config/rules.mk + diff --git a/mozilla/modules/plugin/base/public/MANIFEST b/mozilla/modules/plugin/base/public/MANIFEST new file mode 100644 index 00000000000..9f6a56fcb1e --- /dev/null +++ b/mozilla/modules/plugin/base/public/MANIFEST @@ -0,0 +1,41 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +# This is a list of local files which get copied to the mozilla:dist directory +# + +nsIFileUtilities.h +nsIJRILiveConnectPlugin.h +nsIJRILiveConnectPluginInstancePeer.h +nsILiveConnectPlugin.h +nsILiveConnectPluginInstancePeer.h +nsIPlugin.h +nsIPluginInstance.h +nsIPluginInstancePeer.h +nsIPluginInstancePeer2.h +nsIPluginManager.h +nsIPluginManager2.h +nsIPluginStream.h +nsIPluginStreamPeer.h +nsIPluginStreamPeer2.h +nsIPluginTagInfo.h +nsIPluginTagInfo2.h +nsISeekablePluginStreamPeer.h +nsIWindowlessPluginInstancePeer.h +nsplugin.h +nsplugindefs.h diff --git a/mozilla/modules/plugin/base/public/Makefile b/mozilla/modules/plugin/base/public/Makefile new file mode 100644 index 00000000000..f87022e6eba --- /dev/null +++ b/mozilla/modules/plugin/base/public/Makefile @@ -0,0 +1,44 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +DEPTH = ../../.. + +MODULE = plugin + +EXPORTS = \ + nsIFileUtilities.h \ + nsIJRILiveConnectPlugin.h \ + nsIJRILiveConnectPluginInstancePeer.h \ + nsILiveConnectPlugin.h \ + nsILiveConnectPluginInstancePeer.h \ + nsIPlugin.h \ + nsIPluginInstance.h \ + nsIPluginInstancePeer.h \ + nsIPluginInstancePeer2.h \ + nsIPluginManager.h \ + nsIPluginManager2.h \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsIPluginTagInfo.h \ + nsIPluginTagInfo2.h \ + nsISeekablePluginStreamPeer.h \ + nsIWindowlessPluginInstancePeer.h \ + nsplugin.h \ + nsplugindefs.h + +include $(DEPTH)/config/rules.mk diff --git a/mozilla/modules/plugin/base/public/makefile.win b/mozilla/modules/plugin/base/public/makefile.win new file mode 100644 index 00000000000..4dae17aff4d --- /dev/null +++ b/mozilla/modules/plugin/base/public/makefile.win @@ -0,0 +1,47 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +IGNORE_MANIFEST=1 + +DEPTH = ..\..\.. + +MODULE = plugin + +EXPORTS = \ + nsIFileUtilities.h \ + nsIJRILiveConnectPlugin.h \ + nsIJRILiveConnectPluginInstancePeer.h \ + nsILiveConnectPlugin.h \ + nsILiveConnectPluginInstancePeer.h \ + nsIPlugin.h \ + nsIPluginInstance.h \ + nsIPluginInstancePeer.h \ + nsIPluginInstancePeer2.h \ + nsIPluginManager.h \ + nsIPluginManager2.h \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsIPluginTagInfo.h \ + nsIPluginTagInfo2.h \ + nsISeekablePluginStreamPeer.h \ + nsIWindowlessPluginInstancePeer.h \ + nsplugin.h \ + nsplugindefs.h + +include <$(DEPTH)/config/rules.mak> + diff --git a/mozilla/modules/plugin/base/public/nsIFileUtilities.h b/mozilla/modules/plugin/base/public/nsIFileUtilities.h new file mode 100644 index 00000000000..880435d4d9f --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIFileUtilities.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIFileUtilities_h___ +#define nsIFileUtilities_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// File Utilities Interface +// This interface reflects operations only available in Communicator 5.0. + +class nsIFileUtilities : public nsISupports { +public: + + // QueryInterface on nsIPluginManager to get this. + + NS_IMETHOD_(const char*) + GetProgramPath(void) = 0; + + NS_IMETHOD_(const char*) + GetTempDirPath(void) = 0; + + enum FileNameType { SIGNED_APPLET_DBNAME, TEMP_FILENAME }; + + NS_IMETHOD_(nsresult) + GetFileName(const char* fn, FileNameType type, + char* resultBuf, PRUint32 bufLen) = 0; + + NS_IMETHOD_(nsresult) + NewTempFileName(const char* prefix, char* resultBuf, PRUint32 bufLen) = 0; + +}; + +#define NS_IFILEUTILITIES_IID \ +{ /* 89a31ce0-019a-11d2-815b-006008119d7a */ \ + 0x89a31ce0, \ + 0x019a, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIFileUtilities_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIJRILiveConnectPlugin.h b/mozilla/modules/plugin/base/public/nsIJRILiveConnectPlugin.h new file mode 100644 index 00000000000..bc2382ced4b --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIJRILiveConnectPlugin.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIJRILiveConnectPlugin_h__ +#define nsIJRILiveConnectPlugin_h__ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// JRI-Based LiveConnect Classes +//////////////////////////////////////////////////////////////////////////////// +// +// This stuff is here so that the browser can support older JRI-based +// LiveConnected plugins (when using old plugin to new C++-style plugin +// adapter code). +// +// Warning: Don't use this anymore, unless you're sure that you have to! +//////////////////////////////////////////////////////////////////////////////// + +#include "jri.h" // ancient + +//////////////////////////////////////////////////////////////////////////////// +// JRILiveConnect Plugin Interface +// This interface defines additional entry points that a plugin developer needs +// to implement in order for the plugin to support JRI-based LiveConnect, +// i.e. be scriptable by Java or JavaScript. + +class nsIJRILiveConnectPlugin : public nsIPlugin { +public: + + // (Corresponds to NPP_GetJavaClass.) + NS_IMETHOD_(jref) + GetJavaClass(void) = 0; + +}; + +#define NS_IJRILIVECONNECTPLUGIN_IID \ +{ /* c94058e0-f772-11d1-815b-006008119d7a */ \ + 0xc94058e0, \ + 0xf772, \ + 0x11d1, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIJRILiveConnectPlugin_h__ */ diff --git a/mozilla/modules/plugin/base/public/nsIJRILiveConnectPluginInstancePeer.h b/mozilla/modules/plugin/base/public/nsIJRILiveConnectPluginInstancePeer.h new file mode 100644 index 00000000000..bbd8bac6f1b --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIJRILiveConnectPluginInstancePeer.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIJRILiveConnectPluginInstancePeer_h__ +#define nsIJRILiveConnectPluginInstancePeer_h__ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// JRI-Based LiveConnect Classes +//////////////////////////////////////////////////////////////////////////////// +// +// This stuff is here so that the browser can support older JRI-based +// LiveConnected plugins (when using old plugin to new C++-style plugin +// adapter code). +// +// Warning: Don't use this anymore, unless you're sure that you have to! +//////////////////////////////////////////////////////////////////////////////// + +#include "jri.h" // ancient + +//////////////////////////////////////////////////////////////////////////////// +// JRILiveConnect Plugin Instance Peer Interface +// Browsers that support JRI-based LiveConnect implement this subclass of +// plugin instance peer. + +class nsIJRILiveConnectPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPN_GetJavaPeer.) + NS_IMETHOD_(jref) + GetJavaPeer(void) = 0; + +}; + +#define NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID \ +{ /* 25b63f40-f773-11d1-815b-006008119d7a */ \ + 0x25b63f40, \ + 0xf773, \ + 0x11d1, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +// QueryInterface for this IID on nsIPluginManager to get a JRIEnv +// XXX change this +#define NS_IJRIENV_IID \ +{ /* f9d4ea00-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xf9d4ea00, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIJRILiveConnectPluginInstancePeer_h__ */ diff --git a/mozilla/modules/plugin/base/public/nsILiveConnectPlugin.h b/mozilla/modules/plugin/base/public/nsILiveConnectPlugin.h new file mode 100644 index 00000000000..31753271bcd --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsILiveConnectPlugin.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsILiveConnectPlugin_h__ +#define nsILiveConnectPlugin_h__ + +#include "nsplugindefs.h" +#include "jni.h" // standard JVM API + +//////////////////////////////////////////////////////////////////////////////// +// LiveConnect Plugin Interface +// This interface defines additional entry points that a plugin developer needs +// to implement in order for the plugin to support JNI-based LiveConnect, +// i.e. be scriptable by Java or JavaScript. + +class nsILiveConnectPlugin : public nsIPlugin { +public: + + // (New JNI-based entry point, roughly corresponds to NPP_GetJavaClass.) + NS_IMETHOD_(jclass) + GetJavaClass(void) = 0; + +}; + +#define NS_ILIVECONNECTPLUGIN_IID \ +{ /* cf134df0-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xcf134df0, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsILiveConnectPlugin_h__ */ diff --git a/mozilla/modules/plugin/base/public/nsILiveConnectPluginInstancePeer.h b/mozilla/modules/plugin/base/public/nsILiveConnectPluginInstancePeer.h new file mode 100644 index 00000000000..508b51f3e08 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsILiveConnectPluginInstancePeer.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsILiveConnectPluginInstancePeer_h___ +#define nsILiveConnectPluginInstancePeer_h___ + +#include "nsplugindefs.h" +#include "jni.h" // standard JVM API + +//////////////////////////////////////////////////////////////////////////////// +// LiveConnect Plugin Instance Peer Interface +// Browsers that support JNI-based LiveConnect implement this subclass of +// plugin instance peer. + +class nsILiveConnectPluginInstancePeer : public nsISupports { +public: + + // (New JNI-based entry point, roughly corresponds to NPN_GetJavaPeer.) + NS_IMETHOD_(jobject) + GetJavaPeer(void) = 0; + +}; + +#define NS_ILIVECONNECTPLUGININSTANCEPEER_IID \ +{ /* 1e3502a0-a1bd-11d1-85b1-00805f0e4dfe */ \ + 0x1e3502a0, \ + 0xa1bd, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +// QueryInterface for this IID on nsIPluginManager to get a JNIEnv +// XXX change this +#define NS_IJNIENV_IID \ +{ /* 04610650-a1bd-11d1-85b1-00805f0e4dfe */ \ + 0x04610650, \ + 0xa1bd, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsILiveConnectPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPlugin.h b/mozilla/modules/plugin/base/public/nsIPlugin.h new file mode 100644 index 00000000000..8512a581534 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPlugin.h @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPlugin_h___ +#define nsIPlugin_h___ + +#include "nsplugindefs.h" +#include "nsIFactory.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Interface +// This is the minimum interface plugin developers need to support in order to +// implement a plugin. The plugin manager may QueryInterface for more specific +// plugin types, e.g. nsILiveConnectPlugin. + +struct nsIPlugin : public nsIFactory { +public: + + // This call initializes the plugin and will be called before any new + // instances are created. It is passed browserInterfaces on which QueryInterface + // may be used to obtain an nsIPluginManager, and other interfaces. + NS_IMETHOD_(nsPluginError) + Initialize(nsISupports* browserInterfaces) = 0; + + // (Corresponds to NPP_Shutdown.) + // Called when the browser is done with the plugin factory, or when + // the plugin is disabled by the user. + NS_IMETHOD_(nsPluginError) + Shutdown(void) = 0; + + // (Corresponds to NPP_GetMIMEDescription.) + NS_IMETHOD_(const char*) + GetMIMEDescription(void) = 0; + + // (Corresponds to NPP_GetValue.) + NS_IMETHOD_(nsPluginError) + GetValue(nsPluginVariable variable, void *value) = 0; + + // (Corresponds to NPP_SetValue.) + NS_IMETHOD_(nsPluginError) + SetValue(nsPluginVariable variable, void *value) = 0; + + // The old NPP_New call has been factored into two plugin instance methods: + // + // CreateInstance -- called once, after the plugin instance is created. This + // method is used to initialize the new plugin instance (although the actual + // plugin instance object will be created by the plugin manager). + // + // nsIPluginInstance::Start -- called when the plugin instance is to be + // started. This happens in two circumstances: (1) after the plugin instance + // is first initialized, and (2) after a plugin instance is returned to + // (e.g. by going back in the window history) after previously being stopped + // by the Stop method. + +}; + +#define NS_IPLUGIN_IID \ +{ /* df773070-0199-11d2-815b-006008119d7a */ \ + 0xdf773070, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPlugin_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstance.h b/mozilla/modules/plugin/base/public/nsIPluginInstance.h new file mode 100644 index 00000000000..29825c92f13 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginInstance.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstance_h___ +#define nsIPluginInstance_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Interface + +// (Corresponds to NPP object.) +class nsIPluginInstance : public nsISupports { +public: + + NS_IMETHOD_(nsPluginError) + Initialize(nsIPluginInstancePeer* peer) = 0; + + // Required backpointer to the peer. + NS_IMETHOD_(nsIPluginInstancePeer*) + GetPeer(void) = 0; + + // See comment for nsIPlugin::CreateInstance, above. + NS_IMETHOD_(nsPluginError) + Start(void) = 0; + + // The old NPP_Destroy call has been factored into two plugin instance + // methods: + // + // Stop -- called when the plugin instance is to be stopped (e.g. by + // displaying another plugin manager window, causing the page containing + // the plugin to become removed from the display). + // + // Release -- called once, before the plugin instance peer is to be + // destroyed. This method is used to destroy the plugin instance. + + NS_IMETHOD_(nsPluginError) + Stop(void) = 0; + + NS_IMETHOD_(nsPluginError) + Destroy(void) = 0; + + // (Corresponds to NPP_SetWindow.) + NS_IMETHOD_(nsPluginError) + SetWindow(nsPluginWindow* window) = 0; + + // (Corresponds to NPP_NewStream.) + NS_IMETHOD_(nsPluginError) + NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0; + + // (Corresponds to NPP_Print.) + NS_IMETHOD_(void) + Print(nsPluginPrint* platformPrint) = 0; + + // (Corresponds to NPP_HandleEvent.) + // Note that for Unix and Mac the nsPluginEvent structure is different + // from the old NPEvent structure -- it's no longer the native event + // record, but is instead a struct. This was done for future extensibility, + // and so that the Mac could receive the window argument too. For Windows + // and OS2, it's always been a struct, so there's no change for them. + NS_IMETHOD_(PRInt16) + HandleEvent(nsPluginEvent* event) = 0; + + // (Corresponds to NPP_URLNotify.) + NS_IMETHOD_(void) + URLNotify(const char* url, const char* target, + nsPluginReason reason, void* notifyData) = 0; + +}; + +#define NS_IPLUGININSTANCE_IID \ +{ /* ebe00f40-0199-11d2-815b-006008119d7a */ \ + 0xebe00f40, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstance_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstancePeer.h b/mozilla/modules/plugin/base/public/nsIPluginInstancePeer.h new file mode 100644 index 00000000000..98229dee428 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginInstancePeer.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstancePeer_h___ +#define nsIPluginInstancePeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Peer Interface + +enum nsPluginTagType { + nsPluginTagType_Unknown, + nsPluginTagType_Embed, + nsPluginTagType_Object, + nsPluginTagType_Applet +}; + +class nsIPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPP_New's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void) = 0; + + // (Corresponds to NPP_New's mode argument.) + NS_IMETHOD_(nsPluginType) + GetMode(void) = 0; + + // (Corresponds to NPN_NewStream.) + NS_IMETHOD_(nsPluginError) + NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result) = 0; + + // (Corresponds to NPN_Status.) + NS_IMETHOD_(void) + ShowStatus(const char* message) = 0; + +}; + +#define NS_IPLUGININSTANCEPEER_IID \ +{ /* 4b7cea20-019b-11d2-815b-006008119d7a */ \ + 0x4b7cea20, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginInstancePeer2.h b/mozilla/modules/plugin/base/public/nsIPluginInstancePeer2.h new file mode 100644 index 00000000000..f3b3acbe02f --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginInstancePeer2.h @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstancePeer2_h___ +#define nsIPluginInstancePeer2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Peer 2 Interface +// These extensions to nsIPluginManager are only available in Communicator 5.0. + +class nsIPluginInstancePeer2 : public nsIPluginInstancePeer { +public: + + //////////////////////////////////////////////////////////////////////////// + // New top-level window handling calls for Mac: + + NS_IMETHOD_(void) + RegisterWindow(void* window) = 0; + + NS_IMETHOD_(void) + UnregisterWindow(void* window) = 0; + + // Menu ID allocation calls for Mac: + NS_IMETHOD_(PRInt16) + AllocateMenuID(PRBool isSubmenu) = 0; + + // On the mac (and most likely win16), network activity can + // only occur on the main thread. Therefore, we provide a hook + // here for the case that the main thread needs to tickle itself. + // In this case, we make sure that we give up the monitor so that + // the tickle code can notify it without freezing. + NS_IMETHOD_(PRBool) + Tickle(void) = 0; + +}; + +#define NS_IPLUGININSTANCEPEER2_IID \ +{ /* 51b52b80-019b-11d2-815b-006008119d7a */ \ + 0x51b52b80, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstancePeer2_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager.h b/mozilla/modules/plugin/base/public/nsIPluginManager.h new file mode 100644 index 00000000000..dffd0376f75 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginManager.h @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginManager_h___ +#define nsIPluginManager_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager Interface +// This interface defines the minimum set of functionality that a plugin +// manager will support if it implements plugins. Plugin implementations can +// QueryInterface to determine if a plugin manager implements more specific +// APIs for the plugin to use. + +class nsIPluginManager : public nsISupports { +public: + + // (Corresponds to NPN_ReloadPlugins.) + NS_IMETHOD_(void) + ReloadPlugins(PRBool reloadPages) = 0; + + // (Corresponds to NPN_MemAlloc.) + NS_IMETHOD_(void*) + MemAlloc(PRUint32 size) = 0; + + // (Corresponds to NPN_MemFree.) + NS_IMETHOD_(void) + MemFree(void* ptr) = 0; + + // (Corresponds to NPN_MemFlush.) + NS_IMETHOD_(PRUint32) + MemFlush(PRUint32 size) = 0; + + // (Corresponds to NPN_UserAgent.) + NS_IMETHOD_(const char*) + UserAgent(void) = 0; + + // (Corresponds to NPN_GetValue.) + NS_IMETHOD_(nsPluginError) + GetValue(nsPluginManagerVariable variable, void *value) = 0; + + // (Corresponds to NPN_SetValue.) + NS_IMETHOD_(nsPluginError) + SetValue(nsPluginManagerVariable variable, void *value) = 0; + + + // (Corresponds to NPN_GetURL and NPN_GetURLNotify.) + // notifyData: When present, URLNotify is called passing the notifyData back + // to the client. When NULL, this call behaves like NPN_GetURL. + // New arguments: + // peer: A plugin instance peer. The peer's window will be used to display + // progress information. If NULL, the load happens in the background. + // altHost: An IP-address string that will be used instead of the host + // specified in the URL. This is used to prevent DNS-spoofing attacks. + // Can be defaulted to NULL meaning use the host in the URL. + // referrer: + // forceJSEnabled: Forces JavaScript to be enabled for 'javascript:' URLs, + // even if the user currently has JavaScript disabled. + NS_IMETHOD_(nsPluginError) + GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData = NULL, + const char* altHost = NULL, const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE) = 0; + + // (Corresponds to NPN_PostURL and NPN_PostURLNotify.) + // notifyData: When present, URLNotify is called passing the notifyData back + // to the client. When NULL, this call behaves like NPN_GetURL. + // New arguments: + // peer: A plugin instance peer. The peer's window will be used to display + // progress information. If NULL, the load happens in the background. + // altHost: An IP-address string that will be used instead of the host + // specified in the URL. This is used to prevent DNS-spoofing attacks. + // Can be defaulted to NULL meaning use the host in the URL. + // referrer: + // forceJSEnabled: Forces JavaScript to be enabled for 'javascript:' URLs, + // even if the user currently has JavaScript disabled. + // postHeaders: A string containing post headers. + // postHeadersLength: The length of the post headers string. + NS_IMETHOD_(nsPluginError) + PostURL(nsISupports* peer, const char* url, const char* target, PRUint32 bufLen, + const char* buf, PRBool file, void* notifyData = NULL, + const char* altHost = NULL, const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + +}; + +#define NS_IPLUGINMANAGER_IID \ +{ /* f10b9600-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xf10b9600, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginManager_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginManager2.h b/mozilla/modules/plugin/base/public/nsIPluginManager2.h new file mode 100644 index 00000000000..2ac771339e9 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginManager2.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginManager2_h___ +#define nsIPluginManager2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager 2 Interface +// These extensions to nsIPluginManager are only available in Communicator 5.0. + +class nsIPluginManager2 : public nsIPluginManager { +public: + + NS_IMETHOD_(void) + BeginWaitCursor(void) = 0; + + NS_IMETHOD_(void) + EndWaitCursor(void) = 0; + + NS_IMETHOD_(PRBool) + SupportsURLProtocol(const char* protocol) = 0; + +}; + +#define NS_IPLUGINMANAGER2_IID \ +{ /* 29c4ae70-019a-11d2-815b-006008119d7a */ \ + 0x29c4ae70, \ + 0x019a, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginManager2_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStream.h b/mozilla/modules/plugin/base/public/nsIPluginStream.h new file mode 100644 index 00000000000..e3f9b2c7e13 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginStream.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStream_h___ +#define nsIPluginStream_h___ + +#include "nsplugindefs.h" +#include "nsIOutputStream.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Interface + +class nsIPluginStream : public nsIOutputStream { +public: + + // (Corresponds to NPP_NewStream's stype return parameter.) + NS_IMETHOD_(NPStreamType) + GetStreamType(void) = 0; + + // (Corresponds to NPP_StreamAsFile.) + NS_IMETHOD_(void) + AsFile(const char* fname) = 0; + +}; + +#define NS_IPLUGINSTREAM_IID \ +{ /* f287dd50-0199-11d2-815b-006008119d7a */ \ + 0xf287dd50, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStream_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h new file mode 100644 index 00000000000..da46281e8be --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer.h @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStreamPeer_h___ +#define nsIPluginStreamPeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Peer Interface +// A plugin stream peer is passed to a plugin instance's NewStream call in +// order to indicate that a new stream is to be created and be read by the +// plugin instance. + +class nsIPluginStreamPeer : public nsISupports { +public: + + // (Corresponds to NPStream's url field.) + NS_IMETHOD_(const char*) + GetURL(void) = 0; + + // (Corresponds to NPStream's end field.) + NS_IMETHOD_(PRUint32) + GetEnd(void) = 0; + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD_(PRUint32) + GetLastModified(void) = 0; + + // (Corresponds to NPStream's notifyData field.) + NS_IMETHOD_(void*) + GetNotifyData(void) = 0; + + // (Corresponds to NPP_DestroyStream's reason argument.) + NS_IMETHOD_(nsPluginReason) + GetReason(void) = 0; + + // (Corresponds to NPP_NewStream's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void) = 0; + +}; + +#define NS_IPLUGINSTREAMPEER_IID \ +{ /* 717b1e90-019b-11d2-815b-006008119d7a */ \ + 0x717b1e90, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h new file mode 100644 index 00000000000..30a69a33631 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginStreamPeer2.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStreamPeer2_h___ +#define nsIPluginStreamPeer2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Peer Interface +// These extensions to nsIPluginStreamPeer are only available in Communicator 5.0. + +class nsIPluginStreamPeer2 : public nsIPluginStreamPeer { +public: + + NS_IMETHOD_(PRUint32) + GetContentLength(void) = 0; + + NS_IMETHOD_(PRUint32) + GetHeaderFieldCount(void) = 0; + + NS_IMETHOD_(const char*) + GetHeaderFieldKey(PRUint32 index) = 0; + + NS_IMETHOD_(const char*) + GetHeaderField(PRUint32 index) = 0; + +}; + +#define NS_IPLUGINSTREAMPEER2_IID \ +{ /* 77083af0-019b-11d2-815b-006008119d7a */ \ + 0x77083af0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStreamPeer2_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginTagInfo.h b/mozilla/modules/plugin/base/public/nsIPluginTagInfo.h new file mode 100644 index 00000000000..3171c135265 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginTagInfo.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginTagInfo_h___ +#define nsIPluginTagInfo_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Tag Info Interface +// This interface provides information about the HTML tag on the page. +// Some day this might get superseded by a DOM API. + +class nsIPluginTagInfo : public nsISupports { +public: + + // QueryInterface on nsIPluginInstancePeer to get this. + + // (Corresponds to NPP_New's argc, argn, and argv arguments.) + // Get a ptr to the paired list of attribute names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + NS_IMETHOD_(nsPluginError) + GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values) = 0; + + // Get the value for the named attribute. Returns NULL + // if the attribute was not set. + NS_IMETHOD_(const char*) + GetAttribute(const char* name) = 0; + +}; + +#define NS_IPLUGINTAGINFO_IID \ +{ /* 5f1ec1d0-019b-11d2-815b-006008119d7a */ \ + 0x5f1ec1d0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginTagInfo_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIPluginTagInfo2.h b/mozilla/modules/plugin/base/public/nsIPluginTagInfo2.h new file mode 100644 index 00000000000..f023e58b7c1 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIPluginTagInfo2.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginTagInfo2_h___ +#define nsIPluginTagInfo2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Tag Info Interface +// These extensions to nsIPluginTagInfo are only available in Communicator 5.0. + +class nsIPluginTagInfo2 : public nsIPluginTagInfo { +public: + + // QueryInterface on nsIPluginInstancePeer to get this. + + // Get the type of the HTML tag that was used ot instantiate this + // plugin. Currently supported tags are EMBED, OBJECT and APPLET. + NS_IMETHOD_(nsPluginTagType) + GetTagType(void) = 0; + + // Get the complete text of the HTML tag that was + // used to instantiate this plugin + NS_IMETHOD_(const char *) + GetTagText(void) = 0; + + // Get a ptr to the paired list of parameter names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + NS_IMETHOD_(nsPluginError) + GetParameters(PRUint16& n, const char*const*& names, const char*const*& values) = 0; + + // Get the value for the named parameter. Returns null + // if the parameter was not set. + NS_IMETHOD_(const char*) + GetParameter(const char* name) = 0; + + NS_IMETHOD_(const char*) + GetDocumentBase(void) = 0; + + // Return an encoding whose name is specified in: + // http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303 + NS_IMETHOD_(const char*) + GetDocumentEncoding(void) = 0; + + NS_IMETHOD_(const char*) + GetAlignment(void) = 0; + + NS_IMETHOD_(PRUint32) + GetWidth(void) = 0; + + NS_IMETHOD_(PRUint32) + GetHeight(void) = 0; + + NS_IMETHOD_(PRUint32) + GetBorderVertSpace(void) = 0; + + NS_IMETHOD_(PRUint32) + GetBorderHorizSpace(void) = 0; + + // Returns a unique id for the current document on which the + // plugin is displayed. + NS_IMETHOD_(PRUint32) + GetUniqueID(void) = 0; + +}; + +#define NS_IPLUGINTAGINFO2_IID \ +{ /* 6a49c9a0-019b-11d2-815b-006008119d7a */ \ + 0x6a49c9a0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginTagInfo2_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h b/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h new file mode 100644 index 00000000000..dcfd07f7519 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsISeekablePluginStreamPeer.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsISeekablePluginStreamPeer_h___ +#define nsISeekablePluginStreamPeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Seekable Plugin Stream Peer Interface +// The browser implements this subclass of plugin stream peer if a stream +// is seekable. Plugins can query interface for this type, and call the +// RequestRead method to seek to a particular position in the stream. + +class nsISeekablePluginStreamPeer : public nsISupports { +public: + + // QueryInterface for this class corresponds to NPP_NewStream's + // seekable argument. + + // (Corresponds to NPN_RequestRead.) + NS_IMETHOD_(nsPluginError) + RequestRead(nsByteRange* rangeList) = 0; + +}; + +#define NS_ISEEKABLEPLUGINSTREAMPEER_IID \ +{ /* 7e028d20-019b-11d2-815b-006008119d7a */ \ + 0x7e028d20, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsISeekablePluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsIWindowlessPluginInstancePeer.h b/mozilla/modules/plugin/base/public/nsIWindowlessPluginInstancePeer.h new file mode 100644 index 00000000000..14d4ccac468 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsIWindowlessPluginInstancePeer.h @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIWindowlessPluginInstancePeer_h___ +#define nsIWindowlessPluginInstancePeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Windowless Plugin Instance Peer Interface + +class nsIWindowlessPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPN_InvalidateRect.) + NS_IMETHOD_(void) + InvalidateRect(nsRect *invalidRect) = 0; + + // (Corresponds to NPN_InvalidateRegion.) + NS_IMETHOD_(void) + InvalidateRegion(nsRegion invalidRegion) = 0; + + // (Corresponds to NPN_ForceRedraw.) + NS_IMETHOD_(void) + ForceRedraw(void) = 0; + +}; + +#define NS_IWINDOWLESSPLUGININSTANCEPEER_IID \ +{ /* 57b4e2f0-019b-11d2-815b-006008119d7a */ \ + 0x57b4e2f0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIWindowlessPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/base/public/nsplugin.h b/mozilla/modules/plugin/base/public/nsplugin.h new file mode 100644 index 00000000000..d4f349501e0 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsplugin.h @@ -0,0 +1,238 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

This is the master header file that includes most of the other headers + * you'll need to write a plugin. + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The following diagram depicts the relationships between various objects + * implementing the new plugin interfaces. QueryInterface can be used to switch + * between interfaces in the same box: + * + * + * the plugin (only 1) + * +----------------------+ + * | nsIPlugin or |<- - - - - -NSGetFactory() + * | nsILiveConnectPlugin | + * +----------------------+ + * | + * | + * | instances (many) streams to receive URL data (many) + * | +-------------------+ +-----------------+ + * | | nsIPluginInstance |+ | nsIPluginStream |+ + * | | || | || + * | +-------------------+| +-----------------+| + * | +------|-----------+ +------|---------+ + * | | | + * | PLUGIN SIDE |peer |peer + *~~~~|~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~ + * | BROWSER SIDE | | + * | v v + * | +---------------------------------+ +----------------------------+ + * | | nsIPluginInstancePeer |+ | nsIPluginStreamPeer |+ + * | | nsIPluginInstancePeer2 || | nsISeekablePluginStreamPeer|| + * | | nsIWindowlessPluginInstancePeer || | nsIPluginstreamPeer2 || + * | | nsILiveConnectPluginInstancePeer|| +----------------------------+| + * | | nsIPluginTagInfo || +---------------------------+ + * | | nsIPluginTagInfo2 || + * | +---------------------------------+| + * | +--------------------------------+ + * | + * | + * v the browser (only 1) + * +---------------------+ + * | nsIPluginManager | + * | nsIPluginManager2 | + * | nsIFileUtilities | + * | nsIPref | + * | nsICacheManager ... | + * +---------------------+ + * + */ + +#ifndef nsplugins_h___ +#define nsplugins_h___ + +#include "nsRepository.h" // for NSGetFactory + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces which must be implemented by a plugin + * These interfaces have NPP equivalents in pre-5.0 browsers (see npapi.h). + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * NSGetFactory is the main entry point to the plugin's DLL. The plugin manager + * finds this symbol and calls it to create the plugin class. Once the plugin + * object is returned to the plugin manager, instances on the page are created + * by calling nsIPlugin::CreateInstance. + */ +// (Declared in nsRepository.h) +//extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, +// nsIFactory **aFactory); + +/** + * A plugin object is used to create new plugin instances. It manages the + * global state of all plugins with the same implementation. + */ +#include "nsIPlugin.h" + +/** + * A plugin instance represents a particular activation of a plugin on a page. + */ +#include "nsIPluginInstance.h" + +/** + * A plugin stream gets instantiated when a plugin instance receives data from + * the browser. + */ +#include "nsIPluginStream.h" + +/** + * The nsILiveConnectPlugin interface provides additional operations that a + * plugin must implement if it is to be controlled by JavaScript through + * LiveConnect. + * + * Note that this interface is part of a new JNI-based LiveConnect + * implementation and superceeds that provided prior to Communicator 5.0. + */ +#include "nsILiveConnectPlugin.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces implemented by the browser: + * These interfaces have NPN equivalents in pre-5.0 browsers (see npapi.h). + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The plugin manager which is the main point of interaction with the browser + * and provides general operations needed by a plugin. + */ +#include "nsIPluginManager.h" + +/** + * A plugin instance peer gets created by the browser and associated with each + * plugin instance to represent tag information and other callbacks needed by + * the plugin instance. + */ +#include "nsIPluginInstancePeer.h" + +/** + * The nsIPluginTagInfo interface provides information about the html tag + * that was used to instantiate the plugin instance. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIPluginTagInfo.h" + +/** + * The nsIWindowlessPluginInstancePeer provides additional operations for + * windowless plugins. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIWindowlessPluginInstancePeer.h" + +/** + * A plugin stream peer gets create by the browser and associated with each + * plugin stream to represent stream and URL information, and provides + * other callbacks needed by the plugin stream. + */ +#include "nsIPluginStreamPeer.h" + +/** + * The nsISeekablePluginStreamPeer provides additional operations for seekable + * plugin streams. + * + * To obtain: QueryInterface on nsIPluginStreamPeer + */ +#include "nsISeekablePluginStreamPeer.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces implemented by the browser (new for 5.0): + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The nsIPluginManager2 interface provides additional plugin manager features + * only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginManager + */ +#include "nsIPluginManager2.h" + +/** + * The nsIFileUtilities interface provides operations to manage temporary + * files and directories. + * + * To obtain: QueryInterface on nsIPluginManager + */ +#include "nsIFileUtilities.h" + +/** + * The nsIPluginInstancePeer2 interface provides additional plugin instance + * peer features only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIPluginInstancePeer2.h" + +/** + * The nsILiveConnectPluginInstancePeer allows plugins to be manipulated + * by JavaScript, providing basic scriptability. + * + * Note that this interface is part of a new JNI-based LiveConnect + * implementation and superceeds that provided prior to Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsILiveConnectPluginInstancePeer.h" + +/** + * The nsIPluginStreamPeer2 interface provides additional plugin stream + * peer features only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginStreamPeer + */ +#include "nsIPluginStreamPeer2.h" + +/** + * The nsIPluginTagInfo2 interface provides additional html tag information + * only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginTagInfo + */ +#include "nsIPluginTagInfo2.h" + +//////////////////////////////////////////////////////////////////////////////// +#endif // nsplugins_h___ diff --git a/mozilla/modules/plugin/base/public/nsplugindefs.h b/mozilla/modules/plugin/base/public/nsplugindefs.h new file mode 100644 index 00000000000..3d2e45d9b07 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nsplugindefs.h @@ -0,0 +1,365 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsplugindefs_h___ +#define nsplugindefs_h___ + +#ifdef __OS2__ +#pragma pack(1) +#endif + +#ifdef XP_MAC + #include + #include +#endif + +#ifdef XP_UNIX + #include + #include +#endif + +#ifdef XP_PC + #include +#endif + +//////////////////////////////////////////////////////////////////////////////// + +/* The OS/2 version of Netscape uses RC_DATA to define the + mime types, file extentions, etc that are required. + Use a vertical bar to seperate types, end types with \0. + FileVersion and ProductVersion are 32bit ints, all other + entries are strings the MUST be terminated wwith a \0. + +AN EXAMPLE: + +RCDATA NS_INFO_ProductVersion { 1,0,0,1,} + +RCDATA NS_INFO_MIMEType { "video/x-video|", + "video/x-flick\0" } +RCDATA NS_INFO_FileExtents { "avi|", + "flc\0" } +RCDATA NS_INFO_FileOpenName{ "MMOS2 video player(*.avi)|", + "MMOS2 Flc/Fli player(*.flc)\0" } + +RCDATA NS_INFO_FileVersion { 1,0,0,1 } +RCDATA NS_INFO_CompanyName { "Netscape Communications\0" } +RCDATA NS_INFO_FileDescription { "NPAVI32 Extension DLL\0" +RCDATA NS_INFO_InternalName { "NPAVI32\0" ) +RCDATA NS_INFO_LegalCopyright { "Copyright Netscape Communications \251 1996\0" +RCDATA NS_INFO_OriginalFilename { "NVAPI32.DLL" } +RCDATA NS_INFO_ProductName { "NPAVI32 Dynamic Link Library\0" } + +*/ + + +/* RC_DATA types for version info - required */ +#define NS_INFO_ProductVersion 1 +#define NS_INFO_MIMEType 2 +#define NS_INFO_FileOpenName 3 +#define NS_INFO_FileExtents 4 + +/* RC_DATA types for version info - used if found */ +#define NS_INFO_FileDescription 5 +#define NS_INFO_ProductName 6 + +/* RC_DATA types for version info - optional */ +#define NS_INFO_CompanyName 7 +#define NS_INFO_FileVersion 8 +#define NS_INFO_InternalName 9 +#define NS_INFO_LegalCopyright 10 +#define NS_INFO_OriginalFilename 11 + +#ifndef RC_INVOKED + +//////////////////////////////////////////////////////////////////////////////// +// Structures and definitions + +#ifdef XP_MAC +#pragma options align=mac68k +#endif + +typedef const char* nsMIMEType; + +struct nsByteRange { + PRInt32 offset; /* negative offset means from the end */ + PRUint32 length; + struct nsByteRange* next; +}; + +struct nsRect { + PRUint16 top; + PRUint16 left; + PRUint16 bottom; + PRUint16 right; +}; + +//////////////////////////////////////////////////////////////////////////////// +// Unix specific structures and definitions + +#ifdef XP_UNIX + +#include + +/* + * Callback Structures. + * + * These are used to pass additional platform specific information. + */ +enum nsPluginCallbackType { + nsPluginCallbackType_SetWindow = 1, + nsPluginCallbackType_Print +}; + +struct nsPluginAnyCallbackStruct { + PRInt32 type; +}; + +struct nsPluginSetWindowCallbackStruct { + PRInt32 type; + Display* display; + Visual* visual; + Colormap colormap; + PRUint32 depth; +}; + +struct nsPluginPrintCallbackStruct { + PRInt32 type; + FILE* fp; +}; + +#endif /* XP_UNIX */ + +//////////////////////////////////////////////////////////////////////////////// + +// List of variable names for which NPP_GetValue shall be implemented +enum nsPluginVariable { + nsPluginVariable_NameString = 1, + nsPluginVariable_DescriptionString, + nsPluginVariable_WindowBool, // XXX go away + nsPluginVariable_TransparentBool, // XXX go away? + nsPluginVariable_JavaClass, // XXX go away + nsPluginVariable_WindowSize, + nsPluginVariable_TimerInterval + // XXX add MIMEDescription (for unix) (but GetValue is on the instance, not the class) +}; + +// List of variable names for which NPN_GetValue is implemented by Mozilla +enum nsPluginManagerVariable { + nsPluginManagerVariable_XDisplay = 1, + nsPluginManagerVariable_XtAppContext, + nsPluginManagerVariable_NetscapeWindow, + nsPluginManagerVariable_JavascriptEnabledBool, // XXX prefs accessor api + nsPluginManagerVariable_ASDEnabledBool, // XXX prefs accessor api + nsPluginManagerVariable_IsOfflineBool // XXX prefs accessor api +}; + +//////////////////////////////////////////////////////////////////////////////// + +enum nsPluginType { + nsPluginType_Embedded = 1, + nsPluginType_Full +}; + +// XXX this can go away now +enum NPStreamType { + NPStreamType_Normal = 1, + NPStreamType_Seek, + NPStreamType_AsFile, + NPStreamType_AsFileOnly +}; + +#define NP_STREAM_MAXREADY (((unsigned)(~0)<<1)>>1) + +/* + * The type of a NPWindow - it specifies the type of the data structure + * returned in the window field. + */ +enum nsPluginWindowType { + nsPluginWindowType_Window = 1, + nsPluginWindowType_Drawable +}; + +struct nsPluginWindow { + void* window; /* Platform specific window handle */ + /* OS/2: x - Position of bottom left corner */ + /* OS/2: y - relative to visible netscape window */ + PRUint32 x; /* Position of top left corner relative */ + PRUint32 y; /* to a netscape page. */ + PRUint32 width; /* Maximum window size */ + PRUint32 height; + nsRect clipRect; /* Clipping rectangle in port coordinates */ + /* Used by MAC only. */ +#ifdef XP_UNIX + void* ws_info; /* Platform-dependent additonal data */ +#endif /* XP_UNIX */ + nsPluginWindowType type; /* Is this a window or a drawable? */ +}; + +struct nsPluginFullPrint { + PRBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */ + /* printing */ + PRBool printOne; /* TRUE if plugin should print one copy */ + /* to default printer */ + void* platformPrint; /* Platform-specific printing info */ +}; + +struct nsPluginEmbedPrint { + nsPluginWindow window; + void* platformPrint; /* Platform-specific printing info */ +}; + +struct nsPluginPrint { + nsPluginType mode; /* NP_FULL or nsPluginType_Embedded */ + union + { + nsPluginFullPrint fullPrint; /* if mode is NP_FULL */ + nsPluginEmbedPrint embedPrint; /* if mode is nsPluginType_Embedded */ + } print; +}; + +struct nsPluginEvent { + +#if defined(XP_MAC) + EventRecord* event; + void* window; + +#elif defined(XP_PC) + uint16 event; + uint32 wParam; + uint32 lParam; + +#elif defined(XP_OS2) + uint32 event; + uint32 wParam; + uint32 lParam; + +#elif defined(XP_UNIX) + XEvent event; + +#endif +}; + +#ifdef XP_MAC +typedef RgnHandle nsRegion; +#elif defined(XP_PC) +typedef HRGN nsRegion; +#elif defined(XP_UNIX) +typedef Region nsRegion; +#else +typedef void *nsRegion; +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Mac-specific structures and definitions. + +#ifdef XP_MAC + +struct NPPort { + CGrafPtr port; /* Grafport */ + PRInt32 portx; /* position inside the topmost window */ + PRInt32 porty; +}; + +/* + * Non-standard event types that can be passed to HandleEvent + */ +#define getFocusEvent (osEvt + 16) +#define loseFocusEvent (osEvt + 17) +#define adjustCursorEvent (osEvt + 18) +#define menuCommandEvent (osEvt + 19) + +#endif /* XP_MAC */ + +//////////////////////////////////////////////////////////////////////////////// +// Error and Reason Code definitions + +enum nsPluginError { + nsPluginError_Base = 0, + nsPluginError_NoError = 0, + nsPluginError_GenericError, + nsPluginError_InvalidInstanceError, + nsPluginError_InvalidFunctableError, + nsPluginError_ModuleLoadFailedError, + nsPluginError_OutOfMemoryError, + nsPluginError_InvalidPluginError, + nsPluginError_InvalidPluginDirError, + nsPluginError_IncompatibleVersionError, + nsPluginError_InvalidParam, + nsPluginError_InvalidUrl, + nsPluginError_FileNotFound, + nsPluginError_NoData, + nsPluginError_StreamNotSeekable +}; + +#define NPCallFailed( code ) ((code) != nsPluginError_NoError) + +enum nsPluginReason { + nsPluginReason_Base = 0, + nsPluginReason_Done = 0, + nsPluginReason_NetworkErr, + nsPluginReason_UserBreak, + nsPluginReason_NoReason +}; + +//////////////////////////////////////////////////////////////////////////////// +// Classes +//////////////////////////////////////////////////////////////////////////////// + +// Classes that must be implemented by the plugin DLL: +struct nsIPlugin; // plugin class (MIME-type handler) +class nsILiveConnectPlugin; // subclass of nsIPlugin +class nsIPluginInstance; // plugin instance +class nsIPluginStream; // stream to receive data from the browser + +// Classes that are implemented by the browser: +class nsIPluginManager; // minimum browser requirements +class nsIFileUtilities; // file utilities (accessible from nsIPluginManager) +class nsIPluginInstancePeer; // parts of nsIPluginInstance implemented by the browser +class nsIWindowlessPluginInstancePeer; // subclass of nsIPluginInstancePeer for windowless plugins +class nsIPluginTagInfo; // describes html tag (accessible from nsIPluginInstancePeer) +class nsILiveConnectPluginInstancePeer; // subclass of nsIPluginInstancePeer +class nsIPluginStreamPeer; // parts of nsIPluginStream implemented by the browser +class nsISeekablePluginStreamPeer; // seekable subclass of nsIPluginStreamPeer + +//////////////////////////////////////////////////////////////////////////////// + +#ifdef XP_MAC +#pragma options align=reset +#endif + +#endif /* RC_INVOKED */ +#ifdef __OS2__ +#pragma pack() +#endif + +#endif // nsplugindefs_h___ diff --git a/mozilla/modules/plugin/makefile.win b/mozilla/modules/plugin/makefile.win new file mode 100644 index 00000000000..b4dccf75274 --- /dev/null +++ b/mozilla/modules/plugin/makefile.win @@ -0,0 +1,30 @@ +#//------------------------------------------------------------------------ +#// +#// Makefile to build the MODULES\APPLET tree +#// +#//------------------------------------------------------------------------ + +#//------------------------------------------------------------------------ +#// +#// Specify the depth of the current directory relative to the +#// root of NS +#// +#//------------------------------------------------------------------------ +DEPTH=..\.. + +#//------------------------------------------------------------------------ +#// +#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...) +#// (these must come before the common makefiles are included) +#// +#// DIRS - There are subdirectories to process +#// +#//------------------------------------------------------------------------ +DIRS= public src + +#//------------------------------------------------------------------------ +#// +#// Include the common makefile rules +#// +#//------------------------------------------------------------------------ +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/modules/plugin/public/MANIFEST b/mozilla/modules/plugin/public/MANIFEST new file mode 100644 index 00000000000..9f6a56fcb1e --- /dev/null +++ b/mozilla/modules/plugin/public/MANIFEST @@ -0,0 +1,41 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +# This is a list of local files which get copied to the mozilla:dist directory +# + +nsIFileUtilities.h +nsIJRILiveConnectPlugin.h +nsIJRILiveConnectPluginInstancePeer.h +nsILiveConnectPlugin.h +nsILiveConnectPluginInstancePeer.h +nsIPlugin.h +nsIPluginInstance.h +nsIPluginInstancePeer.h +nsIPluginInstancePeer2.h +nsIPluginManager.h +nsIPluginManager2.h +nsIPluginStream.h +nsIPluginStreamPeer.h +nsIPluginStreamPeer2.h +nsIPluginTagInfo.h +nsIPluginTagInfo2.h +nsISeekablePluginStreamPeer.h +nsIWindowlessPluginInstancePeer.h +nsplugin.h +nsplugindefs.h diff --git a/mozilla/modules/plugin/public/Makefile b/mozilla/modules/plugin/public/Makefile new file mode 100644 index 00000000000..f87022e6eba --- /dev/null +++ b/mozilla/modules/plugin/public/Makefile @@ -0,0 +1,44 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +DEPTH = ../../.. + +MODULE = plugin + +EXPORTS = \ + nsIFileUtilities.h \ + nsIJRILiveConnectPlugin.h \ + nsIJRILiveConnectPluginInstancePeer.h \ + nsILiveConnectPlugin.h \ + nsILiveConnectPluginInstancePeer.h \ + nsIPlugin.h \ + nsIPluginInstance.h \ + nsIPluginInstancePeer.h \ + nsIPluginInstancePeer2.h \ + nsIPluginManager.h \ + nsIPluginManager2.h \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsIPluginTagInfo.h \ + nsIPluginTagInfo2.h \ + nsISeekablePluginStreamPeer.h \ + nsIWindowlessPluginInstancePeer.h \ + nsplugin.h \ + nsplugindefs.h + +include $(DEPTH)/config/rules.mk diff --git a/mozilla/modules/plugin/public/makefile.win b/mozilla/modules/plugin/public/makefile.win new file mode 100644 index 00000000000..4dae17aff4d --- /dev/null +++ b/mozilla/modules/plugin/public/makefile.win @@ -0,0 +1,47 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +IGNORE_MANIFEST=1 + +DEPTH = ..\..\.. + +MODULE = plugin + +EXPORTS = \ + nsIFileUtilities.h \ + nsIJRILiveConnectPlugin.h \ + nsIJRILiveConnectPluginInstancePeer.h \ + nsILiveConnectPlugin.h \ + nsILiveConnectPluginInstancePeer.h \ + nsIPlugin.h \ + nsIPluginInstance.h \ + nsIPluginInstancePeer.h \ + nsIPluginInstancePeer2.h \ + nsIPluginManager.h \ + nsIPluginManager2.h \ + nsIPluginStream.h \ + nsIPluginStreamPeer.h \ + nsIPluginStreamPeer2.h \ + nsIPluginTagInfo.h \ + nsIPluginTagInfo2.h \ + nsISeekablePluginStreamPeer.h \ + nsIWindowlessPluginInstancePeer.h \ + nsplugin.h \ + nsplugindefs.h + +include <$(DEPTH)/config/rules.mak> + diff --git a/mozilla/modules/plugin/public/nsIFileUtilities.h b/mozilla/modules/plugin/public/nsIFileUtilities.h new file mode 100644 index 00000000000..880435d4d9f --- /dev/null +++ b/mozilla/modules/plugin/public/nsIFileUtilities.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIFileUtilities_h___ +#define nsIFileUtilities_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// File Utilities Interface +// This interface reflects operations only available in Communicator 5.0. + +class nsIFileUtilities : public nsISupports { +public: + + // QueryInterface on nsIPluginManager to get this. + + NS_IMETHOD_(const char*) + GetProgramPath(void) = 0; + + NS_IMETHOD_(const char*) + GetTempDirPath(void) = 0; + + enum FileNameType { SIGNED_APPLET_DBNAME, TEMP_FILENAME }; + + NS_IMETHOD_(nsresult) + GetFileName(const char* fn, FileNameType type, + char* resultBuf, PRUint32 bufLen) = 0; + + NS_IMETHOD_(nsresult) + NewTempFileName(const char* prefix, char* resultBuf, PRUint32 bufLen) = 0; + +}; + +#define NS_IFILEUTILITIES_IID \ +{ /* 89a31ce0-019a-11d2-815b-006008119d7a */ \ + 0x89a31ce0, \ + 0x019a, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIFileUtilities_h___ */ diff --git a/mozilla/modules/plugin/public/nsIJRILiveConnectPlugin.h b/mozilla/modules/plugin/public/nsIJRILiveConnectPlugin.h new file mode 100644 index 00000000000..bc2382ced4b --- /dev/null +++ b/mozilla/modules/plugin/public/nsIJRILiveConnectPlugin.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIJRILiveConnectPlugin_h__ +#define nsIJRILiveConnectPlugin_h__ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// JRI-Based LiveConnect Classes +//////////////////////////////////////////////////////////////////////////////// +// +// This stuff is here so that the browser can support older JRI-based +// LiveConnected plugins (when using old plugin to new C++-style plugin +// adapter code). +// +// Warning: Don't use this anymore, unless you're sure that you have to! +//////////////////////////////////////////////////////////////////////////////// + +#include "jri.h" // ancient + +//////////////////////////////////////////////////////////////////////////////// +// JRILiveConnect Plugin Interface +// This interface defines additional entry points that a plugin developer needs +// to implement in order for the plugin to support JRI-based LiveConnect, +// i.e. be scriptable by Java or JavaScript. + +class nsIJRILiveConnectPlugin : public nsIPlugin { +public: + + // (Corresponds to NPP_GetJavaClass.) + NS_IMETHOD_(jref) + GetJavaClass(void) = 0; + +}; + +#define NS_IJRILIVECONNECTPLUGIN_IID \ +{ /* c94058e0-f772-11d1-815b-006008119d7a */ \ + 0xc94058e0, \ + 0xf772, \ + 0x11d1, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIJRILiveConnectPlugin_h__ */ diff --git a/mozilla/modules/plugin/public/nsIJRILiveConnectPluginInstancePeer.h b/mozilla/modules/plugin/public/nsIJRILiveConnectPluginInstancePeer.h new file mode 100644 index 00000000000..bbd8bac6f1b --- /dev/null +++ b/mozilla/modules/plugin/public/nsIJRILiveConnectPluginInstancePeer.h @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIJRILiveConnectPluginInstancePeer_h__ +#define nsIJRILiveConnectPluginInstancePeer_h__ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// JRI-Based LiveConnect Classes +//////////////////////////////////////////////////////////////////////////////// +// +// This stuff is here so that the browser can support older JRI-based +// LiveConnected plugins (when using old plugin to new C++-style plugin +// adapter code). +// +// Warning: Don't use this anymore, unless you're sure that you have to! +//////////////////////////////////////////////////////////////////////////////// + +#include "jri.h" // ancient + +//////////////////////////////////////////////////////////////////////////////// +// JRILiveConnect Plugin Instance Peer Interface +// Browsers that support JRI-based LiveConnect implement this subclass of +// plugin instance peer. + +class nsIJRILiveConnectPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPN_GetJavaPeer.) + NS_IMETHOD_(jref) + GetJavaPeer(void) = 0; + +}; + +#define NS_IJRILIVECONNECTPLUGININSTANCEPEER_IID \ +{ /* 25b63f40-f773-11d1-815b-006008119d7a */ \ + 0x25b63f40, \ + 0xf773, \ + 0x11d1, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +// QueryInterface for this IID on nsIPluginManager to get a JRIEnv +// XXX change this +#define NS_IJRIENV_IID \ +{ /* f9d4ea00-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xf9d4ea00, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIJRILiveConnectPluginInstancePeer_h__ */ diff --git a/mozilla/modules/plugin/public/nsILiveConnectPlugin.h b/mozilla/modules/plugin/public/nsILiveConnectPlugin.h new file mode 100644 index 00000000000..31753271bcd --- /dev/null +++ b/mozilla/modules/plugin/public/nsILiveConnectPlugin.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsILiveConnectPlugin_h__ +#define nsILiveConnectPlugin_h__ + +#include "nsplugindefs.h" +#include "jni.h" // standard JVM API + +//////////////////////////////////////////////////////////////////////////////// +// LiveConnect Plugin Interface +// This interface defines additional entry points that a plugin developer needs +// to implement in order for the plugin to support JNI-based LiveConnect, +// i.e. be scriptable by Java or JavaScript. + +class nsILiveConnectPlugin : public nsIPlugin { +public: + + // (New JNI-based entry point, roughly corresponds to NPP_GetJavaClass.) + NS_IMETHOD_(jclass) + GetJavaClass(void) = 0; + +}; + +#define NS_ILIVECONNECTPLUGIN_IID \ +{ /* cf134df0-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xcf134df0, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsILiveConnectPlugin_h__ */ diff --git a/mozilla/modules/plugin/public/nsILiveConnectPluginInstancePeer.h b/mozilla/modules/plugin/public/nsILiveConnectPluginInstancePeer.h new file mode 100644 index 00000000000..508b51f3e08 --- /dev/null +++ b/mozilla/modules/plugin/public/nsILiveConnectPluginInstancePeer.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsILiveConnectPluginInstancePeer_h___ +#define nsILiveConnectPluginInstancePeer_h___ + +#include "nsplugindefs.h" +#include "jni.h" // standard JVM API + +//////////////////////////////////////////////////////////////////////////////// +// LiveConnect Plugin Instance Peer Interface +// Browsers that support JNI-based LiveConnect implement this subclass of +// plugin instance peer. + +class nsILiveConnectPluginInstancePeer : public nsISupports { +public: + + // (New JNI-based entry point, roughly corresponds to NPN_GetJavaPeer.) + NS_IMETHOD_(jobject) + GetJavaPeer(void) = 0; + +}; + +#define NS_ILIVECONNECTPLUGININSTANCEPEER_IID \ +{ /* 1e3502a0-a1bd-11d1-85b1-00805f0e4dfe */ \ + 0x1e3502a0, \ + 0xa1bd, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +// QueryInterface for this IID on nsIPluginManager to get a JNIEnv +// XXX change this +#define NS_IJNIENV_IID \ +{ /* 04610650-a1bd-11d1-85b1-00805f0e4dfe */ \ + 0x04610650, \ + 0xa1bd, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsILiveConnectPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPlugin.h b/mozilla/modules/plugin/public/nsIPlugin.h new file mode 100644 index 00000000000..8512a581534 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPlugin.h @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPlugin_h___ +#define nsIPlugin_h___ + +#include "nsplugindefs.h" +#include "nsIFactory.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Interface +// This is the minimum interface plugin developers need to support in order to +// implement a plugin. The plugin manager may QueryInterface for more specific +// plugin types, e.g. nsILiveConnectPlugin. + +struct nsIPlugin : public nsIFactory { +public: + + // This call initializes the plugin and will be called before any new + // instances are created. It is passed browserInterfaces on which QueryInterface + // may be used to obtain an nsIPluginManager, and other interfaces. + NS_IMETHOD_(nsPluginError) + Initialize(nsISupports* browserInterfaces) = 0; + + // (Corresponds to NPP_Shutdown.) + // Called when the browser is done with the plugin factory, or when + // the plugin is disabled by the user. + NS_IMETHOD_(nsPluginError) + Shutdown(void) = 0; + + // (Corresponds to NPP_GetMIMEDescription.) + NS_IMETHOD_(const char*) + GetMIMEDescription(void) = 0; + + // (Corresponds to NPP_GetValue.) + NS_IMETHOD_(nsPluginError) + GetValue(nsPluginVariable variable, void *value) = 0; + + // (Corresponds to NPP_SetValue.) + NS_IMETHOD_(nsPluginError) + SetValue(nsPluginVariable variable, void *value) = 0; + + // The old NPP_New call has been factored into two plugin instance methods: + // + // CreateInstance -- called once, after the plugin instance is created. This + // method is used to initialize the new plugin instance (although the actual + // plugin instance object will be created by the plugin manager). + // + // nsIPluginInstance::Start -- called when the plugin instance is to be + // started. This happens in two circumstances: (1) after the plugin instance + // is first initialized, and (2) after a plugin instance is returned to + // (e.g. by going back in the window history) after previously being stopped + // by the Stop method. + +}; + +#define NS_IPLUGIN_IID \ +{ /* df773070-0199-11d2-815b-006008119d7a */ \ + 0xdf773070, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPlugin_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginInstance.h b/mozilla/modules/plugin/public/nsIPluginInstance.h new file mode 100644 index 00000000000..29825c92f13 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginInstance.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstance_h___ +#define nsIPluginInstance_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Interface + +// (Corresponds to NPP object.) +class nsIPluginInstance : public nsISupports { +public: + + NS_IMETHOD_(nsPluginError) + Initialize(nsIPluginInstancePeer* peer) = 0; + + // Required backpointer to the peer. + NS_IMETHOD_(nsIPluginInstancePeer*) + GetPeer(void) = 0; + + // See comment for nsIPlugin::CreateInstance, above. + NS_IMETHOD_(nsPluginError) + Start(void) = 0; + + // The old NPP_Destroy call has been factored into two plugin instance + // methods: + // + // Stop -- called when the plugin instance is to be stopped (e.g. by + // displaying another plugin manager window, causing the page containing + // the plugin to become removed from the display). + // + // Release -- called once, before the plugin instance peer is to be + // destroyed. This method is used to destroy the plugin instance. + + NS_IMETHOD_(nsPluginError) + Stop(void) = 0; + + NS_IMETHOD_(nsPluginError) + Destroy(void) = 0; + + // (Corresponds to NPP_SetWindow.) + NS_IMETHOD_(nsPluginError) + SetWindow(nsPluginWindow* window) = 0; + + // (Corresponds to NPP_NewStream.) + NS_IMETHOD_(nsPluginError) + NewStream(nsIPluginStreamPeer* peer, nsIPluginStream* *result) = 0; + + // (Corresponds to NPP_Print.) + NS_IMETHOD_(void) + Print(nsPluginPrint* platformPrint) = 0; + + // (Corresponds to NPP_HandleEvent.) + // Note that for Unix and Mac the nsPluginEvent structure is different + // from the old NPEvent structure -- it's no longer the native event + // record, but is instead a struct. This was done for future extensibility, + // and so that the Mac could receive the window argument too. For Windows + // and OS2, it's always been a struct, so there's no change for them. + NS_IMETHOD_(PRInt16) + HandleEvent(nsPluginEvent* event) = 0; + + // (Corresponds to NPP_URLNotify.) + NS_IMETHOD_(void) + URLNotify(const char* url, const char* target, + nsPluginReason reason, void* notifyData) = 0; + +}; + +#define NS_IPLUGININSTANCE_IID \ +{ /* ebe00f40-0199-11d2-815b-006008119d7a */ \ + 0xebe00f40, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstance_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginInstancePeer.h b/mozilla/modules/plugin/public/nsIPluginInstancePeer.h new file mode 100644 index 00000000000..98229dee428 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginInstancePeer.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstancePeer_h___ +#define nsIPluginInstancePeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Peer Interface + +enum nsPluginTagType { + nsPluginTagType_Unknown, + nsPluginTagType_Embed, + nsPluginTagType_Object, + nsPluginTagType_Applet +}; + +class nsIPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPP_New's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void) = 0; + + // (Corresponds to NPP_New's mode argument.) + NS_IMETHOD_(nsPluginType) + GetMode(void) = 0; + + // (Corresponds to NPN_NewStream.) + NS_IMETHOD_(nsPluginError) + NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result) = 0; + + // (Corresponds to NPN_Status.) + NS_IMETHOD_(void) + ShowStatus(const char* message) = 0; + +}; + +#define NS_IPLUGININSTANCEPEER_IID \ +{ /* 4b7cea20-019b-11d2-815b-006008119d7a */ \ + 0x4b7cea20, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginInstancePeer2.h b/mozilla/modules/plugin/public/nsIPluginInstancePeer2.h new file mode 100644 index 00000000000..f3b3acbe02f --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginInstancePeer2.h @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginInstancePeer2_h___ +#define nsIPluginInstancePeer2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Peer 2 Interface +// These extensions to nsIPluginManager are only available in Communicator 5.0. + +class nsIPluginInstancePeer2 : public nsIPluginInstancePeer { +public: + + //////////////////////////////////////////////////////////////////////////// + // New top-level window handling calls for Mac: + + NS_IMETHOD_(void) + RegisterWindow(void* window) = 0; + + NS_IMETHOD_(void) + UnregisterWindow(void* window) = 0; + + // Menu ID allocation calls for Mac: + NS_IMETHOD_(PRInt16) + AllocateMenuID(PRBool isSubmenu) = 0; + + // On the mac (and most likely win16), network activity can + // only occur on the main thread. Therefore, we provide a hook + // here for the case that the main thread needs to tickle itself. + // In this case, we make sure that we give up the monitor so that + // the tickle code can notify it without freezing. + NS_IMETHOD_(PRBool) + Tickle(void) = 0; + +}; + +#define NS_IPLUGININSTANCEPEER2_IID \ +{ /* 51b52b80-019b-11d2-815b-006008119d7a */ \ + 0x51b52b80, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginInstancePeer2_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginManager.h b/mozilla/modules/plugin/public/nsIPluginManager.h new file mode 100644 index 00000000000..dffd0376f75 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginManager.h @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginManager_h___ +#define nsIPluginManager_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager Interface +// This interface defines the minimum set of functionality that a plugin +// manager will support if it implements plugins. Plugin implementations can +// QueryInterface to determine if a plugin manager implements more specific +// APIs for the plugin to use. + +class nsIPluginManager : public nsISupports { +public: + + // (Corresponds to NPN_ReloadPlugins.) + NS_IMETHOD_(void) + ReloadPlugins(PRBool reloadPages) = 0; + + // (Corresponds to NPN_MemAlloc.) + NS_IMETHOD_(void*) + MemAlloc(PRUint32 size) = 0; + + // (Corresponds to NPN_MemFree.) + NS_IMETHOD_(void) + MemFree(void* ptr) = 0; + + // (Corresponds to NPN_MemFlush.) + NS_IMETHOD_(PRUint32) + MemFlush(PRUint32 size) = 0; + + // (Corresponds to NPN_UserAgent.) + NS_IMETHOD_(const char*) + UserAgent(void) = 0; + + // (Corresponds to NPN_GetValue.) + NS_IMETHOD_(nsPluginError) + GetValue(nsPluginManagerVariable variable, void *value) = 0; + + // (Corresponds to NPN_SetValue.) + NS_IMETHOD_(nsPluginError) + SetValue(nsPluginManagerVariable variable, void *value) = 0; + + + // (Corresponds to NPN_GetURL and NPN_GetURLNotify.) + // notifyData: When present, URLNotify is called passing the notifyData back + // to the client. When NULL, this call behaves like NPN_GetURL. + // New arguments: + // peer: A plugin instance peer. The peer's window will be used to display + // progress information. If NULL, the load happens in the background. + // altHost: An IP-address string that will be used instead of the host + // specified in the URL. This is used to prevent DNS-spoofing attacks. + // Can be defaulted to NULL meaning use the host in the URL. + // referrer: + // forceJSEnabled: Forces JavaScript to be enabled for 'javascript:' URLs, + // even if the user currently has JavaScript disabled. + NS_IMETHOD_(nsPluginError) + GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData = NULL, + const char* altHost = NULL, const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE) = 0; + + // (Corresponds to NPN_PostURL and NPN_PostURLNotify.) + // notifyData: When present, URLNotify is called passing the notifyData back + // to the client. When NULL, this call behaves like NPN_GetURL. + // New arguments: + // peer: A plugin instance peer. The peer's window will be used to display + // progress information. If NULL, the load happens in the background. + // altHost: An IP-address string that will be used instead of the host + // specified in the URL. This is used to prevent DNS-spoofing attacks. + // Can be defaulted to NULL meaning use the host in the URL. + // referrer: + // forceJSEnabled: Forces JavaScript to be enabled for 'javascript:' URLs, + // even if the user currently has JavaScript disabled. + // postHeaders: A string containing post headers. + // postHeadersLength: The length of the post headers string. + NS_IMETHOD_(nsPluginError) + PostURL(nsISupports* peer, const char* url, const char* target, PRUint32 bufLen, + const char* buf, PRBool file, void* notifyData = NULL, + const char* altHost = NULL, const char* referrer = NULL, + PRBool forceJSEnabled = PR_FALSE, + PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + +}; + +#define NS_IPLUGINMANAGER_IID \ +{ /* f10b9600-a1bc-11d1-85b1-00805f0e4dfe */ \ + 0xf10b9600, \ + 0xa1bc, \ + 0x11d1, \ + {0x85, 0xb1, 0x00, 0x80, 0x5f, 0x0e, 0x4d, 0xfe} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginManager_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginManager2.h b/mozilla/modules/plugin/public/nsIPluginManager2.h new file mode 100644 index 00000000000..2ac771339e9 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginManager2.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginManager2_h___ +#define nsIPluginManager2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager 2 Interface +// These extensions to nsIPluginManager are only available in Communicator 5.0. + +class nsIPluginManager2 : public nsIPluginManager { +public: + + NS_IMETHOD_(void) + BeginWaitCursor(void) = 0; + + NS_IMETHOD_(void) + EndWaitCursor(void) = 0; + + NS_IMETHOD_(PRBool) + SupportsURLProtocol(const char* protocol) = 0; + +}; + +#define NS_IPLUGINMANAGER2_IID \ +{ /* 29c4ae70-019a-11d2-815b-006008119d7a */ \ + 0x29c4ae70, \ + 0x019a, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginManager2_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginStream.h b/mozilla/modules/plugin/public/nsIPluginStream.h new file mode 100644 index 00000000000..e3f9b2c7e13 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginStream.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStream_h___ +#define nsIPluginStream_h___ + +#include "nsplugindefs.h" +#include "nsIOutputStream.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Interface + +class nsIPluginStream : public nsIOutputStream { +public: + + // (Corresponds to NPP_NewStream's stype return parameter.) + NS_IMETHOD_(NPStreamType) + GetStreamType(void) = 0; + + // (Corresponds to NPP_StreamAsFile.) + NS_IMETHOD_(void) + AsFile(const char* fname) = 0; + +}; + +#define NS_IPLUGINSTREAM_IID \ +{ /* f287dd50-0199-11d2-815b-006008119d7a */ \ + 0xf287dd50, \ + 0x0199, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStream_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginStreamPeer.h b/mozilla/modules/plugin/public/nsIPluginStreamPeer.h new file mode 100644 index 00000000000..da46281e8be --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginStreamPeer.h @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStreamPeer_h___ +#define nsIPluginStreamPeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Peer Interface +// A plugin stream peer is passed to a plugin instance's NewStream call in +// order to indicate that a new stream is to be created and be read by the +// plugin instance. + +class nsIPluginStreamPeer : public nsISupports { +public: + + // (Corresponds to NPStream's url field.) + NS_IMETHOD_(const char*) + GetURL(void) = 0; + + // (Corresponds to NPStream's end field.) + NS_IMETHOD_(PRUint32) + GetEnd(void) = 0; + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD_(PRUint32) + GetLastModified(void) = 0; + + // (Corresponds to NPStream's notifyData field.) + NS_IMETHOD_(void*) + GetNotifyData(void) = 0; + + // (Corresponds to NPP_DestroyStream's reason argument.) + NS_IMETHOD_(nsPluginReason) + GetReason(void) = 0; + + // (Corresponds to NPP_NewStream's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void) = 0; + +}; + +#define NS_IPLUGINSTREAMPEER_IID \ +{ /* 717b1e90-019b-11d2-815b-006008119d7a */ \ + 0x717b1e90, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h b/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h new file mode 100644 index 00000000000..30a69a33631 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginStreamPeer2.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginStreamPeer2_h___ +#define nsIPluginStreamPeer2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Peer Interface +// These extensions to nsIPluginStreamPeer are only available in Communicator 5.0. + +class nsIPluginStreamPeer2 : public nsIPluginStreamPeer { +public: + + NS_IMETHOD_(PRUint32) + GetContentLength(void) = 0; + + NS_IMETHOD_(PRUint32) + GetHeaderFieldCount(void) = 0; + + NS_IMETHOD_(const char*) + GetHeaderFieldKey(PRUint32 index) = 0; + + NS_IMETHOD_(const char*) + GetHeaderField(PRUint32 index) = 0; + +}; + +#define NS_IPLUGINSTREAMPEER2_IID \ +{ /* 77083af0-019b-11d2-815b-006008119d7a */ \ + 0x77083af0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginStreamPeer2_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginTagInfo.h b/mozilla/modules/plugin/public/nsIPluginTagInfo.h new file mode 100644 index 00000000000..3171c135265 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginTagInfo.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginTagInfo_h___ +#define nsIPluginTagInfo_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Tag Info Interface +// This interface provides information about the HTML tag on the page. +// Some day this might get superseded by a DOM API. + +class nsIPluginTagInfo : public nsISupports { +public: + + // QueryInterface on nsIPluginInstancePeer to get this. + + // (Corresponds to NPP_New's argc, argn, and argv arguments.) + // Get a ptr to the paired list of attribute names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + NS_IMETHOD_(nsPluginError) + GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values) = 0; + + // Get the value for the named attribute. Returns NULL + // if the attribute was not set. + NS_IMETHOD_(const char*) + GetAttribute(const char* name) = 0; + +}; + +#define NS_IPLUGINTAGINFO_IID \ +{ /* 5f1ec1d0-019b-11d2-815b-006008119d7a */ \ + 0x5f1ec1d0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginTagInfo_h___ */ diff --git a/mozilla/modules/plugin/public/nsIPluginTagInfo2.h b/mozilla/modules/plugin/public/nsIPluginTagInfo2.h new file mode 100644 index 00000000000..f023e58b7c1 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIPluginTagInfo2.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIPluginTagInfo2_h___ +#define nsIPluginTagInfo2_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Tag Info Interface +// These extensions to nsIPluginTagInfo are only available in Communicator 5.0. + +class nsIPluginTagInfo2 : public nsIPluginTagInfo { +public: + + // QueryInterface on nsIPluginInstancePeer to get this. + + // Get the type of the HTML tag that was used ot instantiate this + // plugin. Currently supported tags are EMBED, OBJECT and APPLET. + NS_IMETHOD_(nsPluginTagType) + GetTagType(void) = 0; + + // Get the complete text of the HTML tag that was + // used to instantiate this plugin + NS_IMETHOD_(const char *) + GetTagText(void) = 0; + + // Get a ptr to the paired list of parameter names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + NS_IMETHOD_(nsPluginError) + GetParameters(PRUint16& n, const char*const*& names, const char*const*& values) = 0; + + // Get the value for the named parameter. Returns null + // if the parameter was not set. + NS_IMETHOD_(const char*) + GetParameter(const char* name) = 0; + + NS_IMETHOD_(const char*) + GetDocumentBase(void) = 0; + + // Return an encoding whose name is specified in: + // http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303 + NS_IMETHOD_(const char*) + GetDocumentEncoding(void) = 0; + + NS_IMETHOD_(const char*) + GetAlignment(void) = 0; + + NS_IMETHOD_(PRUint32) + GetWidth(void) = 0; + + NS_IMETHOD_(PRUint32) + GetHeight(void) = 0; + + NS_IMETHOD_(PRUint32) + GetBorderVertSpace(void) = 0; + + NS_IMETHOD_(PRUint32) + GetBorderHorizSpace(void) = 0; + + // Returns a unique id for the current document on which the + // plugin is displayed. + NS_IMETHOD_(PRUint32) + GetUniqueID(void) = 0; + +}; + +#define NS_IPLUGINTAGINFO2_IID \ +{ /* 6a49c9a0-019b-11d2-815b-006008119d7a */ \ + 0x6a49c9a0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIPluginTagInfo2_h___ */ diff --git a/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h b/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h new file mode 100644 index 00000000000..dcfd07f7519 --- /dev/null +++ b/mozilla/modules/plugin/public/nsISeekablePluginStreamPeer.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsISeekablePluginStreamPeer_h___ +#define nsISeekablePluginStreamPeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Seekable Plugin Stream Peer Interface +// The browser implements this subclass of plugin stream peer if a stream +// is seekable. Plugins can query interface for this type, and call the +// RequestRead method to seek to a particular position in the stream. + +class nsISeekablePluginStreamPeer : public nsISupports { +public: + + // QueryInterface for this class corresponds to NPP_NewStream's + // seekable argument. + + // (Corresponds to NPN_RequestRead.) + NS_IMETHOD_(nsPluginError) + RequestRead(nsByteRange* rangeList) = 0; + +}; + +#define NS_ISEEKABLEPLUGINSTREAMPEER_IID \ +{ /* 7e028d20-019b-11d2-815b-006008119d7a */ \ + 0x7e028d20, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsISeekablePluginStreamPeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsIWindowlessPluginInstancePeer.h b/mozilla/modules/plugin/public/nsIWindowlessPluginInstancePeer.h new file mode 100644 index 00000000000..14d4ccac468 --- /dev/null +++ b/mozilla/modules/plugin/public/nsIWindowlessPluginInstancePeer.h @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this interface fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsIWindowlessPluginInstancePeer_h___ +#define nsIWindowlessPluginInstancePeer_h___ + +#include "nsplugindefs.h" + +//////////////////////////////////////////////////////////////////////////////// +// Windowless Plugin Instance Peer Interface + +class nsIWindowlessPluginInstancePeer : public nsISupports { +public: + + // (Corresponds to NPN_InvalidateRect.) + NS_IMETHOD_(void) + InvalidateRect(nsRect *invalidRect) = 0; + + // (Corresponds to NPN_InvalidateRegion.) + NS_IMETHOD_(void) + InvalidateRegion(nsRegion invalidRegion) = 0; + + // (Corresponds to NPN_ForceRedraw.) + NS_IMETHOD_(void) + ForceRedraw(void) = 0; + +}; + +#define NS_IWINDOWLESSPLUGININSTANCEPEER_IID \ +{ /* 57b4e2f0-019b-11d2-815b-006008119d7a */ \ + 0x57b4e2f0, \ + 0x019b, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +#endif /* nsIWindowlessPluginInstancePeer_h___ */ diff --git a/mozilla/modules/plugin/public/nsplugin.h b/mozilla/modules/plugin/public/nsplugin.h new file mode 100644 index 00000000000..d4f349501e0 --- /dev/null +++ b/mozilla/modules/plugin/public/nsplugin.h @@ -0,0 +1,238 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

This is the master header file that includes most of the other headers + * you'll need to write a plugin. + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The following diagram depicts the relationships between various objects + * implementing the new plugin interfaces. QueryInterface can be used to switch + * between interfaces in the same box: + * + * + * the plugin (only 1) + * +----------------------+ + * | nsIPlugin or |<- - - - - -NSGetFactory() + * | nsILiveConnectPlugin | + * +----------------------+ + * | + * | + * | instances (many) streams to receive URL data (many) + * | +-------------------+ +-----------------+ + * | | nsIPluginInstance |+ | nsIPluginStream |+ + * | | || | || + * | +-------------------+| +-----------------+| + * | +------|-----------+ +------|---------+ + * | | | + * | PLUGIN SIDE |peer |peer + *~~~~|~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~~~~~~~~~~~~~~~ + * | BROWSER SIDE | | + * | v v + * | +---------------------------------+ +----------------------------+ + * | | nsIPluginInstancePeer |+ | nsIPluginStreamPeer |+ + * | | nsIPluginInstancePeer2 || | nsISeekablePluginStreamPeer|| + * | | nsIWindowlessPluginInstancePeer || | nsIPluginstreamPeer2 || + * | | nsILiveConnectPluginInstancePeer|| +----------------------------+| + * | | nsIPluginTagInfo || +---------------------------+ + * | | nsIPluginTagInfo2 || + * | +---------------------------------+| + * | +--------------------------------+ + * | + * | + * v the browser (only 1) + * +---------------------+ + * | nsIPluginManager | + * | nsIPluginManager2 | + * | nsIFileUtilities | + * | nsIPref | + * | nsICacheManager ... | + * +---------------------+ + * + */ + +#ifndef nsplugins_h___ +#define nsplugins_h___ + +#include "nsRepository.h" // for NSGetFactory + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces which must be implemented by a plugin + * These interfaces have NPP equivalents in pre-5.0 browsers (see npapi.h). + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * NSGetFactory is the main entry point to the plugin's DLL. The plugin manager + * finds this symbol and calls it to create the plugin class. Once the plugin + * object is returned to the plugin manager, instances on the page are created + * by calling nsIPlugin::CreateInstance. + */ +// (Declared in nsRepository.h) +//extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, +// nsIFactory **aFactory); + +/** + * A plugin object is used to create new plugin instances. It manages the + * global state of all plugins with the same implementation. + */ +#include "nsIPlugin.h" + +/** + * A plugin instance represents a particular activation of a plugin on a page. + */ +#include "nsIPluginInstance.h" + +/** + * A plugin stream gets instantiated when a plugin instance receives data from + * the browser. + */ +#include "nsIPluginStream.h" + +/** + * The nsILiveConnectPlugin interface provides additional operations that a + * plugin must implement if it is to be controlled by JavaScript through + * LiveConnect. + * + * Note that this interface is part of a new JNI-based LiveConnect + * implementation and superceeds that provided prior to Communicator 5.0. + */ +#include "nsILiveConnectPlugin.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces implemented by the browser: + * These interfaces have NPN equivalents in pre-5.0 browsers (see npapi.h). + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The plugin manager which is the main point of interaction with the browser + * and provides general operations needed by a plugin. + */ +#include "nsIPluginManager.h" + +/** + * A plugin instance peer gets created by the browser and associated with each + * plugin instance to represent tag information and other callbacks needed by + * the plugin instance. + */ +#include "nsIPluginInstancePeer.h" + +/** + * The nsIPluginTagInfo interface provides information about the html tag + * that was used to instantiate the plugin instance. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIPluginTagInfo.h" + +/** + * The nsIWindowlessPluginInstancePeer provides additional operations for + * windowless plugins. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIWindowlessPluginInstancePeer.h" + +/** + * A plugin stream peer gets create by the browser and associated with each + * plugin stream to represent stream and URL information, and provides + * other callbacks needed by the plugin stream. + */ +#include "nsIPluginStreamPeer.h" + +/** + * The nsISeekablePluginStreamPeer provides additional operations for seekable + * plugin streams. + * + * To obtain: QueryInterface on nsIPluginStreamPeer + */ +#include "nsISeekablePluginStreamPeer.h" + +//////////////////////////////////////////////////////////////////////////////// +/** + * Interfaces implemented by the browser (new for 5.0): + */ +//////////////////////////////////////////////////////////////////////////////// + +/** + * The nsIPluginManager2 interface provides additional plugin manager features + * only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginManager + */ +#include "nsIPluginManager2.h" + +/** + * The nsIFileUtilities interface provides operations to manage temporary + * files and directories. + * + * To obtain: QueryInterface on nsIPluginManager + */ +#include "nsIFileUtilities.h" + +/** + * The nsIPluginInstancePeer2 interface provides additional plugin instance + * peer features only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsIPluginInstancePeer2.h" + +/** + * The nsILiveConnectPluginInstancePeer allows plugins to be manipulated + * by JavaScript, providing basic scriptability. + * + * Note that this interface is part of a new JNI-based LiveConnect + * implementation and superceeds that provided prior to Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginInstancePeer + */ +#include "nsILiveConnectPluginInstancePeer.h" + +/** + * The nsIPluginStreamPeer2 interface provides additional plugin stream + * peer features only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginStreamPeer + */ +#include "nsIPluginStreamPeer2.h" + +/** + * The nsIPluginTagInfo2 interface provides additional html tag information + * only available in Communicator 5.0. + * + * To obtain: QueryInterface on nsIPluginTagInfo + */ +#include "nsIPluginTagInfo2.h" + +//////////////////////////////////////////////////////////////////////////////// +#endif // nsplugins_h___ diff --git a/mozilla/modules/plugin/public/nsplugindefs.h b/mozilla/modules/plugin/public/nsplugindefs.h new file mode 100644 index 00000000000..3d2e45d9b07 --- /dev/null +++ b/mozilla/modules/plugin/public/nsplugindefs.h @@ -0,0 +1,365 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +/** + * INTERFACE TO NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). + * + *

This superscedes the old plugin API (npapi.h, npupp.h), and + * eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp that + * get linked with the plugin. You will however need to link with the "backward + * adapter" (badapter.cpp) in order to allow your plugin to run in pre-5.0 + * browsers. + * + *

See nsplugin.h for an overview of how this fits with the + * overall plugin architecture. + */ +//////////////////////////////////////////////////////////////////////////////// + +#ifndef nsplugindefs_h___ +#define nsplugindefs_h___ + +#ifdef __OS2__ +#pragma pack(1) +#endif + +#ifdef XP_MAC + #include + #include +#endif + +#ifdef XP_UNIX + #include + #include +#endif + +#ifdef XP_PC + #include +#endif + +//////////////////////////////////////////////////////////////////////////////// + +/* The OS/2 version of Netscape uses RC_DATA to define the + mime types, file extentions, etc that are required. + Use a vertical bar to seperate types, end types with \0. + FileVersion and ProductVersion are 32bit ints, all other + entries are strings the MUST be terminated wwith a \0. + +AN EXAMPLE: + +RCDATA NS_INFO_ProductVersion { 1,0,0,1,} + +RCDATA NS_INFO_MIMEType { "video/x-video|", + "video/x-flick\0" } +RCDATA NS_INFO_FileExtents { "avi|", + "flc\0" } +RCDATA NS_INFO_FileOpenName{ "MMOS2 video player(*.avi)|", + "MMOS2 Flc/Fli player(*.flc)\0" } + +RCDATA NS_INFO_FileVersion { 1,0,0,1 } +RCDATA NS_INFO_CompanyName { "Netscape Communications\0" } +RCDATA NS_INFO_FileDescription { "NPAVI32 Extension DLL\0" +RCDATA NS_INFO_InternalName { "NPAVI32\0" ) +RCDATA NS_INFO_LegalCopyright { "Copyright Netscape Communications \251 1996\0" +RCDATA NS_INFO_OriginalFilename { "NVAPI32.DLL" } +RCDATA NS_INFO_ProductName { "NPAVI32 Dynamic Link Library\0" } + +*/ + + +/* RC_DATA types for version info - required */ +#define NS_INFO_ProductVersion 1 +#define NS_INFO_MIMEType 2 +#define NS_INFO_FileOpenName 3 +#define NS_INFO_FileExtents 4 + +/* RC_DATA types for version info - used if found */ +#define NS_INFO_FileDescription 5 +#define NS_INFO_ProductName 6 + +/* RC_DATA types for version info - optional */ +#define NS_INFO_CompanyName 7 +#define NS_INFO_FileVersion 8 +#define NS_INFO_InternalName 9 +#define NS_INFO_LegalCopyright 10 +#define NS_INFO_OriginalFilename 11 + +#ifndef RC_INVOKED + +//////////////////////////////////////////////////////////////////////////////// +// Structures and definitions + +#ifdef XP_MAC +#pragma options align=mac68k +#endif + +typedef const char* nsMIMEType; + +struct nsByteRange { + PRInt32 offset; /* negative offset means from the end */ + PRUint32 length; + struct nsByteRange* next; +}; + +struct nsRect { + PRUint16 top; + PRUint16 left; + PRUint16 bottom; + PRUint16 right; +}; + +//////////////////////////////////////////////////////////////////////////////// +// Unix specific structures and definitions + +#ifdef XP_UNIX + +#include + +/* + * Callback Structures. + * + * These are used to pass additional platform specific information. + */ +enum nsPluginCallbackType { + nsPluginCallbackType_SetWindow = 1, + nsPluginCallbackType_Print +}; + +struct nsPluginAnyCallbackStruct { + PRInt32 type; +}; + +struct nsPluginSetWindowCallbackStruct { + PRInt32 type; + Display* display; + Visual* visual; + Colormap colormap; + PRUint32 depth; +}; + +struct nsPluginPrintCallbackStruct { + PRInt32 type; + FILE* fp; +}; + +#endif /* XP_UNIX */ + +//////////////////////////////////////////////////////////////////////////////// + +// List of variable names for which NPP_GetValue shall be implemented +enum nsPluginVariable { + nsPluginVariable_NameString = 1, + nsPluginVariable_DescriptionString, + nsPluginVariable_WindowBool, // XXX go away + nsPluginVariable_TransparentBool, // XXX go away? + nsPluginVariable_JavaClass, // XXX go away + nsPluginVariable_WindowSize, + nsPluginVariable_TimerInterval + // XXX add MIMEDescription (for unix) (but GetValue is on the instance, not the class) +}; + +// List of variable names for which NPN_GetValue is implemented by Mozilla +enum nsPluginManagerVariable { + nsPluginManagerVariable_XDisplay = 1, + nsPluginManagerVariable_XtAppContext, + nsPluginManagerVariable_NetscapeWindow, + nsPluginManagerVariable_JavascriptEnabledBool, // XXX prefs accessor api + nsPluginManagerVariable_ASDEnabledBool, // XXX prefs accessor api + nsPluginManagerVariable_IsOfflineBool // XXX prefs accessor api +}; + +//////////////////////////////////////////////////////////////////////////////// + +enum nsPluginType { + nsPluginType_Embedded = 1, + nsPluginType_Full +}; + +// XXX this can go away now +enum NPStreamType { + NPStreamType_Normal = 1, + NPStreamType_Seek, + NPStreamType_AsFile, + NPStreamType_AsFileOnly +}; + +#define NP_STREAM_MAXREADY (((unsigned)(~0)<<1)>>1) + +/* + * The type of a NPWindow - it specifies the type of the data structure + * returned in the window field. + */ +enum nsPluginWindowType { + nsPluginWindowType_Window = 1, + nsPluginWindowType_Drawable +}; + +struct nsPluginWindow { + void* window; /* Platform specific window handle */ + /* OS/2: x - Position of bottom left corner */ + /* OS/2: y - relative to visible netscape window */ + PRUint32 x; /* Position of top left corner relative */ + PRUint32 y; /* to a netscape page. */ + PRUint32 width; /* Maximum window size */ + PRUint32 height; + nsRect clipRect; /* Clipping rectangle in port coordinates */ + /* Used by MAC only. */ +#ifdef XP_UNIX + void* ws_info; /* Platform-dependent additonal data */ +#endif /* XP_UNIX */ + nsPluginWindowType type; /* Is this a window or a drawable? */ +}; + +struct nsPluginFullPrint { + PRBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */ + /* printing */ + PRBool printOne; /* TRUE if plugin should print one copy */ + /* to default printer */ + void* platformPrint; /* Platform-specific printing info */ +}; + +struct nsPluginEmbedPrint { + nsPluginWindow window; + void* platformPrint; /* Platform-specific printing info */ +}; + +struct nsPluginPrint { + nsPluginType mode; /* NP_FULL or nsPluginType_Embedded */ + union + { + nsPluginFullPrint fullPrint; /* if mode is NP_FULL */ + nsPluginEmbedPrint embedPrint; /* if mode is nsPluginType_Embedded */ + } print; +}; + +struct nsPluginEvent { + +#if defined(XP_MAC) + EventRecord* event; + void* window; + +#elif defined(XP_PC) + uint16 event; + uint32 wParam; + uint32 lParam; + +#elif defined(XP_OS2) + uint32 event; + uint32 wParam; + uint32 lParam; + +#elif defined(XP_UNIX) + XEvent event; + +#endif +}; + +#ifdef XP_MAC +typedef RgnHandle nsRegion; +#elif defined(XP_PC) +typedef HRGN nsRegion; +#elif defined(XP_UNIX) +typedef Region nsRegion; +#else +typedef void *nsRegion; +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Mac-specific structures and definitions. + +#ifdef XP_MAC + +struct NPPort { + CGrafPtr port; /* Grafport */ + PRInt32 portx; /* position inside the topmost window */ + PRInt32 porty; +}; + +/* + * Non-standard event types that can be passed to HandleEvent + */ +#define getFocusEvent (osEvt + 16) +#define loseFocusEvent (osEvt + 17) +#define adjustCursorEvent (osEvt + 18) +#define menuCommandEvent (osEvt + 19) + +#endif /* XP_MAC */ + +//////////////////////////////////////////////////////////////////////////////// +// Error and Reason Code definitions + +enum nsPluginError { + nsPluginError_Base = 0, + nsPluginError_NoError = 0, + nsPluginError_GenericError, + nsPluginError_InvalidInstanceError, + nsPluginError_InvalidFunctableError, + nsPluginError_ModuleLoadFailedError, + nsPluginError_OutOfMemoryError, + nsPluginError_InvalidPluginError, + nsPluginError_InvalidPluginDirError, + nsPluginError_IncompatibleVersionError, + nsPluginError_InvalidParam, + nsPluginError_InvalidUrl, + nsPluginError_FileNotFound, + nsPluginError_NoData, + nsPluginError_StreamNotSeekable +}; + +#define NPCallFailed( code ) ((code) != nsPluginError_NoError) + +enum nsPluginReason { + nsPluginReason_Base = 0, + nsPluginReason_Done = 0, + nsPluginReason_NetworkErr, + nsPluginReason_UserBreak, + nsPluginReason_NoReason +}; + +//////////////////////////////////////////////////////////////////////////////// +// Classes +//////////////////////////////////////////////////////////////////////////////// + +// Classes that must be implemented by the plugin DLL: +struct nsIPlugin; // plugin class (MIME-type handler) +class nsILiveConnectPlugin; // subclass of nsIPlugin +class nsIPluginInstance; // plugin instance +class nsIPluginStream; // stream to receive data from the browser + +// Classes that are implemented by the browser: +class nsIPluginManager; // minimum browser requirements +class nsIFileUtilities; // file utilities (accessible from nsIPluginManager) +class nsIPluginInstancePeer; // parts of nsIPluginInstance implemented by the browser +class nsIWindowlessPluginInstancePeer; // subclass of nsIPluginInstancePeer for windowless plugins +class nsIPluginTagInfo; // describes html tag (accessible from nsIPluginInstancePeer) +class nsILiveConnectPluginInstancePeer; // subclass of nsIPluginInstancePeer +class nsIPluginStreamPeer; // parts of nsIPluginStream implemented by the browser +class nsISeekablePluginStreamPeer; // seekable subclass of nsIPluginStreamPeer + +//////////////////////////////////////////////////////////////////////////////// + +#ifdef XP_MAC +#pragma options align=reset +#endif + +#endif /* RC_INVOKED */ +#ifdef __OS2__ +#pragma pack() +#endif + +#endif // nsplugindefs_h___ diff --git a/mozilla/modules/plugin/src/MANIFEST b/mozilla/modules/plugin/src/MANIFEST new file mode 100644 index 00000000000..1c3d36794cd --- /dev/null +++ b/mozilla/modules/plugin/src/MANIFEST @@ -0,0 +1,25 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +# This is a list of local files which get copied to the mozilla:dist directory +# + +nppg.h +npupp.h +npglue.h +nppriv.h diff --git a/mozilla/modules/plugin/src/Makefile b/mozilla/modules/plugin/src/Makefile new file mode 100644 index 00000000000..4d92c13bb44 --- /dev/null +++ b/mozilla/modules/plugin/src/Makefile @@ -0,0 +1,46 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH = ../../.. + +MODULE = plug +LIBRARY_NAME = plug + +CSRCS = npassoc.c + +CPPSRCS = nsplugin.cpp + +EXPORTS = nppg.h npupp.h npglue.h nppriv.h + +REQUIRES = lay layer js style applet nspr dbm img util java pref xpcom netcnvts oji ojiimpl + +ifeq ($(subst /,_,$(shell uname -s)),OS2) +CPPSRCS = npwplat.cpp +REQUIRES += xp libfont os2font jtools +endif + +CPPSRCS += npglue.cpp + +include $(DEPTH)/config/rules.mk + +ifeq ($(subst /,_,$(shell uname -s)),OS2) +INCLUDES += -I$(DEPTH)/cmd/os2fe/nfc/include -I$(DEPTH)/cmd/os2fe -I$(DEPTH)/cmd/winfe +endif + +INCLUDES += -I. + +$(LIBRARY): $(OBJS) diff --git a/mozilla/modules/plugin/src/makefile.win b/mozilla/modules/plugin/src/makefile.win new file mode 100644 index 00000000000..644fd86c80a --- /dev/null +++ b/mozilla/modules/plugin/src/makefile.win @@ -0,0 +1,47 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +IGNORE_MANIFEST=1 + +DEPTH= ..\..\.. + +MODULE = plugimpl + +EXPORTS = \ + nppg.h \ + npupp.h \ + npglue.h \ + nppriv.h + +LIBRARY_NAME = plug + +LINCS = -I$(DIST)\include \ + -I$(PUBLIC)\plugin \ + -I$(PUBLIC)\java \ + -I$(PUBLIC)\pref \ + -I$(PUBLIC)\js \ + -I$(PUBLIC)\lay \ + -I$(PUBLIC)\style \ + -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\oji \ + -I$(PUBLIC)\ojiimpl + +OBJS = .\$(OBJDIR)\npassoc.obj \ + .\$(OBJDIR)\npglue.obj + +include <$(DEPTH)/config/rules.mak> + diff --git a/mozilla/modules/plugin/src/npassoc.c b/mozilla/modules/plugin/src/npassoc.c new file mode 100644 index 00000000000..2116011f53e --- /dev/null +++ b/mozilla/modules/plugin/src/npassoc.c @@ -0,0 +1,239 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * npassoc.c $Revision: 1.1 $ + * some xp mime-type file extension associations + */ + +#include "npassoc.h" +#include "xp_mem.h" +#include "xp_mcom.h" +#include "net.h" + +static NPFileTypeAssoc *np_fassoc_list=0; /* should use xp hash */ + +extern void NET_cdataAdd(NET_cdataStruct *cd); + +#define NP_MAX_EXTS 64 +static char *np_array[NP_MAX_EXTS]; + +/* allocate and fill a null-terminated array of extensions from + a comma and space delimited list */ +static char ** +np_parse_exts(const char *exts) +{ + char *p, *e, **res; + int n=0; + + if(!exts) + return 0; + + /* p is the current position, e is the start of the nth extension */ + for(e=p=(char *)exts; *p; p++) + { + if( (*p==' ') || (*p==',') ) + { + if(*e == '.') e++; + if(p>e) + { + if(!(np_array[n] = (char *)XP_ALLOC(p-e+1))) + return 0; + XP_MEMCPY(np_array[n], e, (p-e)); + *(np_array[n]+(p-e)) = 0; + n++; + e = p+1; + } + } + } + if(*e == '.') e++; + if(p>e) + { + if(!(np_array[n] = (char *)XP_ALLOC(p-e+1))) + return 0; + XP_MEMCPY(np_array[n], e, (p-e)); + *(np_array[n]+(p-e)) = 0; + n++; + } + + if(!(res = (char **)XP_ALLOC((n+1)*sizeof(char *)))) + return 0; + XP_MEMCPY(res, np_array, n*sizeof(char *)); + res[n] = 0; + + return res; +} + + +/* construct a file association from a mime type. + * - extensions is a list of comma/space separated file extensions + * with or without leading .s + * - filetype is platform specific data for this list of extensions, + * currently creator on mac and open file dialog descriptions on win. + * filetype is callee owned data and must remain valid + */ +NPFileTypeAssoc * +NPL_NewFileAssociation(const char *MIMEType, const char *extensions, const char *description, void *fileType) +{ + NPFileTypeAssoc *fassoc = 0; + + /* make a file association struct */ + if(!(fassoc=XP_NEW_ZAP(NPFileTypeAssoc))) + return 0; + + StrAllocCopy((fassoc->type), MIMEType ? MIMEType : ""); + StrAllocCopy((fassoc->description), description ? description : ""); + StrAllocCopy((fassoc->extentstring), extensions ? extensions : ""); + + fassoc->fileType = fileType; /* caller owns this data */ + fassoc->extentlist = np_parse_exts(extensions); + return fassoc; +} + + +/* deletes a file association. Returns the platform specific fileType + data that we dont know how to dispose of. +*/ +void * +NPL_DeleteFileAssociation(NPFileTypeAssoc *fassoc) +{ + void* fileType; + + if (!fassoc) + return NULL; + + fileType = fassoc->fileType; + + NPL_RemoveFileAssociation(fassoc); + + if (fassoc->type) + { + XP_FREE(fassoc->type); + fassoc->type = NULL; + } + + if (fassoc->description) + { + XP_FREE(fassoc->description); + fassoc->description = NULL; + } + + if (fassoc->extentstring) + { + XP_FREE(fassoc->extentstring); + fassoc->extentstring = NULL; + } + + { + char** charPtrPtr; + for (charPtrPtr = &fassoc->extentlist[0]; *charPtrPtr; *charPtrPtr=0, charPtrPtr++) + XP_FREE(*charPtrPtr); + + fassoc->extentlist = NULL; + } + + XP_FREE(fassoc); + + return fileType; +} + + +/* Register a file association with us and netlib. + */ +void +NPL_RegisterFileAssociation(NPFileTypeAssoc *fassoc) +{ + if (fassoc) + { + fassoc->pNext = np_fassoc_list; + np_fassoc_list = fassoc; + + NET_cdataCommit(fassoc->type, fassoc->extentstring); + + /* + * We need to add the description, too, which unfortunately requires + * looking the cinfo up AGAIN and setting the desc field... + */ + if (fassoc->description) + { + NET_cdataStruct temp; + NET_cdataStruct* cdata; + + XP_BZERO(&temp, sizeof(temp)); + temp.ci.type = fassoc->type; + cdata = NET_cdataExist(&temp); + XP_ASSERT(cdata); + if (cdata) + StrAllocCopy(cdata->ci.desc, fassoc->description); + } + } +} + + +/* Unregister a file association. + */ +NPFileTypeAssoc * +NPL_RemoveFileAssociation(NPFileTypeAssoc *fassoc) +{ + NPFileTypeAssoc *f = np_fassoc_list; + + if(!fassoc) + return 0; + + /* unregister with netlib */ + if(fassoc == np_fassoc_list) + np_fassoc_list = np_fassoc_list->pNext; + else + { + for(; f; f=f->pNext) + if(f->pNext == fassoc) + { + NPFileTypeAssoc *ft; + ft = f->pNext; + f->pNext = f->pNext->pNext; + f = ft; + break; + } + } + return f; +} + + +/* returns a linked list of registered associations. + * if type is NULL you get the entire list else the association matching + * that MIME type +*/ +NPFileTypeAssoc * +NPL_GetFileAssociation(const char *type) +{ + NPFileTypeAssoc *f=NULL; + + if(!np_fassoc_list) + return NULL; + + if(type==NULL) + return np_fassoc_list; + + for(f=np_fassoc_list; f; f=f->pNext) + if(!(XP_STRCMP(type, f->type))) + return f; + + return NULL; +} + + diff --git a/mozilla/modules/plugin/src/npglue.cpp b/mozilla/modules/plugin/src/npglue.cpp new file mode 100644 index 00000000000..dcb3d7df0e8 --- /dev/null +++ b/mozilla/modules/plugin/src/npglue.cpp @@ -0,0 +1,5501 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * + * Function naming conventions: + * NPL_ Functions exported to other libs or FEs (prototyped in np.h) + * NPN_ Function prototypes exported to plug-ins via our function table (prototyped in npapi.h) + * npn_ Function definitions whose addresses are placed in the function table + * np_ Miscellaneous functions internal to libplugin (this file) + * + */ + +#include "xp.h" +#include "npglue.h" +#include "plstr.h" +#ifdef OJI +#include "jni.h" +#include "jvmmgr.h" +#endif + +#ifdef ANTHRAX +static char* np_FindAppletNForMimeType(const char* mimetype, char index); +static int32 np_GetNumberOfInstalledApplets(const char* mimetype); +static void np_ReplaceChars(char* word, char oldChar, char newChar); +static char* np_CreateMimePref(const char* mimetype, const char* pref); +#endif /* ANTHRAX */ + +#ifdef PLUGIN_TIMER_EVENT +static void np_SetTimerInterval(NPP npp, uint32 msecs); +static void np_TimerCallback(void* app); +#define DEFAULT_TIMER_INTERVAL 1000 +#endif + +/* list of all plugins */ +static np_handle *np_plist = 0; + +/* list of all applets for ANTHRAX */ +#ifdef ANTHRAX +static np_handle *np_alist = NULL; +#endif + +int np_debug = 0; + +NPNetscapeFuncs npp_funcs; + +/* + * Determine whether or not this is a new-style plugin. + */ +static inline XP_Bool +np_is50StylePlugin(np_handle* handle) +{ + XP_ASSERT(handle != NULL); + return (handle->userPlugin != NULL); +} + +/* Find a mimetype in the handle */ +static np_mimetype * +np_getmimetype(np_handle *handle, const char *mimeStr, XP_Bool wildCard) +{ + np_mimetype *mimetype; + + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (mimetype->enabled) + { + if ((wildCard && !strcmp(mimetype->type, "*")) || + !strcasecomp(mimetype->type, mimeStr)) + return (mimetype); + } + } + return (NULL); +} + + +/* + * Standard conversion from NetLib status + * code to plug-in reason code. + */ +static NPReason +np_statusToReason(int status) +{ + if (status == MK_DATA_LOADED) + return NPRES_DONE; + else if (status == MK_INTERRUPTED) + return NPRES_USER_BREAK; + else + return NPRES_NETWORK_ERR; +} + + +/* + * Add a node to the list of URLs for this + * plug-in instance. The caller must fill + * out the fields of the node, which is returned. + */ +static np_urlsnode* +np_addURLtoList(np_instance* instance) +{ + np_urlsnode* node; + + if (!instance) + return NULL; + + if (!instance->url_list) + instance->url_list = XP_ListNew(); + if (!instance->url_list) + return NULL; + + node = XP_NEW_ZAP(np_urlsnode); + if (!node) + return NULL; + + XP_ListAddObject(instance->url_list, node); + + return node; +} + + +/* + * Deal with one URL from the list of URLs for the instance + * before the URL is removed from the list. If the URL was + * locked in the cache, we must unlock it and delete the URL. + * Otherwise, notify the plug-in that the URL is done (if + * necessary) and break the reference from the URL to the + * instance. + */ +static void +np_processURLNode(np_urlsnode* node, np_instance* instance, int status) +{ + if (node->cached) + { + /* Unlock the cache file */ + XP_ASSERT(!node->notify); + if (node->urls) + { + NET_ChangeCacheFileLock(node->urls, NP_UNLOCK); + + NET_FreeURLStruct(node->urls); + node->urls = NULL; + } + + return; + } + + if (node->notify) + { + /* Notify the plug-in */ + XP_ASSERT(!node->cached); + if (instance) { + TRACEMSG(("npglue.c: CallNPP_URLNotifyProc")); + if (np_is50StylePlugin(instance->handle)) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + userInst->URLNotify(node->urls->address, node->urls->window_target, + (nsPluginReason)np_statusToReason(status), + node->notifyData); + } + else if (ISFUNCPTR(instance->handle->f->urlnotify)) { + CallNPP_URLNotifyProc(instance->handle->f->urlnotify, + instance->npp, + node->urls->address, + np_statusToReason(status), + node->notifyData); + } + } + } + + /* Break the reference from the URL to the instance */ + if (node->urls) + node->urls->fe_data = NULL; +} + + +/* + * Remove an individual URL from the list of URLs for this instance. + */ +static void +np_removeURLfromList(np_instance* instance, URL_Struct* urls, int status) +{ + XP_List* url_list; + np_urlsnode* node; + + if (!instance || !urls || !instance->url_list) + return; + + /* Look for the URL in the list */ + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) + { + if (node->urls == urls) + { + XP_ASSERT(!node->cached); + np_processURLNode(node, instance, status); + + XP_ListRemoveObject(instance->url_list, node); + XP_FREE(node); + + /* If the list is now empty, delete it */ + if (XP_ListCount(instance->url_list) == 0) + { + XP_ListDestroy(instance->url_list); + instance->url_list = NULL; + } + + return; + } + } +} + + +/* + * Remove all URLs from the list of URLs for this instance. + */ +static void +np_removeAllURLsFromList(np_instance* instance) +{ + XP_List* url_list; + np_urlsnode* node; + + if (!instance || !instance->url_list) + return; + + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) + { + /* No notification of URLs now: the instance is going away */ + node->notify = FALSE; + np_processURLNode(node, instance, 0); + } + + /* Remove all elements from the list */ + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListRemoveTopObject(url_list)) != NULL) + XP_FREE(node); + + /* The list should now be empty, so delete it */ + XP_ASSERT(XP_ListCount(instance->url_list) == 0); + XP_ListDestroy(instance->url_list); + instance->url_list = NULL; +} + + + +/* maps from a urls to the corresponding np_stream. + you might well ask why not just store the urls in the stream and + put the stream in the netlib obj. the reason is that there can be + more than one active netlib stream for each plugin stream and + netlib specific data for seekable streams (current position and + so-on is stored in the urls and not in the stream. what a travesty. +*/ +static np_stream * +np_get_stream(URL_Struct *urls) +{ + if(urls) + { + NPEmbeddedApp *pEmbeddedApp = (NPEmbeddedApp*)urls->fe_data; + if(pEmbeddedApp) + { + np_data *ndata = (np_data *)pEmbeddedApp->np_data; + if(ndata && ndata->instance) + { + np_stream *stream; + for (stream=ndata->instance->streams; stream; stream=stream->next) + { + /* + * Matching algorithm: Either this URL is the inital URL for + * the stream, or it's a URL generated by a subsequent byte- + * range request. We don't bother to keep track of all the + * URLs for byte-range requests, but we can still detect if + * the URL matches this stream: since we know that this URL + * belongs to one of the streams for this instance and that + * there can only be one seekable stream for an instance + * active at a time, then we know if this stream is seekable + * and the URL is a byte-range URL then they must match. + * NOTE: We check both urls->high_range and urls->range_header + * because we could have been called before the range_header + * has been parsed and the high_range set. + */ + if ((stream->initial_urls == urls) || + (stream->seek && (urls->high_range || urls->range_header))) + return stream; + } + } + } + } + return NULL; +} + + +/* + * Create the two plug-in data structures we need to go along + * with a netlib stream for a plugin: the np_stream, which is + * private to libplugin, and the NPStream, which is exported + * to the plug-in. The NPStream has an opaque reference (ndata) + * to the associated np_stream. The np_stream as a reference + * (pstream) to the NPStream, and another reference (nstream) + * to the netlib stream. + */ +static np_stream* +np_makestreamobjects(np_instance* instance, NET_StreamClass* netstream, URL_Struct* urls) +{ + np_stream* stream; + NPStream* pstream; + XP_List* url_list; + np_urlsnode* node; + void* notifyData; + + /* check params */ + if (!instance || !netstream || !urls) + return NULL; + + /* make a npglue stream */ + stream = XP_NEW_ZAP(np_stream); + if (!stream) + return NULL; + + stream->instance = instance; + stream->handle = instance->handle; + stream->nstream = netstream; + stream->initial_urls = urls; + + XP_ASSERT(urls->address); + StrAllocCopy(stream->url, urls->address); + stream->len = urls->content_length; + + /* Look for notification data for this URL */ + notifyData = NULL; + url_list = instance->url_list; + while ((node = (np_urlsnode*)XP_ListNextObject(url_list)) != NULL) + { + if (node->urls == urls && node->notify) + { + notifyData = node->notifyData; + break; + } + } + + /* make a plugin stream (the thing the plugin sees) */ + pstream = XP_NEW_ZAP(NPStream); + if (!pstream) + { + XP_FREE(stream); + return NULL; + } + pstream->ndata = stream; /* confused yet? */ + pstream->url = stream->url; + pstream->end = urls->content_length; + pstream->lastmodified = (uint32) urls->last_modified; + pstream->notifyData = notifyData; + + /* make a record of it */ + stream->pstream = pstream; + stream->next = instance->streams; + instance->streams = stream; + + NPTRACE(0,("np: new stream, %s, %s", instance->mimetype->type, urls->address)); + + return stream; +} + +/* + * Do the reverse of np_makestreamobjects: delete the two plug-in + * stream data structures (the NPStream and the np_stream). + * We also need to remove the np_stream from the list of streams + * associated with its instance. + */ +static void +np_deletestreamobjects(np_stream* stream) +{ + np_instance* instance = stream->instance; + + /* remove it from the instance list */ + if (stream == instance->streams) + instance->streams = stream->next; + else + { + np_stream* sx; + for (sx = instance->streams; sx; sx = sx->next) + if (sx->next == stream) + { + sx->next = sx->next->next; + break; + } + } + + /* and nuke the stream */ + if (stream->pstream) + { + XP_FREE(stream->pstream); + stream->pstream = 0; + } + stream->handle = 0; + XP_FREE(stream); +} + + + +/* + * (a) There should be a delayed load LIST (multiple requests get lost currently!) + * (b) We should call NET_GetURL with the app in the fe_data (notification uses it!) + * (c) We need to store the target context (may be different than instance context!) + */ +static void +np_dofetch(URL_Struct *urls, int status, MWContext *window_id) +{ + np_stream *stream = np_get_stream(urls); + if(stream && stream->instance) + { + FE_GetURL(stream->instance->cx, stream->instance->delayedload); + } +} + + +unsigned int +NPL_WriteReady(NET_StreamClass *stream) +{ + URL_Struct *urls = (URL_Struct *)stream->data_object; + np_stream *newstream = nil; + int ret = 0; + + if(!(newstream = np_get_stream(urls))) + return 0; + + if (newstream->asfile == NP_ASFILEONLY) + return NP_MAXREADY; + + /* if prev_stream is not ready to write, then neither is this one... */ + if (newstream->prev_stream != NULL){ + ret = (newstream->prev_stream->is_write_ready(newstream->prev_stream)); + if (ret == FALSE) + return FALSE; + } + + XP_ASSERT(newstream->instance); + newstream->instance->reentrant = 1; + + if (newstream->seek >= 0) { + TRACEMSG(("npglue.c: CallNPP_WriteReadyProc")); + if (newstream->handle->userPlugin) { +#if 0 // XXX until we figure out if nsIOutputStream will work for us + nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)newstream->pstream->pdata; + nsIPluginStream* userStream = peerStream->GetUserStream(); + ret = userStream->WriteReady(); +#else + ret = NP_MAXREADY; +#endif + } + else if (ISFUNCPTR(newstream->handle->f->writeready)) { + ret = CallNPP_WriteReadyProc(newstream->handle->f->writeready, + newstream->instance->npp, newstream->pstream); + } + } + else + ret = NP_MAXREADY; + +#if defined(XP_WIN) || defined(XP_OS2) + /* Prevent WinFE from going to sleep when plug-in blocks */ + if (ret == 0){ + if(!newstream->instance->calling_netlib_all_the_time){ + newstream->instance->calling_netlib_all_the_time = TRUE; + NET_SetCallNetlibAllTheTime(newstream->instance->cx, "npglue"); + } + else{ + + NET_ClearCallNetlibAllTheTime(newstream->instance->cx, "npglue"); + newstream->instance->calling_netlib_all_the_time = FALSE; + } + } +#endif + if(!newstream->instance->reentrant) + { + urls->pre_exit_fn = np_dofetch; + return (unsigned int)-1; + } + newstream->instance->reentrant = 0; + + return ret; +} + +int +NPL_Write(NET_StreamClass *stream, const unsigned char *str, int32 len) +{ + int ret; + URL_Struct *urls = (URL_Struct *)stream->data_object; + np_stream *newstream = np_get_stream(urls); + + if(!newstream || !(newstream->handle->userPlugin ? 1 : ISFUNCPTR(newstream->handle->f->write))) + return -1; + + if (newstream->asfile == NP_ASFILEONLY) + return len; + + if (newstream->prev_stream != NULL){ + ret = newstream->prev_stream->put_block(newstream->prev_stream,(const char *)str,len); + /* should put check here for ret == len? if not, then what? */ + } + + + /* if this is the first non seek write after we turned the + stream, then abort this (netlib) stream */ + + if(!urls->high_range && (newstream->seek == -1)) + return MK_UNABLE_TO_CONVERT; /* will cause an abort */ + + XP_ASSERT(newstream->instance); + newstream->instance->reentrant = 1; + + newstream->pstream->end = urls->content_length; + + if(newstream->seek) + { + /* NPTRACE(0,("seek stream gets %d bytes with high %d low %d pos %d\n", len, + urls->high_range, urls->low_range, urls->position)); */ + /* since we get one range per urls, position will only be non-zero + if we are getting additional writes */ + if(urls->position == 0) + urls->position = urls->low_range; + } + /*TRACEMSG(("npglue.c: CallNPP_WriteProc")); + */ + if (newstream->handle->userPlugin) { + nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)newstream->pstream->pdata; + nsIPluginStream* userStream = peerStream->GetUserStream(); + nsresult err; + ret = userStream->Write((const char*)str, 0, len, &err); + PR_ASSERT(err == NS_OK); // XXX this should go somewhere + } + else if (ISFUNCPTR(newstream->handle->f->write)) { + ret = CallNPP_WriteProc(newstream->handle->f->write, newstream->instance->npp, newstream->pstream, + urls->position, len, (void *)str); + } + + urls->position += len; + + if(!newstream->instance->reentrant) + { + urls->pre_exit_fn = np_dofetch; + return -1; + } + newstream->instance->reentrant = 0; + + return ret; +} + + +static char * +np_make_byterange_string(NPByteRange *ranges) +{ + char *burl; + NPByteRange *br; + int count, maxlen; + + for(count=0, br=ranges; br; br=br->next) + count++; + maxlen = count*22 + 64; /* two 32-bit numbers, plus slop */ + + burl = (char*)XP_ALLOC(maxlen); + if(burl) + { + char range[64]; + int len=0; + int iBytesEqualsLen; + + iBytesEqualsLen = strlen(RANGE_EQUALS); + + /* the range must begin with bytes= + * a final range string looks like: + * bytes=5-8,12-56 + */ + XP_STRCPY(burl, RANGE_EQUALS); + + for(br=ranges; br; br=br->next) + { + int32 brlen = br->length; + if(len) + XP_STRCAT(burl, ","); + if(br->offset<0) + sprintf(range, "%ld", -((long)(br->length))); + else + sprintf(range, "%ld-%ld", br->offset, (br->offset+(brlen-1))); + + len += XP_STRLEN(range); + if((len + iBytesEqualsLen) >= maxlen) + break; + XP_STRCAT(burl, range); + } + + if(len == 0) /* no ranges added */ + *burl = 0; + } + return burl; +} + +static NPByteRange * +np_copy_rangelist(NPByteRange *rangeList) +{ + NPByteRange *r, *rn, *rl=0, *rh=0; + + for(r=rangeList; r; r=r->next) + { + if(!(rn = XP_NEW_ZAP(NPByteRange))) + break; + rn->offset = r->offset; + rn->length = r->length; + + if(!rh) + rh = rn; + if(rl) + rl->next = rn; + rl = rn; + } + return rh; +} + + +static void +np_lock(np_stream *stream) +{ + if(!stream->islocked) + { + NET_ChangeCacheFileLock(stream->initial_urls, NP_LOCK); + stream->islocked = 1; + } +} + +static void +np_unlock(np_stream *stream) +{ + if(stream->islocked) + { + NET_ChangeCacheFileLock(stream->initial_urls, NP_UNLOCK); + stream->islocked = 0; + } +} + +static void +np_GetURL(URL_Struct *pURL,FO_Present_Types iFormatOut,MWContext *cx, Net_GetUrlExitFunc *pExitFunc, NPBool notify){ + + XP_ASSERT(pURL->owner_data == NULL); + pURL->owner_id = 0x0000BAC0; /* plugin's unique identifier */ + pURL->owner_data = pURL->fe_data; + pURL->fe_data = NULL; + FE_GetURL(cx,pURL); +} + + + +NPError NP_EXPORT +npn_requestread(NPStream *pstream, NPByteRange *rangeList) +{ + np_stream *stream; + + if (pstream == NULL || rangeList == NULL) + return NPERR_INVALID_PARAM; + + stream = (np_stream *)pstream->ndata; + + if (stream == NULL) + return NPERR_INVALID_PARAM; + + /* requestread may be called before newstream has returned */ + if (stream) + { + if (!stream->seekable) + { + /* + * If the stream is not seekable, we can only fulfill + * the request if we're going to cache it (seek == 2); + * otherwise it's an error. If we are caching it, + * the request must still wait until the entire file + * is cached (when NPL_Complete is finally called). + */ + if (stream->seek == 2) + { + /* defer the work */ + NPTRACE(0,("\tdeferred the request")); + + if(!stream->deferred) + stream->deferred = np_copy_rangelist(rangeList); + else + { + NPByteRange *r; + /* append */ + for(r=stream->deferred;r && r->next;r++) + ; + if(r) + { + XP_ASSERT(!r->next); + r->next = np_copy_rangelist(rangeList); + } + } + } + else + return NPERR_STREAM_NOT_SEEKABLE; + } + else + { + char *ranges; + + /* if seeking is ok, we delay this abort until now to get + the most out of the existing connection */ + if(!stream->seek) + stream->seek = -1; /* next write aborts */ + + if ((ranges = np_make_byterange_string(rangeList)) != NULL) + { + URL_Struct *urls; + urls = NET_CreateURLStruct(stream->url, NET_DONT_RELOAD); + urls->range_header = ranges; + XP_ASSERT(stream->instance); + if(stream->instance) + { + urls->fe_data = (void *)stream->instance->app; + (void) NET_GetURL(urls, FO_CACHE_AND_BYTERANGE, stream->instance->cx, NPL_URLExit); + } + } + } + } + + return NPERR_NO_ERROR; +} + + +static void +np_destroystream(np_stream *stream, NPError reason) +{ + if (stream) + { + /* Tell the plug-in that the stream is going away, and why */ + np_instance *instance = stream->instance; + TRACEMSG(("npglue.c: CallNPP_DestroyStreamProc")); + if (stream->handle->userPlugin) { + nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)stream->pstream->pdata; + nsIPluginStream* userStream = peerStream->GetUserStream(); + peerStream->SetReason((nsPluginReason)reason); + userStream->Close(); + peerStream->Release(); + } + else if (ISFUNCPTR(stream->handle->f->destroystream)) { + CallNPP_DestroyStreamProc(stream->handle->f->destroystream, instance->npp, stream->pstream, reason); + } + + /* Delete the np_stream and associated NPStream objects */ + np_deletestreamobjects(stream); + } +} + + +void +np_streamAsFile(np_stream* stream) +{ + char* fname = NULL; + XP_ASSERT(stream->asfile); + + if (stream->initial_urls) + { +#ifdef XP_MAC + /* XXX - we should eventually do this for all platforms, but when I tested it with + PC, I encountered an issue w/ EXE files just before shipping, so we're only + checking this in for MAC. */ + if (NET_IsURLInDiskCache(stream->initial_urls)) +#else + if (stream->initial_urls->cache_file) +#endif + { + np_urlsnode* node; + + /* paranoia check for ifdef mac change above */ + XP_ASSERT(stream->initial_urls->cache_file != NULL); + + fname = WH_FileName(stream->initial_urls->cache_file, xpCache); + + /* Lock the file in the cache until we're done with it */ + np_lock(stream); + node = np_addURLtoList(stream->instance); + if (node) + { + /* make a copy of the urls */ + URL_Struct* newurls = NET_CreateURLStruct(stream->initial_urls->address, NET_DONT_RELOAD); + + /* add the struct to the node */ + node->urls = newurls; + node->cached = TRUE; + } + } + else if (NET_IsLocalFileURL(stream->initial_urls->address)) + { + char* pathPart = NET_ParseURL(stream->initial_urls->address, GET_PATH_PART); + fname = WH_FileName(pathPart, xpURL); + XP_FREE(pathPart); + } + + } + + /* fname can be NULL if something went wrong */ + TRACEMSG(("npglue.c: CallNPP_StreamAsFileProc")); + if (stream->handle->userPlugin) { + nsPluginStreamPeer* peerStream = (nsPluginStreamPeer*)stream->pstream->pdata; + nsIPluginStream* userStream = peerStream->GetUserStream(); + userStream->AsFile(fname); + } + else if (ISFUNCPTR(stream->handle->f->asfile)) { + CallNPP_StreamAsFileProc(stream->handle->f->asfile, stream->instance->npp, + stream->pstream, fname); + } + + if (fname) XP_FREE(fname); +} + + +void +NPL_Complete(NET_StreamClass *stream) +{ + URL_Struct *urls = (URL_Struct *)stream->data_object; + np_stream *newstream = nil; + + if(!(newstream = np_get_stream(urls))) + return; + + if (newstream->prev_stream != NULL) + newstream->prev_stream->complete(newstream->prev_stream) ; + + if(newstream->seek) + { + if(newstream->seek == 2) + { + /* request all the outstanding reads that had been waiting */ + newstream->seekable = 1; /* for cgi hack */ + newstream->seek = 1; + np_lock(newstream); + npn_requestread(newstream->pstream, newstream->deferred); + /* and delete the copies we made */ + { + NPByteRange *r, *rl=0; + for(r=newstream->deferred; r; rl=r, r=r->next) + if(rl) XP_FREE(rl); + if(rl) XP_FREE(rl); + newstream->deferred = 0; + } + np_unlock(newstream); + } + } + + if (newstream->asfile) + np_streamAsFile(newstream); + + newstream->nstream = NULL; /* Remove reference to netlib stream */ + + newstream->prev_stream = NULL; + + if (!newstream->dontclose) + np_destroystream(newstream, NPRES_DONE); +} + + +void +NPL_Abort(NET_StreamClass *stream, int status) +{ + URL_Struct *urls = (URL_Struct *)stream->data_object; + np_stream *newstream = nil; + + if(!(newstream = np_get_stream(urls))) + return; + + if (newstream->prev_stream != NULL) + newstream->prev_stream->abort(newstream->prev_stream, status); + + if(newstream->seek == -1) + { + /* this stream is being turned around */ + newstream->seek = 1; + } + + newstream->nstream = NULL; /* Remove reference to netlib stream */ + + /* + * MK_UNABLE_TO_CONVERT is the special status code we + * return from NPL_Write to cancel the original netlib + * stream when we get a byte-range request, so we don't + * want to destroy the plug-in stream in this case (we + * shouldn't get this status code any other time here). + */ + if (!newstream->dontclose || (status < 0 && status != MK_UNABLE_TO_CONVERT)) + np_destroystream(newstream, np_statusToReason(status)); +} + +extern XP_Bool +NPL_HandleURL(MWContext *cx, FO_Present_Types iFormatOut, URL_Struct *pURL, Net_GetUrlExitFunc *pExitFunc) +{ + /* check the cx for takers */ + return FALSE; +} + + +/* + * This exit routine is called for embed streams (the + * initial stream created when the plug-in is instantiated). + * We use a special exit routine in this case because FE's + * may want to take additional action when a plug-in stream + * finishes (e.g. show special error status indicating why + * the stream failed). + */ +/* This needs to have all the code in NPL_URLExit in it too! (notification) */ +void +NPL_EmbedURLExit(URL_Struct *urls, int status, MWContext *cx) +{ + if (urls && status != MK_CHANGING_CONTEXT) + { +#if defined(XP_WIN) || defined(XP_OS2) + /* WinFE is responsible for deleting the URL_Struct */ + FE_EmbedURLExit(urls, status, cx); +#else + NET_FreeURLStruct (urls); +#endif + } +} + +/* + * This exit routine is used for all streams requested by the + * plug-in: byterange request streams, NPN_GetURL streams, and + * NPN_PostURL streams. NOTE: If the exit routine gets called + * in the course of a context switch, we must NOT delete the + * URL_Struct. Example: FTP post with result from server + * displayed in new window -- the exit routine will be called + * when the upload completes, but before the new context to + * display the result is created, since the display of the + * results in the new context gets its own completion routine. + */ +void +NPL_URLExit(URL_Struct *urls, int status, MWContext *cx) +{ + if (urls && status != MK_CHANGING_CONTEXT) + { + NPEmbeddedApp* app; + np_stream* pstream; + /* (part 2 of fix: replace fe_data the way I expect it) */ + if ((urls->owner_data != NULL) && + (urls->owner_id == 0x0000BAC0)) + urls->fe_data = urls->owner_data; + + app = (NPEmbeddedApp*) urls->fe_data; + pstream = np_get_stream(urls); + + if (pstream) + { + /* + * MK_UNABLE_TO_CONVERT is the special status code we + * return from NPL_Write to cancel the original netlib + * stream when we get a byte-range request, so we don't + * want to destroy the plug-in stream in this case (we + * shouldn't get this status code any other time here). + */ + if (!pstream->dontclose || (status < 0 && status != MK_UNABLE_TO_CONVERT)) + np_destroystream(pstream, np_statusToReason(status)); + + /* + * If the initial URL_Struct is being deleted, break our + * reference to it (we might need to unlock it, too). + */ + if (pstream->initial_urls == urls) + { + np_unlock(pstream); + pstream->initial_urls = NULL; + } + } + + /* + * Check to see if the instance wants + * to be notified of the URL completion. + */ + if (app) + { + np_data* ndata = (np_data*) app->np_data; + if (ndata && ndata->instance) + np_removeURLfromList(ndata->instance, urls, status); + } + if (urls->owner_data == NULL) + NET_FreeURLStruct(urls); + + } +} + + + +static URL_Struct* +np_makeurlstruct(np_instance* instance, const char* relativeURL, + const char* altHost, const char* referrer) +{ + History_entry* history; + URL_Struct* temp_urls = NULL; + char* absoluteURL = NULL; + URL_Struct* urls = NULL; + + if (!instance || !relativeURL) + return NULL; + + /* + * Convert the (possibly) relative URL passed in by the plug-in + * to a guaranteed absolute URL. To do this we need the base + * URL of the page we're on, which we can get from the history + * info in the plug-in's context. + */ + XP_ASSERT(instance->cx); + history = SHIST_GetCurrent(&instance->cx->hist); + if (history) + temp_urls = SHIST_CreateURLStructFromHistoryEntry(instance->cx, history); + if (temp_urls) + { + absoluteURL = NET_MakeAbsoluteURL(temp_urls->address, (char*) relativeURL); + NET_FreeURLStruct(temp_urls); + } + + + /* + * Now that we've got the absolute URL string, make a NetLib struct + * for it. If something went wrong making the absolute URL, fall back + * on the relative one. + */ + XP_ASSERT(absoluteURL); + if (absoluteURL) + { + urls = NET_CreateURLStruct(absoluteURL, NET_NORMAL_RELOAD); + XP_FREE(absoluteURL); + } + else + urls = NET_CreateURLStruct(relativeURL, NET_NORMAL_RELOAD); + + urls->owner_data = NULL; + urls->owner_id = 0x0000BAC0; + + if (altHost && NET_SetURLIPAddressString(urls, altHost)) { + NET_FreeURLStruct(urls); + return NULL; + } + if (referrer) { + urls->referer = XP_STRDUP((char*)referrer); + } + return urls; +} + + +static MWContext* +np_makecontext(np_instance* instance, const char* window) +{ + MWContext* cx; + + /* Figure out which context to do this on */ + if ((!strcmp(window, "_self")) || (!strcmp(window, "_current"))) + cx = instance->cx; + else + cx = XP_FindNamedContextInList(instance->cx, (char*) window); + + /* If we didn't find a context, make a new one */ + if (!cx) + cx = FE_MakeNewWindow(instance->cx, NULL, (char*) window, NULL); + + return cx; +} + +PR_STATIC_CALLBACK(void) +np_redisable_js(URL_Struct* url_s, int status, MWContext* context) +{ + context->forceJSEnabled = PR_FALSE; +} + +NPError +np_geturlinternal(NPP npp, const char* relativeURL, const char* target, + const char* altHost, const char* referrer, PRBool forceJSEnabled, + NPBool notify, void* notifyData) +{ + URL_Struct* urls = NULL; + MWContext* cx; + np_instance* instance; + np_urlsnode* node = NULL; + NPError err = NPERR_NO_ERROR; +#ifdef XP_WIN32 + void* pPrevState; +#endif + + if (!npp || !relativeURL) /* OK for window to be NULL */ + return NPERR_INVALID_PARAM; + + instance = (np_instance*) npp->ndata; + if (!instance) + return NPERR_INVALID_PARAM; + + /* Make an abolute URL struct from the (possibly) relative URL passed in */ + urls = np_makeurlstruct(instance, relativeURL, altHost, referrer); + if (!urls) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + + /* + * Add this URL to the list of URLs for this instance, + * and remember if the instance would like notification. + */ + node = np_addURLtoList(instance); + if (node) + { + node->urls = urls; + if (notify) + { + node->notify = TRUE; + node->notifyData = notifyData; + } + } + else + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + + urls->fe_data = (void*) instance->app; + + /* + * If the plug-in passed NULL for the target, load the URL with a special stream + * that will deliver the data to the plug-in; otherwise, convert the target name + * they passed in to a context and load the URL into that context (possibly unloading + * the plug-in in the process, if the target context is the plug-in's context). + */ + if (!target) + { +#ifdef XP_WIN32 + pPrevState = WFE_BeginSetModuleState(); +#endif + (void) NET_GetURL(urls, FO_CACHE_AND_PLUGIN, instance->cx, NPL_URLExit); +#ifdef XP_WIN32 + WFE_EndSetModuleState(pPrevState); +#endif + } + else + { + cx = np_makecontext(instance, target); + if (!cx) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + + /* + * Prevent loading "about:" URLs into the plug-in's context: NET_GetURL + * for these URLs will complete immediately, and the new layout thus + * generated will blow away the plug-in and possibly unload its code, + * causing us to crash when we return from this function. + */ + if (cx == instance->cx && NET_URL_Type(urls->address) == ABOUT_TYPE_URL) + { + err = NPERR_INVALID_URL; + goto error; + } + + if (forceJSEnabled && !cx->forceJSEnabled) { + LM_ForceJSEnabled(cx); + urls->pre_exit_fn = np_redisable_js; + } + +#ifdef XP_MAC + /* + * One day the code below should call FE_GetURL, and this call will be + * unnecessary since the FE will do the right thing. Right now (3.0b6) + * starting to use FE_GetURL is not an option so we'll just create + * (yet another) FE callback for our purposes: we need to ask the FE + * to reset any timer it might have (for META REFRESH) so that the + * timer doesn't go off after leaving the original page via plug-in + * request. + */ + FE_ResetRefreshURLTimer(cx); +#endif + + /* reentrancy matters for this case because it will cause the current + stream to be unloaded which netlib can't deal with */ + if (instance->reentrant && (cx == instance->cx)) + { + XP_ASSERT(instance->delayedload == NULL); /* We lose queued requests if this is non-NULL! */ + if (instance->delayedload) + NET_FreeURLStruct(instance->delayedload); + instance->delayedload = urls; + instance->reentrant = 0; + } + else + { + if ((cx == instance->cx) || + (XP_IsChildContext(cx,instance->cx)) ) + { + /* re-target: use this until figure out why thread violation. + this method obviates question of self-trouncing... */ + if ((instance->cx->type == MWContextBrowser || + instance->cx->type == MWContextPane) + && ((XP_STRNCMP(urls->address, "mailbox:", 8)==0) + || (XP_STRNCMP(urls->address, "mailto:" , 7)==0) + || (XP_STRNCMP(urls->address, "news:" , 5)==0))) + cx = np_makecontext(instance,"_self"); + else{ + /* Since the previous stuff generally worked for this, keep using it */ + urls->fe_data = NULL; +#ifdef XP_WIN32 + pPrevState = WFE_BeginSetModuleState(); +#endif + /* clear the exit routine, since the recipient may not be present! */ + (void) NET_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit); +#ifdef XP_WIN32 + WFE_EndSetModuleState(pPrevState); +#endif + + return NPERR_NO_ERROR; + } + /* Eventually, we should shut down the current instance and + startup a new one */ + } +#ifdef XP_WIN32 + pPrevState = WFE_BeginSetModuleState(); +#endif + + (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); + +#ifdef XP_WIN32 + WFE_EndSetModuleState(pPrevState); +#endif + } + } + + return NPERR_NO_ERROR; + +error: + if (node) + { + node->notify = FALSE; /* Remove node without notification */ + np_removeURLfromList(instance, urls, 0); + } + if (urls) + NET_FreeURLStruct(urls); + return err; +} + + +static NPError +np_parsepostbuffer(URL_Struct* urls, const char* buf, uint32 len) +{ + /* + * Search the buffer passed in for a /n/n. If we find it, break the + * buffer in half: the first part is the header, the rest is the body. + */ + uint32 index; + for (index = 0; index < len; index++) + { + if (buf[index] == '\n' && ++index < len && buf[index] == '\n') + break; + } + + /* + * If we found '\n\n' somewhere in the middle of the string then we + * have headers, so we need to allocate a new string for the headers, + * copy the header data from the plug-in's buffer into it, and put + * it in the appropriate place of the URL struct. + */ + if (index > 1 && index < len) + { + uint32 headerLength = index; + char* headers = (char*) XP_ALLOC(headerLength + 1); + if (!headers) + return NPERR_OUT_OF_MEMORY_ERROR; + XP_MEMCPY(headers, buf, headerLength); + headers[headerLength] = 0; + urls->post_headers = headers; + } + + /* + * If we didn't find '\n\n', then the body starts at the beginning; + * otherwise, it starts right after the second '\n'. Make sure the + * body is non-emtpy, allocate a new string for it, copy the data + * from the plug-in's buffer, and put it in the URL struct. + */ + if (index >= len) + index = 0; /* No '\n\n', start body from beginning */ + else + index++; /* Found '\n\n', start body after it */ + + if (len - index > 0) /* Non-empty body? */ + { + uint32 bodyLength = len - index + 1; + char* body = (char*) XP_ALLOC(bodyLength); + if (!body) + return NPERR_OUT_OF_MEMORY_ERROR; + XP_MEMCPY(body, &(buf[index]), bodyLength); + urls->post_data = body; + urls->post_data_size = bodyLength; + urls->post_data_is_file = FALSE; + } + else + { + /* Uh-oh, no data to post */ + return NPERR_NO_DATA; + } + + return NPERR_NO_ERROR; +} + + +NPError +np_posturlinternal(NPP npp, const char* relativeURL, const char *target, + const char* altHost, const char* referrer, PRBool forceJSEnabled, + uint32 len, const char *buf, NPBool file, NPBool notify, void* notifyData) +{ + np_instance* instance; + URL_Struct* urls = NULL; + char* filename = NULL; + XP_Bool ftp; + np_urlsnode* node = NULL; + NPError err = NPERR_NO_ERROR; +#ifdef XP_WIN32 + void* pPrevState; +#endif + + /* Validate paramters */ + if (!npp || !relativeURL) + return NPERR_INVALID_PARAM; + + instance = (np_instance*) npp->ndata; + if (!instance) + return NPERR_INVALID_PARAM; + + /* Make an absolute URL struct from the (possibly) relative URL passed in */ + urls = np_makeurlstruct(instance, relativeURL, altHost, referrer); + if (!urls) + return NPERR_INVALID_URL; + + + /* + * Add this URL to the list of URLs for this instance, + * and remember if the instance would like notification. + */ + node = np_addURLtoList(instance); + if (node) + { + node->urls = urls; + if (notify) + { + node->notify = TRUE; + node->notifyData = notifyData; + } + } + else + return NPERR_OUT_OF_MEMORY_ERROR; + + /* + * FTP protocol requires that the data be in a file. + * If we really wanted to, we could write code to dump the buffer to + * a temporary file, give the temp file to netlib, and delete it when + * the exit routine fires. + */ + ftp = (strncasecomp(urls->address, "ftp:", 4) == 0); + if (ftp && !file) + { + err = NPERR_INVALID_URL; + goto error; + } + + if (file) + { + XP_StatStruct stat; + + /* If the plug-in passed a file URL, strip the 'file://' */ + if (!strncasecomp(buf, "file://", 7)) + filename = XP_STRDUP((char*) buf + 7); + else + filename = XP_STRDUP((char*) buf); + + if (!filename) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + + /* If the file doesn't exist, return an error NOW before netlib get it */ + if (XP_Stat(filename, &stat, xpURL)) + { + err = NPERR_FILE_NOT_FOUND; + goto error; + } + } + + /* + * NET_GetURL handles FTP posts differently: the post_data fields are + * ignored; instead, files_to_post contains an array of the files. + */ + if (ftp) + { + XP_ASSERT(filename); + urls->files_to_post = (char**) XP_ALLOC(sizeof(char*) + sizeof(char*)); + if (!(urls->files_to_post)) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + urls->files_to_post[0] = filename; + urls->files_to_post[1] = NULL; + urls->post_data = NULL; + urls->post_data_size = 0; + urls->post_data_is_file = FALSE; + } + else if (file) + { + XP_ASSERT(filename); + urls->post_data = filename; + urls->post_data_size = XP_STRLEN(filename); + urls->post_data_is_file = TRUE; + } + else + { + /* + * There are two different sets of buffer-parsing code. + * The new code is contained within np_parsepostbuffer, + * and is used when the plug-in calls NPN_PostURLNotify. + * The old code, below, is preserved for compatibility + * for when the plug-in calls NPN_PostURL. + */ + if (notify) + { + NPError err = np_parsepostbuffer(urls, buf, len); + if (err != NPERR_NO_ERROR) + goto error; + } + else + { + urls->post_data = (char*)XP_ALLOC(len); + if (!urls->post_data) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + XP_MEMCPY(urls->post_data, buf, len); + urls->post_data_size = len; + urls->post_data_is_file = FALSE; + } + } + + urls->method = URL_POST_METHOD; + + if (!target) + { + urls->fe_data = (void*) instance->app; +#ifdef XP_WIN32 + pPrevState = WFE_BeginSetModuleState(); +#endif + (void) NET_GetURL(urls, FO_CACHE_AND_PLUGIN, instance->cx, NPL_URLExit); +#ifdef XP_WIN32 + WFE_EndSetModuleState(pPrevState); +#endif + } + else + { + MWContext* cx = np_makecontext(instance, target); + if (!cx) + { + err = NPERR_OUT_OF_MEMORY_ERROR; + goto error; + } + urls->fe_data = (void*) instance->app; + + if (forceJSEnabled && !cx->forceJSEnabled) { + LM_ForceJSEnabled(cx); + urls->pre_exit_fn = np_redisable_js; + } + +#ifdef XP_MAC + /* + * One day the code below should call FE_GetURL, and this call will be + * unnecessary since the FE will do the right thing. Right now (3.0b6) + * starting to use FE_GetURL is not an option so we'll just create + * (yet another) FE callback for our purposes: we need to ask the FE + * to reset any timer it might have (for META REFRESH) so that the + * timer doesn't go off after leaving the original page via plug-in + * request. + */ + FE_ResetRefreshURLTimer(cx); +#endif + +#ifdef XP_WIN32 + pPrevState = WFE_BeginSetModuleState(); +#endif + (void) np_GetURL(urls, FO_CACHE_AND_PRESENT, cx, NPL_URLExit,notify); + +#ifdef XP_WIN32 + WFE_EndSetModuleState(pPrevState); +#endif + } + + return NPERR_NO_ERROR; + +error: + if (node) + { + node->notify = FALSE; /* Remove node without notification */ + np_removeURLfromList(instance, urls, 0); + } + if (urls) + NET_FreeURLStruct(urls); + return err; +} + + + +NPError NP_EXPORT +npn_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData) +{ + return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, TRUE, notifyData); +} + +NPError NP_EXPORT +npn_getvalue(NPP npp, NPNVariable variable, void *r_value) +{ + np_instance* instance; + NPError ret = NPERR_NO_ERROR; + + if (r_value == NULL) + return NPERR_INVALID_PARAM; + + /* Some of these variabled may be handled by backend. The rest is FE. + * So Handle all the backend variables and pass the rest over to FE. + */ + + switch(variable) { + case NPNVjavascriptEnabledBool : + ret = PREF_GetBoolPref("javascript.enabled", (XP_Bool*)r_value); + break; + case NPNVasdEnabledBool : + ret = PREF_GetBoolPref("autoupdate.enabled", (XP_Bool*)r_value); + break; +#ifdef MOZ_OFFLINE + case NPNVisOfflineBool :{ + XP_Bool *bptr = (XP_Bool *)r_value; + *bptr = NET_IsOffline(); + ret = NPERR_NO_ERROR; + break; } +#endif /* MOZ_OFFLINE */ + default: + instance = NULL; + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } +#ifdef XP_UNIX + ret = FE_PluginGetValue(instance?instance->handle->pdesc:NULL, + variable, r_value); +#else + ret = FE_PluginGetValue(instance->cx, instance->app, variable, + r_value); +#endif /* XP_UNIX */ + } + + return(ret); +} + +NPError NP_EXPORT +npn_setvalue(NPP npp, NPPVariable variable, void *r_value) +{ + np_instance* instance = NULL; + NPError ret = NPERR_NO_ERROR; + + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } + + if (!instance) + return NPERR_INVALID_INSTANCE_ERROR; + + switch(variable) { + case NPPVpluginWindowBool: + /* + * XXX On the Mac, a window has already been allocated by the time NPP_New + * has been called - which is fine, since we'll still use the window. + * Unfortunately, we can't use the window's presence to determine whether + * it's too late to set the windowed property. + */ +#ifndef XP_MAC + /* + * If the window has already been allocated, it's too late + * to tell us. + */ + if (!instance->app->wdata->window) + instance->windowed = (0 != r_value); + else + ret = NPERR_INVALID_PARAM; +#else + instance->windowed = (0 != r_value); +#endif + break; + case NPPVpluginTransparentBool: + instance->transparent = (0 != r_value); +#ifdef LAYERS + if (instance->layer && + (instance->transparent != !(CL_GetLayerFlags(instance->layer) & CL_OPAQUE))) + { + XP_Rect bbox; + + /* Get the bbox and convert it into its own coordinate space */ + CL_GetLayerBbox(instance->layer, &bbox); + + CL_ChangeLayerFlag(instance->layer, CL_OPAQUE, (PRBool)!instance->transparent); + CL_ChangeLayerFlag(instance->layer, + CL_PREFER_DRAW_OFFSCREEN, + (PRBool)instance->transparent); + + /* Force drawing of the entire transparent plug-in. */ + CL_UpdateLayerRect(CL_GetLayerCompositor(instance->layer), + instance->layer, &bbox, PR_FALSE); + } +#endif /* LAYERS */ + break; + + case NPPVpluginTimerInterval: + np_SetTimerInterval(npp, *(uint32*)r_value); + break; + + case NPPVpluginWindowSize: + break; + default: + break; + } + + return(ret); +} + + +NPError NP_EXPORT +npn_geturl(NPP npp, const char* relativeURL, const char* target) +{ + return np_geturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, FALSE, NULL); +} + + +NPError NP_EXPORT +npn_posturlnotify(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file, void* notifyData) +{ + return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, TRUE, notifyData); +} + + +NPError NP_EXPORT +npn_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len, const char *buf, NPBool file) +{ + return np_posturlinternal(npp, relativeURL, target, NULL, NULL, PR_FALSE, len, buf, file, FALSE, NULL); +} + + + +NPError NP_EXPORT +npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream) +{ + np_instance* instance; + np_stream* stream; + NET_StreamClass* netstream; + URL_Struct* urls; + MWContext* cx; + *pstream = NULL; + + if (!npp || !type) + return NPERR_INVALID_PARAM; + instance = (np_instance*) npp->ndata; + if (!instance) + return NPERR_INVALID_PARAM; + + /* Convert the window name to a context */ + cx = np_makecontext(instance, window); + if (!cx) + return NPERR_OUT_OF_MEMORY_ERROR; + + + /* + * Make a bogus URL struct. The URL doesn't point to + * anything, but we need it to build the stream. + */ + urls = NET_CreateURLStruct("", NET_DONT_RELOAD); + if (!urls) + return NPERR_OUT_OF_MEMORY_ERROR; + StrAllocCopy(urls->content_type, type); + + /* Make a netlib stream */ + netstream = NET_StreamBuilder(FO_PRESENT, urls, cx); + if (!netstream) + { + NET_FreeURLStruct(urls); + return NPERR_OUT_OF_MEMORY_ERROR; + } + + /* Make the plug-in stream objects */ + stream = np_makestreamobjects(instance, netstream, urls); + if (!stream) + { + XP_FREE(netstream); + NET_FreeURLStruct(urls); + return NPERR_OUT_OF_MEMORY_ERROR; + } + + *pstream = stream->pstream; + return NPERR_NO_ERROR; +} + + +int32 NP_EXPORT +npn_write(NPP npp, NPStream *pstream, int32 len, void *buffer) +{ + np_instance* instance; + np_stream* stream; + NET_StreamClass* netstream; + + if (!npp || !pstream || !buffer || len<0) + return NPERR_INVALID_PARAM; + + instance = (np_instance*) npp->ndata; + stream = (np_stream*) pstream->ndata; + + if (!instance || !stream) + return NPERR_INVALID_PARAM; + + netstream = stream->nstream; + if (!netstream) + return NPERR_INVALID_PARAM; + + return (*netstream->put_block)(netstream, (const char*) buffer, len); +} + +NPError NP_EXPORT +npn_destroystream(NPP npp, NPStream *pstream, NPError reason) +{ + np_instance* instance; + np_stream* stream; + NET_StreamClass* netstream; + URL_Struct* urls = NULL; + + if (!npp || !pstream) + return NPERR_INVALID_PARAM; + + instance = (np_instance*) npp->ndata; + stream = (np_stream*) pstream->ndata; + + if (!instance || !stream) + return NPERR_INVALID_PARAM; + + netstream = stream->nstream; + if (netstream) + urls = (URL_Struct*) netstream->data_object; + + /* + * If we still have a valid netlib stream, ask netlib + * to destroy it (it will call us back to inform the + * plug-in and delete the plug-in-specific objects). + * If we don't have a netlib stream (possible if the + * stream was in NP_SEEK mode: the netlib stream might + * have been deleted but we would keep the plug-in + * stream around because stream->dontclose was TRUE), + * just inform the plug-in and delete our objects. + */ + stream->dontclose = FALSE; /* Make sure we really delete */ + if (urls) + { + if (NET_InterruptStream(urls) < 0) + { + /* Netlib doesn't know about this stream; we must have made it */ + /*MWContext* cx = netstream->window_id;*/ + switch (reason) + { + case NPRES_DONE: + (*netstream->complete)(netstream); + break; + case NPRES_USER_BREAK: + (*netstream->abort)(netstream, MK_INTERRUPTED); + break; + case NPRES_NETWORK_ERR: + (*netstream->abort)(netstream, MK_BAD_CONNECT); + break; + default: /* Unknown reason code */ + (*netstream->abort)(netstream, -1); + break; + } + np_destroystream(stream, reason); + XP_FREE(netstream); + } + } + else + np_destroystream(stream, reason); + +/* + * We still need a way to pass the right status code + * through to NPL_Abort (NET_InterruptStream doesn't + * take a status code, so the plug-in always gets + * NPRES_USER_BREAK, not what they passed in here). + */ + return NPERR_NO_ERROR; +} + + +void NP_EXPORT +npn_status(NPP npp, const char *message) +{ + if(npp) + { + np_instance *instance = (np_instance *)npp->ndata; + if(instance && instance->cx) +#ifdef XP_MAC + /* Special entry point so MacFE can save/restore port state */ + FE_PluginProgress(instance->cx, message); +#else + FE_Progress(instance->cx, message); +#endif + } +} + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +const char * NP_EXPORT +npn_useragent(NPP npp) +{ + static char *uabuf = 0; + if(!uabuf) + uabuf = PR_smprintf("%.100s/%.90s", XP_AppCodeName, XP_AppVersion); + return (const char *)uabuf; +} +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +void * NP_EXPORT +npn_memalloc (uint32 size) +{ + return XP_ALLOC(size); +} +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + + +void NP_EXPORT +npn_memfree (void *ptr) +{ + (void)XP_FREE(ptr); +} + +#ifdef XP_MAC +/* For the definition of CallCacheFlushers() */ +#ifndef NSPR20 +#include "prmacos.h" +#else +#include "MacMemAllocator.h" +#endif +#endif + +uint32 NP_EXPORT +npn_memflush(uint32 size) +{ +#ifdef XP_MAC + /* Try to free some memory and return the amount we freed. */ + if (CallCacheFlushers(size)) + return size; + else +#endif + return 0; +} + + + + +/* + * Given an instance, switch its handler from whatever it + * currently is to the handler passed in. Assuming the new + * handler really is different, to do this we need to destroy + * the current NPP instance (so the old plug-in's out of the + * picture), then make a new NPP with the new handler + */ +NPError +np_switchHandlers(np_instance* instance, + np_handle* newHandle, + np_mimetype* newMimeType, + char* requestedType) +{ + NPEmbeddedApp* app = instance->app; + MWContext* cx = instance->cx; + np_data* ndata = (np_data*) app->np_data; + + if (app == NULL || cx == NULL || ndata == NULL) + return NPERR_INVALID_PARAM; + + /* + * If it's a full-page plug-in, just reload the document. + * We have to reload the data anyway to send it to the + * new instance, and since the instance is the only thing + * on the page it's easier to just reload the whole thing. + * NOTE: This case shouldn't ever happen, since you can't + * have full-page Default plug-ins currently. + */ + XP_ASSERT(app->pagePluginType != NP_FullPage); + if (app->pagePluginType == NP_FullPage) + { + History_entry* history = SHIST_GetCurrent(&cx->hist); + URL_Struct* urls = SHIST_CreateURLStructFromHistoryEntry(cx, history); + if (urls != NULL) + { + urls->force_reload = NET_NORMAL_RELOAD; + FE_GetURL(cx, urls); + return NPERR_NO_ERROR; + } + else + return NPERR_GENERIC_ERROR; + } + + /* Nuke the old instance */ + np_delete_instance(instance); + if (ndata != NULL && ndata->instance == instance) + ndata->instance = NULL; + + /* Make a new instance */ + ndata->instance = np_newinstance(newHandle, cx, app, newMimeType, requestedType); + NPL_EmbedSize(app); + + if (ndata->instance == NULL) + return NPERR_GENERIC_ERROR; + + /* Get the data stream for the new instance, if necessary */ + if (ndata->lo_struct->embed_src != NULL) + { + char* address; + URL_Struct* urls; + + PA_LOCK(address, char*, ndata->lo_struct->embed_src); + XP_ASSERT(address); + + urls = NET_CreateURLStruct(address, NET_DONT_RELOAD); + + PA_UNLOCK(ndata->lo_struct->embed_src); + + if (urls != NULL) + { + urls->fe_data = (void*) app; + (void) NET_GetURL(urls, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); + return NPERR_NO_ERROR; + } + else + return NPERR_GENERIC_ERROR; + } + + return NPERR_NO_ERROR; +} + + + +/* + * Ask the FE to throw away its old plugin handlers and + * re-scan the plugins folder to find new ones. This function + * is intended for use by the null plugin to signal that + * some new plugin has been installed and we should make a + * note of it. If "reloadPages" is true, we should also + * reload all open pages with plugins on them (since plugin + * handlers could have come or gone as a result of the re- + * registration). + */ +void NP_EXPORT +npn_reloadplugins(NPBool reloadPages) +{ + np_handle* oldHead = NULL; + + /* + * We won't unregister old plug-ins, we just register new ones. + * The new plug-ins will go on the front of the list, so to see + * if we got any new ones we just need to save a pointer to the + * current front of the list. + */ + if (reloadPages) + oldHead = np_plist; + + /* Ask the FE to load new plug-ins */ + FE_RegisterPlugins(); + + /* + * At least one plug-in was added to the front of the list. + * Now we need to find all instances of the default plug-in + * to see if they can be handled by one of the new plug-ins. + */ + if (reloadPages && oldHead != np_plist) + { + np_handle* defaultPlugin = np_plist; + np_instance* instance; + + /* First look for the default plug-in */ + while (defaultPlugin != NULL) + { + if (defaultPlugin->mimetypes != NULL && + defaultPlugin->mimetypes->type && + XP_STRCMP(defaultPlugin->mimetypes->type, "*") == 0) + { + break; + } + defaultPlugin = defaultPlugin->next; + } + + if (defaultPlugin == NULL) + return; + + /* Found the default plug-in; now check its instances */ + instance = defaultPlugin->instances; + while (instance != NULL) + { + NPBool switchedHandler = FALSE; + char* type = instance->typeString; + XP_ASSERT(instance->mimetype == defaultPlugin->mimetypes); + + if (type != NULL) + { + /* + * Try to match this instance's type against the + * types of all new plug-ins to see if any of them + * can handle it. Since the new plug-is were added + * to the front of the list, we only need to look + * at plug-ins up to the old head of the list. + */ + np_handle* handle = np_plist; + while (handle != NULL && handle != oldHead) + { + np_mimetype* mimeType; + XP_ASSERT(handle != defaultPlugin); + mimeType = np_getmimetype(handle, type, FALSE); + + /* + * We found a new handler for this type! Now we + * can destroy the plug-in instance and make a + * new instance handled by the new plug-in. + * Note that we have to point "instance" to the + * next object NOW, because np_switchHandlers + * will remove it from the list. + */ + if (mimeType != NULL) + { + np_instance* switcher = instance; + instance = instance->next; + (void) np_switchHandlers(switcher, handle, mimeType, type); + switchedHandler = TRUE; + break; /* Out of handle "while" loop */ + } + + handle = handle->next; + } + } + + /* + * In the case where we switch the handler (above), + * "instance" already points to the next objTag. + */ + if (!switchedHandler) + instance = instance->next; + } + } +} + + +NPError +NPL_RefreshPluginList(XP_Bool reloadPages) +{ + npn_reloadplugins(reloadPages); + return NPERR_NO_ERROR; /* Always succeeds for now */ +} + + +void NP_EXPORT +npn_invalidaterect(NPP npp, NPRect *invalidRect) +{ + np_instance* instance = NULL; + XP_Rect rect; + + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } + + if (instance && !instance->windowed) { + rect.left = invalidRect->left; + rect.top = invalidRect->top; + rect.right = invalidRect->right; + rect.bottom = invalidRect->bottom; + + CL_UpdateLayerRect(CL_GetLayerCompositor(instance->layer), + instance->layer, &rect, PR_FALSE); + } +} + +void NP_EXPORT +npn_invalidateregion(NPP npp, NPRegion invalidRegion) +{ + np_instance* instance = NULL; + + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } + + if (instance && !instance->windowed) { + CL_UpdateLayerRegion(CL_GetLayerCompositor(instance->layer), + instance->layer, invalidRegion, PR_FALSE); + } +} + +void NP_EXPORT +npn_forceredraw(NPP npp) +{ + np_instance* instance = NULL; + + if (npp != NULL) { + instance = (np_instance*) npp->ndata; + } + + if (instance && !instance->windowed) { + CL_CompositeNow(CL_GetLayerCompositor(instance->layer)); + } +} + +/******************************************************************************/ + +#ifdef JAVA +#define JRI_NO_CPLUSPLUS +#define IMPLEMENT_netscape_plugin_Plugin +#include "netscape_plugin_Plugin.h" +#ifdef MOCHA +#include "libmocha.h" +#endif /* MOCHA */ +#endif /* JAVA */ + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +#if defined(OJI) +JNIEnv* NP_EXPORT +npn_getJavaEnv(PRThread *pPRThread) +{ + +#ifdef XP_MAC + short resNum1, resNum2; + resNum1 = CurResFile(); +#endif /* XP_MAC */ + JNIEnv *pJNIEnv = NULL; + + /* =-= What do we do with the thread passed in? Looks like we cannot + * get a JNIEnv for any arbitrary thread. One can only attach to a + * current thread. + */ + pJNIEnv = JVM_GetJNIEnv(); /* This may startup the VM. */ + +#ifdef XP_MAC + /* if Java changed the res file, change it back to the plugin's res file */ + resNum2 = CurResFile(); + if(resNum1 != resNum2) + UseResFile(resNum1); +#endif /* XP_MAC */ + + return pJNIEnv; +} +#else /* OJI */ +JRIEnv* NP_EXPORT +npn_getJavaEnv(void) +{ +#ifdef JAVA + JRIEnv* env; + +#ifdef XP_MAC + short resNum1, resNum2; + resNum1 = CurResFile(); +#endif /* XP_MAC */ + + env = LJ_EnsureJavaEnv(NULL); /* NULL means for the current thread */ + +#ifdef XP_MAC + /* if Java changed the res file, change it back to the plugin's res file */ + resNum2 = CurResFile(); + if(resNum1 != resNum2) + UseResFile(resNum1); +#endif /* XP_MAC */ + + return env; +#else /* JAVA */ + return NULL; +#endif /* JAVA */ +} +#endif /* !OJI */ + + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + +#if defined(OJI) +#define fieldname_netscape_plugin_Plugin_window "window" +#define fieldsig_netscape_plugin_Plugin_window "Lnetscape/javascript/JSObject;" + +jclass NP_EXPORT +npn_getJavaClass(np_handle* handle); + +void +np_recover_mochaWindow(JNIEnv * env, np_instance * instance) +{ + if (env && instance && instance->mochaWindow && instance->javaInstance){ + /* Store the JavaScript context as the window object: */ + env->SetObjectField(instance->javaInstance, + env->GetFieldID(npn_getJavaClass(instance->handle), + fieldname_netscape_plugin_Plugin_window, fieldsig_netscape_plugin_Plugin_window), + (jobject)instance->mochaWindow); + + } +} +jobject classPlugin = NULL; +#define NPN_NO_JAVA_INSTANCE ((jobject)-1) + +#elif defined(JAVA) +void +np_recover_mochaWindow(JRIEnv * env, np_instance * instance) +{ + netscape_plugin_Plugin* javaInstance = NULL; + + if (env && instance && instance->mochaWindow && instance->javaInstance){ + javaInstance = (struct netscape_plugin_Plugin *) + JRI_GetGlobalRef(env, instance->javaInstance); + if (javaInstance) { + /* Store the JavaScript context as the window object: */ + set_netscape_plugin_Plugin_window(env, javaInstance, + (netscape_javascript_JSObject*) + JRI_GetGlobalRef(env, instance->mochaWindow)); + } + } +} +jglobal classPlugin = NULL; +#define NPN_NO_JAVA_INSTANCE ((jglobal)-1) + +#endif /* ! OJI */ + +extern void +ET_SetPluginWindow(MWContext *cx, void *instance); + +NS_DEFINE_IID(kPluginInstanceIID, NS_IPLUGININSTANCE_IID); +NS_DEFINE_IID(kLiveConnectPluginIID, NS_ILIVECONNECTPLUGIN_IID); + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif + +#if defined(OJI) +jclass NP_EXPORT +npn_getJavaClass(np_handle* handle) +{ + if (handle->userPlugin) { + nsIPlugin* userPluginClass = (nsIPlugin*)handle->userPlugin; + nsILiveConnectPlugin* lcPlugin; + if (userPluginClass->QueryInterface(kLiveConnectPluginIID, + (void**)&lcPlugin) != NS_NOINTERFACE) { + jclass clazz = lcPlugin->GetJavaClass(); + + // Remember, QueryInterface increments the ref count; + // since we're done with it in this scope, release it. + lcPlugin->Release(); + + return clazz; + } + return NULL; // not a LiveConnected plugin + } + else if (handle && handle->f) { + JNIEnv* env = npn_getJavaEnv(NULL); /* may start up the java runtime */ + if (env == NULL) return NULL; + return (jclass) env->NewGlobalRef(handle->f->javaClass); + } + return NULL; +} +#elif defined(JAVA) +java_lang_Class* NP_EXPORT +npn_getJavaClass(np_handle* handle) +{ + if (handle->userPlugin) { + nsIPlugin* userPluginClass = (nsIPlugin*)handle->userPlugin; + nsILiveConnectPlugin* lcPlugin; + if (userPluginClass->QueryInterface(kLiveConnectPluginIID, + (void**)&lcPlugin) != NS_NOINTERFACE) { + java_lang_Class* clazz = (java_lang_Class*)lcPlugin->GetJavaClass(); + + // Remember, QueryInterface increments the ref count; + // since we're done with it in this scope, release it. + lcPlugin->Release(); + + return clazz; + } + return NULL; // not a LiveConnected plugin + } + else if (handle && handle->f) { + JRIEnv* env = npn_getJavaEnv(); /* may start up the java runtime */ + if (env == NULL) return NULL; + return (java_lang_Class*)JRI_GetGlobalRef(env, handle->f->javaClass); + } + return NULL; +} +#endif /* JAVA */ + +#if defined(OJI) +jobject NP_EXPORT +npn_getJavaPeer(NPP npp) +{ + jobject javaInstance = NULL; + np_instance* instance; + + if (npp == NULL) + return NULL; + instance = (np_instance*) npp->ndata; + if (instance == NULL) return NULL; + + if (instance->javaInstance == NPN_NO_JAVA_INSTANCE) { + /* Been there, done that. */ + return NULL; + } + else if (instance->javaInstance != NULL) { + /* + ** It's ok to get the JNIEnv here -- it won't initialize the + ** runtime because it would have already been initialized to + ** create the instance that we're just about to return. + */ + + /* But first, see if we need to recover the mochaWindow... */ + np_recover_mochaWindow(npn_getJavaEnv(NULL),instance); + + return (jref)instance->javaInstance; + } + else { + jclass clazz = npn_getJavaClass(instance->handle); + if (clazz) { + JNIEnv* env = npn_getJavaEnv(NULL); /* may start up the java runtime */ + if (classPlugin == NULL) { + /* + ** Make sure we never unload the Plugin class. Why? Because + ** the method and field IDs we're using below have the same + ** lifetime as the class (theoretically): + */ + classPlugin = env->NewGlobalRef(clazz); + } + + /* instantiate the plugin's class: */ +#define methodname_netscape_plugin_Plugin_new "" +#define methodsig_netscape_plugin_Plugin_new "()V" + + javaInstance = env->NewObject(clazz, env->GetMethodID(clazz, + methodname_netscape_plugin_Plugin_new, methodsig_netscape_plugin_Plugin_new)); + if (javaInstance) { + instance->javaInstance = env->NewGlobalRef(javaInstance); + np_recover_mochaWindow(env,instance); + + /* Store the plugin as the peer: */ +#define fieldname_netscape_plugin_Plugin_peer "peer" +#define fieldsig_netscape_plugin_Plugin_peer "I" + env->SetIntField(javaInstance, + env->GetFieldID(clazz, + fieldname_netscape_plugin_Plugin_peer, fieldsig_netscape_plugin_Plugin_peer), + (jint)instance->npp); + +#define methodname_netscape_plugin_Plugin_init "init" +#define methodsig_netscape_plugin_Plugin_init "()V" + env->CallVoidMethod(javaInstance, + env->GetMethodID(clazz, + methodname_netscape_plugin_Plugin_init, methodsig_netscape_plugin_Plugin_init)); + + } + if (env->ExceptionOccurred()) { + env->DeleteGlobalRef(instance->javaInstance); + instance->javaInstance = NPN_NO_JAVA_INSTANCE; /* prevent trying this every time around */ + env->DeleteGlobalRef(classPlugin); + classPlugin = NULL; + env->ExceptionClear(); + return NULL; + } \ + } + else { + instance->javaInstance = NPN_NO_JAVA_INSTANCE; /* prevent trying this every time around */ + return NULL; + } + } + return (jref)javaInstance; +} +#elif defined(JAVA) +jref NP_EXPORT +npn_getJavaPeer(NPP npp) +{ + netscape_plugin_Plugin* javaInstance = NULL; + np_instance* instance; + + if (npp == NULL) + return NULL; + instance = (np_instance*) npp->ndata; + if (instance == NULL) return NULL; + + if (instance->javaInstance == NPN_NO_JAVA_INSTANCE) { + /* Been there, done that. */ + return NULL; + } + else if (instance->javaInstance != NULL) { + /* + ** It's ok to get the JRIEnv here -- it won't initialize the + ** runtime because it would have already been initialized to + ** create the instance that we're just about to return. + */ + + /* But first, see if we need to recover the mochaWindow... */ + np_recover_mochaWindow(npn_getJavaEnv(),instance); + + return (jref)JRI_GetGlobalRef(npn_getJavaEnv(), instance->javaInstance); + } + else { + struct java_lang_Class* clazz = npn_getJavaClass(instance->handle); + if (clazz) { + JRIEnv* env = npn_getJavaEnv(); /* may start up the java runtime */ + if (classPlugin == NULL) { + /* + ** Make sure we never unload the Plugin class. Why? Because + ** the method and field IDs we're using below have the same + ** lifetime as the class (theoretically): + */ + classPlugin = JRI_NewGlobalRef(env, use_netscape_plugin_Plugin(env)); + } + + /* instantiate the plugin's class: */ + javaInstance = netscape_plugin_Plugin_new(env, clazz); + if (javaInstance) { + + instance->javaInstance = JRI_NewGlobalRef(env, javaInstance); + + np_recover_mochaWindow(env,instance); + + /* Store the plugin as the peer: */ + set_netscape_plugin_Plugin_peer(env, javaInstance, (jint)instance->npp); + + + netscape_plugin_Plugin_init(env, javaInstance); + } + } + else { + instance->javaInstance = NPN_NO_JAVA_INSTANCE; /* prevent trying this every time around */ + return NULL; + } + } + return (jref)javaInstance; +} +#endif /* JAVA */ + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + +static XP_Bool +np_IsLiveConnected(np_handle* handle) +{ + if (handle->userPlugin) { + nsIPlugin* userPluginClass = (nsIPlugin*)handle->userPlugin; + nsILiveConnectPlugin* lcPlugin; + + if (userPluginClass->QueryInterface(kLiveConnectPluginIID, + (void**)&lcPlugin) != NS_NOINTERFACE) { + // Remember, QueryInterface increments the ref count; + // since we're done with it in this scope, release it. + lcPlugin->Release(); + + return TRUE; + } else { + return FALSE; + } + } + else { + return npn_getJavaClass(handle) != NULL; + } +} + +/* Is the plugin associated with this embedStruct liveconnected? */ +XP_Bool NPL_IsLiveConnected(LO_EmbedStruct *embed) +{ +#if defined(JAVA) || defined(OJI) + NPEmbeddedApp* app; + np_data* ndata; + + if (embed == NULL) + return FALSE; + + app = (NPEmbeddedApp*) embed->objTag.FE_Data; + if (app == NULL) + return FALSE; + + ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + return np_IsLiveConnected(ndata->instance->handle); +#endif +} + + + +/******************************************************************************/ + +/* Returns false if there was an error: */ +static PRBool +np_setwindow(np_instance *instance, NPWindow *appWin) +{ + /* + * On Windows and UNIX, we don't want to give a window + * to hidden plug-ins. To determine if we're hidden, + * we can look at the flag bit of the LO_EmbedStruct. + */ + NPEmbeddedApp* app; + np_data* ndata; + LO_EmbedStruct* lo_struct; + + if (instance) + { + app = instance->app; + if (app) + { + ndata = (np_data*) app->np_data; + lo_struct = ndata->lo_struct; +#ifndef XP_MAC + if (lo_struct && lo_struct->objTag.ele_attrmask & LO_ELE_HIDDEN) + return PR_TRUE; +#endif + } + } + + XP_ASSERT(instance); + if (instance && appWin) + { + TRACEMSG(("npglue.c: CallNPP_SetWindowProc")); + if (instance->handle->userPlugin) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + userInst->SetWindow((nsPluginWindow*)appWin); + + // If this is the first time we're drawing this, then call + // the plugin's Start() method. + if (lo_struct && ! (lo_struct->objTag.ele_attrmask & LO_ELE_DRAWN)) { + nsPluginError err = userInst->Start(); + if (err != nsPluginError_NoError) { + np_delete_instance(instance); + return PR_FALSE; + } + } + } + else if (ISFUNCPTR(instance->handle->f->setwindow)) { + CallNPP_SetWindowProc(instance->handle->f->setwindow, instance->npp, appWin); + } + } + else + { + NPTRACE(0,("setwindow before appWin was valid")); + } + return PR_TRUE; +} + +static void +np_UnloadPluginClass(np_handle *handle) +{ + /* only called when we truly want to dispose the plugin class */ + XP_ASSERT(handle && handle->refs == 0); + +#if defined(OJI) + if (handle->userPlugin == NULL && handle->f && handle->f->javaClass != NULL) { + /* Don't get the environment unless there is a Java class, + because this would cause the java runtime to start up. */ + JNIEnv* env = npn_getJavaEnv(NULL); + env->DeleteGlobalRef(handle->f->javaClass); + handle->f->javaClass = NULL; + } +#elif defined(JAVA) + if (handle->userPlugin == NULL && handle->f && handle->f->javaClass != NULL) { + /* Don't get the environment unless there is a Java class, + because this would cause the java runtime to start up. */ + JRIEnv* env = npn_getJavaEnv(); + JRI_DisposeGlobalRef(env, handle->f->javaClass); + handle->f->javaClass = NULL; + } +#endif /* JAVA */ + + FE_UnloadPlugin(handle->pdesc, handle); + handle->f = NULL; + + XP_ASSERT(handle->instances == NULL); + handle->instances = NULL; +} + + +/* this is called from the mocha thread to set the mocha window, +* in response to getJavaPeer */ +PR_IMPLEMENT(void) +NPL_SetPluginWindow(void *data) +{ +#ifdef JAVA + JRIEnv * env = NULL; + np_instance *instance = (np_instance *) data; + struct netscape_javascript_JSObject *mochaWindow = NULL; + + if (instance && instance->cx) + mochaWindow = LJ_GetMochaWindow(instance->cx); + + env = LJ_EnsureJavaEnv(PR_CurrentThread()); + + if (mochaWindow){ + instance->mochaWindow = JRI_NewGlobalRef(env, (jref) mochaWindow); + + /* That's done, now stuff it in */ + np_recover_mochaWindow(env,instance); + } +#endif +} + + +np_instance* +np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, + np_mimetype *mimetype, char *requestedType) +{ + NPError err = NPERR_GENERIC_ERROR; + np_instance* instance = NULL; + NPP npp = NULL; + void* tmp; + np_data* ndata; + + XP_ASSERT(handle && app); + if (!handle || !app) + return NULL; + + /* make sure the plugin is loaded */ + if (!handle->refs) + { +#ifdef JAVA + JRIEnv* env = NULL; +#endif + FE_Progress(cx, XP_GetString(XP_PLUGIN_LOADING_PLUGIN)); + if (!(handle->f = FE_LoadPlugin(handle->pdesc, &npp_funcs, handle))) + { + char* msg = PR_smprintf(XP_GetString(XP_PLUGIN_CANT_LOAD_PLUGIN), handle->name, mimetype->type); + FE_Alert(cx, msg); + XP_FREE(msg); + return NULL; + } +#ifdef JAVA + /* + ** Don't use npn_getJavaEnv here. We don't want to start the + ** interpreter, just use env if it already exists. + */ + env = JRI_GetCurrentEnv(); + + /* + ** An exception could have occurred when the plugin tried to load + ** it's class file. We'll print any exception to the console. + */ + if (env && JRI_ExceptionOccurred(env)) { + JRI_ExceptionDescribe(env); + JRI_ExceptionClear(env); + } +#endif + } + + ndata = (np_data*) app->np_data; + NPSavedData* savedData = (NPSavedData*) (ndata ? ndata->sdata : NULL); + + if (handle->userPlugin == NULL || savedData == NULL) { + // Then we're either an old style plugin that needs to get + // (re)created, or a new style plugin that hasn't yet saved + // its data, so it needs to get created the first time. + + /* make an instance */ + if (!(instance = XP_NEW_ZAP(np_instance))) + goto error; + + instance->handle = handle; + instance->cx = cx; + instance->app = app; + instance->mimetype = mimetype; + instance->type = (app->pagePluginType == NP_FullPage) ? NP_FULL : NP_EMBED; + instance->typeString = (char*) (requestedType ? XP_STRDUP(requestedType) : NULL); + + instance->mochaWindow = NULL; + instance->javaInstance = NULL; + + app->type = NP_Plugin; + + /* make an NPP */ + if (!(tmp = XP_NEW_ZAP(NPP_t))) + goto error; + npp = (NPP) tmp; /* make pc compiler happy */ + npp->ndata = instance; + instance->npp = npp; + instance->windowed = TRUE; + instance->transparent = FALSE; + +#ifdef PLUGIN_TIMER_EVENT + instance->timeout = NULL; + instance->interval = DEFAULT_TIMER_INTERVAL; +#endif + +#ifdef LAYERS + if (ndata) + instance->layer = ndata->lo_struct->objTag.layer; +#endif /* LAYERS */ + + /* invite the plugin */ + TRACEMSG(("npglue.c: CallNPP_NewProc")); + if (handle->userPlugin) { + nsIPlugin* userPluginClass = (nsIPlugin*)handle->userPlugin; + nsPluginInstancePeer* peerInst = new nsPluginInstancePeer(npp); + if (peerInst == NULL) { + err = NPERR_OUT_OF_MEMORY_ERROR; + } + else { + peerInst->AddRef(); + nsIPluginInstance* userInst; + nsresult err2 = userPluginClass->CreateInstance(NULL, kPluginInstanceIID, + (void**)&userInst); + if (err2 == NS_OK && userInst != NULL) { + nsPluginError err3 = userInst->Initialize(peerInst); + if (err3 == nsPluginError_NoError) { + npp->pdata = peerInst; + peerInst->SetUserInstance(userInst); + ndata->sdata = (NPSavedData*)userInst; + err = NPERR_NO_ERROR; + } + else + err = NPERR_INVALID_INSTANCE_ERROR; + } + else + err = NPERR_INVALID_INSTANCE_ERROR; + } + } + else { + if (ISFUNCPTR(handle->f->newp)) + { + XP_ASSERT(ndata); + if (instance->type == NP_EMBED) + { + /* Embedded plug-ins get their attributes passed in from layout */ +#ifdef OJI + int16 argc = (int16) ndata->lo_struct->attributes.n; + char** names = ndata->lo_struct->attributes.names; + char** values = ndata->lo_struct->attributes.values; +#else + int16 argc = (int16) ndata->lo_struct->attribute_cnt; + char** names = ndata->lo_struct->attribute_list; + char** values = ndata->lo_struct->value_list; +#endif + err = CallNPP_NewProc(handle->f->newp, requestedType, npp, + instance->type, argc, names, values, savedData); + } + else + { + /* A full-page plugin must be told its palette may + be realized as a foreground palette */ + char name[] = "PALETTE"; + char value[] = "foreground"; + char* names[1]; + char* values[1]; + int16 argc = 1; + names[0] = name; + values[0] = value; + + err = CallNPP_NewProc(handle->f->newp, requestedType, npp, + instance->type, argc, names, values, savedData); + } + } + } + if (err != NPERR_NO_ERROR) + goto error; + + /* add this to the handle chain */ + instance->next = handle->instances; + handle->instances = instance; + handle->refs++; + + /* + * In the full-page case, FE_DisplayEmbed hasn't been called yet, + * so the window hasn't been created and wdata is still NULL. + * We don't want to give the plug-in a NULL window. + * N.B.: Actually, on the Mac, the window HAS been created (we + * need it because even undisplayed/hidden plug-ins may need a + * window), so wdata is not NULL; that's why we check the plug-in + * type rather than wdata here. + */ +#ifndef LAYERS + /* + * We don't know that layout has set the final position of the plug-in at this + * point. The danger is that the plug-in will draw into the window incorrectly + * with this call. With layers, we don't display the window until layout + * is completely done - at that we can call NPP_SetWindow. + */ + if (app->pagePluginType == NP_Embedded) + { + XP_ASSERT(app->wdata); + PRBool success = np_setwindow(instance, app->wdata); + if (!success) goto error; + } +#endif + } + + /* XXX This is _not_ where Start() should go (IMO). Start() should be + called whenever we re-visit an applet + + // Finally, if it's a 5.0-style (C++) plugin, send it the Start message. + // Do this before sending the mocha OnLoad message. + if (handle->userPlugin && ndata->sdata) { + nsIPluginInstance* userInst = (nsIPluginInstance*)ndata->sdata; + nsPluginError err = userInst->Start(); + if (err != nsPluginError_NoError) goto error; + } + */ + +#ifdef MOCHA + { + /* only wait on applets if onload flag */ + lo_TopState *top_state = lo_FetchTopState(XP_DOCID(cx)); + if (top_state != NULL && top_state->mocha_loading_embeds_count) + { + top_state->mocha_loading_embeds_count--; + ET_SendLoadEvent(cx, EVENT_XFER_DONE, NULL, NULL, + LO_DOCUMENT_LAYER_ID, FALSE); + } + + /* tell the mocha thread to set us up with the window when it can */ + if ( +#if 0 + // XXX This is what we really want here, because it doesn't actually + // start up the jvm, it just checks that the plugin is LiveConnected. + // The problem is that by deferring the jvm startup, we cause it to + // happen later on the wrong thread. + np_IsLiveConnected(handle) +#elif defined(JAVA) + npn_getJavaClass(handle) +#else + FALSE +#endif + ) { /* for liveconnected plugins only */ + ET_SetPluginWindow(cx, (void *)instance); + } + } +#endif /* MOCHA */ + + return instance; + +error: + /* Unload the plugin if there are no other instances */ + if (handle->refs == 0) + { + np_UnloadPluginClass(handle); + } + + if (instance) + XP_FREE(instance); + if (npp) + XP_FREE(npp); + return NULL; +} + + + +NET_StreamClass * +np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance) +{ + NET_StreamClass *nstream = nil; + NPStream *pstream = nil; + np_stream *stream = nil; + uint16 stype; + XP_Bool alreadyLocal; + XP_Bool b1; + XP_Bool b2; + + /* make a netlib stream */ + if (!(nstream = XP_NEW_ZAP(NET_StreamClass))) + return 0; + + /* make the plugin stream data structures */ + stream = np_makestreamobjects(instance, nstream, urls); + if (!stream) + { + XP_FREE(nstream); + return 0; + } + pstream = stream->pstream; + + stream->prev_stream = NULL; + + /* Let us treat mailbox as remote too + Not doing so causes problems with some attachments (Adobe) + */ + b1 = NET_IsURLInDiskCache(stream->initial_urls); + b2 = (XP_STRNCASECMP(urls->address, "mailbox:", 8) == 0) ? 0 : NET_IsLocalFileURL(urls->address); + + alreadyLocal = b1 || b2; + + /* determine if the stream is seekable */ + if (urls->server_can_do_byteranges || alreadyLocal) + { + /* + * Zero-length streams are never seekable. + * This will force us to download the entire + * stream if a byterange request is made. + */ + if (urls->content_length > 0) + stream->seekable = 1; + } + + /* and call the plugin */ + instance->reentrant = 1; + stype = NP_NORMAL; + TRACEMSG(("npglue.c: CallNPP_NewStreamProc")); + if (handle->userPlugin) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + nsPluginStreamPeer* peerStream = new nsPluginStreamPeer(urls, stream); + if (peerStream == NULL) { + /* XXX where's the error go? */ + } + else { + peerStream->AddRef(); + nsIPluginStream* userStream; + nsPluginError err = userInst->NewStream(peerStream, &userStream); + if (err == nsPluginError_NoError && userStream != NULL) { + peerStream->SetUserStream(userStream); + pstream->pdata = peerStream; + + stype = userStream->GetStreamType(); + } + else { + /* XXX where's the error go? */ + } + } + } + else if (ISFUNCPTR(handle->f->newstream)) + { + /*XXX*/CallNPP_NewStreamProc(handle->f->newstream, instance->npp, urls->content_type, + pstream, stream->seekable, &stype); + } + if(!instance->reentrant) + { + urls->pre_exit_fn = np_dofetch; + XP_FREE(nstream); /* will not call abort */ + return 0; + } + instance->reentrant = 0; + + /* see if its hard */ + if(stype == NP_SEEK) + { + if(!stream->seekable) + { + NPTRACE(0,("stream is dumb, force caching")); + stream->seek = 2; + } + /* for a seekable stream that doesn't require caching, in the SSL case, don't cache, because that + will leave the supposedly secure file laying around in the cache! */ + if ( !alreadyLocal + && !(XP_STRNCASECMP(urls->address, "https:", 6)==0)) + urls->must_cache = TRUE; + stream->dontclose++; + } + else if (stype == NP_ASFILE || stype == NP_ASFILEONLY) + { + NPTRACE(0,("stream as file")); + if (!alreadyLocal) + urls->must_cache = TRUE; + stream->asfile = stype; + } + + /* + * If they want just the file, and the file is local, there's + * no need to continue with the netlib stream: just give them + * the file and we're done. + */ + if (stype == NP_ASFILEONLY) + { + if (urls->cache_file || NET_IsLocalFileURL(urls->address)) + { + np_streamAsFile(stream); + np_destroystream(stream, NPRES_DONE); + XP_FREE(nstream); + return NULL; + } + } + + /* and populate the netlib stream */ + nstream->name = "plug-in"; + nstream->complete = NPL_Complete; + nstream->abort = NPL_Abort; + nstream->is_write_ready = NPL_WriteReady; + nstream->put_block = (MKStreamWriteFunc)NPL_Write; + nstream->data_object = (void *)urls; + nstream->window_id = instance->cx; + + /* In case of Mailbox->StreamAsFile, use cache code to store, handle... */ + if ( ((stype == NP_ASFILE) || (stype == NP_ASFILEONLY)) && + ((XP_STRNCASECMP(urls->address, "mailbox:", 8)==0) + || (XP_STRNCASECMP(urls->address, "news:" , 5)==0) + || (XP_STRNCASECMP(urls->address, "snews:" , 6)==0)) + && + (stream != NULL) && + (urls->cache_file == NULL)) /* if already cached, is well-handled */ + { + urls->must_cache = TRUE; + stream->prev_stream = NET_StreamBuilder(FO_CACHE_ONLY,urls,instance->cx); + } + + return nstream; +} + +XP_Bool np_FakeHTMLStream(URL_Struct* urls, MWContext* cx, char * fakehtml) +{ + NET_StreamClass* viewstream; + char* org_content_type = urls->content_type; + XP_Bool ret = FALSE; + + urls->content_type = NULL; + + StrAllocCopy(urls->content_type, TEXT_HTML); + if(urls->content_type == NULL) /* StrAllocCopy failed */ + goto Exit; + + urls->is_binary = 1; /* flag for mailto and saveas */ + + if ((viewstream = NET_StreamBuilder(FO_PRESENT, urls, cx)) != 0) + { + (*viewstream->put_block)(viewstream, fakehtml, XP_STRLEN(fakehtml)); + (*viewstream->complete)(viewstream); + + XP_FREEIF(viewstream); + viewstream = NULL; + ret = TRUE; + } + + XP_FREE(urls->content_type); + +Exit: + urls->content_type = org_content_type; + return ret; +} + +NET_StreamClass* +NPL_NewPresentStream(FO_Present_Types format_out, void* type, URL_Struct* urls, MWContext* cx) +{ + np_handle* handle = (np_handle*) type; + np_instance* instance = NULL; + np_data* ndata = NULL; + np_mimetype* mimetype = NULL; + np_reconnect* reconnect; + NPEmbeddedApp *app = NULL; + +#ifdef ANTHRAX + char* fileName; + char* newTag; + uint32 strLen; +#endif /* ANTHRAX */ + + XP_ASSERT(type && urls && cx); + if (!type || !urls || !cx) + return NULL; + + /* fe_data is set by EmbedCreate, which hasn't happed yet for PRESENT streams */ + XP_ASSERT(urls->fe_data == NULL); + +#ifdef ANTHRAX + if((fileName = NPL_FindAppletEnabledForMimetype(handle->name)) != NULL) + { + XP_FREE(fileName); /* we don't need the applet name here, so discard it */ + fileName = strrchr(urls->address, '/')+1; + + strLen = XP_STRLEN(fileName); + + newTag = XP_ALLOC((36+strLen)*sizeof(char)); + newTag[0] = 0; + + XP_STRCAT(newTag, ""); + + np_FakeHTMLStream(urls,cx,newTag); + XP_FREE(newTag); + return NULL; + } +#endif /* ANTHRAX */ + + mimetype = np_getmimetype(handle, urls->content_type, TRUE); + if (!mimetype) + return NULL; + + /* + * The following code special-cases the LiveAudio plug-in to open + * a new chromeless window. A new window is only opened if there's + * history information for the current context; that prevents us from + * opening ANOTHER new window if the FE has already made one (for + * example, if the user chose "New window for this link" from the + * popup). + */ + if (handle->name && (XP_STRCASECMP(handle->name, "LiveAudio") == 0)) + { + History_entry* history = SHIST_GetCurrent(&cx->hist); + if (history) + { + MWContext* oldContext = cx; + Chrome* customChrome = XP_NEW_ZAP(Chrome); + if (customChrome == NULL) + return NULL; + customChrome->w_hint = 144 + 1; + customChrome->h_hint = 60 + 1; + customChrome->allow_close = TRUE; + + /* Make a new window with no URL or window name, but special chrome */ + cx = FE_MakeNewWindow(oldContext, NULL, NULL, customChrome); + if (cx == NULL) + { + XP_FREE(customChrome); + return NULL; + } + /* Insert some HTML to notify of Java delay: */ + { + JRIEnv* env = NULL; + /* Has Java already been started? */ +#ifdef JAVA + env = JRI_GetCurrentEnv(); +#endif + if (env == NULL){ + /* nope, java not yet started */ + static char fakehtml[255] = ""; + + XP_SPRINTF(fakehtml,"

%s
",XP_GetString(XP_PROGRESS_STARTING_JAVA)); + np_FakeHTMLStream(urls,cx,fakehtml); + } + } + + /* Switch to the new context, but don't change the exit routine */ + NET_SetNewContext(urls, cx, NULL); + } + } + + + /* + * Set up the "reconnect" data, which is used to communicate between this + * function and the call to EmbedCreate that will result from pushing the + * data into the stream below. EmbedCreate needs to know from us the + * np_mimetype and requestedtype for this stream, and we need to know from + * it the NPEmbeddedApp that it created. + */ + XP_ASSERT(cx->pluginReconnect == NULL); + reconnect = XP_NEW_ZAP(np_reconnect); + if (!reconnect) + return NULL; + cx->pluginReconnect = (void*) reconnect; + reconnect->mimetype = mimetype; + reconnect->requestedtype = XP_STRDUP(urls->content_type); + + /* + * To actually create the instance we need to create a stream of + * fake HTML to cause layout to create a new embedded objTag. + * EmbedCreate will be called, which will created the NPEmbeddedApp + * and put it into urls->fe_data, where we can retrieve it. + */ + { + static char fakehtml[] = ""; + np_FakeHTMLStream(urls,cx,fakehtml); + } + + /* + * Retrieve the app created by EmbedCreate and stashed in the reconnect data. + * From the app we can get the np_data, which in turn holds the handle and + * instance, which we need to create the streams. + */ + app = reconnect->app; + XP_FREE(reconnect); + cx->pluginReconnect = NULL; + + if (!app) + return NULL; /* will be NULL if the plugin failed to initialize */ + XP_ASSERT(app->pagePluginType == NP_FullPage); + + urls->fe_data = (void*) app; /* fe_data of plug-in URLs always holds NPEmbeddedApp */ + + ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + if (!ndata) + return NULL; + + handle = ndata->handle; + instance = ndata->instance; + XP_ASSERT(handle && instance); + if (!handle || !instance) + return NULL; + + /* now actually make a plugin and netlib stream */ + return np_newstream(urls, handle, instance); +} + + + +NET_StreamClass* +NPL_NewEmbedStream(FO_Present_Types format_out, void* type, URL_Struct* urls, MWContext* cx) +{ + np_handle* handle = (np_handle*) type; + np_data* ndata = NULL; + NPEmbeddedApp* app = NULL; + + XP_ASSERT(type && urls && cx); + if (!type || !urls || !cx) + return NULL; + + /* fe_data is set by EmbedCreate, which has already happened for EMBED streams */ + app = (NPEmbeddedApp*) urls->fe_data; + XP_ASSERT(app); + if (!app) + return NULL; + XP_ASSERT(app->pagePluginType == NP_Embedded); + + ndata = (np_data*) app->np_data; + XP_ASSERT(ndata && ndata->lo_struct); + if (!ndata) + return NULL; + + if (ndata->instance == NULL) + { + np_instance* instance; + np_mimetype* mimetype; + + /* Map the stream's MIME type to a np_mimetype object */ + mimetype = np_getmimetype(handle, urls->content_type, TRUE); + if (!mimetype) + return NULL; + + /* Now that we have the MIME type and the layout data, we can create an instance */ + instance = np_newinstance(handle, cx, app, mimetype, urls->content_type); + if (!instance) + return NULL; + + ndata->instance = instance; + ndata->handle = handle; +#ifdef LAYERS + LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); +#endif + } + + /* now actually make a plugin and netlib stream */ + return np_newstream(urls, ndata->instance->handle, ndata->instance); +} + + +static NET_StreamClass * +np_newbyterangestream(FO_Present_Types format_out, void *type, URL_Struct *urls, MWContext *cx) +{ + NET_StreamClass *nstream = nil; + + /* make a netlib stream */ + if (!(nstream = XP_NEW_ZAP(NET_StreamClass))) + return 0; + + urls->position = 0; /* single threaded for now */ + + /* populate netlib stream */ + nstream->name = "plug-in byterange"; + nstream->complete = NPL_Complete; + nstream->abort = NPL_Abort; + nstream->is_write_ready = NPL_WriteReady; + nstream->put_block = (MKStreamWriteFunc)NPL_Write; + nstream->data_object = (void *)urls; + nstream->window_id = cx; + + return nstream; +} + +static NET_StreamClass * +np_newpluginstream(FO_Present_Types format_out, void *type, URL_Struct *urls, MWContext *cx) +{ + NPEmbeddedApp* app = (NPEmbeddedApp*) urls->fe_data; + + if (app) + { + np_data *ndata = (np_data *)app->np_data; + if(ndata && ndata->instance) + { + XP_ASSERT(ndata->instance->app == app); + return np_newstream(urls, ndata->instance->handle, ndata->instance); + } + } + return 0; +} + +NPError +NPL_RegisterPluginFile(const char* pluginname, const char* filename, const char* description, + void *pdesc) +{ + np_handle* handle; + + NPTRACE(0,("np: register file %s", filename)); + +#ifdef DEBUG + /* Ensure uniqueness of pdesc values! */ + for (handle = np_plist; handle; handle = handle->next) + XP_ASSERT(handle->pdesc != pdesc); +#endif + + handle = XP_NEW_ZAP(np_handle); + if (!handle) + return NPERR_OUT_OF_MEMORY_ERROR; + + StrAllocCopy(handle->name, pluginname); + StrAllocCopy(handle->filename, filename); + StrAllocCopy(handle->description, description); + + handle->pdesc = pdesc; + handle->next = np_plist; + handle->userPlugin = NULL; + np_plist = handle; + +#ifdef OJI + char* pluginDir = PL_strdup(filename); + if (pluginDir) { + char* lastSlash = PL_strrchr(pluginDir, PR_DIRECTORY_SEPARATOR); + if (lastSlash) + lastSlash[0] = '\0'; + JVM_AddToClassPath(pluginDir); + } +#endif + + return NPERR_NO_ERROR; +} + +/* + * Given a pluginName and a mimetype, this will enable the plugin for + * the mimetype and disable anyother plugin that had been enabled for + * this mimetype. + * + * pluginName and type cannot be NULL. + * + * WARNING: If enable is FALSE, this doesn't unregister the converters yet. + */ +NPError +NPL_EnablePlugin(NPMIMEType type, const char *pluginName, XP_Bool enabled) +{ + np_handle* handle; + np_mimetype* mimetype; + NPTRACE(0,("np: enable plugin %s for type %s", pluginName, type)); + + if (!pluginName || !*pluginName || !type || !*type) + return(NPERR_INVALID_PARAM); + + for (handle = np_plist; handle; handle = handle->next) + { + if (!strcmp(handle->name, pluginName)) + break; + } + + if (!handle) + /* Plugin with the specified name not found */ + return(NPERR_INVALID_INSTANCE_ERROR); + + /* Look for an existing MIME type object for the specified type */ + /* We can't use np_getmimetype, because it respects enabledness and + here we don't care */ + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (strcasecomp(mimetype->type, type) == 0) + break; + } + + if (!mimetype) + /* This plugin cannot handler the specified mimetype */ + return(NPERR_INVALID_PLUGIN_ERROR); + + /* Find the plug-in that was previously enabled for this type and + disable it */ + if (enabled) + { + XP_Bool foundType = FALSE; + np_handle* temphandle; + np_mimetype* temptype; + + for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) + { + for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) + { + if (temptype->enabled && strcasecomp(temptype->type, type) == 0) + { + temptype->enabled = FALSE; + foundType = TRUE; + } + } + } + } + + mimetype->enabled = enabled; + + if (mimetype->enabled) + { + /* + * Is this plugin the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); + +#if defined(XP_WIN) || defined(XP_OS2) + /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ + if (!wildtype) + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ +#else + if (!wildtype) + { + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); +#ifdef XP_UNIX + /* The following three lines should be outside the ifdef someday */ + NET_RegisterAllEncodingConverters(type, FO_PRESENT); + NET_RegisterAllEncodingConverters(type, FO_EMBED); + NET_RegisterAllEncodingConverters(type, FO_PLUGIN); + + /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want + * plugin to possibly handle that case too. Hence this. + */ + NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, + NPL_NewPresentStream); +#endif /* XP_UNIX */ + } + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); +#endif + NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); + NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + } + + return(NPERR_NO_ERROR); +} + + +/* + * Look up the handle and mimetype objects given + * the pdesc value and the mime type string. + * Return TRUE if found successfully. + */ +void +np_findPluginType(NPMIMEType type, void* pdesc, np_handle** outHandle, np_mimetype** outMimetype) +{ + np_handle* handle; + np_mimetype* mimetype; + + *outHandle = NULL; + *outMimetype = NULL; + + /* Look for an existing handle */ + for (handle = np_plist; handle; handle = handle->next) + { + if (handle->pdesc == pdesc) + break; + } + + if (!handle) + return; + *outHandle = handle; + + /* Look for an existing MIME type object for the specified type */ + /* We can't use np_getmimetype, because it respects enabledness and here we don't care */ + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + if (strcasecomp(mimetype->type, type) == 0) + break; + } + + if (!mimetype) + return; + *outMimetype = mimetype; +} + + +void +np_enablePluginType(np_handle* handle, np_mimetype* mimetype, XP_Bool enabled) +{ + char* type = mimetype->type; + + /* + * Find the plug-in that was previously + * enabled for this type and disable it. + */ + if (enabled) + { + XP_Bool foundType = FALSE; + np_handle* temphandle; + np_mimetype* temptype; + + for (temphandle = np_plist; temphandle && !foundType; temphandle = temphandle->next) + { + for (temptype = temphandle->mimetypes; temptype && !foundType; temptype = temptype->next) + { + if (temptype->enabled && strcasecomp(temptype->type, type) == 0) + { + temptype->enabled = FALSE; + foundType = TRUE; + } + } + } + } + + mimetype->enabled = enabled; + + if (enabled) + { + /* + * Is this plugin the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); + +#ifdef XP_WIN + /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ + if (!wildtype) + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ +#else + if (!wildtype) + { + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); +#ifdef XP_UNIX + /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want + * plugin to possibly handle that case too. Hence this. + */ + NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, + NPL_NewPresentStream); +#endif /* XP_UNIX */ + } + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); +#endif + NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); + NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + } +} + + +NPError +NPL_EnablePluginType(NPMIMEType type, void* pdesc, XP_Bool enabled) +{ + np_handle* handle; + np_mimetype* mimetype; + + if (!type) + return NPERR_INVALID_PARAM; + + np_findPluginType(type, pdesc, &handle, &mimetype); + + if (!handle || !mimetype) + return NPERR_INVALID_PARAM; + + np_enablePluginType(handle, mimetype, enabled); + return NPERR_NO_ERROR; +} + + +/* XXX currently there is no unregister */ +NPError +NPL_RegisterPluginType(NPMIMEType type, const char *extensions, const char* description, + void* fileType, void *pdesc, XP_Bool enabled) +{ + np_handle* handle = NULL; + np_mimetype* mimetype = NULL; + NPTRACE(0,("np: register type %s", type)); + + np_findPluginType(type, pdesc, &handle, &mimetype); + + /* We have to find the handle to do anything */ + XP_ASSERT(handle); + if (!handle) + return NPERR_INVALID_PARAM; + + /*If no existing mime type, add a new type to this handle */ + if (!mimetype) + { + mimetype = XP_NEW_ZAP(np_mimetype); + if (!mimetype) + return NPERR_OUT_OF_MEMORY_ERROR; + mimetype->next = handle->mimetypes; + handle->mimetypes = mimetype; + mimetype->handle = handle; + StrAllocCopy(mimetype->type, type); + } + + /* Enable this plug-in for this type and disable any others */ + np_enablePluginType(handle, mimetype, enabled); + + /* Get rid of old file association info, if any */ + if (mimetype->fassoc) + { + void* fileType; + fileType = NPL_DeleteFileAssociation(mimetype->fassoc); +#if 0 + /* Any FE that needs to free this, implement FE_FreeNPFileType */ + if (fileType) + FE_FreeNPFileType(fileType); +#endif + mimetype->fassoc = NULL; + } + + /* Make a new file association and register it with netlib if enabled */ + XP_ASSERT(extensions && description); + mimetype->fassoc = NPL_NewFileAssociation(type, extensions, description, fileType); + if (mimetype->fassoc && enabled) + NPL_RegisterFileAssociation(mimetype->fassoc); + + return NPERR_NO_ERROR; +} + + +/* + * Add a NPEmbeddedApp to the list of plugins for the specified context. + * We need to append items, because the FEs depend on them appearing + * in the list in the same order in which they were created. + */ +void +np_bindContext(NPEmbeddedApp* app, MWContext* cx) +{ + np_data* ndata; + + XP_ASSERT(app && cx); + XP_ASSERT(app->next == NULL); + + if (cx->pluginList == NULL) /* no list yet, just insert item */ + cx->pluginList = app; + else /* the list has at least one item in it, append to it */ + { + NPEmbeddedApp* pItem = cx->pluginList; /* the first element */ + while(pItem->next) pItem = pItem->next; /* find the last element */ + pItem->next = app; /* append */ + } + + /* If there's an instance, set the instance's context */ + ndata = (np_data*) app->np_data; + if (ndata) + { + np_instance* instance = (np_instance*) ndata->instance; + if (instance) + instance->cx = cx; + } + +} + +void +np_unbindContext(NPEmbeddedApp* app, MWContext* cx) +{ + np_data* ndata; + + XP_ASSERT(app && cx); + + if (app == cx->pluginList) + cx->pluginList = app->next; + else + { + NPEmbeddedApp *ax; + for (ax=cx->pluginList; ax; ax=ax->next) + if (ax->next == app) + { + ax->next = ax->next->next; + break; + } + } + + app->next = NULL; + + /* If there's an instance, clear the instance's context */ + ndata = (np_data*) app->np_data; + if (ndata) + { + np_instance* instance = (np_instance*) ndata->instance; + if (instance) + instance->cx = NULL; + } +} + + +void +np_delete_instance(np_instance *instance) +{ + if(instance) + { + np_handle *handle = instance->handle; + np_stream *stream; + + /* nuke all open streams */ + for(stream=instance->streams; stream;) + { + np_stream *next = stream->next; + stream->dontclose = 0; + if (stream->nstream) + { + /* Make sure the urls doesn't still point to us */ + URL_Struct* urls = (URL_Struct*) stream->nstream->data_object; + if (urls) + urls->fe_data = NULL; + } + np_destroystream(stream, NPRES_USER_BREAK); + stream = next; + } + instance->streams = 0; + + if (handle) { + NPSavedData *save = NULL; + + TRACEMSG(("npglue.c: CallNPP_DestroyProc")); + if (np_is50StylePlugin(instance->handle)) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + + userInst->SetWindow(NULL); + + nsPluginError err = userInst->Destroy(); + XP_ASSERT(err == nsPluginError_NoError); + + nsrefcnt cnt = peerInst->Release(); + XP_ASSERT(cnt == 0); + + // XXX Any other bookkeeping we need to do here? + + // Since this is a 5.0-style (C++) plugin, we know we've + // been called from NPL_DeleteSessionData (at best), + // or other similarly terminal functions. So there is + // no chance that the plugin will be able to save any + // of its state for later... + } else if (handle->f && ISFUNCPTR(handle->f->destroy)) { + CallNPP_DestroyProc(handle->f->destroy, instance->npp, &save); + } + if (instance->app && instance->app->np_data) { + np_data* pnp = (np_data*)instance->app->np_data; + pnp->sdata = save; + } +#ifdef JAVA + /* + ** Break any association we have made between this instance and + ** its corresponding Java objTag. That way other java objects + ** still referring to it will be able to detect that the plugin + ** went away (by calling isActive). + */ + if (instance->javaInstance != NULL && + instance->javaInstance != NPN_NO_JAVA_INSTANCE) + { + /* Don't get the environment unless there is a Java instance, + because this would cause the java runtime to start up. */ + JRIEnv* env = npn_getJavaEnv(); + netscape_plugin_Plugin* javaInstance = (netscape_plugin_Plugin*) + JRI_GetGlobalRef(env, instance->javaInstance); + + /* upcall to the user's code */ + netscape_plugin_Plugin_destroy(env, javaInstance); + + set_netscape_plugin_Plugin_peer(env, javaInstance, 0); + JRI_DisposeGlobalRef(env, instance->javaInstance); + instance->javaInstance = NULL; + } +#endif /* JAVA */ + + /* If we come through here after having been unbound from + a context, then we need to make one up to call into the + front-end */ + MWContext *context = (instance->cx != NULL) + ? instance->cx : XP_FindSomeContext(); + + if (XP_OK_ASSERT(context != NULL)) { + +#ifdef XP_MAC + /* turn scrollbars back on */ + if(instance->type == NP_FULL) + FE_ShowScrollBars(context, TRUE); +#endif + + /* Tell the front end to blow away the plugin window */ + FE_DestroyEmbedWindow(context, instance->app); + } + + /* remove it from the handle list */ + if(instance == handle->instances) + handle->instances = instance->next; + else + { + np_instance *ix; + for(ix=handle->instances; ix; ix=ix->next) + if(ix->next == instance) + { + ix->next = ix->next->next; + break; + } + } + + handle->refs--; + XP_ASSERT(handle->refs>=0); + if(!handle->refs) + { + np_UnloadPluginClass(handle); + } + } + + np_removeAllURLsFromList(instance); + + if (instance->typeString) + XP_FREE(instance->typeString); + +#ifdef PLUGIN_TIMER_EVENT + if(instance->timeout) + FE_ClearTimeout(instance->timeout); +#endif + + XP_FREE(instance); + } +} + +#ifdef XP_UNIX +static NET_StreamClass * +np_noembedfound (FO_Present_Types format_out, + void *type, + URL_Struct *urls, MWContext *cx) +{ + char *msg = PR_smprintf(XP_GetString(XP_PLUGIN_NOT_FOUND), + urls->content_type); + if(msg) + { + FE_Alert(cx, msg); + XP_FREE(msg); + } + + return(NULL); +} +#endif /* XP_UNIX */ + +void +NPL_RegisterDefaultConverters() +{ + /* get netlib to deal with our content streams */ + NET_RegisterContentTypeConverter("*", FO_CACHE_AND_EMBED, NULL, NET_CacheConverter); + NET_RegisterContentTypeConverter("*", FO_CACHE_AND_PLUGIN, NULL, NET_CacheConverter); + NET_RegisterContentTypeConverter("*", FO_CACHE_AND_BYTERANGE, NULL, NET_CacheConverter); + + NET_RegisterContentTypeConverter("multipart/x-byteranges", FO_CACHE_AND_BYTERANGE, NULL, CV_MakeMultipleDocumentStream); + + NET_RegisterContentTypeConverter("*", FO_PLUGIN, NULL, np_newpluginstream); + NET_RegisterContentTypeConverter("*", FO_BYTERANGE, NULL, np_newbyterangestream); +#ifdef XP_UNIX + NET_RegisterContentTypeConverter("*", FO_EMBED, NULL, np_noembedfound); +#endif /* XP_UNIX */ +} + +/* called from netscape main */ +void +NPL_Init() +{ + +#if defined(XP_UNIX) && defined(DEBUG) + { + char *str; + str = getenv("NPD"); + if(str) + np_debug=atoi(str); + } +#endif + + /* Register all default plugin converters. Do this before + * FE_RegisterPlugins() because this registers a not found converter + * for "*" and FE can override that with the nullplugin if one is + * available. + */ + NPL_RegisterDefaultConverters(); + + /* call the platform specific FE code to enumerate and register plugins */ + FE_RegisterPlugins(); + + /* construct the function table for calls back into netscape. + no plugin sees this until its actually loaded */ + npp_funcs.size = sizeof(npp_funcs); + npp_funcs.version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; + + npp_funcs.geturl = NewNPN_GetURLProc(npn_geturl); + npp_funcs.posturl = NewNPN_PostURLProc(npn_posturl); + npp_funcs.requestread = NewNPN_RequestReadProc(npn_requestread); + npp_funcs.newstream = NewNPN_NewStreamProc(npn_newstream); + npp_funcs.write = NewNPN_WriteProc(npn_write); + npp_funcs.destroystream = NewNPN_DestroyStreamProc(npn_destroystream); + npp_funcs.status = NewNPN_StatusProc(npn_status); + npp_funcs.uagent = NewNPN_UserAgentProc(npn_useragent); + npp_funcs.memalloc = NewNPN_MemAllocProc(npn_memalloc); + npp_funcs.memfree = NewNPN_MemFreeProc(npn_memfree); + npp_funcs.memflush = NewNPN_MemFlushProc(npn_memflush); + npp_funcs.reloadplugins = NewNPN_ReloadPluginsProc(npn_reloadplugins); + npp_funcs.getJavaEnv = NewNPN_GetJavaEnvProc(npn_getJavaEnv); + npp_funcs.getJavaPeer = NewNPN_GetJavaPeerProc(npn_getJavaPeer); + npp_funcs.geturlnotify = NewNPN_GetURLNotifyProc(npn_geturlnotify); + npp_funcs.posturlnotify = NewNPN_PostURLNotifyProc(npn_posturlnotify); + npp_funcs.getvalue = NewNPN_GetValueProc(npn_getvalue); + npp_funcs.setvalue = NewNPN_SetValueProc(npn_setvalue); + npp_funcs.invalidaterect = NewNPN_InvalidateRectProc(npn_invalidaterect); + npp_funcs.invalidateregion = NewNPN_InvalidateRegionProc(npn_invalidateregion); + npp_funcs.forceredraw = NewNPN_ForceRedrawProc(npn_forceredraw); +} + + +void +NPL_Shutdown() +{ + np_handle *handle, *dh; + np_instance *instance, *di; + + for(handle=np_plist; handle;) + { + dh=handle; + handle = handle->next; + + /* delete handle */ + for(instance=dh->instances; instance;) + { + di = instance; + instance=instance->next; + np_delete_instance(di); + } + } +} + + + +/* + * Like NPL_SamePage, but for an individual element. + * It is called by laytable.c when relaying out table cells. + */ +void +NPL_SameElement(LO_EmbedStruct* embed_struct) +{ + if (embed_struct) + { + NPEmbeddedApp* app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; + if (app) + { + np_data* ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->state != NPDataSaved) + ndata->state = NPDataCache; + } + } +} + + + +/* + * This function is called by the FE's when they're resizing a page. + * We take advantage of this information to mark all our instances + * so we know not to delete them when the layout information is torn + * down so we can keep using the same instances with the new, resized, + * layout structures. + */ +void +NPL_SamePage(MWContext* resizedContext) +{ + MWContext* cx; + XP_List* children; + NPEmbeddedApp* app; + + if (!resizedContext) + return; + + /* Mark all plug-ins in this context */ + app = resizedContext->pluginList; + while (app) + { + np_data* ndata = (np_data*) app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->state != NPDataSaved) + ndata->state = NPDataCache; + app = app->next; + } + + /* Recursively traverse child contexts */ + children = resizedContext->grid_children; + while ((cx = (MWContext*)XP_ListNextObject(children)) != NULL) + NPL_SamePage(cx); +} + +int +NPL_HandleEvent(NPEmbeddedApp *app, void *event, void* window) +{ + if (app) + { + np_data *ndata = (np_data *)app->np_data; + if(ndata && ndata->instance) + { + np_handle *handle = ndata->instance->handle; + if (handle) { + TRACEMSG(("npglue.c: CallNPP_HandleEventProc")); + if (handle->userPlugin) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + + // Note that the new nsPluginEvent struct is different from the + // old NPEvent (which is the argument passed in) so we have to + // translate. (Later we might fix the front end code to pass us + // the new thing instead.) + NPEvent* oldEvent = (NPEvent*)event; + nsPluginEvent newEvent; +#if defined(XP_MAC) + newEvent.event = oldEvent; + newEvent.window = window; +#elif defined(XP_WIN) + newEvent.event = oldEvent->event; + newEvent.wParam = oldEvent->wParam; + newEvent.lParam = oldEvent->lParam; +#elif defined(XP_OS2) + newEvent.event = oldEvent->event; + newEvent.wParam = oldEvent->wParam; + newEvent.lParam = oldEvent->lParam; +#elif defined(XP_UNIX) + XP_MEMCPY(&newEvent.event, event, sizeof(XEvent)); + // we don't need window for unix -- it's already in the event +#endif + return userInst->HandleEvent(&newEvent); + } + else if (handle->f && ISFUNCPTR(handle->f->event)) { + // window is not passed through to old-style plugins + // XXX shouldn't this check for windowless plugins only? + return CallNPP_HandleEventProc(handle->f->event, ndata->instance->npp, event); + } + } + } + } + return 0; +} + +void npn_registerwindow(NPP npp, void* window) +{ +#ifdef XP_MAC + if(npp) { + np_instance* instance = (np_instance*) npp->ndata; + FE_RegisterWindow(instance->app->fe_data, window); + } +#endif +} + +void npn_unregisterwindow(NPP npp, void* window) +{ +#ifdef XP_MAC + if(npp) { + np_instance* instance = (np_instance*) npp->ndata; + FE_UnregisterWindow(instance->app->fe_data, window); + } +#endif +} + +int16 npn_allocateMenuID(NPP npp, XP_Bool isSubmenu) +{ +#ifdef XP_MAC + if (npp) { + np_instance* instance = (np_instance*) npp->ndata; + return FE_AllocateMenuID(instance->app->fe_data, isSubmenu); + } +#endif + return 0; +} + +XP_Bool +npn_IsWindowless(np_handle* handle) +{ + if (handle->userPlugin) { + // XXX anybody using the new plugin api supports windowless, right? + return TRUE; + } + else { + return handle->f->version >= NPVERS_HAS_WINDOWLESS; + } +} + +void +NPL_Print(NPEmbeddedApp *app, void *pdata) +{ + if (app) + { + np_data *ndata = (np_data *)app->np_data; + if(ndata && ndata->instance) + { + np_handle *handle = ndata->instance->handle; + if(handle) + { + NPPrint * nppr = (NPPrint *)pdata; + if (nppr && (nppr->mode == NP_EMBED) && !npn_IsWindowless(handle)) + { + /* + If old (pre-4.0) plugin version, have to the "platformPrint" void * up, + because window.type didn't previously exist. + + check plugin version: + Major,Minor version = 0,11 or greater => 4.0, + else < 4.0 + */ + + NPWindowType old_type = nppr->print.embedPrint.window.type; + void * addr1 = (void *)&nppr->print.embedPrint.window.type; + + void * old_plat_print = nppr->print.embedPrint.platformPrint; + void * addr2 = (void *)&nppr->print.embedPrint.platformPrint; + + XP_MEMCPY(addr1,addr2,sizeof(nppr->print.embedPrint.platformPrint)); + + TRACEMSG(("npglue.c: CallNPP_PrintProc(1)")); + if (handle->userPlugin) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + userInst->Print((nsPluginPrint*)pdata); + + + } + else if (handle->f && ISFUNCPTR(handle->f->print)) { + CallNPP_PrintProc(handle->f->print, ndata->instance->npp, (NPPrint*)pdata); + } + + /* Now restore for downstream dependencies */ + nppr->print.embedPrint.window.type = old_type; + nppr->print.embedPrint.platformPrint = old_plat_print; + + } + else{ + TRACEMSG(("npglue.c: CallNPP_PrintProc(2)")); + if (handle->userPlugin) { + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*)ndata->instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + userInst->Print((nsPluginPrint*)pdata); + } + else if (handle->f && ISFUNCPTR(handle->f->print)) { + CallNPP_PrintProc(handle->f->print, ndata->instance->npp, (NPPrint*)pdata); + } + } + + } + } + } +} + +void +np_deleteapp(MWContext* cx, NPEmbeddedApp* app) +{ + if (app) + { + if (cx) + np_unbindContext(app, cx); + + XP_FREE(app); + } +} + +/* + * This is called by the front-end via layout when the plug-in's + * context is going away. Based on what kind of plugin this is, what + * the context looks like, etc., we decided whether to destroy the + * plug-in's window or to make the front-end store it somewhere safe + * for us. + */ +extern void +NPL_EmbedDelete(MWContext* cx, LO_EmbedStruct* embed_struct) +{ + NPEmbeddedApp* app; + np_data* ndata; + + if (!cx || !embed_struct || !embed_struct->objTag.FE_Data) + return; + + app = (NPEmbeddedApp*) embed_struct->objTag.FE_Data; + embed_struct->objTag.FE_Data = NULL; + + ndata = (np_data*) app->np_data; + + if (ndata) + { + embed_struct->objTag.session_data = (void*) ndata; + + ndata->refs--; + + /* -1 case is added. It happens when this is fake object */ + // XXX I think that "fake objects" should no longer be + // required now that we actually have a front-end callback to + // destroy the window. + XP_ASSERT(/* ndata->refs == -1 || */ ndata->refs == 0 || ndata->refs == 1); + + if (ndata->refs > 0) { + /* When done printing, don't delete and don't save session data */ + XP_ASSERT(cx->type == MWContextPrint || cx->type == MWContextMetaFile || + cx->type == MWContextPostScript); + ndata->state = NPDataCached; + + /* Tell the front-end to save the embedded window for us */ + FE_SaveEmbedWindow(cx, app); + return; + } + else if (ndata->state == NPDataCache) + { + /* Someone is telling us to cache the window; e.g., during + a nasty resize */ + XP_ASSERT(ndata->app); + ndata->state = NPDataCached; + ndata->lo_struct = NULL; /* Remove ref to layout structure since it's about to be deleted */ + np_unbindContext(app, cx); /* Remove ref to context since it may change */ + + /* Tell the front-end to save the embedded window for us */ + FE_SaveEmbedWindow(cx, app); + return; + } + else if (ndata->instance) + { + /* Otherwise, the context is just plain and simple getting + blown away */ + XP_ASSERT(ndata->instance->handle != NULL); + if (ndata->instance->handle->userPlugin) { + /* This is a 5.0-style (C++) plugin. We'll simply stop the plugin. */ + + /* XXX We could just get the _real_ instance by + traversing ndata->sdata, but that scares me for + some reason. */ + nsPluginInstancePeer* peerInst = (nsPluginInstancePeer*) ndata->instance->npp->pdata; + nsIPluginInstance* userInst = peerInst->GetUserInstance(); + + nsPluginError err = userInst->Stop(); + if (err == nsPluginError_NoError) { + /* XXX So I'm going out on a limb here and saying that + by keeping the plugin in a "cached" state, we + should pretty much not need to perturb much + else... */ + ndata->state = NPDataCached; + ndata->lo_struct = NULL; + np_unbindContext(app, cx); + + /* Tell the front-end to save the embedded window for us */ + FE_SaveEmbedWindow(cx, app); + return; + } + else { + // the plugin failed to stop properly + // XXX is the following right?... + np_delete_instance(ndata->instance); + embed_struct->objTag.session_data = NULL; + app->np_data = NULL; + XP_FREE(ndata); + } + } else { + /* It's a normal old-fashioned plugin. Destroy the instance */ + np_delete_instance(ndata->instance); + + ndata->app = NULL; + ndata->instance = NULL; + ndata->lo_struct = NULL; + ndata->streamStarted = FALSE; + ndata->state = NPDataSaved; /* ndata gets freed later when history goes away */ + } + } + else + { + /* If there's no instance, there's no need to save session data */ + embed_struct->objTag.session_data = NULL; + app->np_data = NULL; + XP_FREE(ndata); + } + } + + /* XXX This is pretty convoluted how this just all falls through + to here. Clean it up sometime... */ + np_deleteapp(cx, app); /* unlink app from context and delete app */ +} + + + +/* + * Get all the embeds in this context to save themselves in the + * designated saved data list so we can reuse them when printing. + * (Except hidden ones!) + */ +void +NPL_PreparePrint(MWContext* context, SHIST_SavedData* savedData) +{ + NPEmbeddedApp* app; + + XP_ASSERT(context && savedData); + if (!context || !savedData) + return; + + for (app = context->pluginList; app != NULL; app = app->next) + { + np_data* ndata = (np_data*)app->np_data; + XP_ASSERT(ndata); + if (ndata && ndata->lo_struct) + { + /* ignore this assert if the plugin is hidden */ + XP_ASSERT(ndata->state == NPDataNormal); + ndata->state = NPDataCached; + LO_AddEmbedData(context, ndata->lo_struct, ndata); + } + } + + LO_CopySavedEmbedData(context, savedData); +} + + + +/* + * This function should be moved to layembed.c so the TYPE + * attribute is pulled out the same way as the SRC attribute. + */ +static char* +np_findTypeAttribute(LO_EmbedStruct* embed_struct) +{ + char* typeAttribute = NULL; + unsigned int i; + + /* Look for the TYPE attribute */ +#ifdef OJI + for (i = 0; i < embed_struct->attributes.n; i++) + { + if (XP_STRCASECMP(embed_struct->attributes.names[i], "TYPE") == 0) + { + typeAttribute = embed_struct->attributes.values[i]; + break; + } + } +#else + for (i = 0; i < embed_struct->attribute_cnt; i++) + { + if (XP_STRCASECMP(embed_struct->attribute_list[i], "TYPE") == 0) + { + typeAttribute = embed_struct->value_list[i]; + break; + } + } +#endif + + return typeAttribute; +} + +void +np_FindHandleByType(const char* typeAttribute, np_handle* *resultingHandle, + np_mimetype* *resultingMimetype) +{ + np_handle* handle = NULL; + np_mimetype* mimetype = NULL; + + for (handle = np_plist; handle; handle = handle->next) { + mimetype = np_getmimetype(handle, typeAttribute, FALSE); + if (mimetype) break; + } + + /* No handler with an exactly-matching name, so check for a wildcard */ + if (!mimetype) + { + for (handle = np_plist; handle; handle = handle->next) { + mimetype = np_getmimetype(handle, typeAttribute, TRUE); + if (mimetype) break; + } + } + + *resultingHandle = handle; + *resultingMimetype = mimetype; +} + +// Used by OJI to load the Java VM plugin +PR_IMPLEMENT(struct nsIPlugin*) +NPL_LoadPluginByType(const char* typeAttribute) +{ + np_handle* handle = NULL; + np_mimetype* mimetype = NULL; + np_FindHandleByType(typeAttribute, &handle, &mimetype); + if (mimetype == NULL) + return NULL; + PR_ASSERT(handle); + + PRBool loaded = PR_FALSE; + if (handle->refs == 0) { +// FE_Progress(cx, XP_GetString(XP_PLUGIN_LOADING_PLUGIN)); + if (!(handle->f = FE_LoadPlugin(handle->pdesc, &npp_funcs, handle))) + { +// char* msg = PR_smprintf(XP_GetString(XP_PLUGIN_CANT_LOAD_PLUGIN), handle->name, mimetype->type); +// FE_Alert(cx, msg); +// XP_FREE(msg); + return NULL; + } + loaded = PR_TRUE; + + // Give the handle a ref so we know not to load it again. + // XXX How do we ever _unload_ it once this routine + // has been called??? + handle->refs = 1; +#ifdef JAVA + /* + ** Don't use npn_getJavaEnv here. We don't want to start the + ** interpreter, just use env if it already exists. + */ + JRIEnv* env = JRI_GetCurrentEnv(); + + /* + ** An exception could have occurred when the plugin tried to load + ** it's class file. We'll print any exception to the console. + */ + if (env && JRI_ExceptionOccurred(env)) { + JRI_ExceptionDescribe(env); + JRI_ExceptionClear(env); + } +#endif + } + if (handle->userPlugin) { + // refcount was incremented + return handle->userPlugin; + } + else { + // old style plugin -- we failed so unload it + if (loaded) + FE_UnloadPlugin(handle->pdesc, handle); + return NULL; + } +} + +extern "C" +{ +// Used by layout code to translate between a np_instance and a +// OJI plugin instance. +PR_IMPLEMENT(struct nsIPluginInstance*) +NPL_GetOJIPluginInstance(NPEmbeddedApp *embed) +{ + struct nsIPluginInstance *psNPIT = NULL; + np_data *ndata = (np_data*) embed->np_data; + np_instance *instance = ndata->instance; + if (instance) + { + nsIPluginInstancePeer *pNPIP = (nsIPluginInstancePeer *)instance->npp->pdata; + nsIPluginInstance *pNPI = ((nsPluginInstancePeer *)pNPIP)->GetUserInstance(); + psNPIT = (struct nsIPluginInstance*)pNPI; + } + return (psNPIT); +} + + +// Used by layout code to get to a text representing a java bean. +PR_IMPLEMENT(const char *) +NPL_GetText(struct nsIPluginInstance *psNPIT) +{ + nsIPluginInstance *pNPIT = (nsIPluginInstance *)psNPIT; + const char *text = NULL; + + nsIJVMPluginInstance *pJVMPIT = NULL; + NS_DEFINE_IID(kJvmPluginInstanceIID, NS_IJVMPLUGININSTANCE_IID); + if (pNPIT->QueryInterface(kJvmPluginInstanceIID, + (void**)&pJVMPIT) == NS_OK) { + + text = pJVMPIT->GetText(); + pJVMPIT->Release(); + } + return text; +} + +PR_IMPLEMENT(jobject) +NPL_GetJavaObject(struct nsIPluginInstance *psNPIT) +{ + nsIPluginInstance *pNPIT = (nsIPluginInstance *)psNPIT; + jobject javaobject = NULL; + + nsIJVMPluginInstance *pJVMPIT = NULL; + NS_DEFINE_IID(kJvmPluginInstanceIID, NS_IJVMPLUGININSTANCE_IID); + if (pNPIT->QueryInterface(kJvmPluginInstanceIID, + (void**)&pJVMPIT) == NS_OK) { + + javaobject = pJVMPIT->GetJavaObject(); + pJVMPIT->Release(); + } + return javaobject; +} + +PR_IMPLEMENT(void) NPL_Release(struct nsISupports *psnsISup) +{ + nsISupports *pnsISup = (nsISupports *)psnsISup; + pnsISup->Release(); +} + +PR_IMPLEMENT(XP_Bool) NPL_IsJVMAndMochaPrefsEnabled(void) +{ + XP_Bool bPrefs = PR_FALSE; + nsJVMMgr *pJVMMgr = JVM_GetJVMMgr(); + + if (pJVMMgr != NULL) { + if (pJVMMgr->IsJVMAndMochaPrefsEnabled() == PR_TRUE) { + bPrefs = PR_TRUE; + } + pJVMMgr->Release(); + } + + return bPrefs; +} + +PR_IMPLEMENT(void)NPL_JSJInit(void) +{ + nsJVMMgr* pJVMMgr = JVM_GetJVMMgr(); + if (pJVMMgr != NULL) { + pJVMMgr->JSJInit(); + pJVMMgr->Release(); + } +} + +PR_IMPLEMENT(JNIEnv *)NPL_EnsureJNIExecEnv(PRThread* thread) +{ + return npn_getJavaEnv(thread); +} + + +} /* extern "C" */ + + +/* + * This is called by the front-end to create a new plug-in. It will + * fill in the FE_Data member of the embed_struct with a pointer to + * the NPEmbeddedApp that gets created. + */ +NPEmbeddedApp* +NPL_EmbedCreate(MWContext* cx, LO_EmbedStruct* embed_struct) +{ + NPEmbeddedApp* app = NULL; + np_data* ndata = NULL; + + XP_ASSERT(cx && embed_struct); + if (!cx || !embed_struct) + goto error; + + /* + * Check the contents of the session data. If we have a cached + * app in the session data, we can short-circuit this function + * and just return the app we cached earlier. If we have saved + * data in the session data, keep that np_data object but + * attach it to a new app. If there is nothing in the session + * data, then we must create both a np_data object and an app. + */ + if (embed_struct->objTag.session_data) + { + ndata = (np_data*) embed_struct->objTag.session_data; + embed_struct->objTag.session_data = NULL; + + if (ndata->state == NPDataCached) /* We cached this app, so don't create another */ + { + XP_ASSERT(ndata->app); + if (cx->type == MWContextPrint || + cx->type == MWContextMetaFile || + cx->type == MWContextPostScript) + { + /* This is a printing "instance" that we're restoring + from the session data */ + if (ndata->app->pagePluginType == NP_FullPage) + { + np_reconnect* reconnect; + if (!cx->pluginReconnect) + cx->pluginReconnect = XP_NEW_ZAP(np_reconnect); + reconnect = (np_reconnect*) cx->pluginReconnect; + if (reconnect) + reconnect->app = ndata->app; + } + +#ifdef LAYERS + if ((cx->compositor) && ndata->instance) { + LO_SetEmbedType(embed_struct, (PRBool)ndata->instance->windowed); + } +#endif /* LAYERS */ + } + else + { + /* It's a real instance that we're restoring from the + session data */ + ndata->lo_struct = embed_struct; /* Set reference to new layout structure */ + np_bindContext(ndata->app, cx); /* Set reference to (potentially) new context */ + ndata->state = NPDataNormal; +#ifdef LAYERS + if (ndata->instance) { + ndata->instance->layer = embed_struct->objTag.layer; + LO_SetEmbedType(ndata->lo_struct, + (PRBool)ndata->instance->windowed); + } +#endif /* LAYERS */ + } + + /* + * For full-page/frame plug-ins, make sure scroll + * bars are off in the (potentially) new context. + */ + if (ndata->app->pagePluginType == NP_FullPage) + FE_ShowScrollBars(cx, FALSE); + + /* + * Increment the refcount since this app is now in use. + * Currently the most refs we can have will be 2, if + * this app is being displayed in one context and + * printed in another. + */ + ndata->refs++; + XP_ASSERT(ndata->refs == 1 || ndata->refs == 2); + + /* Make the front-end restore the embedded window from + it's saved context. */ + if (! (embed_struct->objTag.ele_attrmask & LO_ELE_HIDDEN)) + FE_RestoreEmbedWindow(cx, ndata->app); + + /* Tie the app to the layout struct. */ + embed_struct->objTag.FE_Data = ndata->app; + return ndata->app; + } + + /* If not cached, it's just saved data. (XXX NPL_StartPlugin + will take care of re-constituting it?) */ + XP_ASSERT(ndata->state == NPDataSaved); + XP_ASSERT(ndata->app == NULL); + XP_ASSERT(ndata->instance == NULL); + XP_ASSERT(ndata->lo_struct == NULL); + XP_ASSERT(ndata->streamStarted == FALSE); + XP_ASSERT(ndata->refs == 0); + } + + /* So now we either have a "saved" pre-5.0 style plugin, or a + brand new plugin. */ + if (!ndata) + { + ndata = XP_NEW_ZAP(np_data); + if (!ndata) + goto error; + } + ndata->state = NPDataNormal; + ndata->lo_struct = embed_struct; + + /* + * Create the NPEmbeddedApp and attach it to its context. + */ + app = XP_NEW_ZAP(NPEmbeddedApp); + if (!app) + goto error; + app->np_data = (void*) ndata; + app->type = NP_Untyped; + ndata->refs = 1; + ndata->app = app; + np_bindContext(app, cx); + + /* Tell the front-end to create the plugin window for us. */ + if (! (embed_struct->objTag.ele_attrmask & LO_ELE_HIDDEN)) + FE_CreateEmbedWindow(cx, app); + + /* Attach the app to the layout info */ + embed_struct->objTag.FE_Data = ndata->app; + return app; + +error: + if (app) + np_deleteapp(cx, app); /* Unlink app from context and delete app */ + if (ndata) + XP_FREE(ndata); + return NULL; +} + + +NPError +NPL_EmbedStart(MWContext* cx, LO_EmbedStruct* embed_struct, NPEmbeddedApp* app) +{ + np_handle* handle; + np_mimetype* mimetype; + char* typeAttribute; + np_data* ndata = NULL; + + if (!cx || !embed_struct || !app) + goto error; + + ndata = (np_data*) app->np_data; + if (!ndata) + goto error; + + /* + * Don't do all the work in this function multiple times for the + * same NPEmbeddedApp. For example, we could be reusing this + * app in a new context (when resizing or printing) or just re- + * creating the app multiple times (when laying out complex tables), + * so we don't want to be creating another stream, etc. each + * time. + */ + if (ndata->streamStarted) + return NPERR_NO_ERROR; + ndata->streamStarted = TRUE; /* Remember that we've been here */ + + /* + * First check for a TYPE attribute. The type specified + * will override the MIME type of the SRC (if present). + */ + typeAttribute = np_findTypeAttribute(embed_struct); + if (typeAttribute) + { + /* Only embedded plug-ins can have a TYPE attribute */ + app->pagePluginType = NP_Embedded; + + /* Found the TYPE attribute, so look for a matching handler */ + np_FindHandleByType(typeAttribute, &handle, &mimetype); + + /* + * If we found a handler, now we can create an instance. + * If we didn't find a handler, we have to use the SRC + * to determine the MIME type later (so there better be + * SRC, or it's an error). + */ + if (mimetype) + { + ndata->instance = np_newinstance(handle, cx, app, mimetype, typeAttribute); + if (ndata->instance == NULL) + goto error; + +#ifdef LAYERS + LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); +#endif + } + } + + /* + * Now check for the SRC attribute. + * - If it's full-page, create a instance now since we already + * know the MIME type (NPL_NewStream has already happened). + * - If it's embedded, create a stream for the URL (we'll create + * the instance when we get the stream in NPL_NewStream). + */ + if (embed_struct->embed_src) + { + char* theURL; + PA_LOCK(theURL, char*, embed_struct->embed_src); + XP_ASSERT(theURL); + if (XP_STRCMP(theURL, "internal-external-plugin") == 0) + { + /* + * Full-page case: Stream already exists, so now + * we can create the instance. + */ + np_reconnect* reconnect; + np_mimetype* mimetype; + np_handle* handle; + np_instance* instance; + char* requestedtype; + + app->pagePluginType = NP_FullPage; + + reconnect = (np_reconnect*) cx->pluginReconnect; + XP_ASSERT(reconnect); + if (!reconnect) + { + PA_UNLOCK(embed_struct->embed_src); + goto error; + } + + mimetype = reconnect->mimetype; + requestedtype = reconnect->requestedtype; + handle = mimetype->handle; + + /* Now we can create the instance */ + XP_ASSERT(ndata->instance == NULL); + instance = np_newinstance(handle, cx, app, mimetype, requestedtype); + if (!instance) + { + PA_UNLOCK(embed_struct->embed_src); + goto error; + } + + reconnect->app = app; + ndata->instance = instance; + ndata->handle = handle; + ndata->instance->app = app; + FE_ShowScrollBars(cx, FALSE); +#ifdef LAYERS + LO_SetEmbedType(ndata->lo_struct, (PRBool) ndata->instance->windowed); +#endif + } + else + { + /* + * Embedded case: Stream doesn't exist yet, so + * we need to create it before we can make the + * instance (exception: if there was a TYPE tag, + * we already know the MIME type so the instance + * already exists). + */ + app->pagePluginType = NP_Embedded; + + if ((embed_struct->objTag.ele_attrmask & LO_ELE_STREAM_STARTED) == 0) + { + URL_Struct* pURL; + pURL = NET_CreateURLStruct(theURL, NET_DONT_RELOAD); + pURL->fe_data = (void*) app; + + /* start a stream */ + (void) NET_GetURL(pURL, FO_CACHE_AND_EMBED, cx, NPL_EmbedURLExit); + } + } + + PA_UNLOCK(embed_struct->embed_src); + } + + return NPERR_NO_ERROR; + +error: + if (cx && app) + np_deleteapp(cx, app); /* Unlink app from context and delete app */ + if (ndata) + XP_FREE(ndata); + return NPERR_GENERIC_ERROR; +} + + +/* + * Called by the front-end via layout whenever layout information changes, + * including size, visibility status, etc. + */ +void +NPL_EmbedSize(NPEmbeddedApp *app) +{ + if (app) { + np_data *ndata = (np_data *)app->np_data; + if (ndata && ndata->instance && app->wdata) { + PRBool success = np_setwindow(ndata->instance, app->wdata); + if (!success) return; // XXX deal with the error + } + } +} + +/* the following is used in CGenericDoc::FreeEmbedElement */ +int32 +NPL_GetEmbedReferenceCount(NPEmbeddedApp *app) +{ + np_data *ndata = (np_data *)app->np_data; + int32 iRet = ndata->refs; + return iRet; +} + +XP_Bool +NPL_IsEmbedWindowed(NPEmbeddedApp *app) +{ + if(app) + { + np_data *ndata = (np_data *)app->np_data; + if (ndata && ndata->instance) + return ndata->instance->windowed; + else + return FALSE; + } + else + return FALSE; +} + + +/* + * This is called by layout when the context in which the embedded + * object lives is finally decimated. We need to decide: + * + * 1. Exactly what kind of context is getting destroyed (e.g., we + * could care less if it's a printing context, because it was a + * "dummy" context, anyway). + * + * 2. whether or not we have left an embedded window lying around in + * the front-end somewhere. + */ +void +NPL_DeleteSessionData(MWContext* context, void* sdata) +{ + XP_Bool bFreeSessionData = TRUE; + np_data* ndata = (np_data*) sdata; + + /* + * Printing Case + * + * Don't delete the data if we're printing, since + * data really belongs to the original context (a + * MWContextBrowser). A more generic way to make + * this check might be 'if (context != ndata-> + * instance->cx)'. + */ + // XXX Ugh. Now the front-end thinks we've freed our session data, but + // in reality we just leaked some memory and maybe a widget or two... + if (ndata == NULL || + context->type == MWContextPrint || + context->type == MWContextMetaFile || + context->type == MWContextPostScript) + return; + + + if (ndata->state == NPDataCached) { + if (ndata->instance != NULL && np_is50StylePlugin(ndata->instance->handle)) { + /* + * 5.0-style (C++) plugin case + * + * Since 5.0-style plugins aren't deleted and unloaded as + * soon as the current context goes away, they lie around + * in the history for a while with the data state as + * NPDataCached. In this case, we've been called back to + * let us know that it's time to clean up our act. + */ + + np_delete_instance(ndata->instance); + return; + } + + /* + * Resize case + * + * This case happens when we resize a page but must + * delete the session history of the old page before + * creating the new (resized) one. Typically this + * happens because the resized page isn't in the cache; + * thus we must retrieve the document from the net and + * can't use its session data because we don't know if + * the document has changed or not. In this case, + * NPL_EmbedDelete was already called for the instances + * of the original document, but we didn't delete the + * instances because we were expecting to re-use them + * in the resized document. Since the session data is + * going away, we won't have that opportunity, so we + * must delete them here, or else the instances will be + * left dangling, which is really bad. + */ + + /* Shouldn't have instance data when resizing */ + XP_ASSERT(ndata->sdata == NULL); + XP_ASSERT(ndata->app != NULL); + + /* + * Fall through to saved instance case so ndata and + * plug-in's saved data and will be deleted. + */ + } + + + /* ndata could be already freed by this point in NPL_EmbedDelete call + * so check session_data which is zeroed in this case + */ + if(bFreeSessionData) + { + /* + * Saved instance data case + * + * This case occurs when session history is deleted for + * a document that previously contained a plug-in. + * The plug-in may have given us a NPSavedData structure + * to store for it, which we must delete here. + */ + XP_ASSERT(ndata->state == NPDataSaved); + XP_ASSERT(ndata->app == NULL); + XP_ASSERT(ndata->streamStarted == FALSE); + + // XXX I don't think we should ever get here with a + // 5.0-style (C++) plugin since, by default, they cache + // themselves. Throw in an assert just to make sure... + XP_ASSERT(ndata->instance == NULL || !np_is50StylePlugin(ndata->instance->handle)); + + if (ndata->sdata) { + if (ndata->sdata->buf) + XP_FREE(ndata->sdata->buf); + XP_FREE(ndata->sdata); + ndata->sdata = 0; + } + + ndata->handle = NULL; + XP_FREE(ndata); + } + + // XXX Err...what's the point? + ndata = NULL; +} + + +NPBool +NPL_IteratePluginFiles(NPReference* ref, char** name, char** filename, char** description) +{ + np_handle* handle; + + if (*ref == NPRefFromStart) + handle = np_plist; + else + handle = ((np_handle*) *ref)->next; + + if (handle) + { + if (name) + *name = handle->name; + if (filename) + *filename = handle->filename; + if (description) + *description = handle->description; + } + + *ref = handle; + return (handle != NULL); +} + + +NPBool +NPL_IteratePluginTypes(NPReference* ref, NPReference plugin, NPMIMEType* type, char*** extents, + char** description, void** fileType) +{ + np_handle* handle = (np_handle*) plugin; + np_mimetype* mimetype; + + if (*ref == NPRefFromStart) + mimetype = handle->mimetypes; + else + mimetype = ((np_mimetype*) *ref)->next; + + if (mimetype) + { + if (type) + *type = mimetype->type; + if (description) + *description = mimetype->fassoc->description; + if (extents) + *extents = mimetype->fassoc->extentlist; + if (fileType) + *fileType = mimetype->fassoc->fileType; + } + + *ref = mimetype; + return (mimetype != NULL); + +} + + + + +/* + * Returns a null-terminated array of plug-in names that support the specified MIME type. + * This function is called by the FEs to implement their MIME handler controls (they need + * to know which plug-ins can handle a particular type to build their popup menu). + * The caller is responsible for deleting the strings and the array itself. + */ +char** +NPL_FindPluginsForType(const char* typeToFind) +{ + char** result; + uint32 count = 0; + + /* First count plug-ins that support this type */ + { + NPReference plugin = NPRefFromStart; + while (NPL_IteratePluginFiles(&plugin, NULL, NULL, NULL)) + { + char* type; + NPReference mimetype = NPRefFromStart; + while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) + { + if (strcmp(type, typeToFind) == 0) + count++; + } + } + } + + /* Bail if no plug-ins match this type */ + if (count == 0) + return NULL; + + /* Make an array big enough to hold the plug-ins */ + result = (char**) XP_ALLOC((count + 1) * sizeof(char*)); + if (!result) + return NULL; + + /* Look for plug-ins that support this type and put them in the array */ + count = 0; + { + char* name; + NPReference plugin = NPRefFromStart; + while (NPL_IteratePluginFiles(&plugin, &name, NULL, NULL)) + { + char* type; + NPReference mimetype = NPRefFromStart; + while (NPL_IteratePluginTypes(&mimetype, plugin, &type, NULL, NULL, NULL)) + { + if (strcmp(type, typeToFind) == 0) + result[count++] = XP_STRDUP(name); + } + } + } + + /* Null-terminate the array and return it */ + result[count] = NULL; + return result; +} + + +/* + * Returns the name of the plug-in enabled for the + * specified type, of NULL if no plug-in is enabled. + * The caller is responsible for deleting the string. + */ +char* +NPL_FindPluginEnabledForType(const char* typeToFind) +{ + np_handle* handle = np_plist; + while (handle) + { + np_mimetype* mimetype = handle->mimetypes; + while (mimetype) + { + if ((strcmp(mimetype->type, typeToFind) == 0) && mimetype->enabled) + return XP_STRDUP(handle->name); + mimetype = mimetype->next; + } + + handle = handle->next; + } + + return NULL; +} + + + +#if !defined(XP_MAC) && !defined(XP_UNIX) /* plugins change */ + +/* put_block modifies input buffer. We cannot pass static data to it. + * And hence the strdup. + */ +#define PUT(string) if(string) { \ + char *s = XP_STRDUP(string); \ + int ret; \ + ret = (*stream->put_block)(stream,s, XP_STRLEN(s)); \ + XP_FREE(s); \ + if (ret < 0) \ + return; \ +} + +void +NPL_DisplayPluginsAsHTML(FO_Present_Types format_out, URL_Struct *urls, MWContext *cx) +{ + NET_StreamClass * stream; + np_handle *handle; + + StrAllocCopy(urls->content_type, TEXT_HTML); + format_out = CLEAR_CACHE_BIT(format_out); + + stream = NET_StreamBuilder(format_out, urls, cx); + if (!stream) + return; + + if (np_plist) + { + PUT("Installed plug-ins
"); + } + else + { + PUT("No plug-ins are installed.
"); + } + + PUT("For more information on plug-ins, click here.


"); + + for (handle = np_plist; handle; handle = handle->next) + { + np_mimetype* mimetype; + + PUT(""); + PUT(handle->name); + PUT("
"); + + PUT("File name: "); + PUT(handle->filename); + PUT("
"); + + PUT("MIME types:
"); + PUT("
    "); + for (mimetype = handle->mimetypes; mimetype; mimetype = mimetype->next) + { + int index = 0; + char** extents = mimetype->fassoc->extentlist; + + PUT("Type: "); + PUT(mimetype->type); + if (!mimetype->enabled) + PUT(" (disabled)"); + PUT("
    "); + + PUT("File extensions: "); + while (extents[index]) + { + PUT(extents[index]); + index++; + if (extents[index]) + PUT(", "); + } + PUT("
    "); + } + PUT("
"); + + PUT("

"); + PUT("


"); + } + + (*stream->complete)(stream); +} + +#endif + +/* ANTHRAX PUBLIC FUNCTIONS */ + +/* + NPL_FindAppletEnabledForMimetype() + ---------------------------------- + Returns the name of the applet associated AND enabled for the particular mimetype. + Returns NULL if no applet has been set to handle this mimetype. This does not mean + that no Applets have been _installed_ for this mimetype - just that none are enabled. + + mimetype : should be of the form "audio/basic", ect. + + NOTE: Caller must free returned string. + + 11.15.97 +*/ + +#ifdef ANTHRAX +char* NPL_FindAppletEnabledForMimetype(const char* mimetype) +{ + char* prefName; + char* temp; + char* applet; + uint32 len; + int32 loadAction; + + prefName = np_CreateMimePref(mimetype, "applet"); + + if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) + { + /* also check the load action on Mac - this may be XP in the future */ + XP_FREE(prefName); + prefName = np_CreateMimePref(mimetype, "load_action"); + if(PREF_GetIntPref(prefName, &loadAction) == PREF_OK) + if(loadAction == 5) + { + XP_FREE(prefName); + return applet; + } + } + + XP_FREE(prefName); + return NULL; + +} + +/* + NPL_FindAppletsForType() + ------------------------ + Returns an array of strings specifying the installed Applets for a particular + mimetype. + + mimetype : should be of the form "audio/basic", ect. + + NOTE: Caller must free returned array and strings. + + 11.10.97 +*/ + +char** +NPL_FindAppletsForType(const char* mimetype) +{ + char** result; + char* appletName; + int32 numApplets; + int32 i; + + numApplets = np_GetNumberOfInstalledApplets(mimetype); + if(numApplets == 0) + return NULL; + + result = (char**) XP_ALLOC(numApplets * sizeof(char*)); + if (!result) + return NULL; + + for(i=1; i<=numApplets; i++) + { + if((appletName = np_FindAppletNForMimeType(mimetype, (char)i)) == NULL) + return NULL; + result[i-1] = appletName; + } + result[i-1] = NULL; + + return result; +} + +/* + NPL_RegisterAppletType() + ------------------------ + Lets NetLib know that a particular mimetype should be handled by an Applet. + + 11.10.97 +*/ + +NPError +NPL_RegisterAppletType(NPMIMEType type) +{ + /* + * Is this Applet the wildcard (a.k.a. null) plugin? + * If so, we don't want to register it for FO_PRESENT + * or it will interfere with our normal unknown-mime- + * type handling. + */ + XP_Bool wildtype = (strcmp(type, "*") == 0); + np_handle* handle = NULL; + + for(handle = np_alist; handle != NULL; handle = handle->next) + { + if(!XP_STRCMP(handle->name, type)) + break; + } + + if(handle == NULL) + { + handle = XP_NEW_ZAP(np_handle); + if (!handle) + return NPERR_OUT_OF_MEMORY_ERROR; + + StrAllocCopy(handle->name, type); + + handle->pdesc = NULL; + handle->next = np_alist; + np_alist = handle; + } + +#ifdef XP_WIN + /* EmbedStream does some Windows FE work and then calls NPL_NewStream */ + if (!wildtype) + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, EmbedStream); + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, EmbedStream); /* XXX I dont think this does anything useful */ +#else + if (!wildtype) + { + NET_RegisterContentTypeConverter(type, FO_PRESENT, handle, NPL_NewPresentStream); +#ifdef XP_UNIX + /* While printing we use the FO_SAVE_AS_POSTSCRIPT format type. We want + * plugin to possibly handle that case too. Hence this. + */ + NET_RegisterContentTypeConverter(type, FO_SAVE_AS_POSTSCRIPT, handle, + NPL_NewPresentStream); +#endif /* XP_UNIX */ + } + NET_RegisterContentTypeConverter(type, FO_EMBED, handle, NPL_NewEmbedStream); +#endif + NET_RegisterContentTypeConverter(type, FO_PLUGIN, handle, np_newpluginstream); + NET_RegisterContentTypeConverter(type, FO_BYTERANGE, handle, np_newbyterangestream); + + return NPERR_NO_ERROR; +} + +/* ANTHRAX STATIC FUNCTIONS */ + +/* + np_FindAppletNForMimeType() + --------------------------- + Returns a string to the Nth installed applet as specified by index. + Returns NULL if no applet is installed for that type. + + mimetype : should be of the form "audio/basic", ect. + + NOTE: Caller must free returned string. +*/ + +static char* np_FindAppletNForMimeType(const char* mimetype, char index) +{ + char* prefName; + char pref[] = { 'a', 'p', 'p', 'l', 'e', 't', '1', '\0'}; + char* applet; + uint32 len; + + pref[6] = (index+48); + prefName = np_CreateMimePref(mimetype, pref); + + if(PREF_CopyCharPref(prefName, &applet) == PREF_OK) + { + XP_FREE(prefName); + return applet; + } + else + { + XP_FREE(prefName); + return NULL; + } +} + +/* + np_GetNumberOfInstalledApplets() + -------------------------------- + Returns the number of Applets that have been installed for a particular + mimetype. + + mimetype : should be of the form "audio/basic", ect. +*/ + +static int32 np_GetNumberOfInstalledApplets(const char* mimetype) +{ + char* prefName; + char* temp; + uint32 len; + int32 numApplets; + + numApplets = 0; + + prefName = np_CreateMimePref(mimetype, "num_applets"); + + PREF_GetIntPref(prefName, &numApplets); + + XP_FREE(prefName); + return numApplets; +} + +/* + np_CreateMimePref() + ------------------- + Returns a string formatted in the following way: + + "mime.." + + All '/' and '-' characters in and are converted to '_' + + Returns NULL if there's a faliure on the allocation of memory. + + 12.8.97 +*/ + +static char* np_CreateMimePref(const char* mimetype, const char* pref) +{ + uint32 len; + char* prefName; + + len = XP_STRLEN("mime..") + XP_STRLEN(mimetype) + XP_STRLEN(pref); + + prefName = XP_ALLOC((len+1)*sizeof(char)); + XP_ASSERT(prefName); + if(!prefName) + return NULL; + + prefName[0] = 0; + + XP_STRCAT(prefName, "mime."); + XP_STRCAT(prefName, mimetype); + XP_STRCAT(prefName, "."); + XP_STRCAT(prefName, pref); + + np_ReplaceChars(prefName, '-', '_'); + np_ReplaceChars(prefName, '/', '_'); + + return prefName; +} + +/* + np_ReplaceChars() + ----------------- + Swaps all occurances of oldChar with newChar in word. + Should this be inline? +*/ + +static void np_ReplaceChars(char* word, char oldChar, char newChar) +{ + char* index; + XP_ASSERT(word); + for(index = word; *index != 0; ++index) + if(*index == oldChar) + *index = newChar; +} + +#endif /* ANTHRAX */ + +#ifdef PLUGIN_TIMER_EVENT + +static void np_SetTimerInterval(NPP npp, uint32 msecs) +{ + if(npp) { + np_instance* instance = (np_instance*) npp->ndata; + if(instance) + { + instance->interval = msecs; + instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); + } + } +} + +static void np_TimerCallback(void* data) +{ + NPEvent event; + np_instance* instance = (np_instance*) data; + +#ifdef XP_MAC + ((EventRecord)event).what = nullEvent; +#elif defined(XP_WIN) + event.event = 0; // ? +#elif defined(XP_OS2) + event.event = 0; // ? +#elif defined(XP_UNIX) + // not sure what to do here +#endif + + instance->timeout = FE_SetTimeout(np_TimerCallback, (void*)instance, instance->interval); + NPL_HandleEvent(instance->app, &event, NULL); +} +#endif + diff --git a/mozilla/modules/plugin/src/npglue.h b/mozilla/modules/plugin/src/npglue.h new file mode 100644 index 00000000000..b841d7fed63 --- /dev/null +++ b/mozilla/modules/plugin/src/npglue.h @@ -0,0 +1,730 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef npglue_h__ +#define npglue_h__ + +#if defined(__cplusplus) +extern "C" { +#endif + +#include "net.h" +#include "np.h" +#include "nppg.h" +#include "client.h" +#include "xpassert.h" +#include "ntypes.h" +#include "fe_proto.h" +#include "cvactive.h" +#include "gui.h" /* For XP_AppCodeName */ +#include "merrors.h" +#include "xpgetstr.h" +#ifdef JAVA +#include "java.h" +#endif +#include "nppriv.h" +#include "shist.h" + +#include "prefapi.h" +#include "proto.h" + +#ifdef MOCHA +#include "libmocha.h" +#include "libevent.h" +#include "layout.h" /* XXX From ../layout */ +#endif + +#ifdef LAYERS +#include "layers.h" +#endif /* LAYERS */ + +#include "nsplugin.h" +#include "nsAgg.h" /* nsPluginManager aggregates nsJVMManager */ +#ifdef OJI +#include "nsjvm.h" +#else /* OJI */ +/* Just define a dummy struct for nsIJVMManager. In the + plugin code, it is never actually dereferenced outside of an + `#ifdef OJI'. */ +struct nsIJVMManager; +#endif /* OJI */ + +extern int XP_PLUGIN_LOADING_PLUGIN; +extern int MK_BAD_CONNECT; +extern int XP_PLUGIN_NOT_FOUND; +extern int XP_PLUGIN_CANT_LOAD_PLUGIN; +extern int XP_PROGRESS_STARTING_JAVA; + +#define NP_LOCK 1 +#define NP_UNLOCK 0 + +#define NPTRACE(n, msg) TRACEMSG(msg) + +#define RANGE_EQUALS "bytes=" + +/* @@@@ steal the private call from netlib */ +extern void NET_SetCallNetlibAllTheTime(MWContext *context, char *caller); +extern void NET_ClearCallNetlibAllTheTime(MWContext *context, char *caller); + +#if defined(XP_WIN) || defined(XP_OS2) +/* Can't include FEEMBED.H because it's full of C++ */ +extern NET_StreamClass *EmbedStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext); +extern void EmbedUrlExit(URL_Struct *pUrl, int iStatus, MWContext *pContext); +#endif + +extern void NET_RegisterAllEncodingConverters(char* format_in, FO_Present_Types format_out); + + +/* Internal prototypes */ + +void +NPL_EmbedURLExit(URL_Struct *urls, int status, MWContext *cx); + +void +NPL_URLExit(URL_Struct *urls, int status, MWContext *cx); + +void +np_streamAsFile(np_stream* stream); + +NPError +np_switchHandlers(np_instance* instance, + np_handle* newHandle, + np_mimetype* newMimeType, + char* requestedType); + +NET_StreamClass* +np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance); + +void +np_findPluginType(NPMIMEType type, void* pdesc, np_handle** outHandle, np_mimetype** outMimetype); + +void +np_enablePluginType(np_handle* handle, np_mimetype* mimetype, XP_Bool enabled); + +void +np_bindContext(NPEmbeddedApp* app, MWContext* cx); + +void +np_unbindContext(NPEmbeddedApp* app, MWContext* cx); + +void +np_deleteapp(MWContext* cx, NPEmbeddedApp* app); + +np_instance* +np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app, + np_mimetype *mimetype, char *requestedType); + +void +np_delete_instance(np_instance *instance); + +void +np_recover_mochaWindow(JRIEnv * env, np_instance * instance); + +XP_Bool +np_FakeHTMLStream(URL_Struct* urls, MWContext* cx, char * fakehtml); + +/* Navigator plug-in API function prototypes */ + +/* + * Use this macro before each exported function + * (between the return address and the function + * itself), to ensure that the function has the + * right calling conventions on Win16. + */ +#ifdef XP_WIN16 +#define NP_EXPORT __export +#elif defined(XP_OS2) +#define NP_EXPORT _System +#else +#define NP_EXPORT +#endif + +NPError NP_EXPORT +npn_requestread(NPStream *pstream, NPByteRange *rangeList); + +NPError NP_EXPORT +npn_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData); + +NPError NP_EXPORT +npn_getvalue(NPP npp, NPNVariable variable, void *r_value); + +NPError NP_EXPORT +npn_setvalue(NPP npp, NPPVariable variable, void *r_value); + +NPError NP_EXPORT +npn_geturl(NPP npp, const char* relativeURL, const char* target); + +NPError NP_EXPORT +npn_posturlnotify(NPP npp, const char* relativeURL, const char *target, + uint32 len, const char *buf, NPBool file, void* notifyData); + +NPError NP_EXPORT +npn_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len, + const char *buf, NPBool file); + +NPError +np_geturlinternal(NPP npp, const char* relativeURL, const char* target, + const char* altHost, const char* referer, PRBool forceJSEnabled, + NPBool notify, void* notifyData); + +NPError +np_posturlinternal(NPP npp, const char* relativeURL, const char *target, + const char* altHost, const char* referer, PRBool forceJSEnabled, + uint32 len, const char *buf, NPBool file, NPBool notify, void* notifyData); + +NPError NP_EXPORT +npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream); + +int32 NP_EXPORT +npn_write(NPP npp, NPStream *pstream, int32 len, void *buffer); + +NPError NP_EXPORT +npn_destroystream(NPP npp, NPStream *pstream, NPError reason); + +void NP_EXPORT +npn_status(NPP npp, const char *message); + +void NP_EXPORT +npn_registerwindow(NPP npp, void* window); + +void NP_EXPORT +npn_unregisterwindow(NPP npp, void* window); + +int16 NP_EXPORT +npn_allocateMenuID(NPP npp, XP_Bool isSubmenu); + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +const char* NP_EXPORT +npn_useragent(NPP npp); +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +void* NP_EXPORT +npn_memalloc (uint32 size); +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + + +void NP_EXPORT +npn_memfree (void *ptr); + +uint32 NP_EXPORT +npn_memflush(uint32 size); + +void NP_EXPORT +npn_reloadplugins(NPBool reloadPages); + +void NP_EXPORT +npn_invalidaterect(NPP npp, NPRect *invalidRect); + +void NP_EXPORT +npn_invalidateregion(NPP npp, NPRegion invalidRegion); + +void NP_EXPORT +npn_forceredraw(NPP npp); + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +#if defined(OJI) +JNIEnv* NP_EXPORT +npn_getJavaEnv(PRThread *pPRThread); +#else +JRIEnv* NP_EXPORT +npn_getJavaEnv(void); +#endif +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + + +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_D0 +#endif +jref NP_EXPORT +npn_getJavaPeer(NPP npp); +#if defined(XP_MAC) && !defined(powerc) +#pragma pointers_in_A0 +#endif + + +/* End of function prototypes */ + + +/* this is a hack for now */ +#define NP_MAXBUF (0xE000) + +//////////////////////////////////////////////////////////////////////////////// + +class nsPluginManager : public nsIPluginManager2 { +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginManager: + + // (Corresponds to NPN_ReloadPlugins.) + NS_IMETHOD_(void) + ReloadPlugins(PRBool reloadPages); + + // (Corresponds to NPN_MemAlloc.) + NS_IMETHOD_(void*) + MemAlloc(PRUint32 size); + + // (Corresponds to NPN_MemFree.) + NS_IMETHOD_(void) + MemFree(void* ptr); + + // (Corresponds to NPN_MemFlush.) + NS_IMETHOD_(PRUint32) + MemFlush(PRUint32 size); + + // (Corresponds to NPN_UserAgent.) + NS_IMETHOD_(const char*) + UserAgent(void); + + // (Corresponds to NPN_GetURL and NPN_GetURLNotify.) + NS_IMETHOD_(nsPluginError) + GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData, + const char* altHost, const char* referer, PRBool forceJSEnabled); + + // (Corresponds to NPN_PostURL and NPN_PostURLNotify.) + NS_IMETHOD_(nsPluginError) + PostURL(nsISupports* peer, const char* url, const char* target, + PRUint32 len, const char* buf, PRBool file, void* notifyData, + const char* altHost, const char* referer, PRBool forceJSEnabled, + PRUint32 postHeadersLength, const char* postHeaders); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginManager2: + + NS_IMETHOD_(void) + BeginWaitCursor(void); + + NS_IMETHOD_(void) + EndWaitCursor(void); + + NS_IMETHOD_(PRBool) + SupportsURLProtocol(const char* protocol); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginManager specific methods: + + NS_DECL_AGGREGATED + + static NS_METHOD + Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); + +protected: + nsPluginManager(nsISupports* outer); + virtual ~nsPluginManager(void); + + // aggregated interfaces: + nsIJVMManager* GetJVMMgr(const nsIID& aIID); + + nsISupports* fJVMMgr; + PRUint16 fWaiting; + void* fOldCursor; +}; + +extern nsPluginManager* thePluginManager; + +//////////////////////////////////////////////////////////////////////////////// + +class nsFileUtilities : public nsIFileUtilities { +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIFileUtilities: + + NS_IMETHOD_(const char*) + GetProgramPath(void); + + NS_IMETHOD_(const char*) + GetTempDirPath(void); + + NS_IMETHOD_(nsresult) + GetFileName(const char* fn, FileNameType type, + char* resultBuf, PRUint32 bufLen); + + NS_IMETHOD_(nsresult) + NewTempFileName(const char* prefix, char* resultBuf, PRUint32 bufLen); + + //////////////////////////////////////////////////////////////////////////// + // nsFileUtilities specific methods: + + nsFileUtilities(nsISupports* outer); + virtual ~nsFileUtilities(void); + + NS_DECL_AGGREGATED + + void SetProgramPath(const char* path) { fProgramPath = path; } + +protected: + const char* fProgramPath; + +}; + +//////////////////////////////////////////////////////////////////////////////// +typedef struct JSContext JSContext; + +class nsPluginTagInfo; + +class nsPluginInstancePeer : public nsIPluginInstancePeer2, + public nsILiveConnectPluginInstancePeer, + public nsIWindowlessPluginInstancePeer +{ +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInstancePeer: + + // (Corresponds to NPP_New's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void); + + // (Corresponds to NPP_New's mode argument.) + NS_IMETHOD_(nsPluginType) + GetMode(void); + + // (Corresponds to NPN_NewStream.) + NS_IMETHOD_(nsPluginError) + NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result); + + // (Corresponds to NPN_Status.) + NS_IMETHOD_(void) + ShowStatus(const char* message); + + // (Corresponds to NPN_GetValue.) + NS_IMETHOD_(nsPluginError) + GetValue(nsPluginManagerVariable variable, void *value); + + // (Corresponds to NPN_SetValue.) + NS_IMETHOD_(nsPluginError) + SetValue(nsPluginVariable variable, void *value); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginInstancePeer2: + + NS_IMETHOD_(void) + RegisterWindow(void* window); + + NS_IMETHOD_(void) + UnregisterWindow(void* window); + + NS_IMETHOD_(PRInt16) + AllocateMenuID(PRBool isSubmenu); + + // On the mac (and most likely win16), network activity can + // only occur on the main thread. Therefore, we provide a hook + // here for the case that the main thread needs to tickle itself. + // In this case, we make sure that we give up the monitor so that + // the tickle code can notify it without freezing. + NS_IMETHOD_(PRBool) + Tickle(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIJRILiveConnectPluginInstancePeer: + + // (Corresponds to NPN_GetJavaPeer.) + NS_IMETHOD_(jobject) + GetJavaPeer(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIWindowlessPluginInstancePeer: + + // (Corresponds to NPN_InvalidateRect.) + NS_IMETHOD_(void) + InvalidateRect(nsRect *invalidRect); + + // (Corresponds to NPN_InvalidateRegion.) + NS_IMETHOD_(void) + InvalidateRegion(nsRegion invalidRegion); + + // (Corresponds to NPN_ForceRedraw.) + NS_IMETHOD_(void) + ForceRedraw(void); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginInstancePeer specific methods: + + nsPluginInstancePeer(NPP npp); + virtual ~nsPluginInstancePeer(void); + + NS_DECL_AGGREGATED + + nsIPluginInstance* GetUserInstance(void) { + userInst->AddRef(); + return userInst; + } + + void SetUserInstance(nsIPluginInstance* inst) { + userInst = inst; + } + + NPP GetNPP(void) { return npp; } + JSContext *GetJSContext(void); + MWContext *GetMWContext(void); +protected: + + // NPP is the old plugin structure. If we were implementing this + // from scratch we wouldn't use it, but for now we're calling the old + // npglue.c routines wherever possible. + NPP npp; + + nsIPluginInstance* userInst; + nsPluginTagInfo* tagInfo; + +}; + +#define NS_PLUGININSTANCEPEER_CID \ +{ /* 766432d0-01ba-11d2-815b-006008119d7a */ \ + 0x766432d0, \ + 0x01ba, \ + 0x11d2, \ + {0x81, 0x5b, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ +} + +//////////////////////////////////////////////////////////////////////////////// + +class nsPluginTagInfo : public nsIPluginTagInfo2 { +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginTagInfo: + + // Get a ptr to the paired list of attribute names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + // + NS_IMETHOD_(nsPluginError) + GetAttributes(PRUint16& n, const char*const*& names, const char*const*& values); + + // Get the value for the named attribute. Returns null + // if the attribute was not set. + NS_IMETHOD_(const char*) + GetAttribute(const char* name); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginTagInfo2: + + // Get the type of the HTML tag that was used ot instantiate this + // plugin. Currently supported tags are EMBED, OBJECT and APPLET. + NS_IMETHOD_(nsPluginTagType) + GetTagType(void); + + // Get the complete text of the HTML tag that was + // used to instantiate this plugin + NS_IMETHOD_(const char *) + GetTagText(void); + + // Get a ptr to the paired list of parameter names and values, + // returns the length of the array. + // + // Each name or value is a null-terminated string. + NS_IMETHOD_(nsPluginError) + GetParameters(PRUint16& n, const char*const*& names, const char*const*& values); + + // Get the value for the named parameter. Returns null + // if the parameter was not set. + NS_IMETHOD_(const char*) + GetParameter(const char* name); + + NS_IMETHOD_(const char*) + GetDocumentBase(void); + + // Return an encoding whose name is specified in: + // http://java.sun.com/products/jdk/1.1/docs/guide/intl/intl.doc.html#25303 + NS_IMETHOD_(const char*) + GetDocumentEncoding(void); + + NS_IMETHOD_(const char*) + GetAlignment(void); + + NS_IMETHOD_(PRUint32) + GetWidth(void); + + NS_IMETHOD_(PRUint32) + GetHeight(void); + + NS_IMETHOD_(PRUint32) + GetBorderVertSpace(void); + + NS_IMETHOD_(PRUint32) + GetBorderHorizSpace(void); + + // Returns a unique id for the current document on which the + // plugin is displayed. + NS_IMETHOD_(PRUint32) + GetUniqueID(void); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginTagInfo specific methods: + + nsPluginTagInfo(NPP npp); + virtual ~nsPluginTagInfo(void); + + NS_DECL_AGGREGATED + +protected: + LO_CommonPluginStruct* GetLayoutElement(void) + { + np_instance* instance = (np_instance*) npp->ndata; + NPEmbeddedApp* app = instance->app; + np_data* ndata = (np_data*) app->np_data; + return (LO_CommonPluginStruct*)ndata->lo_struct; + } + + // aggregated interfaces: + nsISupports* fJVMPluginTagInfo; + + NPP npp; + PRUint32 fUniqueID; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class nsPluginManagerStream : public nsIOutputStream { +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIBaseStream: + + NS_IMETHOD + Close(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIOutputStream: + + NS_IMETHOD_(PRInt32) + Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, + nsresult *errorResult); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginManagerStream specific methods: + + nsPluginManagerStream(NPP npp, NPStream* pstr); + virtual ~nsPluginManagerStream(void); + + NS_DECL_ISUPPORTS + +protected: + NPP npp; + NPStream* pstream; + +}; + +//////////////////////////////////////////////////////////////////////////////// + +class nsPluginStreamPeer : + virtual public nsIPluginStreamPeer2, + virtual public nsISeekablePluginStreamPeer +{ +public: + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginStreamPeer: + + // (Corresponds to NPStream's url field.) + NS_IMETHOD_(const char*) + GetURL(void); + + // (Corresponds to NPStream's end field.) + NS_IMETHOD_(PRUint32) + GetEnd(void); + + // (Corresponds to NPStream's lastmodified field.) + NS_IMETHOD_(PRUint32) + GetLastModified(void); + + // (Corresponds to NPStream's notifyData field.) + NS_IMETHOD_(void*) + GetNotifyData(void); + + // (Corresponds to NPP_DestroyStream's reason argument.) + NS_IMETHOD_(nsPluginReason) + GetReason(void); + + // (Corresponds to NPP_NewStream's MIMEType argument.) + NS_IMETHOD_(nsMIMEType) + GetMIMEType(void); + + //////////////////////////////////////////////////////////////////////////// + // from nsIPluginStreamPeer2: + + NS_IMETHOD_(PRUint32) + GetContentLength(void); + + NS_IMETHOD_(PRUint32) + GetHeaderFieldCount(void); + + NS_IMETHOD_(const char*) + GetHeaderFieldKey(PRUint32 index); + + NS_IMETHOD_(const char*) + GetHeaderField(PRUint32 index); + + //////////////////////////////////////////////////////////////////////////// + // from nsISeekablePluginStreamPeer: + + // (Corresponds to NPN_RequestRead.) + NS_IMETHOD_(nsPluginError) + RequestRead(nsByteRange* rangeList); + + //////////////////////////////////////////////////////////////////////////// + // nsPluginStreamPeer specific methods: + + nsPluginStreamPeer(URL_Struct *urls, np_stream *stream); + virtual ~nsPluginStreamPeer(void); + + NS_DECL_ISUPPORTS + + nsIPluginStream* GetUserStream(void) { + return userStream; + } + + void SetUserStream(nsIPluginStream* str) { + userStream = str; + } + + void SetReason(nsPluginReason r) { + reason = r; + } + +protected: + nsIPluginStream* userStream; + URL_Struct *urls; + np_stream *stream; + nsPluginReason reason; + +}; + +//////////////////////////////////////////////////////////////////////////////// + +#if defined(__cplusplus) +} /* extern "C" */ +#endif + +#endif /* npglue_h__ */ diff --git a/mozilla/modules/plugin/src/nppg.h b/mozilla/modules/plugin/src/nppg.h new file mode 100644 index 00000000000..5106de1bc44 --- /dev/null +++ b/mozilla/modules/plugin/src/nppg.h @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * nppg.h $Revision: 1.1 $ + * Prototypes for functions exported by the FEs and called by libplugin. + * Some (perhaps all) of these prototypes could be moved to fe_proto.h. + * Protypes for functions exported by libplugin are in np.h. + */ + +#ifndef _NPPG_H +#define _NPPG_H + +#include "npapi.h" +#include "npupp.h" +struct _np_handle; + +XP_BEGIN_PROTOS + +extern void FE_RegisterPlugins(void); +extern NPPluginFuncs* FE_LoadPlugin(void *plugin, NPNetscapeFuncs *, struct _np_handle* handle); +extern void FE_UnloadPlugin(void *plugin, struct _np_handle* handle); +extern void FE_EmbedURLExit(URL_Struct *urls, int status, MWContext *cx); +extern void FE_ShowScrollBars(MWContext *context, XP_Bool show); +#if defined (XP_WIN) || defined(XP_OS2) +extern void FE_FreeEmbedSessionData(MWContext *context, NPEmbeddedApp* pApp); +#endif + +#ifdef XP_MAC +extern void FE_PluginProgress(MWContext *context, const char *message); +extern void FE_ResetRefreshURLTimer(MWContext *context); +extern void FE_RegisterWindow(void* plugin, void* window); +extern void FE_UnregisterWindow(void* plugin, void* window); +extern SInt16 FE_AllocateMenuID(void *plugin, XP_Bool isSubmenu); +#endif + +#ifdef XP_UNIX +extern NPError FE_PluginGetValue(void *pdesc, NPNVariable variable, void *r_value); +#else +extern NPError FE_PluginGetValue(MWContext *context, NPEmbeddedApp *app, NPNVariable variable, void *r_value); +#endif /* XP_UNIX */ + +#ifdef XP_WIN32 +void* WFE_BeginSetModuleState(); +void WFE_EndSetModuleState(void*); +#endif + +XP_END_PROTOS + +#endif /* _NPPG_H */ diff --git a/mozilla/modules/plugin/src/nppriv.h b/mozilla/modules/plugin/src/nppriv.h new file mode 100644 index 00000000000..360042e1484 --- /dev/null +++ b/mozilla/modules/plugin/src/nppriv.h @@ -0,0 +1,153 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + +#ifndef _NPPRIV_H_ +#define _NPPRIV_H_ + +#include "xp_core.h" +#include "xp_mem.h" +#include "xp_trace.h" +#include "xp_mcom.h" +#include "lo_ele.h" +#include "npupp.h" +#include "npassoc.h" +#include "npapi.h" + +#define ISFUNCPTR(x) (x != NULL) + +#define PLUGIN_TIMER_EVENT + +typedef struct _np_handle np_handle; +typedef struct _np_mimetype np_mimetype; +typedef struct _np_instance np_instance; +typedef struct _np_stream np_stream; +typedef struct _np_data np_data; +typedef struct _np_urlsnode np_urlsnode; +typedef struct _np_reconnect np_reconnect; +struct nsIPlugin; + +typedef enum { + NPDataNormal = 0, /* URL_Struct.fe_data -> NPEmbeddedApp.np_data -> np_data */ + NPDataCache = 1, /* LO_EmbedStruct.session_data -> np_data */ + NPDataCached = 2, /* LO_EmbedStruct.session_data -> np_data */ + NPDataSaved = 3 /* LO_EmbedStruct.session_data -> np_data */ +} NPDataState; + +struct _np_data { + NPDataState state; + np_handle *handle; + NPEmbeddedApp *app; + NPSavedData *sdata; + /* Not valid in state NPDataSaved! */ + np_instance *instance; + LO_EmbedStruct *lo_struct; + int32 refs; + XP_Bool streamStarted; +}; + +struct _np_handle { + np_handle *next; + NPPluginFuncs *f; + void *pdesc; /* pd glue description */ + int32 refs; + np_instance *instances; + np_mimetype *mimetypes; + char *name; + char *filename; + char *description; + struct nsIPlugin* userPlugin; +}; + +struct _np_mimetype { + np_mimetype* next; + NPMIMEType type; + NPFileTypeAssoc *fassoc; + np_handle* handle; + XP_Bool enabled; +}; + +struct _np_instance { + np_handle *handle; + np_mimetype *mimetype; + char *typeString; + np_instance *next; + NPEmbeddedApp *app; + NPP npp; + MWContext *cx; + np_stream *streams; + uint16 type; + int reentrant; + URL_Struct *delayedload; + XP_List *url_list; + JRIEnv* javaEnv; +#ifdef OJI + jobject javaInstance; +#else + JRIGlobalRef javaInstance; +#endif /* OJI */ + XP_Bool windowed; /* TRUE = has its own window, FALSE = windowless */ + XP_Bool transparent; /* TRUE = transparent, FALSE = opaque */ + XP_Bool calling_netlib_all_the_time; + JRIGlobalRef mochaWindow; + +#ifdef PLUGIN_TIMER_EVENT + void* timeout; + uint32 interval; +#endif + +#ifdef LAYERS + CL_Layer *layer; +#endif /* LAYERS */ +}; + +struct _np_stream { + np_instance *instance; + np_handle *handle; + np_stream *next; + NPStream *pstream; + char *url; /* convenience */ + URL_Struct *initial_urls; + NET_StreamClass *nstream; + int32 len; + int init; + int seek; /* 0 normal, -1 turn, 1 seek, 2 discard */ + int seekable; + int dontclose; + int asfile; + int islocked; + int32 offset; + NPByteRange *deferred; + NET_StreamClass *prev_stream; +}; + +struct _np_urlsnode { + URL_Struct *urls; + void* notifyData; + XP_Bool cached; + XP_Bool notify; +}; + +/* MWContext.pluginReconnect -> np_reconnect */ +struct _np_reconnect { + np_mimetype* mimetype; + char* requestedtype; + NPEmbeddedApp* app; +}; + +#endif /* _NPPRIV_H_ */ diff --git a/mozilla/modules/plugin/src/npupp.h b/mozilla/modules/plugin/src/npupp.h new file mode 100644 index 00000000000..b70a3075c5d --- /dev/null +++ b/mozilla/modules/plugin/src/npupp.h @@ -0,0 +1,1225 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + +/* + * npupp.h $Revision: 1.1 $ + * function call mecahnics needed by platform specific glue code. + */ + + +#ifndef _NPUPP_H_ +#define _NPUPP_H_ + +#if defined(__OS2__) +#pragma pack(1) +#endif + +#ifndef GENERATINGCFM +#define GENERATINGCFM 0 +#endif + +#ifndef _NPAPI_H_ +#include "npapi.h" +#endif + +#ifdef OJI +#include "jni.h" +#else +#include "jri.h" +#endif + +/****************************************************************************************** + plug-in function table macros + for each function in and out of the plugin API we define + typedef NPP_FooUPP + #define NewNPP_FooProc + #define CallNPP_FooProc + for mac, define the UPP magic for PPC/68K calling + *******************************************************************************************/ + + +/* NPP_Initialize */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_InitializeUPP; + +enum { + uppNPP_InitializeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_InitializeProc(FUNC) \ + (NPP_InitializeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_InitializeProcInfo, GetCurrentArchitecture()) +#define CallNPP_InitializeProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_InitializeProcInfo) + +#else + +typedef void (* NP_LOADDS NPP_InitializeUPP)(void); +#define NewNPP_InitializeProc(FUNC) \ + ((NPP_InitializeUPP) (FUNC)) +#define CallNPP_InitializeProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_Shutdown */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_ShutdownUPP; + +enum { + uppNPP_ShutdownProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_ShutdownProc(FUNC) \ + (NPP_ShutdownUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_ShutdownProcInfo, GetCurrentArchitecture()) +#define CallNPP_ShutdownProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_ShutdownProcInfo) + +#else + +typedef void (* NP_LOADDS NPP_ShutdownUPP)(void); +#define NewNPP_ShutdownProc(FUNC) \ + ((NPP_ShutdownUPP) (FUNC)) +#define CallNPP_ShutdownProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_New */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_NewUPP; + +enum { + uppNPP_NewProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(uint16))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int16))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(NPSavedData *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; + +#define NewNPP_NewProc(FUNC) \ + (NPP_NewUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewProcInfo, \ + (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (* NP_LOADDS NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); +#define NewNPP_NewProc(FUNC) \ + ((NPP_NewUPP) (FUNC)) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) + +#endif + + +/* NPP_Destroy */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyUPP; +enum { + uppNPP_DestroyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPSavedData **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyProc(FUNC) \ + (NPP_DestroyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyProcInfo, (ARG1), (ARG2)) +#else + +typedef NPError (* NP_LOADDS NPP_DestroyUPP)(NPP instance, NPSavedData** save); +#define NewNPP_DestroyProc(FUNC) \ + ((NPP_DestroyUPP) (FUNC)) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_SetWindow */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_SetWindowUPP; +enum { + uppNPP_SetWindowProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPWindow *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_SetWindowProc(FUNC) \ + (NPP_SetWindowUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_SetWindowProcInfo, GetCurrentArchitecture()) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_SetWindowProcInfo, (ARG1), (ARG2)) + +#else + +typedef NPError (* NP_LOADDS NPP_SetWindowUPP)(NPP instance, NPWindow* window); +#define NewNPP_SetWindowProc(FUNC) \ + ((NPP_SetWindowUPP) (FUNC)) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_NewStreamUPP; +enum { + uppNPP_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(uint16 *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_NewStreamProc(FUNC) \ + (NPP_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewStreamProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#else + +typedef NPError (* NP_LOADDS NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); +#define NewNPP_NewStreamProc(FUNC) \ + ((NPP_NewStreamUPP) (FUNC)) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#endif + + +/* NPP_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyStreamUPP; +enum { + uppNPP_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyStreamProc(FUNC) \ + (NPP_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, (NPParg), (NPStreamPtr), (NPReasonArg)) + +#else + +typedef NPError (* NP_LOADDS NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPP_DestroyStreamProc(FUNC) \ + ((NPP_DestroyStreamUPP) (FUNC)) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg)) + +#endif + + +/* NPP_WriteReady */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteReadyUPP; +enum { + uppNPP_WriteReadyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteReadyProc(FUNC) \ + (NPP_WriteReadyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, (NPParg), (NPStreamPtr)) + +#else + +typedef int32 (* NP_LOADDS NPP_WriteReadyUPP)(NPP instance, NPStream* stream); +#define NewNPP_WriteReadyProc(FUNC) \ + ((NPP_WriteReadyUPP) (FUNC)) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr)) + +#endif + + +/* NPP_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteUPP; +enum { + uppNPP_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteProc(FUNC) \ + (NPP_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteProcInfo, (NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#else + +typedef int32 (* NP_LOADDS NPP_WriteUPP)(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); +#define NewNPP_WriteProc(FUNC) \ + ((NPP_WriteUPP) (FUNC)) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#endif + + +/* NPP_StreamAsFile */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_StreamAsFileUPP; +enum { + uppNPP_StreamAsFileProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_StreamAsFileProc(FUNC) \ + (NPP_StreamAsFileUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, GetCurrentArchitecture()) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, (ARG1), (ARG2), (ARG3)) + +#else + +typedef void (* NP_LOADDS NPP_StreamAsFileUPP)(NPP instance, NPStream* stream, const char* fname); +#define NewNPP_StreamAsFileProc(FUNC) \ + ((NPP_StreamAsFileUPP) (FUNC)) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPP_Print */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_PrintUPP; +enum { + uppNPP_PrintProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPrint *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_PrintProc(FUNC) \ + (NPP_PrintUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_PrintProcInfo, GetCurrentArchitecture()) +#define CallNPP_PrintProc(FUNC, NPParg, voidPtr) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_PrintProcInfo, (NPParg), (voidPtr)) + +#else + +typedef void (* NP_LOADDS NPP_PrintUPP)(NPP instance, NPPrint* platformPrint); +#define NewNPP_PrintProc(FUNC) \ + ((NPP_PrintUPP) (FUNC)) +#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \ + (*(FUNC))((NPParg), (NPPrintArg)) + +#endif + + +/* NPP_HandleEvent */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_HandleEventUPP; +enum { + uppNPP_HandleEventProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int16))) +}; +#define NewNPP_HandleEventProc(FUNC) \ + (NPP_HandleEventUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_HandleEventProcInfo, GetCurrentArchitecture()) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (int16)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_HandleEventProcInfo, (NPParg), (voidPtr)) + +#else + +typedef int16 (* NP_LOADDS NPP_HandleEventUPP)(NPP instance, void* event); +#define NewNPP_HandleEventProc(FUNC) \ + ((NPP_HandleEventUPP) (FUNC)) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (*(FUNC))((NPParg), (voidPtr)) + +#endif + + +/* NPP_URLNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_URLNotifyUPP; +enum { + uppNPP_URLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(SIZE_CODE(0))) +}; +#define NewNPP_URLNotifyProc(FUNC) \ + (NPP_URLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) + +#else + +typedef void (* NP_LOADDS NPP_URLNotifyUPP)(NPP instance, const char* url, NPReason reason, void* notifyData); +#define NewNPP_URLNotifyProc(FUNC) \ + ((NPP_URLNotifyUPP) (FUNC)) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) + +#endif + + +/* NPP_GetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_GetValueUPP; +enum { + uppNPP_GetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_GetValueProc(FUNC) \ + (NPP_GetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_GetValueProcInfo, GetCurrentArchitecture()) +#define CallNPP_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_GetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (* NP_LOADDS NPP_GetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); +#define NewNPP_GetValueProc(FUNC) \ + ((NPP_GetValueUPP) (FUNC)) +#define CallNPP_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPP_SetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_SetValueUPP; +enum { + uppNPP_SetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPNVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_SetValueProc(FUNC) \ + (NPP_SetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_SetValueProcInfo, GetCurrentArchitecture()) +#define CallNPP_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_SetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (* NP_LOADDS NPP_SetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPP_SetValueProc(FUNC) \ + ((NPP_SetValueUPP) (FUNC)) +#define CallNPP_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + + + +/* + * Netscape entry points + */ + + +/* NPN_GetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetValueUPP; +enum { + uppNPN_GetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPNVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetValueProc(FUNC) \ + (NPN_GetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetValueProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (* NP_LOADDS NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPN_GetValueProc(FUNC) \ + ((NPN_GetValueUPP) (FUNC)) +#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPN_SetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_SetValueUPP; +enum { + uppNPN_SetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_SetValueProc(FUNC) \ + (NPN_SetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_SetValueProcInfo, GetCurrentArchitecture()) +#define CallNPN_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_SetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (* NP_LOADDS NPN_SetValueUPP)(NPP instance, NPPVariable variable, void *ret_alue); +#define NewNPN_SetValueProc(FUNC) \ + ((NPN_SetValueUPP) (FUNC)) +#define CallNPN_SetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPN_GetUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLNotifyUPP; +enum { + uppNPN_GetURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLNotifyProc(FUNC) \ + (NPN_GetURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) +#else + +typedef NPError (* NP_LOADDS NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData); +#define NewNPN_GetURLNotifyProc(FUNC) \ + ((NPN_GetURLNotifyUPP) (FUNC)) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#endif + + +/* NPN_PostUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLNotifyUPP; +enum { + uppNPN_PostURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLNotifyProc(FUNC) \ + (NPN_PostURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (* NP_LOADDS NPN_PostURLNotifyUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData); +#define NewNPN_PostURLNotifyProc(FUNC) \ + ((NPN_PostURLNotifyUPP) (FUNC)) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#endif + + +/* NPN_GetUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLUPP; +enum { + uppNPN_GetURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLProc(FUNC) \ + (NPN_GetURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (* NP_LOADDS NPN_GetURLUPP)(NPP instance, const char* url, const char* window); +#define NewNPN_GetURLProc(FUNC) \ + ((NPN_GetURLUPP) (FUNC)) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPN_PostUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLUPP; +enum { + uppNPN_PostURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLProc(FUNC) \ + (NPN_PostURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#else + +typedef NPError (* NP_LOADDS NPN_PostURLUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file); +#define NewNPN_PostURLProc(FUNC) \ + ((NPN_PostURLUPP) (FUNC)) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#endif + + +/* NPN_RequestRead */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_RequestReadUPP; +enum { + uppNPN_RequestReadProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPByteRange *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_RequestReadProc(FUNC) \ + (NPN_RequestReadUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_RequestReadProcInfo, GetCurrentArchitecture()) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_RequestReadProcInfo, (stream), (range)) + +#else + +typedef NPError (* NP_LOADDS NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList); +#define NewNPN_RequestReadProc(FUNC) \ + ((NPN_RequestReadUPP) (FUNC)) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (*(FUNC))((stream), (range)) + +#endif + + +/* NPN_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_NewStreamUPP; +enum { + uppNPN_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPStream **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_NewStreamProc(FUNC) \ + (NPN_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_NewStreamProcInfo, (npp), (type), (window), (stream)) + +#else + +typedef NPError (* NP_LOADDS NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); +#define NewNPN_NewStreamProc(FUNC) \ + ((NPN_NewStreamUPP) (FUNC)) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (*(FUNC))((npp), (type), (window), (stream)) + +#endif + + +/* NPN_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_WriteUPP; +enum { + uppNPN_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPN_WriteProc(FUNC) \ + (NPN_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_WriteProcInfo, (npp), (stream), (len), (buffer)) + +#else + +typedef int32 (* NP_LOADDS NPN_WriteUPP)(NPP instance, NPStream* stream, int32 len, void* buffer); +#define NewNPN_WriteProc(FUNC) \ + ((NPN_WriteUPP) (FUNC)) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (*(FUNC))((npp), (stream), (len), (buffer)) + +#endif + + +/* NPN_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_DestroyStreamUPP; +enum { + uppNPN_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP ))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_DestroyStreamProc(FUNC) \ + (NPN_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, (npp), (stream), (reason)) + +#else + +typedef NPError (* NP_LOADDS NPN_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPN_DestroyStreamProc(FUNC) \ + ((NPN_DestroyStreamUPP) (FUNC)) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (*(FUNC))((npp), (stream), (reason)) + +#endif + + +/* NPN_Status */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_StatusUPP; +enum { + uppNPN_StatusProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *))) +}; + +#define NewNPN_StatusProc(FUNC) \ + (NPN_StatusUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_StatusProcInfo, GetCurrentArchitecture()) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_StatusProcInfo, (npp), (msg)) + +#else + +typedef void (* NP_LOADDS NPN_StatusUPP)(NPP instance, const char* message); +#define NewNPN_StatusProc(FUNC) \ + ((NPN_StatusUPP) (FUNC)) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (*(FUNC))((npp), (msg)) + +#endif + + +/* NPN_UserAgent */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_UserAgentUPP; +enum { + uppNPN_UserAgentProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(const char *))) +}; + +#define NewNPN_UserAgentProc(FUNC) \ + (NPN_UserAgentUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_UserAgentProcInfo, GetCurrentArchitecture()) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (const char*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_UserAgentProcInfo, (ARG1)) + +#else + +typedef const char* (* NP_LOADDS NPN_UserAgentUPP)(NPP instance); +#define NewNPN_UserAgentProc(FUNC) \ + ((NPN_UserAgentUPP) (FUNC)) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemAlloc */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemAllocUPP; +enum { + uppNPN_MemAllocProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemAllocProc(FUNC) \ + (NPN_MemAllocUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemAllocProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (void*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemAllocProcInfo, (ARG1)) + +#else + +typedef void* (* NP_LOADDS NPN_MemAllocUPP)(uint32 size); +#define NewNPN_MemAllocProc(FUNC) \ + ((NPN_MemAllocUPP) (FUNC)) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN__MemFree */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFreeUPP; +enum { + uppNPN_MemFreeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemFreeProc(FUNC) \ + (NPN_MemFreeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFreeProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFreeProcInfo, (ARG1)) + +#else + +typedef void (* NP_LOADDS NPN_MemFreeUPP)(void* ptr); +#define NewNPN_MemFreeProc(FUNC) \ + ((NPN_MemFreeUPP) (FUNC)) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemFlush */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFlushUPP; +enum { + uppNPN_MemFlushProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(uint32))) +}; + +#define NewNPN_MemFlushProc(FUNC) \ + (NPN_MemFlushUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFlushProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (uint32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFlushProcInfo, (ARG1)) + +#else + +typedef uint32 (* NP_LOADDS NPN_MemFlushUPP)(uint32 size); +#define NewNPN_MemFlushProc(FUNC) \ + ((NPN_MemFlushUPP) (FUNC)) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + + +/* NPN_ReloadPlugins */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_ReloadPluginsUPP; +enum { + uppNPN_ReloadPluginsProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPN_ReloadPluginsProc(FUNC) \ + (NPN_ReloadPluginsUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, GetCurrentArchitecture()) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, (ARG1)) + +#else + +typedef void (* NP_LOADDS NPN_ReloadPluginsUPP)(NPBool reloadPages); +#define NewNPN_ReloadPluginsProc(FUNC) \ + ((NPN_ReloadPluginsUPP) (FUNC)) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_GetJavaEnv */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaEnvUPP; +enum { + uppNPN_GetJavaEnvProcInfo = kThinkCStackBased + | RESULT_SIZE(SIZE_CODE(sizeof(JRIEnv*))) +}; + +#define NewNPN_GetJavaEnvProc(FUNC) \ + (NPN_GetJavaEnvUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (JRIEnv*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo) + +#else +#ifdef OJI +typedef JNIEnv* (* NP_LOADDS NPN_GetJavaEnvUPP)(void); +#else +typedef JRIEnv* (* NP_LOADDS NPN_GetJavaEnvUPP)(void); +#endif /* ! OJI */ +#define NewNPN_GetJavaEnvProc(FUNC) \ + ((NPN_GetJavaEnvUPP) (FUNC)) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPN_GetJavaPeer */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaPeerUPP; +enum { + uppNPN_GetJavaPeerProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(jref))) +}; + +#define NewNPN_GetJavaPeerProc(FUNC) \ + (NPN_GetJavaPeerUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (jref)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, (ARG1)) + +#else + +typedef jref (* NP_LOADDS NPN_GetJavaPeerUPP)(NPP instance); +#define NewNPN_GetJavaPeerProc(FUNC) \ + ((NPN_GetJavaPeerUPP) (FUNC)) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_InvalidateRect */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_InvalidateRectUPP; +enum { + uppNPN_InvalidateRectProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPRect *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPN_InvalidateRectProc(FUNC) \ + (NPN_InvalidateRectUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_InvalidateRectProcInfo, GetCurrentArchitecture()) +#define CallNPN_InvalidateRectProc(FUNC, ARG1, ARG2) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_InvalidateRectProcInfo, (ARG1), (ARG2)) + +#else + +typedef void (* NP_LOADDS NPN_InvalidateRectUPP)(NPP instance, NPRect *rect); +#define NewNPN_InvalidateRectProc(FUNC) \ + ((NPN_InvalidateRectUPP) (FUNC)) +#define CallNPN_InvalidateRectProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPN_InvalidateRegion */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_InvalidateRegionUPP; +enum { + uppNPN_InvalidateRegionProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPRegion))) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPN_InvalidateRegionProc(FUNC) \ + (NPN_InvalidateRegionUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_InvalidateRegionProcInfo, GetCurrentArchitecture()) +#define CallNPN_InvalidateRegionProc(FUNC, ARG1, ARG2) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_InvalidateRegionProcInfo, (ARG1), (ARG2)) + +#else + +typedef void (* NP_LOADDS NPN_InvalidateRegionUPP)(NPP instance, NPRegion region); +#define NewNPN_InvalidateRegionProc(FUNC) \ + ((NPN_InvalidateRegionUPP) (FUNC)) +#define CallNPN_InvalidateRegionProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + +/* NPN_ForceRedraw */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_ForceRedrawUPP; +enum { + uppNPN_ForceRedrawProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(0))) +}; + +#define NewNPN_ForceRedrawProc(FUNC) \ + (NPN_ForceRedrawUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_ForceRedrawProcInfo, GetCurrentArchitecture()) +#define CallNPN_ForceRedrawProc(FUNC, ARG1) \ + (jref)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_ForceRedrawProcInfo, (ARG1)) + +#else + +typedef void (* NP_LOADDS NPN_ForceRedrawUPP)(NPP instance); +#define NewNPN_ForceRedrawProc(FUNC) \ + ((NPN_ForceRedrawUPP) (FUNC)) +#define CallNPN_ForceRedrawProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/****************************************************************************************** + * The actual plugin function table definitions + *******************************************************************************************/ + +#ifdef XP_MAC +#if PRAGMA_ALIGN_SUPPORTED +#pragma options align=mac68k +#endif +#endif + +typedef struct _NPPluginFuncs { + uint16 size; + uint16 version; + NPP_NewUPP newp; + NPP_DestroyUPP destroy; + NPP_SetWindowUPP setwindow; + NPP_NewStreamUPP newstream; + NPP_DestroyStreamUPP destroystream; + NPP_StreamAsFileUPP asfile; + NPP_WriteReadyUPP writeready; + NPP_WriteUPP write; + NPP_PrintUPP print; + NPP_HandleEventUPP event; + NPP_URLNotifyUPP urlnotify; +#if defined(OJI) + jobject javaClass; +#else + JRIGlobalRef javaClass; +#endif + NPP_GetValueUPP getvalue; + NPP_SetValueUPP setvalue; +} NPPluginFuncs; + +typedef struct _NPNetscapeFuncs { + uint16 size; + uint16 version; + NPN_GetURLUPP geturl; + NPN_PostURLUPP posturl; + NPN_RequestReadUPP requestread; + NPN_NewStreamUPP newstream; + NPN_WriteUPP write; + NPN_DestroyStreamUPP destroystream; + NPN_StatusUPP status; + NPN_UserAgentUPP uagent; + NPN_MemAllocUPP memalloc; + NPN_MemFreeUPP memfree; + NPN_MemFlushUPP memflush; + NPN_ReloadPluginsUPP reloadplugins; + NPN_GetJavaEnvUPP getJavaEnv; + NPN_GetJavaPeerUPP getJavaPeer; + NPN_GetURLNotifyUPP geturlnotify; + NPN_PostURLNotifyUPP posturlnotify; + NPN_GetValueUPP getvalue; + NPN_SetValueUPP setvalue; + NPN_InvalidateRectUPP invalidaterect; + NPN_InvalidateRegionUPP invalidateregion; + NPN_ForceRedrawUPP forceredraw; +} NPNetscapeFuncs; + +#ifdef XP_MAC +#if PRAGMA_ALIGN_SUPPORTED +#pragma options align=reset +#endif +#endif + + +#ifdef XP_MAC +/****************************************************************************************** + * Mac platform-specific plugin glue stuff + *******************************************************************************************/ + +/* + * Main entry point of the plugin. + * This routine will be called when the plugin is loaded. The function + * tables are passed in and the plugin fills in the NPPluginFuncs table + * and NPPShutdownUPP for Netscape's use. + */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_MainEntryUPP; +enum { + uppNPP_MainEntryProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPNetscapeFuncs*))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPluginFuncs*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPP_ShutdownUPP*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_MainEntryProc(FUNC) \ + (NPP_MainEntryUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_MainEntryProcInfo, GetCurrentArchitecture()) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + CallUniversalProc((UniversalProcPtr)(FUNC), (ProcInfoType)uppNPP_MainEntryProcInfo, (netscapeFunc), (pluginFunc), (shutdownUPP)) + +#else + +typedef NPError (* NP_LOADDS NPP_MainEntryUPP)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownUPP*); +#define NewNPP_MainEntryProc(FUNC) \ + ((NPP_MainEntryUPP) (FUNC)) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + (*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP)) + +#endif +#endif /* MAC */ + +#if defined(_WINDOWS) +#define OSCALL WINAPI +#else +#if defined(__OS2__) +#define OSCALL _System +#else +#define OSCALL +#endif +#endif + +#if defined( _WINDOWS ) || defined (__OS2__) + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ +#if defined(__OS2__) + +typedef struct _NPPluginData { /* Alternate OS2 Plugin interface */ + char *pMimeTypes; + char *pFileExtents; + char *pFileOpenTemplate; + char *pProductName; + char *pProductDescription; + unsigned long dwProductVersionMS; + unsigned long dwProductVersionLS; +} NPPluginData; + +NPError OSCALL NP_GetPluginData(NPPluginData * pPluginData); + +#endif + +NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs); + +NPError OSCALL NP_Initialize(NPNetscapeFuncs* pFuncs); + +NPError OSCALL NP_Shutdown(); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS || __OS2__ */ + +#if defined(__OS2__) +#pragma pack() +#endif + +#ifdef XP_UNIX + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ + +char* NP_GetMIMEDescription(void); +NPError NP_Initialize(NPNetscapeFuncs*, NPPluginFuncs*); +NPError NP_Shutdown(void); + +#ifdef __cplusplus +} +#endif + +#endif /* XP_UNIX */ + +#endif /* _NPUPP_H_ */ diff --git a/mozilla/modules/plugin/src/nsplugin.cpp b/mozilla/modules/plugin/src/nsplugin.cpp new file mode 100644 index 00000000000..1c4fd22b959 --- /dev/null +++ b/mozilla/modules/plugin/src/nsplugin.cpp @@ -0,0 +1,1010 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//////////////////////////////////////////////////////////////////////////////// +// IMPLEMENTATION OF NETSCAPE COMMUNICATOR PLUGINS (NEW C++ API). +// +// This superscedes the old plugin API (npapi.h, npupp.h), and +// eliminates the need for glue files: npunix.c, npwin.cpp and npmac.cpp. +// Correspondences to the old API are shown throughout the file. +//////////////////////////////////////////////////////////////////////////////// + +#include "npglue.h" + +#ifdef OJI +#include "nsIPlug.h" +#include "jvmmgr.h" +#endif +#include "plstr.h" /* PL_strcasecmp */ + +#include "xp_mem.h" +#include "xpassert.h" + +#ifdef XP_MAC +#include "MacMemAllocator.h" +#include "asyncCursors.h" +#endif + +#include "intl_csi.h" + +static NS_DEFINE_IID(kIJRIEnvIID, NS_IJRIENV_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +static NS_DEFINE_IID(kIPluginManager2IID, NS_IPLUGINMANAGER2_IID); +static NS_DEFINE_IID(kIJNIEnvIID, NS_IJNIENV_IID); +static NS_DEFINE_IID(kILiveConnectPluginInstancePeerIID, NS_ILIVECONNECTPLUGININSTANCEPEER_IID); +static NS_DEFINE_IID(kPluginInstancePeerCID, NS_PLUGININSTANCEPEER_CID); +static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); +static NS_DEFINE_IID(kIPluginInstancePeer2IID, NS_IPLUGININSTANCEPEER2_IID); +static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID); +static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); +static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID); +static NS_DEFINE_IID(kISeekablePluginStreamPeerIID, NS_ISEEKABLEPLUGINSTREAMPEER_IID); +static NS_DEFINE_IID(kIPluginStreamPeerIID, NS_IPLUGINSTREAMPEER_IID); +static NS_DEFINE_IID(kIPluginStreamPeer2IID, NS_IPLUGINSTREAMPEER2_IID); +static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID); + +//////////////////////////////////////////////////////////////////////////////// +// THINGS IMPLEMENTED BY THE BROWSER... +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager Interface +// This interface defines the minimum set of functionality that a plugin +// manager will support if it implements plugins. Plugin implementations can +// QueryInterface to determine if a plugin manager implements more specific +// APIs for the plugin to use. + +nsPluginManager* thePluginManager = NULL; + +nsPluginManager::nsPluginManager(nsISupports* outer) + : fJVMMgr(NULL) +{ + NS_INIT_AGGREGATED(outer); +} + +nsPluginManager::~nsPluginManager(void) +{ + fJVMMgr->Release(); + fJVMMgr = NULL; +} + +NS_IMPL_AGGREGATED(nsPluginManager); + +#include "nsRepository.h" + +NS_METHOD +nsPluginManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) +{ + if (outer && !aIID.Equals(kISupportsIID)) + return NS_NOINTERFACE; // XXX right error? + nsPluginManager* mgr = new nsPluginManager(outer); + nsresult result = mgr->QueryInterface(aIID, aInstancePtr); + if (result != NS_OK) { + delete mgr; + } + return result; +} + +NS_METHOD_(void) +nsPluginManager::ReloadPlugins(PRBool reloadPages) +{ + npn_reloadplugins(reloadPages); +} + +NS_METHOD_(void*) +nsPluginManager::MemAlloc(PRUint32 size) +{ + return XP_ALLOC(size); +} + +NS_METHOD_(void) +nsPluginManager::MemFree(void* ptr) +{ + (void)XP_FREE(ptr); +} + +NS_METHOD_(PRUint32) +nsPluginManager::MemFlush(PRUint32 size) +{ +#ifdef XP_MAC + /* Try to free some memory and return the amount we freed. */ + if (CallCacheFlushers(size)) + return size; +#endif + return 0; +} + +NS_METHOD_(const char*) +nsPluginManager::UserAgent(void) +{ + return npn_useragent(NULL); // we don't really need an npp here +} + +NS_METHOD +nsPluginManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIPluginManagerIID) || + aIID.Equals(kIPluginManager2IID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) this; + AddRef(); + return NS_OK; + } +#if 0 // Browser interface should be JNI from now on. Hence all new code + // should be written using JNI. sudu. + if (aIID.Equals(kIJRIEnvIID)) { + // XXX Need to implement ISupports for JRIEnv + *aInstancePtr = (void*) ((nsISupports*)npn_getJavaEnv()); +// AddRef(); // XXX should the plugin instance peer and the env be linked? + return NS_OK; + } +#endif + if (aIID.Equals(kIJNIEnvIID)) { + // XXX Need to implement ISupports for JNIEnv + *aInstancePtr = (void*) ((nsISupports*)npn_getJavaEnv(NULL)); //=-= Fix this to return a Interface XXX need JNI version +// AddRef(); // XXX should the plugin instance peer and the env be linked? + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) ((nsISupports*)this); + AddRef(); + return NS_OK; + } + // Aggregates... + nsIJVMManager* jvmMgr = GetJVMMgr(aIID); + if (jvmMgr) { + *aInstancePtr = (void*) ((nsISupports*)jvmMgr); + return NS_OK; + } + return NS_NOINTERFACE; +} + +nsIJVMManager* +nsPluginManager::GetJVMMgr(const nsIID& aIID) +{ + nsIJVMManager* result = NULL; +#ifdef OJI + if (fJVMMgr == NULL) { + // The plugin manager is the outer of the JVM manager + if (nsJVMMgr::Create(this, kISupportsIID, (void**)&fJVMMgr) != NS_OK) + return NULL; + } + if (fJVMMgr->QueryInterface(aIID, (void**)&result) != NS_OK) + return NULL; +#endif + return result; +} + +NS_METHOD_(nsPluginError) +nsPluginManager::GetURL(nsISupports* peer, const char* url, const char* target, void* notifyData, + const char* altHost, const char* referrer, + PRBool forceJSEnabled) +{ + nsPluginError rslt; + nsPluginInstancePeer* instPeer; + NPP npp = NULL; + if (peer->QueryInterface(kPluginInstancePeerCID, (void**)&instPeer) == NS_OK) + npp = instPeer->GetNPP(); + rslt = (nsPluginError)np_geturlinternal(npp, url, target, altHost, referrer, + forceJSEnabled, notifyData != NULL, notifyData); + if (npp) + instPeer->Release(); + return rslt; +} + +NS_METHOD_(nsPluginError) +nsPluginManager::PostURL(nsISupports* peer, const char* url, const char* target, PRUint32 bufLen, + const char* buf, PRBool file, void* notifyData, + const char* altHost, const char* referrer, + PRBool forceJSEnabled, + PRUint32 postHeadersLength, const char* postHeaders) +{ + nsPluginError rslt; + nsPluginInstancePeer* instPeer; + NPP npp = NULL; + if (peer->QueryInterface(kPluginInstancePeerCID, (void**)&instPeer) == NS_OK) + npp = instPeer->GetNPP(); + rslt = (nsPluginError)np_posturlinternal(npp, url, target, altHost, referrer, forceJSEnabled, + bufLen, buf, file, notifyData != NULL, notifyData); + if (npp) + instPeer->Release(); + return rslt; +} + +NS_METHOD_(void) +nsPluginManager::BeginWaitCursor(void) +{ + if (fWaiting == 0) { +#ifdef XP_PC + fOldCursor = (void*)GetCursor(); + HCURSOR newCursor = LoadCursor(NULL, IDC_WAIT); + if (newCursor) + SetCursor(newCursor); +#endif +#ifdef XP_MAC + startAsyncCursors(); +#endif + } + fWaiting++; +} + +NS_METHOD_(void) +nsPluginManager::EndWaitCursor(void) +{ + fWaiting--; + if (fWaiting == 0) { +#ifdef XP_PC + if (fOldCursor) + SetCursor((HCURSOR)fOldCursor); +#endif +#ifdef XP_MAC + stopAsyncCursors(); +#endif + fOldCursor = NULL; + } +} + +NS_METHOD_(PRBool) +nsPluginManager::SupportsURLProtocol(const char* protocol) +{ + int type = NET_URL_Type(protocol); + return (PRBool)(type != 0); +} + +//////////////////////////////////////////////////////////////////////////////// +// File Utilities Interface + +nsFileUtilities::nsFileUtilities(nsISupports* outer) + : fProgramPath(NULL) +{ + NS_INIT_AGGREGATED(outer); +} + +nsFileUtilities::~nsFileUtilities(void) +{ +} + +NS_IMPL_AGGREGATED(nsFileUtilities); + +NS_METHOD +nsFileUtilities::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIFileUtilitiesIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + + +NS_METHOD_(const char*) +nsFileUtilities::GetProgramPath(void) +{ + return fProgramPath; +} + +NS_METHOD_(const char*) +nsFileUtilities::GetTempDirPath(void) +{ + // XXX I don't need a static really, the browser holds the tempDir name + // as a static string -- it's just the XP_TempDirName that strdups it. + static const char* tempDirName = NULL; + if (tempDirName == NULL) + tempDirName = XP_TempDirName(); + return tempDirName; +} + +NS_METHOD +nsFileUtilities::GetFileName(const char* fn, FileNameType type, + char* resultBuf, PRUint32 bufLen) +{ + // XXX This should be rewritten so that we don't have to malloc the name. + XP_FileType filetype; + + if (type == SIGNED_APPLET_DBNAME) + filetype = xpSignedAppletDB; + else if (type == TEMP_FILENAME) + filetype = xpTemporary; + else + return NS_ERROR_ILLEGAL_VALUE; + + char* tempName = WH_FileName(fn, filetype); + if (tempName == NULL) + return NS_ERROR_OUT_OF_MEMORY; + XP_STRNCPY_SAFE(resultBuf, tempName, bufLen); + XP_FREE(tempName); + return NS_OK; +} + +NS_METHOD +nsFileUtilities::NewTempFileName(const char* prefix, char* resultBuf, PRUint32 bufLen) +{ + // XXX This should be rewritten so that we don't have to malloc the name. + char* tempName = WH_TempName(xpTemporary, prefix); + if (tempName == NULL) + return NS_ERROR_OUT_OF_MEMORY; + XP_STRNCPY_SAFE(resultBuf, tempName, bufLen); + XP_FREE(tempName); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Instance Peer Interface + +nsPluginInstancePeer::nsPluginInstancePeer(NPP npp) + : npp(npp), userInst(NULL) +{ + NS_INIT_AGGREGATED(NULL); + tagInfo = new nsPluginTagInfo(npp); + tagInfo->AddRef(); +} + +nsPluginInstancePeer::~nsPluginInstancePeer(void) +{ + tagInfo->Release(); + tagInfo = NULL; +} + +NS_IMPL_AGGREGATED(nsPluginInstancePeer); + +NS_METHOD +nsPluginInstancePeer::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kILiveConnectPluginInstancePeerIID) || + aIID.Equals(kIPluginInstancePeer2IID) || + aIID.Equals(kIPluginInstancePeerIID) || + aIID.Equals(kPluginInstancePeerCID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)(nsIPluginInstancePeer*)this; + AddRef(); + return NS_OK; + } + return tagInfo->QueryInterface(aIID, aInstancePtr); +} + +NS_METHOD_(nsMIMEType) +nsPluginInstancePeer::GetMIMEType(void) +{ + np_instance* instance = (np_instance*)npp->ndata; + return instance->typeString; +} + +NS_METHOD_(nsPluginType) +nsPluginInstancePeer::GetMode(void) +{ + np_instance* instance = (np_instance*)npp->ndata; + return (nsPluginType)instance->type; +} + +NS_METHOD_(nsPluginError) +nsPluginInstancePeer::NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result) +{ + NPStream* pstream; + nsPluginError err = (nsPluginError) + npn_newstream(npp, (char*)type, (char*)target, &pstream); + if (err != nsPluginError_NoError) + return err; + *result = new nsPluginManagerStream(npp, pstream); + return nsPluginError_NoError; +} + +NS_METHOD_(void) +nsPluginInstancePeer::ShowStatus(const char* message) +{ + npn_status(npp, message); +} + +NS_METHOD_(nsPluginError) +nsPluginInstancePeer::GetValue(nsPluginManagerVariable variable, void *value) +{ + return (nsPluginError)npn_getvalue(npp, (NPNVariable)variable, value); +} + +NS_METHOD_(nsPluginError) +nsPluginInstancePeer::SetValue(nsPluginVariable variable, void *value) +{ + return (nsPluginError)npn_setvalue(npp, (NPPVariable)variable, value); +} + +NS_METHOD_(void) +nsPluginInstancePeer::InvalidateRect(nsRect *invalidRect) +{ + npn_invalidaterect(npp, (NPRect*)invalidRect); +} + +NS_METHOD_(void) +nsPluginInstancePeer::InvalidateRegion(nsRegion invalidRegion) +{ + npn_invalidateregion(npp, invalidRegion); +} + +NS_METHOD_(void) +nsPluginInstancePeer::ForceRedraw(void) +{ + npn_forceredraw(npp); +} + +NS_METHOD_(void) +nsPluginInstancePeer::RegisterWindow(void* window) +{ + npn_registerwindow(npp, window); +} + +NS_METHOD_(void) +nsPluginInstancePeer::UnregisterWindow(void* window) +{ + npn_unregisterwindow(npp, window); +} + +NS_METHOD_(PRInt16) +nsPluginInstancePeer::AllocateMenuID(PRBool isSubmenu) +{ +#ifdef XP_MAC + return npn_allocateMenuID(npp, isSubmenu); +#else + return -1; +#endif +} + +NS_METHOD_(PRBool) +nsPluginInstancePeer::Tickle(void) +{ +#ifdef XP_MAC + // XXX add something for the Mac... +#endif + return PR_TRUE; +} + +NS_METHOD_(jref) +nsPluginInstancePeer::GetJavaPeer(void) +{ + return npn_getJavaPeer(npp); +} + +extern "C" JSContext *lm_crippled_context; /* XXX kill me */ + +JSContext * +nsPluginInstancePeer::GetJSContext(void) +{ + MWContext *pMWCX = GetMWContext(); + JSContext *pJSCX = NULL; + if (!pMWCX || (pMWCX->type != MWContextBrowser && pMWCX->type != MWContextPane)) + { + return 0; + } + if( pMWCX->mocha_context != NULL) + { + pJSCX = pMWCX->mocha_context; + } + else + { + pJSCX = lm_crippled_context; + } + return pJSCX; +} + +MWContext * +nsPluginInstancePeer::GetMWContext(void) +{ + np_instance* instance = (np_instance*) npp->ndata; + MWContext *pMWCX = instance->cx; + + return pMWCX; +} + + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Tag Info Interface + +nsPluginTagInfo::nsPluginTagInfo(NPP npp) + : npp(npp), fUniqueID(0), fJVMPluginTagInfo(NULL) +{ + NS_INIT_AGGREGATED(NULL); +} + +nsPluginTagInfo::~nsPluginTagInfo(void) +{ +} + +NS_IMPL_AGGREGATED(nsPluginTagInfo); + +NS_METHOD +nsPluginTagInfo::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kIPluginTagInfo2IID) || + aIID.Equals(kIPluginTagInfoIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)this; + AddRef(); + return NS_OK; + } +#ifdef OJI + // Aggregates... + if (fJVMPluginTagInfo == NULL) { + np_instance* instance = (np_instance*) npp->ndata; + MWContext* cx = instance->cx; + nsresult result = + nsJVMPluginTagInfo::Create((nsISupports*)this, kISupportsIID, + (void**)&fJVMPluginTagInfo, this); + if (result != NS_OK) return result; + } +#endif + return fJVMPluginTagInfo->QueryInterface(aIID, aInstancePtr); +} + +static char* empty_list[] = { "", NULL }; + +NS_METHOD_(nsPluginError) +nsPluginTagInfo::GetAttributes(PRUint16& n, + const char*const*& names, + const char*const*& values) +{ + np_instance* instance = (np_instance*)npp->ndata; + +#if 0 + // defense + PR_ASSERT( 0 != names ); + PR_ASSERT( 0 != values ); + if( 0 == names || 0 == values ) + return 0; +#endif + + if (instance->type == NP_EMBED) { + np_data* ndata = (np_data*)instance->app->np_data; + +#ifdef OJI + names = (const char*const*)ndata->lo_struct->attributes.names; + values = (const char*const*)ndata->lo_struct->attributes.values; + n = (PRUint16)ndata->lo_struct->attributes.n; +#else + // XXX I think all the parameters and attributes just get + // munged together under MOZ_JAVA... + names = (const char*const*) ndata->lo_struct->attribute_list; + values = (const char*const*) ndata->lo_struct->value_list; + n = (PRUint16) ndata->lo_struct->attribute_cnt; +#endif + + return nsPluginError_NoError; + } else { + static char _name[] = "PALETTE"; + static char* _names[1]; + + static char _value[] = "foreground"; + static char* _values[1]; + + _names[0] = _name; + _values[0] = _value; + + names = (const char*const*) _names; + values = (const char*const*) _values; + n = 1; + + return nsPluginError_NoError; + } + + // random, sun-spot induced error + PR_ASSERT( 0 ); + + n = 0; + // const char* const* empty_list = { { '\0' } }; + names = values = (const char*const*)empty_list; + + return nsPluginError_GenericError; +} + +NS_METHOD_(const char*) +nsPluginTagInfo::GetAttribute(const char* name) +{ + PRUint16 nAttrs, i; + const char*const* names; + const char*const* values; + + if( NPCallFailed( GetAttributes( nAttrs, names, values )) ) + return 0; + + for( i = 0; i < nAttrs; i++ ) { + if( PL_strcasecmp( name, names[i] ) == 0 ) + return values[i]; + } + + return 0; +} + +NS_METHOD_(nsPluginTagType) +nsPluginTagInfo::GetTagType(void) +{ +#ifdef XXX + switch (GetLayoutElement()->lo_element.type) { + case LO_JAVA: + return nsPluginTagType_Applet; + case LO_EMBED: + return nsPluginTagType_Embed; + case LO_OBJECT: + return nsPluginTagType_Object; + + default: + return nsPluginTagType_Unknown; + } +#endif + return nsPluginTagType_Unknown; +} + +NS_METHOD_(const char *) +nsPluginTagInfo::GetTagText(void) +{ + // XXX + return NULL; +} + +NS_METHOD_(nsPluginError) +nsPluginTagInfo::GetParameters(PRUint16& n, + const char*const*& names, + const char*const*& values) +{ + np_instance* instance = (np_instance*)npp->ndata; + + if (instance->type == NP_EMBED) { + np_data* ndata = (np_data*)instance->app->np_data; + +#ifdef OJI + names = (const char*const*)ndata->lo_struct->parameters.names; + values = (const char*const*)ndata->lo_struct->parameters.values; + n = (PRUint16)ndata->lo_struct->parameters.n; +#else + // XXX I think all the parameters and attributes just get + // munged together under MOZ_JAVA... + names = (const char*const*) ndata->lo_struct->attribute_list; + values = (const char*const*) ndata->lo_struct->value_list; + n = (PRUint16)ndata->lo_struct->attribute_cnt; +#endif + + return nsPluginError_NoError; + } else { + static char _name[] = "PALETTE"; + static char* _names[1]; + + static char _value[] = "foreground"; + static char* _values[1]; + + _names[0] = _name; + _values[0] = _value; + + names = (const char*const*) _names; + values = (const char*const*) _values; + n = 1; + + return nsPluginError_NoError; + } + + // random, sun-spot induced error + PR_ASSERT( 0 ); + + n = 0; + // static const char* const* empty_list = { { '\0' } }; + names = values = (const char*const*)empty_list; + + return nsPluginError_GenericError; +} + +NS_METHOD_(const char*) +nsPluginTagInfo::GetParameter(const char* name) +{ + PRUint16 nParams, i; + const char*const* names; + const char*const* values; + + if( NPCallFailed( GetParameters( nParams, names, values )) ) + return 0; + + for( i = 0; i < nParams; i++ ) { + if( PL_strcasecmp( name, names[i] ) == 0 ) + return values[i]; + } + + return 0; +} + +NS_METHOD_(const char*) +nsPluginTagInfo::GetDocumentBase(void) +{ + return (const char*)GetLayoutElement()->base_url; +} + +NS_METHOD_(const char*) +nsPluginTagInfo::GetDocumentEncoding(void) +{ + np_instance* instance = (np_instance*) npp->ndata; + MWContext* cx = instance->cx; + INTL_CharSetInfo info = LO_GetDocumentCharacterSetInfo(cx); + int16 doc_csid = INTL_GetCSIWinCSID(info); + return INTL_CharSetIDToJavaCharSetName(doc_csid); +} + +NS_METHOD_(const char*) +nsPluginTagInfo::GetAlignment(void) +{ + int alignment = GetLayoutElement()->alignment; + + const char* cp; + switch (alignment) { + case LO_ALIGN_CENTER: cp = "abscenter"; break; + case LO_ALIGN_LEFT: cp = "left"; break; + case LO_ALIGN_RIGHT: cp = "right"; break; + case LO_ALIGN_TOP: cp = "texttop"; break; + case LO_ALIGN_BOTTOM: cp = "absbottom"; break; + case LO_ALIGN_NCSA_CENTER: cp = "center"; break; + case LO_ALIGN_NCSA_BOTTOM: cp = "bottom"; break; + case LO_ALIGN_NCSA_TOP: cp = "top"; break; + default: cp = "baseline"; break; + } + return cp; +} + +NS_METHOD_(PRUint32) +nsPluginTagInfo::GetWidth(void) +{ + LO_CommonPluginStruct* lo = GetLayoutElement(); + return lo->width ? lo->width : 50; +} + +NS_METHOD_(PRUint32) +nsPluginTagInfo::GetHeight(void) +{ + LO_CommonPluginStruct* lo = GetLayoutElement(); + return lo->height ? lo->height : 50; +} + +NS_METHOD_(PRUint32) +nsPluginTagInfo::GetBorderVertSpace(void) +{ + return GetLayoutElement()->border_vert_space; +} + +NS_METHOD_(PRUint32) +nsPluginTagInfo::GetBorderHorizSpace(void) +{ + return GetLayoutElement()->border_horiz_space; +} + +NS_METHOD_(PRUint32) +nsPluginTagInfo::GetUniqueID(void) +{ + if (fUniqueID == 0) { + np_instance* instance = (np_instance*) npp->ndata; + MWContext* cx = instance->cx; + History_entry* history_element = SHIST_GetCurrent(&cx->hist); + if (history_element) { + fUniqueID = history_element->unique_id; + } else { + /* + ** XXX What to do? This can happen for instance when printing a + ** mail message that contains an applet. + */ + static int32 unique_number; + fUniqueID = --unique_number; + } + PR_ASSERT(fUniqueID != 0); + } + return fUniqueID; +} + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Manager Stream Interface + +nsPluginManagerStream::nsPluginManagerStream(NPP npp, NPStream* pstr) + : npp(npp), pstream(pstr) +{ + NS_INIT_REFCNT(); + // XXX get rid of the npp instance variable if this is true + PR_ASSERT(npp == ((np_stream*)pstr->ndata)->instance->npp); +} + +nsPluginManagerStream::~nsPluginManagerStream(void) +{ +} + +NS_METHOD +nsPluginManagerStream::Close(void) +{ + NPError err = npn_destroystream(npp, pstream, nsPluginReason_Done); + return (nsresult)err; +} + +NS_METHOD_(PRInt32) +nsPluginManagerStream::Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, + nsresult *errorResult) +{ + PRInt32 rslt = npn_write(npp, pstream, aCount, (void*)(aBuf + aOffset)); + if (rslt == -1) + *errorResult = NS_ERROR_FAILURE; // XXX what should this be? + return rslt; +} + +NS_IMPL_QUERY_INTERFACE(nsPluginManagerStream, kIOutputStreamIID); +NS_IMPL_ADDREF(nsPluginManagerStream); +NS_IMPL_RELEASE(nsPluginManagerStream); + +//////////////////////////////////////////////////////////////////////////////// +// Plugin Stream Peer Interface + +nsPluginStreamPeer::nsPluginStreamPeer(URL_Struct *urls, np_stream *stream) + : userStream(NULL), urls(urls), stream(stream), + reason(nsPluginReason_NoReason) +{ + NS_INIT_REFCNT(); +} + +nsPluginStreamPeer::~nsPluginStreamPeer(void) +{ +#if 0 + NPError err = npn_destroystream(stream->instance->npp, stream->pstream, reason); + PR_ASSERT(err == nsPluginError_NoError); +#endif +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetURL(void) +{ + return stream->pstream->url; +} + +NS_METHOD_(PRUint32) +nsPluginStreamPeer::GetEnd(void) +{ + return stream->pstream->end; +} + +NS_METHOD_(PRUint32) +nsPluginStreamPeer::GetLastModified(void) +{ + return stream->pstream->lastmodified; +} + +NS_METHOD_(void*) +nsPluginStreamPeer::GetNotifyData(void) +{ + return stream->pstream->notifyData; +} + +NS_METHOD_(nsPluginReason) +nsPluginStreamPeer::GetReason(void) +{ + return reason; +} + +NS_METHOD_(nsMIMEType) +nsPluginStreamPeer::GetMIMEType(void) +{ + return (nsMIMEType)urls->content_type; +} + +NS_METHOD_(PRUint32) +nsPluginStreamPeer::GetContentLength(void) +{ + return urls->content_length; +} +#if 0 +NS_METHOD_(const char*) +nsPluginStreamPeer::GetContentEncoding(void) +{ + return urls->content_encoding; +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetCharSet(void) +{ + return urls->charset; +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetBoundary(void) +{ + return urls->boundary; +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetContentName(void) +{ + return urls->content_name; +} + +NS_METHOD_(time_t) +nsPluginStreamPeer::GetExpires(void) +{ + return urls->expires; +} + +NS_METHOD_(time_t) +nsPluginStreamPeer::GetLastModified(void) +{ + return urls->last_modified; +} + +NS_METHOD_(time_t) +nsPluginStreamPeer::GetServerDate(void) +{ + return urls->server_date; +} + +NS_METHOD_(NPServerStatus) +nsPluginStreamPeer::GetServerStatus(void) +{ + return urls->server_status; +} +#endif +NS_METHOD_(PRUint32) +nsPluginStreamPeer::GetHeaderFieldCount(void) +{ + return urls->all_headers.empty_index; +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetHeaderFieldKey(PRUint32 index) +{ + return urls->all_headers.key[index]; +} + +NS_METHOD_(const char*) +nsPluginStreamPeer::GetHeaderField(PRUint32 index) +{ + return urls->all_headers.value[index]; +} + +NS_METHOD_(nsPluginError) +nsPluginStreamPeer::RequestRead(nsByteRange* rangeList) +{ + return (nsPluginError)npn_requestread(stream->pstream, + (NPByteRange*)rangeList); +} + +NS_IMPL_ADDREF(nsPluginStreamPeer); +NS_IMPL_RELEASE(nsPluginStreamPeer); + +NS_METHOD +nsPluginStreamPeer::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if ((stream->seekable && aIID.Equals(kISeekablePluginStreamPeerIID)) || + aIID.Equals(kIPluginStreamPeer2IID) || + aIID.Equals(kIPluginStreamPeerIID) || + aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)(nsIPluginStreamPeer2*)this; + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +////////////////////////////////////////////////////////////////////////////////