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/flash_font_file_resource.h"
9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/proxy/ppapi_messages.h"
16 FlashFontFileResource::FlashFontFileResource(
17 Connection connection
,
19 const PP_BrowserFont_Trusted_Description
* description
,
20 PP_PrivateFontCharset charset
)
21 : PluginResource(connection
, instance
),
23 description_
.SetFromPPBrowserFontDescription(*description
);
26 FlashFontFileResource::~FlashFontFileResource() {
29 thunk::PPB_Flash_FontFile_API
*
30 FlashFontFileResource::AsPPB_Flash_FontFile_API() {
34 PP_Bool
FlashFontFileResource::GetFontTable(uint32_t table
,
36 uint32_t* output_length
) {
40 if (!sent_create_to_renderer()) {
42 RENDERER
, PpapiHostMsg_FlashFontFile_Create(description_
, charset_
));
45 std::string
* contents
= GetFontTable(table
);
47 std::string out_contents
;
48 int32_t result
= SyncCall
<PpapiPluginMsg_FlashFontFile_GetFontTableReply
>(
49 RENDERER
, PpapiHostMsg_FlashFontFile_GetFontTable(table
),
54 contents
= AddFontTable(table
, out_contents
);
57 // If we are going to copy the data into |output|, it must be big enough.
58 if (output
&& *output_length
< contents
->size())
61 *output_length
= static_cast<uint32_t>(contents
->size());
63 memcpy(output
, contents
->c_str(), *output_length
);
67 std::string
* FlashFontFileResource::GetFontTable(uint32_t table
) const {
68 FontTableMap::const_iterator found
= font_tables_
.find(table
);
69 if (found
== font_tables_
.end())
71 return found
->second
.get();
74 std::string
* FlashFontFileResource::AddFontTable(uint32_t table
,
75 const std::string
& contents
) {
76 linked_ptr
<std::string
> heap_string(new std::string(contents
));
77 font_tables_
[table
] = heap_string
;
78 return heap_string
.get();