Commit 24fbf130 authored by darin's avatar darin

Reviewed by John Sullivan.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7681
          memory leak in the plug-in tests

        * DumpRenderTree/TestNetscapePlugIn.subproj/main.c:
        (NPP_Destroy): Added code to release the plug-in object. This is the leak fix.
        (NPP_SetWindow): Remove unneeded code to store the window pointer.

        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
        Moved the browser global in here since it's declared in this file's header.
        Changed the code to set up the pluginClass structure to not use function
        pointer casts. Those are dangerous because they can hide many types of mismatch.
        And indeed when I did this I discovered that many functions were missing their
        boolean return values or had parameter declarations with the wrong types.
        (pluginGetProperty): Use STRINGZ_TO_NPVARIANT macro for greater simplicity and
        clarity. Added boolean return value: return true when successful and false when not.
        (pluginSetProperty): Added boolean return value, return false since we have no
        properties we can set.
        (pluginInvoke): Added boolean return value. Return true when successful and false
        when not. Use NPVARIANT macros where appropriate. Added a missing release for the
        return value from calling the browser. Changed code to put the strings in malloc
        buffers instead of relying on GCC's extension that allows variable-sized arrays
        on the stack.
        (pluginInvokeDefault): Added boolean return value, return false since we have no
        default function to call.
        (pluginInvalidate): Added missing parameter. Removed comment.
        (pluginAllocate): Removed unneeded cast. This is C code, not C++, so you don't have
        to cast the result of malloc.
        (pluginDeallocate): Removed uneeded cast.

        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.h: Removed some unneeded
        includes. Changed our PluginObject to use NPObject instead of re-declaring fields
        that match NPObject's fields. Removed unused NPWindow pointer.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@13233 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dc520bc7
