Example #1
0
/*
see https://developer.mozilla.org/en/NPP_NewStream

NPP_NewStream notifies the plug-in when a new stream is created. The NPStream* pointer is valid
until the stream is destroyed. The plug-in can store plug-in-private data associated with the
stream in stream->pdata. The MIME type of the stream is provided by the type parameter.

The data in the stream can be the file specified in the SRC attribute of the EMBED tag, for an
embedded instance, or the file itself, for a full-page instance. A plug-in can also request a
stream with the function NPN_GetURL. The browser calls NPP_DestroyStream when the stream completes
(either successfully or abnormally). The plug-in can terminate the stream itself by calling
NPN_DestroyStream.
*/
NPError NpapiPlugin::NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
{
    NpapiStream* s = static_cast<NpapiStream*>( stream->notifyData );
    // check for streams we did not request or create
    if ( !s ) return NPERR_NO_ERROR;

    s->setMimeType( type );
    s->setStream( stream );
    s->setLength( stream->end );
    s->setUrl( stream->url );
    if( stream->headers ) s->setHeaders( stream->headers );
    s->setSeekableByServer( seekable ? true : false );

    if ( s->isSeekableRequested() && !s->isSeekableByServer() )   // requested seekable stream, but stream was not seekable
    {                                                             //  stream can only be made seekable by downloading the entire file
                                                                  //  which we don't want to happen automatically.
        s->signalFailedOpen();
        // If unsuccessful, the function should return one of the NPError Error Codes.
        // This will cause the browser to destroy the stream without calling NPP_DestroyStream.
        s->setStream( 0 );
        return NPERR_STREAM_NOT_SEEKABLE;
    }

    if ( s->isSeekable() ) *stype = NP_SEEK;
    else if ( s->isCached() ) *stype = NP_ASFILE;
    else *stype = NP_NORMAL;

    // first npp_newstream has to finish before the user may perform a RequestRead in the opened handler
    if ( s->isSeekable() ) signalStreamOpened( s ); //m_npHost->ScheduleAsyncCall( signalStreamOpened, s );
    else signalStreamOpened( s );

    return NPERR_NO_ERROR;
}