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
Родитель c0745e8d5f
Коммит 25cc469ad1
7 изменённых файлов: 91 добавлений и 51 удалений

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

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

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

@ -22,7 +22,7 @@
ok(!p.streamTest('loremipsum.txt', false, null, null, ok(!p.streamTest('loremipsum.txt', false, null, null,
function(r, t) { function(r, t) {
ok(false, "get-during-destroy should have failed"); 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); document.body.removeChild(p);

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

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

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

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

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

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

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

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

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

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