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 "base/logging.h" 6 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/private/ppb_pdf.h" 8 #include "ppapi/thunk/enter.h" 9 #include "ppapi/thunk/ppb_flash_font_file_api.h" 10 #include "ppapi/thunk/ppb_pdf_api.h" 11 #include "ppapi/thunk/resource_creation_api.h" 12 #include "ppapi/thunk/thunk.h" 13 14 namespace ppapi { 15 namespace thunk { 16 17 namespace { 18 19 PP_Var GetLocalizedString(PP_Instance instance, PP_ResourceString string_id) { 20 EnterInstanceAPI<PPB_PDF_API> enter(instance); 21 if (enter.failed()) 22 return PP_MakeUndefined(); 23 return enter.functions()->GetLocalizedString(string_id); 24 } 25 26 PP_Resource GetResourceImage(PP_Instance instance, 27 PP_ResourceImage image_id) { 28 EnterInstanceAPI<PPB_PDF_API> enter(instance); 29 if (enter.failed()) 30 return 0; 31 return enter.functions()->GetResourceImage(image_id); 32 } 33 34 PP_Resource GetFontFileWithFallback( 35 PP_Instance instance, 36 const PP_BrowserFont_Trusted_Description* description, 37 PP_PrivateFontCharset charset) { 38 // TODO(raymes): Eventually we should replace the use of this function with 39 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code. 40 // For now just call into PPB_Flash_Font_File which has the exact same API. 41 EnterResourceCreation enter(instance); 42 if (enter.failed()) 43 return 0; 44 return enter.functions()->CreateFlashFontFile(instance, description, charset); 45 } 46 47 bool GetFontTableForPrivateFontFile(PP_Resource font_file, 48 uint32_t table, 49 void* output, 50 uint32_t* output_length) { 51 // TODO(raymes): Eventually we should replace the use of this function with 52 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code. 53 // For now just call into PPB_Flash_Font_File which has the exact same API. 54 EnterResource<PPB_Flash_FontFile_API> enter(font_file, true); 55 if (enter.failed()) 56 return PP_FALSE; 57 return PP_ToBool(enter.object()->GetFontTable(table, output, output_length)); 58 } 59 60 void SearchString(PP_Instance instance, 61 const unsigned short* string, 62 const unsigned short* term, 63 bool case_sensitive, 64 PP_PrivateFindResult** results, 65 int* count) { 66 EnterInstanceAPI<PPB_PDF_API> enter(instance); 67 if (enter.failed()) 68 return; 69 enter.functions()->SearchString(string, term, case_sensitive, results, count); 70 } 71 72 void DidStartLoading(PP_Instance instance) { 73 EnterInstanceAPI<PPB_PDF_API> enter(instance); 74 if (enter.succeeded()) 75 enter.functions()->DidStartLoading(); 76 } 77 78 void DidStopLoading(PP_Instance instance) { 79 EnterInstanceAPI<PPB_PDF_API> enter(instance); 80 if (enter.succeeded()) 81 enter.functions()->DidStopLoading(); 82 } 83 84 void SetContentRestriction(PP_Instance instance, int restrictions) { 85 EnterInstanceAPI<PPB_PDF_API> enter(instance); 86 if (enter.succeeded()) 87 enter.functions()->SetContentRestriction(restrictions); 88 } 89 90 void HistogramPDFPageCount(PP_Instance instance, int count) { 91 EnterInstanceAPI<PPB_PDF_API> enter(instance); 92 if (enter.succeeded()) 93 enter.functions()->HistogramPDFPageCount(count); 94 } 95 96 void UserMetricsRecordAction(PP_Instance instance, PP_Var action) { 97 EnterInstanceAPI<PPB_PDF_API> enter(instance); 98 if (enter.succeeded()) 99 enter.functions()->UserMetricsRecordAction(action); 100 } 101 102 void HasUnsupportedFeature(PP_Instance instance) { 103 EnterInstanceAPI<PPB_PDF_API> enter(instance); 104 if (enter.succeeded()) 105 enter.functions()->HasUnsupportedFeature(); 106 } 107 108 void SaveAs(PP_Instance instance) { 109 EnterInstanceAPI<PPB_PDF_API> enter(instance); 110 if (enter.succeeded()) 111 enter.functions()->SaveAs(); 112 } 113 114 void Print(PP_Instance instance) { 115 EnterInstanceAPI<PPB_PDF_API> enter(instance); 116 if (enter.succeeded()) 117 enter.functions()->Print(); 118 } 119 120 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { 121 EnterInstanceAPI<PPB_PDF_API> enter(instance); 122 if (enter.failed()) 123 return PP_FALSE; 124 return enter.functions()->IsFeatureEnabled(feature); 125 } 126 127 PP_Resource GetResourceImageForScale(PP_Instance instance, 128 PP_ResourceImage image_id, 129 float scale) { 130 EnterInstanceAPI<PPB_PDF_API> enter(instance); 131 if (enter.failed()) 132 return 0; 133 return enter.functions()->GetResourceImageForScale(image_id, scale); 134 } 135 136 PP_Var ModalPromptForPassword(PP_Instance instance_id, 137 PP_Var message) { 138 // TODO(raymes): Implement or remove this function. 139 NOTIMPLEMENTED(); 140 return PP_MakeUndefined(); 141 } 142 143 PP_Bool IsOutOfProcess(PP_Instance instance) { 144 EnterInstanceAPI<PPB_PDF_API> enter(instance); 145 if (enter.failed()) 146 return PP_FALSE; 147 return enter.functions()->IsOutOfProcess(); 148 } 149 150 const PPB_PDF g_ppb_pdf_thunk = { 151 &GetLocalizedString, 152 &GetResourceImage, 153 &GetFontFileWithFallback, 154 &GetFontTableForPrivateFontFile, 155 &SearchString, 156 &DidStartLoading, 157 &DidStopLoading, 158 &SetContentRestriction, 159 &HistogramPDFPageCount, 160 &UserMetricsRecordAction, 161 &HasUnsupportedFeature, 162 &SaveAs, 163 &Print, 164 &IsFeatureEnabled, 165 &GetResourceImageForScale, 166 &ModalPromptForPassword, 167 &IsOutOfProcess, 168 }; 169 170 } // namespace 171 172 const PPB_PDF* GetPPB_PDF_Thunk() { 173 return &g_ppb_pdf_thunk; 174 } 175 176 } // namespace thunk 177 } // namespace ppapi 178