|
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/. */ |
|
6 |
|
7 #include "PluginIdentifierParent.h" |
|
8 |
|
9 #include "nsNPAPIPlugin.h" |
|
10 #include "nsServiceManagerUtils.h" |
|
11 #include "PluginScriptableObjectUtils.h" |
|
12 #include "nsCxPusher.h" |
|
13 #include "mozilla/unused.h" |
|
14 |
|
15 using namespace mozilla::plugins::parent; |
|
16 |
|
17 namespace mozilla { |
|
18 namespace plugins { |
|
19 |
|
20 bool |
|
21 PluginIdentifierParent::RecvRetain() |
|
22 { |
|
23 mTemporaryRefs = 0; |
|
24 |
|
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 } |
|
31 |
|
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 } |
|
39 |
|
40 NS_ASSERTION(str == str2, "Interning a string in a JSID should always return the same string."); |
|
41 |
|
42 return true; |
|
43 } |
|
44 |
|
45 PluginIdentifierParent::StackIdentifier::StackIdentifier |
|
46 (PluginInstanceParent* inst, NPIdentifier aIdentifier) |
|
47 : mIdentifier(inst->Module()->GetIdentifierForNPIdentifier(inst->GetNPP(), aIdentifier)) |
|
48 { |
|
49 } |
|
50 |
|
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 } |
|
58 |
|
59 PluginIdentifierParent::StackIdentifier::~StackIdentifier() |
|
60 { |
|
61 if (!mIdentifier) { |
|
62 return; |
|
63 } |
|
64 |
|
65 if (!mIdentifier->IsTemporary()) { |
|
66 return; |
|
67 } |
|
68 |
|
69 if (mIdentifier->RemoveTemporaryRef()) { |
|
70 unused << PPluginIdentifierParent::Send__delete__(mIdentifier); |
|
71 } |
|
72 } |
|
73 |
|
74 } // namespace mozilla::plugins |
|
75 } // namespace mozilla |