OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/plugin/npobject_util.h" | 5 #include "content/plugin/npobject_util.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "content/common/plugin_messages.h" | 8 #include "content/common/plugin_messages.h" |
9 #include "content/plugin/npobject_proxy.h" | 9 #include "content/plugin/npobject_proxy.h" |
10 #include "content/plugin/plugin_channel_base.h" | 10 #include "content/plugin/plugin_channel_base.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Don't release, because our original variant is the same as our proxy. | 185 // Don't release, because our original variant is the same as our proxy. |
186 release = false; | 186 release = false; |
187 } else { | 187 } else { |
188 // The channel could be NULL if there was a channel error. The caller's | 188 // The channel could be NULL if there was a channel error. The caller's |
189 // Send call will fail anyways. | 189 // Send call will fail anyways. |
190 if (channel) { | 190 if (channel) { |
191 // NPObjectStub adds its own reference to the NPObject it owns, so if | 191 // NPObjectStub adds its own reference to the NPObject it owns, so if |
192 // we were supposed to release the corresponding variant | 192 // we were supposed to release the corresponding variant |
193 // (release==true), we should still do that. | 193 // (release==true), we should still do that. |
194 param->type = NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID; | 194 param->type = NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID; |
195 int route_id = channel->GenerateRouteID(); | 195 int route_id = channel->GetExistingRouteForNPObjectStub( |
196 new NPObjectStub( | 196 variant.value.objectValue); |
197 variant.value.objectValue, channel, route_id, containing_window, | 197 if (route_id != MSG_ROUTING_NONE) { |
198 page_url); | 198 param->npobject_routing_id = route_id; |
199 param->npobject_routing_id = route_id; | 199 } else { |
| 200 route_id = channel->GenerateRouteID(); |
| 201 new NPObjectStub( |
| 202 variant.value.objectValue, channel, route_id, |
| 203 containing_window, page_url); |
| 204 param->npobject_routing_id = route_id; |
| 205 } |
200 } else { | 206 } else { |
201 param->type = NPVARIANT_PARAM_VOID; | 207 param->type = NPVARIANT_PARAM_VOID; |
202 } | 208 } |
203 } | 209 } |
204 break; | 210 break; |
205 } | 211 } |
206 default: | 212 default: |
207 NOTREACHED(); | 213 NOTREACHED(); |
208 } | 214 } |
209 | 215 |
210 if (release) | 216 if (release) |
211 WebBindings::releaseVariantValue(const_cast<NPVariant*>(&variant)); | 217 WebBindings::releaseVariantValue(const_cast<NPVariant*>(&variant)); |
212 } | 218 } |
213 | 219 |
214 bool CreateNPVariant(const NPVariant_Param& param, | 220 bool CreateNPVariant(const NPVariant_Param& param, |
215 PluginChannelBase* channel, | 221 PluginChannelBase* channel, |
216 NPVariant* result, | 222 NPVariant* result, |
217 gfx::NativeViewId containing_window, | 223 gfx::NativeViewId containing_window, |
218 const GURL& page_url) { | 224 const GURL& page_url) { |
| 225 NPObject* object = NULL; |
219 switch (param.type) { | 226 switch (param.type) { |
220 case NPVARIANT_PARAM_VOID: | 227 case NPVARIANT_PARAM_VOID: |
221 result->type = NPVariantType_Void; | 228 result->type = NPVariantType_Void; |
222 break; | 229 break; |
223 case NPVARIANT_PARAM_NULL: | 230 case NPVARIANT_PARAM_NULL: |
224 result->type = NPVariantType_Null; | 231 result->type = NPVariantType_Null; |
225 break; | 232 break; |
226 case NPVARIANT_PARAM_BOOL: | 233 case NPVARIANT_PARAM_BOOL: |
227 result->type = NPVariantType_Bool; | 234 result->type = NPVariantType_Bool; |
228 result->value.boolValue = param.bool_value; | 235 result->value.boolValue = param.bool_value; |
229 break; | 236 break; |
230 case NPVARIANT_PARAM_INT: | 237 case NPVARIANT_PARAM_INT: |
231 result->type = NPVariantType_Int32; | 238 result->type = NPVariantType_Int32; |
232 result->value.intValue = param.int_value; | 239 result->value.intValue = param.int_value; |
233 break; | 240 break; |
234 case NPVARIANT_PARAM_DOUBLE: | 241 case NPVARIANT_PARAM_DOUBLE: |
235 result->type = NPVariantType_Double; | 242 result->type = NPVariantType_Double; |
236 result->value.doubleValue = param.double_value; | 243 result->value.doubleValue = param.double_value; |
237 break; | 244 break; |
238 case NPVARIANT_PARAM_STRING: | 245 case NPVARIANT_PARAM_STRING: |
239 result->type = NPVariantType_String; | 246 result->type = NPVariantType_String; |
240 result->value.stringValue.UTF8Characters = | 247 result->value.stringValue.UTF8Characters = |
241 static_cast<NPUTF8 *>(base::strdup(param.string_value.c_str())); | 248 static_cast<NPUTF8 *>(base::strdup(param.string_value.c_str())); |
242 result->value.stringValue.UTF8Length = | 249 result->value.stringValue.UTF8Length = |
243 static_cast<int>(param.string_value.size()); | 250 static_cast<int>(param.string_value.size()); |
244 break; | 251 break; |
245 case NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID: | 252 case NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID: |
246 result->type = NPVariantType_Object; | 253 result->type = NPVariantType_Object; |
247 result->value.objectValue = | 254 object = channel->GetExistingNPObjectProxy(param.npobject_routing_id); |
248 NPObjectProxy::Create(channel, | 255 if (object) { |
249 param.npobject_routing_id, | 256 WebBindings::retainObject(object); |
250 containing_window, | 257 result->value.objectValue = object; |
251 page_url); | 258 } else { |
| 259 result->value.objectValue = |
| 260 object = NPObjectProxy::Create(channel, |
| 261 param.npobject_routing_id, |
| 262 containing_window, |
| 263 page_url); |
| 264 result->value.objectValue = object; |
| 265 } |
252 break; | 266 break; |
253 case NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID: { | 267 case NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID: { |
254 NPObjectBase* npobject_base = | 268 NPObjectBase* npobject_base = |
255 channel->GetNPObjectListenerForRoute(param.npobject_routing_id); | 269 channel->GetNPObjectListenerForRoute(param.npobject_routing_id); |
256 if (!npobject_base) { | 270 if (!npobject_base) { |
257 DLOG(WARNING) << "Invalid routing id passed in" | 271 DLOG(WARNING) << "Invalid routing id passed in" |
258 << param.npobject_routing_id; | 272 << param.npobject_routing_id; |
259 return false; | 273 return false; |
260 } | 274 } |
261 | 275 |
262 DCHECK(npobject_base->GetUnderlyingNPObject() != NULL); | 276 DCHECK(npobject_base->GetUnderlyingNPObject() != NULL); |
263 | 277 |
264 result->type = NPVariantType_Object; | 278 result->type = NPVariantType_Object; |
265 result->value.objectValue = npobject_base->GetUnderlyingNPObject(); | 279 result->value.objectValue = npobject_base->GetUnderlyingNPObject(); |
266 WebBindings::retainObject(result->value.objectValue); | 280 WebBindings::retainObject(result->value.objectValue); |
267 break; | 281 break; |
268 } | 282 } |
269 default: | 283 default: |
270 NOTREACHED(); | 284 NOTREACHED(); |
271 } | 285 } |
272 return true; | 286 return true; |
273 } | 287 } |
OLD | NEW |