bug 241092, make nsIStreamLoaderObserver usable in javascript, by changing its

argument from a string to an octet array
r=bryner sr=darin
This commit is contained in:
cbiesinger%web.de 2004-04-27 16:06:00 +00:00
parent abe3ca39a8
commit 79fa1b783a
11 changed files with 73 additions and 69 deletions

View File

@ -142,7 +142,7 @@ RemoteURILoadManager::~RemoteURILoadManager()
NS_IMPL_ISUPPORTS1(RemoteURILoadManager, nsIStreamLoaderObserver)
NS_IMETHODIMP RemoteURILoadManager::OnStreamComplete(nsIStreamLoader *loader, nsISupports *ctxt, nsresult status, PRUint32 resultLength, const char *result)
NS_IMETHODIMP RemoteURILoadManager::OnStreamComplete(nsIStreamLoader *loader, nsISupports *ctxt, nsresult status, PRUint32 resultLength, const PRUint8 *result)
{
StreamLoaderContext* loaderContext = NS_STATIC_CAST(StreamLoaderContext*, ctxt);
if (loaderContext)

View File

@ -736,7 +736,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
nsISupports* aContext,
nsresult aStatus,
PRUint32 stringLen,
const char* string)
const PRUint8* string)
{
nsresult rv;
nsScriptLoadRequest* request = NS_STATIC_CAST(nsScriptLoadRequest*, aContext);
@ -800,7 +800,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
}
if (NS_FAILED(rv) || characterSet.IsEmpty()) {
DetectByteOrderMark((const unsigned char*)string, stringLen, characterSet);
DetectByteOrderMark(string, stringLen, characterSet);
}
if (characterSet.IsEmpty()) {
@ -832,7 +832,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_SUCCEEDED(rv)) {
PRInt32 unicodeLength = 0;
rv = unicodeDecoder->GetMaxLength(string, stringLen, &unicodeLength);
rv = unicodeDecoder->GetMaxLength(NS_REINTERPRET_CAST(const char*, string), stringLen, &unicodeLength);
if (NS_SUCCEEDED(rv)) {
nsString tempStr;
tempStr.SetLength(unicodeLength);
@ -844,7 +844,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
PRInt32 convertedLength = 0;
PRInt32 bufferLength = unicodeLength;
do {
rv = unicodeDecoder->Convert(string, (PRInt32 *) &stringLen, ustr,
rv = unicodeDecoder->Convert(NS_REINTERPRET_CAST(const char*, string), (PRInt32 *) &stringLen, ustr,
&unicodeLength);
if (NS_FAILED(rv)) {
// if we failed, we consume one byte, replace it with U+FFFD

View File

@ -3079,7 +3079,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
nsISupports* context,
nsresult aStatus,
PRUint32 stringLen,
const char* string)
const PRUint8* string)
{
#ifdef DEBUG
// print a load error on bad status
@ -3130,7 +3130,8 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
// not to reach here.
nsCOMPtr<nsIURI> uri = scriptProto->mSrcURI;
nsString stringStr; stringStr.AssignWithConversion(string, stringLen);
// XXX this seems broken - what if the script is non-ascii? (bug 241739)
nsString stringStr; stringStr.AssignWithConversion(NS_REINTERPRET_CAST(const char*, string), stringLen);
rv = scriptProto->Compile(stringStr.get(), stringLen, uri, 1, this,
mCurrentPrototype);

View File

@ -51,7 +51,7 @@ interface nsIStreamLoaderObserver : nsISupports
in nsISupports ctxt,
in nsresult status,
in unsigned long resultLength,
[size_is(resultLength)] in string result);
[const,array,size_is(resultLength)] in octet result);
};
/**

View File

@ -49,7 +49,6 @@
#include "nsInputStreamChannel.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsPrintfCString.h"
#include "nsIErrorService.h"
#include "netCore.h"
#include "nsIObserverService.h"

View File

@ -130,7 +130,9 @@ nsStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
// provide nsIStreamLoader::request during call to OnStreamComplete
mRequest = request;
mObserver->OnStreamComplete(this, mContext, aStatus,
mData.Length(), mData.get());
mData.Length(),
NS_REINTERPRET_CAST(const PRUint8*,
mData.get()));
// done.. cleanup
mRequest = 0;
mObserver = 0;

View File

@ -37,6 +37,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include <string.h>
#include "nscore.h"
#include "plstr.h"
#include "prlink.h"
@ -120,14 +122,14 @@ nsSound::Init()
return NS_OK;
}
#define GET_WORD(s, i) ((unsigned char)s[i+1] << 8) | (unsigned char)s[i]
#define GET_DWORD(s, i) ((unsigned char)s[i+3] << 24) | ((unsigned char)s[i+2] << 16) | ((unsigned char)s[i+1] << 8) | (unsigned char)s[i]
#define GET_WORD(s, i) (s[i+1] << 8) | s[i]
#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i]
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
nsresult aStatus,
PRUint32 stringLen,
const char *string)
PRUint32 dataLen,
const PRUint8 *data)
{
#ifdef DEBUG
@ -159,7 +161,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
unsigned short format, channels = 1, block_align, bits_per_sample=0;
if (PL_strncmp(string, "RIFF", 4)) {
if (memcmp(data, "RIFF", 4)) {
#ifdef DEBUG
printf("We only support WAV files currently.\n");
#endif
@ -167,35 +169,35 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
}
PRUint32 i;
for (i= 0; i < stringLen; i++) {
for (i= 0; i < dataLen; i++) {
if (i+3 <= stringLen)
if ((string[i] == 'f') &&
(string[i+1] == 'm') &&
(string[i+2] == 't') &&
(string[i+3] == ' ')) {
if (i+3 <= dataLen)
if ((data[i] == 'f') &&
(data[i+1] == 'm') &&
(data[i+2] == 't') &&
(data[i+3] == ' ')) {
i += 4;
/* length of the rest of this subblock (should be 16 for PCM data */
// long len = GET_DWORD(string, i);
// long len = GET_DWORD(data, i);
i+=4;
format = GET_WORD(string, i);
format = GET_WORD(data, i);
i+=2;
channels = GET_WORD(string, i);
channels = GET_WORD(data, i);
i+=2;
samples_per_sec = GET_DWORD(string, i);
samples_per_sec = GET_DWORD(data, i);
i+=4;
avg_bytes_per_sec = GET_DWORD(string, i);
avg_bytes_per_sec = GET_DWORD(data, i);
i+=4;
block_align = GET_WORD(string, i);
block_align = GET_WORD(data, i);
i+=2;
bits_per_sample = GET_WORD(string, i);
bits_per_sample = GET_WORD(data, i);
i+=2;
rate = samples_per_sec;
@ -231,7 +233,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
}
/* write data out */
write(fd, string, stringLen);
write(fd, data, dataLen);
close(fd);

