Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ppapi / proxy / flash_font_file_resource.cc
blob659aa652bd94ae36809ea97673df61debcfe6ff6
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"
7 #include <cstring>
9 #include "ppapi/c/dev/ppb_font_dev.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/proxy/ppapi_messages.h"
13 namespace ppapi {
14 namespace proxy {
16 FlashFontFileResource::FlashFontFileResource(
17 Connection connection,
18 PP_Instance instance,
19 const PP_BrowserFont_Trusted_Description* description,
20 PP_PrivateFontCharset charset)
21 : PluginResource(connection, instance),
22 charset_(charset) {
23 description_.SetFromPPBrowserFontDescription(*description);
26 FlashFontFileResource::~FlashFontFileResource() {
29 thunk::PPB_Flash_FontFile_API*
30 FlashFontFileResource::AsPPB_Flash_FontFile_API() {
31 return this;
34 PP_Bool FlashFontFileResource::GetFontTable(uint32_t table,
35 void* output,
36 uint32_t* output_length) {
37 if (!output_length)
38 return PP_FALSE;
40 if (!sent_create_to_renderer()) {
41 SendCreate(
42 RENDERER, PpapiHostMsg_FlashFontFile_Create(description_, charset_));
45 const std::string* contents = GetFontTable(table);
46 if (!contents) {
47 std::string out_contents;
48 int32_t result = SyncCall<PpapiPluginMsg_FlashFontFile_GetFontTableReply>(
49 RENDERER, PpapiHostMsg_FlashFontFile_GetFontTable(table),
50 &out_contents);
51 if (result != PP_OK)
52 return PP_FALSE;
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())
59 return PP_FALSE;
61 *output_length = static_cast<uint32_t>(contents->size());
62 if (output)
63 memcpy(output, contents->c_str(), *output_length);
64 return PP_TRUE;
67 const std::string* FlashFontFileResource::GetFontTable(uint32_t table) const {
68 FontTableMap::const_iterator found = font_tables_.find(table);
69 return (found != font_tables_.end()) ? found->second : nullptr;
72 const std::string* FlashFontFileResource::AddFontTable(
73 uint32_t table,
74 const std::string& contents) {
75 FontTableMap::const_iterator it =
76 font_tables_.set(table, make_scoped_ptr(new std::string(contents)));
77 return it->second;
80 } // namespace proxy
81 } // namespace ppapi