| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/plugin_param_traits.h" | |
| 6 | |
| 7 #include "base/strings/string_number_conversions.h" | |
| 8 #include "ipc/ipc_message_utils.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | |
| 10 #include "webkit/glue/npruntime_util.h" | |
| 11 #include "webkit/plugins/npapi/plugin_host.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 NPIdentifier_Param::NPIdentifier_Param() | |
| 16 : identifier() { | |
| 17 } | |
| 18 | |
| 19 NPIdentifier_Param::~NPIdentifier_Param() { | |
| 20 } | |
| 21 | |
| 22 NPVariant_Param::NPVariant_Param() | |
| 23 : type(NPVARIANT_PARAM_VOID), | |
| 24 bool_value(false), | |
| 25 int_value(0), | |
| 26 double_value(0), | |
| 27 npobject_routing_id(-1) { | |
| 28 } | |
| 29 | |
| 30 NPVariant_Param::~NPVariant_Param() { | |
| 31 } | |
| 32 | |
| 33 } // namespace content | |
| 34 | |
| 35 using content::NPIdentifier_Param; | |
| 36 using content::NPVariant_Param; | |
| 37 | |
| 38 namespace IPC { | |
| 39 | |
| 40 void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) { | |
| 41 WriteParam(m, static_cast<int>(p.type)); | |
| 42 if (p.type == content::NPVARIANT_PARAM_BOOL) { | |
| 43 WriteParam(m, p.bool_value); | |
| 44 } else if (p.type == content::NPVARIANT_PARAM_INT) { | |
| 45 WriteParam(m, p.int_value); | |
| 46 } else if (p.type == content::NPVARIANT_PARAM_DOUBLE) { | |
| 47 WriteParam(m, p.double_value); | |
| 48 } else if (p.type == content::NPVARIANT_PARAM_STRING) { | |
| 49 WriteParam(m, p.string_value); | |
| 50 } else if (p.type == content::NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || | |
| 51 p.type == content::NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { | |
| 52 // This is the routing id used to connect NPObjectProxy in the other | |
| 53 // process with NPObjectStub in this process or to identify the raw | |
| 54 // npobject pointer to be used in the callee process. | |
| 55 WriteParam(m, p.npobject_routing_id); | |
| 56 } else { | |
| 57 DCHECK(p.type == content::NPVARIANT_PARAM_VOID || | |
| 58 p.type == content::NPVARIANT_PARAM_NULL); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 bool ParamTraits<NPVariant_Param>::Read(const Message* m, | |
| 63 PickleIterator* iter, | |
| 64 param_type* r) { | |
| 65 int type; | |
| 66 if (!ReadParam(m, iter, &type)) | |
| 67 return false; | |
| 68 | |
| 69 bool result = false; | |
| 70 r->type = static_cast<content::NPVariant_ParamEnum>(type); | |
| 71 if (r->type == content::NPVARIANT_PARAM_BOOL) { | |
| 72 result = ReadParam(m, iter, &r->bool_value); | |
| 73 } else if (r->type == content::NPVARIANT_PARAM_INT) { | |
| 74 result = ReadParam(m, iter, &r->int_value); | |
| 75 } else if (r->type == content::NPVARIANT_PARAM_DOUBLE) { | |
| 76 result = ReadParam(m, iter, &r->double_value); | |
| 77 } else if (r->type == content::NPVARIANT_PARAM_STRING) { | |
| 78 result = ReadParam(m, iter, &r->string_value); | |
| 79 } else if (r->type == content::NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || | |
| 80 r->type == content::NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { | |
| 81 result = ReadParam(m, iter, &r->npobject_routing_id); | |
| 82 } else if ((r->type == content::NPVARIANT_PARAM_VOID) || | |
| 83 (r->type == content::NPVARIANT_PARAM_NULL)) { | |
| 84 result = true; | |
| 85 } else { | |
| 86 NOTREACHED(); | |
| 87 } | |
| 88 | |
| 89 return result; | |
| 90 } | |
| 91 | |
| 92 void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) { | |
| 93 l->append( | |
| 94 base::StringPrintf("NPVariant_Param(%d, ", static_cast<int>(p.type))); | |
| 95 if (p.type == content::NPVARIANT_PARAM_BOOL) { | |
| 96 LogParam(p.bool_value, l); | |
| 97 } else if (p.type == content::NPVARIANT_PARAM_INT) { | |
| 98 LogParam(p.int_value, l); | |
| 99 } else if (p.type == content::NPVARIANT_PARAM_DOUBLE) { | |
| 100 LogParam(p.double_value, l); | |
| 101 } else if (p.type == content::NPVARIANT_PARAM_STRING) { | |
| 102 LogParam(p.string_value, l); | |
| 103 } else if (p.type == content::NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || | |
| 104 p.type == content::NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { | |
| 105 LogParam(p.npobject_routing_id, l); | |
| 106 } else { | |
| 107 l->append("<none>"); | |
| 108 } | |
| 109 l->append(")"); | |
| 110 } | |
| 111 | |
| 112 void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) { | |
| 113 webkit_glue::SerializeNPIdentifier(p.identifier, m); | |
| 114 } | |
| 115 | |
| 116 bool ParamTraits<NPIdentifier_Param>::Read(const Message* m, | |
| 117 PickleIterator* iter, | |
| 118 param_type* r) { | |
| 119 return webkit_glue::DeserializeNPIdentifier(iter, &r->identifier); | |
| 120 } | |
| 121 | |
| 122 void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) { | |
| 123 if (WebKit::WebBindings::identifierIsString(p.identifier)) { | |
| 124 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); | |
| 125 l->append(str); | |
| 126 webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(str); | |
| 127 } else { | |
| 128 l->append(base::IntToString( | |
| 129 WebKit::WebBindings::intFromIdentifier(p.identifier))); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 } // namespace IPC | |
| OLD | NEW |