Clean up check for dependency_info.
[chromium-blink-merge.git] / ppapi / thunk / ppb_pdf_thunk.cc
blob8c447840018c116353476c07e734c0963b8ded5b
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 "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"
14 namespace ppapi {
15 namespace thunk {
17 namespace {
19 PP_Resource GetFontFileWithFallback(
20 PP_Instance instance,
21 const PP_BrowserFont_Trusted_Description* description,
22 PP_PrivateFontCharset charset) {
23 // TODO(raymes): Eventually we should replace the use of this function with
24 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
25 // For now just call into PPB_Flash_Font_File which has the exact same API.
26 EnterResourceCreation enter(instance);
27 if (enter.failed())
28 return 0;
29 return enter.functions()->CreateFlashFontFile(instance, description, charset);
32 bool GetFontTableForPrivateFontFile(PP_Resource font_file,
33 uint32_t table,
34 void* output,
35 uint32_t* output_length) {
36 // TODO(raymes): Eventually we should replace the use of this function with
37 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
38 // For now just call into PPB_Flash_Font_File which has the exact same API.
39 EnterResource<PPB_Flash_FontFile_API> enter(font_file, true);
40 if (enter.failed())
41 return PP_FALSE;
42 return PP_ToBool(enter.object()->GetFontTable(table, output, output_length));
45 void SearchString(PP_Instance instance,
46 const unsigned short* string,
47 const unsigned short* term,
48 bool case_sensitive,
49 PP_PrivateFindResult** results,
50 int* count) {
51 EnterInstanceAPI<PPB_PDF_API> enter(instance);
52 if (enter.failed())
53 return;
54 enter.functions()->SearchString(string, term, case_sensitive, results, count);
57 void DidStartLoading(PP_Instance instance) {
58 EnterInstanceAPI<PPB_PDF_API> enter(instance);
59 if (enter.succeeded())
60 enter.functions()->DidStartLoading();
63 void DidStopLoading(PP_Instance instance) {
64 EnterInstanceAPI<PPB_PDF_API> enter(instance);
65 if (enter.succeeded())
66 enter.functions()->DidStopLoading();
69 void SetContentRestriction(PP_Instance instance, int restrictions) {
70 EnterInstanceAPI<PPB_PDF_API> enter(instance);
71 if (enter.succeeded())
72 enter.functions()->SetContentRestriction(restrictions);
75 void UserMetricsRecordAction(PP_Instance instance, PP_Var action) {
76 EnterInstanceAPI<PPB_PDF_API> enter(instance);
77 if (enter.succeeded())
78 enter.functions()->UserMetricsRecordAction(action);
81 void HasUnsupportedFeature(PP_Instance instance) {
82 EnterInstanceAPI<PPB_PDF_API> enter(instance);
83 if (enter.succeeded())
84 enter.functions()->HasUnsupportedFeature();
87 void SaveAs(PP_Instance instance) {
88 EnterInstanceAPI<PPB_PDF_API> enter(instance);
89 if (enter.succeeded())
90 enter.functions()->SaveAs();
93 void Print(PP_Instance instance) {
94 EnterInstanceAPI<PPB_PDF_API> enter(instance);
95 if (enter.succeeded())
96 enter.functions()->Print();
99 PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) {
100 EnterInstanceAPI<PPB_PDF_API> enter(instance);
101 if (enter.failed())
102 return PP_FALSE;
103 return enter.functions()->IsFeatureEnabled(feature);
106 void SetSelectedText(PP_Instance instance,
107 const char* selected_text) {
108 EnterInstanceAPI<PPB_PDF_API> enter(instance);
109 if (enter.succeeded())
110 enter.functions()->SetSelectedText(selected_text);
113 void SetLinkUnderCursor(PP_Instance instance, const char* url) {
114 EnterInstanceAPI<PPB_PDF_API> enter(instance);
115 if (enter.failed())
116 return;
117 enter.functions()->SetLinkUnderCursor(url);
120 void GetV8ExternalSnapshotData(PP_Instance instance,
121 const char** natives_data_out,
122 int* natives_size_out,
123 const char** snapshot_data_out,
124 int* snapshot_size_out) {
125 EnterInstanceAPI<PPB_PDF_API> enter(instance);
126 if (enter.failed())
127 return;
128 enter.functions()->GetV8ExternalSnapshotData(natives_data_out,
129 natives_size_out, snapshot_data_out, snapshot_size_out);
132 const PPB_PDF g_ppb_pdf_thunk = {
133 &GetFontFileWithFallback,
134 &GetFontTableForPrivateFontFile,
135 &SearchString,
136 &DidStartLoading,
137 &DidStopLoading,
138 &SetContentRestriction,
139 &UserMetricsRecordAction,
140 &HasUnsupportedFeature,
141 &SaveAs,
142 &Print,
143 &IsFeatureEnabled,
144 &SetSelectedText,
145 &SetLinkUnderCursor,
146 &GetV8ExternalSnapshotData,
149 } // namespace
151 const PPB_PDF* GetPPB_PDF_Thunk() {
152 return &g_ppb_pdf_thunk;
155 } // namespace thunk
156 } // namespace ppapi