Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsEmbedStream Class Reference

#include <nsEmbedStream.h>

Inheritance diagram for nsEmbedStream:
Inheritance graph
[legend]
Collaboration diagram for nsEmbedStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsEmbedStream ()
virtual ~nsEmbedStream ()
void InitOwner (nsIWebBrowser *aOwner)
NS_METHOD Init (void)
NS_METHOD OpenStream (nsIURI *aBaseURI, const nsACString &aContentType)
NS_METHOD AppendToStream (const PRUint8 *aData, PRUint32 aLen)
NS_METHOD CloseStream (void)
NS_METHOD Append (const PRUint8 *aData, PRUint32 aLen)
void close ()
 Close the stream.
unsigned long available ()
unsigned long read (in charPtr aBuf, in unsigned long aCount)
 Read data from the stream.
unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount)
 Low-level read method that has access to the stream's underlying buffer.
boolean isNonBlocking ()

Private Attributes

nsCOMPtr< nsIOutputStreammOutputStream
nsCOMPtr< nsIInputStreammInputStream
nsCOMPtr< nsILoadGroupmLoadGroup
nsCOMPtr< nsIChannelmChannel
nsCOMPtr< nsIStreamListenermStreamListener
PRUint32 mOffset
PRBool mDoingStream
nsIWebBrowsermOwner

Detailed Description

Definition at line 47 of file nsEmbedStream.h.


Constructor & Destructor Documentation

Definition at line 58 of file nsEmbedStream.cpp.

Definition at line 65 of file nsEmbedStream.cpp.

{
}

Member Function Documentation

Definition at line 231 of file nsEmbedStream.cpp.

{
  PRUint32 bytesWritten = 0;
  nsresult rv = mOutputStream->Write(NS_REINTERPRET_CAST(const char*, aData),
                                     aLen, &bytesWritten);
  if (NS_FAILED(rv))
    return rv;
  
  NS_ASSERTION(bytesWritten == aLen,
              "underlying byffer couldn't handle the write");
  return rv;
}

Here is the caller graph for this function:

Definition at line 185 of file nsEmbedStream.cpp.

{
  nsresult rv;

  // append the data
  rv = Append(aData, aLen);
  if (NS_FAILED(rv))
    return rv;

  // notify our listeners
  rv = mStreamListener->OnDataAvailable(mChannel,
                                   NULL,
                                   NS_STATIC_CAST(nsIInputStream *, this),
                                   mOffset, /* offset */
                                   aLen); /* len */
  // move our counter
  mOffset += aLen;
  if (NS_FAILED(rv))
    return rv;

  return NS_OK;
}

Here is the call graph for this function:

unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
void nsIInputStream::close ( ) [inherited]

Close the stream.

Definition at line 209 of file nsEmbedStream.cpp.

{
  nsresult rv = NS_OK;

  // NS_ENSURE_STATE returns NS_ERROR_UNEXPECTED if the condition isn't
  // satisfied; this is exactly what we want to return.
  NS_ENSURE_STATE(mDoingStream);
  mDoingStream = PR_FALSE;

  rv = mStreamListener->OnStopRequest(mChannel, NULL, NS_OK);
  if (NS_FAILED(rv))
    return rv;

  mLoadGroup = nsnull;
  mChannel = nsnull;
  mStreamListener = nsnull;
  mOffset = 0;

  return rv;
}

Definition at line 76 of file nsEmbedStream.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsIInputStream> bufInStream;
  nsCOMPtr<nsIOutputStream> bufOutStream;

  rv = NS_NewPipe(getter_AddRefs(bufInStream),
                  getter_AddRefs(bufOutStream));

  if (NS_FAILED(rv)) return rv;
 
  mInputStream  = bufInStream;
  mOutputStream = bufOutStream;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file nsEmbedStream.cpp.

{
  mOwner = aOwner;
}
Returns:
true if stream is non-blocking
NS_METHOD nsEmbedStream::OpenStream ( nsIURI aBaseURI,
const nsACString &  aContentType 
)

