зеркало из https://github.com/mozilla/pjs.git
265333 change nsIWebBrowserStream in preparation of freezing:
- make it take nsIURI as base URI, for IDN support and correct charset handling - use an octet array instead of string for binary data - use ACString for the mime type - improve documentation r=marco sr=darin
This commit is contained in:
Родитель
548760ac8e
Коммит
273d3d5fae
|
@ -92,16 +92,16 @@ nsEmbedStream::Init(void)
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
nsEmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
||||
nsEmbedStream::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBaseURI);
|
||||
NS_ENSURE_ARG_POINTER(aContentType);
|
||||
NS_ENSURE_TRUE(IsASCII(aContentType), NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// if we're already doing a stream then close the current one
|
||||
// if we're already doing a stream, return an error
|
||||
if (mDoingStream)
|
||||
CloseStream();
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
// set our state
|
||||
mDoingStream = PR_TRUE;
|
||||
|
@ -115,23 +115,15 @@ nsEmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
|||
nsCOMPtr<nsIContentViewerContainer> viewerContainer;
|
||||
viewerContainer = do_GetInterface(mOwner);
|
||||
|
||||
// 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,
|
||||
rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), aBaseURI,
|
||||
NS_STATIC_CAST(nsIInputStream *, this),
|
||||
nsDependentCString(aContentType));
|
||||
aContentType);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -142,12 +134,18 @@ nsEmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
|||
|
||||
// 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", aContentType,
|
||||
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;
|
||||
|
||||
|
@ -160,7 +158,7 @@ nsEmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
|||
// mime type
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
rv = docLoaderFactory->CreateInstance("view", mChannel, mLoadGroup,
|
||||
aContentType, viewerContainer,
|
||||
flatContentType.get(), viewerContainer,
|
||||
nsnull,
|
||||
getter_AddRefs(mStreamListener),
|
||||
getter_AddRefs(contentViewer));
|
||||
|
@ -187,7 +185,7 @@ nsEmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
nsEmbedStream::AppendToStream(const char *aData, PRInt32 aLen)
|
||||
nsEmbedStream::AppendToStream(const PRUint8 *aData, PRUint32 aLen)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -216,6 +214,8 @@ nsEmbedStream::CloseStream(void)
|
|||
{
|
||||
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;
|
||||
|
||||
|
@ -237,11 +237,11 @@ nsEmbedStream::CloseStream(void)
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
nsEmbedStream::Append(const char *aData, PRUint32 aLen)
|
||||
nsEmbedStream::Append(const PRUint8 *aData, PRUint32 aLen)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 bytesWritten = 0;
|
||||
rv = mOutputStream->Write(aData, aLen, &bytesWritten);
|
||||
nsresult rv = mOutputStream->Write(NS_REINTERPRET_CAST(const char*, aData),
|
||||
aLen, &bytesWritten);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include <nsIChannel.h>
|
||||
#include <nsIStreamListener.h>
|
||||
#include <nsIWebBrowser.h>
|
||||
|
||||
|
||||
class nsEmbedStream : public nsIInputStream
|
||||
{
|
||||
public:
|
||||
|
@ -54,11 +54,11 @@ class nsEmbedStream : public nsIInputStream
|
|||
void InitOwner (nsIWebBrowser *aOwner);
|
||||
NS_METHOD Init (void);
|
||||
|
||||
NS_METHOD OpenStream (const char *aBaseURI, const char *aContentType);
|
||||
NS_METHOD AppendToStream (const char *aData, PRInt32 aLen);
|
||||
NS_METHOD OpenStream (nsIURI *aBaseURI, const nsACString& aContentType);
|
||||
NS_METHOD AppendToStream (const PRUint8 *aData, PRUint32 aLen);
|
||||
NS_METHOD CloseStream (void);
|
||||
|
||||
NS_METHOD Append (const char *aData, PRUint32 aLen);
|
||||
NS_METHOD Append (const PRUint8 *aData, PRUint32 aLen);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
|
|
@ -38,12 +38,52 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(27108bc2-dc7c-42d9-9c64-132550c78ce4)]
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* This interface provides a way to stream data to the web browser. This allows
|
||||
* loading of data from sources which it can not access using URIs and
|
||||
* nsIWebNavigation.
|
||||
*/
|
||||
[scriptable, uuid(86d02f0e-219b-4cfc-9c88-bd98d2cce0b8)]
|
||||
interface nsIWebBrowserStream : nsISupports
|
||||
{
|
||||
void openStream(in string aBaseURI, in string aContentType);
|
||||
/**
|
||||
* Prepare to load a stream of data. When this function returns successfully,
|
||||
* it must be paired by a call to closeStream.
|
||||
*
|
||||
* @param aBaseURI
|
||||
* The base URI of the data. Must not be null. Relative
|
||||
* URIs will be resolved relative to this URI.
|
||||
* @param aContentType
|
||||
* ASCII string giving the content type of the data. If rendering
|
||||
* content of this type is not supported, this method fails.
|
||||
* This string may include a charset declaration, for example:
|
||||
* text/html;charset=ISO-8859-1
|
||||
*
|
||||
* @throw NS_ERROR_NOT_AVAILABLE
|
||||
* The requested content type is not supported.
|
||||
* @throw NS_ERROR_IN_PROGRESS
|
||||
* openStream was called twice without an intermediate closeStream.
|
||||
*/
|
||||
void openStream(in nsIURI aBaseURI, in ACString aContentType);
|
||||
|
||||
void appendToStream(in string aData, in long aLen);
|
||||
/**
|
||||
* Append data to this stream.
|
||||
* @param aData The data to append
|
||||
* @param aLen Length of the data to append.
|
||||
*
|
||||
* @note To append more than 4 GB of data, call this method multiple times.
|
||||
*/
|
||||
void appendToStream([const, array, size_is(aLen)] in octet aData,
|
||||
in unsigned long aLen);
|
||||
|
||||
/**
|
||||
* Notifies the browser that all the data has been appended. This may notify
|
||||
* the user that the browser is "done loading" in some form.
|
||||
*
|
||||
* @throw NS_ERROR_UNEXPECTED
|
||||
* This method was called without a preceding openStream.
|
||||
*/
|
||||
void closeStream();
|
||||
};
|
||||
|
|
|
@ -1924,8 +1924,8 @@ NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement)
|
|||
// nsWebBrowser::nsIWebBrowserStream
|
||||
//*****************************************************************************
|
||||
|
||||
/* void openStream (in string aBaseURI, in string aContentType); */
|
||||
NS_IMETHODIMP nsWebBrowser::OpenStream(const char *aBaseURI, const char *aContentType)
|
||||
/* void openStream(in nsIURI aBaseURI, in ACString aContentType); */
|
||||
NS_IMETHODIMP nsWebBrowser::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -1941,8 +1941,9 @@ NS_IMETHODIMP nsWebBrowser::OpenStream(const char *aBaseURI, const char *aConten
|
|||
return mStream->OpenStream(aBaseURI, aContentType);
|
||||
}
|
||||
|
||||
/* void appendStream (in string aData, in long aLen); */
|
||||
NS_IMETHODIMP nsWebBrowser::AppendToStream(const char *aData, PRInt32 aLen)
|
||||
/* void appendToStream([const, array, size_is(aLen)] in octet aData,
|
||||
* in unsigned long aLen); */
|
||||
NS_IMETHODIMP nsWebBrowser::AppendToStream(const PRUint8 *aData, PRUint32 aLen)
|
||||
{
|
||||
if (!mStream)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче