Bug 1081353 - Eliminate PPluginIdentifier (r=bsmedberg)
This commit is contained in:
@@ -6,15 +6,103 @@
|
||||
|
||||
#include "PluginScriptableObjectParent.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/plugins/PluginIdentifierParent.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/plugins/PluginTypes.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "nsNPAPIPlugin.h"
|
||||
#include "PluginScriptableObjectUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::plugins;
|
||||
using namespace mozilla::plugins::parent;
|
||||
|
||||
/**
|
||||
* NPIdentifiers in the chrome process are stored as jsids. The difficulty is in
|
||||
* ensuring that string identifiers are rooted without interning them all. We
|
||||
* assume that all NPIdentifiers passed into nsJSNPRuntime will not be used
|
||||
* outside the scope of the NPAPI call (i.e., they won't be stored in the
|
||||
* heap). Rooting is done using the StackIdentifier class, which roots the
|
||||
* identifier via RootedId.
|
||||
*
|
||||
* This system does not allow jsids to be moved, as would be needed for
|
||||
* generational or compacting GC. When Firefox implements a moving GC for
|
||||
* strings, we will need to ensure that no movement happens while NPAPI code is
|
||||
* on the stack: although StackIdentifier roots all identifiers used, the GC has
|
||||
* no way to no that a jsid cast to an NPIdentifier needs to be fixed up if it
|
||||
* is moved.
|
||||
*/
|
||||
|
||||
class MOZ_STACK_CLASS StackIdentifier
|
||||
{
|
||||
public:
|
||||
StackIdentifier(const PluginIdentifier& aIdentifier, bool aIntern = false);
|
||||
|
||||
bool Failed() const { return mFailed; }
|
||||
NPIdentifier ToNPIdentifier() const { return mIdentifier; }
|
||||
|
||||
private:
|
||||
bool mFailed;
|
||||
NPIdentifier mIdentifier;
|
||||
AutoSafeJSContext mCx;
|
||||
JS::RootedId mId;
|
||||
};
|
||||
|
||||
StackIdentifier::StackIdentifier(const PluginIdentifier& aIdentifier, bool aIntern)
|
||||
: mFailed(false),
|
||||
mId(mCx)
|
||||
{
|
||||
if (aIdentifier.type() == PluginIdentifier::TnsCString) {
|
||||
// We don't call _getstringidentifier because we may not want to intern the string.
|
||||
NS_ConvertUTF8toUTF16 utf16name(aIdentifier.get_nsCString());
|
||||
JS::RootedString str(mCx, JS_NewUCStringCopyN(mCx, utf16name.get(), utf16name.Length()));
|
||||
if (!str) {
|
||||
NS_ERROR("Id can't be allocated");
|
||||
mFailed = true;
|
||||
return;
|
||||
}
|
||||
if (aIntern) {
|
||||
str = JS_InternJSString(mCx, str);
|
||||
if (!str) {
|
||||
NS_ERROR("Id can't be allocated");
|
||||
mFailed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!JS_StringToId(mCx, str, &mId)) {
|
||||
NS_ERROR("Id can't be allocated");
|
||||
mFailed = true;
|
||||
return;
|
||||
}
|
||||
mIdentifier = JSIdToNPIdentifier(mId);
|
||||
return;
|
||||
}
|
||||
|
||||
mIdentifier = mozilla::plugins::parent::_getintidentifier(aIdentifier.get_int32_t());
|
||||
}
|
||||
|
||||
static bool
|
||||
FromNPIdentifier(NPIdentifier aIdentifier, PluginIdentifier* aResult)
|
||||
{
|
||||
if (mozilla::plugins::parent::_identifierisstring(aIdentifier)) {
|
||||
nsCString string;
|
||||
NPUTF8* chars =
|
||||
mozilla::plugins::parent::_utf8fromidentifier(aIdentifier);
|
||||
if (!chars) {
|
||||
return false;
|
||||
}
|
||||
string.Adopt(chars);
|
||||
*aResult = PluginIdentifier(string);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
int32_t intval = mozilla::plugins::parent::_intfromidentifier(aIdentifier);
|
||||
*aResult = PluginIdentifier(intval);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
inline void
|
||||
@@ -105,8 +193,8 @@ PluginScriptableObjectParent::ScriptableHasMethod(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -145,8 +233,8 @@ PluginScriptableObjectParent::ScriptableInvoke(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -247,8 +335,8 @@ PluginScriptableObjectParent::ScriptableHasProperty(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -296,8 +384,8 @@ PluginScriptableObjectParent::ScriptableSetProperty(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -339,8 +427,8 @@ PluginScriptableObjectParent::ScriptableRemoveProperty(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -385,7 +473,7 @@ PluginScriptableObjectParent::ScriptableEnumerate(NPObject* aObject,
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoInfallibleTArray<PPluginIdentifierParent*, 10> identifiers;
|
||||
AutoInfallibleTArray<PluginIdentifier, 10> identifiers;
|
||||
bool success;
|
||||
if (!actor->CallEnumerate(&identifiers, &success)) {
|
||||
NS_WARNING("Failed to send message!");
|
||||
@@ -409,9 +497,13 @@ PluginScriptableObjectParent::ScriptableEnumerate(NPObject* aObject,
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < *aCount; index++) {
|
||||
PluginIdentifierParent* id =
|
||||
static_cast<PluginIdentifierParent*>(identifiers[index]);
|
||||
(*aIdentifiers)[index] = id->ToNPIdentifier();
|
||||
// We intern the ID to avoid a GC hazard here. This could probably be fixed
|
||||
// if the interface with nsJSNPRuntime were smarter.
|
||||
StackIdentifier stackID(identifiers[index], true /* aIntern */);
|
||||
if (stackID.Failed()) {
|
||||
return false;
|
||||
}
|
||||
(*aIdentifiers)[index] = stackID.ToNPIdentifier();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -649,7 +741,7 @@ PluginScriptableObjectParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerHasMethod(PPluginIdentifierParent* aId,
|
||||
PluginScriptableObjectParent::AnswerHasMethod(const PluginIdentifier& aId,
|
||||
bool* aHasMethod)
|
||||
{
|
||||
if (!mObject) {
|
||||
@@ -675,13 +767,17 @@ PluginScriptableObjectParent::AnswerHasMethod(PPluginIdentifierParent* aId,
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
*aHasMethod = npn->hasmethod(instance->GetNPP(), mObject, id->ToNPIdentifier());
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aHasMethod = false;
|
||||
return true;
|
||||
}
|
||||
*aHasMethod = npn->hasmethod(instance->GetNPP(), mObject, stackID.ToNPIdentifier());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerInvoke(PPluginIdentifierParent* aId,
|
||||
PluginScriptableObjectParent::AnswerInvoke(const PluginIdentifier& aId,
|
||||
const InfallibleTArray<Variant>& aArgs,
|
||||
Variant* aResult,
|
||||
bool* aSuccess)
|
||||
@@ -712,6 +808,13 @@ PluginScriptableObjectParent::AnswerInvoke(PPluginIdentifierParent* aId,
|
||||
return true;
|
||||
}
|
||||
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aResult = void_t();
|
||||
*aSuccess = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
AutoFallibleTArray<NPVariant, 10> convertedArgs;
|
||||
uint32_t argCount = aArgs.Length();
|
||||
|
||||
@@ -733,9 +836,8 @@ PluginScriptableObjectParent::AnswerInvoke(PPluginIdentifierParent* aId,
|
||||
}
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
NPVariant result;
|
||||
bool success = npn->invoke(instance->GetNPP(), mObject, id->ToNPIdentifier(),
|
||||
bool success = npn->invoke(instance->GetNPP(), mObject, stackID.ToNPIdentifier(),
|
||||
convertedArgs.Elements(), argCount, &result);
|
||||
|
||||
for (uint32_t index = 0; index < argCount; index++) {
|
||||
@@ -848,7 +950,7 @@ PluginScriptableObjectParent::AnswerInvokeDefault(const InfallibleTArray<Variant
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerHasProperty(PPluginIdentifierParent* aId,
|
||||
PluginScriptableObjectParent::AnswerHasProperty(const PluginIdentifier& aId,
|
||||
bool* aHasProperty)
|
||||
{
|
||||
if (!mObject) {
|
||||
@@ -874,15 +976,20 @@ PluginScriptableObjectParent::AnswerHasProperty(PPluginIdentifierParent* aId,
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aHasProperty = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
*aHasProperty = npn->hasproperty(instance->GetNPP(), mObject,
|
||||
id->ToNPIdentifier());
|
||||
stackID.ToNPIdentifier());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerGetParentProperty(
|
||||
PPluginIdentifierParent* aId,
|
||||
const PluginIdentifier& aId,
|
||||
Variant* aResult,
|
||||
bool* aSuccess)
|
||||
{
|
||||
@@ -912,9 +1019,15 @@ PluginScriptableObjectParent::AnswerGetParentProperty(
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aResult = void_t();
|
||||
*aSuccess = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
NPVariant result;
|
||||
if (!npn->getproperty(instance->GetNPP(), mObject, id->ToNPIdentifier(),
|
||||
if (!npn->getproperty(instance->GetNPP(), mObject, stackID.ToNPIdentifier(),
|
||||
&result)) {
|
||||
*aResult = void_t();
|
||||
*aSuccess = false;
|
||||
@@ -934,7 +1047,7 @@ PluginScriptableObjectParent::AnswerGetParentProperty(
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerSetProperty(PPluginIdentifierParent* aId,
|
||||
PluginScriptableObjectParent::AnswerSetProperty(const PluginIdentifier& aId,
|
||||
const Variant& aValue,
|
||||
bool* aSuccess)
|
||||
{
|
||||
@@ -967,16 +1080,21 @@ PluginScriptableObjectParent::AnswerSetProperty(PPluginIdentifierParent* aId,
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aSuccess = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((*aSuccess = npn->setproperty(instance->GetNPP(), mObject,
|
||||
id->ToNPIdentifier(), &converted))) {
|
||||
stackID.ToNPIdentifier(), &converted))) {
|
||||
ReleaseVariant(converted, instance);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerRemoveProperty(PPluginIdentifierParent* aId,
|
||||
PluginScriptableObjectParent::AnswerRemoveProperty(const PluginIdentifier& aId,
|
||||
bool* aSuccess)
|
||||
{
|
||||
if (!mObject) {
|
||||
@@ -1002,14 +1120,19 @@ PluginScriptableObjectParent::AnswerRemoveProperty(PPluginIdentifierParent* aId,
|
||||
return true;
|
||||
}
|
||||
|
||||
PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
|
||||
StackIdentifier stackID(aId);
|
||||
if (stackID.Failed()) {
|
||||
*aSuccess = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
*aSuccess = npn->removeproperty(instance->GetNPP(), mObject,
|
||||
id->ToNPIdentifier());
|
||||
stackID.ToNPIdentifier());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray<PPluginIdentifierParent*>* aProperties,
|
||||
PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray<PluginIdentifier>* aProperties,
|
||||
bool* aSuccess)
|
||||
{
|
||||
if (!mObject) {
|
||||
@@ -1044,21 +1167,12 @@ PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray<PPluginIdentifier
|
||||
|
||||
aProperties->SetCapacity(idCount);
|
||||
|
||||
mozilla::AutoSafeJSContext cx;
|
||||
for (uint32_t index = 0; index < idCount; index++) {
|
||||
// Because of GC hazards, all identifiers returned from enumerate
|
||||
// must be made permanent.
|
||||
if (_identifierisstring(ids[index])) {
|
||||
JS::Rooted<JSString*> str(cx, NPIdentifierToString(ids[index]));
|
||||
if (!JS_StringHasBeenInterned(cx, str)) {
|
||||
DebugOnly<JSString*> str2 = JS_InternJSString(cx, str);
|
||||
NS_ASSERTION(str2 == str, "Interning a JS string which is currently an ID should return itself.");
|
||||
}
|
||||
PluginIdentifier id;
|
||||
if (!FromNPIdentifier(ids[index], &id)) {
|
||||
return false;
|
||||
}
|
||||
PluginIdentifierParent* id =
|
||||
instance->Module()->GetIdentifierForNPIdentifier(instance->GetNPP(), ids[index]);
|
||||
aProperties->AppendElement(id);
|
||||
NS_ASSERTION(!id->IsTemporary(), "Should only have permanent identifiers!");
|
||||
}
|
||||
|
||||
npn->memfree(ids);
|
||||
@@ -1229,8 +1343,8 @@ PluginScriptableObjectParent::GetPropertyHelper(NPIdentifier aName,
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginIdentifierParent::StackIdentifier identifier(GetInstance(), aName);
|
||||
if (!identifier) {
|
||||
PluginIdentifier identifier;
|
||||
if (!FromNPIdentifier(aName, &identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user