summaryrefslogtreecommitdiffstats
path: root/webkit/tools/npapi_layout_test_plugin/PluginObject.cpp
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-07 09:51:21 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-07 09:51:21 +0000
commit9467a7c272760f3dab020c74b5aeb23c9a6aee1b (patch)
treeaacfc0e83a6ceade29c77f643c7e3a7edce8383d /webkit/tools/npapi_layout_test_plugin/PluginObject.cpp
parent9f8ebd567bb8ef48338baf669553f6451f40f157 (diff)
downloadchromium_src-9467a7c272760f3dab020c74b5aeb23c9a6aee1b.zip
chromium_src-9467a7c272760f3dab020c74b5aeb23c9a6aee1b.tar.gz
chromium_src-9467a7c272760f3dab020c74b5aeb23c9a6aee1b.tar.bz2
Merge in a bunch of upstream changes to the layout test npapi plugin.
Review URL: http://codereview.chromium.org/6272 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2932 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/npapi_layout_test_plugin/PluginObject.cpp')
-rw-r--r--webkit/tools/npapi_layout_test_plugin/PluginObject.cpp249
1 files changed, 124 insertions, 125 deletions
diff --git a/webkit/tools/npapi_layout_test_plugin/PluginObject.cpp b/webkit/tools/npapi_layout_test_plugin/PluginObject.cpp
index 3c005c3..99699d0 100644
--- a/webkit/tools/npapi_layout_test_plugin/PluginObject.cpp
+++ b/webkit/tools/npapi_layout_test_plugin/PluginObject.cpp
@@ -1,34 +1,26 @@
/*
- IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in
- consideration of your agreement to the following terms, and your use, installation,
- modification or redistribution of this Apple software constitutes acceptance of these
- terms. If you do not agree with these terms, please do not use, install, modify or
- redistribute this Apple software.
-
- In consideration of your agreement to abide by the following terms, and subject to these
- terms, Apple grants you a personal, non-exclusive license, under Appleā€™s copyrights in
- this original Apple software (the "Apple Software"), to use, reproduce, modify and
- redistribute the Apple Software, with or without modifications, in source and/or binary
- forms; provided that if you redistribute the Apple Software in its entirety and without
- modifications, you must retain this notice and the following text and disclaimers in all
- such redistributions of the Apple Software. Neither the name, trademarks, service marks
- or logos of Apple Computer, Inc. may be used to endorse or promote products derived from
- the Apple Software without specific prior written permission from Apple. Except as expressly
- stated in this notice, no other rights or licenses, express or implied, are granted by Apple
- herein, including but not limited to any patent rights that may be infringed by your
- derivative works or by other works in which the Apple Software may be incorporated.
-
- The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
- EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS
- USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
-
- IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
- REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND
- WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
- OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginObject.h"
@@ -41,22 +33,22 @@
#define snprintf sprintf_s
#endif
-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);
+static void pluginInvalidate(NPObject*);
+static bool pluginHasProperty(NPObject*, NPIdentifier name);
+static bool pluginHasMethod(NPObject*, NPIdentifier name);
+static bool pluginGetProperty(NPObject*, NPIdentifier name, NPVariant*);
+static bool pluginSetProperty(NPObject*, NPIdentifier name, const NPVariant*);
+static bool pluginInvoke(NPObject*, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result);
+static bool pluginInvokeDefault(NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result);
+static NPObject* pluginAllocate(NPP npp, NPClass*);
+static void pluginDeallocate(NPObject*);
-NPNetscapeFuncs *browser;
+NPNetscapeFuncs* browser;
-static NPClass pluginClass = {
+static NPClass pluginClass = {
NP_CLASS_STRUCT_VERSION,
- pluginAllocate,
- pluginDeallocate,
+ pluginAllocate,
+ pluginDeallocate,
pluginInvalidate,
pluginHasMethod,
pluginInvoke,
@@ -65,7 +57,7 @@ static NPClass pluginClass = {
pluginGetProperty,
pluginSetProperty,
};
-
+
NPClass *getPluginClass(void)
{
return &pluginClass;
@@ -73,13 +65,14 @@ NPClass *getPluginClass(void)
static bool identifiersInitialized = false;
-#define ID_PROPERTY_PROPERTY 0
-#define ID_PROPERTY_EVENT_LOGGING 1
-#define ID_PROPERTY_HAS_STREAM 2
-#define ID_PROPERTY_TEST_OBJECT 3
-#define ID_PROPERTY_LOG_DESTROY 4
-#define ID_PROPERTY_TEST_OBJECT_COUNT 5
-#define NUM_PROPERTY_IDENTIFIERS 6
+#define ID_PROPERTY_PROPERTY 0
+#define ID_PROPERTY_EVENT_LOGGING 1
+#define ID_PROPERTY_HAS_STREAM 2
+#define ID_PROPERTY_TEST_OBJECT 3
+#define ID_PROPERTY_LOG_DESTROY 4
+#define ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM 5
+#define ID_PROPERTY_TEST_OBJECT_COUNT 6
+#define NUM_PROPERTY_IDENTIFIERS 7
static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
@@ -88,6 +81,7 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
"hasStream",
"testObject",
"logDestroy",
+ "returnErrorFromNewStream",
"testObjectCount",
};
@@ -137,7 +131,7 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
"testPostURLFile",
};
-static NPUTF8* createCStringFromNPVariant(const NPVariant *variant)
+static NPUTF8* createCStringFromNPVariant(const NPVariant* variant)
{
size_t length = NPVARIANT_TO_STRING(*variant).UTF8Length;
NPUTF8* result = (NPUTF8*)malloc(length + 1);
@@ -168,44 +162,50 @@ static bool pluginHasMethod(NPObject *obj, NPIdentifier name)
return false;
}
-static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant)
+static bool pluginGetProperty(NPObject* obj, NPIdentifier name, NPVariant* result)
{
+ PluginObject* plugin = reinterpret_cast<PluginObject*>(obj);
if (name == pluginPropertyIdentifiers[ID_PROPERTY_PROPERTY]) {
- char* mem = static_cast<char*>(browser->memalloc(9));
- strcpy(mem, "property");
- STRINGZ_TO_NPVARIANT(mem, *variant);
+ STRINGZ_TO_NPVARIANT("property", *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
- BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->eventLogging, *variant);
+ BOOLEAN_TO_NPVARIANT(plugin->eventLogging, *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
- BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->logDestroy, *variant);
- return true;
+ BOOLEAN_TO_NPVARIANT(plugin->logDestroy, *result);
+ return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_HAS_STREAM]) {
- BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->stream != 0, *variant);
+ BOOLEAN_TO_NPVARIANT(plugin->stream != 0, *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT]) {
- NPObject *testObject = ((PluginObject *)obj)->testObject;
+ NPObject* testObject = plugin->testObject;
browser->retainobject(testObject);
- OBJECT_TO_NPVARIANT(testObject, *variant);
+ OBJECT_TO_NPVARIANT(testObject, *result);
+ return true;
+ } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
+ BOOLEAN_TO_NPVARIANT(plugin->returnErrorFromNewStream, *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT_COUNT]) {
- INT32_TO_NPVARIANT(getTestObjectCount(), *variant);
+ INT32_TO_NPVARIANT(getTestObjectCount(), *result);
return true;
}
return false;
}
-static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
+static bool pluginSetProperty(NPObject* obj, NPIdentifier name, const NPVariant* variant)
{
+ PluginObject* plugin = reinterpret_cast<PluginObject*>(obj);
if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
- ((PluginObject *)obj)->eventLogging = NPVARIANT_TO_BOOLEAN(*variant);
+ plugin->eventLogging = NPVARIANT_TO_BOOLEAN(*variant);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
- ((PluginObject *)obj)->logDestroy = NPVARIANT_TO_BOOLEAN(*variant);
+ plugin->logDestroy = NPVARIANT_TO_BOOLEAN(*variant);
+ return true;
+ } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
+ plugin->returnErrorFromNewStream = NPVARIANT_TO_BOOLEAN(*variant);
return true;
}
-
+
return false;
}
@@ -296,23 +296,22 @@ static bool testIdentifierToInt(PluginObject*, const NPVariant* args, uint32_t a
static bool testCallback(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
- // call whatever method name we're given
- if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
- NPObject *windowScriptObject;
- browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
+ if (argCount == 0 || !NPVARIANT_IS_STRING(args[0]))
+ return false;
- NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
- NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
- free(callbackString);
+ NPObject* windowScriptObject;
+ browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
- NPVariant browserResult;
- browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult);
- browser->releasevariantvalue(&browserResult);
+ NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
+ NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
+ free(callbackString);
- VOID_TO_NPVARIANT(*result);
- return true;
- }
- return false;
+ NPVariant browserResult;
+ browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult);
+ browser->releasevariantvalue(&browserResult);
+
+ VOID_TO_NPVARIANT(*result);
+ return true;
}
static bool getURL(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
@@ -320,18 +319,18 @@ static bool getURL(PluginObject* obj, const NPVariant* args, uint32_t argCount,
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);
+ NPError npErr = browser->geturl(obj->npp, urlString, targetString);
free(urlString);
free(targetString);
- VOID_TO_NPVARIANT(*result);
+ INT32_TO_NPVARIANT(npErr, *result);
return true;
} else if (argCount == 1 && NPVARIANT_IS_STRING(args[0])) {
NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
- browser->geturl(obj->npp, urlString, 0);
+ NPError npErr = browser->geturl(obj->npp, urlString, 0);
free(urlString);
- VOID_TO_NPVARIANT(*result);
+ INT32_TO_NPVARIANT(npErr, *result);
return true;
}
return false;
@@ -346,25 +345,24 @@ static bool removeDefaultMethod(PluginObject*, const NPVariant* args, uint32_t a
static bool getURLNotify(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
- if (argCount == 3
- && NPVARIANT_IS_STRING(args[0])
- && (NPVARIANT_IS_STRING(args[1]) || NPVARIANT_IS_NULL(args[1]))
- && NPVARIANT_IS_STRING(args[2])) {
- NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
- NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : NULL);
- NPUTF8* callbackString = createCStringFromNPVariant(&args[2]);
-
- NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
- browser->geturlnotify(obj->npp, urlString, targetString, callbackIdentifier);
+ if (argCount != 3 || !NPVARIANT_IS_STRING(args[0])
+ || (!NPVARIANT_IS_STRING(args[1]) && !NPVARIANT_IS_NULL(args[1]))
+ || !NPVARIANT_IS_STRING(args[2]))
+ return false;
- free(urlString);
- free(targetString);
- free(callbackString);
-
- VOID_TO_NPVARIANT(*result);
- return true;
- }
- return false;
+ NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
+ NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : NULL);
+ NPUTF8* callbackString = createCStringFromNPVariant(&args[2]);
+
+ NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
+ browser->geturlnotify(obj->npp, urlString, targetString, callbackIdentifier);
+
+ free(urlString);
+ free(targetString);
+ free(callbackString);
+
+ VOID_TO_NPVARIANT(*result);
+ return true;
}
static bool testInvokeDefault(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
@@ -391,7 +389,7 @@ static bool destroyStream(PluginObject* obj, const NPVariant* args, uint32_t arg
{
NPError npError = browser->destroystream(obj->npp, obj->stream, NPRES_USER_BREAK);
INT32_TO_NPVARIANT(npError, *result);
- return true;
+ return true;
}
static bool testEnumerate(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
@@ -545,7 +543,7 @@ static bool testPostURLFile(PluginObject* obj, const NPVariant* args, uint32_t a
return true;
}
-static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
+static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
PluginObject* plugin = reinterpret_cast<PluginObject*>(header);
if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD])
@@ -704,20 +702,20 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
return false;
}
-static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
+static bool pluginInvokeDefault(NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
INT32_TO_NPVARIANT(1, *result);
return true;
}
-static void pluginInvalidate(NPObject *obj)
+static void pluginInvalidate(NPObject* obj)
{
}
static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
{
- PluginObject *newInstance = (PluginObject*)malloc(sizeof(PluginObject));
-
+ PluginObject* newInstance = (PluginObject*)malloc(sizeof(PluginObject));
+
if (!identifiersInitialized) {
identifiersInitialized = true;
initializeIdentifiers();
@@ -726,42 +724,43 @@ static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
newInstance->npp = npp;
newInstance->testObject = browser->createobject(npp, getTestClass());
newInstance->eventLogging = FALSE;
+ newInstance->onStreamLoad = 0;
+ newInstance->onStreamDestroy = 0;
+ newInstance->onURLNotify = 0;
newInstance->logDestroy = FALSE;
newInstance->logSetWindow = FALSE;
newInstance->returnErrorFromNewStream = FALSE;
newInstance->stream = 0;
-
+
newInstance->firstUrl = NULL;
newInstance->firstHeaders = NULL;
newInstance->lastUrl = NULL;
newInstance->lastHeaders = NULL;
-
- return (NPObject *)newInstance;
+
+ return (NPObject*)newInstance;
}
-static void pluginDeallocate(NPObject *header)
+static void pluginDeallocate(NPObject* header)
{
- PluginObject* obj = (PluginObject*)header;
-
- browser->releaseobject(obj->testObject);
-
- free(obj->firstUrl);
- free(obj->firstHeaders);
- free(obj->lastUrl);
- free(obj->lastHeaders);
+ PluginObject* plugin = reinterpret_cast<PluginObject*>(header);
+ browser->releaseobject(plugin->testObject);
- free(obj);
+ free(plugin->firstUrl);
+ free(plugin->firstHeaders);
+ free(plugin->lastUrl);
+ free(plugin->lastHeaders);
+ free(plugin);
}
void handleCallback(PluginObject* object, const char *url, NPReason reason, void *notifyData)
{
assert(object);
-
+
NPVariant args[2];
-
+
NPObject *windowScriptObject;
browser->getvalue(object->npp, NPNVWindowNPObject, &windowScriptObject);
-
+
NPIdentifier callbackIdentifier = notifyData;
INT32_TO_NPVARIANT(reason, args[0]);