Bug 625164: Fix bug in which we send the wrong URL to OOP plugins via NPP_URLRedirectNotify. r=dwitte a=blocking2.0betaN+

This commit is contained in:
Josh Aas 2011-01-13 17:52:15 -08:00
Родитель a16827c7c0
Коммит 2a8f6d2680
7 изменённых файлов: 91 добавлений и 51 удалений

Просмотреть файл

@ -2090,7 +2090,7 @@ StreamNotifyChild::RecvRedirectNotify(const nsCString& url, const int32_t& statu
PluginInstanceChild* instance = static_cast<PluginInstanceChild*>(Manager());
if (instance->mPluginIface->urlredirectnotify)
instance->mPluginIface->urlredirectnotify(instance->GetNPP(), mURL.get(), status, mClosure);
instance->mPluginIface->urlredirectnotify(instance->GetNPP(), url.get(), status, mClosure);
return true;
}

Просмотреть файл

@ -22,7 +22,7 @@
ok(!p.streamTest('loremipsum.txt', false, null, null,
function(r, t) {
ok(false, "get-during-destroy should have failed");
}, true), "NPN_GetURLNotify should fail during NPP_Destroy");
}, null, true), "NPN_GetURLNotify should fail during NPP_Destroy");
});
document.body.removeChild(p);

Просмотреть файл

@ -16,9 +16,13 @@
var redirectTargetURL = "http://example.org/tests/modules/plugin/test/loremipsum.txt";
var expectedWriteURL = "";
var expectedNotifyURL = "";
var expectedNotifyStatus = -1;
function redirectCallback(url, httpStatus) {
is(url, redirectTargetURL, "Test for expected redirect notify URL.");
is(httpStatus, 307, "Test for expected http redirect status.");
}
function writeCallback(url) {
is(url, expectedWriteURL, "Test for expected stream write URL.");
}
@ -30,18 +34,16 @@
function test1() {
expectedWriteURL = "";
expectedNotifyURL = redirectingURL;
expectedNotifyStatus = 1;
p.streamTest(redirectingURL, false, null, writeCallback, notifyCallback, false);
p.streamTest(redirectingURL, false, null, writeCallback, notifyCallback, redirectCallback, false);
}
function test2() {
expectedWriteURL = redirectTargetURL;
expectedNotifyURL = redirectingURL;
expectedNotifyStatus = 0;
p.streamTest(redirectingURL, false, null, writeCallback, notifyCallback, true);
p.streamTest(redirectingURL, false, null, writeCallback, notifyCallback, redirectCallback, true);
}
var tests = [test1, test2];

Просмотреть файл

@ -29,37 +29,37 @@
is(t.substr(0, 11), "Lorem ipsum",
"GET loremipsum.txt correct");
testDone();
}, true), "streamTest GET");
}, null, true), "streamTest GET");
ok(!p.streamTest("post.sjs", true, null, null,
function(r, t) {
ok(false, "Shouldn't get callback from null post");
}, true), "streamTest POST null postdata");
}, null, true), "streamTest POST null postdata");
ok(p.streamTest("post.sjs", true, "Something good", null,
function(r, t) {
is(r, 0, "POST something good");
is(t, "Something good", "POST non-null correct");
testDone();
}, true), "streamTest POST valid postdata");
}, null, true), "streamTest POST valid postdata");
ok(p.streamTest("http://example.invalid/", false, null, null,
function(r, t) {
is(r, 1, "Shouldn't load example.invalid DNS name");
testDone();
}, true), "streamTest GET bad DNS");
}, null, true), "streamTest GET bad DNS");
ok(!p.streamTest("http://localhost:-8/", false, null, null,
function(r, t) {
ok(false, "Shouldn't get callback from malformed URI");
}, true), "streamTest GET invalid URL");
}, null, true), "streamTest GET invalid URL");
ok(p.streamTest("javascript:'Hello';", false, null, null,
function(r, t) {
is(r, 0, "GET javascript: URI");
is(t, "Hello", "GET javascript: URI correct");
testDone();
}, true), "streamTest GET javascript: URI");
}, null, true), "streamTest GET javascript: URI");
/*
* XXX/cjones: disabled for now because it appears to be hard to make
@ -77,11 +77,11 @@
is(r, 0, "GET data: URI");
is(t, "World", "GET data: URI correct");
testDone();
}, true), "streamTest GET data: URI");
}, null, true), "streamTest GET data: URI");
ok(!p.streamTest("data:malformed?", false, null, null,
function(r, t) {
todo(false, "Shouldn't get callback for invalid data: URI");
}, true), "streamTest GET bad data: URI");
}, null, true), "streamTest GET bad data: URI");
}
</script>

Просмотреть файл

@ -26,7 +26,7 @@
function(r, t) {
is(r, 2, "Stream should have failed");
urlnotified = true;
}, true), "neverending.sjs started successfully");
}, null, true), "neverending.sjs started successfully");
setTimeout(removePlugin, 500);
}

Просмотреть файл

@ -347,7 +347,7 @@ If the plugin is instantiated as a full-page plugin, the following defaults
are used:
streammode="seek" frame="testframe" range="100,100"
The streamTest(url, doPost, postData, writeCallback, notifyCallback, allowRedirects)
The streamTest(url, doPost, postData, writeCallback, notifyCallback, redirectCallback, allowRedirects)
function will test how NPN_GetURLNotify and NPN_PostURLNotify behave when they are
called with arbitrary (malformed) URLs. The function will return `true` if
NPN_[Get/Post]URLNotify succeeds, and `false` if it fails.
@ -356,6 +356,7 @@ NPN_[Get/Post]URLNotify succeeds, and `false` if it fails.
@param postData null, or a string to send a postdata
@writeCallback will be called when data is received for the stream
@notifyCallback will be called when the urlnotify is received with the notify result
@redirectCallback will be called from urlredirectnotify if a redirect is attempted
@allowRedirects boolean value indicating whether or not to allow redirects
== Internal consistency ==

Просмотреть файл

@ -96,9 +96,6 @@ IntentionalCrash()
static NPNetscapeFuncs* sBrowserFuncs = NULL;
static NPClass sNPClass;
static void
testplugin_URLNotify(NPP instance, const char* url, NPReason reason,
void* notifyData);
void
asyncCallback(void* cookie);
@ -289,6 +286,7 @@ struct URLNotifyData
const char* cookie;
NPObject* writeCallback;
NPObject* notifyCallback;
NPObject* redirectCallback;
bool allowRedirects;
uint32_t size;
char* data;
@ -590,7 +588,7 @@ static bool fillPluginFunctionTable(NPPluginFuncs* pFuncs)
pFuncs->write = NPP_Write;
pFuncs->print = NPP_Print;
pFuncs->event = NPP_HandleEvent;
pFuncs->urlnotify = testplugin_URLNotify;
pFuncs->urlnotify = NPP_URLNotify;
pFuncs->getvalue = NPP_GetValue;
pFuncs->setvalue = NPP_SetValue;
pFuncs->urlredirectnotify = NPP_URLRedirectNotify;
@ -1249,7 +1247,7 @@ NPP_HandleEvent(NPP instance, void* event)
}
void
testplugin_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
{
InstanceData* instanceData = (InstanceData*)(instance->pdata);
URLNotifyData* ndata = static_cast<URLNotifyData*>(notifyData);
@ -1261,23 +1259,31 @@ testplugin_URLNotify(NPP instance, const char* url, NPReason reason, void* notif
}
}
else if (!strcmp(ndata->cookie, "dynamic-cookie")) {
NPVariant args[2];
NPVariant result;
INT32_TO_NPVARIANT(reason, args[0]);
if (ndata->notifyCallback) {
NPVariant args[2];
INT32_TO_NPVARIANT(reason, args[0]);
if (ndata->data) {
STRINGN_TO_NPVARIANT(ndata->data, ndata->size, args[1]);
}
else {
STRINGN_TO_NPVARIANT("", 0, args[1]);
}
if (ndata->data)
STRINGN_TO_NPVARIANT(ndata->data, ndata->size, args[1]);
else
STRINGN_TO_NPVARIANT("", 0, args[1]);
NPN_InvokeDefault(instance, ndata->notifyCallback, args, 2, &result);
NPN_ReleaseVariantValue(&result);
NPVariant result;
NPN_InvokeDefault(instance, ndata->notifyCallback, args, 2, &result);
NPN_ReleaseVariantValue(&result);
}
// clean up the URLNotifyData
if (ndata->writeCallback) {
NPN_ReleaseObject(ndata->writeCallback);
}
NPN_ReleaseObject(ndata->notifyCallback);
if (ndata->notifyCallback) {
NPN_ReleaseObject(ndata->notifyCallback);
}
if (ndata->redirectCallback) {
NPN_ReleaseObject(ndata->redirectCallback);
}
free(ndata->data);
delete ndata;
}
@ -1321,8 +1327,17 @@ void
NPP_URLRedirectNotify(NPP instance, const char* url, int32_t status, void* notifyData)
{
if (notifyData) {
NPN_URLRedirectResponse(instance, notifyData,
static_cast<URLNotifyData*>(notifyData)->allowRedirects);
URLNotifyData* nd = static_cast<URLNotifyData*>(notifyData);
if (nd->redirectCallback) {
NPVariant args[2];
STRINGN_TO_NPVARIANT(url, strlen(url), args[0]);
INT32_TO_NPVARIANT(status, args[1]);
NPVariant result;
NPN_InvokeDefault(instance, nd->redirectCallback, args, 2, &result);
NPN_ReleaseVariantValue(&result);
}
NPN_URLRedirectResponse(instance, notifyData, nd->allowRedirects);
return;
}
NPN_URLRedirectResponse(instance, notifyData, true);
@ -2319,8 +2334,8 @@ convertPointY(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVaria
static bool
streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
// .streamTest(url, doPost, doNull, writeCallback, notifyCallback, allowRedirects)
if (6 != argCount)
// .streamTest(url, doPost, doNull, writeCallback, notifyCallback, redirectCallback, allowRedirects)
if (7 != argCount)
return false;
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
@ -2334,37 +2349,54 @@ streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant*
bool doPost = NPVARIANT_TO_BOOLEAN(args[1]);
NPString postData = { NULL, 0 };
if (NPVARIANT_IS_NULL(args[2])) {
}
else if (NPVARIANT_IS_STRING(args[2])) {
if (NPVARIANT_IS_STRING(args[2])) {
postData = NPVARIANT_TO_STRING(args[2]);
}
else {
return false;
if (!NPVARIANT_IS_NULL(args[2])) {
return false;
}
}
NPObject* writeCallback = NULL;
if (NPVARIANT_IS_NULL(args[3])) {
}
else if (NPVARIANT_IS_OBJECT(args[3])) {
if (NPVARIANT_IS_OBJECT(args[3])) {
writeCallback = NPVARIANT_TO_OBJECT(args[3]);
}
else {
return false;
if (!NPVARIANT_IS_NULL(args[3])) {
return false;
}
}
if (!NPVARIANT_IS_OBJECT(args[4]))
return false;
NPObject* notifyCallback = NPVARIANT_TO_OBJECT(args[4]);
NPObject* notifyCallback = NULL;
if (NPVARIANT_IS_OBJECT(args[4])) {
notifyCallback = NPVARIANT_TO_OBJECT(args[4]);
}
else {
if (!NPVARIANT_IS_NULL(args[4])) {
return false;
}
}
if (!NPVARIANT_IS_BOOLEAN(args[5]))
NPObject* redirectCallback = NULL;
if (NPVARIANT_IS_OBJECT(args[5])) {
redirectCallback = NPVARIANT_TO_OBJECT(args[5]);
}
else {
if (!NPVARIANT_IS_NULL(args[5])) {
return false;
}
}
if (!NPVARIANT_IS_BOOLEAN(args[6]))
return false;
bool allowRedirects = NPVARIANT_TO_BOOLEAN(args[5]);
bool allowRedirects = NPVARIANT_TO_BOOLEAN(args[6]);
URLNotifyData* ndata = new URLNotifyData;
ndata->cookie = "dynamic-cookie";
ndata->writeCallback = writeCallback;
ndata->notifyCallback = notifyCallback;
ndata->redirectCallback = redirectCallback;
ndata->size = 0;
ndata->data = NULL;
ndata->allowRedirects = allowRedirects;
@ -2390,7 +2422,12 @@ streamTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant*
if (ndata->writeCallback) {
NPN_RetainObject(ndata->writeCallback);
}
NPN_RetainObject(ndata->notifyCallback);
if (ndata->notifyCallback) {
NPN_RetainObject(ndata->notifyCallback);
}
if (ndata->redirectCallback) {
NPN_RetainObject(ndata->redirectCallback);
}
BOOLEAN_TO_NPVARIANT(true, *result);
}
else {