1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/PluginIdentifierParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "PluginIdentifierParent.h" 1.11 + 1.12 +#include "nsNPAPIPlugin.h" 1.13 +#include "nsServiceManagerUtils.h" 1.14 +#include "PluginScriptableObjectUtils.h" 1.15 +#include "nsCxPusher.h" 1.16 +#include "mozilla/unused.h" 1.17 + 1.18 +using namespace mozilla::plugins::parent; 1.19 + 1.20 +namespace mozilla { 1.21 +namespace plugins { 1.22 + 1.23 +bool 1.24 +PluginIdentifierParent::RecvRetain() 1.25 +{ 1.26 + mTemporaryRefs = 0; 1.27 + 1.28 + // Intern the jsid if necessary. 1.29 + AutoSafeJSContext cx; 1.30 + JS::Rooted<jsid> id(cx, NPIdentifierToJSId(mIdentifier)); 1.31 + if (JSID_IS_INT(id)) { 1.32 + return true; 1.33 + } 1.34 + 1.35 + // The following is what nsNPAPIPlugin.cpp does. Gross, but the API doesn't 1.36 + // give you a NPP to play with. 1.37 + JS::Rooted<JSString*> str(cx, JSID_TO_STRING(id)); 1.38 + JSString* str2 = JS_InternJSString(cx, str); 1.39 + if (!str2) { 1.40 + return false; 1.41 + } 1.42 + 1.43 + NS_ASSERTION(str == str2, "Interning a string in a JSID should always return the same string."); 1.44 + 1.45 + return true; 1.46 +} 1.47 + 1.48 +PluginIdentifierParent::StackIdentifier::StackIdentifier 1.49 + (PluginInstanceParent* inst, NPIdentifier aIdentifier) 1.50 + : mIdentifier(inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier)) 1.51 +{ 1.52 +} 1.53 + 1.54 +PluginIdentifierParent::StackIdentifier::StackIdentifier 1.55 + (NPObject* aObject, NPIdentifier aIdentifier) 1.56 + : mIdentifier(nullptr) 1.57 +{ 1.58 + PluginInstanceParent* inst = GetInstance(aObject); 1.59 + mIdentifier = inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier); 1.60 +} 1.61 + 1.62 +PluginIdentifierParent::StackIdentifier::~StackIdentifier() 1.63 +{ 1.64 + if (!mIdentifier) { 1.65 + return; 1.66 + } 1.67 + 1.68 + if (!mIdentifier->IsTemporary()) { 1.69 + return; 1.70 + } 1.71 + 1.72 + if (mIdentifier->RemoveTemporaryRef()) { 1.73 + unused << PPluginIdentifierParent::Send__delete__(mIdentifier); 1.74 + } 1.75 +} 1.76 + 1.77 +} // namespace mozilla::plugins 1.78 +} // namespace mozilla