Back to index

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

#include <JSEvaluator.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS JSEvaluator (MRJPluginInstance *pluginInstance)
virtual ~JSEvaluator ()
const char * eval (const char *script)
const char * getResult ()
NS_IMETHOD OnStartBinding (nsIPluginStreamInfo *pluginInfo)
 Notify the observer that the URL has started to load.
NS_IMETHOD OnDataAvailable (nsIPluginStreamInfo *pluginInfo, nsIInputStream *input, PRUint32 length)
 Notify the client that data is available in the input stream.
NS_IMETHOD OnFileAvailable (nsIPluginStreamInfo *pluginInfo, const char *fileName)
NS_IMETHOD OnStopBinding (nsIPluginStreamInfo *pluginInfo, nsresult status)
 Notify the observer that the URL has finished loading.
NS_IMETHOD GetStreamType (nsPluginStreamType *result)
 What is this method supposed to do?
NS_DECL_ISUPPORTS JSEvaluator (MRJPluginInstance *pluginInstance)
virtual ~JSEvaluator ()
const char * eval (const char *script)
const char * getResult ()
NS_IMETHOD OnStartBinding (nsIPluginStreamInfo *pluginInfo)
 Notify the observer that the URL has started to load.
NS_IMETHOD OnDataAvailable (nsIPluginStreamInfo *pluginInfo, nsIInputStream *input, PRUint32 length)
 Notify the client that data is available in the input stream.
NS_IMETHOD OnFileAvailable (nsIPluginStreamInfo *pluginInfo, const char *fileName)
NS_IMETHOD OnStopBinding (nsIPluginStreamInfo *pluginInfo, nsresult status)
 Notify the observer that the URL has finished loading.
NS_IMETHOD GetStreamType (nsPluginStreamType *result)
 What is this method supposed to do?
void onStartBinding (in nsIPluginStreamInfo aPluginInfo)
 Notify the observer that the URL has started to load.
void onDataAvailable (in nsIPluginStreamInfo aPluginInfo, in nsIInputStream aInputStream, in unsigned long aLength)
 Notify the client that data is available in the input stream.
void onFileAvailable (in nsIPluginStreamInfo aPluginInfo, in string aFileName)
 Notify the client that data is available in the file.
void onStopBinding (in nsIPluginStreamInfo aPluginInfo, in nsresult aStatus)
 Notify the observer that the URL has finished loading.

Public Attributes

readonly attribute
nsPluginStreamType 
streamType
 Gets the type of the stream.

Private Attributes

MRJPluginInstancemPluginInstance
MRJSessionmSession
MRJMonitormJSMonitor
char * mScript
char * mResult

Detailed Description

Definition at line 53 of file JSEvaluator.h.


Constructor & Destructor Documentation

Definition at line 51 of file JSEvaluator.cpp.

       :      mPluginInstance(pluginInstance)
{
       NS_ADDREF(pluginInstance);
       mSession = pluginInstance->getSession();
       mJSMonitor = new MRJMonitor(mSession);
}

Here is the call graph for this function:

Definition at line 59 of file JSEvaluator.cpp.

virtual JSEvaluator::~JSEvaluator ( ) [virtual]

Member Function Documentation

const char * JSEvaluator::eval ( const char *  script)

Definition at line 68 of file JSEvaluator.cpp.

