cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / private / pdf.cc
blob753613c18a3beecaf52629cf54f656b37026dc94
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"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_PDF>() {
18 return PPB_PDF_INTERFACE;
21 } // namespace
23 // static
24 bool PDF::IsAvailable() {
25 return has_interface<PPB_PDF>();
28 // static
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));
36 return Var();
39 // static
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));
47 return ImageData();
50 // static
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);
70 return 0;
73 // static
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);
82 return 0;
85 // static
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);
94 return false;
97 // static
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);
110 // static
111 void PDF::DidStartLoading(const InstanceHandle& instance) {
112 if (has_interface<PPB_PDF>())
113 get_interface<PPB_PDF>()->DidStartLoading(instance.pp_instance());
116 // static
117 void PDF::DidStopLoading(const InstanceHandle& instance) {
118 if (has_interface<PPB_PDF>())
119 get_interface<PPB_PDF>()->DidStopLoading(instance.pp_instance());
122 // static
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);
131 // static
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);
139 // static
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());
148 // static
149 void PDF::HasUnsupportedFeature(const InstanceHandle& instance) {
150 if (has_interface<PPB_PDF>())
151 get_interface<PPB_PDF>()->HasUnsupportedFeature(instance.pp_instance());
154 // static
155 void PDF::SaveAs(const InstanceHandle& instance) {
156 if (has_interface<PPB_PDF>())
157 get_interface<PPB_PDF>()->SaveAs(instance.pp_instance());
160 // static
161 void PDF::Print(const InstanceHandle& instance) {
162 if (has_interface<PPB_PDF>())
163 get_interface<PPB_PDF>()->Print(instance.pp_instance());
166 // static
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;
175 // static
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));
184 return ImageData();
187 } // namespace pp