fix firefox streams

This commit is contained in:
David Rose 2009-10-19 21:29:22 +00:00
parent 678dc259b8
commit 4abfcb2122
4 changed files with 48 additions and 10 deletions

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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);
}
////////////////////////////////////////////////////////////////////