OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ppapi/c/private/ppb_pdf.h" | 14 #include "ppapi/c/private/ppb_pdf.h" |
15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
16 #include "ppapi/proxy/plugin_resource_tracker.h" | 16 #include "ppapi/proxy/plugin_resource_tracker.h" |
17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
| 18 #include "ppapi/shared_impl/ppapi_globals.h" |
| 19 #include "ppapi/shared_impl/proxy_lock.h" |
| 20 #include "ppapi/shared_impl/var_tracker.h" |
18 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
19 #include "ppapi/thunk/ppb_pdf_api.h" | 22 #include "ppapi/thunk/ppb_pdf_api.h" |
20 | 23 |
21 using ppapi::thunk::PPB_PDFFont_API; | 24 using ppapi::thunk::PPB_PDFFont_API; |
22 using ppapi::thunk::EnterResource; | 25 using ppapi::thunk::EnterResource; |
23 | 26 |
24 namespace ppapi { | 27 namespace ppapi { |
25 namespace proxy { | 28 namespace proxy { |
26 | 29 |
27 class PrivateFontFile : public Resource, | 30 class PrivateFontFile : public Resource, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 font_tables_[table] = heap_string; | 63 font_tables_[table] = heap_string; |
61 return heap_string.get(); | 64 return heap_string.get(); |
62 } | 65 } |
63 | 66 |
64 namespace { | 67 namespace { |
65 | 68 |
66 PP_Resource GetFontFileWithFallback( | 69 PP_Resource GetFontFileWithFallback( |
67 PP_Instance instance, | 70 PP_Instance instance, |
68 const PP_FontDescription_Dev* description, | 71 const PP_FontDescription_Dev* description, |
69 PP_PrivateFontCharset charset) { | 72 PP_PrivateFontCharset charset) { |
| 73 ProxyAutoLock lock; |
| 74 |
70 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 75 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
71 if (!dispatcher) | 76 if (!dispatcher) |
72 return 0; | 77 return 0; |
73 | 78 |
74 SerializedFontDescription desc; | 79 SerializedFontDescription desc; |
75 desc.SetFromPPFontDescription(dispatcher, *description, true); | 80 desc.SetFromPPFontDescription(*description); |
76 | 81 |
77 HostResource result; | 82 HostResource result; |
78 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( | 83 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( |
79 API_ID_PPB_PDF, instance, desc, charset, &result)); | 84 API_ID_PPB_PDF, instance, desc, charset, &result)); |
80 if (result.is_null()) | 85 if (result.is_null()) |
81 return 0; | 86 return 0; |
82 return (new PrivateFontFile(result))->GetReference(); | 87 return (new PrivateFontFile(result))->GetReference(); |
83 } | 88 } |
84 | 89 |
85 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 90 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // TODO(brettw): handle bad messages! | 166 // TODO(brettw): handle bad messages! |
162 return handled; | 167 return handled; |
163 } | 168 } |
164 | 169 |
165 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( | 170 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( |
166 PP_Instance instance, | 171 PP_Instance instance, |
167 const SerializedFontDescription& in_desc, | 172 const SerializedFontDescription& in_desc, |
168 int32_t charset, | 173 int32_t charset, |
169 HostResource* result) { | 174 HostResource* result) { |
170 PP_FontDescription_Dev desc; | 175 PP_FontDescription_Dev desc; |
171 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); | 176 in_desc.SetToPPFontDescription(&desc); |
172 result->SetHostResource(instance, | 177 result->SetHostResource(instance, |
173 ppb_pdf_impl_->GetFontFileWithFallback( | 178 ppb_pdf_impl_->GetFontFileWithFallback( |
174 instance, &desc, static_cast<PP_PrivateFontCharset>(charset))); | 179 instance, &desc, static_cast<PP_PrivateFontCharset>(charset))); |
| 180 |
| 181 // SetToPPFontDescription() creates a var which is owned by the caller. |
| 182 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(desc.face); |
175 } | 183 } |
176 | 184 |
177 void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile( | 185 void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile( |
178 const HostResource& font_file, | 186 const HostResource& font_file, |
179 uint32_t table, | 187 uint32_t table, |
180 std::string* result) { | 188 std::string* result) { |
181 // TODO(brettw): It would be nice not to copy here. At least on Linux, | 189 // TODO(brettw): It would be nice not to copy here. At least on Linux, |
182 // we can map the font file into shared memory and read it that way. | 190 // we can map the font file into shared memory and read it that way. |
183 uint32_t table_length = 0; | 191 uint32_t table_length = 0; |
184 if (!ppb_pdf_impl_->GetFontTableForPrivateFontFile( | 192 if (!ppb_pdf_impl_->GetFontTableForPrivateFontFile( |
185 font_file.host_resource(), table, NULL, &table_length)) | 193 font_file.host_resource(), table, NULL, &table_length)) |
186 return; | 194 return; |
187 | 195 |
188 result->resize(table_length); | 196 result->resize(table_length); |
189 ppb_pdf_impl_->GetFontTableForPrivateFontFile(font_file.host_resource(), | 197 ppb_pdf_impl_->GetFontTableForPrivateFontFile(font_file.host_resource(), |
190 table, const_cast<char*>(result->c_str()), &table_length); | 198 table, const_cast<char*>(result->c_str()), &table_length); |
191 } | 199 } |
192 | 200 |
193 } // namespace proxy | 201 } // namespace proxy |
194 } // namespace ppapi | 202 } // namespace ppapi |
OLD | NEW |