[Contents] [Previous]
[Next] [Index]
Stream Methods
Streams represent URLs and the data they contain
or data sent by a plug-in without an associated URL. A stream is associated
with a specific instance of a plug-in, but a plug-in can have more than
one stream object per instance.
The methods in this reference handle streams.
See Chapter 5, "Streams," for information
about using these methods.
[Top] [Reference
to Functions by Functional Group] [API
Organization: Netscape and Plug-in Methods]
NPP_DestroyStream
Tells the plug-in that a stream is about to be closed
or destroyed
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
NPError NPP_DestroyStream(NPP instance,
NPStream* stream,
NPReason reason);
Parameters
The function has the following parameters:
instance
|
Pointer to current
plug-in instance. |
stream
|
Pointer to current
stream. |
reason
|
Reason the stream
was destroyed. Values:
-
NPRES_DONE (Most common): Completed normally; all data was sent
to the instance.
-
NPRES_USER_BREAK: User canceled stream directly by clicking
the Stop button or indirectly by some action such as deleting the
instance or initiating higher-priority network operations.
-
NPRES_NETWORK_ERR: Stream failed due to problems with network,
disk I/O, lack of memory, or other problems.
|
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
Communicator calls the NPP_DestroyStream
function when a data stream sent to the plug-in is finished, either because
it has completed successfully or terminated abnormally. After this, Communicator
deletes the NPStream object.
You should delete any private data allocated
in stream->pdata at this time, and should not make any further
references to the stream object.
See Also
NPP_NewStream, NPN_DestroyStream, NPStream, NPP
"Telling the Plug-in When
a Stream Is Deleted"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPP_NewStream
Notifies a plug-in instance of a new data stream
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
NPError NPP_NewStream(NPP instance,
NPMIMEType type,
NPStream *stream,
NPBool seekable,
uint16* stype);
Parameters
The function has the following parameters:
instance
|
Pointer to current
plug-in instance. |
type
|
Pointer to MIME type
of the stream. |
stream
|
Pointer to new stream. |
seekable
|
Whether the stream
is seekable.
-
true: Seekable. Stream supports random access through calls to
NPN_RequestRead (for example, local files or HTTP servers that
support byte-range requests).
-
false: Not seekable. Communicator must copy data in the stream
to the local cache to satisfy random access requests made through NPN_RequestRead.
|
stype
|
Requested mode of
new stream. For more information about each of these values, see Directions
in this section.
-
NP_NORMAL (Default): Delivers stream data to the instance in a
series of calls to NPP_WriteReady and NPP_Write.
-
NP_ASFILEONLY: New in Netscape Navigator 3.0. Saves stream
data to a file in the local cache.
-
NP_ASFILE: File download. Like NP_ASFILEONLY except that
data is delivered to the plug-in as it is saved to the file (as in mode
NP_NORMAL).
-
NP_SEEK: Stream data randomly accessible by the plug-in as needed,
through calls to NPN_RequestRead.
|
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
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. Communicator calls
NPP_DestroyStream when the stream completes (either successfully
or abnormally). The plug-in can terminate the stream itself by calling
NPN_DestroyStream.
The parameter stype defines the mode
of the stream. Values:
-
NP_NORMAL (Default): Delivers stream data to the instance in a
series of calls to NPP_WriteReady and NPP_Write. The
plug-in can process the data progressively as it arrives from the network
or file system.
-
NP_ASFILEONLY: New in Netscape Navigator 3.0. Communicator
saves stream data to a file in the local cache. When the stream is complete,
Communicator calls NPP_StreamAsFile to deliver the path of the
file to the plug-in. If the stream comes from a local file, the NPP_Write
and NPP_WriteReady functions are not called. NPP_StreamAsFile
is simply called immediately. This mode allows the plug-in full random
access to the data using platform-specific file operations.
-
NP_ASFILE: File download. Differs from
NP_ASFILEONLY in that data is delivered to the plug-in, through
a series of calls to NPP_Write and NPP_Write, as it is
saved to the file (as in mode NP_NORMAL). When the stream is complete,
Communicator calls NPP_StreamAsFile to deliver the path of the
file to the plug-in. If the data in the stream comes from a file that is
already local, the data is read, sent to the plug-in through NPP_Write,
and written to a file in the local cache.
NOTE: Most plug-ins that
need the stream saved to a file should use the more efficient mode NP_ASFILEONLY
(above); this mode is preserved for compatibility only. §
-
NP_SEEK: Stream data is not automatically delivered to the instance,
but can be randomly accessed by the plug-in as needed, through calls to
NPN_RequestRead. If the stream is not seekable, placing the stream
in NP_SEEK mode causes Communicator to save the entire stream
to the disk cache. NPN_RequestRead requests are only fulfilled
when all data has been read and stored in the cache. As an optimization
to extract the maximum benefit from existing network connections, Communicator
continues to read data sequentially out of the stream (as in mode NP_NORMAL)
until the first NPN_RequestRead call is made.
NOTE: In any mode other than
NP_SEEK, the application should call NPP_DestroyStream
once all data in the stream has been written to the plug-in. The plug-in
can also request termination of the stream at any time by calling NPN_DestroyStream.
§
See Also
NPN_NewStream, NPP_StreamAsFile, NPP_Write, NPP_WriteReady, NPP_DestroyStream, NPN_RequestRead, NPStream, NPN_GetURL
"Creating a Stream"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPP_StreamAsFile
Provides a plug-in instance with a local file name
for the data from a stream
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
void NPP_StreamAsFile(NPP instance,
NPStream* stream,
const char* fname);
Parameters
The function has the following parameters:
instance
|
Pointer to current
plug-in instance. |
stream
|
Pointer to current
stream. |
fname
|
Pointer to full path
to a local file. If an error occurs while retrieving the data or writing
the file, fname may be null. |
Description
When the stream is complete, Communicator calls NPP_StreamAsFile
to provide the instance with a full path name for a local file for the
stream. NPP_StreamAsFile is called for streams whose mode is set
to NP_ASFILEONLY or NP_ASFILE
only in a previous call to NPP_NewStream.
If an error occurs while retrieving the
data or writing the file, the file name (fname) is null.
See Also
NPP_NewStream, NPP_Write, NPP_WriteReady, NPStream, NPP
"Sending the Stream in
File Mode"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPP_Write
Delivers data to a plug-in instance
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
int32 NPP_Write(NPP instance,
NPStream* stream,
int32 offset,
int32 len,
void* buf);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
stream
|
Pointer to the current
stream. |
offset
|
Offset in bytes of
buf from the beginning of the data in the stream. Can be used
to check stream progress or bye range requests from NPN_RequestRead. |
len
|
Length in bytes of
buf; number of bytes accepted. |
buf
|
Buffer of data, delivered
by the stream, that contains len bytes of data offset
bytes from the start of the stream. The buffer is allocated by Communicator
and is deleted after returning from the function, so the plug-in should
make a copy of the data it needs to keep. |
Returns
-
If successful, the function returns the number of bytes consumed by the
instance.
-
If unsuccessful, the function destroys the stream by returning a negative
value.
Description
Communicator calls the NPP_Write function
to deliver the data specified in a previous NPP_WriteReady call
to the plug-in. A plug-in must consume at least as many bytes as indicated
in the NPP_WriteReady call.
After a stream is created by a call to NPP_NewStream,
Communicator calls NPP_Write either:
-
If the plug-in requested a normal-mode stream, the data in the stream is
delivered to the plug-in instance in a series of calls to NPP_WriteReady
and NPP_Write.
-
If the plug-in requested a seekable stream, the NPN_RequestRead
function requests reads of a specified byte range that results in a series
of calls to NPP_WriteReady and NPP_Write.
The plug-in can use the offset parameter
to track the bytes that are written. This gives you different information
depending in the type of stream. In a normal-mode stream., the parameter
value increases as the each buffer is written. The buf parameter
is not persistent, so the plug-in must process data immediately or allocate
memory and save a copy of it. In a seekable stream with byte range requests,
you can use this parameter to track NPN_ReqestRead requests.
The plug-in should return the number of bytes
written (consumed by the instance). If the return value is smaller than
the size of the buffer, the browser sends the remaining data to the plug-in
through subsequent calls to NPP_WriteReady and NPP_Write.
A negative return value causes an error on the stream, which causes Communicator
to destroy the stream with NPP_DestroyStream.
See Also
NPP_DestroyStream, NPP_NewStream, NPP_WriteReady, NPStream, NPP
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPP_WriteReady
Returns the maximum number of bytes that an instance
can accept from the stream in a call to NPP_Write
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
int32 NPP_WriteReady(NPP instance, NPStream* stream);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
stream
|
Pointer to the current
stream. |
Returns
Returns the maximum number of bytes that an instance
is prepared to accept from the stream
Description
Communicator calls NPP_WriteReady before
each call to NPP_Write to determine whether a plug-in can receive
data and how many bytes it can receive. This function allows Communicator
to send only as much data to the instance as it can handle at one time,
making resource use more efficient for both Communicator and plug-in.
The NPP_Write function may pass a larger
buffer, but the plug-in is required to consume only the amount of data
returned by NPP_WriteReady.
The browser can write a smaller amount of data
if desired or necessary; for example, if only 8K of data is available in
a network buffer. If the plug-in is allocating memory for the entire stream
at once (an AS_FILE stream), it can return a very large number.
Because it is not processing streaming data, Communicator can pass as much
data to the instance as necessary in a single NPP_Write.
If the plug-in receives a value of zero,
the data flow temporarily stops. Communicator checks to see if the plug-in
can receive data again by resending the data at regular intervals.
See Also
NPP_Write, NPStream, NPP
"Finding Out How Much
Data the Plug-in Can Accept"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_DestroyStream
New in Netscape Navigator 3.0.
Closes and deletes a stream
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_DestroyStream(NPP instance,
NPStream* stream,
NPError reason);
Parameters
The function has the following parameters:
instance
|
Pointer to current
plug-in instance. |
stream
|
Pointer to current
stream, initiated by either Communicator or the plug-in. |
reason
|
Reason the stream
was stopped so the application can give the user appropriate feedback.
Values:
-
NPRES_DONE (most common): Stream completed normally; all data
was sent by the plug-in to Communicator.
-
NPRES_USER_BREAK: Plug-in is terminating the stream due to a user
request.
-
NPRES_NETWORK_ERR: Stream failed due to network problems.
|
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
The plug-in calls the NPN_DestroyStream
function to close and delete a stream. This stream can be either a stream
that Communicator created and passed to the plug-in in NPP_NewStream,
or a stream created by the plug-in through a call to NPN_NewStream.
See Also
NPP_DestroyStream, NPN_NewStream, NPStream, NPP
"Telling the Plug-in When
a Stream Is Deleted"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_NewStream
New in Netscape Navigator 3.0.
Requests the creation of a new data stream produced
by the plug-in and consumed by Communicator
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_NewStream(NPP instance,
NPMIMEType type,
const char* target,
NPStream** stream);
Parameters
The function has the following parameters:
instance
|
Pointer to current
plug-in instance. |
type
|
MIME type of the stream. |
target
|
Name of the target
window or frame, or one of several special target names. For values, see
NPN_GetURL. |
stream
|
Stream to be created
by Communicator. |
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
NPN_NewStream creates a new stream of data
produced by the plug-in and consumed by Communicator.
The MIME parameter is the MIME
type of the plug-in to create. A plug-in can create another instance of
itself by specifying its own MIME type and a new target name in a call
to NPN_NewStream.
The stream is returned in the stream
parameter. The plug-in can use this object in subsequent calls to NPN_Write
to write data into the stream. When the plug-in has written all of its
data into the stream, NPN_DestroyStream terminates the stream
and deallocates the NPStream object.
The target parameter is the name of the
target window or frame, or one of several special target names. For parameter
values and information about how to use them, see NPN_GetURL.
If the new stream has the target of _self, this function should
return an INVALID_PARAM NPError.
For more information on named targets, see
the Netscape document, "Targeting
Windows."
WARNING: In Navigator 3.0,
if the target parameter refers to the window or frame that contains
the plug-in instance (for example, _current), Communicator returns
an NPERR_INVALID_PARM error code to NPN_NewStream. This
error occurs if you use _self or any other call that resolves
to _self, which includes the _top target when
the top frame is the current instance, or the _parent target
when the current target has no parent. §
See Also
NPP_NewStream, NPP_Write, NPP_DestroyStream, NPStream, NPP
"Creating a Stream"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_RequestRead
Requests a range of bytes from a seekable stream
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_RequestRead(NPStream* stream,
NPByteRange* rangeList);
Parameters
The function has the following parameters:
stream
|
Stream of type NP_SEEK
from which to read bytes. Communicator writes the requested bytes to the
plug-in through subsequent calls to NPP_WriteReady and NPP_Write. |
rangeList
|
Range of bytes in
the form of a linked list of NPByteRange objects, each of which
specifies a request for a range of bytes. |
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
For a seekable stream, Communicator sends data only
in response to requests by the plug-in. The plug-in calls NPN_RequestRead
to request data from a seekable stream.
The plug-in can use this function to make
one or more requests for ranges of bytes. These requests result in subsequent
calls to NPP_WriteReady and NPP_Write. For multiple requests,
the function creates a linked list of NPByteRange structures,
each of which represents a separate request.
A NAME="1086850">If the plug-in requests multiple ranges
(either through a list of NPByteRange objects in a single call
to NPN_RequestRead, or multiple calls to NPN_RequestRead),
Communicator can write individual ranges in any order, and with any number
of NPP_WriteReady and NPP_Write calls.
The plug-in must allocate NPByteRange
objects, which Communicator copies if necessary. The plug-in can free these
as soon as the call returns.
Seekable streams are created by calling
NPP_NewStream with NP_SEEK as the stype mode.
-
The plug-in can call NPN_RequestRead on streams that were not
initially in NP_SEEK mode as long as the stream is inherently
seekable; NPN_RequestRead automatically changes the mode to NP_SEEK.
-
If the stream is not inherently seekable, the stream must have been put
in NP_SEEK mode initially (since Communicator must cache all the
stream data on disk in order to access it randomly).
-
If NPN_RequestRead is called on a stream that is not inherently
seekable and not initially in mode NP_SEEK, it returns the error
code NPERR_STREAM_NOT_SEEKABLE.
Typically, the only streams that are inherently seekable
are those from in-memory or on-disk data, or from HTTP servers that support
byte-range requests.
See Also
NPP_NewStream, NPStream
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_Write
New in Netscape Navigator 3.0.
Pushes data into a stream produced by the plug-in
and consumed by Communicator
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPN_Write(NPP instance,
NPStream* stream,
int32 len,
void* buf);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
stream
|
Pointer to the current
stream. |
len
|
Length in bytes of
buf. |
buf
|
Buffer of data delivered
for the stream. |
Returns
-
If successful, the function returns a positive integer representing the
number of bytes written (consumed by Communicator). This number depends
on the size of Communicator's memory buffers, the number of active streams,
and other factors.
-
If unsuccessful, the plug-in returns a negative integer. This indicates
that Communicator encountered an error while processing the data, so the
plug-in should terminate the stream by calling NPN_DestroyStream.
Description
NPN_Write delivers a buffer from the stream
to the instance. A plug-in can call this function multiple times
after creating a stream with NPN_NewStream. Communicator makes
a copy of the buffer if necessary, so the plug-in can free the buffer as
the method returns, if desired. See "Example
of Sending a Stream" for an example that includes NPN_Write.
See Also
NPP_NewStream, NPP_DestroyStream, NPP_Write, NPStream, NPP
"Pushing Data into the
Stream," "Example of Sending a Stream"
[Top] [Stream
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
URL Methods
Plug-ins can retrieve data from or post data to
a URL with all the network functionality of Netscape Communicator. These
Netscape and Plug-in methods support URL
access. See Chapter 6, "URLs," for information
about using these methods.
[Top] [Reference
to Functions by Functional Group] [API
Organization: Netscape and Plug-in Methods]
NPP_URLNotify
New in Netscape Navigator 3.0.
Notifies the instance of the completion of a URL
request made by NPN_GetURLNotify or NPN_PostURLNotify
Plug-in API Type
Implemented by plug-in. See Plug-in
Method Summary.
Syntax
#include <npapi.h>
void NPP_URLNotify(NPP instance,
const char* url,
NPReason reason,
void* notifyData);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
url
|
URL of the NPN_GetURLNotify
or NPN_PostURLNotify request. |
reason
|
Reason code for completion
of request. Values:
-
NPRES_DONE (most common): Completed normally.
-
NPRES_USER_BREAK: User canceled stream directly by clicking
the Stop button or indirectly by some action such as deleting the
instance or initiating higher-priority network operations.
-
NPRES_NETWORK_ERR: Stream failed due to problems with network,
disk I/O, lack of memory, or other problems.
|
notifyData
|
Plug-in-private value
for associating a previous NPN_GetURLNotify or NPN_PostURLNotify
request with a subsequent NPP_URLNotify call. |
Description
Communicator calls NPP_URLNotify after the
completion of a NPN_GetURLNotify or NPN_PostURLNotify
request to inform the plug-in that the request was completed and supply
a reason code for the completion.
The most common reason code is NPRES_DONE,
indicating simply that the request completed normally. Other possible reason
codes are NPRES_USER_BREAK, indicating that the request was halted
due to a user action (for example, clicking the Stop button), and NPRES_NETWORK_ERR,
indicating that the request could not be completed, perhaps because the
URL could not be found.
The parameter notifyData is the
plug-in-private value passed as an argument by a previous NPN_GetURLNotify
or NPN_PostURLNotify call, and can be used as an identifier for
the request.
See Also
NPN_GetURLNotify, NPN_GetURL, NPN_PostURLNotify, NPN_PostURL
[Top] [URL
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_GetURL
Requests Communicator to create a stream for the
specified URL
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_GetURL(NPP instance,
const char* url,
const char* target);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
url
|
Pointer to the URL
of the request. Can be of any type, such as HTTP, FTP, news, mailto,
gopher. |
target
|
Name of the target
window or frame, or one of the following special target names. Values:
-
_blank or _new: Load the link in a new blank unnamed
window. Safest target, even though, when used with a mailto or
news URL, this creates an extra blank Communicator instance.
-
_self or _current: Load the link into the same window the plug-in
instance occupies. Not recommended; see Warning.
If target refers to the window or frame containing the instance,
the instance is destroyed and the plug-in may be unloaded. Use with NPN_GetURL
only if you want to terminate the plug-in.
-
_parent: Load the link into the immediate FRAMESET parent
of the plug-in instance's document. If the plug-in instance's document
has no parent, the default is _self.
-
_top: Load the link into the plug-in instance window. The default
is _self, if the plug-in instance's document is already at the
top. Use for breaking out of a deep frame nesting.
If null, Communicator creates a new stream
and delivers the data to the current instance regardless of the MIME type
of the URL. In general, if a URL works in the location box of the Navigator,
it works here, except for the _self target. |
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
NPN_GetURL is used to load a URL into the
current window or another target or stream. Plug-ins can use this capability
to provide hyperlinks to other documents or to retrieve data from anywhere
on the network. This is especially useful for enabling an existing application
to operate on the web.
For HTTP URLs, Communicator resolves this method
as the HTTP server method GET, which requests URL objects.
Use NPN_PostURLNotify instead of NPN_PostURL
in these cases:
-
To request a stream and receive notification of the result.
-
If the buffer contains header information (even a blank line).
Make sure that the target matches the URL type sent
to it. For example, a null target does not make sense
for some URL types (such as mailto). The following recommendations
about target choice apply to other methods that handle URLs as
well.
If the target parameter refers
to the window or frame containing the current plug-in instance, the instance
is destroyed and the plug-in may be unloaded. If target is null,
the application creates a new stream and delivers the data to the plug-in
instance, through calls to NPP_NewStream, NPP_WriteReady
and NPP_Write, and NPP_DestroyStream. This means that,
if you want the plug-in to handle a new stream, no matter what the MIME
type is, use null. If the application cannot locate the URL and
retrieve the data, it does not create a stream for the instance.
When the plug-in instance is part of a regular
Navigator window, and it uses a _blank target with a mailto
or news URL, another blank navigator window is opened along with
the mail or news window.
When the plug-in uses a _self target,
no other instance is created; the plug-in usually continues to operate
successfully in its own window. The safest target is _blank, even
though this creates an extra blank Communicator instance.
For complete information on named targets for
this function (as well as for normal HTML links), see the Netscape document,
"Targeting
Windows."
The plug-in developer cannot influence the
way that Communicator handles NPN_GetURL. It is typically asynchronous
but this is not guaranteed. The plug-in could call NPN_GetURL
and receive data from the URL right away, but more often the data arrives
later. The rest of the Communicator interface keeps running until the data
is available.
NOTE: In Navigator 2.x or
earlier, this method cannot reference relative URLs. §
See Also
NPN_GetURLNotify, NPN_PostURL, NPN_PostURLNotify, NPP_URLNotify
[Top] [URL
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_GetURLNotify
New in Netscape Navigator 3.0.
Requests creation of a new stream with the contents
of the specified URL; gets notification of the result by calling NPP_URLNotify
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_GetURLNotify(NPP instance,
const char* url,
const char* target,
void* notifyData);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
url
|
Pointer to the URL
of the request. |
target
|
Name of the target
window or frame, or one of several special target names. For values, see
NPN_GetURL. |
notifyData
|
Plug-in-private value
for associating the request with the subsequent NPP_URLNotify
call, which passes this value (see Description
below). |
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
NPN_GetURLNotify works just like NPN_GetURL,
with one exception. NPN_GetURLNotify notifies the plug-in instance
upon successful or unsuccessful completion of the request by calling the
plug-in's NPP_URLNotify function and passing it the notifyData
value.
NPN_GetURLNotify typically handles
the URL request asynchronously. It returns immediately and only later handles
the request and calls NPP_URLNotify. This notification is the
only way the plug-in can tell whether a request with a null target
failed, or that a request with a non-null target completed.
For requests that complete unsuccessfully, Communicator
calls NPP_URLNotify as soon as possible.
For requests that complete successfully:
-
If the target is non-null, Communicator calls NPP_URLNotify
after it has finished loading the URL.
-
If the target is null, Communicator calls NPP_URLNotify
after closing the stream by calling NPN_DestroyStream.
If this function is called with a target parameter
value of _self or a parent to _self, this function should
return an INVALID_PARAM NPError. This is the only way to notify
the plug-in once it is deleted.
See Also
NPN_GetURL, NPN_PostURL, NPN_PostURLNotify, NPP_URLNotify, NPP
[Top] [URL
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_PostURL
NPN_PostURL is only partially implemented
in Netscape Navigator 2.0; the description below applies to Navigator 3.0
and later only.
Called by the plug-in to post data from a file
or buffer to a URL
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_PostURL(NPP instance, const char *url,
const char *target, uint32 len,
const char *buf, NPBool file);
Parameters
The function has the following parameters:
instance
|
Pointer to the current
plug-in instance. |
url
|
URL of the request,
specified by the plug-in. |
target
|
Display target, specified
by the plug-in. If null, pass the new stream back to the current
plug-in instance regardless of MIME type. For values, see NPN_GetURL. |
len
|
Length of the buffer
buf. |
buf
|
Path to local temporary
file or data buffer that contains the data to post. Temporary file is deleted
after use. Data in buffer cannot be posted for a protocol that requires
a header. |
file
|
Whether to post a
file. Values:
-
true: Post the file whose the path is specified in buf,
then delete the file.
-
false: Post the raw data in buf.
|
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
NPN_PostURL works similarly to NPN_GetURL,
but in reverse.
-
NPN_GetURL reads data from the URL and either displays it in the
target window or delivers it to the plug-in.
-
NPN_PostURL writes data from a file or buffer to the URL and either
displays the server's response in the target window or delivers it to the
plug-in. If the target parameter is null, the new stream is passed
to the plug-in regardless of MIME type.
When you use NPN_PostURL to send data to
the server, you can handle the response in several different ways by specifying
different target parameters.
-
If target is null, the server response is sent back to
the plug-in. You can get the data and save it in a file or use it in a
program.
-
If you specify _current, _self, or _top, the
response data is written to the same plug-in window and the plug-in is
unloaded.
-
If you specify _new or _blank, the response data is written
to a new browser window. You can also write the response data to a frame
by specifying the frame name as the target parameter.
For HTTP URLs only, Communicator resolves this method
as the HTTP server method POST, which transmits data
to the server.
The data to post can be contained either in a
local temporary file or a new memory buffer.
-
To post to a temporary file, set the flag file to true,
the buffer buf to the path name string for a file, and len
to the length of the path string. The file-type URL prefix "file://"
is optional.
MS Windows and Mac OS
If a file is posted with any protocol other than
FTP, the file must be text with Unix-style line breaks ('\n' separators
only). §
-
To post data from a memory buffer, set the flag file to false,
the buffer buf to the data to post, and len to the length
of buffer.
Possible URL types include HTTP (similar to an HTML
form submission), mail (sending mail), news (posting
a news article), and FTP (upload a file). Plug-ins can use this function
to post form data to CGI scripts using HTTP or upload files to a remote
server using FTP.
You cannot use NPN_PostURL to specify
headers (even a blank line) in a memory buffer. To do this, use NPN_PostURLNotify.
For protocols in which the headers must
be distinguished from the body, such as HTTP, the buffer or file
should contain the headers, followed by a blank line, then the body. If
no custom headers are required, simply add a blank line ('\n')
to the beginning of the file or buffer.
NPN_PostURL is typically asynchronous:
it returns immediately and only later handles the request. For this reason,
you may find it useful to call NPN_PostURLNotify instead; this
function notifies your plug-in upon successful or unsuccessful completion
of the request.
NOTE: In Navigator 2.x or
earlier, this method cannot reference relative URLs. §
See Also
NPN_GetURL, NPN_GetURLNotify, NPN_PostURLNotify, NPP_URLNotify, NPP
[Top] [URL
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
NPN_PostURLNotify
New in Netscape Navigator 3.0.
Posts data to a URL; gets notification of the
result by calling NPP_URLNotify
Plug-in API Type
Implemented by Navigator. See Netscape
Method Summary.
Syntax
#include <npapi.h>
NPError NPN_PostURLNotify(NPP instance,
const char* url,
const char* target,
uint32 len,
const char* buf,
NPBool file,
void* notifyData);
Parameters
The function has the following parameters:
instance
|
Current plug-in instance,
specified by the plug-in. |
url
|
URL of the POST
request, specified by the plug-in. |
target
|
Target window, specified
by the plug-in. For values, see NPN_GetURL. |
len
|
Length of the buffer
buf. |
buf
|
Path to local temporary
file or data buffer that contains the data to post. |
file
|
Whether to post a
file. Values:
-
true: Post the local file whose path is specified in buf, then
delete the file.
-
false: Post the raw data in buf.
|
notifydata
|
Plug-in-private value
for associating the request with the subsequent NPP_URLNotify
call, which returns this value (see Description
below). |
Returns
-
If successful, the function returns NPERR_NO_ERROR.
-
If unsuccessful, the plug-in is not loaded and the function returns an
error code. For possible values, see Error
Codes.
Description
NPN_PostURLNotify functions identically
to NPN_PostURL, with these exceptions:
-
NPN_PostURLNotify supports specifying headers when posting
a memory buffer.
-
NPN_PostURLNotify calls NPP_URLNotify upon successful
or unsuccessful completion of the request. For more information, see NPN_PostURL.
NPN_PostURLNotify is typically asynchronous:
it returns immediately and only later handles the request and calls NPP_URLNotify.
If this function is called with a target
parameter value of _self or a parent to _self, this function
should return an INVALID_PARAM NPError. This is the only way to
notify the plug-in once it is deleted. See NPN_GetURL for information
about this parameter.
See Also
NPN_GetURL, NPP_URLNotify, NPN_PostURL
[Top] [URL
Methods] [Reference to Functions by Functional
Group] [API Organization: Netscape and
Plug-in Methods]
[Contents] [Previous]
[Next] [Index]
Last Updated: 01/15/97 16:37:32
Copyright © 1997 Netscape
Communications Corporation