Returning scoped_ptr instead of raw pointer in SpdySessionPoolInfoToValue() in net/
[chromium-blink-merge.git] / ppapi / thunk / ppb_pdf_thunk.cc
blobfb06a90fe2b72b2c74a611155b2d7f7549d94a41
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_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);
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);
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);
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));
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);
72 void DidStartLoading(PP_Instance instance) {
73 EnterInstanceAPI<PPB_PDF_API> enter(instance);
74 if (enter.succeeded())
75 enter.functions()->DidStartLoading();
78 void DidStopLoading(PP_Instance instance) {
79 EnterInstanceAPI<PPB_PDF_API> enter(instance);
80 if (enter.succeeded())
81 enter.functions()->DidStopLoading();
84 void SetContentRestriction(PP_Instance instance, int restrictions) {
85 EnterInstanceAPI<PPB_PDF_API> enter(instance);
86 if (enter.succeeded())
87 enter.functions()->SetContentRestriction(restrictions);
90 void HistogramPDFPageCount(PP_Instance instance, int count) {
91 EnterInstanceAPI<PPB_PDF_API> enter(instance);
92 if (enter.succeeded())
93 enter.functions()->HistogramPDFPageCount(count);
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);
102 void HasUnsupportedFeature(PP_Instance instance) {
103 EnterInstanceAPI<PPB_PDF_API> enter(instance);
104 if (enter.succeeded())
105 enter.functions()->HasUnsupportedFeature();
108 void SaveAs(PP_Instance instance) {
109 EnterInstanceAPI<PPB_PDF_API> enter(instance);
110 if (enter.succeeded())
111 enter.functions()->SaveAs();
114 void Print(PP_Instance instance) {
115 EnterInstanceAPI<PPB_PDF_API> enter(instance);
116 if (enter.succeeded())
117 enter.functions()->Print();
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);
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);
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();
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();
150 void SetSelectedText(PP_Instance instance,
151 const char* selected_text) {
152 EnterInstanceAPI<PPB_PDF_API> enter(instance);
153 if (enter.succeeded())
154 enter.functions()->SetSelectedText(selected_text);
157 void SetLinkUnderCursor(PP_Instance instance, const char* url) {
158 EnterInstanceAPI<PPB_PDF_API> enter(instance);
159 if (enter.failed())
160 return;
161 enter.functions()->SetLinkUnderCursor(url);
164 void GetV8ExternalSnapshotData(PP_Instance instance,
165 const char** natives_data_out,
166 int* natives_size_out,
167 const char** snapshot_data_out,
168 int* snapshot_size_out) {
169 EnterInstanceAPI<PPB_PDF_API> enter(instance);
170 if (enter.failed())
171 return;
172 enter.functions()->GetV8ExternalSnapshotData(natives_data_out,
173 natives_size_out, snapshot_data_out, snapshot_size_out);
176 const PPB_PDF g_ppb_pdf_thunk = {
177 &GetLocalizedString,
178 &GetResourceImage,
179 &GetFontFileWithFallback,
180 &GetFontTableForPrivateFontFile,
181 &SearchString,
182 &DidStartLoading,
183 &DidStopLoading,
184 &SetContentRestriction,
185 &HistogramPDFPageCount,
186 &UserMetricsRecordAction,
187 &HasUnsupportedFeature,
188 &SaveAs,
189 &Print,
190 &IsFeatureEnabled,
191 &GetResourceImageForScale,
192 &ModalPromptForPassword,
193 &IsOutOfProcess,
194 &SetSelectedText,
195 &SetLinkUnderCursor,
196 &GetV8ExternalSnapshotData,
199 } // namespace
201 const PPB_PDF* GetPPB_PDF_Thunk() {
202 return &g_ppb_pdf_thunk;
205 } // namespace thunk
206 } // namespace ppapi