| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h" | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <sys/mman.h> | |
| 11 | |
| 12 #include "native_client/src/include/nacl_scoped_ptr.h" | |
| 13 #include "native_client/src/include/portability.h" | |
| 14 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | |
| 15 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" | |
| 16 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h" | |
| 17 #include "native_client/src/shared/ppapi_proxy/plugin_resource.h" | |
| 18 #include "native_client/src/shared/ppapi_proxy/utility.h" | |
| 19 #include "native_client/src/shared/srpc/nacl_srpc.h" | |
| 20 #include "ppapi/c/private/ppb_pdf.h" | |
| 21 #include "srpcgen/ppb_rpc.h" | |
| 22 | |
| 23 namespace ppapi_proxy { | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 const nacl_abi_size_t kPpbPrivateFindResultBytes = | |
| 28 static_cast<nacl_abi_size_t>(sizeof(PP_PrivateFindResult)); | |
| 29 // Limit the maximum result buffer size. | |
| 30 const nacl_abi_size_t kMaxFindResultsBytes = 65536; | |
| 31 const int32_t kMaxFindResults = | |
| 32 kMaxFindResultsBytes / kPpbPrivateFindResultBytes; | |
| 33 | |
| 34 PP_Var GetLocalizedString( | |
| 35 PP_Instance instance, | |
| 36 PP_ResourceString string_id) { | |
| 37 DebugPrintf("PPB_PDF::GetLocalizedString: " | |
| 38 "instance=%"NACL_PRId32"\n", instance); | |
| 39 | |
| 40 NaClSrpcChannel* channel = GetMainSrpcChannel(); | |
| 41 nacl_abi_size_t string_size = kMaxReturnVarSize; | |
| 42 nacl::scoped_array<char> string_bytes(new char[string_size]); | |
| 43 NaClSrpcError srpc_result = | |
| 44 PpbPdfRpcClient::PPB_PDF_GetLocalizedString( | |
| 45 channel, | |
| 46 instance, | |
| 47 static_cast<int32_t>(string_id), | |
| 48 &string_size, string_bytes.get()); | |
| 49 | |
| 50 PP_Var string = PP_MakeUndefined(); | |
| 51 if (srpc_result == NACL_SRPC_RESULT_OK) { | |
| 52 (void) DeserializeTo(string_bytes.get(), string_size, 1, &string); | |
| 53 } | |
| 54 | |
| 55 DebugPrintf("PPB_PDF::GetLocalizedString: %s\n", | |
| 56 NaClSrpcErrorString(srpc_result)); | |
| 57 return string; | |
| 58 } | |
| 59 | |
| 60 PP_Resource GetResourceImage(PP_Instance instance, | |
| 61 PP_ResourceImage image_id) { | |
| 62 DebugPrintf("PPB_PDF::GetResourceImage: " | |
| 63 "instance=%"NACL_PRId32"\n", instance); | |
| 64 | |
| 65 PP_Resource image = kInvalidResourceId; | |
| 66 NaClSrpcError srpc_result = | |
| 67 PpbPdfRpcClient::PPB_PDF_GetResourceImage( | |
| 68 GetMainSrpcChannel(), | |
| 69 instance, | |
| 70 static_cast<int32_t>(image_id), | |
| 71 &image); | |
| 72 | |
| 73 DebugPrintf("PPB_PDF::GetResourceImage: %s\n", | |
| 74 NaClSrpcErrorString(srpc_result)); | |
| 75 if (srpc_result == NACL_SRPC_RESULT_OK) { | |
| 76 scoped_refptr<PluginImageData> image_data = | |
| 77 PluginResource::AdoptAs<PluginImageData>(image); | |
| 78 if (image_data.get()) { | |
| 79 return image; | |
| 80 } | |
| 81 } | |
| 82 return kInvalidResourceId; | |
| 83 } | |
| 84 | |
| 85 PP_Resource GetFontFileWithFallback( | |
| 86 PP_Instance instance, | |
| 87 const struct PP_FontDescription_Dev* description, | |
| 88 PP_PrivateFontCharset charset) { | |
| 89 DebugPrintf("PPB_PDF::GetFontFileWithFallback: Not Implemented\n"); | |
| 90 return kInvalidResourceId; | |
| 91 } | |
| 92 | |
| 93 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | |
| 94 uint32_t table, | |
| 95 void* output, | |
| 96 uint32_t* output_length) { | |
| 97 DebugPrintf("PPB_PDF::GetFontTableForPrivateFontFile: Not Implemented\n"); | |
| 98 *output_length = 0; | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 nacl_abi_size_t utf16_length(const unsigned short* str) { | |
| 103 const unsigned short* s = str; | |
| 104 while (*s) | |
| 105 ++s; | |
| 106 return (s - str); | |
| 107 } | |
| 108 | |
| 109 void SearchString(PP_Instance instance, | |
| 110 const unsigned short* string, | |
| 111 const unsigned short* term, | |
| 112 bool case_sensitive, | |
| 113 struct PP_PrivateFindResult** results, | |
| 114 int* count) { | |
| 115 DebugPrintf("PPB_PDF::SearchString: instance=%"NACL_PRId32"\n", instance); | |
| 116 | |
| 117 CHECK(string != NULL); | |
| 118 CHECK(term != NULL); | |
| 119 CHECK(results != NULL); | |
| 120 CHECK(count != NULL); | |
| 121 | |
| 122 nacl_abi_size_t find_results_size = kMaxFindResultsBytes; | |
| 123 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc(find_results_size)); | |
| 124 *count = 0; | |
| 125 | |
| 126 nacl_abi_size_t string_length = utf16_length(string); | |
| 127 nacl_abi_size_t term_length = utf16_length(term); | |
| 128 if (string_length > 0 && term_length > 0) { | |
| 129 NaClSrpcError srpc_result = | |
| 130 PpbPdfRpcClient::PPB_PDF_SearchString( | |
| 131 GetMainSrpcChannel(), | |
| 132 instance, | |
| 133 (string_length + 1) * sizeof(unsigned short), // include NULL | |
| 134 reinterpret_cast<char*>(const_cast<unsigned short*>(string)), | |
| 135 (term_length + 1) * sizeof(unsigned short), // include NULL | |
| 136 reinterpret_cast<char*>(const_cast<unsigned short*>(term)), | |
| 137 static_cast<int32_t>(case_sensitive), | |
| 138 &find_results_size, | |
| 139 reinterpret_cast<char*>(*results), | |
| 140 reinterpret_cast<int32_t*>(count)); | |
| 141 | |
| 142 DebugPrintf("PPB_PDF::SearchString: %s\n", | |
| 143 NaClSrpcErrorString(srpc_result)); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 void DidStartLoading(PP_Instance instance) { | |
| 148 DebugPrintf("PPB_PDF::DidStartLoading: instance=%"NACL_PRId32"\n", | |
| 149 instance); | |
| 150 | |
| 151 NaClSrpcError srpc_result = | |
| 152 PpbPdfRpcClient::PPB_PDF_DidStartLoading(GetMainSrpcChannel(), | |
| 153 instance); | |
| 154 | |
| 155 DebugPrintf("PPB_PDF::DidStartLoading: %s\n", | |
| 156 NaClSrpcErrorString(srpc_result)); | |
| 157 } | |
| 158 | |
| 159 void DidStopLoading(PP_Instance instance) { | |
| 160 DebugPrintf("PPB_PDF::DidStopLoading: instance=%"NACL_PRId32"\n", | |
| 161 instance); | |
| 162 | |
| 163 NaClSrpcError srpc_result = | |
| 164 PpbPdfRpcClient::PPB_PDF_DidStopLoading(GetMainSrpcChannel(), | |
| 165 instance); | |
| 166 | |
| 167 DebugPrintf("PPB_PDF::DidStopLoading: %s\n", | |
| 168 NaClSrpcErrorString(srpc_result)); | |
| 169 } | |
| 170 | |
| 171 void SetContentRestriction(PP_Instance instance, | |
| 172 int restrictions) { | |
| 173 DebugPrintf("PPB_PDF::SetContentRestriction: instance=%"NACL_PRId32"\n", | |
| 174 instance); | |
| 175 | |
| 176 NaClSrpcError srpc_result = | |
| 177 PpbPdfRpcClient::PPB_PDF_SetContentRestriction(GetMainSrpcChannel(), | |
| 178 instance, | |
| 179 restrictions); | |
| 180 | |
| 181 DebugPrintf("PPB_PDF::SetContentRestriction: %s\n", | |
| 182 NaClSrpcErrorString(srpc_result)); | |
| 183 } | |
| 184 | |
| 185 void HistogramPDFPageCount(int count) { | |
| 186 DebugPrintf("PPB_PDF::HistogramPDFPageCount/n"); | |
| 187 | |
| 188 NaClSrpcError srpc_result = | |
| 189 PpbPdfRpcClient::PPB_PDF_HistogramPDFPageCount(GetMainSrpcChannel(), | |
| 190 count); | |
| 191 | |
| 192 DebugPrintf("PPB_PDF::HistogramPDFPageCount: %s\n", | |
| 193 NaClSrpcErrorString(srpc_result)); | |
| 194 } | |
| 195 | |
| 196 void UserMetricsRecordAction(struct PP_Var action) { | |
| 197 DebugPrintf("PPB_PDF::UserMetricsRecordAction\n"); | |
| 198 | |
| 199 nacl_abi_size_t action_size = 0; | |
| 200 nacl::scoped_array<char> action_bytes( | |
| 201 Serialize(&action, 1, &action_size)); | |
| 202 NaClSrpcError srpc_result = | |
| 203 PpbPdfRpcClient::PPB_PDF_UserMetricsRecordAction(GetMainSrpcChannel(), | |
| 204 action_size, | |
| 205 action_bytes.get()); | |
| 206 | |
| 207 DebugPrintf("PPB_PDF::UserMetricsRecordAction: %s\n", | |
| 208 NaClSrpcErrorString(srpc_result)); | |
| 209 } | |
| 210 | |
| 211 void HasUnsupportedFeature(PP_Instance instance) { | |
| 212 DebugPrintf("PPB_PDF::HasUnsupportedFeature: instance=%"NACL_PRId32"\n", | |
| 213 instance); | |
| 214 | |
| 215 NaClSrpcError srpc_result = | |
| 216 PpbPdfRpcClient::PPB_PDF_HasUnsupportedFeature(GetMainSrpcChannel(), | |
| 217 instance); | |
| 218 | |
| 219 DebugPrintf("PPB_PDF::HasUnsupportedFeature: %s\n", | |
| 220 NaClSrpcErrorString(srpc_result)); | |
| 221 } | |
| 222 | |
| 223 void SaveAs(PP_Instance instance) { | |
| 224 DebugPrintf("PPB_PDF::SaveAs: instance=%"NACL_PRId32"\n", instance); | |
| 225 | |
| 226 NaClSrpcError srpc_result = | |
| 227 PpbPdfRpcClient::PPB_PDF_SaveAs(GetMainSrpcChannel(), | |
| 228 instance); | |
| 229 | |
| 230 DebugPrintf("PPB_PDF::SaveAs: %s\n", NaClSrpcErrorString(srpc_result)); | |
| 231 } | |
| 232 | |
| 233 } // namespace | |
| 234 | |
| 235 const PPB_PDF* PluginPDF::GetInterface() { | |
| 236 static const PPB_PDF pdf_interface = { | |
| 237 GetLocalizedString, | |
| 238 GetResourceImage, | |
| 239 GetFontFileWithFallback, | |
| 240 GetFontTableForPrivateFontFile, | |
| 241 SearchString, | |
| 242 DidStartLoading, | |
| 243 DidStopLoading, | |
| 244 SetContentRestriction, | |
| 245 HistogramPDFPageCount, | |
| 246 UserMetricsRecordAction, | |
| 247 HasUnsupportedFeature, | |
| 248 SaveAs | |
| 249 }; | |
| 250 return &pdf_interface; | |
| 251 } | |
| 252 | |
| 253 } // namespace ppapi_proxy | |
| OLD | NEW |