/src/mozilla-central/dom/plugins/ipc/PluginScriptableObjectUtils-inl.h
Line | Count | Source (jump to first uncovered line) |
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 "PluginScriptableObjectUtils.h" |
8 | | |
9 | | namespace { |
10 | | |
11 | | template<class InstanceType> |
12 | | class VariantTraits; |
13 | | |
14 | | template<> |
15 | | class VariantTraits<mozilla::plugins::PluginInstanceParent> |
16 | | { |
17 | | public: |
18 | | typedef mozilla::plugins::PluginScriptableObjectParent ScriptableObjectType; |
19 | | }; |
20 | | |
21 | | template<> |
22 | | class VariantTraits<mozilla::plugins::PluginInstanceChild> |
23 | | { |
24 | | public: |
25 | | typedef mozilla::plugins::PluginScriptableObjectChild ScriptableObjectType; |
26 | | }; |
27 | | |
28 | | } /* anonymous namespace */ |
29 | | |
30 | | inline bool |
31 | | mozilla::plugins::ConvertToVariant(const Variant& aRemoteVariant, |
32 | | NPVariant& aVariant, |
33 | | PluginInstanceParent* aInstance) |
34 | 0 | { |
35 | 0 | switch (aRemoteVariant.type()) { |
36 | 0 | case Variant::Tvoid_t: { |
37 | 0 | VOID_TO_NPVARIANT(aVariant); |
38 | 0 | break; |
39 | 0 | } |
40 | 0 |
|
41 | 0 | case Variant::Tnull_t: { |
42 | 0 | NULL_TO_NPVARIANT(aVariant); |
43 | 0 | break; |
44 | 0 | } |
45 | 0 |
|
46 | 0 | case Variant::Tbool: { |
47 | 0 | BOOLEAN_TO_NPVARIANT(aRemoteVariant.get_bool(), aVariant); |
48 | 0 | break; |
49 | 0 | } |
50 | 0 |
|
51 | 0 | case Variant::Tint: { |
52 | 0 | INT32_TO_NPVARIANT(aRemoteVariant.get_int(), aVariant); |
53 | 0 | break; |
54 | 0 | } |
55 | 0 |
|
56 | 0 | case Variant::Tdouble: { |
57 | 0 | DOUBLE_TO_NPVARIANT(aRemoteVariant.get_double(), aVariant); |
58 | 0 | break; |
59 | 0 | } |
60 | 0 |
|
61 | 0 | case Variant::TnsCString: { |
62 | 0 | const nsCString& string = aRemoteVariant.get_nsCString(); |
63 | 0 | const size_t length = string.Length(); |
64 | 0 | NPUTF8* buffer = static_cast<NPUTF8*>(::malloc(sizeof(NPUTF8) * (length + 1))); |
65 | 0 | if (!buffer) { |
66 | 0 | NS_ERROR("Out of memory!"); |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 |
|
70 | 0 | std::copy(string.get(), string.get() + length, buffer); |
71 | 0 | buffer[length] = '\0'; |
72 | 0 | STRINGN_TO_NPVARIANT(buffer, length, aVariant); |
73 | 0 | break; |
74 | 0 | } |
75 | 0 |
|
76 | 0 | case Variant::TPPluginScriptableObjectParent: { |
77 | 0 | NS_ASSERTION(aInstance, "Must have an instance!"); |
78 | 0 | NPObject* object = NPObjectFromVariant(aRemoteVariant); |
79 | 0 | if (!object) { |
80 | 0 | NS_ERROR("Er, this shouldn't fail!"); |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 |
|
84 | 0 | const NPNetscapeFuncs* npn = GetNetscapeFuncs(aInstance); |
85 | 0 | if (!npn) { |
86 | 0 | NS_ERROR("Null netscape funcs!"); |
87 | 0 | return false; |
88 | 0 | } |
89 | 0 |
|
90 | 0 | npn->retainobject(object); |
91 | 0 | OBJECT_TO_NPVARIANT(object, aVariant); |
92 | 0 | break; |
93 | 0 | } |
94 | 0 |
|
95 | 0 | case Variant::TPPluginScriptableObjectChild: { |
96 | 0 | NS_ASSERTION(!aInstance, "No instance should be given!"); |
97 | 0 | NS_ASSERTION(XRE_GetProcessType() == GeckoProcessType_Plugin, |
98 | 0 | "Should be running on child only!"); |
99 | 0 |
|
100 | 0 | NPObject* object = NPObjectFromVariant(aRemoteVariant); |
101 | 0 | NS_ASSERTION(object, "Null object?!"); |
102 | 0 |
|
103 | 0 | PluginModuleChild::sBrowserFuncs.retainobject(object); |
104 | 0 | OBJECT_TO_NPVARIANT(object, aVariant); |
105 | 0 | break; |
106 | 0 | } |
107 | 0 |
|
108 | 0 | default: |
109 | 0 | MOZ_ASSERT_UNREACHABLE("Shouldn't get here!"); |
110 | 0 | return false; |
111 | 0 | } |
112 | 0 |
|
113 | 0 | return true; |
114 | 0 | } |
115 | | |
116 | | template <class InstanceType> |
117 | | bool |
118 | | mozilla::plugins::ConvertToRemoteVariant(const NPVariant& aVariant, |
119 | | Variant& aRemoteVariant, |
120 | | InstanceType* aInstance, |
121 | | bool aProtectActors) |
122 | 0 | { |
123 | 0 | if (NPVARIANT_IS_VOID(aVariant)) { |
124 | 0 | aRemoteVariant = mozilla::void_t(); |
125 | 0 | } |
126 | 0 | else if (NPVARIANT_IS_NULL(aVariant)) { |
127 | 0 | aRemoteVariant = mozilla::null_t(); |
128 | 0 | } |
129 | 0 | else if (NPVARIANT_IS_BOOLEAN(aVariant)) { |
130 | 0 | aRemoteVariant = NPVARIANT_TO_BOOLEAN(aVariant); |
131 | 0 | } |
132 | 0 | else if (NPVARIANT_IS_INT32(aVariant)) { |
133 | 0 | aRemoteVariant = NPVARIANT_TO_INT32(aVariant); |
134 | 0 | } |
135 | 0 | else if (NPVARIANT_IS_DOUBLE(aVariant)) { |
136 | 0 | aRemoteVariant = NPVARIANT_TO_DOUBLE(aVariant); |
137 | 0 | } |
138 | 0 | else if (NPVARIANT_IS_STRING(aVariant)) { |
139 | 0 | NPString str = NPVARIANT_TO_STRING(aVariant); |
140 | 0 | nsCString string(str.UTF8Characters, str.UTF8Length); |
141 | 0 | aRemoteVariant = string; |
142 | 0 | } |
143 | 0 | else if (NPVARIANT_IS_OBJECT(aVariant)) { |
144 | 0 | NPObject* object = NPVARIANT_TO_OBJECT(aVariant); |
145 | 0 |
|
146 | 0 | typename VariantTraits<InstanceType>::ScriptableObjectType* actor = |
147 | 0 | aInstance->GetActorForNPObject(object); |
148 | 0 |
|
149 | 0 | if (!actor) { |
150 | 0 | NS_ERROR("Null actor!"); |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 |
|
154 | 0 | if (aProtectActors) { |
155 | 0 | actor->Protect(); |
156 | 0 | } |
157 | 0 |
|
158 | 0 | aRemoteVariant = actor; |
159 | 0 | } |
160 | 0 | else { |
161 | 0 | MOZ_ASSERT_UNREACHABLE("Shouldn't get here!"); |
162 | 0 | return false; |
163 | 0 | } |
164 | 0 |
|
165 | 0 | return true; |
166 | 0 | } Unexecuted instantiation: bool mozilla::plugins::ConvertToRemoteVariant<mozilla::plugins::PluginInstanceParent>(_NPVariant const&, mozilla::plugins::Variant&, mozilla::plugins::PluginInstanceParent*, bool) Unexecuted instantiation: bool mozilla::plugins::ConvertToRemoteVariant<mozilla::plugins::PluginInstanceChild>(_NPVariant const&, mozilla::plugins::Variant&, mozilla::plugins::PluginInstanceChild*, bool) |