Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_printing.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "native_client/src/shared/ppapi_proxy/browser_ppp_printing.h"
6
7 // Include file order cannot be observed because ppp_instance declares a
8 // structure return type that causes an error on Windows.
9 // TODO(sehr, brettw): fix the return types and include order in PPAPI.
10 #include "ppapi/c/pp_instance.h"
11 #include "ppapi/c/pp_resource.h"
12 #include "srpcgen/ppp_rpc.h"
13 #include "native_client/src/include/portability.h"
14 #include "native_client/src/shared/ppapi_proxy/browser_globals.h"
15 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
16 #include "native_client/src/shared/ppapi_proxy/utility.h"
17
18 namespace ppapi_proxy {
19
20 namespace {
21
22 const nacl_abi_size_t kPPPrintOutputFormatBytes =
23 static_cast<nacl_abi_size_t>(sizeof(PP_PrintOutputFormat_Dev));
24 const nacl_abi_size_t kPPPrintSettingsBytes =
25 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintSettings_Dev));
26 const nacl_abi_size_t kPPPrintPageNumberRangeBytes =
27 static_cast<nacl_abi_size_t>(sizeof(struct PP_PrintPageNumberRange_Dev));
28
29 PP_PrintOutputFormat_Dev* QuerySupportedFormats(PP_Instance instance,
30 uint32_t* format_count) {
31 DebugPrintf("PPP_Printing_Dev::QuerySupportedFormats: "
32 "instance=%"NACL_PRIu32"\n", instance);
33
34 const PPB_Memory_Dev* ppb_memory = PPBMemoryInterface();
35 const nacl_abi_size_t kMaxFormats = 8;
36 nacl_abi_size_t formats_bytes = kMaxFormats * kPPPrintOutputFormatBytes;
37 char* formats =
38 reinterpret_cast<char*>(ppb_memory->MemAlloc(formats_bytes));
39 NaClSrpcError srpc_result =
40 PppPrintingRpcClient::PPP_Printing_QuerySupportedFormats(
41 GetMainSrpcChannel(instance),
42 instance,
43 &formats_bytes, formats,
44 reinterpret_cast<int32_t*>(format_count));
45
46 DebugPrintf("PPP_Printing_Dev::QuerySupportedFormats: %s\n",
47 NaClSrpcErrorString(srpc_result));
48
49 if (*format_count > 0)
50 return reinterpret_cast<PP_PrintOutputFormat_Dev*>(formats);
51
52 ppb_memory->MemFree(formats);
53 return NULL;
54 }
55
56 int32_t Begin(PP_Instance instance,
57 const struct PP_PrintSettings_Dev* print_settings) {
58 DebugPrintf("PPP_Printing_Dev::Begin: instance=%"NACL_PRIu32"\n", instance);
59
60 int32_t pages_required = 0;
61 NaClSrpcError srpc_result =
62 PppPrintingRpcClient::PPP_Printing_Begin(
63 GetMainSrpcChannel(instance),
64 instance,
65 kPPPrintSettingsBytes,
66 reinterpret_cast<char*>(
67 const_cast<PP_PrintSettings_Dev*>(print_settings)),
68 &pages_required);
69
70 DebugPrintf("PPP_Printing_Dev::QuerySupportedFormats: %s\n",
71 NaClSrpcErrorString(srpc_result));
72 return pages_required;
73 }
74
75 PP_Resource PrintPages(PP_Instance instance,
76 const struct PP_PrintPageNumberRange_Dev* page_ranges,
77 uint32_t page_range_count) {
78 DebugPrintf("PPP_Printing_Dev::PrintPages: "
79 "instance=%"NACL_PRIu32"\n", instance);
80
81 PP_Resource image_data = kInvalidResourceId;
82 NaClSrpcError srpc_result =
83 PppPrintingRpcClient::PPP_Printing_PrintPages(
84 GetMainSrpcChannel(instance),
85 instance,
86 page_range_count * kPPPrintPageNumberRangeBytes,
87 reinterpret_cast<char*>(
88 const_cast<PP_PrintPageNumberRange_Dev*>(page_ranges)),
89 page_range_count,
90 &image_data);
91
92 DebugPrintf("PPP_Printing_Dev::QuerySupportedFormats: %s\n",
93 NaClSrpcErrorString(srpc_result));
94 return image_data;
95 }
96
97 void End(PP_Instance instance) {
98 DebugPrintf("PPP_Printing_Dev::End: instance=%"NACL_PRIu32"\n", instance);
99
100 NaClSrpcError srpc_result =
101 PppPrintingRpcClient::PPP_Printing_End(GetMainSrpcChannel(instance),
102 instance);
103
104 DebugPrintf("PPP_Printing_Dev::End: %s\n", NaClSrpcErrorString(srpc_result));
105 }
106
107 } // namespace
108
109 const PPP_Printing_Dev* BrowserPrinting::GetInterface() {
110 static const PPP_Printing_Dev printing_interface = {
111 QuerySupportedFormats,
112 Begin,
113 PrintPages,
114 End
115 };
116 return &printing_interface;
117 }
118
119 } // namespace ppapi_proxy
120
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698