1 // Copyright (c) 2013 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/cpp/private/pdf.h"
6
7 #include "ppapi/c/trusted/ppb_browser_font_trusted.h"
8 #include "ppapi/cpp/image_data.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h"
12
13 namespace pp {
14
15 namespace {
16
interface_name()17 template <> const char* interface_name<PPB_PDF>() {
18 return PPB_PDF_INTERFACE;
19 }
20
21 } // namespace
22
23 // static
IsAvailable()24 bool PDF::IsAvailable() {
25 return has_interface<PPB_PDF>();
26 }
27
28 // static
GetLocalizedString(const InstanceHandle & instance,PP_ResourceString string_id)29 Var PDF::GetLocalizedString(const InstanceHandle& instance,
30 PP_ResourceString string_id) {
31 if (has_interface<PPB_PDF>()) {
32 return Var(PASS_REF,
33 get_interface<PPB_PDF>()->GetLocalizedString(
34 instance.pp_instance(), string_id));
35 }
36 return Var();
37 }
38
39 // static
GetResourceImage(const InstanceHandle & instance,PP_ResourceImage image_id)40 ImageData PDF::GetResourceImage(const InstanceHandle& instance,
41 PP_ResourceImage image_id) {
42 if (has_interface<PPB_PDF>()) {
43 return ImageData(PASS_REF,
44 get_interface<PPB_PDF>()->GetResourceImage(
45 instance.pp_instance(), image_id));
46 }
47 return ImageData();
48 }
49
50 // static
GetFontFileWithFallback(const InstanceHandle & instance,const PP_FontDescription_Dev * description,PP_PrivateFontCharset charset)51 PP_Resource PDF::GetFontFileWithFallback(
52 const InstanceHandle& instance,
53 const PP_FontDescription_Dev* description,
54 PP_PrivateFontCharset charset) {
55 if (has_interface<PPB_PDF>()) {
56 PP_BrowserFont_Trusted_Description converted_desc;
57 converted_desc.face = description->face;
58 converted_desc.family = static_cast<PP_BrowserFont_Trusted_Family>(
59 description->family);
60 converted_desc.size = description->size;
61 converted_desc.weight = static_cast<PP_BrowserFont_Trusted_Weight>(
62 description->weight);
63 converted_desc.italic = description->italic;
64 converted_desc.small_caps = description->small_caps;
65 converted_desc.letter_spacing = description->letter_spacing;
66 converted_desc.word_spacing = description->word_spacing;
67 return get_interface<PPB_PDF>()->GetFontFileWithFallback(
68 instance.pp_instance(), &converted_desc, charset);
69 }
70 return 0;
71 }
72
73 // static
GetFontFileWithFallback(const InstanceHandle & instance,const PP_BrowserFont_Trusted_Description * description,PP_PrivateFontCharset charset)74 PP_Resource PDF::GetFontFileWithFallback(
75 const InstanceHandle& instance,
76 const PP_BrowserFont_Trusted_Description* description,
77 PP_PrivateFontCharset charset) {
78 if (has_interface<PPB_PDF>()) {
79 return get_interface<PPB_PDF>()->GetFontFileWithFallback(
80 instance.pp_instance(), description, charset);
81 }
82 return 0;
83 }
84
85 // static
GetFontTableForPrivateFontFile(PP_Resource font_file,uint32_t table,void * output,uint32_t * output_length)86 bool PDF::GetFontTableForPrivateFontFile(PP_Resource font_file,
87 uint32_t table,
88 void* output,
89 uint32_t* output_length) {
90 if (has_interface<PPB_PDF>()) {
91 return get_interface<PPB_PDF>()->GetFontTableForPrivateFontFile(font_file,
92 table, output, output_length);
93 }
94 return false;
95 }
96
97 // static
SearchString(const InstanceHandle & instance,const unsigned short * string,const unsigned short * term,bool case_sensitive,PP_PrivateFindResult ** results,int * count)98 void PDF::SearchString(const InstanceHandle& instance,
99 const unsigned short* string,
100 const unsigned short* term,
101 bool case_sensitive,
102 PP_PrivateFindResult** results,
103 int* count) {
104 if (has_interface<PPB_PDF>()) {
105 get_interface<PPB_PDF>()->SearchString(instance.pp_instance(), string,
106 term, case_sensitive, results, count);
107 }
108 }
109
110 // static
DidStartLoading(const InstanceHandle & instance)111 void PDF::DidStartLoading(const InstanceHandle& instance) {
112 if (has_interface<PPB_PDF>())
113 get_interface<PPB_PDF>()->DidStartLoading(instance.pp_instance());
114 }
115
116 // static
DidStopLoading(const InstanceHandle & instance)117 void PDF::DidStopLoading(const InstanceHandle& instance) {
118 if (has_interface<PPB_PDF>())
119 get_interface<PPB_PDF>()->DidStopLoading(instance.pp_instance());
120 }
121
122 // static
SetContentRestriction(const InstanceHandle & instance,int restrictions)123 void PDF::SetContentRestriction(const InstanceHandle& instance,
124 int restrictions) {
125 if (has_interface<PPB_PDF>()) {
126 get_interface<PPB_PDF>()->SetContentRestriction(instance.pp_instance(),
127 restrictions);
128 }
129 }
130
131 // static
HistogramPDFPageCount(const InstanceHandle & instance,int count)132 void PDF::HistogramPDFPageCount(const InstanceHandle& instance,
133 int count) {
134 if (has_interface<PPB_PDF>())
135 get_interface<PPB_PDF>()->HistogramPDFPageCount(instance.pp_instance(),
136 count);
137 }
138
139 // static
UserMetricsRecordAction(const InstanceHandle & instance,const Var & action)140 void PDF::UserMetricsRecordAction(const InstanceHandle& instance,
141 const Var& action) {
142 if (has_interface<PPB_PDF>()) {
143 get_interface<PPB_PDF>()->UserMetricsRecordAction(instance.pp_instance(),
144 action.pp_var());
145 }
146 }
147
148 // static
HasUnsupportedFeature(const InstanceHandle & instance)149 void PDF::HasUnsupportedFeature(const InstanceHandle& instance) {
150 if (has_interface<PPB_PDF>())
151 get_interface<PPB_PDF>()->HasUnsupportedFeature(instance.pp_instance());
152 }
153
154 // static
SaveAs(const InstanceHandle & instance)155 void PDF::SaveAs(const InstanceHandle& instance) {
156 if (has_interface<PPB_PDF>())
157 get_interface<PPB_PDF>()->SaveAs(instance.pp_instance());
158 }
159
160 // static
Print(const InstanceHandle & instance)161 void PDF::Print(const InstanceHandle& instance) {
162 if (has_interface<PPB_PDF>())
163 get_interface<PPB_PDF>()->Print(instance.pp_instance());
164 }
165
166 // static
IsFeatureEnabled(const InstanceHandle & instance,PP_PDFFeature feature)167 bool PDF::IsFeatureEnabled(const InstanceHandle& instance,
168 PP_PDFFeature feature) {
169 if (has_interface<PPB_PDF>())
170 return PP_ToBool(get_interface<PPB_PDF>()->IsFeatureEnabled(
171 instance.pp_instance(), feature));
172 return false;
173 }
174
175 // static
GetResourceImageForScale(const InstanceHandle & instance,PP_ResourceImage image_id,float scale)176 ImageData PDF::GetResourceImageForScale(const InstanceHandle& instance,
177 PP_ResourceImage image_id,
178 float scale) {
179 if (has_interface<PPB_PDF>()) {
180 return ImageData(PASS_REF,
181 get_interface<PPB_PDF>()->GetResourceImageForScale(
182 instance.pp_instance(), image_id, scale));
183 }
184 return ImageData();
185 }
186
187 // static
ModalPromptForPassword(const InstanceHandle & instance,Var message)188 Var PDF::ModalPromptForPassword(const InstanceHandle& instance,
189 Var message) {
190 if (has_interface<PPB_PDF>()) {
191 return Var(PASS_REF,
192 get_interface<PPB_PDF>()->ModalPromptForPassword(
193 instance.pp_instance(),
194 message.pp_var()));
195 }
196 return Var();
197 }
198
199 // static
IsOutOfProcess(const InstanceHandle & instance)200 bool PDF::IsOutOfProcess(const InstanceHandle& instance) {
201 if (has_interface<PPB_PDF>()) {
202 return PP_ToBool(get_interface<PPB_PDF>()->IsOutOfProcess(
203 instance.pp_instance()));
204 }
205 return false;
206 }
207
208 } // namespace pp
209