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 13namespace pp { 14 15namespace { 16 17template <> const char* interface_name<PPB_PDF>() { 18 return PPB_PDF_INTERFACE; 19} 20 21} // namespace 22 23// static 24bool PDF::IsAvailable() { 25 return has_interface<PPB_PDF>(); 26} 27 28// static 29Var 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 40ImageData 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 51PP_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); 58 } 59 return 0; 60} 61 62// static 63bool PDF::GetFontTableForPrivateFontFile(PP_Resource font_file, 64 uint32_t table, 65 void* output, 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); 70 } 71 return false; 72} 73 74// static 75void PDF::SearchString(const InstanceHandle& instance, 76 const unsigned short* string, 77 const unsigned short* term, 78 bool case_sensitive, 79 PP_PrivateFindResult** results, 80 int* count) { 81 if (has_interface<PPB_PDF>()) { 82 get_interface<PPB_PDF>()->SearchString(instance.pp_instance(), string, 83 term, case_sensitive, results, count); 84 } 85} 86 87// static 88void PDF::DidStartLoading(const InstanceHandle& instance) { 89 if (has_interface<PPB_PDF>()) 90 get_interface<PPB_PDF>()->DidStartLoading(instance.pp_instance()); 91} 92 93// static 94void PDF::DidStopLoading(const InstanceHandle& instance) { 95 if (has_interface<PPB_PDF>()) 96 get_interface<PPB_PDF>()->DidStopLoading(instance.pp_instance()); 97} 98 99// static 100void PDF::SetContentRestriction(const InstanceHandle& instance, 101 int restrictions) { 102 if (has_interface<PPB_PDF>()) { 103 get_interface<PPB_PDF>()->SetContentRestriction(instance.pp_instance(), 104 restrictions); 105 } 106} 107 108// static 109void PDF::HistogramPDFPageCount(const InstanceHandle& instance, 110 int count) { 111 if (has_interface<PPB_PDF>()) 112 get_interface<PPB_PDF>()->HistogramPDFPageCount(instance.pp_instance(), 113 count); 114} 115 116// static 117void PDF::UserMetricsRecordAction(const InstanceHandle& instance, 118 const Var& action) { 119 if (has_interface<PPB_PDF>()) { 120 get_interface<PPB_PDF>()->UserMetricsRecordAction(instance.pp_instance(), 121 action.pp_var()); 122 } 123} 124 125// static 126void PDF::HasUnsupportedFeature(const InstanceHandle& instance) { 127 if (has_interface<PPB_PDF>()) 128 get_interface<PPB_PDF>()->HasUnsupportedFeature(instance.pp_instance()); 129} 130 131// static 132void PDF::SaveAs(const InstanceHandle& instance) { 133 if (has_interface<PPB_PDF>()) 134 get_interface<PPB_PDF>()->SaveAs(instance.pp_instance()); 135} 136 137// static 138void PDF::Print(const InstanceHandle& instance) { 139 if (has_interface<PPB_PDF>()) 140 get_interface<PPB_PDF>()->Print(instance.pp_instance()); 141} 142 143// static 144bool 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)); 149 return false; 150} 151 152// static 153ImageData PDF::GetResourceImageForScale(const InstanceHandle& instance, 154 PP_ResourceImage image_id, 155 float scale) { 156 if (has_interface<PPB_PDF>()) { 157 return ImageData(PASS_REF, 158 get_interface<PPB_PDF>()->GetResourceImageForScale( 159 instance.pp_instance(), image_id, scale)); 160 } 161 return ImageData(); 162} 163 164// static 165Var PDF::ModalPromptForPassword(const InstanceHandle& instance, 166 Var message) { 167 if (has_interface<PPB_PDF>()) { 168 return Var(PASS_REF, 169 get_interface<PPB_PDF>()->ModalPromptForPassword( 170 instance.pp_instance(), 171 message.pp_var())); 172 } 173 return Var(); 174} 175 176// static 177bool PDF::IsOutOfProcess(const InstanceHandle& instance) { 178 if (has_interface<PPB_PDF>()) { 179 return PP_ToBool(get_interface<PPB_PDF>()->IsOutOfProcess( 180 instance.pp_instance())); 181 } 182 return false; 183} 184 185// static 186void 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(), 190 selected_text); 191 } 192} 193 194// static 195void PDF::SetLinkUnderCursor(const InstanceHandle& instance, const char* url) { 196 if (has_interface<PPB_PDF>()) 197 get_interface<PPB_PDF>()->SetLinkUnderCursor(instance.pp_instance(), url); 198} 199 200} // namespace pp 201