gecko-dev/java/plugins/mozilla/npAPInsIInputStreamShim.h
edburns%acm.org a0319d2d7b This change-bundle fixes memory allocation in streams. Next step is to
make a final pass to make sure we are not leaking memory.  After that, I
want to clean up the build system, and the samples.

M build.xml

- Call make export in mozilla directory

- Fix clean target

M mozilla/Makefile.in

- Added export target
M classes/org/mozilla/pluglet/PlugletLoader.java

- avoid ambiguity by casting

+	    CodeSource codesource = new CodeSource(url,(java.security.cert.Certificate []) null);

M examples/MediaPlayer/JMPlayer.java

- remove debug printfs

M mozilla/npAPInsIInputStreamShim.cpp
M mozilla/npAPInsIInputStreamShim.h

- remove debug printfs

- fix buffer allocation, refactor into its own method.

- Use NPN_Mem* methods for memory allocation.

- isolate lock access to private methods.  Avoids locking when we
  already own the lock, which would cause an assertion.

M mozilla/nppluglet.cpp

- in dtor, check for null mScriptablePeer ivar before accessing it.

M mozilla/nsScriptablePeer.cpp

- whitespace

M src/Pluglet.cpp

- get the plugletEngine from do_GetService().

M src/PlugletEngine.cpp
M src/PlugletFactory.cpp
M src/PlugletLoader.cpp

- remove debug printfs

M test/test.java

- added test finalize.


build.xml classes/org/mozilla/pluglet/PlugletLoader.java examples/MediaPlayer/JMPlayer.java mozilla/Makefile.in mozilla/npAPInsIInputStreamShim.cpp mozilla/npAPInsIInputStreamShim.h mozilla/nppluglet.cpp mozilla/nsScriptablePeer.cpp src/Pluglet.cpp src/PlugletEngine.cpp src/PlugletFactory.cpp src/PlugletLoader.cpp test/test.java
2006-11-02 18:55:50 +00:00

160 lines
3.5 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
*/
#ifndef npAPInsIInputStreamShim_h
#define npAPInsIInputStreamShim_h
#include "nsIPluginStreamListener.h"
#include "nsIPluginStreamInfo.h"
#include "nsIInputStream.h"
#include "nsIAsyncInputStream.h"
#include "nsCOMPtr.h"
struct PRLock;
class npAPInsIInputStreamShim : public nsIAsyncInputStream
{
public:
npAPInsIInputStreamShim(nsIPluginStreamListener *plugletListener,
nsIPluginStreamInfo *streamInfo);
virtual ~npAPInsIInputStreamShim();
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIInputStream methods
NS_DECL_NSIINPUTSTREAM
// nsIAsyncInputStream
NS_DECL_NSIASYNCINPUTSTREAM
NS_IMETHOD AllowStreamToReadFromBuffer(int32 len, void* buf, int32* outWritten);
NS_IMETHOD DoClose(void);
private:
NS_IMETHOD CopyFromPluginHostToBuffer(int32 len, void* buf,
int32* outWritten);
NS_IMETHOD EnsureBuffer(int32 len);
nsCOMPtr<nsIPluginStreamListener> mPlugletListener;
nsCOMPtr<nsIPluginStreamInfo> mStreamInfo;
/**
* a dynamically allocated buffer, written by nppluglet.cpp's
* nsPluginInstance::Write(), read by
* PlugletStreamListener::OnDataAvailable calling our Read().
* deleting this buffer signifies the nppluglet's InputStream should
* be closed.
* MUST be deallocated in the destructor.
*/
void *mBuffer;
/**
* the length of the buffer
*/
uint32 mBufferLength;
/**
* Running sum of the total number of bytes read so far from the
* npapi plugin.
*/
uint32 mCountFromPluginHost;
/**
* Running sum of the total number of bytes read so far by pluglet
*/
uint32 mCountFromPluglet;
/**
* The number of bytes available on the plugin's InputStream
*/
uint32 mAvailable;
/**
* The number of bytes available in the buffer that haven't yet been
* read by the pluglet.
*/
uint32 mAvailableForPluglet;
/**
* The number of bytes written to our internal buffer on the last
* call to AllowStreamToReadFromBuffer.
*/
uint32 mNumWrittenFromPluginHost;
PRBool mDoClose;
PRBool mDidClose;
/**
* Provides mutex
*/
PRLock *mLock;
PRStatus doLock(void);
PRStatus doUnlock(void);
PRBool mHasLock;
nsresult mCloseStatus;
nsCOMPtr<nsIInputStreamCallback> mCallback;
PRUint32 mCallbackFlags;
static const uint32 INITIAL_BUFFER_LENGTH;
static const uint32 buffer_increment;
static const PRInt32 do_close_code;
};
#endif // npAPInsIInputStreamShim_h