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.
5 #include "ppapi/cpp/private/pdf.h"
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"
17 template <> const char* interface_name
<PPB_PDF
>() {
18 return PPB_PDF_INTERFACE
;
24 bool PDF::IsAvailable() {
25 return has_interface
<PPB_PDF
>();
29 Var
PDF::GetLocalizedString(const InstanceHandle
& instance
,
30 PP_ResourceString string_id
) {
31 if (has_interface
<PPB_PDF
>()) {
33 get_interface
<PPB_PDF
>()->GetLocalizedString(
34 instance
.pp_instance(), string_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
));
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
>(
60 converted_desc
.size
= description
->size
;
61 converted_desc
.weight
= static_cast<PP_BrowserFont_Trusted_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
);
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
);
86 bool PDF::GetFontTableForPrivateFontFile(PP_Resource font_file
,
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
);
98 void PDF::SearchString(const InstanceHandle
& instance
,
99 const unsigned short* string
,
100 const unsigned short* term
,
102 PP_PrivateFindResult
** results
,
104 if (has_interface
<PPB_PDF
>()) {
105 get_interface
<PPB_PDF
>()->SearchString(instance
.pp_instance(), string
,
106 term
, case_sensitive
, results
, count
);
111 void PDF::DidStartLoading(const InstanceHandle
& instance
) {
112 if (has_interface
<PPB_PDF
>())
113 get_interface
<PPB_PDF
>()->DidStartLoading(instance
.pp_instance());
117 void PDF::DidStopLoading(const InstanceHandle
& instance
) {
118 if (has_interface
<PPB_PDF
>())
119 get_interface
<PPB_PDF
>()->DidStopLoading(instance
.pp_instance());
123 void PDF::SetContentRestriction(const InstanceHandle
& instance
,
125 if (has_interface
<PPB_PDF
>()) {
126 get_interface
<PPB_PDF
>()->SetContentRestriction(instance
.pp_instance(),
132 void PDF::HistogramPDFPageCount(const InstanceHandle
& instance
,
134 if (has_interface
<PPB_PDF
>())
135 get_interface
<PPB_PDF
>()->HistogramPDFPageCount(instance
.pp_instance(),
140 void PDF::UserMetricsRecordAction(const InstanceHandle
& instance
,
142 if (has_interface
<PPB_PDF
>()) {
143 get_interface
<PPB_PDF
>()->UserMetricsRecordAction(instance
.pp_instance(),
149 void PDF::HasUnsupportedFeature(const InstanceHandle
& instance
) {
150 if (has_interface
<PPB_PDF
>())
151 get_interface
<PPB_PDF
>()->HasUnsupportedFeature(instance
.pp_instance());
155 void PDF::SaveAs(const InstanceHandle
& instance
) {
156 if (has_interface
<PPB_PDF
>())
157 get_interface
<PPB_PDF
>()->SaveAs(instance
.pp_instance());
161 void PDF::Print(const InstanceHandle
& instance
) {
162 if (has_interface
<PPB_PDF
>())
163 get_interface
<PPB_PDF
>()->Print(instance
.pp_instance());
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
));
176 ImageData
PDF::GetResourceImageForScale(const InstanceHandle
& instance
,
177 PP_ResourceImage image_id
,
179 if (has_interface
<PPB_PDF
>()) {
180 return ImageData(PASS_REF
,
181 get_interface
<PPB_PDF
>()->GetResourceImageForScale(
182 instance
.pp_instance(), image_id
, scale
));