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 #include "ppapi/proxy/serialized_structs.h" | 5 #include "ppapi/proxy/serialized_handle.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ipc/ipc_platform_file.h" | 11 #include "ipc/ipc_platform_file.h" |
12 #include "ppapi/c/dev/ppb_font_dev.h" | |
13 #include "ppapi/c/pp_file_info.h" | |
14 #include "ppapi/c/pp_rect.h" | |
15 #include "ppapi/c/trusted/ppb_browser_font_trusted.h" | |
16 #include "ppapi/shared_impl/var.h" | |
17 | 12 |
18 #if defined(OS_NACL) | 13 #if defined(OS_NACL) |
19 #include <unistd.h> | 14 #include <unistd.h> |
20 #endif | 15 #endif |
21 | 16 |
22 namespace ppapi { | 17 namespace ppapi { |
23 namespace proxy { | 18 namespace proxy { |
24 | 19 |
25 SerializedFontDescription::SerializedFontDescription() | |
26 : face(), | |
27 family(0), | |
28 size(0), | |
29 weight(0), | |
30 italic(PP_FALSE), | |
31 small_caps(PP_FALSE), | |
32 letter_spacing(0), | |
33 word_spacing(0) { | |
34 } | |
35 | |
36 SerializedFontDescription::~SerializedFontDescription() {} | |
37 | |
38 void SerializedFontDescription::SetFromPPFontDescription( | |
39 const PP_FontDescription_Dev& desc) { | |
40 StringVar* string_var = StringVar::FromPPVar(desc.face); | |
41 face = string_var ? string_var->value() : std::string(); | |
42 | |
43 family = desc.family; | |
44 size = desc.size; | |
45 weight = desc.weight; | |
46 italic = desc.italic; | |
47 small_caps = desc.small_caps; | |
48 letter_spacing = desc.letter_spacing; | |
49 word_spacing = desc.word_spacing; | |
50 } | |
51 | |
52 void SerializedFontDescription::SetFromPPBrowserFontDescription( | |
53 const PP_BrowserFont_Trusted_Description& desc) { | |
54 StringVar* string_var = StringVar::FromPPVar(desc.face); | |
55 face = string_var ? string_var->value() : std::string(); | |
56 | |
57 family = desc.family; | |
58 size = desc.size; | |
59 weight = desc.weight; | |
60 italic = desc.italic; | |
61 small_caps = desc.small_caps; | |
62 letter_spacing = desc.letter_spacing; | |
63 word_spacing = desc.word_spacing; | |
64 } | |
65 | |
66 void SerializedFontDescription::SetToPPFontDescription( | |
67 PP_FontDescription_Dev* desc) const { | |
68 desc->face = StringVar::StringToPPVar(face); | |
69 desc->family = static_cast<PP_FontFamily_Dev>(family); | |
70 desc->size = size; | |
71 desc->weight = static_cast<PP_FontWeight_Dev>(weight); | |
72 desc->italic = italic; | |
73 desc->small_caps = small_caps; | |
74 desc->letter_spacing = letter_spacing; | |
75 desc->word_spacing = word_spacing; | |
76 } | |
77 | |
78 void SerializedFontDescription::SetToPPBrowserFontDescription( | |
79 PP_BrowserFont_Trusted_Description* desc) const { | |
80 desc->face = StringVar::StringToPPVar(face); | |
81 desc->family = static_cast<PP_BrowserFont_Trusted_Family>(family); | |
82 desc->size = size; | |
83 desc->weight = static_cast<PP_BrowserFont_Trusted_Weight>(weight); | |
84 desc->italic = italic; | |
85 desc->small_caps = small_caps; | |
86 desc->letter_spacing = letter_spacing; | |
87 desc->word_spacing = word_spacing; | |
88 } | |
89 | |
90 PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params() | |
91 : instance(0), | |
92 font_desc(), | |
93 color(0) { | |
94 clip.point.x = 0; | |
95 clip.point.y = 0; | |
96 clip.size.height = 0; | |
97 clip.size.width = 0; | |
98 position.x = 0; | |
99 position.y = 0; | |
100 allow_subpixel_aa = PP_FALSE; | |
101 } | |
102 | |
103 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {} | |
104 | |
105 SerializedHandle::SerializedHandle() | 20 SerializedHandle::SerializedHandle() |
106 : type_(INVALID), | 21 : type_(INVALID), |
107 shm_handle_(base::SharedMemory::NULLHandle()), | 22 shm_handle_(base::SharedMemory::NULLHandle()), |
108 size_(0), | 23 size_(0), |
109 descriptor_(IPC::InvalidPlatformFileForTransit()) { | 24 descriptor_(IPC::InvalidPlatformFileForTransit()) { |
110 } | 25 } |
111 | 26 |
112 SerializedHandle::SerializedHandle(Type type_param) | 27 SerializedHandle::SerializedHandle(Type type_param) |
113 : type_(type_param), | 28 : type_(type_param), |
114 shm_handle_(base::SharedMemory::NULLHandle()), | 29 shm_handle_(base::SharedMemory::NULLHandle()), |
115 size_(0), | 30 size_(0), |
116 descriptor_(IPC::InvalidPlatformFileForTransit()) { | 31 descriptor_(IPC::InvalidPlatformFileForTransit()) { |
117 } | 32 } |
118 | 33 |
119 SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle, | 34 SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle, |
120 uint32_t size) | 35 uint32 size) |
121 : type_(SHARED_MEMORY), | 36 : type_(SHARED_MEMORY), |
122 shm_handle_(handle), | 37 shm_handle_(handle), |
123 size_(size), | 38 size_(size), |
124 descriptor_(IPC::InvalidPlatformFileForTransit()) { | 39 descriptor_(IPC::InvalidPlatformFileForTransit()) { |
125 } | 40 } |
126 | 41 |
127 SerializedHandle::SerializedHandle( | 42 SerializedHandle::SerializedHandle( |
128 Type type, | 43 Type type, |
129 const IPC::PlatformFileForTransit& socket_descriptor) | 44 const IPC::PlatformFileForTransit& socket_descriptor) |
130 : type_(type), | 45 : type_(type), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 102 |
188 // static | 103 // static |
189 bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { | 104 bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) { |
190 *hdr = Header(INVALID, 0); | 105 *hdr = Header(INVALID, 0); |
191 int type = 0; | 106 int type = 0; |
192 if (!iter->ReadInt(&type)) | 107 if (!iter->ReadInt(&type)) |
193 return false; | 108 return false; |
194 bool valid_type = false; | 109 bool valid_type = false; |
195 switch (type) { | 110 switch (type) { |
196 case SHARED_MEMORY: { | 111 case SHARED_MEMORY: { |
197 uint32_t size = 0; | 112 uint32 size = 0; |
198 if (!iter->ReadUInt32(&size)) | 113 if (!iter->ReadUInt32(&size)) |
199 return false; | 114 return false; |
200 hdr->size = size; | 115 hdr->size = size; |
201 valid_type = true; | 116 valid_type = true; |
202 break; | 117 break; |
203 } | 118 } |
204 case SOCKET: | 119 case SOCKET: |
205 case CHANNEL_HANDLE: | 120 case CHANNEL_HANDLE: |
206 case FILE: | 121 case FILE: |
207 case INVALID: | 122 case INVALID: |
208 valid_type = true; | 123 valid_type = true; |
209 break; | 124 break; |
210 // No default so the compiler will warn us if a new type is added. | 125 // No default so the compiler will warn us if a new type is added. |
211 } | 126 } |
212 if (valid_type) | 127 if (valid_type) |
213 hdr->type = Type(type); | 128 hdr->type = Type(type); |
214 return valid_type; | 129 return valid_type; |
215 } | 130 } |
216 | 131 |
217 } // namespace proxy | 132 } // namespace proxy |
218 } // namespace ppapi | 133 } // namespace ppapi |
OLD | NEW |