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

Side by Side Diff: ppapi/proxy/ppp_printing_proxy.cc

Issue 9455083: Proxy the PPP_Printing interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « ppapi/proxy/ppp_printing_proxy.h ('k') | ppapi/shared_impl/api_id.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "ppapi/proxy/ppp_printing_proxy.h"
6
7 #include <string.h>
8
9 #include "ppapi/c/dev/ppp_printing_dev.h"
10 #include "ppapi/proxy/host_dispatcher.h"
11 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
14
15 namespace ppapi {
16 namespace proxy {
17
18 namespace {
19
20 uint32_t QuerySupportedFormats(PP_Instance instance) {
21 uint32_t result = 0;
22 HostDispatcher::GetForInstance(instance)->Send(
23 new PpapiMsg_PPPPrinting_QuerySupportedFormats(API_ID_PPP_PRINTING,
24 instance, &result));
25 return result;
26 }
27
28 int32_t Begin(PP_Instance instance,
29 const struct PP_PrintSettings_Dev* print_settings) {
30 // Settings is just serialized as a string.
31 std::string settings_string;
32 settings_string.resize(sizeof(PP_PrintSettings_Dev));
33 memcpy(&settings_string[0], print_settings, sizeof(PP_PrintSettings_Dev));
viettrungluu 2012/02/27 18:58:46 I suppose this is more aliasing-rules-correct than
34
35 int32_t result = 0;
36 HostDispatcher::GetForInstance(instance)->Send(
37 new PpapiMsg_PPPPrinting_Begin(API_ID_PPP_PRINTING, instance,
38 settings_string, &result));
39 return result;
40 }
41
42 PP_Resource PrintPages(PP_Instance instance,
43 const PP_PrintPageNumberRange_Dev* page_ranges,
44 uint32_t page_range_count) {
45 std::vector<PP_PrintPageNumberRange_Dev> pages;
viettrungluu 2012/02/27 18:58:46 You can just do: std::vector<...> pages(page_rang
46 for (uint32_t i = 0; i < page_range_count; i++)
47 pages.push_back(page_ranges[i]);
48
49 HostResource result;
50 HostDispatcher::GetForInstance(instance)->Send(
51 new PpapiMsg_PPPPrinting_PrintPages(API_ID_PPP_PRINTING,
52 instance, pages, &result));
53 return result.host_resource();
54 }
55
56 void End(PP_Instance instance) {
57 HostDispatcher::GetForInstance(instance)->Send(
58 new PpapiMsg_PPPPrinting_End(API_ID_PPP_PRINTING, instance));
59 }
60
61 PP_Bool IsScalingDisabled(PP_Instance instance) {
62 bool result = false;
63 HostDispatcher::GetForInstance(instance)->Send(
64 new PpapiMsg_PPPPrinting_IsScalingDisabled(API_ID_PPP_PRINTING,
65 instance, &result));
66 return PP_FromBool(result);
67 }
68
69 const PPP_Printing_Dev ppp_printing_interface = {
70 &QuerySupportedFormats,
71 &Begin,
72 &PrintPages,
73 &End,
74 &IsScalingDisabled
75 };
76
77 } // namespace
78
79 PPP_Printing_Proxy::PPP_Printing_Proxy(Dispatcher* dispatcher)
80 : InterfaceProxy(dispatcher),
81 ppp_printing_impl_(NULL) {
82 if (dispatcher->IsPlugin()) {
83 ppp_printing_impl_ = static_cast<const PPP_Printing_Dev*>(
84 dispatcher->local_get_interface()(PPP_PRINTING_DEV_INTERFACE));
85 }
86 }
87
88 PPP_Printing_Proxy::~PPP_Printing_Proxy() {
89 }
90
91 // static
92 const PPP_Printing_Dev* PPP_Printing_Proxy::GetProxyInterface() {
93 return &ppp_printing_interface;
94 }
95
96 bool PPP_Printing_Proxy::OnMessageReceived(const IPC::Message& msg) {
97 bool handled = true;
98 IPC_BEGIN_MESSAGE_MAP(PPP_Printing_Proxy, msg)
99 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPrinting_QuerySupportedFormats,
100 OnPluginMsgQuerySupportedFormats)
101 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPrinting_Begin,
102 OnPluginMsgBegin)
103 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPrinting_PrintPages,
104 OnPluginMsgPrintPages)
105 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPrinting_End,
106 OnPluginMsgEnd)
107 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPrinting_IsScalingDisabled,
108 OnPluginMsgIsScalingDisabled)
109 IPC_MESSAGE_UNHANDLED(handled = false)
110 IPC_END_MESSAGE_MAP()
111 return handled;
112 }
113
114 void PPP_Printing_Proxy::OnPluginMsgQuerySupportedFormats(PP_Instance instance,
115 uint32_t* result) {
116 if (ppp_printing_impl_)
117 *result = ppp_printing_impl_->QuerySupportedFormats(instance);
118 else
119 *result = 0;
120 }
121
122 void PPP_Printing_Proxy::OnPluginMsgBegin(PP_Instance instance,
123 const std::string& settings_string,
124 int32_t* result) {
125 *result = 0;
126
127 PP_PrintSettings_Dev settings;
128 if (settings_string.size() != sizeof(settings))
129 return;
130 memcpy(&settings, &settings_string[0], sizeof(settings));
131
132 if (ppp_printing_impl_)
133 ppp_printing_impl_->Begin(instance, &settings);
134 }
135
136 void PPP_Printing_Proxy::OnPluginMsgPrintPages(
137 PP_Instance instance,
138 const std::vector<PP_PrintPageNumberRange_Dev>& pages,
139 HostResource* result) {
140 if (ppp_printing_impl_ && !pages.empty()) {
141 result->SetHostResource(
142 instance,
143 ppp_printing_impl_->PrintPages(instance, &pages[0],
144 static_cast<uint32_t>(pages.size())));
145 }
146 }
147
148 void PPP_Printing_Proxy::OnPluginMsgEnd(PP_Instance instance) {
149 if (ppp_printing_impl_)
150 ppp_printing_impl_->End(instance);
151 }
152
153 void PPP_Printing_Proxy::OnPluginMsgIsScalingDisabled(PP_Instance instance,
154 bool* result) {
155 if (ppp_printing_impl_)
156 *result = PP_ToBool(ppp_printing_impl_->IsScalingDisabled(instance));
157 else
158 *result = false;
159 }
160
161 } // namespace proxy
162 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_printing_proxy.h ('k') | ppapi/shared_impl/api_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698