зеркало из https://github.com/mozilla/gecko-dev.git
Bug 97488 -- sample code to reflect new approach to scripting, not part of the build, patch by jband and av, r=av
This commit is contained in:
Родитель
6739f719bb
Коммит
3d8172178a
|
@ -21,7 +21,7 @@ include <$(DEPTH)/config/config.mak>
|
||||||
MODULE = np4xscr
|
MODULE = np4xscr
|
||||||
|
|
||||||
XPIDLSRCS = \
|
XPIDLSRCS = \
|
||||||
.\nsI4xScrPlugin.idl \
|
.\nsI4xScriptablePlugin.idl \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
MAKE_OBJ_TYPE = DLL
|
MAKE_OBJ_TYPE = DLL
|
||||||
|
@ -40,6 +40,11 @@ OBJS = \
|
||||||
|
|
||||||
WIN_LIBS = version.lib
|
WIN_LIBS = version.lib
|
||||||
|
|
||||||
|
#uncomment if you are building the nsScriptablePeer1 version
|
||||||
|
#LLIBS= $(LIBNSPR) \
|
||||||
|
# $(DIST)\lib\xpcom.lib \
|
||||||
|
# $(NULL)
|
||||||
|
|
||||||
include <$(DEPTH)/config/rules.mak>
|
include <$(DEPTH)/config/rules.mak>
|
||||||
|
|
||||||
#MAKE_INSTALL=echo $(MAKE_INSTALL)
|
#MAKE_INSTALL=echo $(MAKE_INSTALL)
|
||||||
|
|
|
@ -132,11 +132,11 @@ NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
|
||||||
if(pPlugin == NULL)
|
if(pPlugin == NULL)
|
||||||
return NPERR_GENERIC_ERROR;
|
return NPERR_GENERIC_ERROR;
|
||||||
|
|
||||||
static nsIID scriptableIID = NS_I4XSCRPLUGIN_IID;
|
static nsIID scriptableIID = NS_I4XSCRIPTABLEPLUGIN_IID;
|
||||||
|
|
||||||
if (variable == NPPVpluginScriptableInstance) {
|
if (variable == NPPVpluginScriptableInstance) {
|
||||||
// addref happens in getter, so we don't addref here
|
// addref happens in getter, so we don't addref here
|
||||||
nsI4xScrPlugin * scriptablePeer = pPlugin->getScriptablePeer();
|
nsI4xScriptablePlugin * scriptablePeer = pPlugin->getScriptablePeer();
|
||||||
*(nsISupports **)value = scriptablePeer;
|
*(nsISupports **)value = scriptablePeer;
|
||||||
}
|
}
|
||||||
else if (variable == NPPVpluginScriptableIID) {
|
else if (variable == NPPVpluginScriptableIID) {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||||
|
*
|
||||||
|
* 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.org code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
|
[scriptable, uuid(482e1890-1fe5-11d5-9cf8-0060b0fbd8ac)]
|
||||||
|
interface nsI4xScriptablePlugin : nsISupports {
|
||||||
|
void showVersion();
|
||||||
|
void clear();
|
||||||
|
};
|
|
@ -33,8 +33,8 @@
|
||||||
//
|
//
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
static NS_DEFINE_IID(kI4xScrPluginIID, NS_I4XSCRPLUGIN_IID);
|
static NS_DEFINE_IID(kI4xScriptablePluginIID, NS_I4XSCRIPTABLEPLUGIN_IID);
|
||||||
static NS_DEFINE_IID(kISecurityCheckedComponentIID, NS_ISECURITYCHECKEDCOMPONENT_IID);
|
static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
|
||||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
|
||||||
nsScriptablePeer::nsScriptablePeer(CPlugin* aPlugin)
|
nsScriptablePeer::nsScriptablePeer(CPlugin* aPlugin)
|
||||||
|
@ -72,20 +72,20 @@ NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstan
|
||||||
if(!aInstancePtr)
|
if(!aInstancePtr)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
if(aIID.Equals(kI4xScrPluginIID)) {
|
if(aIID.Equals(kI4xScriptablePluginIID)) {
|
||||||
*aInstancePtr = static_cast<nsI4xScrPlugin*>(this);
|
*aInstancePtr = static_cast<nsI4xScriptablePlugin*>(this);
|
||||||
AddRef();
|
AddRef();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aIID.Equals(kISecurityCheckedComponentIID)) {
|
if(aIID.Equals(kIClassInfoIID)) {
|
||||||
*aInstancePtr = static_cast<nsISecurityCheckedComponent*>(this);
|
*aInstancePtr = static_cast<nsIClassInfo*>(this);
|
||||||
AddRef();
|
AddRef();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aIID.Equals(kISupportsIID)) {
|
if(aIID.Equals(kISupportsIID)) {
|
||||||
*aInstancePtr = static_cast<nsISupports*>(static_cast<nsI4xScrPlugin*>(this));
|
*aInstancePtr = static_cast<nsISupports*>(static_cast<nsI4xScriptablePlugin*>(this));
|
||||||
AddRef();
|
AddRef();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -111,65 +111,3 @@ NS_IMETHODIMP nsScriptablePeer::Clear()
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// the purpose of the rest of the code is to get succesfully
|
|
||||||
// through the Mozilla Security Manager
|
|
||||||
//
|
|
||||||
static const char gAllAccess[] = "AllAccess";
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanCreateWrapper(const nsIID * iid, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,17 +30,41 @@
|
||||||
#ifndef __nsScriptablePeer_h__
|
#ifndef __nsScriptablePeer_h__
|
||||||
#define __nsScriptablePeer_h__
|
#define __nsScriptablePeer_h__
|
||||||
|
|
||||||
#include "nsI4xScrPlugin.h"
|
#include "nsI4xScriptablePlugin.h"
|
||||||
#include "nsISecurityCheckedComponent.h"
|
#include "nsIClassInfo.h"
|
||||||
|
|
||||||
class CPlugin;
|
class CPlugin;
|
||||||
|
|
||||||
// we should add nsISecurityCheckedComponent because the
|
// We must implement nsIClassInfo because it signals the
|
||||||
// Mozilla Security Manager will ask scriptable object about
|
// Mozilla Security Manager to allow calls from JavaScript.
|
||||||
// priveleges the plugin requests in order to allow calls
|
|
||||||
// from JavaScript
|
class nsClassInfoMixin : public nsIClassInfo
|
||||||
class nsScriptablePeer : public nsI4xScrPlugin,
|
{
|
||||||
public nsISecurityCheckedComponent
|
// These flags are used by the DOM and security systems to signal that
|
||||||
|
// JavaScript callers are allowed to call this object's scritable methods.
|
||||||
|
NS_IMETHOD GetFlags(PRUint32 *aFlags)
|
||||||
|
{*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
|
||||||
|
return NS_OK;}
|
||||||
|
NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
|
||||||
|
{*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
||||||
|
return NS_OK;}
|
||||||
|
// The rest of the methods can safely return error codes...
|
||||||
|
NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetContractID(char * *aContractID)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassDescription(char * *aClassDescription)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassID(nsCID * *aClassID)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class nsScriptablePeer : public nsI4xScriptablePlugin,
|
||||||
|
public nsClassInfoMixin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsScriptablePeer(CPlugin* plugin);
|
nsScriptablePeer(CPlugin* plugin);
|
||||||
|
@ -60,12 +84,6 @@ public:
|
||||||
NS_IMETHOD ShowVersion();
|
NS_IMETHOD ShowVersion();
|
||||||
NS_IMETHOD Clear();
|
NS_IMETHOD Clear();
|
||||||
|
|
||||||
// methods from nsISecurityCheckedComponent
|
|
||||||
NS_IMETHOD CanCreateWrapper(const nsIID * iid, char **_retval);
|
|
||||||
NS_IMETHOD CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval);
|
|
||||||
NS_IMETHOD CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval);
|
|
||||||
NS_IMETHOD CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CPlugin* mPlugin;
|
CPlugin* mPlugin;
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,7 +44,8 @@ nsScriptablePeer::~nsScriptablePeer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS2(nsScriptablePeer, nsI4xScrPlugin, nsISecurityCheckedComponent)
|
// Notice that we expose our claim to implement nsIClassInfo.
|
||||||
|
NS_IMPL_ISUPPORTS2(nsScriptablePeer, nsI4xScriptablePlugin, nsIClassInfo)
|
||||||
|
|
||||||
//
|
//
|
||||||
// the following two methods will be callable from JavaScript
|
// the following two methods will be callable from JavaScript
|
||||||
|
@ -64,65 +65,3 @@ NS_IMETHODIMP nsScriptablePeer::Clear()
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// the purpose of the rest of the code is to get succesfully
|
|
||||||
// through the Mozilla Security Manager
|
|
||||||
//
|
|
||||||
static const char gAllAccess[] = "AllAccess";
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanCreateWrapper(const nsIID * iid, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsScriptablePeer::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
||||||
{
|
|
||||||
if (!_retval)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*_retval = (char*)NPN_MemAlloc(sizeof(gAllAccess)+1);
|
|
||||||
if (!*_retval)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
strcpy(*_retval, gAllAccess);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,25 +30,48 @@
|
||||||
#ifndef __nsScriptablePeer_h__
|
#ifndef __nsScriptablePeer_h__
|
||||||
#define __nsScriptablePeer_h__
|
#define __nsScriptablePeer_h__
|
||||||
|
|
||||||
#include "nsI4xScrPlugin.h"
|
#include "nsI4xScriptablePlugin.h"
|
||||||
#include "nsISecurityCheckedComponent.h"
|
#include "nsIClassInfo.h"
|
||||||
|
|
||||||
class CPlugin;
|
class CPlugin;
|
||||||
|
|
||||||
// we should add nsISecurityCheckedComponent because the
|
// We must implement nsIClassInfo because it signals the
|
||||||
// Mozilla Security Manager will ask scriptable object about
|
// Mozilla Security Manager to allow calls from JavaScript.
|
||||||
// priveleges the plugin requests in order to allow calls
|
|
||||||
// from JavaScript
|
class nsClassInfoMixin : public nsIClassInfo
|
||||||
class nsScriptablePeer : public nsI4xScrPlugin,
|
{
|
||||||
public nsISecurityCheckedComponent
|
// These flags are used by the DOM and security systems to signal that
|
||||||
|
// JavaScript callers are allowed to call this object's scritable methods.
|
||||||
|
NS_IMETHOD GetFlags(PRUint32 *aFlags)
|
||||||
|
{*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
|
||||||
|
return NS_OK;}
|
||||||
|
NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
|
||||||
|
{*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
||||||
|
return NS_OK;}
|
||||||
|
// The rest of the methods can safely return error codes...
|
||||||
|
NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetContractID(char * *aContractID)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassDescription(char * *aClassDescription)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassID(nsCID * *aClassID)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
||||||
|
{return NS_ERROR_NOT_IMPLEMENTED;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class nsScriptablePeer : public nsI4xScriptablePlugin,
|
||||||
|
public nsClassInfoMixin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsScriptablePeer(CPlugin* plugin);
|
nsScriptablePeer(CPlugin* plugin);
|
||||||
~nsScriptablePeer();
|
~nsScriptablePeer();
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
NS_DECL_NSI4XSCRPLUGIN
|
NS_DECL_NSI4XSCRIPTABLEPLUGIN
|
||||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CPlugin* mPlugin;
|
CPlugin* mPlugin;
|
||||||
|
|
|
@ -121,7 +121,7 @@ void CPlugin::clear()
|
||||||
// ==============================
|
// ==============================
|
||||||
//
|
//
|
||||||
// this method will return the scriptable object (and create it if necessary)
|
// this method will return the scriptable object (and create it if necessary)
|
||||||
nsI4xScrPlugin* CPlugin::getScriptablePeer()
|
nsI4xScriptablePlugin* CPlugin::getScriptablePeer()
|
||||||
{
|
{
|
||||||
if (!m_pScriptablePeer) {
|
if (!m_pScriptablePeer) {
|
||||||
m_pScriptablePeer = new nsScriptablePeer(this);
|
m_pScriptablePeer = new nsScriptablePeer(this);
|
||||||
|
|
|
@ -37,7 +37,7 @@ private:
|
||||||
|
|
||||||
NPStream * m_pNPStream;
|
NPStream * m_pNPStream;
|
||||||
BOOL m_bInitialized;
|
BOOL m_bInitialized;
|
||||||
nsI4xScrPlugin * m_pScriptablePeer;
|
nsI4xScriptablePlugin * m_pScriptablePeer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
char m_String[128];
|
char m_String[128];
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
void showVersion();
|
void showVersion();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
nsI4xScrPlugin* getScriptablePeer();
|
nsI4xScriptablePlugin* getScriptablePeer();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __PLUGIN_H__
|
#endif // __PLUGIN_H__
|
||||||
|
|
Загрузка…
Ссылка в новой задаче