| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef PPAPI_PROXY_SERIALIZED_STRUCTS_H_ | 5 #ifndef PPAPI_PROXY_SERIALIZED_HANDLES_H_ |
| 6 #define PPAPI_PROXY_SERIALIZED_STRUCTS_H_ | 6 #define PPAPI_PROXY_SERIALIZED_HANDLES_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
| 15 #include "ppapi/c/pp_bool.h" | |
| 16 #include "ppapi/c/pp_instance.h" | |
| 17 #include "ppapi/c/pp_point.h" | |
| 18 #include "ppapi/c/pp_rect.h" | |
| 19 #include "ppapi/proxy/ppapi_proxy_export.h" | 16 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 20 #include "ppapi/shared_impl/host_resource.h" | |
| 21 | 17 |
| 22 class Pickle; | 18 class Pickle; |
| 23 struct PP_FontDescription_Dev; | |
| 24 struct PP_BrowserFont_Trusted_Description; | |
| 25 | 19 |
| 26 namespace ppapi { | 20 namespace ppapi { |
| 27 namespace proxy { | 21 namespace proxy { |
| 28 | 22 |
| 29 // PP_FontDescription_Dev/PP_BrowserFontDescription (same definition, different | 23 // SerializedHandle is a unified structure for holding a handle (e.g., a shared |
| 30 // names) has to be redefined with a string in place of the PP_Var used for the | 24 // memory handle, socket descriptor, etc). This is useful for passing handles in |
| 31 // face name. | 25 // resource messages and also makes it easier to translate handles in |
| 32 struct PPAPI_PROXY_EXPORT SerializedFontDescription { | 26 // NaClIPCAdapter for use in NaCl. |
| 33 SerializedFontDescription(); | |
| 34 ~SerializedFontDescription(); | |
| 35 | |
| 36 // Converts a PP_FontDescription_Dev to a SerializedFontDescription. | |
| 37 // | |
| 38 // The reference of |face| owned by the PP_FontDescription_Dev will be | |
| 39 // unchanged and the caller is responsible for freeing it. | |
| 40 void SetFromPPFontDescription(const PP_FontDescription_Dev& desc); | |
| 41 void SetFromPPBrowserFontDescription( | |
| 42 const PP_BrowserFont_Trusted_Description& desc); | |
| 43 | |
| 44 // Converts to a PP_FontDescription_Dev. The face name will have one ref | |
| 45 // assigned to it. The caller is responsible for freeing it. | |
| 46 void SetToPPFontDescription(PP_FontDescription_Dev* desc) const; | |
| 47 void SetToPPBrowserFontDescription( | |
| 48 PP_BrowserFont_Trusted_Description* desc) const; | |
| 49 | |
| 50 std::string face; | |
| 51 int32_t family; | |
| 52 uint32_t size; | |
| 53 int32_t weight; | |
| 54 PP_Bool italic; | |
| 55 PP_Bool small_caps; | |
| 56 int32_t letter_spacing; | |
| 57 int32_t word_spacing; | |
| 58 }; | |
| 59 | |
| 60 struct SerializedDirEntry { | |
| 61 std::string name; | |
| 62 bool is_dir; | |
| 63 }; | |
| 64 | |
| 65 struct PPAPI_PROXY_EXPORT PPBFlash_DrawGlyphs_Params { | |
| 66 PPBFlash_DrawGlyphs_Params(); | |
| 67 ~PPBFlash_DrawGlyphs_Params(); | |
| 68 | |
| 69 PP_Instance instance; | |
| 70 ppapi::HostResource image_data; | |
| 71 SerializedFontDescription font_desc; | |
| 72 uint32_t color; | |
| 73 PP_Point position; | |
| 74 PP_Rect clip; | |
| 75 float transformation[3][3]; | |
| 76 PP_Bool allow_subpixel_aa; | |
| 77 std::vector<uint16_t> glyph_indices; | |
| 78 std::vector<PP_Point> glyph_advances; | |
| 79 }; | |
| 80 | |
| 81 struct PPBURLLoader_UpdateProgress_Params { | |
| 82 PP_Instance instance; | |
| 83 ppapi::HostResource resource; | |
| 84 int64_t bytes_sent; | |
| 85 int64_t total_bytes_to_be_sent; | |
| 86 int64_t bytes_received; | |
| 87 int64_t total_bytes_to_be_received; | |
| 88 }; | |
| 89 | |
| 90 // We put all our handles in a unified structure to make it easy to translate | |
| 91 // them in NaClIPCAdapter for use in NaCl. | |
| 92 class PPAPI_PROXY_EXPORT SerializedHandle { | 27 class PPAPI_PROXY_EXPORT SerializedHandle { |
| 93 public: | 28 public: |
| 94 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE, FILE }; | 29 enum Type { INVALID, SHARED_MEMORY, SOCKET, CHANNEL_HANDLE, FILE }; |
| 95 struct Header { | 30 struct Header { |
| 96 Header() : type(INVALID), size(0) {} | 31 Header() : type(INVALID), size(0) {} |
| 97 Header(Type type_arg, uint32_t size_arg) | 32 Header(Type type_arg, uint32 size_arg) |
| 98 : type(type_arg), size(size_arg) { | 33 : type(type_arg), size(size_arg) { |
| 99 } | 34 } |
| 100 Type type; | 35 Type type; |
| 101 uint32_t size; | 36 uint32 size; |
| 102 }; | 37 }; |
| 103 | 38 |
| 104 SerializedHandle(); | 39 SerializedHandle(); |
| 105 // Create an invalid handle of the given type. | 40 // Create an invalid handle of the given type. |
| 106 explicit SerializedHandle(Type type); | 41 explicit SerializedHandle(Type type); |
| 107 | 42 |
| 108 // Create a shared memory handle. | 43 // Create a shared memory handle. |
| 109 SerializedHandle(const base::SharedMemoryHandle& handle, uint32_t size); | 44 SerializedHandle(const base::SharedMemoryHandle& handle, uint32 size); |
| 110 | 45 |
| 111 // Create a socket, channel or file handle. | 46 // Create a socket, channel or file handle. |
| 112 SerializedHandle(const Type type, | 47 SerializedHandle(const Type type, |
| 113 const IPC::PlatformFileForTransit& descriptor); | 48 const IPC::PlatformFileForTransit& descriptor); |
| 114 | 49 |
| 115 Type type() const { return type_; } | 50 Type type() const { return type_; } |
| 116 bool is_shmem() const { return type_ == SHARED_MEMORY; } | 51 bool is_shmem() const { return type_ == SHARED_MEMORY; } |
| 117 bool is_socket() const { return type_ == SOCKET; } | 52 bool is_socket() const { return type_ == SOCKET; } |
| 118 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; } | 53 bool is_channel_handle() const { return type_ == CHANNEL_HANDLE; } |
| 119 bool is_file() const { return type_ == FILE; } | 54 bool is_file() const { return type_ == FILE; } |
| 120 const base::SharedMemoryHandle& shmem() const { | 55 const base::SharedMemoryHandle& shmem() const { |
| 121 DCHECK(is_shmem()); | 56 DCHECK(is_shmem()); |
| 122 return shm_handle_; | 57 return shm_handle_; |
| 123 } | 58 } |
| 124 uint32_t size() const { | 59 uint32 size() const { |
| 125 DCHECK(is_shmem()); | 60 DCHECK(is_shmem()); |
| 126 return size_; | 61 return size_; |
| 127 } | 62 } |
| 128 const IPC::PlatformFileForTransit& descriptor() const { | 63 const IPC::PlatformFileForTransit& descriptor() const { |
| 129 DCHECK(is_socket() || is_channel_handle() || is_file()); | 64 DCHECK(is_socket() || is_channel_handle() || is_file()); |
| 130 return descriptor_; | 65 return descriptor_; |
| 131 } | 66 } |
| 132 void set_shmem(const base::SharedMemoryHandle& handle, uint32_t size) { | 67 void set_shmem(const base::SharedMemoryHandle& handle, uint32 size) { |
| 133 type_ = SHARED_MEMORY; | 68 type_ = SHARED_MEMORY; |
| 134 shm_handle_ = handle; | 69 shm_handle_ = handle; |
| 135 size_ = size; | 70 size_ = size; |
| 136 | 71 |
| 137 descriptor_ = IPC::InvalidPlatformFileForTransit(); | 72 descriptor_ = IPC::InvalidPlatformFileForTransit(); |
| 138 } | 73 } |
| 139 void set_socket(const IPC::PlatformFileForTransit& socket) { | 74 void set_socket(const IPC::PlatformFileForTransit& socket) { |
| 140 type_ = SOCKET; | 75 type_ = SOCKET; |
| 141 descriptor_ = socket; | 76 descriptor_ = socket; |
| 142 | 77 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 private: | 122 private: |
| 188 // The kind of handle we're holding. | 123 // The kind of handle we're holding. |
| 189 Type type_; | 124 Type type_; |
| 190 | 125 |
| 191 // We hold more members than we really need; we can't easily use a union, | 126 // We hold more members than we really need; we can't easily use a union, |
| 192 // because we hold non-POD types. But these types are pretty light-weight. If | 127 // because we hold non-POD types. But these types are pretty light-weight. If |
| 193 // we add more complex things later, we should come up with a more memory- | 128 // we add more complex things later, we should come up with a more memory- |
| 194 // efficient strategy. | 129 // efficient strategy. |
| 195 // These are valid if type == SHARED_MEMORY. | 130 // These are valid if type == SHARED_MEMORY. |
| 196 base::SharedMemoryHandle shm_handle_; | 131 base::SharedMemoryHandle shm_handle_; |
| 197 uint32_t size_; | 132 uint32 size_; |
| 198 | 133 |
| 199 // This is valid if type == SOCKET || type == CHANNEL_HANDLE. | 134 // This is valid if type == SOCKET || type == CHANNEL_HANDLE. |
| 200 IPC::PlatformFileForTransit descriptor_; | 135 IPC::PlatformFileForTransit descriptor_; |
| 201 }; | 136 }; |
| 202 | 137 |
| 203 struct PPPDecryptor_Buffer { | |
| 204 ppapi::HostResource resource; | |
| 205 uint32_t size; | |
| 206 base::SharedMemoryHandle handle; | |
| 207 }; | |
| 208 | |
| 209 #if defined(OS_WIN) | |
| 210 typedef HANDLE ImageHandle; | |
| 211 #elif defined(OS_MACOSX) || defined(OS_ANDROID) | |
| 212 typedef base::SharedMemoryHandle ImageHandle; | |
| 213 #else | |
| 214 // On X Windows this is a SysV shared memory key. | |
| 215 typedef int ImageHandle; | |
| 216 #endif | |
| 217 | |
| 218 } // namespace proxy | 138 } // namespace proxy |
| 219 } // namespace ppapi | 139 } // namespace ppapi |
| 220 | 140 |
| 221 #endif // PPAPI_PROXY_SERIALIZED_STRUCTS_H_ | 141 #endif // PPAPI_PROXY_SERIALIZED_HANDLES_H_ |
| OLD | NEW |