OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2011 The Native Client 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 // SRPC-abstraction wrappers around PPP_Printing functions. | 5 // SRPC-abstraction wrappers around PPP_Printing functions. |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "native_client/src/include/portability.h" | 9 #include "native_client/src/include/portability.h" |
10 #include "native_client/src/include/portability_process.h" | 10 #include "native_client/src/include/portability_process.h" |
11 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" | 11 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" |
12 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" | 12 #include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h" |
elijahtaylor (use chromium)
2011/08/24 20:08:23
Same comment
| |
13 #include "native_client/src/shared/ppapi_proxy/utility.h" | 13 #include "native_client/src/shared/ppapi_proxy/utility.h" |
14 #include "native_client/src/third_party/ppapi/c/dev/ppp_printing_dev.h" | 14 #include "native_client/src/third_party/ppapi/c/dev/ppp_printing_dev.h" |
15 #include "native_client/src/third_party/ppapi/c/pp_resource.h" | 15 #include "native_client/src/third_party/ppapi/c/pp_resource.h" |
16 #include "native_client/src/third_party/ppapi/c/ppp.h" | 16 #include "native_client/src/third_party/ppapi/c/ppp.h" |
17 #include "srpcgen/ppp_rpc.h" | |
18 | 17 |
19 using ppapi_proxy::DebugPrintf; | 18 using ppapi_proxy::DebugPrintf; |
20 using ppapi_proxy::PPPPrintingInterface; | |
21 | 19 |
22 namespace { | 20 namespace { |
23 | 21 |
24 const nacl_abi_size_t kPPPrintOutputFormatBytes = | |
25 static_cast<nacl_abi_size_t>(sizeof(PP_PrintOutputFormat_Dev)); | |
26 const nacl_abi_size_t kPPPrintSettingsBytes = | 22 const nacl_abi_size_t kPPPrintSettingsBytes = |
27 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintSettings_Dev)); | 23 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintSettings_Dev)); |
28 const nacl_abi_size_t kPPPrintPageNumberRangeBytes = | 24 const nacl_abi_size_t kPPPrintPageNumberRangeBytes = |
29 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintPageNumberRange_Dev)); | 25 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintPageNumberRange_Dev)); |
30 | 26 |
27 const PPP_Printing_Dev* PPPPrinting() { | |
28 static const PPP_Printing_Dev* ppp_printing = NULL; | |
29 if (ppp_printing == NULL) { | |
30 ppp_printing = reinterpret_cast<const PPP_Printing_Dev*>( | |
31 ::PPP_GetInterface(PPP_PRINTING_DEV_INTERFACE)); | |
32 } | |
33 return ppp_printing; | |
34 } | |
elijahtaylor (use chromium)
2011/08/24 20:08:23
It looks like this is normally implemented in plug
| |
35 | |
31 } // namespace | 36 } // namespace |
32 | 37 |
33 void PppPrintingRpcServer::PPP_Printing_QuerySupportedFormats( | 38 void PppPrintingRpcServer::PPP_Printing_QuerySupportedFormats( |
34 NaClSrpcRpc* rpc, | 39 NaClSrpcRpc* rpc, |
35 NaClSrpcClosure* done, | 40 NaClSrpcClosure* done, |
36 // inputs | 41 // inputs |
37 PP_Instance instance, | 42 PP_Instance instance, |
38 // outputs | 43 // outputs |
39 nacl_abi_size_t* formats_bytes, char* formats, | 44 int32_t* formats) { |
40 int32_t* format_count) { | |
41 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 45 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
42 NaClSrpcClosureRunner runner(done); | 46 NaClSrpcClosureRunner runner(done); |
43 | 47 |
44 PP_PrintOutputFormat_Dev* pp_formats = | 48 const PPP_Printing_Dev* ppp_printing = PPPPrinting(); |
45 PPPPrintingInterface()->QuerySupportedFormats( | 49 if (ppp_printing == NULL || ppp_printing->QuerySupportedFormats == NULL) |
46 instance, | 50 return; |
47 reinterpret_cast<uint32_t*>(format_count)); | 51 uint32_t pp_formats = ppp_printing->QuerySupportedFormats(instance); |
48 if (pp_formats != NULL) { | 52 *formats = static_cast<int32_t>(pp_formats); |
49 nacl_abi_size_t formats_bytes_needed = | |
50 *format_count * kPPPrintOutputFormatBytes; | |
51 if (*formats_bytes >= formats_bytes_needed) { | |
52 *formats_bytes = formats_bytes_needed; | |
53 memcpy(pp_formats, formats, formats_bytes_needed); | |
54 } else { | |
55 *format_count = 0; | |
56 } | |
57 ppapi_proxy::PPBMemoryInterface()->MemFree(pp_formats); | |
58 } | |
59 | 53 |
60 DebugPrintf("PPP_Printing::QuerySupportedFormats: " | 54 DebugPrintf("PPP_Printing::QuerySupportedFormats: " |
61 "format_count=%"NACL_PRId32"\n", *format_count); | 55 "formats=%"NACL_PRId32"\n", *formats); |
62 rpc->result = NACL_SRPC_RESULT_OK; | 56 rpc->result = NACL_SRPC_RESULT_OK; |
63 } | 57 } |
64 | 58 |
65 void PppPrintingRpcServer::PPP_Printing_Begin( | 59 void PppPrintingRpcServer::PPP_Printing_Begin( |
66 NaClSrpcRpc* rpc, | 60 NaClSrpcRpc* rpc, |
67 NaClSrpcClosure* done, | 61 NaClSrpcClosure* done, |
68 // inputs | 62 // inputs |
69 PP_Instance instance, | 63 PP_Instance instance, |
70 nacl_abi_size_t print_settings_bytes, char* print_settings, | 64 nacl_abi_size_t print_settings_bytes, char* print_settings, |
71 // outputs | 65 // outputs |
72 int32_t* pages_required) { | 66 int32_t* pages_required) { |
73 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 67 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
74 NaClSrpcClosureRunner runner(done); | 68 NaClSrpcClosureRunner runner(done); |
75 | 69 |
70 const PPP_Printing_Dev* ppp_printing = PPPPrinting(); | |
71 if (ppp_printing == NULL || ppp_printing->Begin == NULL) | |
elijahtaylor (use chromium)
2011/08/24 20:08:23
If you follow the pattern from plugin_globals.cc,
dmichael (off chromium)
2011/08/24 21:21:30
Oops. I had the change in a git repo that was set
| |
72 return; | |
76 if (print_settings_bytes != sizeof(struct PP_PrintSettings_Dev)) | 73 if (print_settings_bytes != sizeof(struct PP_PrintSettings_Dev)) |
77 return; | 74 return; |
78 struct PP_PrintSettings_Dev* pp_print_settings = | 75 struct PP_PrintSettings_Dev* pp_print_settings = |
79 reinterpret_cast<struct PP_PrintSettings_Dev*>(print_settings); | 76 reinterpret_cast<struct PP_PrintSettings_Dev*>(print_settings); |
80 *pages_required = PPPPrintingInterface()->Begin(instance, pp_print_settings); | 77 *pages_required = ppp_printing->Begin(instance, pp_print_settings); |
81 | 78 |
82 DebugPrintf("PPP_Printing::Begin: pages_required=%"NACL_PRId32"\n", | 79 DebugPrintf("PPP_Printing::Begin: pages_required=%"NACL_PRId32"\n", |
83 *pages_required); | 80 *pages_required); |
84 rpc->result = NACL_SRPC_RESULT_OK; | 81 rpc->result = NACL_SRPC_RESULT_OK; |
85 } | 82 } |
86 | 83 |
87 void PppPrintingRpcServer::PPP_Printing_PrintPages( | 84 void PppPrintingRpcServer::PPP_Printing_PrintPages( |
88 NaClSrpcRpc* rpc, | 85 NaClSrpcRpc* rpc, |
89 NaClSrpcClosure* done, | 86 NaClSrpcClosure* done, |
90 // inputs | 87 // inputs |
91 PP_Instance instance, | 88 PP_Instance instance, |
92 nacl_abi_size_t page_ranges_bytes, char* page_ranges, | 89 nacl_abi_size_t page_ranges_bytes, char* page_ranges, |
93 int32_t page_range_count, | 90 int32_t page_range_count, |
94 // outputs | 91 // outputs |
95 PP_Resource* image_data) { | 92 PP_Resource* image_data) { |
96 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 93 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
97 NaClSrpcClosureRunner runner(done); | 94 NaClSrpcClosureRunner runner(done); |
98 | 95 |
96 const PPP_Printing_Dev* ppp_printing = PPPPrinting(); | |
97 if (ppp_printing == NULL || ppp_printing->PrintPages == NULL) | |
98 return; | |
elijahtaylor (use chromium)
2011/08/24 20:08:23
same
| |
99 if (page_ranges_bytes < kPPPrintPageNumberRangeBytes * page_range_count) | 99 if (page_ranges_bytes < kPPPrintPageNumberRangeBytes * page_range_count) |
100 return; | 100 return; |
101 struct PP_PrintPageNumberRange_Dev* pp_page_ranges = | 101 struct PP_PrintPageNumberRange_Dev* pp_page_ranges = |
102 reinterpret_cast<struct PP_PrintPageNumberRange_Dev*>(page_ranges); | 102 reinterpret_cast<struct PP_PrintPageNumberRange_Dev*>(page_ranges); |
103 *image_data = PPPPrintingInterface()->PrintPages(instance, | 103 *image_data = ppp_printing->PrintPages(instance, |
104 pp_page_ranges, | 104 pp_page_ranges, |
105 page_range_count); | 105 page_range_count); |
106 | 106 |
107 DebugPrintf("PPP_Printing::PrintPages: image_data=%"NACL_PRIu32"\n", | 107 DebugPrintf("PPP_Printing::PrintPages: image_data=%"NACL_PRIu32"\n", |
108 *image_data); | 108 *image_data); |
109 rpc->result = NACL_SRPC_RESULT_OK; | 109 rpc->result = NACL_SRPC_RESULT_OK; |
110 } | 110 } |
111 | 111 |
112 void PppPrintingRpcServer::PPP_Printing_End( | 112 void PppPrintingRpcServer::PPP_Printing_End( |
113 NaClSrpcRpc* rpc, | 113 NaClSrpcRpc* rpc, |
114 NaClSrpcClosure* done, | 114 NaClSrpcClosure* done, |
115 // inputs | 115 // inputs |
116 PP_Instance instance) { | 116 PP_Instance instance) { |
117 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 117 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
118 NaClSrpcClosureRunner runner(done); | 118 NaClSrpcClosureRunner runner(done); |
119 | 119 |
120 PPPPrintingInterface()->End(instance); | 120 const PPP_Printing_Dev* ppp_printing = PPPPrinting(); |
121 if (ppp_printing == NULL || ppp_printing->End == NULL) | |
122 return; | |
elijahtaylor (use chromium)
2011/08/24 20:08:23
same
| |
123 ppp_printing->End(instance); | |
121 | 124 |
122 DebugPrintf("PPP_Printing::End\n"); | 125 DebugPrintf("PPP_Printing::End\n"); |
123 rpc->result = NACL_SRPC_RESULT_OK; | 126 rpc->result = NACL_SRPC_RESULT_OK; |
124 } | 127 } |
128 | |
OLD | NEW |