| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 // This file is used to define IPC::ParamTraits<> specializations for a number | |
| 6 // of WebKit types so that they can be serialized over IPC. IPC::ParamTraits<> | |
| 7 // specializations for basic types (like int and std::string) and types in the | |
| 8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains | |
| 9 // specializations for types that are used by the content code, and which need | |
| 10 // manual serialization code. This is usually because they're not structs with | |
| 11 // public members. | |
| 12 | |
| 13 #ifndef CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
| 14 #define CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
| 15 #pragma once | |
| 16 | |
| 17 #include <string> | |
| 18 | |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "content/common/content_export.h" | |
| 21 #include "ipc/ipc_message_utils.h" | |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | |
| 24 #include "webkit/blob/blob_data.h" | |
| 25 #include "webkit/glue/npruntime_util.h" | |
| 26 #include "webkit/glue/resource_type.h" | |
| 27 #include "webkit/glue/webcursor.h" | |
| 28 #include "webkit/glue/window_open_disposition.h" | |
| 29 #include "webkit/plugins/webplugininfo.h" | |
| 30 | |
| 31 namespace webkit_glue { | |
| 32 struct PasswordForm; | |
| 33 struct ResourceDevToolsInfo; | |
| 34 struct ResourceLoadTimingInfo; | |
| 35 } | |
| 36 | |
| 37 // Define the NPVariant_Param struct and its enum here since it needs manual | |
| 38 // serialization code. | |
| 39 enum NPVariant_ParamEnum { | |
| 40 NPVARIANT_PARAM_VOID, | |
| 41 NPVARIANT_PARAM_NULL, | |
| 42 NPVARIANT_PARAM_BOOL, | |
| 43 NPVARIANT_PARAM_INT, | |
| 44 NPVARIANT_PARAM_DOUBLE, | |
| 45 NPVARIANT_PARAM_STRING, | |
| 46 // Used when when the NPObject is running in the caller's process, so we | |
| 47 // create an NPObjectProxy in the other process. | |
| 48 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, | |
| 49 // Used when the NPObject we're sending is running in the callee's process | |
| 50 // (i.e. we have an NPObjectProxy for it). In that case we want the callee | |
| 51 // to just use the raw pointer. | |
| 52 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, | |
| 53 }; | |
| 54 | |
| 55 struct NPVariant_Param { | |
| 56 NPVariant_Param(); | |
| 57 ~NPVariant_Param(); | |
| 58 | |
| 59 NPVariant_ParamEnum type; | |
| 60 bool bool_value; | |
| 61 int int_value; | |
| 62 double double_value; | |
| 63 std::string string_value; | |
| 64 int npobject_routing_id; | |
| 65 }; | |
| 66 | |
| 67 struct NPIdentifier_Param { | |
| 68 NPIdentifier_Param(); | |
| 69 ~NPIdentifier_Param(); | |
| 70 | |
| 71 NPIdentifier identifier; | |
| 72 }; | |
| 73 | |
| 74 namespace IPC { | |
| 75 | |
| 76 template <> | |
| 77 struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> { | |
| 78 typedef webkit_glue::ResourceLoadTimingInfo param_type; | |
| 79 static void Write(Message* m, const param_type& p); | |
| 80 static bool Read(const Message* m, void** iter, param_type* r); | |
| 81 static void Log(const param_type& p, std::string* l); | |
| 82 }; | |
| 83 | |
| 84 template <> | |
| 85 struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > { | |
| 86 typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type; | |
| 87 static void Write(Message* m, const param_type& p); | |
| 88 static bool Read(const Message* m, void** iter, param_type* r); | |
| 89 static void Log(const param_type& p, std::string* l); | |
| 90 }; | |
| 91 | |
| 92 template <> | |
| 93 struct ParamTraits<NPVariant_Param> { | |
| 94 typedef NPVariant_Param param_type; | |
| 95 static void Write(Message* m, const param_type& p); | |
| 96 static bool Read(const Message* m, void** iter, param_type* r); | |
| 97 static void Log(const param_type& p, std::string* l); | |
| 98 }; | |
| 99 | |
| 100 template <> | |
| 101 struct ParamTraits<NPIdentifier_Param> { | |
| 102 typedef NPIdentifier_Param param_type; | |
| 103 static void Write(Message* m, const param_type& p); | |
| 104 static bool Read(const Message* m, void** iter, param_type* r); | |
| 105 static void Log(const param_type& p, std::string* l); | |
| 106 }; | |
| 107 | |
| 108 template <> | |
| 109 struct ParamTraits<webkit::WebPluginMimeType> { | |
| 110 typedef webkit::WebPluginMimeType param_type; | |
| 111 static void Write(Message* m, const param_type& p); | |
| 112 static bool Read(const Message* m, void** iter, param_type* r); | |
| 113 static void Log(const param_type& p, std::string* l); | |
| 114 }; | |
| 115 | |
| 116 template <> | |
| 117 struct CONTENT_EXPORT ParamTraits<webkit::WebPluginInfo> { | |
| 118 typedef webkit::WebPluginInfo param_type; | |
| 119 static void Write(Message* m, const param_type& p); | |
| 120 static bool Read(const Message* m, void** iter, param_type* r); | |
| 121 static void Log(const param_type& p, std::string* l); | |
| 122 }; | |
| 123 | |
| 124 template <> | |
| 125 struct ParamTraits<WebCursor> { | |
| 126 typedef WebCursor param_type; | |
| 127 static void Write(Message* m, const param_type& p) { | |
| 128 p.Serialize(m); | |
| 129 } | |
| 130 static bool Read(const Message* m, void** iter, param_type* r) { | |
| 131 return r->Deserialize(m, iter); | |
| 132 } | |
| 133 static void Log(const param_type& p, std::string* l) { | |
| 134 l->append("<WebCursor>"); | |
| 135 } | |
| 136 }; | |
| 137 | |
| 138 template <> | |
| 139 struct ParamTraits<WebKit::WebInputEvent::Type> { | |
| 140 typedef WebKit::WebInputEvent::Type param_type; | |
| 141 static void Write(Message* m, const param_type& p) { | |
| 142 m->WriteInt(p); | |
| 143 } | |
| 144 static bool Read(const Message* m, void** iter, param_type* p) { | |
| 145 int type; | |
| 146 if (!m->ReadInt(iter, &type)) | |
| 147 return false; | |
| 148 *p = static_cast<WebKit::WebInputEvent::Type>(type); | |
| 149 return true; | |
| 150 } | |
| 151 static void Log(const param_type& p, std::string* l) { | |
| 152 const char* type; | |
| 153 switch (p) { | |
| 154 case WebKit::WebInputEvent::MouseDown: | |
| 155 type = "MouseDown"; | |
| 156 break; | |
| 157 case WebKit::WebInputEvent::MouseUp: | |
| 158 type = "MouseUp"; | |
| 159 break; | |
| 160 case WebKit::WebInputEvent::MouseMove: | |
| 161 type = "MouseMove"; | |
| 162 break; | |
| 163 case WebKit::WebInputEvent::MouseLeave: | |
| 164 type = "MouseLeave"; | |
| 165 break; | |
| 166 case WebKit::WebInputEvent::MouseEnter: | |
| 167 type = "MouseEnter"; | |
| 168 break; | |
| 169 case WebKit::WebInputEvent::MouseWheel: | |
| 170 type = "MouseWheel"; | |
| 171 break; | |
| 172 case WebKit::WebInputEvent::RawKeyDown: | |
| 173 type = "RawKeyDown"; | |
| 174 break; | |
| 175 case WebKit::WebInputEvent::KeyDown: | |
| 176 type = "KeyDown"; | |
| 177 break; | |
| 178 case WebKit::WebInputEvent::KeyUp: | |
| 179 type = "KeyUp"; | |
| 180 break; | |
| 181 default: | |
| 182 type = "None"; | |
| 183 break; | |
| 184 } | |
| 185 LogParam(std::string(type), l); | |
| 186 } | |
| 187 }; | |
| 188 | |
| 189 typedef const WebKit::WebInputEvent* WebInputEventPointer; | |
| 190 template <> | |
| 191 struct ParamTraits<WebInputEventPointer> { | |
| 192 typedef WebInputEventPointer param_type; | |
| 193 static void Write(Message* m, const param_type& p) { | |
| 194 m->WriteData(reinterpret_cast<const char*>(p), p->size); | |
| 195 } | |
| 196 // Note: upon read, the event has the lifetime of the message. | |
| 197 static bool Read(const Message* m, void** iter, param_type* r) { | |
| 198 const char* data; | |
| 199 int data_length; | |
| 200 if (!m->ReadData(iter, &data, &data_length)) { | |
| 201 NOTREACHED(); | |
| 202 return false; | |
| 203 } | |
| 204 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) { | |
| 205 NOTREACHED(); | |
| 206 return false; | |
| 207 } | |
| 208 param_type event = reinterpret_cast<param_type>(data); | |
| 209 // Check that the data size matches that of the event (we check the latter | |
| 210 // in the delegate). | |
| 211 if (data_length != static_cast<int>(event->size)) { | |
| 212 NOTREACHED(); | |
| 213 return false; | |
| 214 } | |
| 215 *r = event; | |
| 216 return true; | |
| 217 } | |
| 218 static void Log(const param_type& p, std::string* l) { | |
| 219 l->append("("); | |
| 220 LogParam(p->size, l); | |
| 221 l->append(", "); | |
| 222 LogParam(p->type, l); | |
| 223 l->append(", "); | |
| 224 LogParam(p->timeStampSeconds, l); | |
| 225 l->append(")"); | |
| 226 } | |
| 227 }; | |
| 228 | |
| 229 template <> | |
| 230 struct SimilarTypeTraits<WebKit::WebTextDirection> { | |
| 231 typedef int Type; | |
| 232 }; | |
| 233 | |
| 234 template <> | |
| 235 struct SimilarTypeTraits<WindowOpenDisposition> { | |
| 236 typedef int Type; | |
| 237 }; | |
| 238 | |
| 239 template <> | |
| 240 struct CONTENT_EXPORT ParamTraits<webkit_glue::PasswordForm> { | |
| 241 typedef webkit_glue::PasswordForm param_type; | |
| 242 static void Write(Message* m, const param_type& p); | |
| 243 static bool Read(const Message* m, void** iter, param_type* p); | |
| 244 static void Log(const param_type& p, std::string* l); | |
| 245 }; | |
| 246 | |
| 247 } // namespace IPC | |
| 248 | |
| 249 #endif // CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
| OLD | NEW |