| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/proxy/serialized_structs.h" | 5 #include "ppapi/proxy/serialized_structs.h" |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/platform_file.h" | |
| 9 #include "base/shared_memory.h" | |
| 10 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 11 #include "ipc/ipc_platform_file.h" | |
| 12 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 13 #include "ppapi/c/pp_file_info.h" | 10 #include "ppapi/c/pp_file_info.h" |
| 14 #include "ppapi/c/pp_rect.h" | 11 #include "ppapi/c/pp_rect.h" |
| 15 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | 12 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" |
| 16 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
| 17 | 14 |
| 18 #if defined(OS_NACL) | |
| 19 #include <unistd.h> | |
| 20 #endif | |
| 21 | |
| 22 namespace ppapi { | 15 namespace ppapi { |
| 23 namespace proxy { | 16 namespace proxy { |
| 24 | 17 |
| 25 SerializedFontDescription::SerializedFontDescription() | 18 SerializedFontDescription::SerializedFontDescription() |
| 26 : face(), | 19 : face(), |
| 27 family(0), | 20 family(0), |
| 28 size(0), | 21 size(0), |
| 29 weight(0), | 22 weight(0), |
| 30 italic(PP_FALSE), | 23 italic(PP_FALSE), |
| 31 small_caps(PP_FALSE), | 24 small_caps(PP_FALSE), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 clip.point.y = 0; | 88 clip.point.y = 0; |
| 96 clip.size.height = 0; | 89 clip.size.height = 0; |
| 97 clip.size.width = 0; | 90 clip.size.width = 0; |
| 98 position.x = 0; | 91 position.x = 0; |
| 99 position.y = 0; | 92 position.y = 0; |
| 100 allow_subpixel_aa = PP_FALSE; | 93 allow_subpixel_aa = PP_FALSE; |
| 101 } | 94 } |
| 102 | 95 |
| 103 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {} | 96 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {} |
| 104 | 97 |
| 105 SerializedHandle::SerializedHandle() | |
| 106 : type_(INVALID), | |
| 107 shm_handle_(base::SharedMemory::NULLHandle()), | |
| 108 size_(0), | |
| 109 descriptor_(IPC::InvalidPlatformFileForTransit()) { | |
| 110 } | |
| 111 | |
| 112 SerializedHandle::SerializedHandle(Type type_param) | |
| 113 : type_(type_param), | |
| 114 shm_handle_(base::SharedMemory::NULLHandle()), | |
| 115 size_(0), | |
| 116 descriptor_(IPC::InvalidPlatformFileForTransit()) { | |
| 117 } | |
| 118 | |
| 119 SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle, | |
| 120 uint32_t size) | |
| 121 : type_(SHARED_MEMORY), | |
| 122 shm_handle_(handle), | |
| 123 size_(size), | |
| 124 descriptor_(IPC::InvalidPlatformFileForTransit()) { | |
| 125 } | |
| 126 | |
| 127 SerializedHandle::SerializedHandle( | |
| 128 Type type, | |
| 129 const IPC::PlatformFileForTransit& socket_descriptor) | |
| 130 : type_(type), | |
| 131 shm_handle_(base::SharedMemory::NULLHandle()), | |
| 132 size_(0), | |
| 133 descriptor_(socket_descriptor) { | |
| 134 } | |
| 135 | |
| 136 bool SerializedHandle::IsHandleValid() const { | |
| 137 switch (type_) { | |
| 138 case SHARED_MEMORY: | |
| 139 return base::SharedMemory::IsHandleValid(shm_handle_); | |
| 140 case SOCKET: | |
| 141 case CHANNEL_HANDLE: | |
| 142 case FILE: | |
| 143 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); | |
| 144 case INVALID: | |
| 145 return false; | |
| 146 // No default so the compiler will warn us if a new type is added. | |
| 147 } | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 void SerializedHandle::Close() { | |
| 152 if (IsHandleValid()) { | |
| 153 switch (type_) { | |
| 154 case INVALID: | |
| 155 NOTREACHED(); | |
| 156 break; | |
| 157 case SHARED_MEMORY: | |
| 158 base::SharedMemory::CloseHandle(shm_handle_); | |
| 159 break; | |
| 160 case SOCKET: | |
| 161 case CHANNEL_HANDLE: | |
| 162 case FILE: | |
| 163 base::PlatformFile file = | |
| 164 IPC::PlatformFileForTransitToPlatformFile(descriptor_); | |
| 165 #if !defined(OS_NACL) | |
| 166 base::ClosePlatformFile(file); | |
| 167 #else | |
| 168 close(file); | |
| 169 #endif | |
| 170 break; | |
| 171 // No default so the compiler will warn us if a new type is added. | |
| 172 } | |
| 173 } | |
| 174 *this = SerializedHandle(); | |
| 175 } | |
| 176 | |
| 177 // static | |
| 178 bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) { | |
| 179 if (!pickle->WriteInt(hdr.type)) | |
| 180 return false; | |
| 181 if (hdr.type == SHARED_MEMORY) { | |
| 182 if (!pickle->WriteUInt32(hdr.size)) | |
| 183 return false; | |
| 184 } | |
| 185 return true; | |
| 186 } | |
| 187 | |
| 188 // static | |
| 189 bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { | |
| 190 *hdr = Header(INVALID, 0); | |
| 191 int type = 0; | |
| 192 if (!iter->ReadInt(&type)) | |
| 193 return false; | |
| 194 bool valid_type = false; | |
| 195 switch (type) { | |
| 196 case SHARED_MEMORY: { | |
| 197 uint32_t size = 0; | |
| 198 if (!iter->ReadUInt32(&size)) | |
| 199 return false; | |
| 200 hdr->size = size; | |
| 201 valid_type = true; | |
| 202 break; | |
| 203 } | |
| 204 case SOCKET: | |
| 205 case CHANNEL_HANDLE: | |
| 206 case FILE: | |
| 207 case INVALID: | |
| 208 valid_type = true; | |
| 209 break; | |
| 210 // No default so the compiler will warn us if a new type is added. | |
| 211 } | |
| 212 if (valid_type) | |
| 213 hdr->type = Type(type); | |
| 214 return valid_type; | |
| 215 } | |
| 216 | |
| 217 } // namespace proxy | 98 } // namespace proxy |
| 218 } // namespace ppapi | 99 } // namespace ppapi |
| OLD | NEW |