View File

@ -38,6 +38,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include <string.h>
#include "nscore.h"
#include "plstr.h"
#include "prlink.h"
@ -124,16 +126,14 @@ nsSound::Init()
return NS_OK;
}
#define GET_WORD(s, i) ((unsigned char)s[i+1] << 8) | (unsigned char)s[i]
#define GET_DWORD(s, i) ((unsigned char)s[i+3] << 24) | \
((unsigned char)s[i+2] << 16) | ((unsigned char)s[i+1] << 8) | \
(unsigned char)s[i]
#define GET_WORD(s, i) (s[i+1] << 8) | s[i]
#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i]
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
nsresult aStatus,
PRUint32 stringLen,
const char *string)
PRUint32 dataLen,
const PRUint8 *data)
{
#ifdef DEBUG
@ -163,7 +163,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
unsigned long rate=0;
unsigned short format, channels = 1, block_align, bits_per_sample=0;
if (PL_strncmp(string, "RIFF", 4)) {
if (memcmp(data, "RIFF", 4)) {
#ifdef DEBUG
printf("We only support WAV files currently.\n");
#endif
@ -171,33 +171,33 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
}
PRUint32 i;
for (i= 0; i < stringLen; i++) {
if (i+3 <= stringLen)
if ((string[i] == 'f') &&
(string[i+1] == 'm') &&
(string[i+2] == 't') &&
(string[i+3] == ' ')) {
for (i= 0; i < dataLen; i++) {
if (i+3 <= dataLen)
if ((data[i] == 'f') &&
(data[i+1] == 'm') &&
(data[i+2] == 't') &&
(data[i+3] == ' ')) {
i += 4;
/* length of the rest of this subblock (should be 16 for PCM data */
i+=4;
format = GET_WORD(string, i);
format = GET_WORD(data, i);
i+=2;
channels = GET_WORD(string, i);
channels = GET_WORD(data, i);
i+=2;
samples_per_sec = GET_DWORD(string, i);
samples_per_sec = GET_DWORD(data, i);
i+=4;
avg_bytes_per_sec = GET_DWORD(string, i);
avg_bytes_per_sec = GET_DWORD(data, i);
i+=4;
block_align = GET_WORD(string, i);
block_align = GET_WORD(data, i);
i+=2;
bits_per_sample = GET_WORD(string, i);
bits_per_sample = GET_WORD(data, i);
i+=2;
rate = samples_per_sec;
@ -215,6 +215,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
EsdPlayStreamFallbackType EsdPlayStreamFallback =
(EsdPlayStreamFallbackType) PR_FindSymbol(elib,
"esd_play_stream_fallback");
// XXX what if that fails? (Bug 241738)
mask = ESD_PLAY | ESD_STREAM;
@ -235,7 +236,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
}
/* write data out */
write(fd, string, stringLen);
write(fd, data, dataLen);
close(fd);

View File

@ -740,8 +740,8 @@ NS_IMETHODIMP
nsMovieSoundRequest::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
nsresult aStatus,
PRUint32 stringLen,
const char *stringData)
PRUint32 dataLen,
const PRUint8 *data)
{
NS_ENSURE_ARG(aLoader);
@ -759,14 +759,14 @@ nsMovieSoundRequest::OnStreamComplete(nsIStreamLoader *aLoader,
// we could use a Pointer data handler type, and avoid this
// allocation/copy, in QuickTime 5 and above.
OSErr err;
mDataHandle = ::TempNewHandle(stringLen, &err);
mDataHandle = ::TempNewHandle(dataLen, &err);
if (!mDataHandle) return NS_ERROR_OUT_OF_MEMORY;
::BlockMoveData(stringData, *mDataHandle, stringLen);
::BlockMoveData(data, *mDataHandle, dataLen);
NS_ASSERTION(mMovie == nsnull, "nsMovieSoundRequest has a movie already");
err = ImportMovie(mDataHandle, stringLen, contentType);
err = ImportMovie(mDataHandle, dataLen, contentType);
if (err != noErr) {
Cleanup();
return NS_ERROR_FAILURE;
@ -778,7 +778,7 @@ nsMovieSoundRequest::OnStreamComplete(nsIStreamLoader *aLoader,
// put it in the cache. Not vital that this succeeds.
// for the data size we just use the string data, since the movie simply wraps this
// (we have to keep the handle around until the movies are done playing)
nsresult rv = macSound->PutSoundInCache(channel, stringLen, NS_STATIC_CAST(nsITimerCallback*, this));
nsresult rv = macSound->PutSoundInCache(channel, dataLen, NS_STATIC_CAST(nsITimerCallback*, this));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to put sound in cache");
return PlaySound();

View File

@ -88,8 +88,8 @@ nsSound::~nsSound()
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
nsresult aStatus,
PRUint32 stringLen,
const char *string)
PRUint32 dataLen,
const PRUint8 *data)
{
if (NS_FAILED(aStatus)) {
@ -114,7 +114,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
return NS_ERROR_FAILURE;
}
if (PL_strncmp(string, "RIFF", 4) || (!gMMPMInstalled)) {
if (PL_strncmp(data, "RIFF", 4) || (!gMMPMInstalled)) {
#ifdef DEBUG
printf("We only support WAV files currently.\n");
#endif
@ -132,7 +132,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsCAutoString soundFilename;
(void) soundTmp->GetNativePath(soundFilename);
FILE *fp = fopen(soundFilename.get(), "wb+");
fwrite(string, stringLen, 1, fp);
fwrite(data, dataLen, 1, fp);
fclose(fp);
HOBJECT hobject = WinQueryObject(soundFilename.get());
WinSetObjectData(hobject, "OPEN=DEFAULT");
@ -148,8 +148,8 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
memset(&mmioinfo, 0, sizeof(MMIOINFO));
mmioinfo.fccIOProc = FOURCC_MEM;
mmioinfo.cchBuffer = stringLen;
mmioinfo.pchBuffer = (char*)string;
mmioinfo.cchBuffer = dataLen;
mmioinfo.pchBuffer = (char*)data;
USHORT usDeviceID;
hmmio = mmioOpen(NULL, &mmioinfo, MMIO_READWRITE);

View File

@ -130,8 +130,8 @@ NS_IMETHODIMP nsSound::Beep()
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
nsresult aStatus,
PRUint32 stringLen,
const char *string)
PRUint32 dataLen,
const PRUint8 *data)
{
// print a load error on bad status
if (NS_FAILED(aStatus)) {
@ -158,19 +158,18 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
PurgeLastSound();
if (string && stringLen > 0) {
if (data && dataLen > 0) {
DWORD flags = SND_MEMORY | SND_NODEFAULT;
// We try to make a copy so we can play it async.
// XXX Can sharable strings improve this?
mLastSound = (char *) malloc(stringLen);
mLastSound = (char *) malloc(dataLen);
if (mLastSound) {
memcpy(mLastSound, string, stringLen);
string = mLastSound;
memcpy(mLastSound, data, dataLen);
data = mLastSound;
flags |= SND_ASYNC;
}
CWinMM& theMM = CWinMM::GetModule();
theMM.PlaySound(string, 0, flags);
theMM.PlaySound(NS_REINTERPRET_CAST(const char*, data), 0, flags);
}
return NS_OK;