Things get even more complicated when trying to support document formats that haven't yet been invented.
Naturally some document formats just can not be read in one go. It is possible to convert the given stream into a temporary local file and operate on that.
The following methods may be implemented by a plug-in. NP_New be implemented by the plug-in. |
void NP_Initialize(void)
void NP_Shutdown(void)
NPError NP_New(void *pluginType, NPP instance, NPPluginType mode, int16
argc, char *argn[], char *argv[], NPSavedData *saved)
NPP
is an instance handle
which uniquely describes this instance. Mode
indicates whether
this
instance is embedded or not. A list of name-value pairs may be passed
in argc
, argn
and argv
. These correspond
to any
HTML attributes associated with this instance. The final argument is any data
saved for
this instance as a result of a previous NP_Destroy
(see below).
NP_New
returns NULL or an error result if an
instance cannot be created.
NPError NP_Destroy(NPP instance, NPSavedData **save)
The plug-in may specify in save
some specific piece of data which
is
relative to this instance which it would like preserved between instances. This
is
useful if the plug-in wishes to save some state so that, if the user were to
return
to exactly the same document at some time in the future, a new instance could
be
created that remembered the state. For example a video player might choose to
save the
frame number that was last displayed so that upon returning to this document a
new
instance could initially display the same frame. This data is is not persistent
and may never be returned to the plug-in. The allocation space for the data
passes ownership from the plug-in to Netscape when NP_Destroy
returns.
Netscape can and will discard this data based on arbitrary criteria such as its
size,
the users page history and other factors. Plug-ins should treat it as a hint
and not rely
on it being provided in a future call to NP_New
.
NPError NP_SetWindow(NPP instance, NPWindow *window)
NPP
is of type NPEmbed
or NPFull
.
Subsequent calls to NP_SetWindow
for a single instance indicate
that the window
has been resized. A NULL
value for window
indicates
that the
plug-in should no longer use the window and must free any resources associated
with it.
NPError NP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
NPBool seekable, NPStreamType
*stype)
NP_GetUrl
request by the plug-in.
The MIME-type of the stream is provided in type
. If the stream is
known to be capable of byte-range requests then the boolean
seekable
will be TRUE
. An instance can request stream
modes other than the default (NPNormal
) by setting the value of
stype
. The semantics of NPSeek
and
NPAsFile
streams are described elsewhere.
int32 NP_WriteReady(NPP instance, NPStream *stream)
NP_Write
call.
int32 NP_Write(NPP instance, NPStream *stream, int32 offset, int32 len,
void *buf)
len
bytes of data in buf
to the
stream
. Offset
is the logical position of
buf
in an idealized file URL. A plug-in must consume at least as
many bytes as it indicated in the preceding NP_WriteReady
call. A
negative return value will cause an error on the stream which will subsequently
be destroyed.
NPError NP_DestroyStream(NPP instance, NPStream *stream, NPError
reason)
stream
. Reason
indicates why
the stream was closed. Possible reasons are that it was complete, because there
was some error, or because the user interrupted it.
void NP_StreamAsFile(NPP instance, NPStream *stream, const char*
fname)
NPAsFile
mode
and it completed without error. If the file was created from a network stream,
it will be locked in the disk cache until the stream or its owning instance is
destroyed.
int16 NP_HandleEvent(NPP instance, void *event)
event
to the instance
.
Currently this function is only used on the Macintosh platform.
void NP_Print(NPP instance, void *platformPrint)
instance
. Platform
specific print machinery is provided in platformPrint
.
TBD: The printing API is not specified by this current draft of the
spec.
NPError NP_GetURL(NPP instance, const char *url, const char
*window)
url
.
This operation is asynchronous and will happen at some time in the future. If
window
is NULL
then a new stream will be created for
this instance, regardless of the type of the data. If window
is
"_current"
then the URL will be interpreted as though a user had
requested it and this may result in the current plug-in being unloaded and the
current view being replaced with the new mime-type.
NPError NP_PostURL(NPP instance, const char *url, uint32 len, const char
*buf, NPBool
file)
NPError NP_RequestRead((NPStream *stream, NPByteRange *rangeList)
stream
. One or more
NP_Writes
will result from this call. This operation is an error
unless the stream is of type NPSeek
. Rangelist
is a
NULL
terminated linked list of offsets and lengths to get from
this stream. It is likely to be substantially more efficient to request a
number of segments in one call than to make a number of separate calls to this
routine.
NPError NP_NewStream(NPP instance, NPMIMEType type, NPStream
*stream)
NPBackground
.
int32 NP_Write(NPP instance, NPStream *stream, int32 len, void
*buffer)
len
bytes of data in buf
to the Netscape
stream
.
NPError NP_DestroyStream(NPP instance, NPStream *stream, NPError
reason)
Reason
indicates why the stream was
closed.
void NP_Status((NPP instance, const char *message)