michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "PluginIdentifierParent.h" michael@0: michael@0: #include "nsNPAPIPlugin.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "PluginScriptableObjectUtils.h" michael@0: #include "nsCxPusher.h" michael@0: #include "mozilla/unused.h" michael@0: michael@0: using namespace mozilla::plugins::parent; michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: bool michael@0: PluginIdentifierParent::RecvRetain() michael@0: { michael@0: mTemporaryRefs = 0; michael@0: michael@0: // Intern the jsid if necessary. michael@0: AutoSafeJSContext cx; michael@0: JS::Rooted id(cx, NPIdentifierToJSId(mIdentifier)); michael@0: if (JSID_IS_INT(id)) { michael@0: return true; michael@0: } michael@0: michael@0: // The following is what nsNPAPIPlugin.cpp does. Gross, but the API doesn't michael@0: // give you a NPP to play with. michael@0: JS::Rooted str(cx, JSID_TO_STRING(id)); michael@0: JSString* str2 = JS_InternJSString(cx, str); michael@0: if (!str2) { michael@0: return false; michael@0: } michael@0: michael@0: NS_ASSERTION(str == str2, "Interning a string in a JSID should always return the same string."); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: PluginIdentifierParent::StackIdentifier::StackIdentifier michael@0: (PluginInstanceParent* inst, NPIdentifier aIdentifier) michael@0: : mIdentifier(inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier)) michael@0: { michael@0: } michael@0: michael@0: PluginIdentifierParent::StackIdentifier::StackIdentifier michael@0: (NPObject* aObject, NPIdentifier aIdentifier) michael@0: : mIdentifier(nullptr) michael@0: { michael@0: PluginInstanceParent* inst = GetInstance(aObject); michael@0: mIdentifier = inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier); michael@0: } michael@0: michael@0: PluginIdentifierParent::StackIdentifier::~StackIdentifier() michael@0: { michael@0: if (!mIdentifier) { michael@0: return; michael@0: } michael@0: michael@0: if (!mIdentifier->IsTemporary()) { michael@0: return; michael@0: } michael@0: michael@0: if (mIdentifier->RemoveTemporaryRef()) { michael@0: unused << PPluginIdentifierParent::Send__delete__(mIdentifier); michael@0: } michael@0: } michael@0: michael@0: } // namespace mozilla::plugins michael@0: } // namespace mozilla