Definition at line 95 of file nsEmbedStream.cpp.

{
  NS_ENSURE_ARG_POINTER(aBaseURI);
  NS_ENSURE_TRUE(IsASCII(aContentType), NS_ERROR_INVALID_ARG);

  // if we're already doing a stream, return an error
  if (mDoingStream)
    return NS_ERROR_IN_PROGRESS;

  // set our state
  mDoingStream = PR_TRUE;

  // initialize our streams
  nsresult rv = Init();
  if (NS_FAILED(rv))
    return rv;

  // get the viewer container
  nsCOMPtr<nsIContentViewerContainer> viewerContainer;
  viewerContainer = do_GetInterface(mOwner);

  // create a new load group
  rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull);
  if (NS_FAILED(rv))
    return rv;

  // create a new input stream channel
  rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), aBaseURI,
                            NS_STATIC_CAST(nsIInputStream *, this),
                            aContentType);
  if (NS_FAILED(rv))
    return rv;

  // set the channel's load group
  rv = mChannel->SetLoadGroup(mLoadGroup);
  if (NS_FAILED(rv))
    return rv;

  // find a document loader for this content type

  const nsCString& flatContentType = PromiseFlatCString(aContentType);

  nsXPIDLCString docLoaderContractID;
  nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = catMan->GetCategoryEntry("Gecko-Content-Viewers",
                                flatContentType.get(),
                                getter_Copies(docLoaderContractID));
  // Note: When the category manager does not find an entry for the requested
  // contract ID, it will return NS_ERROR_NOT_AVAILABLE. This conveniently
  // matches what this method wants to return in that case.
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;  
  docLoaderFactory = do_GetService(docLoaderContractID.get(), &rv);
  if (NS_FAILED(rv))
    return rv;

  // ok, create an instance of the content viewer for that command and
  // mime type
  nsCOMPtr<nsIContentViewer> contentViewer;
  rv = docLoaderFactory->CreateInstance("view", mChannel, mLoadGroup,
                                   flatContentType.get(), viewerContainer,
                                   nsnull,
                                   getter_AddRefs(mStreamListener),
                                   getter_AddRefs(contentViewer));
  if (NS_FAILED(rv))
    return rv;

  // set the container viewer container for this content view
  rv = contentViewer->SetContainer(viewerContainer);
  if (NS_FAILED(rv))
    return rv;

  // embed this sucker
  rv = viewerContainer->Embed(contentViewer, "view", nsnull);
  if (NS_FAILED(rv))
    return rv;

  // start our request
  rv = mStreamListener->OnStartRequest(mChannel, NULL);
  if (NS_FAILED(rv))
    return rv;
  
  return NS_OK;
}

Here is the call graph for this function:

unsigned long nsIInputStream::read ( in charPtr  aBuf,
in unsigned long  aCount 
) [inherited]

Read data from the stream.

Parameters:
aBufthe buffer into which the data is to be read
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount).
0 if reached end of file
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure
unsigned long nsIInputStream::readSegments ( in nsWriteSegmentFun  aWriter,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

Low-level read method that has access to the stream's underlying buffer.

The writer function may be called multiple times for segmented buffers. ReadSegments is expected to keep calling the writer until either there is nothing left to read or the writer returns an error. ReadSegments should not call the writer with zero bytes to consume.

Parameters:
aWriterthe "consumer" of the data to be read
aClosureopaque parameter passed to writer
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount)
0 if reached end of file (or if aWriter refused to consume data)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: this function may be unimplemented if a stream has no underlying buffer (e.g., socket input stream).


Member Data Documentation

Definition at line 73 of file nsEmbedStream.h.

Definition at line 77 of file nsEmbedStream.h.

Definition at line 70 of file nsEmbedStream.h.

Definition at line 72 of file nsEmbedStream.h.

Definition at line 76 of file nsEmbedStream.h.

Definition at line 69 of file nsEmbedStream.h.

Definition at line 79 of file nsEmbedStream.h.

Definition at line 74 of file nsEmbedStream.h.


The documentation for this class was generated from the following files: