Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "PluginIdentifierParent.h"
9 #include "nsNPAPIPlugin.h"
10 #include "nsServiceManagerUtils.h"
11 #include "PluginScriptableObjectUtils.h"
12 #include "nsCxPusher.h"
13 #include "mozilla/unused.h"
15 using namespace mozilla::plugins::parent;
17 namespace mozilla {
18 namespace plugins {
20 bool
21 PluginIdentifierParent::RecvRetain()
22 {
23 mTemporaryRefs = 0;
25 // Intern the jsid if necessary.
26 AutoSafeJSContext cx;
27 JS::Rooted<jsid> id(cx, NPIdentifierToJSId(mIdentifier));
28 if (JSID_IS_INT(id)) {
29 return true;
30 }
32 // The following is what nsNPAPIPlugin.cpp does. Gross, but the API doesn't
33 // give you a NPP to play with.
34 JS::Rooted<JSString*> str(cx, JSID_TO_STRING(id));
35 JSString* str2 = JS_InternJSString(cx, str);
36 if (!str2) {
37 return false;
38 }
40 NS_ASSERTION(str == str2, "Interning a string in a JSID should always return the same string.");
42 return true;
43 }
45 PluginIdentifierParent::StackIdentifier::StackIdentifier
46 (PluginInstanceParent* inst, NPIdentifier aIdentifier)
47 : mIdentifier(inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier))
48 {
49 }
51 PluginIdentifierParent::StackIdentifier::StackIdentifier
52 (NPObject* aObject, NPIdentifier aIdentifier)
53 : mIdentifier(nullptr)
54 {
55 PluginInstanceParent* inst = GetInstance(aObject);
56 mIdentifier = inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier);
57 }
59 PluginIdentifierParent::StackIdentifier::~StackIdentifier()
60 {
61 if (!mIdentifier) {
62 return;
63 }
65 if (!mIdentifier->IsTemporary()) {
66 return;
67 }
69 if (mIdentifier->RemoveTemporaryRef()) {
70 unused << PPluginIdentifierParent::Send__delete__(mIdentifier);
71 }
72 }
74 } // namespace mozilla::plugins
75 } // namespace mozilla