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
3 // found in the LICENSE file.
5 #include "ppapi/proxy/serialized_structs.h"
7 #include "base/pickle.h"
8 #include "base/platform_file.h"
9 #include "base/shared_memory.h"
10 #include "build/build_config.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"
25 SerializedFontDescription::SerializedFontDescription()
36 SerializedFontDescription::~SerializedFontDescription() {}
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();
47 small_caps
= desc
.small_caps
;
48 letter_spacing
= desc
.letter_spacing
;
49 word_spacing
= desc
.word_spacing
;
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();
61 small_caps
= desc
.small_caps
;
62 letter_spacing
= desc
.letter_spacing
;
63 word_spacing
= desc
.word_spacing
;
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
);
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
;
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
);
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
;
90 PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params()
100 allow_subpixel_aa
= PP_FALSE
;
103 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {}
105 SerializedHandle::SerializedHandle()
107 shm_handle_(base::SharedMemory::NULLHandle()),
109 descriptor_(IPC::InvalidPlatformFileForTransit()) {
112 SerializedHandle::SerializedHandle(Type type_param
)
114 shm_handle_(base::SharedMemory::NULLHandle()),
116 descriptor_(IPC::InvalidPlatformFileForTransit()) {
119 SerializedHandle::SerializedHandle(const base::SharedMemoryHandle
& handle
,
121 : type_(SHARED_MEMORY
),
124 descriptor_(IPC::InvalidPlatformFileForTransit()) {
127 SerializedHandle::SerializedHandle(
129 const IPC::PlatformFileForTransit
& socket_descriptor
)
131 shm_handle_(base::SharedMemory::NULLHandle()),
133 descriptor_(socket_descriptor
) {
136 bool SerializedHandle::IsHandleValid() const {
139 return base::SharedMemory::IsHandleValid(shm_handle_
);
143 return !(IPC::InvalidPlatformFileForTransit() == descriptor_
);
146 // No default so the compiler will warn us if a new type is added.
151 void SerializedHandle::Close() {
152 if (IsHandleValid()) {
158 base::SharedMemory::CloseHandle(shm_handle_
);
163 base::PlatformFile file
=
164 IPC::PlatformFileForTransitToPlatformFile(descriptor_
);
165 #if !defined(OS_NACL)
166 base::ClosePlatformFile(file
);
171 // No default so the compiler will warn us if a new type is added.
174 *this = SerializedHandle();
178 bool SerializedHandle::WriteHeader(const Header
& hdr
, Pickle
* pickle
) {
179 if (!pickle
->WriteInt(hdr
.type
))
181 if (hdr
.type
== SHARED_MEMORY
) {
182 if (!pickle
->WriteUInt32(hdr
.size
))
189 bool SerializedHandle::ReadHeader(PickleIterator
* iter
, Header
* hdr
) {
190 *hdr
= Header(INVALID
, 0);
192 if (!iter
->ReadInt(&type
))
194 bool valid_type
= false;
196 case SHARED_MEMORY
: {
198 if (!iter
->ReadUInt32(&size
))
210 // No default so the compiler will warn us if a new type is added.
213 hdr
->type
= Type(type
);