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