OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ppb_pdf_proxy.h" | 5 #include "ppapi/proxy/ppb_pdf_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy. | 7 #include <string.h> // For memcpy. |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/linked_ptr.h" | 11 #include "base/linked_ptr.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource.h" | 15 #include "ppapi/proxy/plugin_resource.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "webkit/glue/plugins/ppb_private.h" | 17 #include "webkit/plugins/ppapi/ppb_pdf.h" |
18 | 18 |
19 namespace pp { | 19 namespace pp { |
20 namespace proxy { | 20 namespace proxy { |
21 | 21 |
22 class PrivateFontFile : public PluginResource { | 22 class PrivateFontFile : public PluginResource { |
23 public: | 23 public: |
24 PrivateFontFile() {} | 24 PrivateFontFile() {} |
25 virtual ~PrivateFontFile() {} | 25 virtual ~PrivateFontFile() {} |
26 | 26 |
27 // Resource overrides. | 27 // Resource overrides. |
(...skipping 30 matching lines...) Expand all Loading... |
58 | 58 |
59 PP_Resource GetFontFileWithFallback( | 59 PP_Resource GetFontFileWithFallback( |
60 PP_Module module_id, | 60 PP_Module module_id, |
61 const PP_FontDescription_Dev* description, | 61 const PP_FontDescription_Dev* description, |
62 PP_PrivateFontCharset charset) { | 62 PP_PrivateFontCharset charset) { |
63 PluginDispatcher* dispatcher = PluginDispatcher::Get(); | 63 PluginDispatcher* dispatcher = PluginDispatcher::Get(); |
64 SerializedFontDescription desc; | 64 SerializedFontDescription desc; |
65 desc.SetFromPPFontDescription(dispatcher, *description, true); | 65 desc.SetFromPPFontDescription(dispatcher, *description, true); |
66 | 66 |
67 PP_Resource result = 0; | 67 PP_Resource result = 0; |
68 dispatcher->Send(new PpapiHostMsg_PPBPdf_GetFontFileWithFallback( | 68 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( |
69 INTERFACE_ID_PPB_PDF, module_id, desc, charset, &result)); | 69 INTERFACE_ID_PPB_PDF, module_id, desc, charset, &result)); |
70 if (!result) | 70 if (!result) |
71 return 0; | 71 return 0; |
72 | 72 |
73 linked_ptr<PrivateFontFile> object(new PrivateFontFile); | 73 linked_ptr<PrivateFontFile> object(new PrivateFontFile); |
74 dispatcher->plugin_resource_tracker()->AddResource(result, object); | 74 dispatcher->plugin_resource_tracker()->AddResource(result, object); |
75 return result; | 75 return result; |
76 } | 76 } |
77 | 77 |
78 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 78 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
79 uint32_t table, | 79 uint32_t table, |
80 void* output, | 80 void* output, |
81 uint32_t* output_length) { | 81 uint32_t* output_length) { |
82 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); | 82 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); |
83 if (!object) | 83 if (!object) |
84 return false; | 84 return false; |
85 | 85 |
86 std::string* contents = object->GetFontTable(table); | 86 std::string* contents = object->GetFontTable(table); |
87 if (!contents) { | 87 if (!contents) { |
88 std::string deserialized; | 88 std::string deserialized; |
89 PluginDispatcher::Get()->Send( | 89 PluginDispatcher::Get()->Send( |
90 new PpapiHostMsg_PPBPdf_GetFontTableForPrivateFontFile( | 90 new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( |
91 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); | 91 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); |
92 if (deserialized.empty()) | 92 if (deserialized.empty()) |
93 return false; | 93 return false; |
94 contents = object->AddFontTable(table, deserialized); | 94 contents = object->AddFontTable(table, deserialized); |
95 } | 95 } |
96 | 96 |
97 *output_length = static_cast<uint32_t>(contents->size()); | 97 *output_length = static_cast<uint32_t>(contents->size()); |
98 if (output) | 98 if (output) |
99 memcpy(output, contents->c_str(), *output_length); | 99 memcpy(output, contents->c_str(), *output_length); |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 const PPB_Private ppb_private = { | 103 const PPB_PDF ppb_pdf = { |
104 NULL, // &GetLocalizedString, | 104 NULL, // &GetLocalizedString, |
105 NULL, // &GetResourceImage, | 105 NULL, // &GetResourceImage, |
106 &GetFontFileWithFallback, | 106 &GetFontFileWithFallback, |
107 &GetFontTableForPrivateFontFile, | 107 &GetFontTableForPrivateFontFile, |
108 }; | 108 }; |
109 | 109 |
110 } // namespace | 110 } // namespace |
111 | 111 |
112 PPB_Pdf_Proxy::PPB_Pdf_Proxy(Dispatcher* dispatcher, | 112 PPB_PDF_Proxy::PPB_PDF_Proxy(Dispatcher* dispatcher, |
113 const void* target_interface) | 113 const void* target_interface) |
114 : InterfaceProxy(dispatcher, target_interface) { | 114 : InterfaceProxy(dispatcher, target_interface) { |
115 } | 115 } |
116 | 116 |
117 PPB_Pdf_Proxy::~PPB_Pdf_Proxy() { | 117 PPB_PDF_Proxy::~PPB_PDF_Proxy() { |
118 } | 118 } |
119 | 119 |
120 const void* PPB_Pdf_Proxy::GetSourceInterface() const { | 120 const void* PPB_PDF_Proxy::GetSourceInterface() const { |
121 return &ppb_private; | 121 return &ppb_pdf; |
122 } | 122 } |
123 | 123 |
124 InterfaceID PPB_Pdf_Proxy::GetInterfaceId() const { | 124 InterfaceID PPB_PDF_Proxy::GetInterfaceId() const { |
125 return INTERFACE_ID_PPB_PDF; | 125 return INTERFACE_ID_PPB_PDF; |
126 } | 126 } |
127 | 127 |
128 void PPB_Pdf_Proxy::OnMessageReceived(const IPC::Message& msg) { | 128 void PPB_PDF_Proxy::OnMessageReceived(const IPC::Message& msg) { |
129 IPC_BEGIN_MESSAGE_MAP(PPB_Pdf_Proxy, msg) | 129 IPC_BEGIN_MESSAGE_MAP(PPB_PDF_Proxy, msg) |
130 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPdf_GetFontFileWithFallback, | 130 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPDF_GetFontFileWithFallback, |
131 OnMsgGetFontFileWithFallback) | 131 OnMsgGetFontFileWithFallback) |
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPdf_GetFontTableForPrivateFontFile, | 132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile, |
133 OnMsgGetFontTableForPrivateFontFile) | 133 OnMsgGetFontTableForPrivateFontFile) |
134 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
135 // TODO(brettw): handle bad messages! | 135 // TODO(brettw): handle bad messages! |
136 } | 136 } |
137 | 137 |
138 void PPB_Pdf_Proxy::OnMsgGetFontFileWithFallback( | 138 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( |
139 PP_Module module, | 139 PP_Module module, |
140 const SerializedFontDescription& in_desc, | 140 const SerializedFontDescription& in_desc, |
141 int32_t charset, | 141 int32_t charset, |
142 PP_Resource* result) { | 142 PP_Resource* result) { |
143 PP_FontDescription_Dev desc; | 143 PP_FontDescription_Dev desc; |
144 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); | 144 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); |
145 *result = ppb_pdf_target()->GetFontFileWithFallback(module, &desc, | 145 *result = ppb_pdf_target()->GetFontFileWithFallback(module, &desc, |
146 static_cast<PP_PrivateFontCharset>(charset)); | 146 static_cast<PP_PrivateFontCharset>(charset)); |
147 } | 147 } |
148 | 148 |
149 void PPB_Pdf_Proxy::OnMsgGetFontTableForPrivateFontFile(PP_Resource font_file, | 149 void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile(PP_Resource font_file, |
150 uint32_t table, | 150 uint32_t table, |
151 std::string* result) { | 151 std::string* result) { |
152 // TODO(brettw): It would be nice not to copy here. At least on Linux, | 152 // TODO(brettw): It would be nice not to copy here. At least on Linux, |
153 // we can map the font file into shared memory and read it that way. | 153 // we can map the font file into shared memory and read it that way. |
154 uint32_t table_length = 0; | 154 uint32_t table_length = 0; |
155 if (!ppb_pdf_target()->GetFontTableForPrivateFontFile( | 155 if (!ppb_pdf_target()->GetFontTableForPrivateFontFile( |
156 font_file, table, NULL, &table_length)) | 156 font_file, table, NULL, &table_length)) |
157 return; | 157 return; |
158 | 158 |
159 result->resize(table_length); | 159 result->resize(table_length); |
160 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table, | 160 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table, |
161 const_cast<char*>(result->c_str()), &table_length); | 161 const_cast<char*>(result->c_str()), &table_length); |
162 } | 162 } |
163 | 163 |
164 } // namespace proxy | 164 } // namespace proxy |
165 } // namespace pp | 165 } // namespace pp |
OLD | NEW |