Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / proxy / ppp_pdf_proxy.cc
blob4b16dd6b66a4d12d307edb09d191174db7e18f7b
1 // Copyright 2014 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.
5 #include "ppapi/proxy/ppp_pdf_proxy.h"
7 #include "ppapi/proxy/host_dispatcher.h"
8 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/shared_impl/proxy_lock.h"
11 namespace ppapi {
12 namespace proxy {
14 namespace {
16 #if !defined(OS_NACL)
17 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
18 // This isn't implemented in the out of process case.
19 return PP_MakeUndefined();
22 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) {
23 bool clockwise = type == PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW;
24 HostDispatcher::GetForInstance(instance)->Send(
25 new PpapiMsg_PPPPdf_Rotate(API_ID_PPP_PDF, instance, clockwise));
28 PP_Bool GetPrintPresetOptionsFromDocument(
29 PP_Instance instance,
30 PP_PdfPrintPresetOptions_Dev* options) {
31 PP_Bool ret = PP_FALSE;
32 HostDispatcher::GetForInstance(instance)
33 ->Send(new PpapiMsg_PPPPdf_PrintPresetOptions(
34 API_ID_PPP_PDF, instance, options, &ret));
35 return ret;
38 const PPP_Pdf ppp_pdf_interface = {
39 &GetLinkAtPosition,
40 &Transform,
41 &GetPrintPresetOptionsFromDocument
43 #else
44 // The NaCl plugin doesn't need the host side interface - stub it out.
45 const PPP_Pdf ppp_pdf_interface = {};
46 #endif
48 } // namespace
50 PPP_Pdf_Proxy::PPP_Pdf_Proxy(Dispatcher* dispatcher)
51 : InterfaceProxy(dispatcher),
52 ppp_pdf_(NULL) {
53 if (dispatcher->IsPlugin()) {
54 ppp_pdf_ = static_cast<const PPP_Pdf*>(
55 dispatcher->local_get_interface()(PPP_PDF_INTERFACE));
59 PPP_Pdf_Proxy::~PPP_Pdf_Proxy() {
62 // static
63 const PPP_Pdf* PPP_Pdf_Proxy::GetProxyInterface() {
64 return &ppp_pdf_interface;
67 bool PPP_Pdf_Proxy::OnMessageReceived(const IPC::Message& msg) {
68 if (!dispatcher()->IsPlugin())
69 return false;
71 bool handled = true;
72 IPC_BEGIN_MESSAGE_MAP(PPP_Pdf_Proxy, msg)
73 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPdf_Rotate, OnPluginMsgRotate)
74 IPC_MESSAGE_HANDLER(PpapiMsg_PPPPdf_PrintPresetOptions,
75 OnPluginMsgPrintPresetOptions)
76 IPC_MESSAGE_UNHANDLED(handled = false)
77 IPC_END_MESSAGE_MAP()
78 return handled;
81 void PPP_Pdf_Proxy::OnPluginMsgRotate(PP_Instance instance, bool clockwise) {
82 PP_PrivatePageTransformType type = clockwise ?
83 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW :
84 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW;
85 if (ppp_pdf_)
86 CallWhileUnlocked(ppp_pdf_->Transform, instance, type);
89 void PPP_Pdf_Proxy::OnPluginMsgPrintPresetOptions(
90 PP_Instance instance,
91 PP_PdfPrintPresetOptions_Dev* options,
92 PP_Bool* result) {
93 if (ppp_pdf_) {
94 *result = CallWhileUnlocked(
95 ppp_pdf_->GetPrintPresetOptionsFromDocument, instance, options);
99 } // namespace proxy
100 } // namespace ppapi