2006-03-09 Darin Adler <darin@apple.com>
Reviewed by John Sullivan.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=7681
memory leak in the plug-in tests
* DumpRenderTree/TestNetscapePlugIn.subproj/main.c:
(NPP_Destroy): Added code to release the plug-in object. This is the leak fix.
(NPP_SetWindow): Remove unneeded code to store the window pointer.
* DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
Moved the browser global in here since it's declared in this file's header.
Changed the code to set up the pluginClass structure to not use function
pointer casts. Those are dangerous because they can hide many types of mismatch.
And indeed when I did this I discovered that many functions were missing their
boolean return values or had parameter declarations with the wrong types.
(pluginGetProperty): Use STRINGZ_TO_NPVARIANT macro for greater simplicity and
clarity. Added boolean return value: return true when successful and false when not.
(pluginSetProperty): Added boolean return value, return false since we have no
properties we can set.
(pluginInvoke): Added boolean return value. Return true when successful and false
when not. Use NPVARIANT macros where appropriate. Added a missing release for the
return value from calling the browser. Changed code to put the strings in malloc
buffers instead of relying on GCC's extension that allows variable-sized arrays
on the stack.
(pluginInvokeDefault): Added boolean return value, return false since we have no
default function to call.
(pluginInvalidate): Added missing parameter. Removed comment.
(pluginAllocate): Removed unneeded cast. This is C code, not C++, so you don't have
to cast the result of malloc.
(pluginDeallocate): Removed uneeded cast.
* DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.h: Removed some unneeded
includes. Changed our PluginObject to use NPObject instead of re-declaring fields
that match NPObject's fields. Removed unused NPWindow pointer.
2006-03-09 Mitz Pettel <opendarwin.org@mitzpettel.com>
Test: fast/events/event-sender-mouse-click.html
......
......@@ -108,10 +108,10 @@
/* Begin PBXFileReference section */
08FB7796FE84155DC02AAC07 /* DumpRenderTree.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DumpRenderTree.m; sourceTree = "<group>"; };
141BF233096A44CF00E0753C /* TestNetscapePlugIn.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestNetscapePlugIn.plugin; sourceTree = BUILT_PRODUCTS_DIR; };
141BF445096A45C800E0753C /* main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = main.c; path = ../TestNetscapePlugIn.subproj/main.c; sourceTree = "<group>"; };
141BF446096A45C800E0753C /* PluginObject.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = PluginObject.c; path = ../TestNetscapePlugIn.subproj/PluginObject.c; sourceTree = "<group>"; };
141BF447096A45C800E0753C /* PluginObject.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = PluginObject.h; path = ../TestNetscapePlugIn.subproj/PluginObject.h; sourceTree = "<group>"; };
141BF448096A45C800E0753C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; name = Info.plist; path = ../TestNetscapePlugIn.subproj/Info.plist; sourceTree = "<group>"; };
141BF445096A45C800E0753C /* main.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
141BF446096A45C800E0753C /* PluginObject.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = PluginObject.c; sourceTree = "<group>"; };
141BF447096A45C800E0753C /* PluginObject.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PluginObject.h; sourceTree = "<group>"; };
141BF448096A45C800E0753C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; path = Info.plist; sourceTree = "<group>"; };
14A6FB880971CAE5008B014F /* NavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = "<group>"; };
14A6FB890971CAE5008B014F /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = "<group>"; };
32A70AAB03705E1F00C91783 /* DumpRenderTreePrefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DumpRenderTreePrefix.h; sourceTree = "<group>"; };
......
......@@ -30,34 +30,37 @@
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "PluginObject.h"
void pluginInvalidate ();
bool pluginHasProperty (NPClass *theClass, NPIdentifier name);
bool pluginHasMethod (NPClass *theClass, NPIdentifier name);
void pluginGetProperty (PluginObject *obj, NPIdentifier name, NPVariant *variant);
void pluginSetProperty (PluginObject *obj, NPIdentifier name, const NPVariant *variant);
void pluginInvoke (PluginObject *obj, NPIdentifier name, NPVariant *args, uint32_t argCount, NPVariant *result);
void pluginInvokeDefault (PluginObject *obj, NPVariant *args, uint32_t argCount, NPVariant *result);
NPObject *pluginAllocate (NPP npp, NPClass *theClass);
void pluginDeallocate (PluginObject *obj);
static NPClass _pluginFunctionPtrs = {
static void pluginInvalidate(NPObject *obj);
static bool pluginHasProperty(NPObject *obj, NPIdentifier name);
static bool pluginHasMethod(NPObject *obj, NPIdentifier name);
static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant);
static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant);
static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
static NPObject *pluginAllocate(NPP npp, NPClass *theClass);
static void pluginDeallocate(NPObject *obj);
NPNetscapeFuncs *browser;
static NPClass pluginClass = {
NP_CLASS_STRUCT_VERSION,
(NPAllocateFunctionPtr) pluginAllocate,
(NPDeallocateFunctionPtr) pluginDeallocate,
(NPInvalidateFunctionPtr) pluginInvalidate,
(NPHasMethodFunctionPtr) pluginHasMethod,
(NPInvokeFunctionPtr) pluginInvoke,
(NPInvokeDefaultFunctionPtr) pluginInvokeDefault,
(NPHasPropertyFunctionPtr) pluginHasProperty,
(NPGetPropertyFunctionPtr) pluginGetProperty,
(NPSetPropertyFunctionPtr) pluginSetProperty,
pluginAllocate,
pluginDeallocate,
pluginInvalidate,
pluginHasMethod,
pluginInvoke,
pluginInvokeDefault,
pluginHasProperty,
pluginGetProperty,
pluginSetProperty,
};
NPClass *getPluginClass(void)
{
return &_pluginFunctionPtrs;
return &pluginClass;
}
static bool identifiersInitialized = false;
......@@ -80,102 +83,99 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
"getURL"
};
static void initializeIdentifiers()
static NPUTF8* createCStringFromNPVariant(const NPVariant *variant)
{
browser->getstringidentifiers (pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers);
browser->getstringidentifiers (pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers);
};
size_t length = NPVARIANT_TO_STRING(*variant).UTF8Length;
NPUTF8* result = malloc(length + 1);
memcpy(result, NPVARIANT_TO_STRING(*variant).UTF8Characters, length);
result[length] = '\0';
return result;
}
static void initializeIdentifiers(void)
{
browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers);
browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers);
}
bool pluginHasProperty (NPClass *theClass, NPIdentifier name)
static bool pluginHasProperty(NPObject *obj, NPIdentifier name)
{
for (int i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) {
for (int i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++)
if (name == pluginPropertyIdentifiers[i])
return true;
}
return false;
}
bool pluginHasMethod (NPClass *theClass, NPIdentifier name)
static bool pluginHasMethod(NPObject *obj, NPIdentifier name)
{
for (int i = 0; i < NUM_METHOD_IDENTIFIERS; i++) {
for (int i = 0; i < NUM_METHOD_IDENTIFIERS; i++)
if (name == pluginMethodIdentifiers[i])
return true;
}
return false;
}
void pluginGetProperty (PluginObject *obj, NPIdentifier name, NPVariant *variant)
static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant)
{
if (name == pluginPropertyIdentifiers[ID_PROPERTY_PROPERTY]) {
// just return "property"
NPString propertyNameString;
propertyNameString.UTF8Characters = "property";
propertyNameString.UTF8Length = sizeof("property") - 1;
variant->type = NPVariantType_String;
variant->value.stringValue = propertyNameString;
} else
variant->type = NPVariantType_Void;
STRINGZ_TO_NPVARIANT("property", *variant);
return true;
}
return false;
}
void pluginSetProperty (PluginObject *obj, NPIdentifier name, const NPVariant *variant)
static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
{
return false;
}
void pluginInvoke (PluginObject *obj, NPIdentifier name, NPVariant *args, unsigned argCount, NPVariant *result)
static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
PluginObject *obj = (PluginObject *)header;
if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD]) {
// call whatever method name we're given
if (argCount > 0 && args->type == NPVariantType_String) {
NPVariant browserResult;
if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
NPObject *windowScriptObject;
browser->getvalue(obj->npp, NPPVpluginScriptableNPObject, &windowScriptObject);
NPString argString = args[0].value.stringValue;
int size = argString.UTF8Length + 1;
NPUTF8 callbackString[size];
strncpy(callbackString, argString.UTF8Characters, argString.UTF8Length);
callbackString[size - 1] = '\0';
NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
free(callbackString);
NPVariant browserResult;
browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult);
browser->releasevariantvalue(&browserResult);
NPIdentifier callbackMethodID = browser->getstringidentifier(callbackString);
browser->invoke(obj->npp, windowScriptObject, callbackMethodID, 0, 0, &browserResult);
VOID_TO_NPVARIANT(*result);
return true;
}
} else if (name == pluginMethodIdentifiers[ID_TEST_GETURL]) {
if (argCount == 2 && args[0].type == NPVariantType_String && args[1].type == NPVariantType_String) {
NPString argString = args[0].value.stringValue;
int size = argString.UTF8Length + 1;
NPUTF8 urlString[size];
strncpy(urlString, argString.UTF8Characters, argString.UTF8Length);
urlString[size - 1] = '\0';
argString = args[1].value.stringValue;
size = argString.UTF8Length + 1;
NPUTF8 targetString[size];
strncpy(targetString, argString.UTF8Characters, argString.UTF8Length);
targetString[size - 1] = '\0';
if (argCount == 2 && NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1])) {
NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
NPUTF8* targetString = createCStringFromNPVariant(&args[1]);
browser->geturl(obj->npp, urlString, targetString);
free(urlString);
free(targetString);
VOID_TO_NPVARIANT(*result);
return true;
}
}
result->type = NPVariantType_Void;
return false;
}
void pluginInvokeDefault (PluginObject *obj, NPVariant *args, unsigned argCount, NPVariant *result)
static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
result->type = NPVariantType_Void;
return false;
}
void pluginInvalidate ()
static void pluginInvalidate(NPObject *obj)
{
// Make sure we've released any remainging references to JavaScript
// objects.
}
NPObject *pluginAllocate (NPP npp, NPClass *theClass)
static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
{
PluginObject *newInstance = (PluginObject *)malloc (sizeof(PluginObject));
PluginObject *newInstance = malloc(sizeof(PluginObject));
if (!identifiersInitialized) {
identifiersInitialized = true;
......@@ -187,8 +187,7 @@ NPObject *pluginAllocate (NPP npp, NPClass *theClass)
return (NPObject *)newInstance;
}
void pluginDeallocate (PluginObject *obj)
static void pluginDeallocate(NPObject *obj)
{
free ((void *)obj);
free(obj);
}
......@@ -30,19 +30,14 @@
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <WebKit/npapi.h>
#import <WebKit/npfunctions.h>
#import <WebKit/npruntime.h>
extern NPNetscapeFuncs* browser;
extern NPNetscapeFuncs *browser;
typedef struct
{
NPClass *_class;
uint32_t referenceCount;
typedef struct {
NPObject header;
NPP npp;
NPWindow* window;
} PluginObject;
extern NPClass *getPluginClass(void);
......@@ -30,9 +30,8 @@
WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "PluginObject.h"
NPNetscapeFuncs *browser;
#import "PluginObject.h"
// Mach-o entry points
NPError NP_Initialize(NPNetscapeFuncs *browserFuncs);
......@@ -69,34 +68,28 @@ NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs)
void NP_Shutdown(void)
{
}
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
{
if (browser->version >= 14)
instance->pdata = browser->createobject (instance, getPluginClass());
instance->pdata = browser->createobject(instance, getPluginClass());
return NPERR_NO_ERROR;
}
NPError NPP_Destroy(NPP instance, NPSavedData **save)
{
PluginObject *obj = instance->pdata;
if (obj)
browser->releaseobject(&obj->header);
return NPERR_NO_ERROR;
}
NPError NPP_SetWindow(NPP instance, NPWindow *window)
{
PluginObject *obj = instance->pdata;
// Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject.
if (obj != NULL)
obj->window = window;
return NPERR_NO_ERROR;
}
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
{
*stype = NP_ASFILEONLY;
......@@ -120,12 +113,10 @@ int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *b
void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
{
}
void NPP_Print(NPP instance, NPPrint *platformPrint)
{
}
int16 NPP_HandleEvent(NPP instance, void *event)
......@@ -135,7 +126,6 @@ int16 NPP_HandleEvent(NPP instance, void *event)
void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
{
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment