[not part of build] 2-way plugin scripting example.

This commit is contained in:
beard@netscape.com
2002-03-27 01:16:06 +00:00
parent 15278b9a02
commit 8fc2b95947
3 changed files with 39 additions and 1 deletions

View File

@@ -47,6 +47,8 @@
// be callable from JavaScript
//
#include "plugin.h"
#include "acmeIScriptObject.h"
#include "npapi.h"
static NS_DEFINE_IID(kI4xScriptablePluginIID, NS_I4XSCRIPTABLEPLUGIN_IID);
static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
@@ -54,8 +56,9 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsScriptablePeer::nsScriptablePeer(CPlugin* aPlugin)
{
mPlugin = aPlugin;
mRefCnt = 0;
mPlugin = aPlugin;
mWindow = nsnull;
}
nsScriptablePeer::~nsScriptablePeer()
@@ -133,3 +136,33 @@ NS_IMETHODIMP nsScriptablePeer::GetVersion(char * *aVersion)
mPlugin->getVersion(aVersion);
return NS_OK;
}
NS_IMETHODIMP nsScriptablePeer::SetWindow(acmeIScriptObject *window)
{
NS_IF_ADDREF(window);
NS_IF_RELEASE(mWindow);
mWindow = window;
// evaluate a JavaScript expression.
acmeIScriptObject* result;
nsresult rv = window->Evaluate("Math.PI", &result);
if (NS_SUCCEEDED(rv) && result) {
double value;
result->ToNumber(&value);
NS_RELEASE(result);
}
// read the current window's location.
acmeIScriptObject* location = nsnull;
rv = window->GetProperty("location", &location);
if (NS_SUCCEEDED(rv) && location) {
char* locationStr = NULL;
rv = location->ToString(&locationStr);
if (NS_SUCCEEDED(rv) && locationStr) {
NPN_MemFree(locationStr);
}
NS_RELEASE(location);
}
return NS_OK;
}