From 4abfcb2122376f6ebf8ef804e3627e5df947f42e Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 19 Oct 2009 21:29:22 +0000 Subject: [PATCH] fix firefox streams --- direct/src/plugin_npapi/ppDownloadRequest.h | 3 +- direct/src/plugin_npapi/ppInstance.cxx | 44 ++++++++++++++++++--- direct/src/plugin_npapi/ppInstance.h | 2 + direct/src/plugin_npapi/startup.cxx | 9 +++-- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/direct/src/plugin_npapi/ppDownloadRequest.h b/direct/src/plugin_npapi/ppDownloadRequest.h index 9b485b9d13..ee2fb1f515 100644 --- a/direct/src/plugin_npapi/ppDownloadRequest.h +++ b/direct/src/plugin_npapi/ppDownloadRequest.h @@ -28,7 +28,8 @@ public: enum RequestType { RT_contents_file, RT_core_dll, - RT_user + RT_user, + RT_instance_data }; inline PPDownloadRequest(RequestType rtype, int user_id = 0); diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 321e8910f9..2f3f9d8a1f 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -192,13 +192,11 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) { // stream we receive is the instance data; any other unsolicited // stream is an error. - if (!_got_instance_url && stream->url != NULL && _p3d_inst != NULL) { + if (!_got_instance_url && stream->url != NULL) { _got_instance_url = true; _instance_url = stream->url; - int user_id = P3D_instance_start_stream(_p3d_inst, _instance_url.c_str()); - - stream->notifyData = new PPDownloadRequest(PPDownloadRequest::RT_user, user_id); - + stream->notifyData = new PPDownloadRequest(PPDownloadRequest::RT_instance_data); + *stype = NP_NORMAL; return NPERR_NO_ERROR; } @@ -235,6 +233,42 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) { return NPERR_GENERIC_ERROR; } +//////////////////////////////////////////////////////////////////// +// Function: PPInstance::write_ready +// Access: Public +// Description: Called by the browser to ask how much data is ready +// to be received for the indicated stream. +//////////////////////////////////////////////////////////////////// +int32 PPInstance:: +write_ready(NPStream *stream) { + if (stream->notifyData != NULL) { + PPDownloadRequest *req = (PPDownloadRequest *)(stream->notifyData); + if (req->_rtype == PPDownloadRequest::RT_instance_data) { + // There's a special case for the RT_instance_data stream. This + // is the first, unsolicited stream that indicates the p3d + // instance data. We have to send this stream into the + // instance, but we can only do this once the instance itself + // has been created. + if (_p3d_inst == NULL) { + // The instance hasn't yet been created. We're not ready for + // data yet. + return 0; + } + // The instance has been created. Redirect the stream into the + // instance. + assert(_got_instance_url); + int user_id = P3D_instance_start_stream(_p3d_inst, _instance_url.c_str()); + req->_rtype = PPDownloadRequest::RT_user; + req->_user_id = user_id; + } + } + + // We're supposed to return the maximum amount of data the plugin is + // prepared to handle. Gee, I don't know. As much as you can give + // me, I guess. + return 0x7fffffff; +} + //////////////////////////////////////////////////////////////////// // Function: PPInstance::write_stream // Access: Public diff --git a/direct/src/plugin_npapi/ppInstance.h b/direct/src/plugin_npapi/ppInstance.h index c8f6eca7f3..bb4c9d955b 100644 --- a/direct/src/plugin_npapi/ppInstance.h +++ b/direct/src/plugin_npapi/ppInstance.h @@ -46,6 +46,8 @@ public: void set_window(NPWindow *window); NPError new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype); + + int32 write_ready(NPStream *stream); int write_stream(NPStream *stream, int offset, int len, void *buffer); NPError destroy_stream(NPStream *stream, NPReason reason); void url_notify(const char *url, NPReason reason, void *notifyData); diff --git a/direct/src/plugin_npapi/startup.cxx b/direct/src/plugin_npapi/startup.cxx index b36baa5f9d..d0fd576068 100644 --- a/direct/src/plugin_npapi/startup.cxx +++ b/direct/src/plugin_npapi/startup.cxx @@ -346,10 +346,11 @@ NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) { //////////////////////////////////////////////////////////////////// int32 NPP_WriteReady(NPP instance, NPStream *stream) { - // We're supposed to return the maximum amount of data the plugin is - // prepared to handle. Gee, I don't know. As much as you can give - // me, I guess. - return 0x7fffffff; + PPInstance::generic_browser_call(); + PPInstance *inst = (PPInstance *)(instance->pdata); + assert(inst != NULL); + + return inst->write_ready(stream); } ////////////////////////////////////////////////////////////////////