зеркало из https://github.com/mozilla/pjs.git
Add a plugin test that sets and then gets a cookie. b=530980 r=roc
This commit is contained in:
Родитель
5bc27e93c9
Коммит
2f8807d42c
|
@ -68,6 +68,7 @@ _MOCHITEST_FILES = \
|
|||
test_multipleinstanceobjects.html \
|
||||
test_streamNotify.html \
|
||||
test_instantiation.html \
|
||||
test_cookies.html \
|
||||
$(NULL)
|
||||
|
||||
# test_npruntime_npnsetexception.html \ Disabled for e10s
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>NPAPI Cookie Tests</title>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
</head>
|
||||
|
||||
<body onload="runTests()">
|
||||
<embed id="plugin1" type="application/x-test" width="400" height="400"></embed>
|
||||
<script class="testbody" type="application/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
function runTests() {
|
||||
var pluginElement = document.getElementById("plugin1");
|
||||
pluginElement.setCookie("foo");
|
||||
ok(pluginElement.getCookie() == "foo", "Cookie was set and retrieved correctly via NPAPI.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -312,9 +312,17 @@ overridden windowproc.
|
|||
widget, if the plugin is windowed. If it's not windowed they're passed to
|
||||
the overriden windowproc (but hopefully never sent by the browser anyway).
|
||||
|
||||
== Getting and Setting Cookies ==
|
||||
|
||||
* setCookie(string)
|
||||
Sets the given string as the cookie for window's URL.
|
||||
|
||||
* getCookie()
|
||||
Returns the cookie string for the window's URL, the cookie set by setCookie.
|
||||
|
||||
== FPU Control ==
|
||||
|
||||
x86-only on some OSes:
|
||||
|
||||
* The .enableFPExceptions() method will enable floating-point exceptions,
|
||||
as evil plugins or extensions might do.
|
||||
as evil plugins or extensions might do.
|
||||
|
|
|
@ -135,6 +135,8 @@ static bool crashOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argC
|
|||
static bool getObjectValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool checkObjectValue(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool enableFPExceptions(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool setCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
|
||||
static const NPUTF8* sPluginMethodIdentifierNames[] = {
|
||||
"npnEvaluateTest",
|
||||
|
@ -169,6 +171,8 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
|
|||
"getObjectValue",
|
||||
"checkObjectValue",
|
||||
"enableFPExceptions",
|
||||
"setCookie",
|
||||
"getCookie",
|
||||
};
|
||||
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
|
||||
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
|
||||
|
@ -204,6 +208,8 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho
|
|||
getObjectValue,
|
||||
checkObjectValue,
|
||||
enableFPExceptions,
|
||||
setCookie,
|
||||
getCookie,
|
||||
};
|
||||
|
||||
struct URLNotifyData
|
||||
|
@ -1313,6 +1319,18 @@ NPN_ConvertPoint(NPP instance, double sourceX, double sourceY, NPCoordinateSpace
|
|||
return sBrowserFuncs->convertpoint(instance, sourceX, sourceY, sourceSpace, destX, destY, destSpace);
|
||||
}
|
||||
|
||||
NPError
|
||||
NPN_SetValueForURL(NPP instance, NPNURLVariable variable, const char *url, const char *value, uint32_t len)
|
||||
{
|
||||
return sBrowserFuncs->setvalueforurl(instance, variable, url, value, len);
|
||||
}
|
||||
|
||||
NPError
|
||||
NPN_GetValueForURL(NPP instance, NPNURLVariable variable, const char *url, char **value, uint32_t *len)
|
||||
{
|
||||
return sBrowserFuncs->getvalueforurl(instance, variable, url, value, len);
|
||||
}
|
||||
|
||||
//
|
||||
// npruntime object functions
|
||||
//
|
||||
|
@ -2183,3 +2201,81 @@ static bool enableFPExceptions(NPObject* npobj, const NPVariant* args, uint32_t
|
|||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// caller is responsible for freeing return buffer
|
||||
static char* URLForInstanceWindow(NPP instance) {
|
||||
char *outString = NULL;
|
||||
|
||||
NPObject* windowObject = NULL;
|
||||
NPError err = NPN_GetValue(instance, NPNVWindowNPObject, &windowObject);
|
||||
if (err != NPERR_NO_ERROR || !windowObject)
|
||||
return NULL;
|
||||
|
||||
NPIdentifier locationIdentifier = NPN_GetStringIdentifier("location");
|
||||
NPVariant locationVariant;
|
||||
if (NPN_GetProperty(instance, windowObject, locationIdentifier, &locationVariant)) {
|
||||
NPObject *locationObject = locationVariant.value.objectValue;
|
||||
if (locationObject) {
|
||||
NPIdentifier hrefIdentifier = NPN_GetStringIdentifier("href");
|
||||
NPVariant hrefVariant;
|
||||
if (NPN_GetProperty(instance, locationObject, hrefIdentifier, &hrefVariant)) {
|
||||
const NPString* hrefString = &NPVARIANT_TO_STRING(hrefVariant);
|
||||
if (hrefString) {
|
||||
outString = (char *)malloc(hrefString->UTF8Length + 1);
|
||||
if (outString) {
|
||||
strcpy(outString, hrefString->UTF8Characters);
|
||||
outString[hrefString->UTF8Length] = '\0';
|
||||
}
|
||||
}
|
||||
NPN_ReleaseVariantValue(&hrefVariant);
|
||||
}
|
||||
}
|
||||
NPN_ReleaseVariantValue(&locationVariant);
|
||||
}
|
||||
|
||||
NPN_ReleaseObject(windowObject);
|
||||
|
||||
return outString;
|
||||
}
|
||||
|
||||
static bool
|
||||
setCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
|
||||
{
|
||||
if (argCount != 1)
|
||||
return false;
|
||||
if (!NPVARIANT_IS_STRING(args[0]))
|
||||
return false;
|
||||
const NPString* cookie = &NPVARIANT_TO_STRING(args[0]);
|
||||
|
||||
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
|
||||
|
||||
char* url = URLForInstanceWindow(npp);
|
||||
if (!url)
|
||||
return false;
|
||||
NPError err = NPN_SetValueForURL(npp, NPNURLVCookie, url, cookie->UTF8Characters, cookie->UTF8Length);
|
||||
free(url);
|
||||
|
||||
return (err == NPERR_NO_ERROR);
|
||||
}
|
||||
|
||||
static bool
|
||||
getCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
|
||||
{
|
||||
if (argCount != 0)
|
||||
return false;
|
||||
|
||||
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
|
||||
|
||||
char* url = URLForInstanceWindow(npp);
|
||||
if (!url)
|
||||
return false;
|
||||
char* cookie = NULL;
|
||||
unsigned int length = 0;
|
||||
NPError err = NPN_GetValueForURL(npp, NPNURLVCookie, url, &cookie, &length);
|
||||
free(url);
|
||||
if (err != NPERR_NO_ERROR || !cookie)
|
||||
return false;
|
||||
|
||||
STRINGZ_TO_NPVARIANT(cookie, *result);
|
||||
return true;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче