Back to index

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

#include <EmbedStream.h>

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

List of all members.

Public Member Functions

 EmbedStream ()
virtual ~EmbedStream ()
void InitOwner (EmbedPrivate *aOwner)
NS_METHOD Init (void)
NS_METHOD OpenStream (const char *aBaseURI, const char *aContentType)
NS_METHOD AppendToStream (const char *aData, PRInt32 aLen)
NS_METHOD CloseStream (void)
NS_METHOD Append (const char *aData, PRUint32 aLen)
 EmbedStream ()
 ~EmbedStream ()
void InitOwner (QGeckoEmbed *aOwner)
NS_METHOD Init (void)
NS_METHOD OpenStream (const char *aBaseURI, const char *aContentType)
NS_METHOD AppendToStream (const char *aData, PRInt32 aLen)
NS_METHOD CloseStream (void)
NS_METHOD Append (const char *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
EmbedPrivatemOwner
QGeckoEmbedmOwner

Detailed Description

Definition at line 48 of file EmbedStream.h.


Constructor & Destructor Documentation

Definition at line 58 of file EmbedStream.cpp.

Definition at line 66 of file EmbedStream.cpp.

{
}

Member Function Documentation

NS_METHOD EmbedStream::Append ( const char *  aData,
PRUint32  aLen 
)

Definition at line 243 of file EmbedStream.cpp.

{
  nsresult rv = NS_OK;
  PRUint32 bytesWritten = 0;
  rv = mOutputStream->Write(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:

NS_METHOD EmbedStream::Append ( const char *  aData,
PRUint32  aLen 
)
NS_METHOD EmbedStream::AppendToStream ( const char *  aData,
PRInt32  aLen 
)

Definition at line 193 of file EmbedStream.cpp.

{
  nsresult rv;

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

  // notify our listeners
  nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel); 
  rv = mStreamListener->OnDataAvailable(request,
                                   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:

Here is the caller graph for this function:

NS_METHOD EmbedStream::AppendToStream ( const char *  aData,
PRInt32  aLen 
)
unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
void nsIInputStream::close ( ) [inherited]

Close the stream.

Definition at line 218 of file EmbedStream.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file EmbedStream.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 71 of file EmbedStream.cpp.

{
  mOwner = aOwner;
}

Here is the caller graph for this function:

Definition at line 74 of file EmbedStream.cpp.

{
    mOwner = aOwner;
}
Returns:
true if stream is non-blocking
NS_METHOD EmbedStream::OpenStream ( const char *  aBaseURI,
const char *  aContentType 
)

Definition at line 95 of file EmbedStream.cpp.

{
  NS_ENSURE_ARG_POINTER(aBaseURI);
  NS_ENSURE_ARG_POINTER(aContentType);

  nsresult rv = NS_OK;

  // if we're already doing a stream then close the current one
  if (mDoingStream)
    CloseStream();

  // set our state
  mDoingStream = PR_TRUE;

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

  // get the content area of our web browser
  nsCOMPtr<nsIWebBrowser> browser;
  mOwner->mWindow->GetWebBrowser(getter_AddRefs(browser));

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

  // create a new uri object
  nsCOMPtr<nsIURI> uri;
  nsCAutoString spec(aBaseURI);
  rv = NS_NewURI(getter_AddRefs(uri), spec.get());
  
  if (NS_FAILED(rv))
    return rv;

  // 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), uri,
                            NS_STATIC_CAST(nsIInputStream *, this),
                            nsDependentCString(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
  nsXPIDLCString docLoaderContractID;
  nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;
  rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType,
                                getter_Copies(docLoaderContractID));
  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,
                                   aContentType, 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
  nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel); 
  rv = mStreamListener->OnStartRequest(request, NULL);
  if (NS_FAILED(rv))
    return rv;
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD EmbedStream::OpenStream ( const char *  aBaseURI,
const char *  aContentType 
)
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 74 of file EmbedStream.h.

Definition at line 78 of file EmbedStream.h.

Definition at line 71 of file EmbedStream.h.

Definition at line 73 of file EmbedStream.h.

Definition at line 77 of file EmbedStream.h.

Definition at line 70 of file EmbedStream.h.

Definition at line 80 of file EmbedStream.h.

Definition at line 82 of file EmbedStream.h.

Definition at line 75 of file EmbedStream.h.


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