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_BrowserFont_Trusted_Description
* description
,
54 PP_PrivateFontCharset charset
) {
55 if (has_interface
<PPB_PDF
>()) {
56 return get_interface
<PPB_PDF
>()->GetFontFileWithFallback(
57 instance
.pp_instance(), description
, charset
);
63 bool PDF::GetFontTableForPrivateFontFile(PP_Resource font_file
,
66 uint32_t* output_length
) {
67 if (has_interface
<PPB_PDF
>()) {
68 return get_interface
<PPB_PDF
>()->GetFontTableForPrivateFontFile(font_file
,
69 table
, output
, output_length
);
75 void PDF::SearchString(const InstanceHandle
& instance
,
76 const unsigned short* string
,
77 const unsigned short* term
,
79 PP_PrivateFindResult
** results
,
81 if (has_interface
<PPB_PDF
>()) {
82 get_interface
<PPB_PDF
>()->SearchString(instance
.pp_instance(), string
,
83 term
, case_sensitive
, results
, count
);
88 void PDF::DidStartLoading(const InstanceHandle
& instance
) {
89 if (has_interface
<PPB_PDF
>())
90 get_interface
<PPB_PDF
>()->DidStartLoading(instance
.pp_instance());
94 void PDF::DidStopLoading(const InstanceHandle
& instance
) {
95 if (has_interface
<PPB_PDF
>())
96 get_interface
<PPB_PDF
>()->DidStopLoading(instance
.pp_instance());
100 void PDF::SetContentRestriction(const InstanceHandle
& instance
,
102 if (has_interface
<PPB_PDF
>()) {
103 get_interface
<PPB_PDF
>()->SetContentRestriction(instance
.pp_instance(),
109 void PDF::HistogramPDFPageCount(const InstanceHandle
& instance
,
111 if (has_interface
<PPB_PDF
>())
112 get_interface
<PPB_PDF
>()->HistogramPDFPageCount(instance
.pp_instance(),
117 void PDF::UserMetricsRecordAction(const InstanceHandle
& instance
,
119 if (has_interface
<PPB_PDF
>()) {
120 get_interface
<PPB_PDF
>()->UserMetricsRecordAction(instance
.pp_instance(),
126 void PDF::HasUnsupportedFeature(const InstanceHandle
& instance
) {
127 if (has_interface
<PPB_PDF
>())
128 get_interface
<PPB_PDF
>()->HasUnsupportedFeature(instance
.pp_instance());
132 void PDF::SaveAs(const InstanceHandle
& instance
) {
133 if (has_interface
<PPB_PDF
>())
134 get_interface
<PPB_PDF
>()->SaveAs(instance
.pp_instance());
138 void PDF::Print(const InstanceHandle
& instance
) {
139 if (has_interface
<PPB_PDF
>())
140 get_interface
<PPB_PDF
>()->Print(instance
.pp_instance());
144 bool PDF::IsFeatureEnabled(const InstanceHandle
& instance
,
145 PP_PDFFeature feature
) {
146 if (has_interface
<PPB_PDF
>())
147 return PP_ToBool(get_interface
<PPB_PDF
>()->IsFeatureEnabled(
148 instance
.pp_instance(), feature
));
153 ImageData
PDF::GetResourceImageForScale(const InstanceHandle
& instance
,
154 PP_ResourceImage image_id
,
156 if (has_interface
<PPB_PDF
>()) {
157 return ImageData(PASS_REF
,
158 get_interface
<PPB_PDF
>()->GetResourceImageForScale(
159 instance
.pp_instance(), image_id
, scale
));
165 Var
PDF::ModalPromptForPassword(const InstanceHandle
& instance
,
167 if (has_interface
<PPB_PDF
>()) {
169 get_interface
<PPB_PDF
>()->ModalPromptForPassword(
170 instance
.pp_instance(),
177 bool PDF::IsOutOfProcess(const InstanceHandle
& instance
) {
178 if (has_interface
<PPB_PDF
>()) {
179 return PP_ToBool(get_interface
<PPB_PDF
>()->IsOutOfProcess(
180 instance
.pp_instance()));
186 void PDF::SetSelectedText(const InstanceHandle
& instance
,
187 const char* selected_text
) {
188 if (has_interface
<PPB_PDF
>()) {
189 get_interface
<PPB_PDF
>()->SetSelectedText(instance
.pp_instance(),
195 void PDF::SetLinkUnderCursor(const InstanceHandle
& instance
, const char* url
) {
196 if (has_interface
<PPB_PDF
>())
197 get_interface
<PPB_PDF
>()->SetLinkUnderCursor(instance
.pp_instance(), url
);
201 void PDF::GetV8ExternalSnapshotData(const InstanceHandle
& instance
,
202 const char** natives_data_out
,
203 int* natives_size_out
,
204 const char** snapshot_data_out
,
205 int* snapshot_size_out
) {
206 if (has_interface
<PPB_PDF
>()) {
207 get_interface
<PPB_PDF
>()->GetV8ExternalSnapshotData(instance
.pp_instance(),
208 natives_data_out
, natives_size_out
, snapshot_data_out
,
212 *natives_data_out
= NULL
;
213 *snapshot_data_out
= NULL
;
214 *natives_size_out
= 0;
215 *snapshot_size_out
= 0;