Properly detect failure in receiving plugin NPObjects.

Properly handles NPError reporting and makes sure that, in the case of
failure, it does not return junk for the NPObject.
This commit is contained in:
David Parks 2019-12-06 12:28:18 +01:00 • committed by Roy Tam
commit db34f0e7be

View file

@ -310,9 +310,10 @@ PluginInstanceChild::InternalGetNPObjectForValue(NPNVariable aValue,
switch (aValue) { switch (aValue) {
case NPNVWindowNPObject: case NPNVWindowNPObject:
if (!(actor = mCachedWindowActor)) { if (!(actor = mCachedWindowActor)) {
result = NPERR_GENERIC_ERROR;
PPluginScriptableObjectChild* actorProtocol; PPluginScriptableObjectChild* actorProtocol;
CallNPN_GetValue_NPNVWindowNPObject(&actorProtocol, &result); if (CallNPN_GetValue_NPNVWindowNPObject(&actorProtocol, &result) &&
if (result == NPERR_NO_ERROR) { result == NPERR_NO_ERROR) {
actor = mCachedWindowActor = actor = mCachedWindowActor =
static_cast<PluginScriptableObjectChild*>(actorProtocol); static_cast<PluginScriptableObjectChild*>(actorProtocol);
NS_ASSERTION(actor, "Null actor!"); NS_ASSERTION(actor, "Null actor!");
@ -324,10 +325,10 @@ PluginInstanceChild::InternalGetNPObjectForValue(NPNVariable aValue,
case NPNVPluginElementNPObject: case NPNVPluginElementNPObject:
if (!(actor = mCachedElementActor)) { if (!(actor = mCachedElementActor)) {
result = NPERR_GENERIC_ERROR;
PPluginScriptableObjectChild* actorProtocol; PPluginScriptableObjectChild* actorProtocol;
CallNPN_GetValue_NPNVPluginElementNPObject(&actorProtocol, if (CallNPN_GetValue_NPNVPluginElementNPObject(&actorProtocol, &result) &&
&result); result == NPERR_NO_ERROR) {
if (result == NPERR_NO_ERROR) {
actor = mCachedElementActor = actor = mCachedElementActor =
static_cast<PluginScriptableObjectChild*>(actorProtocol); static_cast<PluginScriptableObjectChild*>(actorProtocol);
NS_ASSERTION(actor, "Null actor!"); NS_ASSERTION(actor, "Null actor!");
@ -338,6 +339,7 @@ PluginInstanceChild::InternalGetNPObjectForValue(NPNVariable aValue,
break; break;
default: default:
result = NPERR_GENERIC_ERROR;
NS_NOTREACHED("Don't know what to do with this value type!"); NS_NOTREACHED("Don't know what to do with this value type!");
} }
@ -434,6 +436,7 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
case NPNVWindowNPObject: // Intentional fall-through case NPNVWindowNPObject: // Intentional fall-through
case NPNVPluginElementNPObject: { case NPNVPluginElementNPObject: {
NPObject* object; NPObject* object;
*((NPObject**)aValue) = nullptr;
NPError result = InternalGetNPObjectForValue(aVar, &object); NPError result = InternalGetNPObjectForValue(aVar, &object);
if (result == NPERR_NO_ERROR) { if (result == NPERR_NO_ERROR) {
*((NPObject**)aValue) = object; *((NPObject**)aValue) = object;