{
       JNIEnv* env = mSession->getCurrentEnv();
       nsIPluginStreamListener* listener = this;

       mJSMonitor->enter();

       while (mScript != NULL) {
              // some other thread is evaluating a script.
              mJSMonitor->wait();
       }
       
       // construct a "javascript:" URL from the passed-in script.
       const char* kJavaScriptPrefix = "javascript:";
       mScript = new char[strlen(kJavaScriptPrefix) + strlen(script) + 1];
       if (mScript != NULL) {
              strcpy(mScript, kJavaScriptPrefix);
              strcat(mScript, script);

              // start an async evaluation of this script.
              nsresult result = thePluginManager->GetURL((nsIPluginInstance*)mPluginInstance, mScript, NULL, (nsIPluginStreamListener*)this);
              
              // default result is NULL, in case JavaScript returns undefined value.
              if (mResult != NULL) {
                     delete[] mResult;
                     mResult = NULL;
              }

              // need to block until the result is ready.
              mJSMonitor->wait();
              
              // can now delete the script.
              delete[] mScript;
              mScript = NULL;
       }
       
       mJSMonitor->notifyAll();
       
       mJSMonitor->exit();
       
       return mResult;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* JSEvaluator::eval ( const char *  script)
const char* JSEvaluator::getResult ( ) [inline]

Definition at line 62 of file JSEvaluator.h.

    {
       return mResult;
    }
const char* JSEvaluator::getResult ( ) [inline]

Definition at line 63 of file JSEvaluator.h.

    {
       return mResult;
    }

What is this method supposed to do?

Definition at line 119 of file JSEvaluator.h.

What is this method supposed to do?

Definition at line 120 of file JSEvaluator.h.

void nsIPluginStreamListener::onDataAvailable ( in nsIPluginStreamInfo  aPluginInfo,
in nsIInputStream  aInputStream,
in unsigned long  aLength 
) [inherited]

Notify the client that data is available in the input stream.

This method is called whenver data is written into the input stream by the networking library...

Parameters:
aPluginInfo- plugin stream info
aInputStream- the input stream containing the data. This stream can be either a blocking or non-blocking stream.
aLength- the amount of data that was just pushed into the stream.
Returns:
- the return value is currently ignored.

Notify the client that data is available in the input stream.

This method is called whenver data is written into the input stream by the networking library...

Parameters:
aIStreamThe input stream containing the data. This stream can be either a blocking or non-blocking stream.
lengthThe amount of data that was just pushed into the stream.
Returns:
The return value is currently ignored.

Definition at line 111 of file JSEvaluator.cpp.

{
       // hopefully all our data is available.
       mResult = new char[length + 1];
       if (mResult != NULL) {
              if (input->Read(mResult, length, &length) == NS_OK) {
                     // We've delayed processing the applet tag, because we
                     // don't know the location of the curren document yet.
                     mResult[length] = '\0';
              }
       }
       return NS_OK;
}

Notify the client that data is available in the input stream.

This method is called whenver data is written into the input stream by the networking library...

Parameters:
aIStreamThe input stream containing the data. This stream can be either a blocking or non-blocking stream.
lengthThe amount of data that was just pushed into the stream.
Returns:
The return value is currently ignored.
NS_IMETHOD JSEvaluator::OnFileAvailable ( nsIPluginStreamInfo pluginInfo,
const char *  fileName 
) [inline]

Definition at line 96 of file JSEvaluator.h.

void nsIPluginStreamListener::onFileAvailable ( in nsIPluginStreamInfo  aPluginInfo,
in string  aFileName 
) [inherited]

Notify the client that data is available in the file.

Parameters:
aPluginInfo- plugin stream info
aFileName- the name of the file containing the data
Returns:
- the return value is currently ignored.
NS_IMETHOD JSEvaluator::OnFileAvailable ( nsIPluginStreamInfo pluginInfo,
const char *  fileName 
) [inline]

Definition at line 97 of file JSEvaluator.h.

Notify the observer that the URL has started to load.

This method is called only once, at the beginning of a URL load.

Parameters:
aPluginInfo- plugin stream info
Returns:
- the return value is currently ignored, in the future it may be used to cancel the URL load..

Notify the observer that the URL has started to load.

This method is called only once, at the beginning of a URL load.

Returns:
The return value is currently ignored. In the future it may be used to cancel the URL load..

Definition at line 77 of file JSEvaluator.h.

    {
       return NS_OK;
    }

Notify the observer that the URL has started to load.

This method is called only once, at the beginning of a URL load.

Returns:
The return value is currently ignored. In the future it may be used to cancel the URL load..

Definition at line 78 of file JSEvaluator.h.

    {
       return NS_OK;
    }
void nsIPluginStreamListener::onStopBinding ( in nsIPluginStreamInfo  aPluginInfo,
in nsresult  aStatus 
) [inherited]

Notify the observer that the URL has finished loading.

This method is called once when the networking library has finished processing the URL transaction initiatied via the nsINetService::Open(...) call.

This method is called regardless of whether the URL loaded successfully.

Parameters:
aPluginInfo- plugin stream info
aStatus- reason why the stream has been terminated
Returns:
- the return value is currently ignored.

Notify the observer that the URL has finished loading.

This method is called once when the networking library has finished processing the URL transaction initiatied via the nsINetService::Open(...) call.

This method is called regardless of whether the URL loaded successfully.

Parameters:
statusStatus code for the URL load.
msgA text string describing the error.
Returns:
The return value is currently ignored.

Definition at line 125 of file JSEvaluator.cpp.

{
       // the stream has been closed, notify any waiting Java threads.
       mJSMonitor->notifyAll();
       return NS_OK;
}

Here is the call graph for this function:

Notify the observer that the URL has finished loading.

This method is called once when the networking library has finished processing the URL transaction initiatied via the nsINetService::Open(...) call.

This method is called regardless of whether the URL loaded successfully.

Parameters:
statusStatus code for the URL load.
msgA text string describing the error.
Returns:
The return value is currently ignored.

Member Data Documentation

Definition at line 128 of file JSEvaluator.h.

Definition at line 126 of file JSEvaluator.h.

char * JSEvaluator::mResult [private]

Definition at line 130 of file JSEvaluator.h.

char * JSEvaluator::mScript [private]

Definition at line 129 of file JSEvaluator.h.

Definition at line 127 of file JSEvaluator.h.

Gets the type of the stream.

Parameters:
aStreamType- the type of the stream

Definition at line 118 of file nsIPluginStreamListener.idl.


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