|
|
@@ -21,7 +21,10 @@
|
|
|
#endif
|
|
|
|
|
|
ofstream logfile;
|
|
|
-bool logfile_is_open = false;
|
|
|
+
|
|
|
+NPNetscapeFuncs *browser;
|
|
|
+
|
|
|
+static bool logfile_is_open = false;
|
|
|
static void
|
|
|
open_logfile() {
|
|
|
if (!logfile_is_open) {
|
|
|
@@ -34,11 +37,100 @@ open_logfile() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NP_Initialize
|
|
|
+// Description: This function is called (almost) before any other
|
|
|
+// function, to ask the plugin to initialize itself and
|
|
|
+// to send the pointers to the browser control
|
|
|
+// functions. Also see NP_GetEntryPoints.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+#ifdef _WIN32
|
|
|
+NPError OSCALL
|
|
|
+NP_Initialize(NPNetscapeFuncs *browserFuncs)
|
|
|
+#else
|
|
|
+// On Mac, the API specifies this second parameter is included, but it
|
|
|
+// lies. We actually don't get a second parameter on Mac, but we have
|
|
|
+// to put it here to make the compiler happy.
|
|
|
+NPError OSCALL
|
|
|
+NP_Initialize(NPNetscapeFuncs *browserFuncs,
|
|
|
+ NPPluginFuncs *pluginFuncs)
|
|
|
+#endif
|
|
|
+{
|
|
|
+ // save away browser functions
|
|
|
+ browser = browserFuncs;
|
|
|
|
|
|
-// structure containing pointers to functions implemented by the browser
|
|
|
-static NPNetscapeFuncs *browser;
|
|
|
+ open_logfile();
|
|
|
+ logfile << "initializing\n" << flush;
|
|
|
|
|
|
-// Called to create a new instance of the plugin
|
|
|
+ logfile << "browserFuncs = " << browserFuncs << "\n" << flush;
|
|
|
+
|
|
|
+#ifdef _WIN32
|
|
|
+ string plugin_location = "c:/cygwin/home/drose/player/direct/built/lib/p3d_plugin.dll";
|
|
|
+#else
|
|
|
+ string plugin_location = "/Users/drose/player/direct/built/lib/p3d_plugin.dylib";
|
|
|
+#endif
|
|
|
+
|
|
|
+ if (!load_plugin(plugin_location.c_str())) {
|
|
|
+ logfile << "couldn't load plugin\n" << flush;
|
|
|
+ return NPERR_INVALID_PLUGIN_ERROR;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NPERR_NO_ERROR;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NP_GetEntryPoints
|
|
|
+// Description: This method is extracted directly from the DLL and
|
|
|
+// called at initialization time by the browser, either
|
|
|
+// before or after NP_Initialize, to retrieve the
|
|
|
+// pointers to the rest of the plugin functions that are
|
|
|
+// not exported from the DLL.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+NPError OSCALL
|
|
|
+NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
|
|
|
+ open_logfile();
|
|
|
+ logfile << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n"
|
|
|
+ << flush;
|
|
|
+ pluginFuncs->version = 11;
|
|
|
+ pluginFuncs->size = sizeof(pluginFuncs);
|
|
|
+ pluginFuncs->newp = NPP_New;
|
|
|
+ pluginFuncs->destroy = NPP_Destroy;
|
|
|
+ pluginFuncs->setwindow = NPP_SetWindow;
|
|
|
+ pluginFuncs->newstream = NPP_NewStream;
|
|
|
+ pluginFuncs->destroystream = NPP_DestroyStream;
|
|
|
+ pluginFuncs->asfile = NPP_StreamAsFile;
|
|
|
+ pluginFuncs->writeready = NPP_WriteReady;
|
|
|
+ pluginFuncs->write = NPP_Write;
|
|
|
+ pluginFuncs->print = NPP_Print;
|
|
|
+ pluginFuncs->event = NPP_HandleEvent;
|
|
|
+ pluginFuncs->urlnotify = NPP_URLNotify;
|
|
|
+ pluginFuncs->getvalue = NPP_GetValue;
|
|
|
+ pluginFuncs->setvalue = NPP_SetValue;
|
|
|
+
|
|
|
+ return NPERR_NO_ERROR;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NP_Shutdown
|
|
|
+// Description: This function is called when the browser is done with
|
|
|
+// the plugin; it asks the plugin to unload itself and
|
|
|
+// free all used resources.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+NPError OSCALL
|
|
|
+NP_Shutdown(void) {
|
|
|
+ logfile << "shutdown\n" << flush;
|
|
|
+ unload_plugin();
|
|
|
+
|
|
|
+ // Not clear whether there's a return value or not. Some versions
|
|
|
+ // of the API have different opinions on this.
|
|
|
+ return NPERR_NO_ERROR;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_New
|
|
|
+// Description: Called by the browser to create a new instance of the
|
|
|
+// plugin.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,
|
|
|
int16 argc, char *argn[], char *argv[], NPSavedData *saved) {
|
|
|
@@ -58,7 +150,11 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,
|
|
|
return NPERR_NO_ERROR;
|
|
|
}
|
|
|
|
|
|
-// Called to destroy an instance of the plugin
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_Destroy
|
|
|
+// Description: Called by the browser to destroy an instance of the
|
|
|
+// plugin previously created with NPP_New.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_Destroy(NPP instance, NPSavedData **save) {
|
|
|
logfile << "destroy instance\n" << flush;
|
|
|
@@ -69,7 +165,14 @@ NPP_Destroy(NPP instance, NPSavedData **save) {
|
|
|
return NPERR_NO_ERROR;
|
|
|
}
|
|
|
|
|
|
-// Called to update a plugin instances's NPWindow
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_SetWindow
|
|
|
+// Description: Called by the browser to inform the instance of its
|
|
|
+// window size and placement. This is called initially
|
|
|
+// to create the window, and may be called subsequently
|
|
|
+// when the window needs to be moved. It may be called
|
|
|
+// redundantly.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_SetWindow(NPP instance, NPWindow *window) {
|
|
|
logfile << "SetWindow " << window->x << ", " << window->y
|
|
|
@@ -84,133 +187,127 @@ NPP_SetWindow(NPP instance, NPWindow *window) {
|
|
|
parent_window._hwnd = (HWND)(window->window);
|
|
|
#endif
|
|
|
|
|
|
- P3D_window_type window_type = P3D_WT_embedded;
|
|
|
-
|
|
|
P3D_instance_setup_window
|
|
|
- (inst, window_type,
|
|
|
+ (inst, P3D_WT_embedded,
|
|
|
window->x, window->y, window->width, window->height,
|
|
|
parent_window);
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_NewStream
|
|
|
+// Description: Called by the browser when a new data stream is
|
|
|
+// created, usually in response to a geturl request; but
|
|
|
+// it is also called initially to supply the data in the
|
|
|
+// data or src element. The plugin must specify how it
|
|
|
+// can receive the stream.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
|
|
|
NPBool seekable, uint16 *stype) {
|
|
|
+ logfile << "NewStream " << type << ", " << stream->url
|
|
|
+ << ", " << stream->end << "\n" << flush;
|
|
|
*stype = NP_ASFILEONLY;
|
|
|
return NPERR_NO_ERROR;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_DestroyStream
|
|
|
+// Description: Called by the browser to mark the end of a stream
|
|
|
+// created with NewStream.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) {
|
|
|
+ logfile << "DestroyStream\n" << flush;
|
|
|
return NPERR_NO_ERROR;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_WriteReady
|
|
|
+// Description: Called by the browser to ask how many bytes it can
|
|
|
+// deliver for a stream.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
int32
|
|
|
NPP_WriteReady(NPP instance, NPStream *stream) {
|
|
|
+ logfile << "WriteReady\n";
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_Write
|
|
|
+// Description: Called by the browser to deliver bytes for the
|
|
|
+// stream; the plugin should return the number of bytes
|
|
|
+// consumed.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
int32
|
|
|
NPP_Write(NPP instance, NPStream *stream, int32 offset,
|
|
|
int32 len, void *buffer) {
|
|
|
+ logfile << "Write\n";
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_StreamAsFile
|
|
|
+// Description: Called by the browser to report the filename that
|
|
|
+// contains the fully-downloaded stream, if
|
|
|
+// NP_ASFILEONLY was specified by the plugin in
|
|
|
+// NPP_NewStream.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
void
|
|
|
NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) {
|
|
|
+ logfile << "StreamAsFile: " << fname << "\n" << flush;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_Print
|
|
|
+// Description: Called by the browser when the user attempts to print
|
|
|
+// the page containing the plugin instance.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
void
|
|
|
NPP_Print(NPP instance, NPPrint *platformPrint) {
|
|
|
+ logfile << "Print\n";
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_HandleEvent
|
|
|
+// Description: Called by the browser to inform the plugin of OS
|
|
|
+// window events.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
int16
|
|
|
NPP_HandleEvent(NPP instance, void *event) {
|
|
|
+ logfile << "HandleEvent\n";
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_URLNotify
|
|
|
+// Description: Called by the browser to inform the plugin of a
|
|
|
+// completed URL request.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
void
|
|
|
NPP_URLNotify(NPP instance, const char *url,
|
|
|
NPReason reason, void *notifyData) {
|
|
|
+ logfile << "URLNotify: " << url << "\n";
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_GetValue
|
|
|
+// Description: Called by the browser to query specific information
|
|
|
+// from the plugin.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
|
|
|
+ logfile << "GetValue " << variable << "\n";
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: NPP_URLNotify
|
|
|
+// Description: Called by the browser to update a scriptable value.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
NPError
|
|
|
NPP_SetValue(NPP instance, NPNVariable variable, void *value) {
|
|
|
+ logfile << "SetValue " << variable << "\n";
|
|
|
return NPERR_GENERIC_ERROR;
|
|
|
}
|
|
|
-
|
|
|
-// Symbol called once by the browser to initialize the plugin
|
|
|
-#ifdef _WIN32
|
|
|
-NPError OSCALL
|
|
|
-NP_Initialize(NPNetscapeFuncs *browserFuncs)
|
|
|
-#else
|
|
|
-// On Mac, the API specifies this second parameter is included, but it
|
|
|
-// lies. We actually don't get a second parameter on Mac, but we have
|
|
|
-// to put it here to make the compiler happy.
|
|
|
-NPError OSCALL
|
|
|
-NP_Initialize(NPNetscapeFuncs *browserFuncs,
|
|
|
- NPPluginFuncs *pluginFuncs)
|
|
|
-#endif
|
|
|
-{
|
|
|
- // save away browser functions
|
|
|
- browser = browserFuncs;
|
|
|
-
|
|
|
- open_logfile();
|
|
|
- logfile << "initializing\n" << flush;
|
|
|
-
|
|
|
- logfile << "browserFuncs = " << browserFuncs << "\n" << flush;
|
|
|
-
|
|
|
-#ifdef _WIN32
|
|
|
- string plugin_location = "c:/cygwin/home/drose/player/direct/built/lib/libp3d_plugin.dll";
|
|
|
-#else
|
|
|
- string plugin_location = "/Users/drose/player/direct/built/lib/libp3d_plugin.dylib";
|
|
|
-#endif
|
|
|
-
|
|
|
- if (!load_plugin(plugin_location.c_str())) {
|
|
|
- logfile << "couldn't load plugin\n" << flush;
|
|
|
- return NPERR_INVALID_PLUGIN_ERROR;
|
|
|
- }
|
|
|
-
|
|
|
- return NPERR_NO_ERROR;
|
|
|
-}
|
|
|
-
|
|
|
-// Symbol called by the browser to get the plugin's function list
|
|
|
-NPError OSCALL
|
|
|
-NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) {
|
|
|
- open_logfile();
|
|
|
- logfile << "NP_GetEntryPoints, pluginFuncs = " << pluginFuncs << "\n"
|
|
|
- << flush;
|
|
|
- pluginFuncs->version = 11;
|
|
|
- pluginFuncs->size = sizeof(pluginFuncs);
|
|
|
- pluginFuncs->newp = NPP_New;
|
|
|
- pluginFuncs->destroy = NPP_Destroy;
|
|
|
- pluginFuncs->setwindow = NPP_SetWindow;
|
|
|
- pluginFuncs->newstream = NPP_NewStream;
|
|
|
- pluginFuncs->destroystream = NPP_DestroyStream;
|
|
|
- pluginFuncs->asfile = NPP_StreamAsFile;
|
|
|
- pluginFuncs->writeready = NPP_WriteReady;
|
|
|
- pluginFuncs->write = NPP_Write;
|
|
|
- pluginFuncs->print = NPP_Print;
|
|
|
- pluginFuncs->event = NPP_HandleEvent;
|
|
|
- pluginFuncs->urlnotify = NPP_URLNotify;
|
|
|
- pluginFuncs->getvalue = NPP_GetValue;
|
|
|
- pluginFuncs->setvalue = NPP_SetValue;
|
|
|
-
|
|
|
- return NPERR_NO_ERROR;
|
|
|
-}
|
|
|
-
|
|
|
-// Symbol called once by the browser to shut down the plugin
|
|
|
-NPError OSCALL
|
|
|
-NP_Shutdown(void) {
|
|
|
- logfile << "shutdown\n" << flush;
|
|
|
- unload_plugin();
|
|
|
-
|
|
|
- return NPERR_NO_ERROR;
|
|
|
-}
|